Advertisement
Bannip73

Model

Nov 10th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.91 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Model extends CI_Model
  5. {
  6.     public function simpan($tabel, $data)
  7.     {
  8.         return $this->db->insert($tabel, $data);
  9.     }
  10.     public function update($tabel, $date, $where)
  11.     {
  12.         return $this->db->update($tabel, $date, $where);
  13.     }
  14.     public function getusers($where = '')
  15.     {
  16.         return $this->db->query("SELECT * FROM users".$where);
  17.     }
  18.     public function getLogin($username, $password)
  19.     {
  20.         return $this->db->query("SELECT * FROM users WHERE username = '$username' AND password = '".md5($password)."'");
  21.     }
  22.  
  23.     function nomor()
  24.     {
  25.         $this->db->select('nomor');
  26.         $this->db->order_by('nomor DESC');
  27.         $query = $this->db->get('data');
  28.         return $query->result_array();
  29.     }
  30.  
  31.     function ambil_data($nomor)
  32.     {
  33.         $this->db->where('nomor', $nomor);
  34.         $query = $this->db->get('data');
  35.         return $query->result_array();
  36.     }
  37.  
  38.     function tambah_pemasukan($data)
  39.     {
  40.         $query = $this->db->insert('data', $data);
  41.         return $query;
  42.     }
  43.  
  44.     function tambah_pengeluaran($data)
  45.     {
  46.         $query = $this->db->insert('data', $data);
  47.         return $query;
  48.     }
  49.  
  50.     function ubah($nomor, $data)
  51.     {
  52.         $this->db->where('nomor', $nomor);
  53.         $query = $this->db->update('data', $data);
  54.         return $query;
  55.     }
  56.  
  57.     function hapus($nomor)
  58.     {
  59.         $this->db->where('nomor', $nomor);
  60.         $query = $this->db->delete('data');
  61.         return $query;
  62.     }
  63.  
  64.     function row_harian($tanggal){
  65.         $this->db->where('tanggal', $tanggal);
  66.         $query = $this->db->get('data');
  67.         return $query->num_rows();
  68.     }
  69.  
  70.     function laporan_harian($tanggal, $number, $offset)
  71.     {
  72.         $this->db->where('tanggal', $tanggal);
  73.         $this->db->order_by('nomor DESC');
  74.         $query = $this->db->get('data', $number, $offset);
  75.         return $query->result();
  76.     }
  77.  
  78.     function row_periode($mulai, $sampai)
  79.     {
  80.         $this->db->where('tanggal >=', $mulai);
  81.         $this->db->where('tanggal <=', $sampai);
  82.         $query = $this->db->get('data');
  83.         return $query->num_rows();
  84.     }
  85.  
  86.     function laporan_periode($mulai, $sampai, $number, $offset)
  87.     {
  88.         $this->db->where('tanggal >=', $mulai);
  89.         $this->db->where('tanggal <=', $sampai);
  90.         $this->db->order_by('nomor DESC');
  91.         $query = $this->db->get('data', $number, $offset);
  92.         return $query->result();
  93.     }
  94.  
  95.     function row_masuk(){
  96.         $this->db->where('jenis', 'masuk');
  97.         $query = $this->db->get('data');
  98.         return $query->num_rows();
  99.     }
  100.  
  101.     function masuk($number, $offset){
  102.         $this->db->where('jenis', 'masuk');
  103.         $this->db->order_by('nomor DESC');
  104.         $query = $this->db->get('data',$number,$offset);
  105.         return $query->result();
  106.     }
  107.  
  108.     function row_keluar(){
  109.         $this->db->where('jenis', 'keluar');
  110.         $query = $this->db->get('data');
  111.         return $query->num_rows();
  112.     }
  113.  
  114.     function keluar($number, $offset){
  115.         $this->db->where('jenis', 'keluar');
  116.         $this->db->order_by('nomor DESC');
  117.         $query = $this->db->get('data', $number, $offset);
  118.         return $query->result();
  119.     }
  120.  
  121.     function row_cari($search)
  122.     {
  123.         $this->db->from('data');
  124.         $this->db->or_like($search);
  125.         $query = $this->db->get();
  126.         return $query->num_rows();
  127.     }
  128.  
  129.     function cari($batas=null, $offset=null, $search=null)
  130.     {
  131.         $this->db->from('data');
  132.         if($batas != null){
  133.             $this->db->limit($batas, $offset);
  134.         }
  135.         if ($search != null) {
  136.             $this->db->or_like($search);
  137.         }
  138.         $this->db->order_by('nomor DESC');
  139.         $query = $this->db->get();
  140.  
  141.         if ($query->num_rows() > 0) {
  142.             return $query->result();
  143.         }
  144.     }
  145.  
  146.     function total_masuk()
  147.     {
  148.         $this->db->select('jumlah');
  149.         $this->db->from('data');
  150.         $this->db->where('jenis', 'masuk');
  151.         $query = $this->db->get();
  152.         return $query->result();
  153.     }
  154.  
  155.     function total_keluar()
  156.     {
  157.         $this->db->select('jumlah');
  158.         $this->db->from('data');
  159.         $this->db->where('jenis', 'keluar');
  160.         $query = $this->db->get();
  161.         return $query->result();
  162.     }
  163.  
  164.     function total_harian_masuk($tanggal)
  165.     {
  166.         $this->db->select('jumlah');
  167.         $this->db->from('data');
  168.         $this->db->where('tanggal', $tanggal);
  169.         $this->db->where('jenis','masuk');
  170.         $query = $this->db->get();
  171.         return $query->result();
  172.     }
  173.  
  174.     function total_harian_keluar($tanggal)
  175.     {
  176.         $this->db->select('jumlah');
  177.         $this->db->from('data');
  178.         $this->db->where('tanggal', $tanggal);
  179.         $this->db->where('jenis','keluar');
  180.         $query = $this->db->get();
  181.         return $query->result();
  182.     }
  183.  
  184.     function total_periode_masuk($mulai, $sampai)
  185.     {
  186.         $this->db->select('jumlah');
  187.         $this->db->from('data');
  188.         $this->db->where('tanggal >=', $mulai);
  189.         $this->db->where('tanggal <=', $sampai);
  190.         $this->db->where('jenis', 'masuk');
  191.         $query = $this->db->get();
  192.         return $query->result();
  193.     }
  194.  
  195.     function total_periode_keluar($mulai, $sampai)
  196.     {
  197.         $this->db->select('jumlah');
  198.         $this->db->from('data');
  199.         $this->db->where('tanggal >=', $mulai);
  200.         $this->db->where('tanggal <=', $sampai);
  201.         $this->db->where('jenis', 'keluar');
  202.         $query = $this->db->get();
  203.         return $query->result();
  204.     }
  205.  
  206.     function clean()
  207.     {
  208.         $query = $this->db->truncate('data');
  209.         return $query;
  210.     }
  211. }
  212. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement