Esempio n. 1
0
 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;
 }
Esempio n. 2
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);
    }
}