mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-05-24 16:28:40 -04:00
Bug #25: Deleting a sale/receiving would not effect the stock/quantity.
This commit is contained in:
@@ -47,5 +47,20 @@ class Item_quantities extends CI_Model
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*
|
||||
* changes to quantity of an item according to the given amount.
|
||||
* if $quantity_change is negative, it will be subtracted,
|
||||
* if it is positive, it will be added to the current quantity
|
||||
*/
|
||||
function change_quantity($item_id, $location_id, $quantity_change)
|
||||
{
|
||||
$quantity_old = $this->get_item_quantity($item_id, $location_id);
|
||||
$quantity_new = $quantity_old->quantity + intval($quantity_change);
|
||||
$location_detail = array('item_id'=>$item_id,
|
||||
'location_id'=>$location_id,
|
||||
'quantity'=>$quantity_new);
|
||||
return $this->save($location_detail,$item_id,$location_id);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -137,11 +137,17 @@ class Receiving extends CI_Model
|
||||
'trans_items'=>$item['item_id'],
|
||||
'trans_user'=>$employee_id,
|
||||
'trans_comment'=>'Deleting sale ' . $receiving_id,
|
||||
'trans_inventory'=>$item['quantity_purchased']
|
||||
'trans_location'=>$item['item_location'],
|
||||
'trans_inventory'=>$item['quantity_purchased']*-1
|
||||
|
||||
);
|
||||
// update inventory
|
||||
$this->Inventory->insert($inv_data);
|
||||
|
||||
// update quantities
|
||||
$this->Item_quantities->change_quantity($item['item_id'],
|
||||
$item['item_location'],
|
||||
$item['quantity_purchased']*-1);
|
||||
}
|
||||
}
|
||||
// delete all items
|
||||
|
||||
@@ -184,11 +184,17 @@ class Sale extends CI_Model
|
||||
'trans_items'=>$item['item_id'],
|
||||
'trans_user'=>$employee_id,
|
||||
'trans_comment'=>'Deleting sale ' . $sale_id,
|
||||
'trans_inventory'=>$item['quantity_purchased']
|
||||
'trans_location'=>$item['item_location'],
|
||||
'trans_inventory'=>$item['quantity_purchased']*-1
|
||||
|
||||
);
|
||||
// update inventory
|
||||
$this->Inventory->insert($inv_data);
|
||||
|
||||
// update quantities
|
||||
$this->Item_quantities->change_quantity($item['item_id'],
|
||||
$item['item_location'],
|
||||
$item['quantity_purchased']*-1);
|
||||
}
|
||||
}
|
||||
// delete all items
|
||||
|
||||
Reference in New Issue
Block a user