I'm working on macros to format time estimates to execute project tasks. I have a custom environment to format subtask estimates and now I want to add a table summarizing everything.
I'm using tocloft to create a custom list and it works as expected for all the subtask entries but I would also like to show the summary for the full milestone. What I have right now gets all the content right but the milestone summery in the list of estimates is after the subtasks whereas I want it before. If I put the respective macro at the start of the section placement in the list of estimates is correct but estimate itself it incorrect (0 days).
How can I either get the the milestone line before the subtasks but also have the correct estimate?
\documentclass[11pt,letterpaper,oneside]{article}
\usepackage{tocloft}
%----------------------------------------------------------------------
% Environment for estimates
%----------------------------------------------------------------------
\newcommand{\listestimatename}{List of Estimates}
\newlistof{estimate}{est}{\listestimatename}
\newlistentry{subestimate}{est}{1}
\setcounter{estdepth}{2}
\cftsetindents{estimate}{1em}{1.5em}
\cftsetindents{subestimate}{2em}{3.8em}
\newcommand{\CurWorkLabel}{}
\newcounter{cntScnWorkEstimate}[section]
\newcounter{cntEnvWorkEstimate}
\newenvironment{workestimate}[1]
{
\small
\renewcommand{\CurWorkLabel}{#1}
\setcounter{cntEnvWorkEstimate}{0}
\begin{tabular}{c l}
\multicolumn{2}{l}{\emph{#1}}\tabularnewline
\hline
}
{
% finish the table
\textbf{\emph{\thecntEnvWorkEstimate\ days}} & \textbf{\emph{Total}}
\end{tabular}
% now add a list of estimates entry
\phantomsection
\addcontentsline{est}{subestimate}
{\protect\numberline{\thesubsection}\CurWorkLabel\ (\thecntEnvWorkEstimate\ days)}
}
\newcommand{\estimate}[2]{%
\addtocounter{cntEnvWorkEstimate}{#1}%
\addtocounter{cntScnWorkEstimate}{#1}%
\emph{#1 days} & #2 \tabularnewline
}
\newcommand{\addsectionestimate}[1]{%
\addcontentsline{est}{estimate}
{\protect\numberline{\thesection}\textbf{#1 Total} (\thecntScnWorkEstimate\ days)}
}
%----------------------------------------------------------------------
% Now the actual document
%----------------------------------------------------------------------
\begin{document}
\listofestimate
\section{Milestone 1}
\subsection{Sub Task 1}
\begin{workestimate}{Subtask1 Estimate}
\estimate{1}{detail A}
\estimate{2}{detail B}
\end{workestimate}
Long description of how this sub task will be carried out.
\subsection{Sub Task 2}
\begin{workestimate}{Subtask 2 Estimate}
\estimate{3}{detail C}
\estimate{4}{detail D}
\end{workestimate}
Long description of how this sub task will be carried out.
\addsectionestimate{Milestone 1}
\end{document}


