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: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68:
<?php
class Item_kit_items extends CI_Model
{
public function get_info($item_kit_id)
{
$this->db->select('item_kit_id, item_kit_items.item_id, quantity, kit_sequence, unit_price, item_type, stock_type');
$this->db->from('item_kit_items as item_kit_items');
$this->db->join('items as items', 'item_kit_items.item_id = items.item_id');
$this->db->where('item_kit_id', $item_kit_id);
$this->db->order_by('kit_sequence', 'asc');
return $this->db->get()->result_array();
}
public function get_info_for_sale($item_kit_id)
{
$this->db->from('item_kit_items');
$this->db->where('item_kit_id', $item_kit_id);
$this->db->order_by('kit_sequence', 'desc');
return $this->db->get()->result_array();
}
public function save(&$item_kit_items_data, $item_kit_id)
{
$success = TRUE;
$this->db->trans_start();
$this->delete($item_kit_id);
if ($item_kit_items_data != NULL) {
foreach ($item_kit_items_data as $row) {
$row['item_kit_id'] = $item_kit_id;
$success &= $this->db->insert('item_kit_items', $row);
}
}
$this->db->trans_complete();
$success &= $this->db->trans_status();
return $success;
}
public function delete($item_kit_id)
{
return $this->db->delete('item_kit_items', array('item_kit_id' => $item_kit_id));
}
}
?>