function show_time_sheets_list_for_classes($template_name, $doAdmin = false)
{
    $current_user =& singleton("current_user");
    global $TPL;
    if ($doAdmin) {
        $db = get_pending_admin_timesheet_db();
    } else {
        $db = get_pending_timesheet_db();
    }
    $people =& get_cached_table("person");
    while ($db->next_record()) {
        $timeSheet = new timeSheet();
        $timeSheet->read_db_record($db);
        $timeSheet->set_values();
        unset($date);
        if ($timeSheet->get_value("status") == "manager") {
            $date = $timeSheet->get_value("dateSubmittedToManager");
        } else {
            if ($timeSheet->get_value("status") == "admin") {
                $date = $timeSheet->get_value("dateSubmittedToAdmin");
            }
        }
        unset($TPL["warning"]);
        // older than $current_user->prefs["timeSheetDaysWarn"] days
        if ($date && imp($current_user->prefs["timeSheetDaysWarn"]) && (mktime() - format_date("U", $date)) / 60 / 60 / 24 > $current_user->prefs["timeSheetDaysWarn"]) {
            $TPL["warning"] = page::help("This time sheet was submitted to you over " . $current_user->prefs["timeSheetDaysWarn"] . " days ago.", page::warn());
        }
        $TPL["date"] = "<a href=\"" . $TPL["url_alloc_timeSheet"] . "timeSheetID=" . $timeSheet->get_id() . "\">" . $date . "</a>";
        $TPL["user"] = $people[$timeSheet->get_value("personID")]["name"];
        $TPL["projectName"] = $db->f("projectName");
        include_template("../time/templates/" . $template_name);
    }
}
Exemple #2
0
function show_filter()
{
    global $TPL;
    global $defaults;
    $_FORM = timeSheet::load_form_data($defaults);
    $arr = timeSheet::load_timeSheet_filter($_FORM);
    is_array($arr) and $TPL = array_merge($TPL, $arr);
    include_template("templates/timeSheetListFilterS.tpl");
}
 function render()
 {
     $current_user =& singleton("current_user");
     global $TPL;
     $ops["showShortProjectLink"] = "true";
     $ops["personID"] = $current_user->get_id();
     $ops["status"] = array('edit', 'manager', 'admin', 'invoiced', 'rejected');
     $rtn = timeSheet::get_list($ops);
     $TPL["timeSheetListRows"] = $rtn["rows"];
     $TPL["timeSheetListExtra"] = $rtn["extra"];
     if ($TPL["timeSheetListRows"]) {
         return true;
     }
 }
Exemple #4
0
 function close_related_entity()
 {
     global $TPL;
     // It checks for approved transactions and only approves the timesheets
     // or expenseforms that are completely paid for by an invoice item.
     $db = new db_alloc();
     $q = prepare("SELECT amount, currencyTypeID, status \n                    FROM transaction \n                   WHERE invoiceItemID = %d \n                ORDER BY transactionCreatedTime DESC \n                   LIMIT 1\n                 ", $this->get_id());
     $db->query($q);
     $row = $db->row();
     $total = $row["amount"];
     $currency = $row["currencyTypeID"];
     $status = $row["status"];
     $timeSheetID = $this->get_value("timeSheetID");
     $expenseFormID = $this->get_value("expenseFormID");
     if ($timeSheetID) {
         $timeSheet = new timeSheet();
         $timeSheet->set_id($timeSheetID);
         $timeSheet->select();
         $db = new db_alloc();
         if ($timeSheet->get_value("status") == "invoiced") {
             // If the time sheet doesn't have any transactions and it is in
             // status invoiced, then we'll simulate the "Create Default Transactions"
             // button being pressed.
             $q = prepare("SELECT count(*) as num_transactions \n                        FROM transaction \n                       WHERE timeSheetID = %d \n                         AND invoiceItemID IS NULL\n                     ", $timeSheet->get_id());
             $db->query($q);
             $row = $db->row();
             if ($row["num_transactions"] == 0) {
                 $_POST["create_transactions_default"] = true;
                 $timeSheet->createTransactions($status);
                 $TPL["message_good"][] = "Automatically created time sheet transactions.";
             }
             // Get total of all time sheet transactions.
             $q = prepare("SELECT SUM(amount) AS total \n                        FROM transaction \n                       WHERE timeSheetID = %d \n                         AND status != 'rejected' \n                         AND invoiceItemID IS NULL\n                     ", $timeSheet->get_id());
             $db->query($q);
             $row = $db->row();
             $total_timeSheet = $row["total"];
             if ($total >= $total_timeSheet) {
                 $timeSheet->pending_transactions_to_approved();
                 $timeSheet->change_status("forwards");
                 $TPL["message_good"][] = "Closed Time Sheet #" . $timeSheet->get_id() . " and marked its Transactions: " . $status;
             } else {
                 $TPL["message_help"][] = "Unable to close Time Sheet #" . $timeSheet->get_id() . " the sum of the Time Sheet's *Transactions* (" . page::money($timeSheet->get_value("currencyTypeID"), $total_timeSheet, "%s%mo %c") . ") is greater than the Invoice Item Transaction (" . page::money($currency, $total, "%s%mo %c") . ")";
             }
         }
     } else {
         if ($expenseFormID) {
             $expenseForm = new expenseForm();
             $expenseForm->set_id($expenseFormID);
             $expenseForm->select();
             $total_expenseForm = $expenseForm->get_abs_sum_transactions();
             if ($total == $total_expenseForm) {
                 $expenseForm->set_status("approved");
                 $TPL["message_good"][] = "Approved Expense Form #" . $expenseForm->get_id() . ".";
             } else {
                 $TPL["message_help"][] = "Unable to approve Expense Form #" . $expenseForm->get_id() . " the sum of Expense Form Transactions does not equal the Invoice Item Transaction.";
             }
         }
     }
 }
Exemple #5
0
} else {
    // if this is the invoice -> completed step it should be checked by default
    if ($timeSheet->get_value("status") == 'invoiced') {
        $TPL["dont_send_email_checked"] = " checked";
    } else {
        $TPL["dont_send_email_checked"] = "";
    }
}
$timeSheet->load_pay_info();
$percent_array = array("" => "Calculate %", "A" => "Standard", sprintf("%0.2f", $timeSheet->pay_info["total_dollars"] * 1) => "100%", sprintf("%0.2f", $timeSheet->pay_info["total_dollars"] * 0.715) => "71.5%", sprintf("%0.2f", $timeSheet->pay_info["total_dollars"] * 0.665) => "66.5%", sprintf("%0.2f", $timeSheet->pay_info["total_dollars"] * 0.615) => "61.5%", sprintf("%0.2f", $timeSheet->pay_info["total_dollars"] * 0.285) => "28.5%", "B" => "Agency", sprintf("%0.2f", $timeSheet->pay_info["total_dollars"] * 0.765) => "76.5%", sprintf("%0.2f", $timeSheet->pay_info["total_dollars"] * 0.715) => "71.5%", sprintf("%0.2f", $timeSheet->pay_info["total_dollars"] * 0.665) => "66.5%", sprintf("%0.2f", $timeSheet->pay_info["total_dollars"] * 0.235) => "23.5%", "C" => "Commission", sprintf("%0.2f", $timeSheet->pay_info["total_dollars"] * 0.05) => "5.0%", sprintf("%0.2f", $timeSheet->pay_info["total_dollars"] * 0.025) => "2.5%", "D" => "Old Rates", sprintf("%0.2f", $timeSheet->pay_info["total_dollars"] * 0.772) => "77.2%", sprintf("%0.2f", $timeSheet->pay_info["total_dollars"] * 0.722) => "72.2%", sprintf("%0.2f", $timeSheet->pay_info["total_dollars"] * 0.228) => "22.8%");
// display the buttons to move timesheet forward and backward.
if (!$timeSheet->get_id()) {
    $TPL["timeSheet_ChangeStatusButton"] = '<button type="submit" name="save" value="1" class="save_button">Create Time Sheet<i class="icon-ok-sign"></i></button>';
}
$radio_email = "<input type=\"checkbox\" id=\"dont_send_email\" name=\"dont_send_email\" value=\"1\"" . $TPL["dont_send_email_checked"] . "> <label for=\"dont_send_email\">Don't send email</label><br>";
$statii = timeSheet::get_timeSheet_statii();
if (!$projectManagers) {
    unset($statii["manager"]);
}
foreach ($statii as $s => $label) {
    unset($pre, $suf);
    // prefix and suffix
    $status = $timeSheet->get_value("status");
    unset($red);
    $status == "rejected" and $red = true;
    $status == "rejected" and $status = "edit";
    if (!$timeSheet->get_id()) {
        $status = "create";
    }
    if ($s == $status) {
        $red and $red = ' class="warn"';
<?php

/*
 * Copyright (C) 2006-2011 Alex Lance, Clancy Malcolm, Cyber IT Solutions
 * Pty. Ltd.
 * 
 * This file is part of the allocPSA application <*****@*****.**>.
 * 
 * allocPSA is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * 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";
if ($_GET["task_type"] && $_GET["timeSheetID"]) {
    usleep(400000);
    echo timeSheet::get_task_list_dropdown($_GET["task_type"], $_GET["timeSheetID"], $_GET["taskID"]);
}
Exemple #7
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.");
     }
 }
Exemple #8
0
 function add_time($commands, $email_receive)
 {
     $current_user =& singleton("current_user");
     if ($commands["time"]) {
         // CLI passes time along as a string, email passes time along as an array
         if (!is_array($commands["time"])) {
             $t = $commands["time"];
             unset($commands["time"]);
             $commands["time"][] = $t;
         }
         foreach ((array) $commands["time"] as $time) {
             $t = timeSheetItem::parse_time_string($time);
             if (is_numeric($t["duration"]) && $current_user->get_id()) {
                 $timeSheet = new timeSheet();
                 is_object($email_receive) and $t["msg_uid"] = $email_receive->msg_uid;
                 $tsi_row = $timeSheet->add_timeSheetItem($t);
                 $status[] = $tsi_row["status"];
                 $message[] = $tsi_row["message"];
             }
         }
     }
     return array($status, $message);
 }
Exemple #9
0
<?php

// Create a search index for Time Sheets. This patch may take a long time to apply.
ini_set('max_execution_time', 180000);
ini_set('memory_limit', "256M");
$index = Zend_Search_Lucene::create(ATTACHMENTS_DIR . 'search/timeSheet');
$db = new db_alloc();
$q = prepare("SELECT * FROM timeSheet");
$db->query($q);
while ($db->row()) {
    $timeSheet = new timeSheet();
    $timeSheet->read_db_record($db);
    $timeSheet->update_search_index_doc($index);
}
$index->commit();
 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;
 }
Exemple #11
0
 * 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/>.
*/
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.";
 function get_printable_timeSheet_file($timeSheetID, $timeSheetPrintMode, $printDesc, $format)
 {
     global $TPL;
     $TPL["timeSheetID"] = $timeSheetID;
     $TPL["timeSheetPrintMode"] = $timeSheetPrintMode;
     $TPL["printDesc"] = $printDesc;
     $TPL["format"] = $format;
     $db = new db_alloc();
     if ($timeSheetID) {
         $timeSheet = new timeSheet();
         $timeSheet->set_id($timeSheetID);
         $timeSheet->select();
         $timeSheet->set_tpl_values();
         $person = $timeSheet->get_foreign_object("person");
         $TPL["timeSheet_personName"] = $person->get_name();
         $timeSheet->set_tpl_values("timeSheet_");
         // Display the project name.
         $project = new project();
         $project->set_id($timeSheet->get_value("projectID"));
         $project->select();
         $TPL["timeSheet_projectName"] = $project->get_value("projectName", DST_HTML_DISPLAY);
         // Get client name
         $client = $project->get_foreign_object("client");
         $client->set_tpl_values();
         $TPL["clientName"] = $client->get_value("clientName", DST_HTML_DISPLAY);
         $TPL["companyName"] = config::get_config_item("companyName");
         $TPL["companyNos1"] = config::get_config_item("companyACN");
         $TPL["companyNos2"] = config::get_config_item("companyABN");
         unset($br);
         $phone = config::get_config_item("companyContactPhone");
         $fax = config::get_config_item("companyContactFax");
         $phone and $TPL["phone"] = "Ph: " . $phone;
         $fax and $TPL["fax"] = "Fax: " . $fax;
         $timeSheet->load_pay_info();
         $db->query(prepare("SELECT max(dateTimeSheetItem) AS maxDate\n                                ,min(dateTimeSheetItem) AS minDate\n                                ,count(timeSheetItemID) as count\n                            FROM timeSheetItem \n                           WHERE timeSheetID=%d ", $timeSheetID));
         $db->next_record();
         $timeSheet->set_id($timeSheetID);
         $timeSheet->select() || alloc_error("Unable to select time sheet, trying to use id: " . $timeSheetID);
         $TPL["period"] = format_date(DATE_FORMAT, $db->f("minDate")) . " to " . format_date(DATE_FORMAT, $db->f("maxDate"));
         $TPL["img"] = config::get_config_item("companyImage");
         $TPL["companyContactAddress"] = config::get_config_item("companyContactAddress");
         $TPL["companyContactAddress2"] = config::get_config_item("companyContactAddress2");
         $TPL["companyContactAddress3"] = config::get_config_item("companyContactAddress3");
         $email = config::get_config_item("companyContactEmail");
         $email and $TPL["companyContactEmail"] = "Email: " . $email;
         $web = config::get_config_item("companyContactHomePage");
         $web and $TPL["companyContactHomePage"] = "Web: " . $web;
         $TPL["footer"] = config::get_config_item("timeSheetPrintFooter");
         $TPL["taxName"] = config::get_config_item("taxName");
         $default_header = "Time Sheet";
         $default_id_label = "Time Sheet ID";
         $default_contractor_label = "Contractor";
         $default_total_label = "TOTAL AMOUNT PAYABLE";
         if ($timeSheetPrintMode == "money") {
             $default_header = "Tax Invoice";
             $default_id_label = "Invoice Number";
         }
         if ($timeSheetPrintMode == "estimate") {
             $default_header = "Estimate";
             $default_id_label = "Estimate Number";
             $default_contractor_label = "Issued By";
             $default_total_label = "TOTAL AMOUNT ESTIMATED";
         }
         if ($format != "html") {
             // Build PDF document
             $font1 = ALLOC_MOD_DIR . "util/fonts/Helvetica.afm";
             $font2 = ALLOC_MOD_DIR . "util/fonts/Helvetica-Oblique.afm";
             $pdf_table_options = array("showLines" => 0, "shaded" => 0, "showHeadings" => 0, "xPos" => "left", "xOrientation" => "right", "fontSize" => 10, "rowGap" => 0, "fontSize" => 10);
             $cols = array("one" => "", "two" => "", "three" => "", "four" => "");
             $cols3 = array("one" => "", "two" => "");
             $cols_settings["one"] = array("justification" => "right");
             $cols_settings["three"] = array("justification" => "right");
             $pdf_table_options2 = array("showLines" => 0, "shaded" => 0, "showHeadings" => 0, "width" => 400, "fontSize" => 10, "xPos" => "center", "xOrientation" => "center", "cols" => $cols_settings);
             $cols_settings2["gst"] = array("justification" => "right");
             $cols_settings2["money"] = array("justification" => "right");
             $pdf_table_options3 = array("showLines" => 2, "shaded" => 0, "width" => 400, "xPos" => "center", "fontSize" => 10, "cols" => $cols_settings2, "lineCol" => array(0.8, 0.8, 0.8), "splitRows" => 1, "protectRows" => 0);
             $cols_settings["two"] = array("justification" => "right", "width" => 80);
             $pdf_table_options4 = array("showLines" => 2, "shaded" => 0, "width" => 400, "showHeadings" => 0, "fontSize" => 10, "xPos" => "center", "cols" => $cols_settings, "lineCol" => array(0.8, 0.8, 0.8));
             $pdf = new Cezpdf();
             $pdf->ezSetMargins(90, 90, 90, 90);
             $pdf->selectFont($font1);
             $pdf->ezStartPageNumbers(436, 80, 10, 'right', 'Page {PAGENUM} of {TOTALPAGENUM}');
             $pdf->ezStartPageNumbers(200, 80, 10, 'left', '<b>' . $default_id_label . ': </b>' . $TPL["timeSheetID"]);
             $pdf->ezSetY(775);
             $TPL["companyName"] and $contact_info[] = array($TPL["companyName"]);
             $TPL["companyContactAddress"] and $contact_info[] = array($TPL["companyContactAddress"]);
             $TPL["companyContactAddress2"] and $contact_info[] = array($TPL["companyContactAddress2"]);
             $TPL["companyContactAddress3"] and $contact_info[] = array($TPL["companyContactAddress3"]);
             $TPL["companyContactEmail"] and $contact_info[] = array($TPL["companyContactEmail"]);
             $TPL["companyContactHomePage"] and $contact_info[] = array($TPL["companyContactHomePage"]);
             $TPL["phone"] and $contact_info[] = array($TPL["phone"]);
             $TPL["fax"] and $contact_info[] = array($TPL["fax"]);
             $pdf->selectFont($font2);
             $y = $pdf->ezTable($contact_info, false, "", $pdf_table_options);
             $pdf->selectFont($font1);
             $line_y = $y - 10;
             $pdf->setLineStyle(1, "round");
             $pdf->line(90, $line_y, 510, $line_y);
             $pdf->ezSetY(782);
             $image_jpg = ALLOC_LOGO;
             if (file_exists($image_jpg)) {
                 $pdf->ezImage($image_jpg, 0, sprintf("%d", config::get_config_item("logoScaleX")), 'none');
                 $y = 700;
             } else {
                 $y = $pdf->ezText($TPL["companyName"], 27, array("justification" => "right"));
             }
             $nos_y = $line_y + 22;
             $TPL["companyNos2"] and $nos_y = $line_y + 34;
             $pdf->ezSetY($nos_y);
             $TPL["companyNos1"] and $y = $pdf->ezText($TPL["companyNos1"], 10, array("justification" => "right"));
             $TPL["companyNos2"] and $y = $pdf->ezText($TPL["companyNos2"], 10, array("justification" => "right"));
             $pdf->ezSetY($line_y - 20);
             $y = $pdf->ezText($default_header, 20, array("justification" => "center"));
             $pdf->ezSetY($y - 20);
             $ts_info[] = array("one" => "<b>" . $default_id_label . ":</b>", "two" => $TPL["timeSheetID"], "three" => "<b>Date Issued:</b>", "four" => date("d/m/Y"));
             $ts_info[] = array("one" => "<b>Client:</b>", "two" => $TPL["clientName"], "three" => "<b>Project:</b>", "four" => $TPL["timeSheet_projectName"]);
             $ts_info[] = array("one" => "<b>" . $default_contractor_label . ":</b>", "two" => $TPL["timeSheet_personName"], "three" => "<b>Billing Period:</b>", "four" => $TPL["period"]);
             if ($timeSheetPrintMode == "estimate") {
                 // This line needs to be glued to the above line
                 $temp = array_pop($ts_info);
                 $temp["three"] = "";
                 // Nuke Billing Period for the Estimate version of the pdf.
                 $temp["four"] = "";
                 // Nuke Billing Period for the Estimate version of the pdf.
                 $ts_info[] = $temp;
             }
             $y = $pdf->ezTable($ts_info, $cols, "", $pdf_table_options2);
             $pdf->ezSetY($y - 20);
             if ($timeSheetPrintMode == "money" || $timeSheetPrintMode == "estimate") {
                 list($rows, $info) = $this->get_timeSheetItem_list_money($TPL["timeSheetID"]);
                 $cols2 = array("desc" => "Description", "units" => "Units", "money" => "Charges", "gst" => $TPL["taxName"]);
                 $taxPercent = config::get_config_item("taxPercent");
                 if ($taxPercent === '') {
                     unset($cols2["gst"]);
                 }
                 $rows[] = array("desc" => "<b>TOTAL</b>", "units" => $info["total_units"], "money" => $info["total"], "gst" => $info["total_gst"]);
                 $y = $pdf->ezTable($rows, $cols2, "", $pdf_table_options3);
                 $pdf->ezSetY($y - 20);
                 if ($taxPercent !== '') {
                     $totals[] = array("one" => "TOTAL " . $TPL["taxName"], "two" => $info["total_gst"]);
                 }
                 $totals[] = array("one" => "TOTAL CHARGES", "two" => $info["total"]);
                 $totals[] = array("one" => "<b>" . $default_total_label . "</b>", "two" => "<b>" . $info["total_inc_gst"] . "</b>");
                 $y = $pdf->ezTable($totals, $cols3, "", $pdf_table_options4);
             } else {
                 if ($timeSheetPrintMode == "units") {
                     list($rows, $info) = $this->get_timeSheetItem_list_units($TPL["timeSheetID"]);
                     $cols2 = array("desc" => "Description", "units" => "Units");
                     $rows[] = array("desc" => "<b>TOTAL</b>", "units" => "<b>" . $info["total"] . "</b>");
                     $y = $pdf->ezTable($rows, $cols2, "", $pdf_table_options3);
                 } else {
                     if ($timeSheetPrintMode == "items") {
                         list($rows, $info) = $this->get_timeSheetItem_list_items($TPL["timeSheetID"]);
                         $cols2 = array("date" => "Date", "units" => "Units", "multiplier_string" => "Multiplier", "desc" => "Description");
                         $rows[] = array("date" => "<b>TOTAL</b>", "units" => "<b>" . $info["total"] . "</b>");
                         $y = $pdf->ezTable($rows, $cols2, "", $pdf_table_options3);
                     }
                 }
             }
             $pdf->ezSetY($y - 20);
             $pdf->ezText(str_replace(array("<br>", "<br/>", "<br />"), "\n", $TPL["footer"]), 10);
             $pdf->ezStream(array("Content-Disposition" => "timeSheet_" . $timeSheetID . ".pdf"));
             // Else HTML format
         } else {
             if (file_exists(ALLOC_LOGO)) {
                 $TPL["companyName"] = '<img alt="Company logo" src="' . $TPL["url_alloc_logo"] . '" />';
             }
             $TPL["this_tsp"] = $this;
             $TPL["main_alloc_title"] = "Time Sheet - " . APPLICATION_NAME;
             include_template(dirname(__FILE__) . "/../templates/timeSheetPrintM.tpl");
         }
     }
 }
Exemple #13
0
function show_invoiceItem_list()
{
    global $invoiceID;
    global $TPL;
    global $invoice;
    $current_user =& singleton("current_user");
    $template = "templates/invoiceItemListR.tpl";
    $db = new db_alloc();
    $db2 = new db_alloc();
    $q = prepare("SELECT *\n                  FROM invoiceItem \n                 WHERE invoiceItem.invoiceID = %d \n              ORDER BY iiDate,invoiceItem.invoiceItemID", $invoiceID);
    $db->query($q);
    while ($db->next_record()) {
        $invoiceItem = new invoiceItem();
        $invoiceItem->currency = $invoice->get_value("currencyTypeID");
        if (!$invoiceItem->read_db_record($db)) {
            continue;
        }
        $invoiceItem->set_tpl_values("invoiceItem_");
        unset($transaction_sum);
        unset($transaction_info);
        unset($transaction_statii);
        unset($one_approved);
        unset($one_rejected);
        unset($one_pending);
        unset($br);
        unset($sel);
        unset($amount);
        unset($TPL["invoiceItem_buttons_top"], $TPL["invoiceItem_buttons"], $TPL["transaction_info"], $TPL["status_label"]);
        // If editing a invoiceItem then don't display it in the list
        if (is_array($_POST["invoiceItem_edit"]) && key($_POST["invoiceItem_edit"]) == $invoiceItem->get_id()) {
            continue;
        }
        $q = prepare("SELECT *\n                       , transaction.amount * pow(10,-currencyType.numberToBasic) AS transaction_amount\n                       , transaction.tfID AS transaction_tfID\n                       , transaction.fromTfID AS transaction_fromTfID\n                       , transaction.status AS transaction_status  \n                       , transaction.currencyTypeID\n                    FROM transaction \n               LEFT JOIN currencyType on transaction.currencyTypeID = currencyType.currencyTypeID\n                   WHERE transaction.invoiceItemID = %d", $invoiceItem->get_id());
        $db2->query($q);
        while ($db2->next_record()) {
            $transaction = new transaction();
            if (!$transaction->read_db_record($db2)) {
                $other_peoples_transactions .= "<br>Tansaction access denied for transaction #" . $db2->f("transactionID");
                continue;
            }
            if ($db2->f("transaction_status") == "approved") {
                $one_approved = true;
            }
            if ($db2->f("transaction_status") == "rejected") {
                $one_rejected = true;
            }
            if ($db2->f("transaction_status") == "pending") {
                $one_pending = true;
            }
            $amounts[$invoiceItem->get_id()] += $db2->f("transaction_amount");
            $db2->f("transaction_status") != "rejected" and $transaction_sum += $db2->f("transaction_amount");
            $transaction_info .= $br . ucwords($db2->f("transaction_status")) . " Transaction ";
            $transaction_info .= "<a href=\"" . $TPL["url_alloc_transaction"] . "transactionID=" . $db2->f("transactionID") . "\">#" . $db2->f("transactionID") . "</a>";
            $transaction_info .= " from ";
            $transaction_info .= "<a href=\"" . $TPL["url_alloc_transactionList"] . "tfID=" . $db2->f("transaction_fromTfID") . "\">" . tf::get_name($db2->f("transaction_fromTfID")) . "</a>";
            $transaction_info .= " to <a href=\"" . $TPL["url_alloc_transactionList"] . "tfID=" . $db2->f("transaction_tfID") . "\">" . tf::get_name($db2->f("transaction_tfID")) . "</a>";
            $transaction_info .= " for <b>" . page::money($db2->f("currencyTypeID"), $db2->f("transaction_amount"), "%s%m") . "</b>";
            $br = "<br>";
        }
        $TPL["transaction_info"] = $transaction_info;
        $TPL["transaction_info"] .= $other_peoples_transactions;
        // Sets the background colour of the invoice item boxes based on transaction.status
        if (!$one_rejected && !$one_pending && $one_approved) {
            $TPL["box_class"] = " approved";
            $transaction_status = "approved";
        } else {
            if ($one_rejected) {
                $TPL["box_class"] = " rejected";
                $transaction_status = "rejected";
            } else {
                if ($one_pending) {
                    $transaction_status = "pending";
                    $TPL["box_class"] = " warn";
                } else {
                    $TPL["box_class"] = " pending";
                    $transaction_status = "";
                }
            }
        }
        $sel[$transaction_status] = " checked";
        if ($sel["rejected"]) {
            $TPL["status_label"] = "<b>[Not Going To Be Paid]</b>";
        } else {
            if ($sel["pending"]) {
                $TPL["status_label"] = "<b>[Pending]</b>";
            } else {
                if ($sel["approved"]) {
                    $TPL["status_label"] = "<b>[Paid]</b>";
                }
            }
        }
        if ($transaction_sum > 0 && $transaction_sum < $invoiceItem->get_value("iiAmount", DST_HTML_DISPLAY)) {
            $TPL["status_label"] = "<b>[Paid in part]</b>";
            $TPL["box_class"] = " warn";
        } else {
            if ($transaction_sum > $invoiceItem->get_value("iiAmount")) {
                $TPL["status_label"] = "<b>[Overpaid]</b>";
            }
        }
        $TPL["status_label"] or $TPL["status_label"] = "<b>[No Transactions Created]</b>";
        if ($invoice->get_value("invoiceStatus") == "reconcile") {
            if ($amounts[$invoiceItem->get_id()] === null) {
                $amount = $invoiceItem->get_value("iiAmount", DST_HTML_DISPLAY);
                if (config::get_config_item("taxPercent") && $invoiceItem->get_value("iiTax") == 0) {
                    $amount = page::money($invoice->get_value("currencyTypeID"), $amount * (config::get_config_item("taxPercent") / 100 + 1), "%m");
                }
            } else {
                $amount = page::money($invoice->get_value("currencyTypeID"), $amounts[$invoiceItem->get_id()], "%m");
            }
            $selected_tfID = $db2->f("transaction_tfID");
            if (!$selected_tfID && $invoiceItem->get_value("timeSheetID")) {
                $timeSheet = $invoiceItem->get_foreign_object("timeSheet");
                $project = $timeSheet->get_foreign_object("project");
                $selected_tfID = $project->get_value("cost_centre_tfID");
            } else {
                if (!$selected_tfID && $invoiceItem->get_value("transactionID")) {
                    $transaction = $invoiceItem->get_foreign_object("transaction");
                    $project = $transaction->get_foreign_object("project");
                    $selected_tfID = $project->get_value("cost_centre_tfID");
                    $selected_tfID or $selected_tfID = $transaction->get_value("tfID");
                }
            }
            $selected_tfID or $selected_tfID = config::get_config_item("mainTfID");
            #$tf_options = page::select_options($tf_array, $selected_tfID);
            #$tf_options = "<select name=\"invoiceItemAmountPaidTfID[".$invoiceItem->get_id()."]\">".$tf_options."</select>";
            #$TPL["invoiceItem_buttons"] = "<input size=\"8\" type=\"text\" id=\"ap_".$invoiceItem->get_id()."\" name=\"invoiceItemAmountPaid[".$invoiceItem->get_id()."]\" value=\"".$amount."\">";
            #$TPL["invoiceItem_buttons"].= $tf_options;
            unset($radio_buttons);
            if ($current_user->have_role('admin')) {
                $radio_buttons = "<label class='radio corner' for=\"invoiceItemStatus_rejected_" . $invoiceItem->get_id() . "\">Not Going To Be Paid";
                $radio_buttons .= "<input type=\"radio\" id=\"invoiceItemStatus_rejected_" . $invoiceItem->get_id() . "\" name=\"invoiceItemStatus[" . $invoiceItem->get_id() . "]\"";
                $radio_buttons .= " value=\"rejected\"" . $sel["rejected"] . ">";
                $radio_buttons .= "</label>";
                $radio_buttons .= "&nbsp;&nbsp;";
                $radio_buttons .= "<label class='radio corner' for=\"invoiceItemStatus_pending_" . $invoiceItem->get_id() . "\">Pending";
                $radio_buttons .= "<input type=\"radio\" id=\"invoiceItemStatus_pending_" . $invoiceItem->get_id() . "\" name=\"invoiceItemStatus[" . $invoiceItem->get_id() . "]\"";
                $radio_buttons .= " value=\"pending\"" . $sel["pending"] . ">";
                $radio_buttons .= "</label>";
                $radio_buttons .= "&nbsp;&nbsp;";
                $radio_buttons .= "<label class='radio corner' for=\"invoiceItemStatus_approved_" . $invoiceItem->get_id() . "\">Paid";
                $radio_buttons .= "<input type=\"radio\" id=\"invoiceItemStatus_approved_" . $invoiceItem->get_id() . "\" name=\"invoiceItemStatus[" . $invoiceItem->get_id() . "]\"";
                $radio_buttons .= " value=\"approved\"" . $sel["approved"] . ">";
                $radio_buttons .= "</label>";
                $TPL["invoiceItem_buttons_top"] = $radio_buttons;
                $TPL["invoiceItem_buttons_top"] .= "&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"text\" size=\"7\" name=\"invoiceItemAmountPaid[" . $invoiceItem->get_id() . "]\" value=\"" . $amount . "\">";
                $TPL["invoiceItem_buttons_top"] .= "<input type=\"hidden\" name=\"invoiceItemAmountPaidTfID[" . $invoiceItem->get_id() . "]\" value=\"" . $selected_tfID . "\">";
            }
            unset($TPL["invoiceItem_buttons"]);
        } else {
            if ($invoice->get_value("invoiceStatus") == "finished") {
            } else {
                if (is_object($invoice) && $invoice->get_value("invoiceStatus") == "edit") {
                    $TPL["invoiceItem_buttons"] = '
        <button type="submit" name="invoiceItem_delete[' . $invoiceItem->get_id() . ']" value="1" class="delete_button">Delete<i class="icon-trash"></i></button>
        <button type="submit" name="invoiceItem_edit[' . $invoiceItem->get_id() . ']" value="1">Edit<i class="icon-edit"></i></button>
      ';
                }
            }
        }
        if ($invoiceItem->get_value("timeSheetID")) {
            $t = new timeSheet();
            $t->set_id($invoiceItem->get_value("timeSheetID"));
            $t->select();
            $t->load_pay_info();
            $amount = $t->pay_info["total_customerBilledDollars"] or $amount = $t->pay_info["total_dollars"];
            $TPL["invoiceItem_iiMemo"] = "<a href=\"" . $TPL["url_alloc_timeSheet"] . "timeSheetID=" . $invoiceItem->get_value("timeSheetID") . "\">" . $invoiceItem->get_value("iiMemo") . " (Currently: \$" . $amount . ", Status: " . $t->get_timeSheet_status() . ")</a>";
        } else {
            if ($invoiceItem->get_value("expenseFormID")) {
                $ep = $invoiceItem->get_foreign_object("expenseForm");
                $total = $ep->get_abs_sum_transactions();
                $TPL["invoiceItem_iiMemo"] = "<a href=\"" . $TPL["url_alloc_expenseForm"] . "expenseFormID=" . $invoiceItem->get_value("expenseFormID") . "\">" . $invoiceItem->get_value("iiMemo") . " (Currently: " . page::money(config::get_config_item("currency"), $total, "%s%m %c") . ", Status: " . $ep->get_status() . ")</a>";
            }
        }
        $TPL["currency"] = $invoice->get_value("currencyTypeID");
        include_template($template);
    }
}
Exemple #14
0
 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 #15
0
 /**
  * Move a time sheet to a different status
  * @param integer $timeSheetID the time sheet to change
  * @param string $direction the direction to move the timesheet eg "forwards" or "backwards"
  * @return string a success message
  */
 public function change_timeSheet_status($timeSheetID, $direction)
 {
     $timeSheet = new timeSheet();
     $timeSheet->set_id($timeSheetID);
     $timeSheet->select();
     $rtn = $timeSheet->change_status($direction);
     $timeSheet->save();
     return $rtn;
 }
 function populate_string($str, $entity, $entityID = false)
 {
     // Actually do the text substitution
     $current_user =& singleton("current_user");
     is_object($current_user) and $swap["cu"] = person::get_fullname($current_user->get_id());
     if ($entity == "timeSheet" && $entityID) {
         $timeSheet = new timeSheet();
         $timeSheet->set_id($entityID);
         $timeSheet->select();
         $timeSheet->load_pay_info();
         foreach ($timeSheet->pay_info as $k => $v) {
             $swap[$k] = $v;
         }
         if ($timeSheet->get_value("approvedByManagerPersonID")) {
             $swap["tm"] = person::get_fullname($timeSheet->get_value("approvedByManagerPersonID"));
         } else {
             $project = $timeSheet->get_foreign_object("project");
             $projectManagers = $project->get_timeSheetRecipients();
             if (is_array($projectManagers) && count($projectManagers)) {
                 $people =& get_cached_table("person");
                 foreach ($projectManagers as $pID) {
                     $swap["tm"] .= $commar . $people[$pID]["name"];
                     $commar = ", ";
                 }
             }
         }
         if ($timeSheet->get_value("approvedByAdminPersonID")) {
             $swap["tc"] = person::get_fullname($timeSheet->get_value("approvedByAdminPersonID"));
         } else {
             $people =& get_cached_table("person");
             $timeSheetAdministrators = config::get_config_item('defaultTimeSheetAdminList');
             if (count($timeSheetAdministrators)) {
                 $swap["tc"] = "";
                 $comma = "";
                 foreach ($timeSheetAdministrators as $adminID) {
                     $swap["tc"] .= $comma . $people[$adminID]["name"];
                     $comma = ", ";
                 }
             } else {
                 $swap["tc"] = 'no-one';
             }
         }
         $swap["ti"] = $timeSheet->get_id();
         $swap["to"] = person::get_fullname($timeSheet->get_value("personID"));
         $swap["ta"] = person::get_fullname($timeSheet->get_value("personID"));
         $swap["tf"] = $timeSheet->get_value("dateFrom");
         $swap["tt"] = $timeSheet->get_value("dateTo");
         $swap["ts"] = $timeSheet->get_timeSheet_status();
         $swap["tu"] = config::get_config_item("allocURL") . "time/timeSheet.php?timeSheetID=" . $timeSheet->get_id();
         $projectID = $timeSheet->get_value("projectID");
     }
     if ($entity == "task" && $entityID) {
         $task = new task();
         $task->set_id($entityID);
         $task->select();
         $swap["ti"] = $task->get_id();
         $swap["to"] = person::get_fullname($task->get_value("creatorID"));
         $swap["ta"] = person::get_fullname($task->get_value("personID"));
         $swap["tm"] = person::get_fullname($task->get_value("managerID"));
         $swap["tc"] = person::get_fullname($task->get_value("closerID"));
         $swap["tn"] = $task->get_value("taskName");
         $swap["td"] = $task->get_value("taskDescription");
         $swap["tu"] = config::get_config_item("allocURL") . "task/task.php?taskID=" . $task->get_id();
         $swap["tp"] = $task->get_priority_label();
         $swap["ts"] = $task->get_task_status("label");
         $swap["teb"] = $task->get_value("timeBest");
         $swap["tem"] = $task->get_value("timeExpected");
         $swap["tew"] = $task->get_value("timeWorst");
         $swap["tep"] = person::get_fullname($task->get_value("estimatorID"));
         //time estimate person, when it's implemented
         $projectID = $task->get_value("projectID");
     }
     if ($entity == "project" && $entityID || $projectID) {
         $project = new project();
         if ($projectID) {
             $project->set_id($projectID);
         } else {
             $project->set_id($entityID);
         }
         $project->select();
         $swap["pn"] = $project->get_value("projectName");
         $swap["pi"] = $project->get_id();
         $clientID = $project->get_value("clientID");
     }
     if ($entity == "client" && $entityID || $clientID) {
         $client = new client();
         if ($clientID) {
             $client->set_id($clientID);
         } else {
             $client->set_id($entityID);
         }
         $client->select();
         $swap["li"] = $client->get_id();
         $swap["cc"] = $client->get_value("clientName");
     }
     $swap["cd"] = config::get_config_item("companyContactAddress");
     $swap["cd"] .= " " . config::get_config_item("companyContactAddress2");
     $swap["cd"] .= " " . config::get_config_item("companyContactAddress3");
     $swap["cd"] .= "\nP: " . config::get_config_item("companyContactPhone");
     $swap["cd"] .= "\nF: " . config::get_config_item("companyContactFax");
     $swap["cd"] .= "\nE: " . config::get_config_item("companyContactEmail");
     $swap["cd"] .= "\nW: " . config::get_config_item("companyContactHomePage");
     $swap["cn"] = config::get_config_item("companyName");
     $swap["c1"] = config::get_config_item("companyContactAddress");
     $swap["c2"] = config::get_config_item("companyContactAddress2");
     $swap["c3"] = config::get_config_item("companyContactAddress3");
     $swap["ce"] = config::get_config_item("companyContactEmail");
     $swap["cp"] = config::get_config_item("companyContactPhone");
     $swap["cf"] = config::get_config_item("companyContactFax");
     $swap["cw"] = config::get_config_item("companyContactHomePage");
     foreach ($swap as $k => $v) {
         $str = str_replace("%" . $k, $v, $str);
     }
     return $str;
 }
Exemple #17
0
}
$TPL["total_invoice_transactions_pending"] = page::money_print($rows);
$q = prepare("SELECT SUM((amount * pow(10,-currencyType.numberToBasic))) \n                  AS amount, transaction.currencyTypeID as currency\n                FROM transaction\n           LEFT JOIN invoiceItem on invoiceItem.invoiceItemID = transaction.invoiceItemID\n           LEFT JOIN invoice on invoice.invoiceID = invoiceItem.invoiceID\n           LEFT JOIN currencyType on currencyType.currencyTypeID = invoice.currencyTypeID\n               WHERE invoice.projectID = %d\n                 AND transaction.status = 'approved'\n            GROUP BY transaction.currencyTypeID\n              ", $project->get_id());
$db->query($q);
unset($rows);
while ($row = $db->row()) {
    $rows[] = $row;
}
$TPL["total_invoice_transactions_approved"] = page::money_print($rows);
$q = prepare("SELECT SUM((amount * pow(10,-currencyType.numberToBasic))) \n                  AS amount, transaction.currencyTypeID as currency\n                FROM transaction\n           LEFT JOIN currencyType on currencyType.currencyTypeID = transaction.currencyTypeID\n               WHERE transaction.projectID = %d\n                 AND transaction.status = 'approved'\n            GROUP BY transaction.currencyTypeID\n              ", $project->get_id());
$db->query($q);
unset($rows);
while ($row = $db->row()) {
    $rows[] = $row;
}
$TPL["total_expenses_transactions_approved"] = page::money_print($rows);
if ($project->get_id()) {
    $defaults["projectID"] = $project->get_id();
    $defaults["showFinances"] = true;
    if (!$project->have_perm(PERM_READ_WRITE)) {
        $defaults["personID"] = $current_user->get_id();
    }
    $rtn = timeSheet::get_list($defaults);
    $TPL["timeSheetListRows"] = $rtn["rows"];
    $TPL["timeSheetListExtra"] = $rtn["extra"];
}
if ($project->have_perm(PERM_READ_WRITE)) {
    include_template("templates/projectFormM.tpl");
} else {
    include_template("templates/projectViewM.tpl");
}
Exemple #18
0
 function get_project_id()
 {
     $this->select();
     if ($this->get_value("commentType") == "task" && $this->get_value("commentLinkID")) {
         $t = new task();
         $t->set_id($this->get_value("commentLinkID"));
         $t->select();
         $projectID = $t->get_value("projectID");
     } else {
         if ($this->get_value("commentType") == "project" && $this->get_value("commentLinkID")) {
             $projectID = $this->get_value("commentLinkID");
         } else {
             if ($this->get_value("commentType") == "timeSheet" && $this->get_value("commentLinkID")) {
                 $t = new timeSheet();
                 $t->set_id($this->get_value("commentLinkID"));
                 $t->select();
                 $projectID = $t->get_value("projectID");
             }
         }
     }
     return $projectID;
 }
Exemple #19
0
 function save_invoice_timeSheetItems($invoiceID, $timeSheetID)
 {
     $timeSheet = new timeSheet();
     $timeSheet->set_id($timeSheetID);
     $timeSheet->select();
     $currency = $timeSheet->get_value("currencyTypeID");
     $timeSheet->load_pay_info();
     $amount = $timeSheet->pay_info["total_customerBilledDollars"] or $amount = $timeSheet->pay_info["total_dollars"];
     $project = $timeSheet->get_foreign_object("project");
     $client = $project->get_foreign_object("client");
     $db = new db_alloc();
     $q1 = $db->query(prepare("SELECT * FROM timeSheetItem WHERE timeSheetID = %d", $timeSheetID));
     while ($row = $db->row($q1)) {
         if (imp($timeSheet->pay_info["customerBilledDollars"])) {
             $iiUnitPrice = $timeSheet->pay_info["customerBilledDollars"];
         } else {
             $iiUnitPrice = page::money($currency, $row["rate"], "%mo");
         }
         unset($str);
         if ($row["comment"] && !$row["commentPrivate"]) {
             $str = $row["comment"];
         }
         // Look for an existing invoiceItem
         $q = prepare("SELECT invoiceItem.invoiceItemID\n                      FROM invoiceItem\n                 LEFT JOIN invoice ON invoiceItem.invoiceID = invoice.invoiceID\n                     WHERE invoiceItem.timeSheetID = %d\n                       AND invoiceItem.timeSheetItemID = %d\n                       AND invoiceItem.invoiceID = %d\n                       AND invoice.invoiceStatus != 'finished'\n                  ORDER BY iiDate DESC LIMIT 1\n                   ", $timeSheet->get_id(), $row["timeSheetItemID"], $invoiceID);
         $q2 = $db->query($q);
         $r2 = $db->row($q2);
         $ii = new invoiceItem();
         if ($r2["invoiceItemID"]) {
             $ii->set_id($r2["invoiceItemID"]);
         }
         $ii->currency = $currency;
         $ii->set_value("invoiceID", $invoiceID);
         $ii->set_value("timeSheetID", $timeSheet->get_id());
         $ii->set_value("timeSheetItemID", $row["timeSheetItemID"]);
         $ii->set_value("iiMemo", "Time Sheet for " . person::get_fullname($timeSheet->get_value("personID")) . ", Project: " . $project->get_value("projectName") . ", " . $row["description"] . "\n" . $str);
         $ii->set_value("iiQuantity", $row["timeSheetItemDuration"] * $row["multiplier"]);
         $ii->set_value("iiUnitPrice", $iiUnitPrice);
         $ii->set_value("iiAmount", $iiUnitPrice * $row["timeSheetItemDuration"] * $row["multiplier"]);
         $ii->set_value("iiDate", $row["dateTimeSheetItem"]);
         $ii->set_value("iiTax", config::get_config_item("taxPercent"));
         $ii->save();
     }
 }
//Comment: This is the comment
$str[] = "<tr><td>" . $rtn["date"] . " </td><td class='nobr bold'> " . $rtn["duration"] . " " . $rtn["unit"] . "</td><td class='nobr'>&times; " . $rtn["multiplier"] . "</td></tr>";
$rtn["taskID"] and $str[] = "<tr><td colspan='3'>" . $rtn["taskID"] . "</td></tr>";
$rtn["comment"] and $str[] = "<tr><td colspan='3'>" . $rtn["comment"] . "</td></tr>";
if (isset($_REQUEST["save"]) && isset($_REQUEST["time_item"])) {
    $t = timeSheetItem::parse_time_string($_REQUEST["time_item"]);
    if (!is_numeric($t["duration"])) {
        $status = "bad";
        $extra = "Time not added. Duration not found.";
    } else {
        if (!is_numeric($t["taskID"])) {
            $status = "bad";
            $extra = "Time not added. Task not found.";
        }
    }
    if ($status != "bad") {
        $timeSheet = new timeSheet();
        $tsi_row = $timeSheet->add_timeSheetItem($t);
        if ($TPL["message"]) {
            $status = "bad";
            $extra = "Time not added.<br>" . implode("<br>", $TPL["message"]);
        } else {
            $status = "good";
            $tsid = $tsi_row["message"];
            $extra = "Added time to time sheet <a href='" . $TPL["url_alloc_timeSheet"] . "timeSheetID=" . $tsid . "'>#" . $tsid . "</a>";
        }
    }
}
#$extra and array_unshift($str, "<tr><td colspan='3' class='".$status." bold'>".$extra."</td></tr>");
$extra and $str[] = "<tr><td colspan='3' class='" . $status . " bold'>" . $extra . "</td></tr>";
print alloc_json_encode(array("status" => $status, "table" => "<table class='" . $status . "'>" . implode("\n", $str) . "</table>"));
Exemple #21
0
 function get_transaction_type_link()
 {
     global $TPL;
     $type = $this->get_value("transactionType");
     $transactionTypes = transaction::get_transactionTypes();
     // Transaction stems from an invoice
     if ($type == "invoice") {
         $invoice = $this->get_foreign_object("invoice");
         if (!$invoice->get_id()) {
             $invoiceItem = $this->get_foreign_object("invoiceItem");
             $invoice = $invoiceItem->get_foreign_object("invoice");
         }
         $invoice->get_id() and $str = "<a href=\"" . $invoice->get_url() . "\">" . $transactionTypes[$type] . " " . $invoice->get_value("invoiceNum") . "</a>";
         // Transaction is from an expenseform
     } else {
         if ($type == "expense") {
             $expenseForm = $this->get_foreign_object("expenseForm");
             if ($expenseForm->get_id() && $expenseForm->have_perm(PERM_READ_WRITE)) {
                 $str = "<a href=\"" . $expenseForm->get_url() . "\">" . $transactionTypes[$type] . " " . $this->get_value("expenseFormID") . "</a>";
             }
             // Had to rewrite this so that people who had transactions on other peoples timesheets
             // could see their own transactions, but not the other persons timesheet.
         } else {
             if ($type == "timesheet" && $this->get_value("timeSheetID")) {
                 $timeSheet = new timeSheet();
                 $timeSheet->set_id($this->get_value("timeSheetID"));
                 $str = "<a href=\"" . $timeSheet->get_url() . "\">" . $transactionTypes[$type] . " " . $this->get_value("timeSheetID") . "</a>";
             } else {
                 if (($type == "commission" || $type == "tax") && $this->get_value("timeSheetID")) {
                     $timeSheet = new timeSheet();
                     $timeSheet->set_id($this->get_value("timeSheetID"));
                     $str = "<a href=\"" . $timeSheet->get_url() . "\">" . $transactionTypes[$type] . " (Time Sheet " . $this->get_value("timeSheetID") . ")</a>";
                 } else {
                     $str = $transactionTypes[$type];
                 }
             }
         }
     }
     if ($this->get_value("transactionGroupID")) {
         $str .= " <a href=\"" . $TPL["url_alloc_transactionGroup"] . "transactionGroupID=" . $this->get_value("transactionGroupID") . "\">Group " . $this->get_value("transactionGroupID") . "</a>";
     }
     return $str;
 }