function show_productSale_list($productSaleID, $template) { global $TPL; global $productSaleItemsDoExist; $productSale = new productSale(); $productSale->set_id($productSaleID); $productSale->select(); $productSale->set_tpl_values(); $taxName = config::get_config_item("taxName"); $product = new product(); $ops = $product->get_assoc_array("productID", "productName"); $query = prepare("SELECT *\n FROM productSaleItem \n WHERE productSaleID = %d", $productSaleID); $db = new db_alloc(); $db->query($query); while ($db->next_record()) { $productSaleItemsDoExist = true; $productSaleItem = new productSaleItem(); $productSaleItem->read_db_record($db); $productSaleItem->set_tpl_values(); $TPL["itemSellPrice"] = $productSaleItem->get_value("sellPrice"); $TPL["itemMargin"] = $productSaleItem->get_amount_margin(); $TPL["itemSpent"] = $productSaleItem->get_amount_spent(); $TPL["itemEarnt"] = $productSaleItem->get_amount_earnt(); $TPL["itemOther"] = $productSaleItem->get_amount_other(); $TPL["itemCosts"] = page::money(config::get_config_item("currency"), product::get_buy_cost($productSaleItem->get_value("productID")) * $productSaleItem->get_value("quantity"), "%s%mo %c"); $TPL["itemTotalUnallocated"] = $productSaleItem->get_amount_unallocated(); $TPL["productList_dropdown"] = page::select_options($ops, $productSaleItem->get_value("productID")); $TPL["productLink"] = "<a href=\"" . $TPL["url_alloc_product"] . "productID=" . $productSaleItem->get_value("productID") . "\">" . page::htmlentities($ops[$productSaleItem->get_value("productID")]) . "</a>"; $TPL["transactions"] = $productSale->get_transactions($productSaleItem->get_id()); if ($taxName) { $TPL["sellPriceTax_check"] = sprintf(" <input type='checkbox' name='sellPriceIncTax[]' value='%d'%s> inc %s", $productSaleItem->get_id(), $productSaleItem->get_value("sellPriceIncTax") ? ' checked' : '', $taxName); $TPL["sellPriceTax_label"] = $productSaleItem->get_value("sellPriceIncTax") ? " inc " . $taxName : " ex " . $taxName; } include_template($template); } }
function get_amounts() { $rows = $this->get_productSaleItems(); $rows or $rows = array(); $rtn = array(); foreach ($rows as $row) { $productSaleItem = new productSaleItem(); $productSaleItem->read_row_record($row); //$rtn["total_spent"] += $productSaleItem->get_amount_spent(); //$rtn["total_earnt"] += $productSaleItem->get_amount_earnt(); //$rtn["total_other"] += $productSaleItem->get_amount_other(); list($sp, $spcur) = array($productSaleItem->get_value("sellPrice"), $productSaleItem->get_value("sellPriceCurrencyTypeID")); $sellPriceCurr[$spcur] += page::money($spcur, $sp, "%m"); $total_sellPrice += exchangeRate::convert($spcur, $sp); $total_margin += $productSaleItem->get_amount_margin(); $total_unallocated += $productSaleItem->get_amount_unallocated(); } unset($sep, $label, $show); foreach ((array) $sellPriceCurr as $code => $amount) { $label .= $sep . page::money($code, $amount, "%s%mo %c"); $sep = " + "; $code != config::get_config_item("currency") and $show = true; } $show && $label and $sellPrice_label = " (" . $label . ")"; $total_sellPrice_plus_gst = add_tax($total_sellPrice); $rtn["total_sellPrice"] = page::money(config::get_config_item("currency"), $total_sellPrice, "%s%mo %c") . $sellPrice_label; $rtn["total_sellPrice_plus_gst"] = page::money(config::get_config_item("currency"), $total_sellPrice_plus_gst, "%s%mo %c") . $sellPrice_label; $rtn["total_margin"] = page::money(config::get_config_item("currency"), $total_margin, "%s%mo %c"); $rtn["total_unallocated"] = page::money(config::get_config_item("currency"), $total_unallocated, "%s%mo %c"); $rtn["total_unallocated_number"] = page::money(config::get_config_item("currency"), $total_unallocated, "%mo"); $rtn["total_sellPrice_value"] = page::money(config::get_config_item("currency"), $total_sellPrice, "%mo"); return $rtn; }