From: Janusz Dobrowolski Date: Tue, 7 May 2013 13:11:25 +0000 (+0200) Subject: Optional switch in config file for sorting document lines by item code during new... X-Git-Tag: 2.3-final~259 X-Git-Url: https://delta.frontaccounting.com/gitweb/?p=fa-stable.git;a=commitdiff_plain;h=6d3e1d19bf8d2a19f6b39a90f76566846675deef Optional switch in config file for sorting document lines by item code during new Sales Order/Direct Delivery/Direct Invoice entry. --- diff --git a/config.default.php b/config.default.php index 56b5c88e..d952c54c 100644 --- a/config.default.php +++ b/config.default.php @@ -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; +?> diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index 4b01809f..9b8c27ed 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -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)