mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-05-04 13:54:51 -04:00
Reset stock inventory when deleting items (#1288)
This commit is contained in:
@@ -18,5 +18,34 @@ class Inventory extends CI_Model
|
||||
|
||||
return $this->db->get();
|
||||
}
|
||||
|
||||
public function reset_quantity($item_id)
|
||||
{
|
||||
$inventory_sums = $this->Inventory->get_inventory_sum($item_id);
|
||||
foreach($inventory_sums as $inventory_sum)
|
||||
{
|
||||
if ($inventory_sum['sum'] > 0)
|
||||
{
|
||||
return $this->Inventory->insert(array(
|
||||
'trans_inventory' => -1 * $inventory_sum['sum'],
|
||||
'trans_items' => $item_id,
|
||||
'trans_location' => $inventory_sum['location_id'],
|
||||
'trans_comment' => $this->lang->line('items_is_deleted'),
|
||||
'trans_user' => $this->Employee->get_logged_in_employee_info()->person_id)
|
||||
);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function get_inventory_sum($item_id)
|
||||
{
|
||||
$this->db->select('SUM(trans_inventory) AS sum, MAX(trans_location) AS location_id');
|
||||
$this->db->from('inventory');
|
||||
$this->db->where('trans_items', $item_id);
|
||||
$this->db->group_by('trans_location');
|
||||
|
||||
return $this->db->get()->result_array();
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -358,6 +358,7 @@ class Item extends CI_Model
|
||||
$this->Item_quantity->reset_quantity($item_id);
|
||||
$this->db->where('item_id', $item_id);
|
||||
$success = $this->db->update('items', array('deleted'=>1));
|
||||
$success &= $this->Inventory->reset_quantity($item_id);
|
||||
|
||||
$this->db->trans_complete();
|
||||
|
||||
@@ -389,6 +390,11 @@ class Item extends CI_Model
|
||||
$this->db->where_in('item_id', $item_ids);
|
||||
$success = $this->db->update('items', array('deleted'=>1));
|
||||
|
||||
foreach($item_ids as $item_id)
|
||||
{
|
||||
$success &= $this->Inventory->reset_quantity($item_id);
|
||||
}
|
||||
|
||||
$this->db->trans_complete();
|
||||
|
||||
$success &= $this->db->trans_status();
|
||||
|
||||
Reference in New Issue
Block a user