load->model('ModelSkuHarga','MSH'); $this->load->model('ModelSku','MSku'); $this->load->model('ModelHarga','MHarga'); $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"); } $datSH = $this->MSH->getDataSkuHarga(); $data = [ 'sidebar' => "data master", 'navChild' => "data harga", 'skuharga' => $datSH ]; $this->load->view('sku/table-skuharga', $data); } public function add() { $username = $this->session->userdata('username'); if ($username == null) { redirect("Login"); } $datPo = $this->MSku->getDataSku(); $datHarga = $this->MHarga->getDataHarga(); $data = [ 'sidebar' => "data master", 'navChild' => "data harga", 'sku' => $datPo, 'harga' => $datHarga ]; //var_dump($data); $this->load->view('sku/sku-tambahskuharga', $data); } public function save() { $method = $this->input->post('method'); $id_skuharga = $this->input->post('id'); $po = $this->input->post('NO_PO'); $hpp = $this->input->post('hpp'); $this->form_validation->set_rules('NO_PO', 'Pilih Nomor PO', 'required'); $this->form_validation->set_rules('hpp', 'HPP', 'required'); if ($this->form_validation->run() == FALSE) { $data = [ 'status' => false, 'errors' => [ 'NO_PO' => form_error('NO_PO'), 'hpp' => form_error('hpp') ] ]; $this->output_json($data); } else { $inputharga = [ 'HPP' => $hpp ]; $action = $this->MHarga->create('harga', $inputharga); } $isi = $this->input->post('hpp'); $harga = $this->MHarga->getIdHarga($isi); $input = [ 'ID_SKU' => $po, 'ID_HARGA' => $harga ]; $action = $this->MHarga->create('skuharga', $input); if ($action) { $this->session->set_flashdata('flash', 'ditambah'); //$this->output_json(['status' => true]); redirect('ManageSkuHarga'); } else { $this->session->set_flashdata('flashgagal', 'ditambah'); //$this->output_json(['status' => true]); redirect('ManageSkuHarga'); } } public function hapus() { $id = $this->input->post('id'); if ($this->MSH->delete('skuharga', $id, 'ID_SKUHARGA')) { $this->session->set_flashdata('flash', 'dihapus'); redirect('ManageSkuHarga'); } } // public function add(){ // $username = $this->session->userdata('username'); // if ($username == null){ // redirect("Action"); // } // $this->load->view('tambah-user'); // } }