public static function get_list($_FORM = array()) { $filter = productSale::get_list_filter($_FORM); $debug = $_FORM["debug"]; $debug and print "\n<pre>_FORM: " . print_r($_FORM, 1) . "</pre>"; $debug and print "\n<pre>filter: " . print_r($filter, 1) . "</pre>"; if (is_array($filter) && count($filter)) { $f = " WHERE " . implode(" AND ", $filter); } $f .= " ORDER BY IFNULL(productSaleDate,productSaleCreatedTime)"; $db = new db_alloc(); $query = prepare("SELECT productSale.*, project.projectName, client.clientName\n FROM productSale \n LEFT JOIN client ON productSale.clientID = client.clientID\n LEFT JOIN project ON productSale.projectID = project.projectID\n " . $f); $db->query($query); $statii = productSale::get_statii(); $people =& get_cached_table("person"); $rows = array(); while ($row = $db->next_record()) { $productSale = new productSale(); $productSale->read_db_record($db); $row["amounts"] = $productSale->get_amounts(); $row["statusLabel"] = $statii[$row["status"]]; $row["salespersonLabel"] = $people[$row["personID"]]["name"]; $row["creatorLabel"] = $people[$row["productSaleCreatedUser"]]["name"]; $row["productSaleLink"] = $productSale->get_link(); $rows[] = $row; } return (array) $rows; }
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); } }
function save_invoice_productSale($invoiceID, $productSaleID) { $productSale = new productSale(); $productSale->set_id($productSaleID); $productSale->select(); $db = new db_alloc(); $db->query("SELECT max(transactionDate) as maxDate\n FROM transaction\n WHERE productSaleID = %d", $productSaleID); $row = $db->row(); $amounts = $productSale->get_amounts(); $q = prepare("SELECT * FROM invoiceItem WHERE productSaleID = %d AND productSaleItemID IS NULL", $productSaleID); $db = new db_alloc(); $q2 = $db->query($q); $r2 = $db->row($q2); $ii = new invoiceItem(); if ($r2) { $ii->set_id($r2["invoiceItemID"]); } $ii->set_value("invoiceID", $invoiceID); $ii->set_value("productSaleID", $productSale->get_id()); $ii->set_value("iiMemo", "Sale #" . $productSale->get_id() . " for " . person::get_fullname($productSale->get_value("personID"))); $ii->set_value("iiQuantity", 1); $ii->set_value("iiUnitPrice", $amounts["total_sellPrice_value"]); $ii->set_value("iiAmount", $amounts["total_sellPrice_value"]); $ii->set_value("iiDate", $row["maxDate"]); //$ii->set_value("iiTax",config::get_config_item("taxPercent")); $ii->save(); }
$TPL["show_person_options"] = person::get_fullname($productSale->get_value("personID")); $TPL["show_date"] = $productSale->get_value("productSaleDate"); $TPL["show_extRef"] = $productSale->get_value("extRef"); $TPL["show_extRefDate"] = $productSale->get_value("extRefDate"); if (!$productSale->get_id() || $productSale->get_value("status") != "finished" && !($productSale->get_value("status") == "admin" && !CAN_APPROVE_TRANSACTIONS)) { $TPL["show_client_options"] = $client_select; $TPL["show_project_options"] = $project_select; $TPL["show_tf_options"] = $tf_select; $personID = $productSale->get_value("personID") or $personID = $current_user->get_id(); $TPL["show_person_options"] = "<select name='personID'>" . page::select_options(person::get_username_list($personID), $personID) . "</select>"; $TPL["show_date"] = page::calendar("productSaleDate", $productSale->get_value("productSaleDate")); $TPL["show_extRef"] = "<input type='text' name='extRef' value='" . $productSale->get_value("extRef") . "' size='10'>"; $TPL["show_extRefDate"] = page::calendar("extRefDate", $productSale->get_value("extRefDate")); } $TPL["productSale_status"] = $productSale->get_value("status"); $amounts = $productSale->get_amounts(); $TPL = array_merge($TPL, $amounts); define("DISPLAY_PRODUCT_SALE_ITEM_EDIT", 1); define("DISPLAY_PRODUCT_SALE_ITEM_TRANSACTION_EDIT", 2); define("DISPLAY_PRODUCT_SALE_ITEM_TRANSACTION_VIEW", 3); define("DISPLAY_PRODUCT_SALE_EDIT", 4); // Show line item edit $productSaleID = $productSale->get_id(); $status = $productSale->get_value("status"); if ($productSaleID && $status == "edit") { define("DISPLAY", DISPLAY_PRODUCT_SALE_ITEM_EDIT); // Show line item + transaction + edit } else { if ($productSaleID && ($status == "allocate" || $status == "admin" && $productSale->have_perm(PERM_APPROVE_PRODUCT_TRANSACTIONS))) { define("DISPLAY", DISPLAY_PRODUCT_SALE_ITEM_TRANSACTION_EDIT); // Show line item + transaction + view