function set_invoice_payment($id, $invoicetype, $itemid, $date_trans, $chartid, $amount, $source, $description) { log_debug("accounts_invoices_manage", "Executing set_invoice_payment({$id}, {$invoicetype}, values...)"); // check the invoicetype if ($invoicetype != "ar" && $invoicetype != "ap") { throw new SoapFault("Sender", "INVALID_INVOICE_TYPE"); } if (user_permissions_get("accounts_" . $invoicetype . "_write")) { $obj_invoice_item = new invoice_items(); $obj_invoice_item->type_invoice = $invoicetype; $obj_invoice_item->id_invoice = @security_script_input_predefined("int", $id); $obj_invoice_item->id_item = @security_script_input_predefined("any", $itemid); $obj_invoice_item->type_item = "payment"; /* Error Handling */ // verify invoice existance if (!$obj_invoice_item->verify_invoice()) { throw new SoapFault("Sender", "INVALID_INVOICE"); } // make sure invoice is not locked if ($obj_invoice_item->check_lock()) { throw new SoapFault("Sender", "LOCKED"); } // verify item existance (if editing one) if ($obj_invoice_item->id_item) { if (!$obj_invoice_item->verify_item()) { throw new SoapFault("Sender", "INVALID_ITEMID"); } } /* Load SOAP data */ $data["date_trans"] = @security_script_input_predefined("date", $date_trans); $data["chartid"] = @security_script_input_predefined("int", $chartid); $data["amount"] = @security_script_input_predefined("money", $amount); $data["source"] = @security_script_input_predefined("any", $source); $data["description"] = @security_script_input_predefined("any", $description); foreach (array_keys($data) as $key) { if ($data[$key] == "error") { throw new SoapFault("Sender", "INVALID_INPUT"); } } // process the data if (!$obj_invoice_item->prepare_data($data)) { throw new SoapFault("Sender", "UNEXPECTED_PREP_ERROR"); } /* Apply Data */ // create SQL transaction $sql_obj = new sql_query(); $sql_obj->trans_begin(); // create / update payment if (!$obj_invoice_item->id_item) { if (!$obj_invoice_item->action_create()) { $sql_obj->trans_rollback(); throw new SoapFault("Sender", "UNEXPECTED_ACTION_ERROR"); } } if (!$obj_invoice_item->action_update()) { $sql_obj->trans_rollback(); throw new SoapFault("Sender", "UNEXPECTED_ACTION_ERROR"); } // update invoice totals $obj_invoice_item->action_update_total(); // Generate ledger entries. $obj_invoice_item->action_update_ledger(); // commit if (error_check()) { $sql_obj->trans_rollback(); throw new SoapFault("Sender", "UNEXPECTED_ACTION_ERROR"); } else { $sql_obj->trans_commit(); return $obj_invoice_item->id_item; } } else { throw new SoapFault("Sender", "ACCESS DENIED"); } }
function invoice_form_tax_override_process($returnpage) { log_debug("inc_invoices_items", "Executing invoice_form_tax_override_process({$returnpage})"); /* Start invoice_items object */ $item = new invoice_items(); $item->id_invoice = @security_form_input_predefined("int", "invoiceid", 1, ""); $item->id_item = @security_form_input_predefined("int", "itemid", 1, ""); $item->type_invoice = "ap"; // only AP invoices can have taxes overridden /* Fetch all form data */ $data["amount"] = @security_form_input_predefined("money", "amount", 0, ""); //// ERROR CHECKING /////////////////////// /* Verify invoice/form data */ if ($item->verify_invoice()) { if (!$item->verify_item()) { $_SESSION["error"]["message"][] = "The provided tax does not exist."; } } else { $_SESSION["error"]["message"][] = "The provided invoice does not exist."; } /// if there was an error, go back to the entry page if ($_SESSION["error"]["message"]) { $_SESSION["error"]["form"]["ap_invoice_" . $mode . "_override"] = "failed"; header("Location: ../../index.php?page={$returnpage}&id=" . $item->id_invoice); exit(0); } else { /* Start SQL Transaction */ $sql_obj = new sql_query(); $sql_obj->trans_begin(); /* Depending on the amount, we either delete the tax item (if the amount is 0) or we adjust the tax item. */ if ($data["amount"] == 0) { // delete item $item->action_delete(); // done $_SESSION["notification"]["message"] = array("Deleted unwanted tax."); } else { // load & update the tax item $item->load_data(); $item->data["amount"] = $data["amount"]; $item->action_update(); // done $_SESSION["notification"]["message"] = array("Updated tax value with custom input."); } // update invoice summary $item->action_update_total(); // update ledger $item->action_update_ledger(); /* Commit */ if (error_check()) { $sql_obj->trans_rollback(); log_write("error", "inc_invoice_items", "An error occured whilst overriding tax. No changes have been made"); } else { $sql_obj->trans_commit(); } // done header("Location: ../../index.php?page={$returnpage}&id=" . $item->id_invoice); exit(0); } }