global $TPL; $timeSheetID = $_POST["timeSheetID"] or $timeSheetID = $_GET["timeSheetID"]; $db = new db_alloc(); $timeSheet = new timeSheet(); if ($timeSheetID) { $timeSheet = new timeSheet(); $timeSheet->set_id($timeSheetID); $timeSheet->select(); $timeSheet->set_values(); } // Manually update the Client Billing field if ($_REQUEST["updateCB"] && $timeSheet->get_id() && $timeSheet->can_edit_rate()) { $project = new project(); $project->set_id($timeSheet->get_value("projectID")); $project->select(); $timeSheet->set_value("customerBilledDollars", page::money($project->get_value("currencyTypeID"), $project->get_value("customerBilledDollars"), "%mo")); $timeSheet->set_value("currencyTypeID", $project->get_value("currencyTypeID")); $timeSheet->save(); } // Manually update the person's rate if ($_REQUEST["updateRate"] && $timeSheet->get_id() && $timeSheet->can_edit_rate()) { $row_projectPerson = projectPerson::get_projectPerson_row($timeSheet->get_value("projectID"), $timeSheet->get_value("personID")); if (!$row_projectPerson) { alloc_error("The person has not been added to the project."); } else { $q = prepare("SELECT timeSheetItemID from timeSheetItem WHERE timeSheetID = %d", $timeSheet->get_id()); $db = new db_alloc(); $db->query($q); while ($row = $db->row()) { $tsi = new timeSheetItem(); $tsi->set_id($row["timeSheetItemID"]);
function add_timeSheetItem($stuff) { $current_user =& singleton("current_user"); $errstr = "Failed to record new time sheet item. "; $taskID = $stuff["taskID"]; $projectID = $stuff["projectID"]; $duration = $stuff["duration"]; $comment = $stuff["comment"]; $emailUID = $stuff["msg_uid"]; $emailMessageID = $stuff["msg_id"]; $date = $stuff["date"]; $unit = $stuff["unit"]; $multiplier = $stuff["multiplier"]; if ($taskID) { $task = new task(); $task->set_id($taskID); $task->select(); $projectID = $task->get_value("projectID"); $extra = " for task " . $taskID; } $projectID or alloc_error(sprintf($errstr . "No project found%s.", $extra)); $row_projectPerson = projectPerson::get_projectPerson_row($projectID, $current_user->get_id()); $row_projectPerson or alloc_error($errstr . "The person(" . $current_user->get_id() . ") has not been added to the project(" . $projectID . ")."); if ($row_projectPerson && $projectID) { if ($stuff["timeSheetID"]) { $q = prepare("SELECT *\n FROM timeSheet\n WHERE status = 'edit'\n AND personID = %d\n AND timeSheetID = %d\n ORDER BY dateFrom\n LIMIT 1\n ", $current_user->get_id(), $stuff["timeSheetID"]); $db = new db_alloc(); $db->query($q); $row = $db->row(); $row or alloc_error("Couldn't find an editable time sheet with that ID."); } else { $q = prepare("SELECT *\n FROM timeSheet\n WHERE status = 'edit'\n AND projectID = %d\n AND personID = %d\n ORDER BY dateFrom\n LIMIT 1\n ", $projectID, $current_user->get_id()); $db = new db_alloc(); $db->query($q); $row = $db->row(); } // If no timeSheets add a new one if (!$row) { $project = new project(); $project->set_id($projectID); $project->select(); $timeSheet = new timeSheet(); $timeSheet->set_value("projectID", $projectID); $timeSheet->set_value("status", "edit"); $timeSheet->set_value("personID", $current_user->get_id()); $timeSheet->set_value("recipient_tfID", $current_user->get_value("preferred_tfID")); $timeSheet->set_value("customerBilledDollars", page::money($project->get_value("currencyTypeID"), $project->get_value("customerBilledDollars"), "%mo")); $timeSheet->set_value("currencyTypeID", $project->get_value("currencyTypeID")); $timeSheet->save(); $timeSheetID = $timeSheet->get_id(); // Else use the first timesheet we found } else { $timeSheetID = $row["timeSheetID"]; } $timeSheetID or alloc_error($errstr . "Couldn't locate an existing, or create a new Time Sheet."); // Add new time sheet item if ($timeSheetID) { $timeSheet = new timeSheet(); $timeSheet->set_id($timeSheetID); $timeSheet->select(); $tsi = new timeSheetItem(); $tsi->currency = $timeSheet->get_value("currencyTypeID"); $tsi->set_value("timeSheetID", $timeSheetID); $d = $date or $d = date("Y-m-d"); $tsi->set_value("dateTimeSheetItem", $d); $tsi->set_value("timeSheetItemDuration", $duration); $tsi->set_value("timeSheetItemDurationUnitID", $unit); if (is_object($task)) { $tsi->set_value("description", $task->get_name()); $tsi->set_value("taskID", sprintf("%d", $taskID)); $_POST["timeSheetItem_taskID"] = sprintf("%d", $taskID); // this gets used in timeSheetItem->save(); } $tsi->set_value("personID", $current_user->get_id()); $tsi->set_value("rate", page::money($timeSheet->get_value("currencyTypeID"), $row_projectPerson["rate"], "%mo")); $tsi->set_value("multiplier", $multiplier); $tsi->set_value("comment", $comment); $tsi->set_value("emailUID", $emailUID); $tsi->set_value("emailMessageID", $emailMessageID); $tsi->save(); $id = $tsi->get_id(); $tsi = new timeSheetItem(); $tsi->set_id($id); $tsi->select(); $ID = $tsi->get_value("timeSheetID"); } } if ($ID) { return array("status" => "yay", "message" => $ID); } else { alloc_error($errstr . "Time not added."); } }