$x++; } // error check input if (!$order->bill_acct_id) { // no account was selected, error $messageStack->add(constant('BNK_' . JOURNAL_ID . '_ERROR_NO_VENDOR'), 'error'); $error = true; } if (!$order->item_rows) { $messageStack->add(GL_ERROR_NO_ITEMS, 'error'); $error = true; } // check to make sure the payment method is valid if (JOURNAL_ID == 18) { $payment_module = $order->shipper_code; $payment_module = load_service_module('payment', $payment_module); if (class_exists($payment_module)) { $processor = new $payment_module(); if (!$processor->check()) { $error = true; } if ($processor->pre_confirmation_check()) { $error = true; } } } /* This has been commented out to allow customer refunds (negative invoices) if ($order->total_amount < 0) { $messageStack->add(constant('BNK_' . JOURNAL_ID . '_NEGATIVE_TOTAL'),'error'); $error = true; }
function load_service_modules($module_type) { global $PHP_SELF; $file_extension = substr($PHP_SELF, strrpos($PHP_SELF, '.')); $directory_array = array(); $standard_module_dir = DIR_WS_MODULES . 'services/' . $module_type . '/modules/'; // standard modules if ($dir = @dir($standard_module_dir)) { while ($file = $dir->read()) { if (!is_dir($standard_module_dir . $file)) { if (substr($file, strrpos($file, '.')) == $file_extension) { $modules_names[] = substr($file, 0, strrpos($file, '.')); } } } $dir->close(); } // custom modules $custom_module_dir = DIR_FS_MY_FILES . 'custom/services/' . $module_type . '/modules/'; if ($dir = @dir($custom_module_dir)) { while ($file = $dir->read()) { if (!is_dir($custom_module_dir . $file)) { if (substr($file, strrpos($file, '.')) == $file_extension) { $modules_names[] = substr($file, 0, strrpos($file, '.')); } } } $dir->close(); } sort($modules_names); $class = array(); foreach ($modules_names as $module_name) { $class[] = load_service_module($module_type, $module_name); } return $class; }
function post_ordr($action) { global $db, $currencies, $messageStack, $processor; $this->journal_main_array = $this->build_journal_main_array(); // build ledger main record $this->journal_rows = array(); // initialize ledger row(s) array switch ($this->journal_id) { case 18: // Cash Receipts Journal $module = isset($this->shipper_code) ? $this->shipper_code : 'freecharger'; $module = load_service_module('payment', $module); if (class_exists($module)) { $processor = new $module(); if (!$processor->check()) { return false; } } $result = $this->add_item_journal_rows('credit'); // read in line items and add to journal row array $credit_total = $result['total']; $debit_total = $this->add_discount_journal_row('debit'); $debit_total += $this->add_total_journal_row('debit', $result['total'] - $result['discount']); break; case 20: // Cash Disbursements Journal $result = $this->add_item_journal_rows('debit'); // read in line items and add to journal row array $debit_total = $result['total']; $credit_total = $this->add_discount_journal_row('credit'); $credit_total += $this->add_total_journal_row('credit', $result['total'] - $result['discount']); break; default: return $this->fail_message('bad journal_id in banking pre-POST processing'); // this should never happen, JOURNAL_ID is tested at script entry! } // ***************************** START TRANSACTION ******************************* $db->transStart(); // ************* Pre-POST processing ************* if (!$this->validate_purchase_invoice_id()) { return false; } // ************* POST journal entry ************* if ($this->id) { // it's an edit, first unPost record, then rewrite if (!$this->Post($new_post = 'edit')) { return false; } $messageStack->add(BNK_REPOST_PAYMENT, 'caution'); } else { if (!$this->Post($new_post = 'insert')) { return false; } } // ************* post-POST processing ************* switch ($this->journal_id) { case 18: // case 19: if ($this->purchase_invoice_id == '') { // it's a new record, increment the po/so/inv to next number if (!$this->increment_purchase_invoice_id()) { return false; } } // Lastly, we process the payment (for receipts). NEEDS TO BE AT THE END BEFORE THE COMMIT!!! // Because, if an error here we need to back out the entire post (which we can), but if // the credit card has been processed and the post fails, there is no way to back out the credit card charge. if ($processor->pre_confirmation_check()) { return false; } // Update the save payment/encryption data if requested if (ENABLE_ENCRYPTION && $this->save_payment && $processor->enable_encryption !== false) { if (!$this->encrypt_payment($module, $processor->enable_encryption)) { return false; } } if ($processor->before_process()) { return false; } if ($processor->after_process()) { return false; } break; case 20: // case 21: if ($new_post == 'insert') { // only increment if posting a new payment if (!$this->increment_purchase_invoice_id($force = true)) { return false; } } break; default: } $db->transCommit(); // finished successfully // ***************************** END TRANSACTION ******************************* $this->session_message(constant('BNK_' . $this->journal_id . '_POST_SUCCESSFUL') . $this->purchase_invoice_id, 'success'); return true; }