From b809585cf0244647799c9cecd52a380cb7ea32e0 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Tue, 8 Jul 2008 13:32:44 +0000 Subject: [PATCH] Fixed some bugs in sales module (see CHANGELOG.txt) --- CHANGELOG.txt | 13 ++++++++++ sales/customer_credit_invoice.php | 19 +++++++++++--- sales/customer_delivery.php | 32 +++++++++++++++-------- sales/customer_invoice.php | 34 ++++++++++++++++++++++--- sales/includes/cart_class.inc | 1 + sales/includes/db/sales_delivery_db.inc | 5 ++-- sales/includes/db/sales_invoice_db.inc | 12 ++++----- sales/includes/sales_db.inc | 2 +- 8 files changed, 92 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 75662a88..2801b07c 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,19 @@ Legend: ! -> Note $ -> Affected files +08-Jul-2008 Janusz Dobrowolski +# Added validation of entered quantities +$ /sales/customer_credit_invoice.php +# Fixed ajax update (0000015) and quantity checks +$ /sales/customer_delivery.php + /sales/customer_invoice.php +# Fixed invalid voiding sales invoice/delivery/credit (0000016) +$ /sales/includes/db/sales_delivery_db.inc + /sales/includes/db/sales_invoice_db.inc + /sales/includes/sales_db.inc +# Fixed setting document date to Today() +$ /sales/includes/cart_class.inc + 08-Jul-2008 Joe Hunt + Addition in test of duplicate fiscal year $ /admin/fiscalyears.php diff --git a/sales/customer_credit_invoice.php b/sales/customer_credit_invoice.php index 8d5a104a..16147a82 100644 --- a/sales/customer_credit_invoice.php +++ b/sales/customer_credit_invoice.php @@ -99,7 +99,10 @@ function can_process() set_focus('ChargeFreightCost'); return false; } - + if (!check_quantities()) { + display_error(_("Selected quantity cannot be less than zero nor more than quantity not credited yet.")); + return false; + } return true; } @@ -140,14 +143,23 @@ if (isset($_GET['InvoiceNumber']) && $_GET['InvoiceNumber'] > 0) { } elseif (!processing_active()) { /* This page can only be called with an invoice number for crediting*/ die (_("This page can only be opened if an invoice has been selected for crediting.")); -} else { +} elseif (!check_quantities()) { + display_error(_("Selected quantity cannot be less than zero nor more than quantity not credited yet.")); +} + +function check_quantities() +{ + $ok =1; foreach ($_SESSION['Items']->line_items as $line_no=>$itm) { if (isset($_POST['Line'.$line_no])) { - if (check_num('Line'.$line_no, ($itm->quantity - $itm->qty_done))) { + if (check_num('Line'.$line_no, 0, $itm->quantity))) { $_SESSION['Items']->line_items[$line_no]->qty_dispatched = input_num('Line'.$line_no); } } + else { + $ok = 0; + } if (isset($_POST['Line'.$line_no.'Desc'])) { $line_desc = $_POST['Line'.$line_no.'Desc']; @@ -156,6 +168,7 @@ if (isset($_GET['InvoiceNumber']) && $_GET['InvoiceNumber'] > 0) { } } } + return $ok; } //----------------------------------------------------------------------------- diff --git a/sales/customer_delivery.php b/sales/customer_delivery.php index fd20ebb0..8365cc81 100644 --- a/sales/customer_delivery.php +++ b/sales/customer_delivery.php @@ -73,7 +73,7 @@ if (isset($_GET['AddedID'])) { if (isset($_GET['OrderNumber']) && $_GET['OrderNumber'] > 0) { - $ord = new Cart(30,$_GET['OrderNumber'], true); + $ord = new Cart(30, $_GET['OrderNumber'], true); /*read in all the selected order into the Items cart */ @@ -104,7 +104,7 @@ if (isset($_GET['OrderNumber']) && $_GET['OrderNumber'] > 0) { } copy_from_cart(); - + } elseif ( !processing_active() ) { /* This page can only be called with an order number for invoicing*/ @@ -188,7 +188,7 @@ function copy_to_cart() $cart = &$_SESSION['Items']; $cart->ship_via = $_POST['ship_via']; $cart->freight_cost = input_num('ChargeFreightCost'); - $cart->document_date = $_POST['DispatchDate']; + $cart->document_date = $_POST['DispatchDate']; $cart->due_date = $_POST['due_date']; $cart->Location = $_POST['Location']; $cart->Comments = $_POST['Comments']; @@ -203,10 +203,10 @@ function copy_from_cart() $cart = &$_SESSION['Items']; $_POST['ship_via'] = $cart->ship_via; $_POST['ChargeFreightCost'] = price_format($cart->freight_cost); - $_POST['DispatchDate']= $cart->document_date; + $_POST['DispatchDate'] = $cart->document_date; $_POST['due_date'] = $cart->due_date; - $_POST['Location']= $cart->Location; - $_POST['Comments']= $cart->Comments; + $_POST['Location'] = $cart->Location; + $_POST['Comments'] = $cart->Comments; } //------------------------------------------------------------------------------ @@ -216,10 +216,19 @@ function check_quantities() // Update cart delivery quantities/descriptions foreach ($_SESSION['Items']->line_items as $line=>$itm) { if (isset($_POST['Line'.$line])) { - if (!check_num('Line'.$line, $itm->qty_done, $itm->quantity) == 0) { + if($_SESSION['Items']->trans_no) { + $min = $itm->qty_done; + $max = $itm->quantity; + } else { + $min = 0; + $max = $itm->quantity - $itm->qty_done; + } + + if (check_num('Line'.$line, $min, $max)) { $_SESSION['Items']->line_items[$line]->qty_dispatched = input_num('Line'.$line); } else { + set_focus('Line'.$line); $ok = 0; } @@ -281,6 +290,9 @@ if (isset($_POST['process_delivery']) && check_data() && check_qoh()) { } } +if (isset($_POST['Update']) || isset($_POST['_Location_update'])) { + $Ajax->activate('Items'); +} //------------------------------------------------------------------------------ start_form(false, true); @@ -314,7 +326,7 @@ if (!isset($_POST['Location'])) { $_POST['Location'] = $_SESSION['Items']->Location; } label_cell(_("Delivery From"), "class='tableheader2'"); -locations_list_cells(null, 'Location',$_POST['Location'], false, true); +locations_list_cells(null, 'Location', null, false, true); if (!isset($_POST['ship_via'])) { $_POST['ship_via'] = $_SESSION['Items']->ship_via; @@ -348,7 +360,7 @@ echo ""; end_table(1); // outer table display_heading(_("Delivery Items")); - +div_start('Items'); start_table("$table_style width=80%"); $th = array(_("Item Code"), _("Item Description"), _("Ordered"), _("Units"), _("Delivered"), _("This Delivery"), _("Price"), _("Tax Type"), _("Discount"), _("Total")); @@ -435,7 +447,7 @@ policy_list_row(_("Action For Balance"), "bo_policy", null); textarea_row(_("Memo"), 'Comments', null, 50, 4); end_table(1); - +div_end(); submit_center_first('Update', _("Update"), _('Refresh document page'), true); submit_center_last('process_delivery', _("Process Dispatch"), diff --git a/sales/customer_invoice.php b/sales/customer_invoice.php index 540b4515..ac2e75e5 100644 --- a/sales/customer_invoice.php +++ b/sales/customer_invoice.php @@ -136,13 +136,33 @@ if ( (isset($_GET['DeliveryNumber']) && ($_GET['DeliveryNumber'] > 0) ) end_page(); exit; -} else { +} elseif (!check_quantities()) { + display_error(_("Selected quantity cannot be less than quantity credited nor more than quantity not invoiced yet.")); +} +if (isset($_POST['Update'])) { + $Ajax->activate('Items'); +} +//----------------------------------------------------------------------------- +function check_quantities() +{ + $ok =1; foreach ($_SESSION['Items']->line_items as $line_no=>$itm) { if (isset($_POST['Line'.$line_no])) { - if (!check_num('Line'.$line_no, 0, ($itm->quantity - $itm->qty_done))) { + if($_SESSION['Items']->trans_no) { + $min = $itm->qty_done; + $max = $itm->quantity; + } else { + $min = 0; + $max = $itm->quantity - $itm->qty_done; + } + if (check_num('Line'.$line_no, $min, $max)) { $_SESSION['Items']->line_items[$line_no]->qty_dispatched = input_num('Line'.$line_no); } + else { + $ok = 0; + } + } if (isset($_POST['Line'.$line_no.'Desc'])) { @@ -152,8 +172,8 @@ if ( (isset($_GET['DeliveryNumber']) && ($_GET['DeliveryNumber'] > 0) ) } } } + return $ok; } -//----------------------------------------------------------------------------- function copy_to_cart() { @@ -227,6 +247,11 @@ function check_data() return false; } + if (!check_quantities()) { + display_error(_("Selected quantity cannot be less than quantity credited nor more than quantity not invoiced yet.")); + return false; + } + return true; } @@ -321,6 +346,7 @@ end_table(); display_heading(_("Invoice Items")); +div_start('Items'); start_table("$table_style width=80%"); $th = array(_("Item Code"), _("Item Description"), _("Delivered"), _("Units"), _("Invoiced"), _("This Invoice"), _("Price"), _("Tax Type"), _("Discount"), _("Total")); @@ -423,9 +449,9 @@ $display_total = price_format(($inv_items_total + input_num('ChargeFreightCost') label_row(_("Invoice Total"), $display_total, "colspan=9 align=right","align=right", $is_batch_invoice ? 2 : 0); end_table(1); +div_end(); start_table($table_style2); - textarea_row(_("Memo"), 'Comments', null, 50, 4); end_table(1); diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index 00332e09..38ffeba7 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -84,6 +84,7 @@ class cart $line = &$this->line_items[$line_no]; $line->qty_dispatched = $line->quantity - $line->qty_done; } + $this->document_date = Today(); } } else { // derivative transaction read_sales_trans($type, $trans_no, $this); diff --git a/sales/includes/db/sales_delivery_db.inc b/sales/includes/db/sales_delivery_db.inc index 71d5ca88..c216a572 100644 --- a/sales/includes/db/sales_delivery_db.inc +++ b/sales/includes/db/sales_delivery_db.inc @@ -128,15 +128,16 @@ function void_sales_delivery($type, $type_no) void_gl_trans($type, $type_no, true); - // for invoices and credits related to invoices, // reverse all the changes in the sales order $items_result = get_customer_trans_details($type, $type_no); $order = get_customer_trans_order($type, $type_no); if ($order) { + $order_items = get_sales_order_details($order); while ($row = db_fetch($items_result)) { - update_parent_line(13, $row['id'], -$row['quantity']); + $order_line = db_fetch($order_items); + update_parent_line(13, $order_line['id'], -$row['quantity']); } } diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index 8270ea6e..4bf6ee48 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -163,18 +163,18 @@ function void_sales_invoice($type, $type_no) void_bank_trans($type, $type_no, true); void_gl_trans($type, $type_no, true); - // for invoices and credits related to invoices, - // reverse all the changes in the sales order + // reverse all the changes in parent document(s) $items_result = get_customer_trans_details($type, $type_no); - $delivery = get_customer_trans_link($type, $type_no); + $deliveries = get_parent_trans($type, $type_no); - if ($delivery) { + if (count($deliveries)) { + $srcdetails = get_customer_trans_details(get_parent_type($type), $deliveries); while ($row = db_fetch($items_result)) { - update_parent_line(10, $row['id'], -$row['quantity']); + $src_line = db_fetch($srcdetails); + update_parent_line(10, $src_line['id'], -$row['quantity']); } } - // clear details after they've been reversed in the sales order void_customer_trans_details($type, $type_no); diff --git a/sales/includes/sales_db.inc b/sales/includes/sales_db.inc index acdc245c..f368b402 100644 --- a/sales/includes/sales_db.inc +++ b/sales/includes/sales_db.inc @@ -169,7 +169,7 @@ function update_parent_line($doc_type, $line_id, $qty_dispatched) { $doc_type = get_parent_type($doc_type); - //echo "update line: $line_id, $doc_type, $qty_dispatch"; +// echo "update line: $line_id, $doc_type, $qty_dispatched"; if ($doc_type==0) return false; else { -- 2.30.2