1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Inventory extends CI_Model
{
public function insert($inventory_data)
{
return $this->db->insert('inventory', $inventory_data);
}
public function get_inventory_data_for_item($item_id, $location_id = FALSE)
{
$this->db->from('inventory');
$this->db->where('trans_items', $item_id);
if($location_id != FALSE)
{
$this->db->where('trans_location', $location_id);
}
$this->db->order_by('trans_date', 'desc');
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();
}
}
?>