function show_timeSheet_list($template) { global $TPL; global $timeSheet; global $db; global $tskDesc; global $timeSheetItem; global $timeSheetID; $db_task = new db_alloc(); if (is_object($timeSheet) && ($timeSheet->get_value("status") == "edit" || $timeSheet->get_value("status") == "rejected")) { $TPL["timeSheetItem_buttons"] = ' <button type="submit" name="timeSheetItem_delete" value="1" class="delete_button">Delete<i class="icon-trash"></i></button> <button type="submit" name="timeSheetItem_edit" value="1">Edit<i class="icon-edit"></i></button>'; } $TPL["currency"] = page::money($timeSheet->get_value("currencyTypeID"), '', "%S"); $timeUnit = new timeUnit(); $unit_array = $timeUnit->get_assoc_array("timeUnitID", "timeUnitLabelA"); $item_query = prepare("SELECT * from timeSheetItem WHERE timeSheetID=%d", $timeSheetID); // If editing a timeSheetItem then don't display it in the list $timeSheetItemID = $_POST["timeSheetItemID"] or $timeSheetItemID = $_GET["timeSheetItemID"]; $timeSheetItemID and $item_query .= prepare(" AND timeSheetItemID != %d", $timeSheetItemID); $item_query .= prepare(" GROUP BY timeSheetItemID ORDER BY dateTimeSheetItem, timeSheetItemID"); $db->query($item_query); if (is_object($timeSheet)) { $project = $timeSheet->get_foreign_object("project"); $row_projectPerson = projectPerson::get_projectPerson_row($project->get_id(), $timeSheet->get_value("personID")); $default_rate = array(); if ($row_projectPerson && $row_projectPerson['rate'] > 0) { $default_rate['rate'] = $row_projectPerson['rate']; $default_rate['unit'] = $row_projectPerson['rateUnitID']; } } while ($db->next_record()) { $timeSheetItem = new timeSheetItem(); $timeSheetItem->currency = $timeSheet->get_value("currencyTypeID"); $timeSheetItem->read_db_record($db); $timeSheetItem->set_tpl_values("timeSheetItem_"); $TPL["timeSheet_totalHours"] += $timeSheetItem->get_value("timeSheetItemDuration"); $TPL["unit"] = $unit_array[$timeSheetItem->get_value("timeSheetItemDurationUnitID")]; $br = ""; $commentPrivateText = ""; $text = $timeSheetItem->get_value('description', DST_HTML_DISPLAY); if ($timeSheetItem->get_value("commentPrivate")) { $commentPrivateText = "<b>[Private Comment]</b> "; } $text and $TPL["timeSheetItem_description"] = "<a href=\"" . $TPL["url_alloc_task"] . "taskID=" . $timeSheetItem->get_value('taskID') . "\">" . $text . "</a>"; $text && $timeSheetItem->get_value("comment") and $br = "<br>"; $timeSheetItem->get_value("comment") and $TPL["timeSheetItem_comment"] = $br . $commentPrivateText . page::to_html($timeSheetItem->get_value("comment")); $TPL["timeSheetItem_unit_times_rate"] = $timeSheetItem->calculate_item_charge($timeSheet->get_value("currencyTypeID"), $timeSheetItem->get_value("rate")); $m = new meta("timeSheetItemMultiplier"); $tsMultipliers = $m->get_list(); $timeSheetItem->get_value('multiplier') and $TPL["timeSheetItem_multiplier"] = $tsMultipliers[$timeSheetItem->get_value('multiplier')]['timeSheetItemMultiplierName']; // Check to see if this tsi is part of an overrun $TPL["timeSheetItem_class"] = "panel"; $TPL["timeSheetItem_status"] = ""; $row_messages = array(); if ($timeSheetItem->get_value('taskID')) { $task = new task(); $task->set_id($timeSheetItem->get_value('taskID')); $task->select(); if ($task->get_value('timeLimit') > 0) { $total_billed_time = $task->get_time_billed(false) / 3600; // get_time_billed returns seconds, limit hours is in hours if ($total_billed_time > $task->get_value('timeLimit')) { $row_messages[] = "<em class='faint warn nobr'>[ Exceeds Limit ]</em>"; } } } // Highlight the rate if the project person has a non-zero rate and it doesn't match the item's rate if ($default_rate) { if ($timeSheetItem->get_value('rate') != $default_rate['rate'] || $timeSheetItem->get_value('timeSheetItemDurationUnitID') != $default_rate['unit']) { $row_messages[] = "<em class='faint warn nobr'>[ Modified rate ]</em>"; } } if ($row_messages) { $TPL["timeSheetItem_status"] = implode("<br />", $row_messages); $TPL["timeSheetItem_class"] = "panel loud"; } include_template($template); } $TPL["summary_totals"] = $timeSheet->pay_info["summary_unit_totals"]; }
function get_timeSheetItem_list_money($timeSheetID) { global $TPL; list($db, $customerBilledDollars, $timeSheet, $unit_array, $currency) = $this->get_timeSheetItem_vars($timeSheetID); $taxPercent = config::get_config_item("taxPercent"); $taxPercentDivisor = $taxPercent / 100 + 1; while ($db->next_record()) { $timeSheetItem = new timeSheetItem(); $timeSheetItem->read_db_record($db); $taskID = sprintf("%d", $timeSheetItem->get_value("taskID")); $num = $timeSheetItem->calculate_item_charge($currency, $customerBilledDollars ? $customerBilledDollars : $timeSheetItem->get_value("rate")); if ($taxPercent !== '') { $num_minus_gst = $num / $taxPercentDivisor; $gst = $num - $num_minus_gst; if ($num_minus_gst + $gst != $num) { $num_minus_gst += $num - ($num_minus_gst + $gst); // round it up. } $rows[$taskID]["money"] += page::money($timeSheet->get_value("currencyTypeID"), $num_minus_gst, "%mo"); $rows[$taskID]["gst"] += page::money($timeSheet->get_value("currencyTypeID"), $gst, "%mo"); $info["total_gst"] += $gst; $info["total"] += $num_minus_gst; } else { $rows[$taskID]["money"] += page::money($timeSheet->get_value("currencyTypeID"), $num, "%mo"); $info["total"] += $num; } $unit = $unit_array[$timeSheetItem->get_value("timeSheetItemDurationUnitID")]; $units[$taskID][$unit] += sprintf("%0.2f", $timeSheetItem->get_value("timeSheetItemDuration") * $timeSheetItem->get_value("multiplier")); unset($str); $d = $timeSheetItem->get_value('taskID', DST_HTML_DISPLAY) . ": " . $timeSheetItem->get_value('description', DST_HTML_DISPLAY); $d && !$rows[$taskID]["desc"] and $str[] = "<b>" . $d . "</b>"; //inline because the PDF needs it that way // Get task description if ($taskID && $TPL["printDesc"]) { $t = new task(); $t->set_id($taskID); $t->select(); $d2 = str_replace("\r\n", "\n", $t->get_value("taskDescription", DST_HTML_DISPLAY)); $d2 .= "\n"; $d2 && !$d2s[$taskID] and $str[] = $d2; $d2 and $d2s[$taskID] = true; } $c = str_replace("\r\n", "\n", $timeSheetItem->get_value("comment")); !$timeSheetItem->get_value("commentPrivate") && $c and $str[] = page::htmlentities($c); is_array($str) and $rows[$taskID]["desc"] .= trim(implode(DEFAULT_SEP, $str)); } // Group by units ie, a particular row/task might have 3 Weeks, 2 Hours of work done. $units or $units = array(); foreach ($units as $tid => $u) { unset($commar); foreach ($u as $unit => $amount) { $rows[$tid]["units"] .= $commar . $amount . " " . $unit; $commar = ", "; $i[$unit] += $amount; } } unset($commar); $i or $i = array(); foreach ($i as $unit => $amount) { $info["total_units"] .= $commar . $amount . " " . $unit; $commar = ", "; } $info["total_inc_gst"] = page::money($timeSheet->get_value("currencyTypeID"), $info["total"] + $info["total_gst"], "%s%mo"); // If we are in dollar mode, then prefix the total with a dollar sign $info["total"] = page::money($timeSheet->get_value("currencyTypeID"), $info["total"], "%s%mo"); $info["total_gst"] = page::money($timeSheet->get_value("currencyTypeID"), $info["total_gst"], "%s%mo"); $rows or $rows = array(); $info or $info = array(); return array($rows, $info); }