Код: Выделить всё
if(isset($_POST['save'])){
$location = $this->input->post('location');
$loc = explode("-",$location,2);
$location_id = $loc[0];
$location_name =$loc[1];
$stk_number = $this->input->post('stk_number');
$item_id = $this->input->post('item_id');
$item_name = $this->input->post('item_name');
$measure_unit = $this->input->post('measure_unit');
$barcode = $this->input->post('barcode');
$category_id = $this->input->post('category_id');
$stocktake_quantity = $this->input->post('stocktake_quantity');
$comment = $this->input->post('comment');
$date = $this->input->post('date');
$expiry_date = $this->input->post('expiry_date');
// Save Stock Take
$data = array(
'stk_number' => $this->input->post('stk_number'),
'location' => $location_name,
'location_id' => $location_id,
'comment' => $this->input->post('comment'),
'status' => '1',
'created_at' => $this->input->post('date'),
'created_by' => $this->session->userdata('name')
);
$this->db->insert('stocktake', $data);
$stk_id = $this->db->insert_id();
for ($i = 0; $i < count($stocktake_quantity); $i++)
{
if($stocktake_quantity[$i] != ''){
$no_expiry = '0';
if($expiry_date[$i] == '0000-00-00'){
$no_expiry = '1';
}
$data = [
'stk_number' => $stk_number,
'stk_id' => $stk_id,
'item_id' => $item_id[$i],
'item_name' => $item_name[$i],
'measure_unit' => $measure_unit[$i],
'barcode' => $barcode[$i],
'category_id' => $category_id[$i],
'stocktake_quantity' => $stocktake_quantity[$i],
'no_expiry' => $no_expiry,
'status' => '1',
'detail' => 'stock take',
'date' => $date
];
$this->db->insert('stocktake_trans', $data);
}
}
// Set message
$this->session->set_flashdata('stocktake_saved', 'Stock Take has been saved!');
redirect('stocktake');
}
Подробнее здесь: https://stackoverflow.com/questions/783 ... s-are-more