Optional switch in config file for sorting document lines by item code during new...
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 7 May 2013 13:11:25 +0000 (15:11 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Wed, 8 May 2013 05:33:37 +0000 (07:33 +0200)
config.default.php
sales/includes/cart_class.inc

index 56b5c88e755bee8a642bd7a131b9eed0ca34126a..d952c54cafa501eb355853ce3b97cbf0df972537 100644 (file)
@@ -281,4 +281,8 @@ $login_max_attempts = 10;
 $xr_providers = array("ECB", "YAHOO", "GOOGLE", "BLOOMBERG");
 $dflt_xr_provider = 0;
 
-?>
\ No newline at end of file
+/*
+       Optional sorting new sales documents lines according to item code
+*/
+$sort_sales_items = false;
+?>
index 4b01809feba94a838edcec70a395ef0c93241c61..9b8c27edf86573716a4b81aa8bff5934615a644c 100644 (file)
@@ -92,7 +92,22 @@ class cart
                $this->read($type, $trans_no, $prep_child);
                $this->cart_id = uniqid('');
        }
-       
+
+       /*
+               Optional sorting items by stock_id.
+       */
+       function _cmp_lines($a, $b)
+       {
+               return strcmp($a->stock_id, $b->stock_id);
+       }
+
+       function sort_items()
+       {
+               global $sort_sales_items;
+
+               if (@$sort_sales_items && !$this->trans_no) // sort items optionally for new transaction
+                       usort($this->line_items, array($this, '_cmp_lines'));
+       }
        //
        //      Prepare cart to new child document entry, just after initial parent doc read.
        //
@@ -351,6 +366,7 @@ class cart
 
                if ($line->valid) {
                        $this->line_items[$line_no] = $line;
+                       $this->sort_items();
                        return 1;
                } else
                        display_error(_("You have to enter valid stock code or nonempty description"));
@@ -365,6 +381,7 @@ class cart
                $this->line_items[$line_no]->qty_dispatched = $qty;
                $this->line_items[$line_no]->price = $price;
                $this->line_items[$line_no]->discount_percent = $disc;
+               $this->sort_items();
        }
 
        function update_add_cart_item_qty($line_no, $qty)