From 1fd7fda645067c3a13c088f1393dc3818cf8820e Mon Sep 17 00:00:00 2001 From: jekkos Date: Thu, 8 Oct 2015 18:50:39 +0200 Subject: [PATCH] Fix totals calculation when adding item multiple times (issue #165) Fix typo in script comments --- application/libraries/Sale_lib.php | 64 ++++++++++++++++-------------- database/2.3.2_to_2.3.3.sql | 2 +- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 49816d831..baf4cba44 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -263,7 +263,7 @@ class Sale_lib $itemalreadyinsale=FALSE; //We did not find the item yet. $insertkey=0; //Key to use for new entry. $updatekey=0; //Key to use to update(quantity) - + $item_info=$this->CI->Item->get_info($item_id,$item_location); foreach ($items as $item) { //We primed the loop so maxkey is 0 the first time. @@ -277,46 +277,52 @@ class Sale_lib if($item['item_id']==$item_id && $item['item_location']==$item_location) { $itemalreadyinsale=TRUE; - $updatekey=$item['line']; + $updatekey = $item['line']; + if (!$item_info->is_serialized) + { + $quantity += $items[$updatekey]['quantity']; + } } } $insertkey=$maxkey+1; - $item_info=$this->CI->Item->get_info($item_id,$item_location); //array/cart records are identified by $insertkey and item_id is just another field. $price=$price!=null?$price:$item_info->unit_price; $total=$this->get_item_total($quantity, $price, $discount); - $item = array(($insertkey)=> - array( - 'item_id'=>$item_id, - 'item_location'=>$item_location, - 'stock_name'=>$this->CI->Stock_location->get_location_name($item_location), - 'line'=>$insertkey, - 'name'=>$item_info->name, - 'item_number'=>$item_info->item_number, - 'description'=>$description!=null ? $description: $item_info->description, - 'serialnumber'=>$serialnumber!=null ? $serialnumber: '', - 'allow_alt_description'=>$item_info->allow_alt_description, - 'is_serialized'=>$item_info->is_serialized, - 'quantity'=>$quantity, - 'discount'=>$discount, - 'in_stock'=>$this->CI->Item_quantity->get_item_quantity($item_id, $item_location)->quantity, - 'price'=>$price, - 'total'=>$total, - 'discounted_total'=>$this->get_item_total($quantity, $price, $discount, TRUE) - ) - ); - + $discounted_total=$this->get_item_total($quantity, $price, $discount, TRUE); //Item already exists and is not serialized, add to quantity - if($itemalreadyinsale && ($item_info->is_serialized ==0) ) - { - $items[$updatekey]['quantity']+=$quantity; - } - else + if(!$itemalreadyinsale || $item_info->is_serialized) { + $item = array(($insertkey)=> + array( + 'item_id'=>$item_id, + 'item_location'=>$item_location, + 'stock_name'=>$this->CI->Stock_location->get_location_name($item_location), + 'line'=>$insertkey, + 'name'=>$item_info->name, + 'item_number'=>$item_info->item_number, + 'description'=>$description!=null ? $description: $item_info->description, + 'serialnumber'=>$serialnumber!=null ? $serialnumber: '', + 'allow_alt_description'=>$item_info->allow_alt_description, + 'is_serialized'=>$item_info->is_serialized, + 'quantity'=>$quantity, + 'discount'=>$discount, + 'in_stock'=>$this->CI->Item_quantity->get_item_quantity($item_id, $item_location)->quantity, + 'price'=>$price, + 'total'=>$total, + 'discounted_total'=>$discounted_total + ) + ); //add to existing array $items+=$item; } + else + { + $line = &$items[$updatekey]; + $line['quantity'] = $quantity; + $line['total'] = $total; + $line['discounted_total'] = $discounted_total; + } $this->set_cart($items); return true; diff --git a/database/2.3.2_to_2.3.3.sql b/database/2.3.2_to_2.3.3.sql index bc1a92757..75efb89f7 100644 --- a/database/2.3.2_to_2.3.3.sql +++ b/database/2.3.2_to_2.3.3.sql @@ -8,7 +8,7 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ALTER TABLE `ospos_sales_suspended` DROP KEY `invoice_number`; --- Clear out emptied comments (0 inserted in comments if emtpy ##192) +-- Clear out emptied comments (0 inserted in comment if empty #192) UPDATE `ospos_sales` SET comment = NULL WHERE comment = '0'; UPDATE `ospos_receivings` SET comment = NULL WHERE comment = '0'; UPDATE `ospos_sales_suspended` SET comment = NULL WHERE comment = '0'; \ No newline at end of file