Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class SalaryModel extends CI_Model
- {
- private $_table = 'salary';
- private $_tableView = 'view_salary';
- private $_columns = array(
- 'nik',
- 'p1_gaji_pokok',
- 'p1_tj_tetap',
- 'p1_tj_jabatan',
- 'p1_overtime',
- 'p1_dinas_luar_kota',
- 'p1_u_makan_trans',
- 'p1_tj_hp_lainnya',
- 'p1_insentif_thr_pulsa',
- 'p1_tj_kehadiran_transport',
- 'p1_makan',
- 'p1_late_meal',
- 'p1_bpjs_p',
- 'p1_astek_p',
- 'p1_iuran_pensiun_p',
- 'p1_akdhk_p',
- 'p1_meal_private_tj_dll',
- 'p1_out_of_town_rapel_insentif',
- 'p1_tj_pph21',
- 'p1_total_bruto',
- 'p2_astek_p_deduction',
- 'p2_jht2',
- 'p2_iuran_pensiun_p',
- 'p2_iuran_pensiun_k',
- 'p2_bpjs_p',
- 'p2_bpjs_k',
- 'p2_akdhk_d',
- 'p2_pinjaman_koperasi',
- 'p2_pinjaman_perusahaan',
- 'p2_simpanan_koperasi',
- 'p2_tj_pph21',
- 'take_home_pay'
- ); // Urutan (index) harus sama dengan template excel, dan penamaan harus sama dengan tabel (case-sensitive)
- public function getColumnName($columnIndex) {
- $temp = array_combine(range(1, count($this->_columns)), array_values($this->_columns)); // Reset index to 1
- $result = (isset($temp[$columnIndex])) ? $temp[$columnIndex] : 0; // Get value
- return $result;
- }
- public function rules() {
- return array(
- [
- 'field' => 'nik',
- 'label' => 'NIK',
- 'rules' => 'required|trim'
- ],
- [
- 'field' => 'periode',
- 'label' => 'Periode',
- 'rules' => 'required|trim'
- ],
- [
- 'field' => 'p1_gaji_pokok',
- 'label' => 'Gaji Pokok',
- 'rules' => 'required|trim'
- ],
- [
- 'field' => 'take_home_pay',
- 'label' => 'Take Home Pay',
- 'rules' => 'required|trim'
- ]
- );
- }
- public function getAll($params = []) {
- return $this->db->where($params)->get($this->_tableView)->result();
- }
- public function getDetail($params = []) {
- return $this->db->where($params)->get($this->_tableView)->row();
- }
- public function insert() {
- $response = array('status' => false, 'data' => 'No operation.');
- try {
- $post = $this->input->post();
- $post['periode'] = $post['periode_tahun'].$post['periode_bulan'];
- $this->nik = $post['nik'];
- $this->periode = $post['periode'];
- $this->p1_gaji_pokok = $this->cleanNumber($post['p1_gaji_pokok']);
- $this->p1_tj_tetap = $this->cleanNumber($post['p1_tj_tetap']);
- $this->p1_tj_jabatan = $this->cleanNumber($post['p1_tj_jabatan']);
- $this->p1_overtime = $this->cleanNumber($post['p1_overtime']);
- $this->p1_dinas_luar_kota = $this->cleanNumber($post['p1_dinas_luar_kota']);
- $this->p1_u_makan_trans = $this->cleanNumber($post['p1_u_makan_trans']);
- $this->p1_tj_hp_lainnya = $this->cleanNumber($post['p1_tj_hp_lainnya']);
- $this->p1_insentif_thr_pulsa = $this->cleanNumber($post['p1_insentif_thr_pulsa']);
- $this->p1_tj_kehadiran_transport = $this->cleanNumber($post['p1_tj_kehadiran_transport']);
- $this->p1_makan = $this->cleanNumber($post['p1_makan']);
- $this->p1_late_meal = $this->cleanNumber($post['p1_late_meal']);
- $this->p1_bpjs_p = $this->cleanNumber($post['p1_bpjs_p']);
- $this->p1_astek_p = $this->cleanNumber($post['p1_astek_p']);
- $this->p1_iuran_pensiun_p = $this->cleanNumber($post['p1_iuran_pensiun_p']);
- $this->p1_akdhk_p = $this->cleanNumber($post['p1_akdhk_p']);
- $this->p1_meal_private_tj_dll = $this->cleanNumber($post['p1_meal_private_tj_dll']);
- $this->p1_out_of_town_rapel_insentif = $this->cleanNumber($post['p1_out_of_town_rapel_insentif']);
- $this->p1_tj_pph21 = $this->cleanNumber($post['p1_tj_pph21']);
- $this->p1_total_bruto = $this->cleanNumber($post['p1_total_bruto']);
- $this->p2_astek_p_deduction = $this->cleanNumber($post['p2_astek_p_deduction']);
- $this->p2_jht2 = $this->cleanNumber($post['p2_jht2']);
- $this->p2_iuran_pensiun_p = $this->cleanNumber($post['p2_iuran_pensiun_p']);
- $this->p2_iuran_pensiun_k = $this->cleanNumber($post['p2_iuran_pensiun_k']);
- $this->p2_bpjs_p = $this->cleanNumber($post['p2_bpjs_p']);
- $this->p2_bpjs_k = $this->cleanNumber($post['p2_bpjs_k']);
- $this->p2_akdhk_d = $this->cleanNumber($post['p2_akdhk_d']);
- $this->p2_pinjaman_koperasi = $this->cleanNumber($post['p2_pinjaman_koperasi']);
- $this->p2_pinjaman_perusahaan = $this->cleanNumber($post['p2_pinjaman_perusahaan']);
- $this->p2_simpanan_koperasi = $this->cleanNumber($post['p2_simpanan_koperasi']);
- $this->p2_tj_pph21 = $this->cleanNumber($post['p2_tj_pph21']);
- $this->take_home_pay = $this->cleanNumber($post['take_home_pay']);
- $this->db->insert($this->_table, $this);
- $response = array('status' => true, 'data' => 'Data has been saved.');
- } catch (\Throwable $th) {
- $response = array('status' => false, 'data' => 'Failed to save your data.');
- };
- return $response;
- }
- public function insertBatch($data) {
- $response = array('status' => false, 'data' => 'No operation.');
- try {
- $this->db->insert_batch($this->_table, $data);
- $response = array('status' => true, 'data' => 'Data has been saved.');
- } catch (\Throwable $th) {
- $response = array('status' => false, 'data' => 'Failed to save your data.');
- };
- return $response;
- }
- public function update($id) {
- $response = array('status' => false, 'data' => 'No operation.');
- try {
- $post = $this->input->post();
- $post['periode'] = $post['periode_tahun'].$post['periode_bulan'];
- $this->nik = $post['nik'];
- $this->periode = $post['periode'];
- $this->p1_gaji_pokok = $this->cleanNumber($post['p1_gaji_pokok']);
- $this->p1_tj_tetap = $this->cleanNumber($post['p1_tj_tetap']);
- $this->p1_tj_jabatan = $this->cleanNumber($post['p1_tj_jabatan']);
- $this->p1_overtime = $this->cleanNumber($post['p1_overtime']);
- $this->p1_dinas_luar_kota = $this->cleanNumber($post['p1_dinas_luar_kota']);
- $this->p1_u_makan_trans = $this->cleanNumber($post['p1_u_makan_trans']);
- $this->p1_tj_hp_lainnya = $this->cleanNumber($post['p1_tj_hp_lainnya']);
- $this->p1_insentif_thr_pulsa = $this->cleanNumber($post['p1_insentif_thr_pulsa']);
- $this->p1_tj_kehadiran_transport = $this->cleanNumber($post['p1_tj_kehadiran_transport']);
- $this->p1_makan = $this->cleanNumber($post['p1_makan']);
- $this->p1_late_meal = $this->cleanNumber($post['p1_late_meal']);
- $this->p1_bpjs_p = $this->cleanNumber($post['p1_bpjs_p']);
- $this->p1_astek_p = $this->cleanNumber($post['p1_astek_p']);
- $this->p1_iuran_pensiun_p = $this->cleanNumber($post['p1_iuran_pensiun_p']);
- $this->p1_akdhk_p = $this->cleanNumber($post['p1_akdhk_p']);
- $this->p1_meal_private_tj_dll = $this->cleanNumber($post['p1_meal_private_tj_dll']);
- $this->p1_out_of_town_rapel_insentif = $this->cleanNumber($post['p1_out_of_town_rapel_insentif']);
- $this->p1_tj_pph21 = $this->cleanNumber($post['p1_tj_pph21']);
- $this->p1_total_bruto = $this->cleanNumber($post['p1_total_bruto']);
- $this->p2_astek_p_deduction = $this->cleanNumber($post['p2_astek_p_deduction']);
- $this->p2_jht2 = $this->cleanNumber($post['p2_jht2']);
- $this->p2_iuran_pensiun_p = $this->cleanNumber($post['p2_iuran_pensiun_p']);
- $this->p2_iuran_pensiun_k = $this->cleanNumber($post['p2_iuran_pensiun_k']);
- $this->p2_bpjs_p = $this->cleanNumber($post['p2_bpjs_p']);
- $this->p2_bpjs_k = $this->cleanNumber($post['p2_bpjs_k']);
- $this->p2_akdhk_d = $this->cleanNumber($post['p2_akdhk_d']);
- $this->p2_pinjaman_koperasi = $this->cleanNumber($post['p2_pinjaman_koperasi']);
- $this->p2_pinjaman_perusahaan = $this->cleanNumber($post['p2_pinjaman_perusahaan']);
- $this->p2_simpanan_koperasi = $this->cleanNumber($post['p2_simpanan_koperasi']);
- $this->p2_tj_pph21 = $this->cleanNumber($post['p2_tj_pph21']);
- $this->take_home_pay = $this->cleanNumber($post['take_home_pay']);
- $this->db->update($this->_table, $this, ['id' => $id]);
- $response = array('status' => true, 'data' => 'Data has been saved.');
- } catch (\Throwable $th) {
- $response = array('status' => false, 'data' => 'Failed to save your data.');
- };
- return $response;
- }
- public function delete($id) {
- $response = array('status' => false, 'data' => 'No operation.');
- try {
- $this->db->delete($this->_table, ['id' => $id]);
- $response = array('status' => true, 'data' => 'Data has been deleted.');
- } catch (\Throwable $th) {
- $response = array('status' => false, 'data' => 'Failed to delete your data.');
- };
- return $response;
- }
- public function deleteByPeriode($periode) {
- $response = array('status' => false, 'data' => 'No operation.');
- try {
- $this->db->delete($this->_table, ['periode' => $periode]);
- $response = array('status' => true, 'data' => 'Data has been deleted.');
- } catch (\Throwable $th) {
- $response = array('status' => false, 'data' => 'Failed to delete your data.');
- };
- return $response;
- }
- public function truncate() {
- $response = array('status' => false, 'data' => 'No operation.');
- try {
- $this->db->truncate($this->_table);
- $response = array('status' => true, 'data' => 'Data has been deleted.');
- } catch (\Throwable $th) {
- $response = array('status' => false, 'data' => 'Failed to delete your data.');
- };
- return $response;
- }
- private function cleanNumber($number) {
- $result = str_replace(',', '', $number);
- $result = str_replace('.', '', $result);
- return $result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement