load->model('MStocks'); $this->load->model('MSales'); checkLogin(); } public function _remap($alias = "", $params = array()) { $data['dataValue'] = $this->session; $data['pageTitle'] = "Sales"; switch ($alias) { case 'create': $data['items'] = $this->MStocks->getSellableItems(); loadView("inventory/sales/create", $data); break; case 'store': // print_r(filter_var($_POST['salesDate']));die; if (isset($_POST['accounts_id'])) { $TableData = array( 'transaction_type' => "Sales Entry", 'accounts_id' => filter_var($_POST['accounts_id']), 'sales_date' => filter_var($_POST['salesDate']), 'created_on' => date('Y-m-d H:i:s'), 'created_by' => 'admin', 'remarks' => '', 'status' => 1, ); $this->db->insert('tbl_sales', $TableData); $sales_id = $this->db->insert_id(); $i = 0; // print_r($_POST);die; foreach ($_POST['item_id'] as $item) { if ($item != 0 || $_POST['qty'][$i] != 0 || $_POST['rate'][$i] != 0) : $TableData = array( 'sales_id' => $sales_id, 'items_id' => $item, 'qty' => $_POST['qty'][$i], 'rate' => $_POST['rate'][$i], 'created_on' => date('Y-m-d H:i:s'), 'created_by' => 'admin', 'status' => 1, ); $i += 1; $this->db->insert('tbl_salesdetails', $TableData); endif; } } // print_r($TableData); // die; // $this->db->where('sales_id', $sales_id); $this->MStocks->addSalesToStock($this->db->where('sales_id', $sales_id)->get('tbl_salesdetails')->result()); redirect("inventory/sales/list"); break; case 'sales_register': $data['SalesRecords'] = $this->MSales->getSalesRecords(); loadView("inventory/sales/register", $data); break; case 'details': $id = $this->uri->segment(4); $data['Sales'] = $this->db->where('sales_id', $id)->get("tbl_sales")->row(); $data['SalesDetails'] = $this->db->where('sales_id', $id)->get('tbl_salesdetails')->result(); loadView("inventory/sales/view", $data); break; case 'edit': if (isset($_POST['submit'])) { $id = $this->uri->segment(4); $TableData = array( 'transaction_type' => filter_var($_POST['transaction_type']), 'accounts_id' => filter_var($_POST['accounts_id']), 'sales_date' => filter_var($_POST['sales_date']), 'created_on' => date('Y-m-d H:i:s'), 'created_by' => 'admin', 'remarks' => filter_var($_POST['remarks']), 'status' => 1, ); $this->db->where('sales_id', $id); $this->db->update('tbl_sales', $TableData); redirect("inventory/sales/list"); } loadView("inventory/sales/edit", $data); break; case 'delete': $id = $this->uri->segment(4); $this->db->where('sales_id', $id); $this->db->delete('tbl_sales'); $this->db->where('sales_id', $id); $this->db->delete('tbl_salesdetails'); redirect("inventory/sales/list"); break; default: $data['SalesRecords'] = $this->MSales->getSalesRecords(); loadView("inventory/sales/list", $data); } } // public function getUnitByItemId($id) { // $unitName = $this->MStocks->getUnitByItemId($id); // echo json_encode(['unitName' => $unitName]); // } }