public function insertMaterials() { $this->form_validation->set_rules('txtItemID', 'Item ID', 'trim|required'); $this->form_validation->set_rules('txtQuantity', 'Quantity', 'trim|required'); $this->form_validation->set_rules('txtProjectID', 'Project ID', 'trim|required'); $this->form_validation->set_rules('txtDateIssued', 'Date Issued', 'trim|required'); if ($this->form_validation->run()) { $item_id = $this->input->post('txtItemID'); $quantity = $this->input->post('txtQuantity'); $stock = Stock_info_model::find($item_id); //insert into materials table $data = array('item_id' => $item_id, 'quantity' => $quantity, 'price' => $stock->price, 'project_id' => $this->input->post('txtProjectID'), 'date_issued' => $this->input->post('txtDateIssued')); if (Materials_model::create($data)) { $row = Stocks_model::find($item_id); $row->quantity -= $quantity; $row->save(); $this->session->set_userdata('added', 1); redirect('ams/view_all_materials'); } } }
public function delete_materials() { $data = Materials_model::find($this->input->get('id')); if ($data->delete()) { $this->session->set_userdata('deleted', 1); redirect('ams/view_all_materials'); } }