} else { if ($timeSheetID) { // Displaying a record $timeSheet->set_id($timeSheetID); $timeSheet->select(); } else { // create a new record $timeSheet->read_globals(); $timeSheet->read_globals("timeSheet_"); $timeSheet->set_value("status", "edit"); $TPL["message_help"] = "Begin a Time Sheet by selecting a Project and clicking the Create Time Sheet button. A manager must add you to the project before you can create time sheets for it."; } } } // THAT'S THE END OF THE BIG SAVE. $person = $timeSheet->get_foreign_object("person"); $TPL["timeSheet_personName"] = $person->get_name(); $timeSheet->set_values("timeSheet_"); if (!$timeSheetID) { $timeSheet->set_value("personID", $current_user->get_id()); } if ($_POST["create_transactions_default"] && $timeSheet->have_perm(PERM_TIME_INVOICE_TIMESHEETS)) { $msg .= $timeSheet->createTransactions(); } else { if ($_POST["delete_all_transactions"] && $timeSheet->have_perm(PERM_TIME_INVOICE_TIMESHEETS)) { $msg .= $timeSheet->destroyTransactions(); } } // Take care of saving transactions if (($_POST["p_button"] || $_POST["a_button"] || $_POST["r_button"]) && $timeSheet->have_perm(PERM_TIME_INVOICE_TIMESHEETS)) { if ($_POST["p_button"]) {
function populate_string($str, $entity, $entityID = false) { // Actually do the text substitution $current_user =& singleton("current_user"); is_object($current_user) and $swap["cu"] = person::get_fullname($current_user->get_id()); if ($entity == "timeSheet" && $entityID) { $timeSheet = new timeSheet(); $timeSheet->set_id($entityID); $timeSheet->select(); $timeSheet->load_pay_info(); foreach ($timeSheet->pay_info as $k => $v) { $swap[$k] = $v; } if ($timeSheet->get_value("approvedByManagerPersonID")) { $swap["tm"] = person::get_fullname($timeSheet->get_value("approvedByManagerPersonID")); } else { $project = $timeSheet->get_foreign_object("project"); $projectManagers = $project->get_timeSheetRecipients(); if (is_array($projectManagers) && count($projectManagers)) { $people =& get_cached_table("person"); foreach ($projectManagers as $pID) { $swap["tm"] .= $commar . $people[$pID]["name"]; $commar = ", "; } } } if ($timeSheet->get_value("approvedByAdminPersonID")) { $swap["tc"] = person::get_fullname($timeSheet->get_value("approvedByAdminPersonID")); } else { $people =& get_cached_table("person"); $timeSheetAdministrators = config::get_config_item('defaultTimeSheetAdminList'); if (count($timeSheetAdministrators)) { $swap["tc"] = ""; $comma = ""; foreach ($timeSheetAdministrators as $adminID) { $swap["tc"] .= $comma . $people[$adminID]["name"]; $comma = ", "; } } else { $swap["tc"] = 'no-one'; } } $swap["ti"] = $timeSheet->get_id(); $swap["to"] = person::get_fullname($timeSheet->get_value("personID")); $swap["ta"] = person::get_fullname($timeSheet->get_value("personID")); $swap["tf"] = $timeSheet->get_value("dateFrom"); $swap["tt"] = $timeSheet->get_value("dateTo"); $swap["ts"] = $timeSheet->get_timeSheet_status(); $swap["tu"] = config::get_config_item("allocURL") . "time/timeSheet.php?timeSheetID=" . $timeSheet->get_id(); $projectID = $timeSheet->get_value("projectID"); } if ($entity == "task" && $entityID) { $task = new task(); $task->set_id($entityID); $task->select(); $swap["ti"] = $task->get_id(); $swap["to"] = person::get_fullname($task->get_value("creatorID")); $swap["ta"] = person::get_fullname($task->get_value("personID")); $swap["tm"] = person::get_fullname($task->get_value("managerID")); $swap["tc"] = person::get_fullname($task->get_value("closerID")); $swap["tn"] = $task->get_value("taskName"); $swap["td"] = $task->get_value("taskDescription"); $swap["tu"] = config::get_config_item("allocURL") . "task/task.php?taskID=" . $task->get_id(); $swap["tp"] = $task->get_priority_label(); $swap["ts"] = $task->get_task_status("label"); $swap["teb"] = $task->get_value("timeBest"); $swap["tem"] = $task->get_value("timeExpected"); $swap["tew"] = $task->get_value("timeWorst"); $swap["tep"] = person::get_fullname($task->get_value("estimatorID")); //time estimate person, when it's implemented $projectID = $task->get_value("projectID"); } if ($entity == "project" && $entityID || $projectID) { $project = new project(); if ($projectID) { $project->set_id($projectID); } else { $project->set_id($entityID); } $project->select(); $swap["pn"] = $project->get_value("projectName"); $swap["pi"] = $project->get_id(); $clientID = $project->get_value("clientID"); } if ($entity == "client" && $entityID || $clientID) { $client = new client(); if ($clientID) { $client->set_id($clientID); } else { $client->set_id($entityID); } $client->select(); $swap["li"] = $client->get_id(); $swap["cc"] = $client->get_value("clientName"); } $swap["cd"] = config::get_config_item("companyContactAddress"); $swap["cd"] .= " " . config::get_config_item("companyContactAddress2"); $swap["cd"] .= " " . config::get_config_item("companyContactAddress3"); $swap["cd"] .= "\nP: " . config::get_config_item("companyContactPhone"); $swap["cd"] .= "\nF: " . config::get_config_item("companyContactFax"); $swap["cd"] .= "\nE: " . config::get_config_item("companyContactEmail"); $swap["cd"] .= "\nW: " . config::get_config_item("companyContactHomePage"); $swap["cn"] = config::get_config_item("companyName"); $swap["c1"] = config::get_config_item("companyContactAddress"); $swap["c2"] = config::get_config_item("companyContactAddress2"); $swap["c3"] = config::get_config_item("companyContactAddress3"); $swap["ce"] = config::get_config_item("companyContactEmail"); $swap["cp"] = config::get_config_item("companyContactPhone"); $swap["cf"] = config::get_config_item("companyContactFax"); $swap["cw"] = config::get_config_item("companyContactHomePage"); foreach ($swap as $k => $v) { $str = str_replace("%" . $k, $v, $str); } return $str; }
function save_invoice_timeSheetItems($invoiceID, $timeSheetID) { $timeSheet = new timeSheet(); $timeSheet->set_id($timeSheetID); $timeSheet->select(); $currency = $timeSheet->get_value("currencyTypeID"); $timeSheet->load_pay_info(); $amount = $timeSheet->pay_info["total_customerBilledDollars"] or $amount = $timeSheet->pay_info["total_dollars"]; $project = $timeSheet->get_foreign_object("project"); $client = $project->get_foreign_object("client"); $db = new db_alloc(); $q1 = $db->query(prepare("SELECT * FROM timeSheetItem WHERE timeSheetID = %d", $timeSheetID)); while ($row = $db->row($q1)) { if (imp($timeSheet->pay_info["customerBilledDollars"])) { $iiUnitPrice = $timeSheet->pay_info["customerBilledDollars"]; } else { $iiUnitPrice = page::money($currency, $row["rate"], "%mo"); } unset($str); if ($row["comment"] && !$row["commentPrivate"]) { $str = $row["comment"]; } // Look for an existing invoiceItem $q = prepare("SELECT invoiceItem.invoiceItemID\n FROM invoiceItem\n LEFT JOIN invoice ON invoiceItem.invoiceID = invoice.invoiceID\n WHERE invoiceItem.timeSheetID = %d\n AND invoiceItem.timeSheetItemID = %d\n AND invoiceItem.invoiceID = %d\n AND invoice.invoiceStatus != 'finished'\n ORDER BY iiDate DESC LIMIT 1\n ", $timeSheet->get_id(), $row["timeSheetItemID"], $invoiceID); $q2 = $db->query($q); $r2 = $db->row($q2); $ii = new invoiceItem(); if ($r2["invoiceItemID"]) { $ii->set_id($r2["invoiceItemID"]); } $ii->currency = $currency; $ii->set_value("invoiceID", $invoiceID); $ii->set_value("timeSheetID", $timeSheet->get_id()); $ii->set_value("timeSheetItemID", $row["timeSheetItemID"]); $ii->set_value("iiMemo", "Time Sheet for " . person::get_fullname($timeSheet->get_value("personID")) . ", Project: " . $project->get_value("projectName") . ", " . $row["description"] . "\n" . $str); $ii->set_value("iiQuantity", $row["timeSheetItemDuration"] * $row["multiplier"]); $ii->set_value("iiUnitPrice", $iiUnitPrice); $ii->set_value("iiAmount", $iiUnitPrice * $row["timeSheetItemDuration"] * $row["multiplier"]); $ii->set_value("iiDate", $row["dateTimeSheetItem"]); $ii->set_value("iiTax", config::get_config_item("taxPercent")); $ii->save(); } }
function get_printable_timeSheet_file($timeSheetID, $timeSheetPrintMode, $printDesc, $format) { global $TPL; $TPL["timeSheetID"] = $timeSheetID; $TPL["timeSheetPrintMode"] = $timeSheetPrintMode; $TPL["printDesc"] = $printDesc; $TPL["format"] = $format; $db = new db_alloc(); if ($timeSheetID) { $timeSheet = new timeSheet(); $timeSheet->set_id($timeSheetID); $timeSheet->select(); $timeSheet->set_tpl_values(); $person = $timeSheet->get_foreign_object("person"); $TPL["timeSheet_personName"] = $person->get_name(); $timeSheet->set_tpl_values("timeSheet_"); // Display the project name. $project = new project(); $project->set_id($timeSheet->get_value("projectID")); $project->select(); $TPL["timeSheet_projectName"] = $project->get_value("projectName", DST_HTML_DISPLAY); // Get client name $client = $project->get_foreign_object("client"); $client->set_tpl_values(); $TPL["clientName"] = $client->get_value("clientName", DST_HTML_DISPLAY); $TPL["companyName"] = config::get_config_item("companyName"); $TPL["companyNos1"] = config::get_config_item("companyACN"); $TPL["companyNos2"] = config::get_config_item("companyABN"); unset($br); $phone = config::get_config_item("companyContactPhone"); $fax = config::get_config_item("companyContactFax"); $phone and $TPL["phone"] = "Ph: " . $phone; $fax and $TPL["fax"] = "Fax: " . $fax; $timeSheet->load_pay_info(); $db->query(prepare("SELECT max(dateTimeSheetItem) AS maxDate\n ,min(dateTimeSheetItem) AS minDate\n ,count(timeSheetItemID) as count\n FROM timeSheetItem \n WHERE timeSheetID=%d ", $timeSheetID)); $db->next_record(); $timeSheet->set_id($timeSheetID); $timeSheet->select() || alloc_error("Unable to select time sheet, trying to use id: " . $timeSheetID); $TPL["period"] = format_date(DATE_FORMAT, $db->f("minDate")) . " to " . format_date(DATE_FORMAT, $db->f("maxDate")); $TPL["img"] = config::get_config_item("companyImage"); $TPL["companyContactAddress"] = config::get_config_item("companyContactAddress"); $TPL["companyContactAddress2"] = config::get_config_item("companyContactAddress2"); $TPL["companyContactAddress3"] = config::get_config_item("companyContactAddress3"); $email = config::get_config_item("companyContactEmail"); $email and $TPL["companyContactEmail"] = "Email: " . $email; $web = config::get_config_item("companyContactHomePage"); $web and $TPL["companyContactHomePage"] = "Web: " . $web; $TPL["footer"] = config::get_config_item("timeSheetPrintFooter"); $TPL["taxName"] = config::get_config_item("taxName"); $default_header = "Time Sheet"; $default_id_label = "Time Sheet ID"; $default_contractor_label = "Contractor"; $default_total_label = "TOTAL AMOUNT PAYABLE"; if ($timeSheetPrintMode == "money") { $default_header = "Tax Invoice"; $default_id_label = "Invoice Number"; } if ($timeSheetPrintMode == "estimate") { $default_header = "Estimate"; $default_id_label = "Estimate Number"; $default_contractor_label = "Issued By"; $default_total_label = "TOTAL AMOUNT ESTIMATED"; } if ($format != "html") { // Build PDF document $font1 = ALLOC_MOD_DIR . "util/fonts/Helvetica.afm"; $font2 = ALLOC_MOD_DIR . "util/fonts/Helvetica-Oblique.afm"; $pdf_table_options = array("showLines" => 0, "shaded" => 0, "showHeadings" => 0, "xPos" => "left", "xOrientation" => "right", "fontSize" => 10, "rowGap" => 0, "fontSize" => 10); $cols = array("one" => "", "two" => "", "three" => "", "four" => ""); $cols3 = array("one" => "", "two" => ""); $cols_settings["one"] = array("justification" => "right"); $cols_settings["three"] = array("justification" => "right"); $pdf_table_options2 = array("showLines" => 0, "shaded" => 0, "showHeadings" => 0, "width" => 400, "fontSize" => 10, "xPos" => "center", "xOrientation" => "center", "cols" => $cols_settings); $cols_settings2["gst"] = array("justification" => "right"); $cols_settings2["money"] = array("justification" => "right"); $pdf_table_options3 = array("showLines" => 2, "shaded" => 0, "width" => 400, "xPos" => "center", "fontSize" => 10, "cols" => $cols_settings2, "lineCol" => array(0.8, 0.8, 0.8), "splitRows" => 1, "protectRows" => 0); $cols_settings["two"] = array("justification" => "right", "width" => 80); $pdf_table_options4 = array("showLines" => 2, "shaded" => 0, "width" => 400, "showHeadings" => 0, "fontSize" => 10, "xPos" => "center", "cols" => $cols_settings, "lineCol" => array(0.8, 0.8, 0.8)); $pdf = new Cezpdf(); $pdf->ezSetMargins(90, 90, 90, 90); $pdf->selectFont($font1); $pdf->ezStartPageNumbers(436, 80, 10, 'right', 'Page {PAGENUM} of {TOTALPAGENUM}'); $pdf->ezStartPageNumbers(200, 80, 10, 'left', '<b>' . $default_id_label . ': </b>' . $TPL["timeSheetID"]); $pdf->ezSetY(775); $TPL["companyName"] and $contact_info[] = array($TPL["companyName"]); $TPL["companyContactAddress"] and $contact_info[] = array($TPL["companyContactAddress"]); $TPL["companyContactAddress2"] and $contact_info[] = array($TPL["companyContactAddress2"]); $TPL["companyContactAddress3"] and $contact_info[] = array($TPL["companyContactAddress3"]); $TPL["companyContactEmail"] and $contact_info[] = array($TPL["companyContactEmail"]); $TPL["companyContactHomePage"] and $contact_info[] = array($TPL["companyContactHomePage"]); $TPL["phone"] and $contact_info[] = array($TPL["phone"]); $TPL["fax"] and $contact_info[] = array($TPL["fax"]); $pdf->selectFont($font2); $y = $pdf->ezTable($contact_info, false, "", $pdf_table_options); $pdf->selectFont($font1); $line_y = $y - 10; $pdf->setLineStyle(1, "round"); $pdf->line(90, $line_y, 510, $line_y); $pdf->ezSetY(782); $image_jpg = ALLOC_LOGO; if (file_exists($image_jpg)) { $pdf->ezImage($image_jpg, 0, sprintf("%d", config::get_config_item("logoScaleX")), 'none'); $y = 700; } else { $y = $pdf->ezText($TPL["companyName"], 27, array("justification" => "right")); } $nos_y = $line_y + 22; $TPL["companyNos2"] and $nos_y = $line_y + 34; $pdf->ezSetY($nos_y); $TPL["companyNos1"] and $y = $pdf->ezText($TPL["companyNos1"], 10, array("justification" => "right")); $TPL["companyNos2"] and $y = $pdf->ezText($TPL["companyNos2"], 10, array("justification" => "right")); $pdf->ezSetY($line_y - 20); $y = $pdf->ezText($default_header, 20, array("justification" => "center")); $pdf->ezSetY($y - 20); $ts_info[] = array("one" => "<b>" . $default_id_label . ":</b>", "two" => $TPL["timeSheetID"], "three" => "<b>Date Issued:</b>", "four" => date("d/m/Y")); $ts_info[] = array("one" => "<b>Client:</b>", "two" => $TPL["clientName"], "three" => "<b>Project:</b>", "four" => $TPL["timeSheet_projectName"]); $ts_info[] = array("one" => "<b>" . $default_contractor_label . ":</b>", "two" => $TPL["timeSheet_personName"], "three" => "<b>Billing Period:</b>", "four" => $TPL["period"]); if ($timeSheetPrintMode == "estimate") { // This line needs to be glued to the above line $temp = array_pop($ts_info); $temp["three"] = ""; // Nuke Billing Period for the Estimate version of the pdf. $temp["four"] = ""; // Nuke Billing Period for the Estimate version of the pdf. $ts_info[] = $temp; } $y = $pdf->ezTable($ts_info, $cols, "", $pdf_table_options2); $pdf->ezSetY($y - 20); if ($timeSheetPrintMode == "money" || $timeSheetPrintMode == "estimate") { list($rows, $info) = $this->get_timeSheetItem_list_money($TPL["timeSheetID"]); $cols2 = array("desc" => "Description", "units" => "Units", "money" => "Charges", "gst" => $TPL["taxName"]); $taxPercent = config::get_config_item("taxPercent"); if ($taxPercent === '') { unset($cols2["gst"]); } $rows[] = array("desc" => "<b>TOTAL</b>", "units" => $info["total_units"], "money" => $info["total"], "gst" => $info["total_gst"]); $y = $pdf->ezTable($rows, $cols2, "", $pdf_table_options3); $pdf->ezSetY($y - 20); if ($taxPercent !== '') { $totals[] = array("one" => "TOTAL " . $TPL["taxName"], "two" => $info["total_gst"]); } $totals[] = array("one" => "TOTAL CHARGES", "two" => $info["total"]); $totals[] = array("one" => "<b>" . $default_total_label . "</b>", "two" => "<b>" . $info["total_inc_gst"] . "</b>"); $y = $pdf->ezTable($totals, $cols3, "", $pdf_table_options4); } else { if ($timeSheetPrintMode == "units") { list($rows, $info) = $this->get_timeSheetItem_list_units($TPL["timeSheetID"]); $cols2 = array("desc" => "Description", "units" => "Units"); $rows[] = array("desc" => "<b>TOTAL</b>", "units" => "<b>" . $info["total"] . "</b>"); $y = $pdf->ezTable($rows, $cols2, "", $pdf_table_options3); } else { if ($timeSheetPrintMode == "items") { list($rows, $info) = $this->get_timeSheetItem_list_items($TPL["timeSheetID"]); $cols2 = array("date" => "Date", "units" => "Units", "multiplier_string" => "Multiplier", "desc" => "Description"); $rows[] = array("date" => "<b>TOTAL</b>", "units" => "<b>" . $info["total"] . "</b>"); $y = $pdf->ezTable($rows, $cols2, "", $pdf_table_options3); } } } $pdf->ezSetY($y - 20); $pdf->ezText(str_replace(array("<br>", "<br/>", "<br />"), "\n", $TPL["footer"]), 10); $pdf->ezStream(array("Content-Disposition" => "timeSheet_" . $timeSheetID . ".pdf")); // Else HTML format } else { if (file_exists(ALLOC_LOGO)) { $TPL["companyName"] = '<img alt="Company logo" src="' . $TPL["url_alloc_logo"] . '" />'; } $TPL["this_tsp"] = $this; $TPL["main_alloc_title"] = "Time Sheet - " . APPLICATION_NAME; include_template(dirname(__FILE__) . "/../templates/timeSheetPrintM.tpl"); } } }