<?php

class LaporanModel extends CI_Model
{
    private $_table = "tb_laporan";

    public function getLaporanCountByYear($tahun){
        $this->db->where('tahun',$tahun);
        return  $laporan = count($this->db->get($this->_table)->result());
    
    }
    

    public function getCountByTahunByBulanByKelurahan($tahun,$bulan,$kelurahan){
        $this->db->where('tahun',$tahun);
        $this->db->where('bulan',$bulan);
        $this->db->where('kelurahan',$kelurahan);
        return  $laporan = count($this->db->get($this->_table)->result());
    }

    public function getLaporanByBulanByYearByKelurahan($bulan,$year,$kelurahan){
        $this->db->where('tahun',$year);
        $this->db->where('bulan',$bulan);
        $this->db->where('kelurahan',$kelurahan);
        return  $laporan = $this->db->get($this->_table)->row();
    }

    public function getLaporanCount(){
        $this->db->select('tahun');
        $this->db->distinct('tahun');
        $this->db->order_by('tahun','DESC');
        return  $laporan = count($this->db->get($this->_table)->result());
    }

    public function getLaporanBeforeCount(){
        $this->db->select('tahun');
        $this->db->distinct('tahun');
        $this->db->order_by('tahun','DESC');
        $this->db->limit(2,1);
        return  $laporan = count($this->db->get($this->_table)->result());
    }
    
    public function getLastYearLaporan(){
        $this->db->select('tahun');
        $this->db->distinct('tahun');
        $this->db->order_by('tahun','DESC');
        $this->db->limit(1);
        return  $laporan =$this->db->get($this->_table)->row();
    }

    public function getBulanLaporanByYear($tahun){
        $this->db->select('bulan');
        $this->db->where('tahun',$tahun);
        $this->db->distinct('bulan');
        $this->db->order_by('id_laporan','ASC');
        return  $laporan =$this->db->get($this->_table)->result();
    }

    public function getKelurahanByBulanAndYear($bulan,$year){
        $this->db->select('kelurahan');
        $this->db->where('tahun',$year);
        $this->db->where('bulan',$bulan);
        $this->db->distinct('kelurahan');
        $this->db->order_by('id_laporan','ASC');
        return  $laporan =$this->db->get($this->_table)->result();
    }
    
    public function getLastYearLaporanBefore(){
        $this->db->select('tahun');
        $this->db->distinct('tahun');
        $this->db->order_by('tahun','DESC');
        $this->db->limit(2,1);
        return  $laporan =$this->db->get($this->_table)->row();
    }

    public function save($tahun,$bulan,$kelurahan,$kecamatan,$aset,$omset,$jumlah_umkm,$karyawan_jenis1,$karyawan_jenis2,$karyawan_jenis3,$omset_jenis1,$omset_jenis2,$omset_jenis3,$aset_jenis1,$aset_jenis2,$aset_jenis3,$karyawan_jen1_l,$karyawan_jen1_p,$karyawan_jen2_l,$karyawan_jen2_p,$karyawan_jen3_l,$karyawan_jen3_p,$umkm_jen1_kat1,$umkm_jen1_kat2,$umkm_jen1_kat3,$umkm_jen2_kat1,$umkm_jen2_kat2,$umkm_jen2_kat3,$umkm_jen3_kat1,$umkm_jen3_kat2,$umkm_jen3_kat3)
    {
        $this->tahun = $tahun;
        $this->bulan = $bulan;
        $this->kelurahan = $kelurahan;
        $this->kecamatan = $kecamatan;
        $this->aset = $aset;
        $this->omset = $omset;
        $this->jumlah_umkm = $jumlah_umkm;
        $this->karyawan_jenis1 = $karyawan_jenis1;
        $this->karyawan_jenis2 = $karyawan_jenis2;
        $this->karyawan_jenis3 = $karyawan_jenis3;
        $this->omset_jenis1 = $omset_jenis1;
        $this->omset_jenis2 = $omset_jenis2;
        $this->omset_jenis3 = $omset_jenis3;
        $this->aset_jenis1 = $aset_jenis1;
        $this->aset_jenis2 = $aset_jenis2;
        $this->aset_jenis3 = $aset_jenis3;
        $this->karyawan_jen1_l = $karyawan_jen1_l;
        $this->karyawan_jen1_p = $karyawan_jen1_p;
        $this->karyawan_jen2_l = $karyawan_jen2_l;
        $this->karyawan_jen2_p = $karyawan_jen2_p;
        $this->karyawan_jen3_l = $karyawan_jen3_l;
        $this->karyawan_jen3_p = $karyawan_jen3_p;
        $this->umkm_jen1_kat1 = $umkm_jen1_kat1;
        $this->umkm_jen1_kat2 = $umkm_jen1_kat2;
        $this->umkm_jen1_kat3 = $umkm_jen1_kat3;
        $this->umkm_jen2_kat1 = $umkm_jen2_kat1;
        $this->umkm_jen2_kat2 = $umkm_jen2_kat2;
        $this->umkm_jen2_kat3 = $umkm_jen2_kat3;
        $this->umkm_jen3_kat1 = $umkm_jen3_kat1;
        $this->umkm_jen3_kat2 = $umkm_jen3_kat2;
        $this->umkm_jen3_kat3 = $umkm_jen3_kat3;

        //var_dump($this);die();
        
        return $this->db->insert($this->_table, $this);
    }

    public function update($id_laporan,$tahun,$bulan,$kelurahan,$kecamatan,$aset,$omset,$jumlah_umkm,$karyawan_jenis1,$karyawan_jenis2,$karyawan_jenis3,$omset_jenis1,$omset_jenis2,$omset_jenis3,$aset_jenis1,$aset_jenis2,$aset_jenis3,$karyawan_jen1_l,$karyawan_jen1_p,$karyawan_jen2_l,$karyawan_jen2_p,$karyawan_jen3_l,$karyawan_jen3_p,$umkm_jen1_kat1,$umkm_jen1_kat2,$umkm_jen1_kat3,$umkm_jen2_kat1,$umkm_jen2_kat2,$umkm_jen2_kat3,$umkm_jen3_kat1,$umkm_jen3_kat2,$umkm_jen3_kat3)
    {
        $this->tahun = $tahun;
        $this->bulan = $bulan;
        $this->kelurahan = $kelurahan;
        $this->kecamatan = $kecamatan;
        $this->aset = $aset;
        $this->omset = $omset;
        $this->jumlah_umkm = $jumlah_umkm;
        $this->karyawan_jenis1 = $karyawan_jenis1;
        $this->karyawan_jenis2 = $karyawan_jenis2;
        $this->karyawan_jenis3 = $karyawan_jenis3;
        $this->omset_jenis1 = $omset_jenis1;
        $this->omset_jenis2 = $omset_jenis2;
        $this->omset_jenis3 = $omset_jenis3;
        $this->aset_jenis1 = $aset_jenis1;
        $this->aset_jenis2 = $aset_jenis2;
        $this->aset_jenis3 = $aset_jenis3;
        $this->karyawan_jen1_l = $karyawan_jen1_l;
        $this->karyawan_jen1_p = $karyawan_jen1_p;
        $this->karyawan_jen2_l = $karyawan_jen2_l;
        $this->karyawan_jen2_p = $karyawan_jen2_p;
        $this->karyawan_jen3_l = $karyawan_jen3_l;
        $this->karyawan_jen3_p = $karyawan_jen3_p;
        $this->umkm_jen1_kat1 = $umkm_jen1_kat1;
        $this->umkm_jen1_kat2 = $umkm_jen1_kat2;
        $this->umkm_jen1_kat3 = $umkm_jen1_kat3;
        $this->umkm_jen2_kat1 = $umkm_jen2_kat1;
        $this->umkm_jen2_kat2 = $umkm_jen2_kat2;
        $this->umkm_jen2_kat3 = $umkm_jen2_kat3;
        $this->umkm_jen3_kat1 = $umkm_jen3_kat1;
        $this->umkm_jen3_kat2 = $umkm_jen3_kat2;
        $this->umkm_jen3_kat3 = $umkm_jen3_kat3;

        //var_dump($this);die();
        
        return $this->db->update($this->_table, $this, array('id_laporan' => $id_laporan));
    }

}