function report_projecthours($from, $to) { $from_date = setFromDate($from); $to_date = setToDate($to); $reports = []; $all_projects = get_all_projects(); $count = 0; foreach ($all_projects as $p) { $hours = 0; $minutes = 0; $hrmin = [0, 0]; $project_date = date_create_from_mm_dd_yyyy($p->get_mm_dd_yy()); if ($project_date >= $from_date && $project_date <= $to_date && $p->get_persons() != null) { if (!isset($reports[$p->get_id()][0]) || !isset($reports[$p->get_id()][1]) || !isset($reports[$p->get_id()][2])) { $reports[$p->get_id()][0] = NULL; $reports[$p->get_id()][1] = NULL; } error_log("Getting total hours and number of volunteers---------------------------"); error_log("The number of hours is " . $p->duration()); error_log("The number of volunteers is " . $p->get_num_of_persons()); $hrmin = ConvertTimeToHrMin($p->duration()); $hours = $hrmin[0] * $p->get_num_of_persons(); $minutes = $hrmin[1] * $p->get_num_of_persons(); $projectTime = ArrangeMinutesInHours($hours, $minutes); $reports[$p->get_id()][0] = $projectTime; $reports[$p->get_id()][1] = $p->get_num_of_persons(); $count++; error_log("End of loop--------------------------------------"); } } error_log("------- " . $count . " project(s) recorded-----------"); return $reports; }
function displayProjectTotalHoursReport($labels, $reports) { $res = "<style type='text/css'>\n newft { font-size:14px; color:black; font-weight:bold; }\n </style>\n <table id = 'report' style = width:300px;>\n <thead>\n <td><newft>Project Date & Name</newft></td>\n <td><newft>Hours</newft></td>\n <td><newft>Volunteers</newft></td>\n </thead>\n <tbody>"; $total = [0, 0, 0]; foreach ($reports as $projid => $data) { $hrmin = explode(':', $data[0]); $total[0] += $hrmin[0]; $total[1] += $hrmin[1]; $total[2] += $data[1]; } if (count($labels) == count($reports)) { foreach (array_combine($labels, $reports) as $label => $report) { $res .= appendShiftOrProjectData($label, $report); } } else { error_log("FAIL: The two arrays are not equal"); echo "<br> - FAIL: There was an error in combining the arrays."; die; } $res = $res . "<td><newft>Total:</newft></td><td style='text-align:center'><newft>" . ArrangeMinutesInHours($total[0], $total[1]) . "</newft></td><td style='text-align:center'><newft>{$total['2']}</newft></td></tbody></table>"; return $res; }