load->model('MStocks'); $this->load->model('MPurchases'); checkLogin(); } public function _remap($alias = "", $params = array()) { $data['dataValue'] = $this->session; $data['pageTitle'] = "Purchase"; switch ($alias) { case 'details': $id = $this->uri->segment(4); $this->db->where('purchase_id', $id); $data['Purchase'] = $this->db->get("tbl_purchases")->row(); $this->db->where('purchases_id', $id); $data['PurchaseDetails'] = $this->db->get("tbl_purchasedetails")->result(); $data['pageTitle'] = "View Purchase"; loadView("inventory/purchases/view", $data); break; case 'create': // print_r($_POST);die; if (isset($_POST['accounts_id'])) { $TableData = array( 'transaction_type' => "Purchase Entry", 'accounts_id' => filter_var($_POST['accounts_id']), 'purchase_date' => filter_var($_POST['purchase_date']), 'created_on' => date('Y-m-d H:i:s'), 'created_by' => 'admin', 'remarks' => '', 'status' => 1, ); $this->db->insert('tbl_purchases', $TableData); $purchase_id = $this->db->insert_id(); $a = 0; foreach ($_POST['item_id'] as $item) { $TableData = array( 'purchases_id' => $purchase_id, 'items_id' => $item, 'qty' => $_POST['quantity'][$a], 'rate' => $_POST['rate'][$a], 'created_on' => date('Y-m-d H:i:s'), 'created_by' => 'admin', 'remarks' => '', 'status' => 1, ); $this->db->insert('tbl_purchasedetails', $TableData); $a += 1; } $this->MStocks->addPurchaseToStock($this->db->where("purchases_id", $purchase_id)->get("tbl_purchasedetails")->result()); redirect("inventory/purchases/list"); } break; case 'add': // if (isset($_POST['submit'])) { $TableData = array( 'transaction_type' => filter_var($_POST['transaction_type']), 'accounts_id' => filter_var($_POST['accounts_id']), 'purchase_date' => filter_var($_POST['purchase_date']), 'created_on' => date('Y-m-d H:i:s'), 'created_by' => 'admin', 'remarks' => filter_var($_POST['remarks']), 'status' => 1, ); pre($_POST); die; //$this->db->insert('tbl_purchases', $TableData); redirect("inventory/purchases/list"); } loadView("inventory/purchases/create", $data); break; case 'delete': $id = $this->uri->segment(4); $this->db->where('purchase_id', $id); $this->db->delete('tbl_purchases'); $this->db->where('purchases_id', $id); $this->db->delete('tbl_purchasedetails'); redirect("inventory/purchases/list"); break; case 'purchase_register': $data['PurchaseRecords'] = $this->MPurchases->getPurchaseRecords(); loadView("inventory/purchases/register", $data); break; default: $data['PurchaseRecords'] = $this->MPurchases->getPurchaseRecords(); loadView("inventory/purchases/list", $data); } } }