Beispiel #1
0
        $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"]);
            $tsi->select();
            if ($row_projectPerson["rateUnitID"]) {
                $v = $row_projectPerson["rateUnitID"];
            } else {
                $v = "";
            }
            $tsi->set_value("timeSheetItemDurationUnitID", $v);
            $tsi->set_value("rate", page::money($timeSheet->get_value("currencyTypeID"), $row_projectPerson["rate"], "%mo"));
            $tsi->skip_tsi_status_check = true;
            $tsi->save();
        }
    }
}
if ($_POST["save"] || $_POST["save_and_new"] || $_POST["save_and_returnToList"] || $_POST["save_and_returnToProject"] || $_POST["save_and_MoveForward"] || $_POST["save_and_MoveBack"]) {
    // Saving a record
    $timeSheet->read_globals();
    $timeSheet->read_globals("timeSheet_");
    $projectID = $timeSheet->get_value("projectID");
    if ($projectID != 0) {
        $project = new project();
        $project->set_id($projectID);
        $project->select();
        $projectManagers = $project->get_timeSheetRecipients();
        if (!$timeSheet->get_id()) {
            $timeSheet->set_value("customerBilledDollars", page::money($project->get_value("currencyTypeID"), $project->get_value("customerBilledDollars"), "%mo"));
Beispiel #2
0
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 {
            if ($_POST["timeSheetItem_delete"]) {
                $timeSheetItem->select();
                $timeSheetItem->delete();
                $TPL["message_good"][] = "Time Sheet Item deleted.";
                alloc_redirect($TPL["url_alloc_timeSheet"] . "timeSheetID=" . $timeSheetID);
            }
        }
    }
Beispiel #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.");
     }
 }
Beispiel #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);
 }