load->model('ModelInventoryNB', 'MINB'); $this->load->model('ModelType', 'MType'); $this->load->model('ModelProcessor', 'MProcessor'); $this->load->model('ModelRam', 'MRam'); $this->load->model('ModelHarddisk', 'MHarddisk'); $this->load->model('ModelSsd', 'MSsd'); $this->load->model('ModelVga', 'MVga'); $this->load->model('ModelOs', 'MOs'); $this->load->model('ModelWarna', 'MWarna'); $this->load->model('ModelDvd', 'MDvd'); $this->load->library(['datatables', 'form_validation']); $this->form_validation->set_error_delimiters('', ''); } public function output_json($data, $encode = true) { if ($encode) $data = json_encode($data); $this->output->set_content_type('application/json')->set_output($data); } public function index() { $username = $this->session->userdata('username'); $jabatan = $this->session->userdata('jabatan'); if ($username == null) { redirect("Action"); } elseif ($jabatan != "ADMIN") { redirect("Action"); } $datInventoryNB = $this->MINB->getDataInventoryNB(); $data = [ 'sidebar' => "data inventory", 'navChild' => "data inventory sku", 'nb' => $datInventoryNB ]; $this->load->view('inventory/table-inventory', $data); } public function add() { $username = $this->session->userdata('username'); if ($username == null) { redirect("Login"); } $datInventoryNB = $this->MINB->getDataInventoryNB(); $datType = $this->MType->getDataType(); $datProcessor = $this->MProcessor->getDataProcessor(); $datRam = $this->MRam->getDataRam(); $datHarddisk = $this->MHarddisk->getDataHarddisk(); $datSsd = $this->MSsd->getDataSsd(); $datVga = $this->MVga->getDataVga(); $datOs = $this->MOs->getDataOs(); $datWarna = $this->MWarna->getDataWarna(); $datDvd = $this->MDvd->getDataDvd(); $data = [ 'sidebar' => "data inventory", 'navChild' => "data inventory sku", 'nb' => $datInventoryNB, 'type' => $datType, 'processor' => $datProcessor, 'ram' => $datRam, 'hdd' => $datHarddisk, 'ssd' => $datSsd, 'vga' => $datVga, 'os' => $datOs, 'warna' => $datWarna, 'dvd' => $datDvd ]; //var_dump($data); $this->load->view('inventory/inventory-tambahnb', $data); } public function save() { $method = $this->input->post('method'); $id_nb = $this->input->post('id'); $nota_pembelian = $this->input->post('nota_pembelian'); $type = $this->input->post('TYPE'); $processor = $this->input->post('PROCESSOR'); $ram = $this->input->post('RAM'); $hdd = $this->input->post('HDD'); $ssd = $this->input->post('SSD'); $vga = $this->input->post('VGA'); $os = $this->input->post('OS'); $warna = $this->input->post('WARNA'); $dvd = $this->input->post('DVD'); $this->form_validation->set_rules('nota_pembelian', 'Nota Pembelian', 'required'); $this->form_validation->set_rules('TYPE', 'Pilih Type', 'required'); $this->form_validation->set_rules('PROCESSOR', 'Pilih Processor', 'required'); $this->form_validation->set_rules('RAM', 'Pilih RAM', 'required'); $this->form_validation->set_rules('HDD', 'Pilih HDD', 'required'); $this->form_validation->set_rules('SSD', 'Pilih SSD', 'required'); $this->form_validation->set_rules('VGA', 'Pilih VGA', 'required'); $this->form_validation->set_rules('OS', 'Pilih OS', 'required'); $this->form_validation->set_rules('WARNA', 'Pilih Warna', 'required'); $this->form_validation->set_rules('DVD', 'Pilih Dvd', 'required'); if ($this->form_validation->run() == FALSE) { $data = [ 'status' => false, 'errors' => [ 'nota_pembelian' => form_error('nota_pembelian'), 'TYPE' => form_error('TYPE'), 'PROCESSOR' => form_error('PROCESSOR'), 'RAM' => form_error('RAM'), 'HDD' => form_error('HDD'), 'SSD' => form_error('SSD'), 'VGA' => form_error('VGA'), 'OS' => form_error('OS'), 'WARNA' => form_error('WARNA'), 'DVD' => form_error('DVD') ] ]; //$this->output_json($data);// $this->session->set_flashdata('flashgagal', 'ditambah'); redirect('ManageInventoryNB'); } else { $input = [ 'NOTA_PEMBELIAN' => $nota_pembelian, 'ID_TYPE' => $type, 'ID_PROCESSOR' => $processor, 'ID_RAM' => $ram, 'ID_HDD' => $hdd, 'ID_SSD' => $ssd, 'ID_VGA' => $vga, 'ID_OS' => $os, 'ID_WARNA' => $warna, 'ID_DVD' => $dvd ]; $action = $this->MINB->create('inventory', $input); if ($action) { $this->session->set_flashdata('flash', 'ditambah'); //$this->output_json(['status' => true]); redirect('ManageInventoryNB'); } else { $this->session->set_flashdata('flashgagal', 'ditambah'); //$this->output_json(['status' => true]); redirect('ManageInventoryNB'); } } } public function hapus() { $id = $this->input->post('id'); if ($this->MINB->delete('inventory', $id, 'ID_INVENTORY')) { $this->session->set_flashdata('flash', 'dihapus'); redirect('ManageInventoryNB'); } } }