Exemple #1
0
function show_timeSheetItems($template_name)
{
    global $date_to_view;
    $current_user =& singleton("current_user");
    global $TPL;
    $query = prepare("SELECT * \n                      FROM timeSheetItem \n                           LEFT JOIN timeSheet ON timeSheetItem.timeSheetID = timeSheet.timeSheetID\n                           LEFT JOIN project ON timeSheet.projectID = project.projectID\n                      WHERE dateTimeSheetItem='%s'\n                            AND timeSheet.personID=%d", date("Y-m-d", $date_to_view), $current_user->get_id());
    $db = new db_alloc();
    $db->query($query);
    while ($db->next_record()) {
        $timeSheetItem = new timeSheetItem();
        $timeSheetItem->read_db_record($db);
        $timeSheetItem->set_values();
        if ($timeSheetItem->get_value("unit") == "Hour") {
            $TPL["daily_hours_total"] += $timeSheetItem->get_value("timeSheetItemDuration");
        }
        $project = new project();
        $project->read_db_record($db);
        $project->set_values();
        if ($project->get_value("projectShortName")) {
            $TPL["item_description"] = $project->get_value("projectShortName");
        } else {
            $TPL["item_description"] = $project->get_value("projectName");
        }
        include_template($template_name);
    }
}
Exemple #2
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);
    }
}
Exemple #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.");
     }
 }
 function get_timeSheetItem_list_items($timeSheetID)
 {
     global $TPL;
     list($db, $customerBilledDollars, $timeSheet, $unit_array, $currency) = $this->get_timeSheetItem_vars($timeSheetID);
     $m = new meta("timeSheetItemMultiplier");
     $multipliers = $m->get_list();
     while ($db->next_record()) {
         $timeSheetItem = new timeSheetItem();
         $timeSheetItem->read_db_record($db);
         $row_num++;
         $taskID = sprintf("%d", $timeSheetItem->get_value("taskID"));
         $num = sprintf("%0.2f", $timeSheetItem->get_value("timeSheetItemDuration"));
         $info["total"] += $num;
         $rows[$row_num]["date"] = $timeSheetItem->get_value("dateTimeSheetItem");
         $rows[$row_num]["units"] = $num . " " . $unit_array[$timeSheetItem->get_value("timeSheetItemDurationUnitID")];
         $rows[$row_num]["multiplier_string"] = $multipliers[$timeSheetItem->get_value("multiplier")]["timeSheetItemMultiplierName"];
         unset($str);
         $d = $timeSheetItem->get_value('taskID', DST_HTML_DISPLAY) . ": " . $timeSheetItem->get_value('description', DST_HTML_DISPLAY);
         $d && !$rows[$row_num]["desc"] and $str[] = "<b>" . $d . "</b>";
         // 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[$row_num]["desc"] .= trim(implode(DEFAULT_SEP, $str));
     }
     $timeSheet->load_pay_info();
     $info["total"] = $timeSheet->pay_info["summary_unit_totals"];
     $rows or $rows = array();
     $info or $info = array();
     return array($rows, $info);
 }
 public static function get_list($_FORM)
 {
     /*
      * This is the definitive method of getting a list of timeSheetItems that need a sophisticated level of filtering
      *
      */
     global $TPL;
     $filter = timeSheetItem::get_list_filter($_FORM);
     $debug = $_FORM["debug"];
     $debug and print "<pre>_FORM: " . print_r($_FORM, 1) . "</pre>";
     $debug and print "<pre>filter: " . print_r($filter, 1) . "</pre>";
     $_FORM["return"] or $_FORM["return"] = "html";
     if (is_array($filter) && count($filter)) {
         $filter = " WHERE " . implode(" AND ", $filter);
     }
     $q = "SELECT * FROM timeSheetItem\n       LEFT JOIN timeSheet ON timeSheet.timeSheetID = timeSheetItem.timeSheetID\n                 " . $filter . "\n        ORDER BY timeSheet.timeSheetID,dateTimeSheetItem asc";
     $debug and print "Query: " . $q;
     $db = new db_alloc();
     $db->query($q);
     while ($row = $db->next_record()) {
         $print = true;
         $t = new timeSheet();
         $t->read_db_record($db);
         $tsi = new timeSheetItem();
         $tsi->read_db_record($db);
         $tsi->currency = $t->get_value("currencyTypeID");
         $row["secondsBilled"] = $row["hoursBilled"] = $row["timeLimit"] = $row["limitWarning"] = "";
         # set these for the CLI
         if ($tsi->get_value("taskID")) {
             $task = $tsi->get_foreign_object('task');
             $row["secondsBilled"] = $task->get_time_billed();
             $row["hoursBilled"] = sprintf("%0.2f", $row["secondsBilled"] / 60 / 60);
             $task->get_value('timeLimit') && $row["hoursBilled"] > $task->get_value('timeLimit') and $row["limitWarning"] = 'Exceeds Limit!';
             $row["timeLimit"] = $task->get_value("timeLimit");
         }
         $row["rate"] = $tsi->get_value("rate", DST_HTML_DISPLAY);
         $row["worth"] = page::money($tsi->currency, $row["rate"] * $tsi->get_value("multiplier") * $tsi->get_value("timeSheetItemDuration"), "%m");
         $rows[$row["timeSheetItemID"]] = $row;
     }
     if ($print && $_FORM["return"] == "array") {
         return $rows;
     }
 }
Exemple #6
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);
 }