From: Joe Hunt Date: Wed, 2 May 2012 16:57:36 +0000 (+0200) Subject: Better check for duplicate references in multiuser environments for sales documents. X-Git-Tag: 2.3-final~453 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=acbb281bf6915bfccd6798b12eae1fd7d60f63c6;p=fa-stable.git Better check for duplicate references in multiuser environments for sales documents. --- diff --git a/sales/create_recurrent_invoices.php b/sales/create_recurrent_invoices.php index fc4312c6..15b71d8e 100644 --- a/sales/create_recurrent_invoices.php +++ b/sales/create_recurrent_invoices.php @@ -50,6 +50,11 @@ function create_recurrent_invoices($customer_id, $branch_id, $order_no, $tmpl_no $cart->trans_type = ST_SALESINVOICE; $cart->reference = $Refs->get_next($cart->trans_type); $invno = $cart->write(1); + if ($invno == -1) + { + display_error(_("The entered reference is already in use.")); + display_footer_exit(); + } update_last_sent_recurrent_invoice($tmpl_no, $to); return $invno; } diff --git a/sales/credit_note_entry.php b/sales/credit_note_entry.php index de84ba09..70148e81 100644 --- a/sales/credit_note_entry.php +++ b/sales/credit_note_entry.php @@ -144,14 +144,10 @@ function can_process() return false; if($_SESSION['Items']->trans_no == 0) { if (!$Refs->is_valid($_POST['ref'])) { - display_error( _("You must enter a reference.")); - set_focus('ref'); - $input_error = 1; - } elseif (!is_new_reference($_POST['ref'], ST_CUSTCREDIT)) { - display_error( _("The entered reference is already in use.")); - set_focus('ref'); - $input_error = 1; - } + display_error( _("You must enter a reference.")); + set_focus('ref'); + $input_error = 1; + } } if (!is_date($_POST['OrderDate'])) { display_error(_("The entered date for the credit note is invalid.")); @@ -174,17 +170,23 @@ if (isset($_POST['ProcessCredit']) && can_process()) { display_note(_("For credit notes created to write off the stock, a general ledger account is required to be selected."), 1, 0); display_note(_("Please select an account to write the cost of the stock off to, then click on Process again."), 1, 0); exit; - } if (!isset($_POST['WriteOffGLCode'])) { $_POST['WriteOffGLCode'] = 0; } copy_to_cn(); $credit_no = $_SESSION['Items']->write($_POST['WriteOffGLCode']); - new_doc_date($_SESSION['Items']->document_date); - processing_end(); - meta_forward($_SERVER['PHP_SELF'], "AddedID=$credit_no"); - + if ($credit_no == -1) + { + display_error(_("The entered reference is already in use.")); + set_focus('ref'); + } + else + { + new_doc_date($_SESSION['Items']->document_date); + processing_end(); + meta_forward($_SERVER['PHP_SELF'], "AddedID=$credit_no"); + } } /*end of process credit note */ //----------------------------------------------------------------------------- diff --git a/sales/customer_credit_invoice.php b/sales/customer_credit_invoice.php index 18318e56..59e454ef 100644 --- a/sales/customer_credit_invoice.php +++ b/sales/customer_credit_invoice.php @@ -104,11 +104,6 @@ function can_process() return false; } - if (!is_new_reference($_POST['ref'], ST_CUSTCREDIT)) { - display_error(_("The entered reference is already in use."));; - set_focus('ref'); - return false; - } } if (!check_num('ChargeFreightCost', 0)) { display_error(_("The entered shipping cost is invalid or less than zero."));; @@ -196,22 +191,25 @@ function copy_from_cart() //----------------------------------------------------------------------------- if (isset($_POST['ProcessCredit']) && can_process()) { + $new_credit = ($_SESSION['Items']->trans_no == 0); - $new_credit = ($_SESSION['Items']->trans_no == 0); - - if (!isset($_POST['WriteOffGLCode'])) + if (!isset($_POST['WriteOffGLCode'])) $_POST['WriteOffGLCode'] = 0; copy_to_cart(); - if ($new_credit) new_doc_date($_SESSION['Items']->document_date); - $credit_no = $_SESSION['Items']->write($_POST['WriteOffGLCode']); - - if($credit_no) { + if ($new_credit) + new_doc_date($_SESSION['Items']->document_date); + $credit_no = $_SESSION['Items']->write($_POST['WriteOffGLCode']); + if ($credit_no == -1) + { + display_error(_("The entered reference is already in use.")); + set_focus('ref'); + } elseif($credit_no) { processing_end(); if ($new_credit) { - meta_forward($_SERVER['PHP_SELF'], "AddedID=$credit_no"); + meta_forward($_SERVER['PHP_SELF'], "AddedID=$credit_no"); } else { - meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$credit_no"); + meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$credit_no"); } } } diff --git a/sales/customer_delivery.php b/sales/customer_delivery.php index 30e35919..eb78f62e 100644 --- a/sales/customer_delivery.php +++ b/sales/customer_delivery.php @@ -167,12 +167,6 @@ function check_data() set_focus('ref'); return false; } - - if ($_SESSION['Items']->trans_no==0 && !is_new_reference($_POST['ref'], ST_CUSTDELIVERY)) { - display_error(_("The entered reference is already in use.")); - set_focus('ref'); - return false; - } } if ($_POST['ChargeFreightCost'] == "") { $_POST['ChargeFreightCost'] = price_format(0); @@ -301,7 +295,6 @@ function check_qoh() //------------------------------------------------------------------------------ if (isset($_POST['process_delivery']) && check_data() && check_qoh()) { - $dn = &$_SESSION['Items']; if ($_POST['bo_policy']) { @@ -314,13 +307,20 @@ if (isset($_POST['process_delivery']) && check_data() && check_qoh()) { copy_to_cart(); if ($newdelivery) new_doc_date($dn->document_date); $delivery_no = $dn->write($bo_policy); - - processing_end(); - if ($newdelivery) { - meta_forward($_SERVER['PHP_SELF'], "AddedID=$delivery_no"); - } else { - meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$delivery_no"); + if ($delivery_no == -1) + { + display_error(_("The entered reference is already in use.")); + set_focus('ref'); } + else + { + processing_end(); + if ($newdelivery) { + meta_forward($_SERVER['PHP_SELF'], "AddedID=$delivery_no"); + } else { + meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$delivery_no"); + } + } } if (isset($_POST['Update']) || isset($_POST['_Location_update'])) { diff --git a/sales/customer_invoice.php b/sales/customer_invoice.php index 9c9e171b..b2499485 100644 --- a/sales/customer_invoice.php +++ b/sales/customer_invoice.php @@ -281,12 +281,6 @@ function check_data() set_focus('ref'); return false; } - - if (!is_new_reference($_POST['ref'], 10)) { - display_error(_("The entered reference is already in use.")); - set_focus('ref'); - return false; - } } if ($_POST['ChargeFreightCost'] == "") { @@ -314,19 +308,27 @@ function check_data() //----------------------------------------------------------------------------- if (isset($_POST['process_invoice']) && check_data()) { - $newinvoice= $_SESSION['Items']->trans_no == 0; copy_to_cart(); - if ($newinvoice) new_doc_date($_SESSION['Items']->document_date); + if ($newinvoice) + new_doc_date($_SESSION['Items']->document_date); $invoice_no = $_SESSION['Items']->write(); - processing_end(); - - if ($newinvoice) { - meta_forward($_SERVER['PHP_SELF'], "AddedID=$invoice_no"); - } else { - meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$invoice_no"); + if ($invoice_no == -1) + { + display_error(_("The entered reference is already in use.")); + set_focus('ref'); } + else + { + processing_end(); + + if ($newinvoice) { + meta_forward($_SERVER['PHP_SELF'], "AddedID=$invoice_no"); + } else { + meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$invoice_no"); + } + } } if(list_updated('payment')) { diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index cc7d1567..63309367 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -260,6 +260,11 @@ class cart $this->due_date = $due_date; } $this->reference = @html_entity_decode($this->reference, ENT_QUOTES); + if ($this->reference != 'auto' && $this->trans_no == 0 && !is_new_reference($this->reference, $this->trans_type)) + { + commit_transaction(); + return -1; + } $this->Comments = @html_entity_decode($this->Comments, ENT_QUOTES); foreach($this->line_items as $lineno => $line) { $this->line_items[$lineno]->stock_id = @html_entity_decode($line->stock_id, ENT_QUOTES); diff --git a/sales/sales_order_entry.php b/sales/sales_order_entry.php index fd9723df..af29a1dd 100644 --- a/sales/sales_order_entry.php +++ b/sales/sales_order_entry.php @@ -404,12 +404,8 @@ function can_process() { set_focus('ref'); return false; } - if ($_SESSION['Items']->trans_no==0 && !is_new_reference($_POST['ref'], - $_SESSION['Items']->trans_type)) { - display_error(_("The entered reference is already in use.")); - set_focus('ref'); - return false; - } elseif ($_SESSION['Items']->get_items_total() < 0) { + + if ($_SESSION['Items']->get_items_total() < 0) { display_error("Invoice total amount cannot be less than zero."); return false; } @@ -427,30 +423,38 @@ if (isset($_POST['ProcessOrder']) && can_process()) { copy_to_cart(); $modified = ($_SESSION['Items']->trans_no != 0); $so_type = $_SESSION['Items']->so_type; - - $_SESSION['Items']->write(1); - if (count($messages)) { // abort on failure or error messages are lost - $Ajax->activate('_page_body'); - display_footer_exit(); - } - $trans_no = key($_SESSION['Items']->trans_no); - $trans_type = $_SESSION['Items']->trans_type; - new_doc_date($_SESSION['Items']->document_date); - processing_end(); - if ($modified) { - if ($trans_type == ST_SALESQUOTE) - meta_forward($_SERVER['PHP_SELF'], "UpdatedQU=$trans_no"); - else - meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$trans_no"); - } elseif ($trans_type == ST_SALESORDER) { - meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no"); - } elseif ($trans_type == ST_SALESQUOTE) { - meta_forward($_SERVER['PHP_SELF'], "AddedQU=$trans_no"); - } elseif ($trans_type == ST_SALESINVOICE) { - meta_forward($_SERVER['PHP_SELF'], "AddedDI=$trans_no&Type=$so_type"); - } else { - meta_forward($_SERVER['PHP_SELF'], "AddedDN=$trans_no&Type=$so_type"); + + $ret = $_SESSION['Items']->write(1); + if ($ret == -1) + { + display_error(_("The entered reference is already in use.")); + set_focus('ref'); } + else + { + if (count($messages)) { // abort on failure or error messages are lost + $Ajax->activate('_page_body'); + display_footer_exit(); + } + $trans_no = key($_SESSION['Items']->trans_no); + $trans_type = $_SESSION['Items']->trans_type; + new_doc_date($_SESSION['Items']->document_date); + processing_end(); + if ($modified) { + if ($trans_type == ST_SALESQUOTE) + meta_forward($_SERVER['PHP_SELF'], "UpdatedQU=$trans_no"); + else + meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$trans_no"); + } elseif ($trans_type == ST_SALESORDER) { + meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no"); + } elseif ($trans_type == ST_SALESQUOTE) { + meta_forward($_SERVER['PHP_SELF'], "AddedQU=$trans_no"); + } elseif ($trans_type == ST_SALESINVOICE) { + meta_forward($_SERVER['PHP_SELF'], "AddedDI=$trans_no&Type=$so_type"); + } else { + meta_forward($_SERVER['PHP_SELF'], "AddedDN=$trans_no&Type=$so_type"); + } + } } //--------------------------------------------------------------------------------