Fixed some bugs in sales module (see CHANGELOG.txt)
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 8 Jul 2008 13:32:44 +0000 (13:32 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 8 Jul 2008 13:32:44 +0000 (13:32 +0000)
CHANGELOG.txt
sales/customer_credit_invoice.php
sales/customer_delivery.php
sales/customer_invoice.php
sales/includes/cart_class.inc
sales/includes/db/sales_delivery_db.inc
sales/includes/db/sales_invoice_db.inc
sales/includes/sales_db.inc

index 75662a8817fe9f3a54b2e82a85b3453ebc1c8685..2801b07cae770c3dac6e0bd4cc643b752ba0fb47 100644 (file)
@@ -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
index 8d5a104a459e80029a88d176b21ea26f38814645..16147a82ad42a6d2eda9039fcad56f13360ec348 100644 (file)
@@ -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;
 }
 //-----------------------------------------------------------------------------
 
index fd20ebb05a88386572a802770ca8d8119d440389..8365cc819a4e1bc0f2cb77fc6af1e61d59247d9e 100644 (file)
@@ -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 "</td></tr>";
 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"),
index 540b45156909215ddd2a1ef430e7ca5bb9c1fcb2..ac2e75e5096942524f1cee56fe985376a7cb241b 100644 (file)
@@ -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);
index 00332e09f70b400fa5dfe17ed7b6055881700220..38ffeba76be1147b2bb0dc9bff49cb59e741dfdf 100644 (file)
@@ -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);
index 71d5ca8856c5f68b04c2dc613b57ecafead0726a..c216a572c6ff50a86aebb001807314b8e8655939 100644 (file)
@@ -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']);
                }
        }
 
index 8270ea6eaf3f92c2d9d7f9cc72f4556fece6dfd5..4bf6ee48bde98b1e2aa3638aa6bc7c75732d0e19 100644 (file)
@@ -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);
 
index acdc245cc0acca3be287c904422dd41ed11135f0..f368b402180d1c1ba544e4e27e6e24ebad6e306b 100644 (file)
@@ -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 {