Advertisement
Guest User

SalaryModel.php

a guest
Jan 22nd, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.75 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class SalaryModel extends CI_Model
  5. {
  6.   private $_table = 'salary';
  7.   private $_tableView = 'view_salary';
  8.   private $_columns = array(
  9.     'nik',
  10.     'p1_gaji_pokok',
  11.     'p1_tj_tetap',
  12.     'p1_tj_jabatan',
  13.     'p1_overtime',
  14.     'p1_dinas_luar_kota',
  15.     'p1_u_makan_trans',
  16.     'p1_tj_hp_lainnya',
  17.     'p1_insentif_thr_pulsa',
  18.     'p1_tj_kehadiran_transport',
  19.     'p1_makan',
  20.     'p1_late_meal',
  21.     'p1_bpjs_p',
  22.     'p1_astek_p',
  23.     'p1_iuran_pensiun_p',
  24.     'p1_akdhk_p',
  25.     'p1_meal_private_tj_dll',
  26.     'p1_out_of_town_rapel_insentif',
  27.     'p1_tj_pph21',
  28.     'p1_total_bruto',
  29.     'p2_astek_p_deduction',
  30.     'p2_jht2',
  31.     'p2_iuran_pensiun_p',
  32.     'p2_iuran_pensiun_k',
  33.     'p2_bpjs_p',
  34.     'p2_bpjs_k',
  35.     'p2_akdhk_d',
  36.     'p2_pinjaman_koperasi',
  37.     'p2_pinjaman_perusahaan',
  38.     'p2_simpanan_koperasi',
  39.     'p2_tj_pph21',
  40.     'take_home_pay'
  41.   ); // Urutan (index) harus sama dengan template excel, dan penamaan harus sama dengan tabel (case-sensitive)
  42.  
  43.     public function getColumnName($columnIndex) {
  44.     $temp = array_combine(range(1, count($this->_columns)), array_values($this->_columns)); // Reset index to 1
  45.     $result = (isset($temp[$columnIndex])) ? $temp[$columnIndex] : 0; // Get value
  46.         return $result;
  47.   }
  48.  
  49.   public function rules() {
  50.     return array(
  51.       [
  52.         'field' => 'nik',
  53.         'label' => 'NIK',
  54.         'rules' => 'required|trim'
  55.       ],
  56.       [
  57.         'field' => 'periode',
  58.         'label' => 'Periode',
  59.         'rules' => 'required|trim'
  60.       ],
  61.       [
  62.         'field' => 'p1_gaji_pokok',
  63.         'label' => 'Gaji Pokok',
  64.         'rules' => 'required|trim'
  65.       ],
  66.       [
  67.         'field' => 'take_home_pay',
  68.         'label' => 'Take Home Pay',
  69.         'rules' => 'required|trim'
  70.       ]
  71.     );
  72.   }
  73.  
  74.   public function getAll($params = []) {
  75.     return $this->db->where($params)->get($this->_tableView)->result();
  76.   }
  77.  
  78.   public function getDetail($params = []) {
  79.     return $this->db->where($params)->get($this->_tableView)->row();
  80.   }
  81.  
  82.   public function insert() {
  83.     $response = array('status' => false, 'data' => 'No operation.');
  84.  
  85.     try {
  86.       $post = $this->input->post();
  87.       $post['periode'] = $post['periode_tahun'].$post['periode_bulan'];
  88.  
  89.       $this->nik = $post['nik'];
  90.       $this->periode = $post['periode'];
  91.       $this->p1_gaji_pokok = $this->cleanNumber($post['p1_gaji_pokok']);
  92.       $this->p1_tj_tetap = $this->cleanNumber($post['p1_tj_tetap']);
  93.       $this->p1_tj_jabatan = $this->cleanNumber($post['p1_tj_jabatan']);
  94.       $this->p1_overtime = $this->cleanNumber($post['p1_overtime']);
  95.       $this->p1_dinas_luar_kota = $this->cleanNumber($post['p1_dinas_luar_kota']);
  96.       $this->p1_u_makan_trans = $this->cleanNumber($post['p1_u_makan_trans']);
  97.       $this->p1_tj_hp_lainnya = $this->cleanNumber($post['p1_tj_hp_lainnya']);
  98.       $this->p1_insentif_thr_pulsa = $this->cleanNumber($post['p1_insentif_thr_pulsa']);
  99.       $this->p1_tj_kehadiran_transport = $this->cleanNumber($post['p1_tj_kehadiran_transport']);
  100.       $this->p1_makan = $this->cleanNumber($post['p1_makan']);
  101.       $this->p1_late_meal = $this->cleanNumber($post['p1_late_meal']);
  102.       $this->p1_bpjs_p = $this->cleanNumber($post['p1_bpjs_p']);
  103.       $this->p1_astek_p = $this->cleanNumber($post['p1_astek_p']);
  104.       $this->p1_iuran_pensiun_p = $this->cleanNumber($post['p1_iuran_pensiun_p']);
  105.       $this->p1_akdhk_p = $this->cleanNumber($post['p1_akdhk_p']);
  106.       $this->p1_meal_private_tj_dll = $this->cleanNumber($post['p1_meal_private_tj_dll']);
  107.       $this->p1_out_of_town_rapel_insentif = $this->cleanNumber($post['p1_out_of_town_rapel_insentif']);
  108.       $this->p1_tj_pph21 = $this->cleanNumber($post['p1_tj_pph21']);
  109.       $this->p1_total_bruto = $this->cleanNumber($post['p1_total_bruto']);
  110.       $this->p2_astek_p_deduction = $this->cleanNumber($post['p2_astek_p_deduction']);
  111.       $this->p2_jht2 = $this->cleanNumber($post['p2_jht2']);
  112.       $this->p2_iuran_pensiun_p = $this->cleanNumber($post['p2_iuran_pensiun_p']);
  113.       $this->p2_iuran_pensiun_k = $this->cleanNumber($post['p2_iuran_pensiun_k']);
  114.       $this->p2_bpjs_p = $this->cleanNumber($post['p2_bpjs_p']);
  115.       $this->p2_bpjs_k = $this->cleanNumber($post['p2_bpjs_k']);
  116.       $this->p2_akdhk_d = $this->cleanNumber($post['p2_akdhk_d']);
  117.       $this->p2_pinjaman_koperasi = $this->cleanNumber($post['p2_pinjaman_koperasi']);
  118.       $this->p2_pinjaman_perusahaan = $this->cleanNumber($post['p2_pinjaman_perusahaan']);
  119.       $this->p2_simpanan_koperasi = $this->cleanNumber($post['p2_simpanan_koperasi']);
  120.       $this->p2_tj_pph21 = $this->cleanNumber($post['p2_tj_pph21']);
  121.       $this->take_home_pay = $this->cleanNumber($post['take_home_pay']);
  122.       $this->db->insert($this->_table, $this);
  123.  
  124.       $response = array('status' => true, 'data' => 'Data has been saved.');
  125.     } catch (\Throwable $th) {
  126.       $response = array('status' => false, 'data' => 'Failed to save your data.');
  127.     };
  128.  
  129.     return $response;
  130.   }
  131.  
  132.   public function insertBatch($data) {
  133.     $response = array('status' => false, 'data' => 'No operation.');
  134.  
  135.     try {
  136.       $this->db->insert_batch($this->_table, $data);
  137.  
  138.       $response = array('status' => true, 'data' => 'Data has been saved.');
  139.     } catch (\Throwable $th) {
  140.       $response = array('status' => false, 'data' => 'Failed to save your data.');
  141.     };
  142.  
  143.     return $response;
  144.   }
  145.  
  146.   public function update($id) {
  147.     $response = array('status' => false, 'data' => 'No operation.');
  148.  
  149.     try {
  150.       $post = $this->input->post();
  151.       $post['periode'] = $post['periode_tahun'].$post['periode_bulan'];
  152.  
  153.       $this->nik = $post['nik'];
  154.       $this->periode = $post['periode'];
  155.       $this->p1_gaji_pokok = $this->cleanNumber($post['p1_gaji_pokok']);
  156.       $this->p1_tj_tetap = $this->cleanNumber($post['p1_tj_tetap']);
  157.       $this->p1_tj_jabatan = $this->cleanNumber($post['p1_tj_jabatan']);
  158.       $this->p1_overtime = $this->cleanNumber($post['p1_overtime']);
  159.       $this->p1_dinas_luar_kota = $this->cleanNumber($post['p1_dinas_luar_kota']);
  160.       $this->p1_u_makan_trans = $this->cleanNumber($post['p1_u_makan_trans']);
  161.       $this->p1_tj_hp_lainnya = $this->cleanNumber($post['p1_tj_hp_lainnya']);
  162.       $this->p1_insentif_thr_pulsa = $this->cleanNumber($post['p1_insentif_thr_pulsa']);
  163.       $this->p1_tj_kehadiran_transport = $this->cleanNumber($post['p1_tj_kehadiran_transport']);
  164.       $this->p1_makan = $this->cleanNumber($post['p1_makan']);
  165.       $this->p1_late_meal = $this->cleanNumber($post['p1_late_meal']);
  166.       $this->p1_bpjs_p = $this->cleanNumber($post['p1_bpjs_p']);
  167.       $this->p1_astek_p = $this->cleanNumber($post['p1_astek_p']);
  168.       $this->p1_iuran_pensiun_p = $this->cleanNumber($post['p1_iuran_pensiun_p']);
  169.       $this->p1_akdhk_p = $this->cleanNumber($post['p1_akdhk_p']);
  170.       $this->p1_meal_private_tj_dll = $this->cleanNumber($post['p1_meal_private_tj_dll']);
  171.       $this->p1_out_of_town_rapel_insentif = $this->cleanNumber($post['p1_out_of_town_rapel_insentif']);
  172.       $this->p1_tj_pph21 = $this->cleanNumber($post['p1_tj_pph21']);
  173.       $this->p1_total_bruto = $this->cleanNumber($post['p1_total_bruto']);
  174.       $this->p2_astek_p_deduction = $this->cleanNumber($post['p2_astek_p_deduction']);
  175.       $this->p2_jht2 = $this->cleanNumber($post['p2_jht2']);
  176.       $this->p2_iuran_pensiun_p = $this->cleanNumber($post['p2_iuran_pensiun_p']);
  177.       $this->p2_iuran_pensiun_k = $this->cleanNumber($post['p2_iuran_pensiun_k']);
  178.       $this->p2_bpjs_p = $this->cleanNumber($post['p2_bpjs_p']);
  179.       $this->p2_bpjs_k = $this->cleanNumber($post['p2_bpjs_k']);
  180.       $this->p2_akdhk_d = $this->cleanNumber($post['p2_akdhk_d']);
  181.       $this->p2_pinjaman_koperasi = $this->cleanNumber($post['p2_pinjaman_koperasi']);
  182.       $this->p2_pinjaman_perusahaan = $this->cleanNumber($post['p2_pinjaman_perusahaan']);
  183.       $this->p2_simpanan_koperasi = $this->cleanNumber($post['p2_simpanan_koperasi']);
  184.       $this->p2_tj_pph21 = $this->cleanNumber($post['p2_tj_pph21']);
  185.       $this->take_home_pay = $this->cleanNumber($post['take_home_pay']);
  186.       $this->db->update($this->_table, $this, ['id' => $id]);
  187.  
  188.       $response = array('status' => true, 'data' => 'Data has been saved.');
  189.     } catch (\Throwable $th) {
  190.       $response = array('status' => false, 'data' => 'Failed to save your data.');
  191.     };
  192.  
  193.     return $response;
  194.   }
  195.  
  196.   public function delete($id) {
  197.     $response = array('status' => false, 'data' => 'No operation.');
  198.  
  199.     try {
  200.       $this->db->delete($this->_table, ['id' => $id]);
  201.  
  202.       $response = array('status' => true, 'data' => 'Data has been deleted.');
  203.     } catch (\Throwable $th) {
  204.       $response = array('status' => false, 'data' => 'Failed to delete your data.');
  205.     };
  206.  
  207.     return $response;
  208.   }
  209.  
  210.   public function deleteByPeriode($periode) {
  211.     $response = array('status' => false, 'data' => 'No operation.');
  212.  
  213.     try {
  214.       $this->db->delete($this->_table, ['periode' => $periode]);
  215.  
  216.       $response = array('status' => true, 'data' => 'Data has been deleted.');
  217.     } catch (\Throwable $th) {
  218.       $response = array('status' => false, 'data' => 'Failed to delete your data.');
  219.     };
  220.  
  221.     return $response;
  222.   }
  223.  
  224.   public function truncate() {
  225.     $response = array('status' => false, 'data' => 'No operation.');
  226.  
  227.     try {
  228.       $this->db->truncate($this->_table);
  229.  
  230.       $response = array('status' => true, 'data' => 'Data has been deleted.');
  231.     } catch (\Throwable $th) {
  232.       $response = array('status' => false, 'data' => 'Failed to delete your data.');
  233.     };
  234.  
  235.     return $response;
  236.   }
  237.  
  238.   private function cleanNumber($number) {
  239.     $result = str_replace(',', '', $number);
  240.     $result = str_replace('.', '', $result);
  241.  
  242.     return $result;
  243.   }
  244. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement