Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

cost.cc

Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 2000 Alan McIvor <alan@mcivor.gen.nz>
00003 **  
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 ** 
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 ** 
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software 
00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 #ifdef HAVE_CONFIG_H
00019 #include <config.h>
00020 #endif
00021 
00022 using namespace std;
00023 
00024 #include "project.h"
00025 #include "reporter.h"
00026 
00027 
00028 void Reporter::HTMLCostReport(Project *project, FILE *f)
00029 {
00030     fprintf(f,"<html>\n<body>\n\n");
00031 
00032     fprintf(f, "<h1>Project Costing</h1>\n");
00033     fprintf(f, "<table BORDER=1 CELLPADDING=2>\n");
00034 
00035     fprintf(f,
00036             "<tr><th>ID</th><th>Task</th><th>Personnel</th><th>Equipment</th><th>Total</th></tr>\n");
00037 
00038     double grand_total = 0.0;
00039 
00040     for ( Project::TPLCI pt = project->beginTaskList() ; 
00041           pt != project->endTaskList() ; 
00042           pt++ )
00043     {
00044         TASK * t = *pt;
00045         if ( t->isVacation() )
00046             continue;                   /* vacation */
00047 
00048         double time_cost = t->timeCost();
00049         double item_cost = t->itemCost();
00050         double total = time_cost + item_cost;
00051 
00052         fprintf(f,
00053                 "<tr><td>%s</td><td><b>%s</bf></td><td align=right>%6.2f</td>\n",
00054                 t->id(),
00055                 t->name(),
00056                 time_cost);
00057 
00058         if ( t->numItems() == 0 )
00059             fprintf(f, "<td>&nbsp;</td>\n");
00060         else
00061         {
00062             fprintf(f, "<td><table>\n");
00063             for ( Project::IPLCI pi = t->begin_items() ; pi != t->end_items() ; pi++ )
00064                 fprintf(f,
00065                         "<tr><td>%s</td><td align=right>%6.2f</td></tr>\n",
00066                         (*pi)->description().c_str(),
00067                         (*pi)->cost());
00068             fprintf(f,
00069                     "<tr><td><em>Equipment Total</em></td><td align=right><em>%6.2f</em></td></tr>\n",
00070                     item_cost);
00071             fprintf(f, "</table></td>\n");
00072         }
00073         
00074         fprintf(f,
00075                 "<td align=right><b>%6.2f</b></td></tr>\n",
00076                 total);
00077         
00078         grand_total += total;
00079     }
00080 
00081     fprintf(f,
00082             "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>\n");
00083 
00084     for ( Project::IPLCI pi = project->begin_items() ; pi != project->end_items() ; pi++ )
00085     {
00086         fprintf(f, 
00087                 "<tr><td>&nbsp;</td><td colspan=3>%s</td><td align=right>%6.2f</td></tr>\n",
00088                 (*pi)->description().c_str(),
00089                 (*pi)->cost());
00090 
00091         grand_total += (*pi)->cost();
00092     }
00093     
00094     fprintf(f,
00095             "<tr><td>&nbsp;</td><td colspan=3><b>Total</b></td><td align=right><b>%6.2f</b></td></tr>\n",
00096             grand_total);
00097         
00098     fprintf(f, "</table>\n");
00099 
00100     fprintf(f,"\n\n</body>\n</html>\n");
00101 }
00102 
00103 
00104 void Reporter::TeXCostReport(Project *project, FILE *f)
00105 {
00106     fprintf(f, "\\section{Project Costing}\n\n");
00107     fprintf(f,"\\begin{supertabular}{|l|l|l|r|}\n");
00108 
00109     fprintf(f, "\\hline\n");
00110     fprintf(f, "\\textbf{ID} & \\textbf{Task} & \\textbf{Item} & \\textbf{Cost} \\\\\n");
00111     fprintf(f, "\\hline\n");
00112 
00113     double grand_total = 0.0;
00114 
00115     for ( Project::TPLCI pt = project->beginTaskList() ; 
00116           pt != project->endTaskList() ; 
00117           pt++ )
00118     {
00119         TASK * t = *pt;
00120         if ( t->isVacation() )
00121             continue;                   /* vacation */
00122 
00123         double time_cost = t->timeCost();
00124         double item_cost = t->itemCost();
00125         double total = time_cost + item_cost;
00126 
00127         fprintf(f,
00128                 "%s & \\textbf{%s} & Personnel & %6.2f \\\\\n",
00129                 t->id(),
00130                 t->name(),
00131                 time_cost);
00132 
00133         if ( t->numItems() != 0 )
00134         {
00135             for ( Project::IPLCI pi = t->begin_items() ; pi != t->end_items() ; pi++ )
00136                 fprintf(f,
00137                         " & & %s & %6.2f \\\\\n",
00138                         (*pi)->description().c_str(),
00139                         (*pi)->cost());
00140         }
00141         
00142         grand_total += total;
00143     }
00144 
00145     if ( project->numItems() != 0 )
00146     {
00147         fprintf(f, "\\hline\n");
00148         for ( Project::IPLCI pi = project->begin_items() ; 
00149               pi != project->end_items() ; pi++ )
00150         {
00151             fprintf(f, 
00152                     " & & %s & %6.2f \\\\ \n",
00153                     (*pi)->description().c_str(),
00154                     (*pi)->cost());
00155             
00156             grand_total += (*pi)->cost();
00157         }
00158     }
00159     
00160     fprintf(f, "\\hline\n");
00161     fprintf(f,
00162             " & \\multicolumn{2}{l|}{\\textbf{Total}} & \\textbf{%6.2f} \\\\ \n",
00163             grand_total);
00164         
00165     fprintf(f, "\\hline\n");
00166     fprintf(f, "\\end{supertabular}\n");
00167 }
00168 
00169 
00170 void Reporter::CostReport(Project *project, char *filename, REPORTTYPE rep_type)
00171 {
00172     FILE *f;
00173 
00174     project->SortTasks(tg_sortbyresource);
00175 
00176     f = OpenOutputFile(filename);
00177 
00178     switch ( rep_type )
00179     {
00180         case HTML_REPORT:
00181             HTMLCostReport(project, f);
00182             break;
00183 
00184         case TEX_REPORT:
00185             TeXCostReport(project, f);
00186             break;
00187 
00188         case TXT_REPORT:
00189         default:
00190             Error("Unhandled rep_type in CostReport()\n");
00191     }
00192     
00193     if ( f != stdout )
00194         fclose(f);
00195 }
00196 

Generated on Wed Feb 18 22:23:53 2004 for Opensched by doxygen1.2.15