예제 #1
0
function show_new_timeSheet($template)
{
    global $TPL;
    global $timeSheet;
    global $timeSheetID;
    $current_user =& singleton("current_user");
    // Don't show entry form for new timeSheet.
    if (!$timeSheetID) {
        return;
    }
    if (is_object($timeSheet) && ($timeSheet->get_value("status") == 'edit' || $timeSheet->get_value("status") == 'rejected') && ($timeSheet->get_value("personID") == $current_user->get_id() || $timeSheet->have_perm(PERM_TIME_INVOICE_TIMESHEETS))) {
        $TPL["currency"] = page::money($timeSheet->get_value("currencyTypeID"), '', "%S");
        // If we are editing an existing timeSheetItem
        $timeSheetItem_edit = $_POST["timeSheetItem_edit"] or $timeSheetItem_edit = $_GET["timeSheetItem_edit"];
        $timeSheetItemID = $_POST["timeSheetItemID"] or $timeSheetItemID = $_GET["timeSheetItemID"];
        if ($timeSheetItemID && $timeSheetItem_edit) {
            $timeSheetItem = new timeSheetItem();
            $timeSheetItem->currency = $timeSheet->get_value("currencyTypeID");
            $timeSheetItem->set_id($timeSheetItemID);
            $timeSheetItem->select();
            $timeSheetItem->set_values("tsi_");
            $TPL["tsi_rate"] = $timeSheetItem->get_value("rate", DST_HTML_DISPLAY);
            $taskID = $timeSheetItem->get_value("taskID");
            $TPL["tsi_buttons"] = '
         <button type="submit" name="timeSheetItem_delete" value="1" class="delete_button">Delete<i class="icon-trash"></i></button>
         <button type="submit" name="timeSheetItem_save" value="1" class="save_button default">Save Item<i class="icon-ok-sign"></i></button>
         ';
            $timeSheetItemDurationUnitID = $timeSheetItem->get_value("timeSheetItemDurationUnitID");
            $TPL["tsi_commentPrivate"] and $TPL["commentPrivateChecked"] = " checked";
            $TPL["ts_rate_editable"] = $timeSheet->can_edit_rate();
            $timeSheetItemMultiplier = $timeSheetItem->get_value("multiplier");
            // Else default values for creating a new timeSheetItem
        } else {
            $TPL["tsi_buttons"] = '<button type="submit" name="timeSheetItem_save" value="1" class="save_button">Add Item<i class="icon-plus-sign"></i></button>';
            $TPL["tsi_personID"] = $current_user->get_id();
            $timeSheet->load_pay_info();
            $TPL["tsi_rate"] = $timeSheet->pay_info["project_rate"];
            $timeSheetItemDurationUnitID = $timeSheet->pay_info["project_rateUnitID"];
            $TPL["ts_rate_editable"] = $timeSheet->can_edit_rate();
        }
        $taskID or $taskID = $_GET["taskID"];
        $TPL["taskListDropdown_taskID"] = $taskID;
        $TPL["taskListDropdown"] = $timeSheet->get_task_list_dropdown("mine", $timeSheet->get_id(), $taskID);
        $TPL["tsi_timeSheetID"] = $timeSheet->get_id();
        $timeUnit = new timeUnit();
        $unit_array = $timeUnit->get_assoc_array("timeUnitID", "timeUnitLabelA");
        $TPL["tsi_unit_options"] = page::select_options($unit_array, $timeSheetItemDurationUnitID);
        $timeSheetItemDurationUnitID and $TPL["tsi_unit_label"] = $unit_array[$timeSheetItemDurationUnitID];
        $m = new meta("timeSheetItemMultiplier");
        $tsMultipliers = $m->get_list();
        foreach ($tsMultipliers as $k => $v) {
            $multiplier_array[$k] = $v["timeSheetItemMultiplierName"];
        }
        $TPL["tsi_multiplier_options"] = page::select_options($multiplier_array, $timeSheetItemMultiplier);
        include_template($template);
    }
}
예제 #2
0
 * along with allocPSA. If not, see <http://www.gnu.org/licenses/>.
*/
require_once "../alloc.php";
if (!$current_user->is_employee()) {
    alloc_error("You do not have permission to access time sheets", true);
}
$timeSheetID = $_POST["timeSheetID"];
$timeSheetItemID = $_POST["timeSheetItem_timeSheetItemID"];
if (($_POST["timeSheetItem_save"] || $_POST["timeSheetItem_edit"] || $_POST["timeSheetItem_delete"]) && $timeSheetID) {
    $timeSheet = new timeSheet();
    $timeSheet->set_id($timeSheetID);
    $timeSheet->select();
    $timeSheet->load_pay_info();
    $timeSheetItem = new timeSheetItem();
    if ($timeSheetItemID) {
        $timeSheetItem->set_id($timeSheetItemID);
        $timeSheetItem->select();
    }
    $timeSheetItem->read_globals();
    $timeSheetItem->read_globals("timeSheetItem_");
    if ($_POST["timeSheetItem_save"]) {
        $timeSheetItem->read_globals();
        $timeSheetItem->read_globals("timeSheetItem_");
        $rtn = $timeSheetItem->save();
        $rtn and $TPL["message_good"][] = "Time Sheet Item saved.";
        $_POST["timeSheetItem_taskID"] and $t = "&taskID=" . $_POST["timeSheetItem_taskID"];
        alloc_redirect($TPL["url_alloc_timeSheet"] . "timeSheetID=" . $timeSheetID . $t);
    } else {
        if ($_POST["timeSheetItem_edit"]) {
            alloc_redirect($TPL["url_alloc_timeSheet"] . "timeSheetID=" . $timeSheetID . "&timeSheetItem_edit=true&timeSheetItemID=" . $timeSheetItem->get_id());
        } else {
예제 #3
0
 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.");
     }
 }
예제 #4
0
 function edit_timeSheetItem($commands)
 {
     $item_fields = $this->get_fields("item");
     // Time Sheet Item commands
     if ($commands["item"]) {
         $timeSheetItem = new timeSheetItem();
         if ($commands["item"] && strtolower($commands["item"] != "new")) {
             $timeSheetItem->set_id($commands["item"]);
             if (!$timeSheetItem->select()) {
                 alloc_error("Unable to select time sheet item with ID: " . $commands["item"]);
             }
         }
         $timeSheet = $timeSheetItem->get_foreign_object("timeSheet");
         $timeSheetItem->currency = $timeSheet->get_value("currencyTypeID");
         $timeSheetItem->set_value("rate", $timeSheetItem->get_value("rate", DST_HTML_DISPLAY));
         foreach ($commands as $k => $v) {
             // Validate/coerce the fields
             if ($k == "unit") {
                 $changes[$k] = "timeSheetItemDurationUnitID";
                 in_array($v, array(1, 2, 3, 4, 5)) or $err[] = "Invalid unit. Try a number from 1-5.";
             } else {
                 if ($k == "task") {
                     $changes[$k] = "taskID";
                     $t = new task();
                     $t->set_id($v);
                     $t->select();
                     is_object($timeSheet) && $timeSheet->get_id() && $t->get_value("projectID") != $timeSheet->get_value("projectID") and $err[] = "Invalid task. Task belongs to different project.";
                 }
             }
             // Plug the value in
             if ($item_fields[$k][0]) {
                 $changes[$k] = $item_fields[$k][0];
                 $timeSheetItem->set_value($item_fields[$k][0], sprintf("%s", $v));
             }
         }
         $after_label2 = "After:  ";
         if (strtolower($commands["item"]) != "new") {
             $str = $this->condense_changes($changes, $timeSheetItem->row());
             $str and $status[] = "msg";
             $str and $message[] = "Before: " . $str;
         } else {
             $after_label2 = "Fields: ";
         }
         if ($commands["delete"]) {
             $id = $timeSheetItem->get_id();
             $timeSheetItem->delete();
             $status[] = "yay";
             $message[] = "Time sheet item " . $id . " deleted.";
             // Save timeSheetItem
         } else {
             if (!$err && $commands["item"] && $timeSheetItem->save()) {
                 $timeSheetItem->select();
                 $str = $this->condense_changes($changes, $timeSheetItem->row());
                 $str and $status[] = "msg";
                 $str and $message[] = $after_label2 . $str;
                 $status[] = "yay";
                 if (strtolower($commands["item"]) == "new") {
                     $message[] = "Time sheet item " . $timeSheetItem->get_id() . " created.";
                 } else {
                     $message[] = "Time sheet item " . $timeSheetItem->get_id() . " updated.";
                 }
                 // Problems
             } else {
                 if ($err && $commands["item"]) {
                     alloc_error("Problem updating time sheet item: " . implode("\n", (array) $err));
                 }
             }
         }
     }
     return array($status, $message);
 }