function credit_form_lock_process($type, $returnpage_error, $returnpage_success) { log_debug("inc_credits_forms", "Executing credit_form_lock_process({$type}, {$mode}, {$returnpage_error}, {$returnpage_success})"); $credit = new credit(); $credit->type = $type; /* Import POST Data */ $credit->id = @security_form_input_predefined("int", "id_credit", 1, ""); $data["lock_credit"] = @security_form_input_predefined("checkbox", "lock_credit", 0, ""); /* Error Handling */ // make sure the credit actually exists if (!$credit->verify_credit()) { log_write("error", "process", "The credit note you have attempted to delete - " . $credit->id . " - does not exist in this system."); } // check if credit is locked or not if ($credit->check_lock()) { log_write("error", "process", "The credit note can not be locked because it is *already* locked."); } // check lock if (!$data["lock_credit"]) { log_write("error", "process", "You must check to confirm the credit note lock."); } // return to input page in event of an error if ($_SESSION["error"]["message"]) { $_SESSION["error"]["form"][$type . "_credit_lock"] = "failed"; header("Location: ../../index.php?page={$returnpage_error}&id=" . $credit->id); exit(0); } /* Lock Credit Note */ $credit->load_data(); if ($credit->action_lock()) { log_write("notification", "process", "The selected credit note has now been locked."); } else { log_write("error", "process", "An error occured whilst attempting to lock the credit note."); } // display updated details header("Location: ../../index.php?page={$returnpage_success}&id=" . $credit->id); exit(0); }
function action_update_total() { log_debug("invoice_items", "Executing action_update_total()"); // default values $amount = "0"; $amount_tax = "0"; $amount_total = "0"; /* Total up all the items, and all the tax */ $amount = 0; $amount_tax = 0; $amount_paid = 0; // fetch item amounts from DB $sql_obj = new sql_query(); $sql_obj->string = "SELECT amount, type FROM `account_items` WHERE invoicetype='" . $this->type_invoice . "' AND invoiceid='" . $this->id_invoice . "'"; $sql_obj->execute(); if ($sql_obj->num_rows()) { $sql_obj->fetch_array(); foreach ($sql_obj->data as $data_sql) { // total up the different item types if ($data_sql["type"] != "tax" && $data_sql["type"] != "payment") { $amount += $data_sql["amount"]; } if ($data_sql["type"] == "tax") { $amount_tax += $data_sql["amount"]; } if ($data_sql["type"] == "payment") { $amount_paid += $data_sql["amount"]; } } } // final totals $amount_total = $amount + $amount_tax; $amount = sprintf("%0.2f", $amount); $amount_tax = sprintf("%0.2f", $amount_tax); $amount_total = sprintf("%0.2f", $amount_total); $amount_paid = sprintf("%0.2f", $amount_paid); /* Update the invoice */ $sql_obj = new sql_query(); if ($this->type_invoice == "quotes" || $this->type_invoice == "ar_credit" || $this->type_invoice == "ar_credit") { $sql_obj->string = "UPDATE `account_" . $this->type_invoice . "` SET " . "amount='" . $amount . "', " . "amount_tax='" . $amount_tax . "', " . "amount_total='" . $amount_total . "' " . "WHERE id='" . $this->id_invoice . "' LIMIT 1"; } else { $sql_obj->string = "UPDATE `account_" . $this->type_invoice . "` SET " . "amount='" . $amount . "', " . "amount_tax='" . $amount_tax . "', " . "amount_total='" . $amount_total . "', " . "amount_paid='" . $amount_paid . "' " . "WHERE id='" . $this->id_invoice . "' LIMIT 1"; } if (!$sql_obj->execute()) { log_debug("invoice_items", "A fatal SQL error occured whilst attempting to update invoice totals"); return 0; } /* Update the credit (if any) */ if ($this->type_invoice == "ar_credit" || $this->type_invoice == "ap_credit") { $credit = new credit(); $credit->id = $this->id_invoice; $credit->type = $this->type_invoice; $credit->load_data(); $credit->action_update_balance(); } return 1; }
function get_credit_pdf($id, $credittype) { log_debug('invoices_manage_soap', "Executing get_creditnote_pdf({$id}, {$credittype})"); // check the credit type if ($credittype != 'ar' && $credittype != 'ap') { throw new SoapFault('Sender', 'INVALID_CREDIT_TYPE'); } if (user_permissions_get('accounts_' . $credittype . '_view')) { $obj_credit = new credit(); $obj_credit->type = $credittype; // sanitise input $obj_credit->id = @security_script_input_predefined('int', $id); if (!$obj_credit->id || $obj_credit->id == 'error') { throw new SoapFault('Sender', 'INVALID_INPUT'); } // load data from DB for this credit note if (!$obj_credit->load_data()) { throw new SoapFault('Sender', 'UNEXPECTED_ACTION_ERROR'); } // generate PDF $obj_credit->generate_pdf(); // return data return base64_encode($obj_credit->obj_pdf->output); } else { throw new SoapFault('Sender', 'ACCESS_DENIED'); } }