load->model('ModelLaporan1', 'MLaporan1'); $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("Login"); } elseif ($jabatan != "ADMIN") { redirect("Login"); } $datLaporan1 = $this->MLaporan1->getDataLaporan1(); $data = [ 'sidebar' => "data master 2", 'navChild' => "data laporan 1", 'laporan1' => $datLaporan1 ]; $this->load->view('laporan/table-laporan1', $data); } public function add() { $username = $this->session->userdata('username'); if ($username == null) { redirect("Login"); } $datPromo = $this->MPromo->getDataPromo(); $datInvoice = $this->MInvoice->getDataInvoice(); $data = [ 'sidebar' => "data master", 'navChild' => "data invoice", 'invoice' => $datInvoice, 'promo' => $datPromo ]; $this->load->view('promo/promo-tambah', $data); } public function save() { $method = $this->input->post('method'); $nama_promo = $this->input->post('nama_promo'); $tgl_promo = $this->input->post('tgl_promo'); $potongan = $this->input->post('potongan'); $no_invoice = $this->input->post('no_invoice'); $this->form_validation->set_rules('nama_promo', 'Nama Promo', 'required'); $this->form_validation->set_rules('tgl_promo', 'Tanggal Promo', 'required'); $this->form_validation->set_rules('potongan', 'Potongan', 'required'); $this->form_validation->set_rules('no_invoice', 'Nomor Invoice', 'required'); if ($this->form_validation->run() == FALSE) { $data = [ 'status' => false, 'errors' => [ 'nama_promo' => form_error('nama_promo'), 'tgl_promo' => form_error('tgl_promo'), 'potongan' => form_error('potongan'), 'no_invoice' => form_error('no_invoice') ] ]; $this->output_json($data); } else { $input = [ 'NAMA_PROMO' => $nama_promo, 'TGL_PROMO' => $tgl_promo, 'POTONGAN' => $potongan, 'ID_INVOICE' => $no_invoice ]; $action = $this->MPromo->create('promo', $input); if ($action) { $this->session->set_flashdata('flash', 'ditambah'); redirect('ManagePromo'); } else { $this->session->set_flashdata('flashgagal', 'ditambah'); redirect('ManagePromo'); } } } public function hapus() { $id = $this->input->post('id'); if ($this->MPromo->delete('promo', $id, 'ID_PROMO')) { $this->session->set_flashdata('flash', 'dihapus'); redirect('ManagePromo'); } } }