function credit_form_details_process($type, $mode, $returnpage_error, $returnpage_success) { log_debug("inc_credits_forms", "Executing credit_form_details_process({$type}, {$mode}, {$returnpage_error}, {$returnpage_success})"); // TODO: it seems this function requests the $mode, but then works it out itself anyway. // check out what is going on here. /* Start the credit */ $credit = new credit(); $credit->type = $type; /* Fetch all form data */ // get the ID for an edit if ($mode == "edit") { $credit->id = @security_form_input_predefined("int", "id_credit", 1, ""); } // general details if ($type == "ap_credit") { $credit->data["vendorid"] = @security_form_input_predefined("int", "vendorid", 1, ""); } else { $credit->data["customerid"] = @security_form_input_predefined("int", "customerid", 1, ""); } $credit->data["invoiceid"] = @security_form_input_predefined("int", "invoiceid", 1, ""); $credit->data["employeeid"] = @security_form_input_predefined("int", "employeeid", 1, ""); $credit->data["notes"] = @security_form_input_predefined("any", "notes", 0, ""); $credit->data["code_ordernumber"] = @security_form_input_predefined("any", "code_ordernumber", 0, ""); $credit->data["code_ponumber"] = @security_form_input_predefined("any", "code_ponumber", 0, ""); $credit->data["date_trans"] = @security_form_input_predefined("date", "date_trans", 1, ""); // other $credit->data["dest_account"] = @security_form_input_predefined("int", "dest_account", 1, ""); // are we editing an existing credit or adding a new one? if ($credit->id) { $mode = "edit"; // make sure the credit actually exists if (!$credit->verify_credit()) { log_write("error", "process", "The credit you have attempted to edit - " . $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 can not be edited because it is locked."); } } else { $mode = "add"; } // credit must be provided by edit page, but not by add credit, since we can just generate a new one if ($mode == "add") { $credit->data["code_credit"] = @security_form_input_predefined("any", "code_credit", 0, ""); } else { $credit->data["code_credit"] = @security_form_input_predefined("any", "code_credit", 1, ""); } //// ERROR CHECKING /////////////////////// // make sure we don't choose a credit credit number that is already in use if ($credit->data["code_credit"]) { $credit->prepare_code_credit($credit->data["code_credit"]); } /// if there was an error, go back to the entry page if ($_SESSION["error"]["message"]) { $_SESSION["error"]["form"][$type . "_credit_" . $mode] = "failed"; header("Location: ../../index.php?page={$returnpage_error}&id=" . $credit->id . ""); exit(0); } else { // GENERATE INVOICE ID // if no credit ID has been supplied, we now need to generate a unique credit id if (!$credit->data["code_credit"]) { $credit->prepare_code_credit(); config_generate_uniqueid("ACCOUNTS_CREDIT_NUM", "SELECT id FROM account_" . $credit->type . " WHERE code_credit='VALUE'"); } // APPLY GENERAL OPTIONS if ($mode == "add") { // create a new credit if ($credit->action_create()) { log_write("process", "notification", "Credit note successfully created"); journal_quickadd_event("account_" . $credit->type . "", $credit->id, "Credit Note successfully created"); } else { log_write("process", "error", "An unexpected fault occured whilst attempting to create the credit note"); } // display items page $returnpage_success = str_replace("view", "items", $returnpage_success); header("Location: ../../index.php?page={$returnpage_success}&id=" . $credit->id . ""); } else { // update an existing credit if ($credit->action_update()) { log_write("process", "notification", "Credit note successfully updated."); journal_quickadd_event("account_" . $credit->type . "", $credit->id, "Credit note successfully updated"); } else { log_write("process", "error", "An unexpected fault occured whilst attempting to update the credit note"); } // display updated details header("Location: ../../index.php?page={$returnpage_success}&id=" . $credit->id . ""); } exit(0); } // end if passed tests }