function render() { global $TPL; $ops["status"] = "pending"; $ops["finalised"] = 1; $TPL["expenseFormRows"] = expenseForm::get_list($ops); if (count($TPL["expenseFormRows"])) { return true; } }
} else { if (check_optional_has_line_items() && !$expenseForm->get_value("expenseFormFinalised")) { $TPL["message_help"][] = "Step 3/4: When finished adding Expense Form Line Items, click the To Admin button to finalise the Expense Form."; } else { if (is_object($expenseForm) && $expenseForm->get_id() && !$expenseForm->get_value("expenseFormFinalised")) { $TPL["message_help"][] = "Step 2/4: Add Expense Form Line Items by filling in the details and clicking the Add Expense Form Line Item button."; } else { if (!is_object($expenseForm) || !$expenseForm->get_id()) { $TPL["message_help"][] = "Step 1/4: Begin an Expense Form by choosing the Payment Method and then clicking the Create Expense Form button."; } } } } $paymentOptionNames = array("", "COD", "Cheque", "Company Amex Charge", "Company Amex Blue", "Company Virgin MasterCard", "Other Credit Card", "Account", "Direct Deposit"); $paymentOptions = page::select_options($paymentOptionNames, $expenseForm->get_value("paymentMethod")); $rr_options = expenseForm::get_reimbursementRequired_array(); $rr_checked[sprintf("%d", $expenseForm->get_value("reimbursementRequired"))] = " checked"; $expenseForm->get_value("paymentMethod") and $extra = " (" . $paymentOptionNames[$expenseForm->get_value("paymentMethod")] . ")"; $rr_label = $rr_options[$expenseForm->get_value("reimbursementRequired")] . $extra; $TPL["rr_label"] = $rr_options[$expenseForm->get_value("reimbursementRequired")] . $extra; foreach ($rr_options as $value => $label) { unset($extra); $value == 2 and $extra = " <select name=\"paymentMethod\">" . $paymentOptions . "</select>"; $reimbursementRequiredRadios .= $br . "<input type=\"radio\" name=\"reimbursementRequired\" value=\"" . $value . "\"" . $rr_checked[$value] . ">" . $label . $extra; $br = "<br>"; } $TPL["paymentMethodOptions"] = $expenseForm->get_value("paymentMethod"); $TPL["reimbursementRequiredOption"] = $rr_label; $scr_label = "No"; if ($expenseForm->get_value("seekClientReimbursement")) { $scr_sel = " checked";
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."; } } } }
function save_invoice_expenseFormItems($invoiceID, $expenseFormID) { $expenseForm = new expenseForm(); $expenseForm->set_id($expenseFormID); $expenseForm->select(); $db = new db_alloc(); $q1 = $db->query("SELECT * FROM transaction WHERE expenseFormID = %d", $expenseFormID); while ($row = $db->row($q1)) { $amount = page::money($row["currencyTypeID"], $row["amount"], "%mo"); $q = prepare("SELECT * FROM invoiceItem WHERE expenseFormID = %d AND transactionID = %d", $expenseFormID, $row["transactionID"]); $db = new db_alloc(); $q2 = $db->query($q); $r2 = $db->row($q2); $ii = new invoiceItem(); if ($r2) { $ii->set_id($r2["invoiceItemID"]); } $ii->currency = $row["currencyTypeID"]; $ii->set_value("invoiceID", $invoiceID); $ii->set_value("expenseFormID", $expenseForm->get_id()); $ii->set_value("transactionID", $row["transactionID"]); $ii->set_value("iiMemo", "Expenses for " . person::get_fullname($expenseForm->get_value("expenseFormCreatedUser")) . ", " . $row["product"]); $ii->set_value("iiQuantity", $row["quantity"]); $ii->set_value("iiUnitPrice", $amount / $row["quantity"]); $ii->set_value("iiAmount", $amount); $ii->set_value("iiDate", $row["transactionDate"]); $ii->set_value("iiTax", config::get_config_item("taxPercent")); $ii->save(); } }
function show_new_invoiceItem($template) { global $TPL; global $invoice; global $invoiceID; $current_user =& singleton("current_user"); // Don't show entry form if no ID if (!$invoiceID) { return; } $TPL["div1"] = ""; $TPL["div2"] = " class=\"hidden\""; $TPL["div3"] = " class=\"hidden\""; $TPL["div4"] = " class=\"hidden\""; if (is_object($invoice) && $invoice->get_value("invoiceStatus") == 'edit' && $current_user->have_role('admin')) { // If we are editing an existing invoiceItem if (is_array($_POST["invoiceItem_edit"])) { $invoiceItemID = key($_POST["invoiceItem_edit"]); $invoiceItem = new invoiceItem(); $invoiceItem->currency = $invoice->get_value("currencyTypeID"); $invoiceItem->set_id($invoiceItemID); $invoiceItem->select(); $invoiceItem->set_tpl_values("invoiceItem_"); $TPL["invoiceItem_buttons"] = ' <button type="submit" name="invoiceItem_delete[' . $invoiceItemID . ']" value="1" class="delete_button">Delete<i class="icon-trash"></i></button> <button type="submit" name="invoiceItem_save[' . $invoiceItemID . ']" value="1" class="save_button">Save Item<i class="icon-edit"></i></button> '; if ($invoiceItem->get_value("timeSheetID")) { unset($TPL["div2"]); $TPL["div1"] = " class=\"hidden\""; $TPL["sbs_link"] = "timeSheet_ii"; } else { if ($invoiceItem->get_value("expenseFormID")) { unset($TPL["div3"]); $TPL["div1"] = " class=\"hidden\""; $TPL["sbs_link"] = "expenseForm_ii"; } else { if ($invoiceItem->get_value("productSaleID")) { unset($TPL["div4"]); $TPL["div1"] = " class=\"hidden\""; $TPL["sbs_link"] = "productSale_ii"; } } } // Else default values for creating a new invoiceItem } else { $invoiceItem = new invoiceItem(); $invoiceItem->set_values("invoiceItem_"); $TPL["invoiceItem_buttons"] = ' <button type="submit" name="invoiceItem_save" value="1" class="save_button">Add Item<i class="icon-plus-sign"></i></button> '; } // Build dropdown lists for timeSheet and expenseForm options. if ($invoice->get_value("clientID")) { // Time Sheet dropdown $db = new db_alloc(); $q = prepare("SELECT projectID FROM project WHERE clientID = %d", $invoice->get_value("clientID")); $db->query($q); $projectIDs = array(); while ($row = $db->row()) { $projectIDs[] = $row["projectID"]; } if ($projectIDs) { $q = prepare("SELECT timeSheet.*, project.projectName \n FROM timeSheet\n LEFT JOIN project ON project.projectID = timeSheet.projectID \n WHERE timeSheet.projectID IN (%s) \n AND timeSheet.status != 'finished'\n GROUP BY timeSheet.timeSheetID\n ORDER BY timeSheetID\n ", $projectIDs); $db->query($q); $timeSheetStatii = timeSheet::get_timeSheet_statii(); while ($row = $db->row()) { $t = new timeSheet(); $t->read_db_record($db); $t->load_pay_info(); $dollars = $t->pay_info["total_customerBilledDollars"] or $dollars = $t->pay_info["total_dollars"]; $timeSheetOptions[$row["timeSheetID"]] = "Time Sheet #" . $t->get_id() . " " . $row["dateFrom"] . " " . $dollars . " for " . person::get_fullname($row["personID"]) . ", Project: " . $row["projectName"] . " [" . $timeSheetStatii[$t->get_value("status")] . "]"; } $TPL["timeSheetOptions"] = page::select_options($timeSheetOptions, $invoiceItem->get_value("timeSheetID"), 150); } // Expense Form dropdown $db = new db_alloc(); $q = prepare("SELECT expenseFormID, expenseFormCreatedUser\n FROM expenseForm \n WHERE expenseFormFinalised = 1 \n AND seekClientReimbursement = 1\n AND clientID = %d\n ORDER BY expenseForm.expenseFormCreatedTime", $invoice->get_value("clientID")); $db->query($q); while ($row = $db->row()) { $expenseFormOptions[$row["expenseFormID"]] = "Expense Form #" . $row["expenseFormID"] . " " . page::money(config::get_config_item("currency"), expenseForm::get_abs_sum_transactions($row["expenseFormID"]), "%s%m %c") . " " . person::get_fullname($row["expenseFormCreatedUser"]); } if ($invoiceItem->get_value("expenseFormID")) { $id = $invoiceItem->get_value("expenseFormID"); } $TPL["expenseFormOptions"] = page::select_options($expenseFormOptions, $id, 90); $q = prepare("SELECT *\n FROM productSale\n WHERE clientID = %d\n AND status = 'admin'\n ", $invoice->get_value("clientID")); $invoice->get_value("projectID") and $q .= prepare(" AND projectID = %d", $invoice->get_value("projectID")); $db->query($q); while ($row = $db->row()) { $productSale = new productSale(); $productSale->set_id($row["productSaleID"]); $productSale->select(); $ps_row = $productSale->get_amounts(); $productSaleOptions[$row["productSaleID"]] = "Sale #" . $row["productSaleID"] . " " . $ps_row["total_sellPrice"] . " " . person::get_fullname($row["personID"]); } if ($invoiceItem->get_value("productSaleID")) { $id = $invoiceItem->get_value("productSaleID"); } $TPL["productSaleOptions"] = page::select_options($productSaleOptions, $id, 90); } $TPL["invoiceItem_iiQuantity"] or $TPL["invoiceItem_iiQuantity"] = 1; $TPL["invoiceItem_invoiceID"] = $invoice->get_id(); include_template($template); } }
public static function get_list($_FORM = array()) { global $TPL; $filter = expenseForm::get_list_filter($_FORM); if (is_array($filter) && count($filter)) { $f = " AND " . implode(" AND ", $filter); } $db = new db_alloc(); $dbTwo = new db_alloc(); $transDB = new db_alloc(); $expenseForm = new expenseForm(); $transaction = new transaction(); $rr_options = expenseForm::get_reimbursementRequired_array(); $q = prepare("SELECT expenseForm.*\n ,SUM(transaction.amount * pow(10,-currencyType.numberToBasic)) as formTotal\n ,transaction.currencyTypeID\n FROM expenseForm, transaction\n LEFT JOIN currencyType on transaction.currencyTypeID = currencyType.currencyTypeID\n WHERE expenseForm.expenseFormID = transaction.expenseFormID\n " . $f . "\n GROUP BY expenseForm.expenseFormID, transaction.currencyTypeID\n ORDER BY expenseFormID"); $db->query($q); while ($row = $db->row()) { $amounts[$row["expenseFormID"]] .= $sp[$row["expenseFormID"]] . page::money($row["currencyTypeID"], $row["formTotal"], "%s%m"); $sp[$row["expenseFormID"]] = " + "; $allrows[$row["expenseFormID"]] = $row; } foreach ((array) $allrows as $expenseFormID => $row) { $expenseForm = new expenseForm(); if ($expenseForm->read_row_record($row)) { $expenseForm->set_values(); $row["formTotal"] = $amounts[$expenseFormID]; $row["expenseFormModifiedUser"] = person::get_fullname($expenseForm->get_value("expenseFormModifiedUser")); $row["expenseFormModifiedTime"] = $expenseForm->get_value("expenseFormModifiedTime"); $row["expenseFormCreatedUser"] = person::get_fullname($expenseForm->get_value("expenseFormCreatedUser")); $row["expenseFormCreatedTime"] = $expenseForm->get_value("expenseFormCreatedTime"); unset($extra); $expenseForm->get_value("paymentMethod") and $extra = " (" . $expenseForm->get_value("paymentMethod") . ")"; $row["rr_label"] = $rr_options[$expenseForm->get_value("reimbursementRequired")] . $extra; $rows[] = $row; } } return (array) $rows; }
<?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/>. */ require_once "../alloc.php"; $ops["status"] = "pending"; $TPL["expenseFormRows"] = expenseForm::get_list($ops); $TPL["transactionRows"] = expenseForm::get_pending_repeat_transaction_list(); $TPL["main_alloc_title"] = "Expense Form List - " . APPLICATION_NAME; include_template("templates/expenseFormListM.tpl");