invoiceEntity::create($invoiceItem->get_value("invoiceID"), "expenseForm", $_POST["expenseFormID"], 1); invoiceEntity::save_invoice_expenseFormItems($invoiceItem->get_value("invoiceID"), $_POST["expenseFormID"]); } else { if ($_POST["expenseFormID"]) { invoiceEntity::create($invoiceItem->get_value("invoiceID"), "expenseForm", $_POST["expenseFormID"]); invoiceEntity::save_invoice_expenseForm($invoiceItem->get_value("invoiceID"), $_POST["expenseFormID"]); } else { if ($_POST["productSaleID"] && $_POST["split_productSale"]) { invoiceEntity::create($invoiceItem->get_value("invoiceID"), "productSale", $_POST["productSaleID"], 1); invoiceEntity::save_invoice_productSaleItems($invoiceItem->get_value("invoiceID"), $_POST["productSaleID"]); } else { if ($_POST["productSaleID"]) { invoiceEntity::create($invoiceItem->get_value("invoiceID"), "productSale", $_POST["productSaleID"]); invoiceEntity::save_invoice_productSale($invoiceItem->get_value("invoiceID"), $_POST["productSaleID"]); } else { $invoiceItem->save(); } } } } } } $TPL["message_good"][] = "Invoice Item saved."; alloc_redirect($TPL["url_alloc_invoice"] . "invoiceID=" . $invoiceItem->get_value("invoiceID")); } else { if ($_POST["invoiceItem_edit"]) { // Hmph. Nothing needs to go here? } else { if ($_POST["invoiceItem_delete"]) { $invoiceItem->select(); $invoiceItem->delete();
function save_invoice_productSaleItems($invoiceID, $productSaleID) { $productSale = new productSale(); $productSale->set_id($productSaleID); $productSale->select(); $db = new db_alloc(); $q = prepare("SELECT * FROM productSaleItem WHERE productSaleID = %d", $productSale->get_id()); $q1 = $db->query($q); while ($row = $db->row($q1)) { $q = prepare("SELECT * FROM invoiceItem WHERE productSaleID = %d AND productSaleItemID = %d", $productSaleID, $row["productSaleItemID"]); $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["sellPriceCurrencyTypeID"]; $ii->set_value("invoiceID", $invoiceID); $ii->set_value("productSaleID", $productSale->get_id()); $ii->set_value("productSaleItemID", $row["productSaleItemID"]); $ii->set_value("iiMemo", "Sale (" . $productSale->get_id() . ") item for " . person::get_fullname($productSale->get_value("personID")) . ", " . $row["description"]); $ii->set_value("iiQuantity", $row["quantity"]); $row["sellPrice"] = page::money($ii->currency, $row["sellPrice"] / $row["quantity"], "%mo"); $ii->set_value("iiUnitPrice", $row["sellPrice"]); $ii->set_value("iiAmount", $row["sellPrice"] * $row["quantity"]); $d = $productSale->get_value("productSaleDate") or $d = $productSale->get_value("productSaleModifiedTime") or $d = $productSale->get_value("productSaleCreatedTime"); $ii->set_value("iiDate", $d); //$ii->set_value("iiTax",config::get_config_item("taxPercent")); // product sale items are always excl GST $ii->save(); } }
$i->set_value("invoiceDateTo", $row["invoiceDate"]); $i->set_value("currencyTypeID", $invoice->get_value("currencyTypeID")); $i->set_value("maxAmount", $invoice->get_value("maxAmount")); $i->save(); #echo "<br>Created invoice: ".$i->get_id(); $q = prepare("SELECT * FROM invoiceItem WHERE invoiceID = %d", $invoice->get_id()); $id2 = $db->query($q); while ($item = $db->row($id2)) { $ii = new invoiceItem(); $ii->currency = $i->get_value("currencyTypeID"); $ii->set_value("invoiceID", $i->get_id()); $ii->set_value("iiMemo", $item["iiMemo"]); $ii->set_value("iiUnitPrice", page::money($ii->currency, $item["iiUnitPrice"], "%mo")); $ii->set_value("iiAmount", page::money($ii->currency, $item["iiAmount"], "%mo")); $ii->set_value("iiQuantity", $item["iiQuantity"]); $ii->save(); #echo "<br>Created invoice item: ".$ii->get_id(); } if ($row["message"]) { $ips = interestedParty::get_interested_parties("invoiceRepeat", $row["invoiceRepeatID"]); $recipients = array(); foreach ($ips as $email => $info) { $recipients[$email] = $info; $recipients[$email]["addIP"] = true; } $commentID = comment::add_comment("invoice", $i->get_id(), $row["message"], "invoice", $i->get_id()); if ($recipients) { $emailRecipients = comment::add_interested_parties($commentID, null, $recipients); comment::attach_invoice($commentID, $i->get_id(), $verbose = true); // Re-email the comment out, including any attachments if (!comment::send_comment($commentID, $emailRecipients)) {