Fix totals calculation when adding item multiple times (issue #165)

Fix typo in script comments
This commit is contained in:
jekkos
2015-10-08 18:50:39 +02:00
parent 3eb798917d
commit 1fd7fda645
2 changed files with 36 additions and 30 deletions

View File

@@ -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;

View File

@@ -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';