azmicolejr

Mdl WarrantyCard

Apr 15th, 2021
481
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Warranty_card_model extends CI_Model
  4. {
  5.     var $table  = 'pelunasan';
  6.     var $id     = 'id_pelunasan';
  7.  
  8.     var $column = array(
  9.         'no_nota_pelunasan', 'nota_spk', 'nama_customer', 'no_hp', 'nama_produk', 'valid_until'
  10.     );
  11.  
  12.     private function _get_datatables_query()
  13.     {
  14.         $this->db->select('
  15.             produk.nama_produk,
  16.             spk.id_spk, spk.nota_spk, spk.nama_customer, spk.no_hp,
  17.             spk_detail.spk_valid_until as valid_until,
  18.             pelunasan.id_pelunasan, pelunasan.no_nota_pelunasan, pelunasan.tgl_pelunasan,
  19.             pelunasan_detail.pelunasan_valid_until as valid_until
  20.         ');
  21.  
  22.         $this->db->from($this->table); // pelunasan
  23.  
  24.         $this->db->join('spk', 'pelunasan.pelunasan_nota_spk = spk.id_spk');
  25.  
  26.         $this->db->join(
  27.             "(SELECT spk_id, produk_id, spk_valid_until, spk_maintenance_notes FROM spk_detail
  28.                 UNION ALL
  29.                 SELECT pelunasan_id, produk_id, pelunasan_valid_until, pelunasan_maintenance_notes FROM pelunasan_detail
  30.                 INNER JOIN pelunasan ON pelunasan_detail.pelunasan_id = pelunasan.id_pelunasan
  31.                 ) spk_detail",
  32.             'spk.id_spk = spk_detail.spk_id'
  33.         );
  34.  
  35.         $this->db->join('produk', 'spk_detail.produk_id = produk.id_produk');
  36.  
  37.         $this->db->where('pelunasan.is_delete', 0);
  38.         $this->db->where('spk.is_delete', 0);
  39.  
  40.         $i = 0;
  41.  
  42.         foreach ($this->column as $item)
  43.         {
  44.             if ($_POST['search']['value']) // if datatable send POST for search
  45.             {
  46.                 if ($i === 0) // first loop
  47.                 {
  48.                     $this->db->group_start();
  49.                     $this->db->like($item, $_POST['search']['value']);
  50.                 } else {
  51.                     $this->db->or_like($item, $_POST['search']['value']);
  52.                 }
  53.  
  54.                 if (count($this->column) - 1 == $i)
  55.                     $this->db->group_end(); //close bracket
  56.             }
  57.             $column[$i] = $item; // set column array variable to order processing
  58.             $i++;
  59.         }
  60.  
  61.         if (isset($_POST['order']))
  62.         {
  63.             $this->db->order_by($column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
  64.         } else if (isset($this->order)) {
  65.             $order = $this->order;
  66.             $this->db->order_by(key($order), $order[key($order)]);
  67.         }
  68.     }
  69.  
  70.     public function get_datatables()
  71.     {
  72.         $this->_get_datatables_query();
  73.  
  74.         if ($_POST['length'] != -1)
  75.             $this->db->limit($_POST['length'], $_POST['start']);
  76.  
  77.         $query = $this->db->get();
  78.  
  79.         return $query->result();
  80.     }
  81.  
  82.     public function count_filtered()
  83.     {
  84.         $this->_get_datatables_query();
  85.  
  86.         $query = $this->db->get();
  87.  
  88.         return $query->num_rows();
  89.     }
  90.  
  91.     public function count_all()
  92.     {
  93.         $this->_get_datatables_query();
  94.  
  95.         return $this->db->count_all_results();
  96.     }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×