load->model('informasispp_model'); is_logged_in(); } public function index() { $data['title'] = 'SPP'; // $data['informasispp'] = $this->informasispp_model->get_data('tb_informasispp')->result(); $data['informasispp'] = $this->informasispp_model->get_informasispp(); $data['admin'] = $this->db->get_where('admin', ['email' => $this->session->userdata('email')])->row_array(); $this->load->view('templates/header', $data); $this->load->view('templates/sidebar', $data); $this->load->view('admin/informasi_spp'); $this->load->view('templates/footer'); } public function tambah() { $data['title'] = 'Tambah Waktu Pembayaran'; $data['informasispp'] = $this->informasispp_model->get_data('tb_informasispp')->result(); $data['admin'] = $this->db->get_where('admin', ['email' => $this->session->userdata('email')])->row_array(); $this->load->view('templates/header', $data); $this->load->view('templates/sidebar', $data); $this->load->view('admin/tambah_informasi_spp', $data); $this->load->view('templates/footer'); } public function tambah_aksi() { $this->_rules(); if ($this->form_validation->run() == FALSE) { $this->tambah(); } else { $bulan = $this->input->post('bulan'); $tahun = $this->input->post('tahun'); // Cek apakah kombinasi bulan & tahun sudah ada $cek = $this->db->get_where('tb_informasispp', [ 'bulan' => $bulan, 'tahun' => $tahun ])->num_rows(); if ($cek > 0) { // Jika data sudah ada, tampilkan pesan error $this->session->set_flashdata('pesan', ''); redirect('informasispp/tambah'); } else { // Jika belum ada, lanjutkan menyimpan data $data = array( 'bulan' => $bulan, 'tahun' => $tahun, 'jumlah_pembayaran' => $this->input->post('jumlah_pembayaran'), 'jatuh_tempo' => $this->input->post('jatuh_tempo') ); $this->informasispp_model->insert_data($data, 'tb_informasispp'); $this->session->set_flashdata('pesan', ''); redirect('informasispp'); } } } public function edit($id_spp) { $this->_rules(); if ($this->form_validation->run() == FALSE) { $this->index(); } else { $bulan = $this->input->post('bulan'); $tahun = $this->input->post('tahun'); // Cek apakah kombinasi bulan dan tahun sudah ada di data lain (bukan data yang sedang diedit) $this->db->where('bulan', $bulan); $this->db->where('tahun', $tahun); $this->db->where('id_spp !=', $id_spp); // pengecualian untuk data yang sedang diedit $cek = $this->db->get('tb_informasispp')->num_rows(); if ($cek > 0) { // Jika kombinasi bulan & tahun sudah ada di data lain, tampilkan pesan $this->session->set_flashdata('pesan', ''); redirect('informasispp'); } else { // Jika aman, lanjut update $data = array( 'id_spp' => $id_spp, 'bulan' => $bulan, 'tahun' => $tahun, 'jumlah_pembayaran' => $this->input->post('jumlah_pembayaran'), 'jatuh_tempo' => $this->input->post('jatuh_tempo') ); $this->informasispp_model->update_data($data, 'tb_informasispp'); $this->session->set_flashdata('pesan', ''); redirect('informasispp'); } } } public function _rules() { $this->form_validation->set_rules('bulan', 'Bulan', 'required', array( 'required' => '%s harus diisi!!' )); $this->form_validation->set_rules('tahun', 'Tahun', 'required', array( 'required' => '%s harus diisi!!' )); $this->form_validation->set_rules('jumlah_pembayaran', 'Jumlah Pembayaran', 'required', array( 'required' => '%s harus diisi!!' )); $this->form_validation->set_rules('jatuh_tempo', 'Jatuh Tempo', 'required', array( 'required' => '%s harus diisi!!' )); } public function delete($id) { $where = array('id_spp' => $id); $this->informasispp_model->delete($where, 'tb_informasispp'); $this->session->set_flashdata('pesan', ''); redirect('informasispp'); } }