Esempio n. 1
0
 function get_timeSheetItem_vars($timeSheetID)
 {
     $timeSheet = new timeSheet();
     $timeSheet->set_id($timeSheetID);
     $timeSheet->select();
     $timeUnit = new timeUnit();
     $unit_array = $timeUnit->get_assoc_array("timeUnitID", "timeUnitLabelA");
     $q = prepare("SELECT * from timeSheetItem WHERE timeSheetID=%d ", $timeSheetID);
     $q .= prepare("GROUP BY timeSheetItemID ORDER BY dateTimeSheetItem, timeSheetItemID");
     $db = new db_alloc();
     $db->query($q);
     $customerBilledDollars = $timeSheet->get_value("customerBilledDollars");
     $currency = page::money($timeSheet->get_value("currencyTypeID"), '', "%S");
     return array($db, $customerBilledDollars, $timeSheet, $unit_array, $currency);
 }
Esempio n. 2
0
 * your option) any later version.
 * 
 * allocPSA is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with allocPSA. If not, see <http://www.gnu.org/licenses/>.
*/
define("NO_REDIRECT", 1);
require_once "../alloc.php";
//usleep(1000);
$t = timeSheetItem::parse_time_string($_REQUEST["time_item"]);
$timeUnit = new timeUnit();
$units = $timeUnit->get_assoc_array("timeUnitID", "timeUnitLabelA");
$timeSheetItemMultiplier = new meta("timeSheetItemMultiplier");
$tsims = $timeSheetItemMultiplier->get_list();
foreach ($t as $k => $v) {
    if ($v) {
        if ($k == "taskID") {
            $task = new task();
            $task->set_id($v);
            if ($task->select()) {
                $v = $task->get_id() . " " . $task->get_link();
            } else {
                $v = "Task " . $v . " not found.";
            }
        } else {
            if ($k == "unit") {
                $v = $units[$v];
Esempio n. 3
0
$people =& get_cached_table("person");
foreach ($people as $p) {
    $peeps[$p["personID"]] = $p["name"];
}
// get the default time sheet manager/admin options
$TPL["defaultTimeSheetManagerListText"] = get_person_list(config::get_config_item("defaultTimeSheetManagerList"));
$TPL["defaultTimeSheetAdminListText"] = get_person_list(config::get_config_item("defaultTimeSheetAdminList"));
$days = array("Sun" => "Sun", "Mon" => "Mon", "Tue" => "Tue", "Wed" => "Wed", "Thu" => "Thu", "Fri" => "Fri", "Sat" => "Sat");
$TPL["calendarFirstDayOptions"] = page::select_options($days, config::get_config_item("calendarFirstDay"));
$TPL["timeSheetPrintOptions"] = page::select_options($TPL["timeSheetPrintOptions"], $TPL["timeSheetPrint"]);
$commentTemplate = new commentTemplate();
$ops = $commentTemplate->get_assoc_array("commentTemplateID", "commentTemplateName");
$TPL["rssStatusFilterOptions"] = page::select_options(task::get_task_statii_array(true), config::get_config_item("rssStatusFilter"));
if (has("timeUnit")) {
    $timeUnit = new timeUnit();
    $rate_type_array = $timeUnit->get_assoc_array("timeUnitID", "timeUnitLabelB");
}
$TPL["timesheetRate_options"] = page::select_options($rate_type_array, config::get_config_item("defaultTimeSheetUnit"));
$TPL["main_alloc_title"] = "Setup - " . APPLICATION_NAME;
include_template("templates/configM.tpl");
function get_person_list($personID_array)
{
    global $peeps;
    $people = array();
    foreach ($personID_array as $personID) {
        $people[] = $peeps[$personID];
    }
    if (count($people) > 0) {
        return implode(", ", $people);
    } else {
        return "<i>none</i>";
Esempio n. 4
0
 function adjust_by_email_subject($email_receive, $e)
 {
     $current_user =& singleton("current_user");
     $entity = $e->classname;
     $entityID = $e->get_id();
     $subject = trim($email_receive->mail_headers["subject"]);
     $body = $email_receive->get_converted_encoding();
     $msg_uid = $email_receive->msg_uid;
     list($emailAddress, $fullName) = parse_email_address($email_receive->mail_headers["from"]);
     list($personID, $clientContactID, $fullName) = comment::get_person_and_client($emailAddress, $fullName, $e->get_project_id());
     // Load up the parent object that this comment refers to, be it task or timeSheet etc
     if ($entity == "comment" && $entityID) {
         $c = new comment();
         $c->set_id($entityID);
         $c->select();
         $object = $c->get_parent_object();
     } else {
         if (class_exists($entity) && $entityID) {
             $object = new $entity();
             $object->set_id($entityID);
             $object->select();
         }
     }
     // If we're doing subject line magic, then we're only going to do it with
     // subject lines that have a {Key:fdsFFeSD} in them.
     preg_match("/\\{Key:[A-Za-z0-9]{8}\\}(.*)\\s*\$/i", $subject, $m);
     $commands = explode(" ", trim($m[1]));
     foreach ((array) $commands as $command) {
         $command = strtolower($command);
         list($command, $command2) = explode(":", $command);
         // for eg: duplicate:1234
         // If "quiet" in the subject line, then the email/comment won't be re-emailed out again
         if ($command == "quiet") {
             $quiet = true;
             // To unsubscribe from this conversation
         } else {
             if ($command == "unsub" || $command == "unsubscribe") {
                 if (interestedParty::active($entity, $entityID, $emailAddress)) {
                     interestedParty::delete_interested_party($entity, $entityID, $emailAddress);
                 }
                 // To subscribe to this conversation
             } else {
                 if ($command == "sub" || $command == "subscribe") {
                     $ip = interestedParty::exists($entity, $entityID, $emailAddress);
                     if (!$ip) {
                         $data = array("entity" => $entity, "entityID" => $entityID, "fullName" => $fullName, "emailAddress" => $emailAddress, "personID" => $personID, "clientContactID" => $clientContactID);
                         interestedParty::add_interested_party($data);
                         // Else reactivate existing IP
                     } else {
                         if (!interestedParty::active($entity, $entityID, $emailAddress)) {
                             $interestedParty = new interestedParty();
                             $interestedParty->set_id($ip["interestedPartyID"]);
                             $interestedParty->select();
                             $interestedParty->set_value("interestedPartyActive", 1);
                             $interestedParty->save();
                         }
                     }
                     // If there's a number/duration then add some time to a time sheet
                 } else {
                     if (is_object($current_user) && $current_user->get_id() && preg_match("/([\\.\\d]+)/i", $command, $m)) {
                         $duration = $m[1];
                         if (is_numeric($duration)) {
                             if (is_object($object) && $object->classname == "task" && $object->get_id() && $current_user->get_id()) {
                                 $timeSheet = new timeSheet();
                                 $tsi_row = $timeSheet->add_timeSheetItem(array("taskID" => $object->get_id(), "duration" => $duration, "comment" => $body, "msg_uid" => $msg_uid, "msg_id" => $email_receive->mail_headers["message-id"], "multiplier" => 1));
                                 $timeUnit = new timeUnit();
                                 $units = $timeUnit->get_assoc_array("timeUnitID", "timeUnitLabelA");
                                 $unitLabel = $units[$tsi_row["timeSheetItemDurationUnitID"]];
                             }
                         }
                         // Otherwise assume it's a status change
                     } else {
                         if (is_object($current_user) && $current_user->get_id() && $command) {
                             if (is_object($object) && $object->get_id()) {
                                 $object->set_value("taskStatus", $command);
                                 if ($command2 && preg_match("/dup/i", $command)) {
                                     $object->set_value("duplicateTaskID", $command2);
                                 } else {
                                     if ($command2 && preg_match("/tasks/i", $command)) {
                                         $object->add_pending_tasks($command2);
                                     }
                                 }
                                 $object->save();
                             }
                         }
                     }
                 }
             }
         }
     }
     return $quiet;
 }
Esempio n. 5
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);
    }
}
Esempio n. 6
0
 function load_pay_info()
 {
     /***************************************************************************
      *                                                                         *
      * load_pay_info() loads these vars:                                       *
      * $this->pay_info["project_rate"];	    according to projectPerson table   *
      * $this->pay_info["project_rate_orig"];before the currency transform      *
      * $this->pay_info["timeSheetItem_rate"];according to timeSheetItem table  *
      * $this->pay_info["customerBilledDollars"];                               *
      * $this->pay_info["project_rateUnitID"];	according to projectPerson table *
      * $this->pay_info["duration"][time sheet ITEM ID];                        *
      * $this->pay_info["total_duration"]; of a timesheet                       *
      * $this->pay_info["total_dollars"];  of a timesheet                       *
      * $this->pay_info["total_customerBilledDollars"]                          *
      * $this->pay_info["total_dollars_minus_gst"]                              *
      * $this->pay_info["total_customerBilledDollars_minus_gst"]                *
      * $this->pay_info["unit"]                                                 *
      * $this->pay_info["summary_unit_totals"]                                  *
      * $this->pay_info["total_dollars_not_null"] tot_custbilled/tot_dollars    *
      * $this->pay_info["currency"]; according to timeSheet table               *
      *                                                                         *
      ***************************************************************************/
     static $rates;
     unset($this->pay_info);
     $db = new db_alloc();
     if (!$this->get_value("projectID") || !$this->get_value("personID")) {
         return false;
     }
     $currency = $this->get_value("currencyTypeID");
     // The unit labels
     $timeUnit = new timeUnit();
     $units = array_reverse($timeUnit->get_assoc_array("timeUnitID", "timeUnitLabelA"), true);
     if ($rates[$this->get_value("projectID")][$this->get_value("personID")]) {
         list($this->pay_info["project_rate"], $this->pay_info["project_rateUnitID"]) = $rates[$this->get_value("projectID")][$this->get_value("personID")];
     } else {
         // Get rate for person for this particular project
         $db->query("SELECT rate, rateUnitID, project.currencyTypeID\n                    FROM projectPerson\n               LEFT JOIN project on projectPerson.projectID = project.projectID\n                   WHERE projectPerson.projectID = %d\n                     AND projectPerson.personID = %d", $this->get_value("projectID"), $this->get_value("personID"));
         $db->next_record();
         $this->pay_info["project_rate"] = page::money($db->f("currencyTypeID"), $db->f("rate"), "%mo");
         $this->pay_info["project_rateUnitID"] = $db->f("rateUnitID");
         $rates[$this->get_value("projectID")][$this->get_value("personID")] = array($this->pay_info["project_rate"], $this->pay_info["project_rateUnitID"]);
     }
     // Get external rate, only load up customerBilledDollars if the field is actually set
     if (imp($this->get_value("customerBilledDollars"))) {
         $this->pay_info["customerBilledDollars"] = page::money($currency, $this->get_value("customerBilledDollars"), "%mo");
     }
     $q = "SELECT * FROM timeUnit ORDER BY timeUnitSequence DESC";
     $db->query($q);
     while ($row = $db->row()) {
         if ($row["timeUnitSeconds"]) {
             $extra_sql[] = "SUM(IF(timeUnit.timeUnitLabelA = '" . $row["timeUnitLabelA"] . "',multiplier * timeSheetItemDuration * timeUnit.timeUnitSeconds,0)) /" . $row["timeUnitSeconds"] . " as " . $row["timeUnitLabelA"];
         }
         $timeUnitRows[] = $row;
     }
     $extra_sql and $sql = "," . implode("\n,", $extra_sql);
     // Get duration for this timesheet/timeSheetItems
     $db->query(prepare("SELECT SUM(timeSheetItemDuration) AS total_duration, \n                               SUM((timeSheetItemDuration * timeUnit.timeUnitSeconds) / 3600) AS total_duration_hours,\n                               SUM((rate * pow(10,-currencyType.numberToBasic)) * timeSheetItemDuration * multiplier) AS total_dollars,\n                               SUM((IFNULL(timeSheet.customerBilledDollars,0) * pow(10,-currencyType.numberToBasic)) * timeSheetItemDuration * multiplier) AS total_customerBilledDollars\n                               " . $sql . "\n                          FROM timeSheetItem\n                     LEFT JOIN timeUnit ON timeUnit.timeUnitID = timeSheetItem.timeSheetItemDurationUnitID\n                     LEFT JOIN timeSheet on timeSheet.timeSheetID = timeSheetItem.timeSheetID\n                     LEFT JOIN currencyType on currencyType.currencyTypeID = timeSheet.currencyTypeID\n                         WHERE timeSheetItem.timeSheetID = %d", $this->get_id()));
     $row = $db->row();
     $this->pay_info = array_merge((array) $this->pay_info, (array) $row);
     $this->pay_info["total_customerBilledDollars"] = page::money($currency, $this->pay_info["total_customerBilledDollars"], "%m");
     $this->pay_info["total_dollars"] = page::money($currency, $this->pay_info["total_dollars"], "%m");
     unset($commar);
     foreach ((array) $timeUnitRows as $r) {
         if ($row[$r["timeUnitLabelA"]] != 0) {
             $this->pay_info["summary_unit_totals"] .= $commar . ($row[$r["timeUnitLabelA"]] + 0) . " " . $r["timeUnitLabelA"];
             $commar = ", ";
         }
     }
     if (!isset($this->pay_info["total_dollars"])) {
         $this->pay_info["total_dollars"] = 0;
     }
     if (!isset($this->pay_info["total_duration"])) {
         $this->pay_info["total_duration"] = 0;
     }
     if (!isset($this->pay_info["total_duration_hours"])) {
         $this->pay_info["total_duration_hours"] = 0;
     }
     $taxPercent = config::get_config_item("taxPercent");
     $taxPercentDivisor = $taxPercent / 100 + 1;
     $this->pay_info["total_dollars_minus_gst"] = page::money($currency, $this->pay_info["total_dollars"] / $taxPercentDivisor, "%m");
     $this->pay_info["total_customerBilledDollars_minus_gst"] = page::money($currency, $this->pay_info["total_customerBilledDollars"] / $taxPercentDivisor, "%m");
     $this->pay_info["total_dollars_not_null"] = $this->pay_info["total_customerBilledDollars"] or $this->pay_info["total_dollars_not_null"] = $this->pay_info["total_dollars"];
     $this->pay_info["currency"] = page::money($currency, '', "%S");
 }
Esempio n. 7
0
 function get_changes_list()
 {
     // This function returns HTML rows for the changes that have been made to this project
     $rows = array();
     $people_cache =& get_cached_table("person");
     $timeUnit = new timeUnit();
     $timeUnits = array_reverse($timeUnit->get_assoc_array("timeUnitID", "timeUnitLabelA"), true);
     $options = array("projectID" => $this->get_id());
     $changes = audit::get_list($options);
     foreach ((array) $changes as $audit) {
         $changeDescription = "";
         $newValue = $audit['value'];
         switch ($audit['field']) {
             case 'created':
                 $changeDescription = $newValue;
                 break;
             case 'dip':
                 $changeDescription = "Default parties set to " . interestedParty::abbreviate($newValue);
                 break;
             case 'projectShortName':
                 $changeDescription = "Project nickname set to '{$newValue}'.";
                 break;
             case 'projectComments':
                 $changeDescription = "Project description set to <a class=\"magic\" href=\"#x\" onclick=\"\$('#audit" . $audit["auditID"] . "').slideToggle('fast');\">Show</a> <div class=\"hidden\" id=\"audit" . $audit["auditID"] . "\"><div>" . $newValue . "</div></div>";
                 break;
             case 'clientID':
                 $newClient = new client($newValue);
                 is_object($newClient) and $newClientLink = $newClient->get_link();
                 $newClientLink or $newClientLink = "&lt;empty&gt;";
                 $changeDescription = "Client set to " . $newClientLink . ".";
                 break;
             case 'clientContactID':
                 $newClientContact = new clientContact($newValue);
                 is_object($newClientContact) and $newClientContactLink = $newClientContact->get_link();
                 $newClientContactLink or $newClientContactLink = "&lt;empty&gt;";
                 $changeDescription = "Client contact set to " . $newClientContactLink . ".";
                 break;
             case 'projectType':
                 $changeDescription = "Project type set to " . $newValue . ".";
                 break;
             case 'projectBudget':
                 $changeDescription = "Project budget set to " . page::money($this->get_value("currencyTypeID"), $newValue) . ".";
                 break;
             case 'currencyTypeID':
                 $changeDescription = "Project currency set to " . $newValue . ".";
                 break;
             case 'projectStatus':
                 $changeDescription = "Project status set to " . $newValue . ".";
                 break;
             case 'projectName':
                 $changeDescription = "Project name set to '{$newValue}'.";
                 break;
             case 'cost_centre_tfID':
                 $newCostCentre = new tf($newValue);
                 is_object($newCostCentre) and $newCostCentreLink = $newCostCentre->get_link();
                 $newCostCentreLink or $newCostCentreLink = "&lt;empty&gt;";
                 $changeDescription = "Cost centre TF set to " . $newCostCentreLink . ".";
                 break;
             case 'customerBilledDollars':
                 $changeDescription = "Client billing set to " . page::money($this->get_value("currencyTypeID"), $newValue) . ".";
                 break;
             case 'defaultTaskLimit':
                 $changeDescription = "Default task limit set to " . $newValue . ".";
                 break;
             case 'defaultTimeSheetRate':
                 $changeDescription = "Default time sheet rate set to " . page::money($this->get_value("currencyTypeID"), $newValue) . ".";
                 break;
             case 'defaultTimeSheetRateUnitID':
                 $changeDescription = "Default time sheet rate unit set to '" . $timeUnits[$newValue] . "'.";
                 break;
             case 'projectPriority':
                 $priorities = config::get_config_item("projectPriorities");
                 $changeDescription = sprintf('Project priority set to <span style="color: %s;">%s</span>.', $priorities[$newValue]["colour"], $priorities[$newValue]["label"]);
                 break;
             case 'dateActualCompletion':
             case 'dateActualStart':
             case 'dateTargetStart':
             case 'dateTargetCompletion':
                 // these cases are more or less identical
                 switch ($audit['field']) {
                     case 'dateActualCompletion':
                         $fieldDesc = "actual completion date";
                         break;
                     case 'dateActualStart':
                         $fieldDesc = "actual start date";
                         break;
                     case 'dateTargetStart':
                         $fieldDesc = "estimate/target start date";
                         break;
                     case 'dateTargetCompletion':
                         $fieldDesc = "estimate/target completion date";
                         break;
                 }
                 if (!$newValue) {
                     $changeDescription = "The {$fieldDesc} was removed.";
                 } else {
                     $changeDescription = "The {$fieldDesc} set to {$newValue}.";
                 }
                 break;
         }
         $rows[] = "<tr><td class=\"nobr\">" . $audit["dateChanged"] . "</td><td>{$changeDescription}</td><td>" . page::htmlentities($people_cache[$audit["personID"]]["name"]) . "</td></tr>";
     }
     return implode("\n", $rows);
 }
Esempio n. 8
0
function get_projectPerson_hourly_rate($personID, $projectID)
{
    $db = new db_alloc();
    $q = prepare("SELECT rate,rateUnitID FROM projectPerson WHERE personID = %d AND projectID = %d", $personID, $projectID);
    $db->query($q);
    $db->next_record();
    $rate = $db->f("rate");
    $unitID = $db->f("rateUnitID");
    $t = new timeUnit();
    $timeUnits = $t->get_assoc_array("timeUnitID", "timeUnitSeconds", $unitID);
    $rate && $timeUnits[$unitID] and $hourly_rate = $rate / ($timeUnits[$unitID] / 60 / 60);
    return $hourly_rate;
}