<?php

use Google\Service\CloudSearch\Resource\Query;

defined('BASEPATH') or exit('No direct script access allowed');

class Select_model extends CI_Model
{
    // Bagian Kelola Data
    // Menu Marketing
    function vd_marketing()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('sistem_login');
        $query = $this->db->where('role_id', 7);
        $query = $this->db->get();
        return $query->result();
    }

    // Menu Kegiatan
    // Verifikasi Pengajuan Pinjaman
    function vd_jenisPinjaman()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_aturan as A');
        $query = $this->db->join('sistem_produk_koperasi as B', 'A.produk_id=B.id');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_jenisPinjamanKabag()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_aturan as A');
        $query = $this->db->join('sistem_produk_koperasi as B', 'A.produk_id=B.id');
        $query = $this->db->where('produk_id !=', '126');
        $query = $this->db->get();
        return $query->result();
    }
    // menampilkan data kas keluar ( realisasi ) bulanan
    function vd_MingguanKoperasiBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(A.pokok_pinjaman) as saldo, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('A.aturan_id', '1');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas keluar ( realisasi ) bulanan
    function vd_2MingguanKoperasiBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(A.pokok_pinjaman) as saldo, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('A.aturan_id', '2');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas keluar ( realisasi ) bulanan
    function vd_CAKoperasiBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(A.pokok_pinjaman) as saldo, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('A.aturan_id', '3');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas keluar ( realisasi ) bulanan
    function vd_AKoperasiBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(A.pokok_pinjaman) as saldo, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('A.aturan_id', '5');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas keluar ( realisasi ) bulanan
    function vd_KKoperasiBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(A.pokok_pinjaman) as saldo, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('A.aturan_id', '6');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas keluar ( realisasi ) bulanan
    function vd_MusimanKoperasiBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(A.pokok_pinjaman) as saldo, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('A.aturan_id', '4');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas keluar ( realisasi ) tahunan
    function vd_RealisasiKoperasiTahunan()
    {
        $tahun = date('Y');
        $query = $this->db->select('SUM(A.pokok_pinjaman) as saldo, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas keluar ( realisasi ) tahunan
    function vd_RealisasiKoperasiSemua()
    {
        $query = $this->db->select('SUM(A.pokok_pinjaman) as saldo, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->get();
        return $query->row_array();
    }
    // View Data Pengajuan Pinjaman
    function vd_pengajuanPinjaman()
    {
        $query = $this->db->select('*, A.id as nomor_kontrak, C.no_hp as nomor_hp_asli');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id');
        $query = $this->db->join('anggota_keluarga_detail as E', 'A.anggota_id=E.anggota_id');
        $query = $this->db->join('p_koperasi_aturan as F', 'A.aturan_id=F.id');
        $query = $this->db->join('sistem_login as G', 'A.login_id=G.id');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'AKTIF');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'LUNAS_LANCAR');
        $query = $this->db->where('A.status_kontrak !=', 'MACET');
        $query = $this->db->where('A.status_kontrak !=', 'LUNAS_MACET');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // View Data Pengajuan Pinjaman
    function vd_permintaanPinjaman()
    {
        $query = $this->db->select('*, A.id as nomor_kontrak, C.no_hp as nomor_hp_asli');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id');
        $query = $this->db->join('p_koperasi_aturan as F', 'A.aturan_id=F.id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'AKTIF');
        $query = $this->db->where('A.status_kontrak !=', 'LUNAS_LANCAR');
        $query = $this->db->where('A.status_kontrak !=', 'MACET');
        $query = $this->db->where('A.status_kontrak !=', 'LUNAS_MACET');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // View Data Detail Pengajuan Pinjaman
    function nvd_pengajuanPinjaman($kontrak_id)
    {
        $query = $this->db->select('*, A.id as nomor_kontrak, C.no_hp as nomor_anggota');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id');
        $query = $this->db->join('anggota_keluarga as E', 'A.anggota_id=E.anggota_id');
        $query = $this->db->join('p_koperasi_aturan as F', 'A.aturan_id=F.id');
        $query = $this->db->join('sistem_login as G', 'A.login_id=G.id');
        $query = $this->db->where('A.id', $kontrak_id);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data riwayat pengajuan pinjaman
    function vd_RiwayatPengajuanPinjaman()
    {
        $query = $this->db->select('*, A.id as nomor_kontrak, C.no_hp as nomor_hp_asli');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id');
        $query = $this->db->join('anggota_keluarga_detail as E', 'A.anggota_id=E.anggota_id');
        $query = $this->db->join('p_koperasi_aturan as F', 'A.aturan_id=F.id');
        $query = $this->db->join('sistem_login as G', 'A.login_id=G.id');
        $query = $this->db->where('A.status_kontrak', 'TERIMA');
        $query = $this->db->or_where('A.status_kontrak', 'TOLAK');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data jaminan pinjaman
    function vd_jaminanPinjaman()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_agungan');
        $query = $this->db->get();
        return $query->result();
    }
    // Menu Identitas Anggota koperasi
    // Menampilkan data identitas Pengajuan Anggota Arisan
    function getDataIdentitasAnggota($id_anggota)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('anggota as A');
        $query = $this->db->join('sistem_alamat as B', 'A.id_alamat=B.id');
        $query = $this->db->where('A.id', $id_anggota);
        $query = $this->db->get();
        return $query->row_array();
    }
    function getDataIdentitasAnggotaKeluarga($id_anggota)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('anggota_keluarga');
        $query = $this->db->where('anggota_id', $id_anggota);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data produk arisan heboh aktif anggota
    function getDataProdukAHA($id_anggota)
    {
        $query = $this->db->select('*, A.status as status_arisan, B.id as arisan_id');
        $query = $this->db->from('p_arisan_anggota as A');
        $query = $this->db->join('p_arisan as B', 'A.regist_arisan=B.id');
        $query = $this->db->join('sistem_login as C', 'A.login_id=C.id');
        $query = $this->db->where('A.status', 'AKTIF');
        $query = $this->db->where('A.anggota_id', $id_anggota);
        $query = $this->db->where('B.produk_id', 21);
        $query = $this->db->get();
        return $query->result();
    }
    function getDataProdukAHP($id_anggota)
    {
        $query = $this->db->select('*, A.status as status_arisan, B.id as arisan_id');
        $query = $this->db->from('p_arisan_anggota as A');
        $query = $this->db->join('p_arisan as B', 'A.regist_arisan=B.id');
        $query = $this->db->join('sistem_login as C', 'A.login_id=C.id');
        $query = $this->db->where('A.status !=', 'AKTIF');
        $query = $this->db->where('A.anggota_id', $id_anggota);
        $query = $this->db->where('B.produk_id', 21);
        $query = $this->db->get();
        return $query->result();
    }
    function getDataProdukAMA($id_anggota)
    {
        $query = $this->db->select('*, A.status as status_arisan, B.id as arisan_id');
        $query = $this->db->from('p_arisan_anggota as A');
        $query = $this->db->join('p_arisan as B', 'A.regist_arisan=B.id');
        $query = $this->db->join('sistem_login as C', 'A.login_id=C.id');
        $query = $this->db->where('B.status_arisan', 'AKTIF');
        $query = $this->db->where('A.anggota_id', $id_anggota);
        $query = $this->db->where('B.produk_id', 22);
        $query = $this->db->get();
        return $query->result();
    }
    function getDataProdukAMP($id_anggota)
    {
        $query = $this->db->select('*, A.status as status_arisan, B.id as arisan_id');
        $query = $this->db->from('p_arisan_anggota as A');
        $query = $this->db->join('p_arisan as B', 'A.regist_arisan=B.id');
        $query = $this->db->join('sistem_login as C', 'A.login_id=C.id');
        $query = $this->db->where('B.status_arisan', 'SELESAI');
        $query = $this->db->where('A.anggota_id', $id_anggota);
        $query = $this->db->where('B.produk_id', 22);
        $query = $this->db->get();
        return $query->result();
    }
    // Bagian Ajax
    // Cari anggota koperasi
    function getDataAnggota($nik)
    {
        $query = $this->db->select('*, A.id as id_anggota');
        $query = $this->db->from('anggota as A');
        $query = $this->db->join('sistem_alamat as B', 'A.id_alamat=B.id');
        $query = $this->db->where('A.nik', $nik);
        $query = $this->db->get();
        return $query->row_array();
    }
    function vd_kotkab()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('sistem_alamat');
        $query = $this->db->group_by('kot_kab', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_kecamatan($nm_kot_kab)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('sistem_alamat');
        $query = $this->db->where('kot_kab', $nm_kot_kab);
        $query = $this->db->group_by('nm_kecamatan', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_desa($nm_kecamatan)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('sistem_alamat');
        $query = $this->db->where('nm_kecamatan', $nm_kecamatan);
        $query = $this->db->group_by('nm_desa', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_PinjamanAktif()
    {
        $query = $this->db->select('*, A.id as nomor_kontrak, C.no_hp as nomor_hp_asli');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id');
        $query = $this->db->join('anggota_keluarga_detail as E', 'A.anggota_id=E.anggota_id');
        $query = $this->db->join('p_koperasi_aturan as F', 'A.aturan_id=F.id');
        $query = $this->db->join('sistem_login as G', 'A.login_id=G.id');
        $query = $this->db->where('A.status_kontrak', 'AKTIF');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan buku pinjaman
    function vd_angsuran($kontrak_id)
    {
        $query = $this->db->select('*, A.id as angs_id');
        $query = $this->db->from('p_koperasi_angsuran as A');
        $query = $this->db->join('p_koperasi_kontrak as B', 'A.kontrak_id=B.id');
        $query = $this->db->join('p_koperasi_aturan as C', 'B.aturan_id=C.id');
        $query = $this->db->where('kontrak_id', $kontrak_id);
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan buku pinjaman
    function vd_SudahBayarAngsuran($kontrak_id)
    {
        $query = $this->db->select('SUM(bsr_bayar) as sudah_bayar');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('kontrak_id', $kontrak_id);
        $query = $this->db->where('status_angsuran !=', 'BELUM');
        $query = $this->db->get();
        return $query->row_array();
    }
    // View Data Pinjaman Macet
    function vd_PinjamanMacet()
    {
        $query = $this->db->select('*, A.id as nomor_kontrak, C.no_hp as nomor_hp_asli');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id');
        $query = $this->db->join('anggota_keluarga_detail as E', 'A.anggota_id=E.anggota_id');
        $query = $this->db->join('p_koperasi_aturan as F', 'A.aturan_id=F.id');
        $query = $this->db->join('sistem_login as G', 'A.login_id=G.id');
        $query = $this->db->where('A.status_kontrak', 'MACET');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // View Data Pinjaman Lunas
    function vd_PinjamanLunas()
    {
        $query = $this->db->select('*, A.id as nomor_kontrak, C.no_hp as nomor_hp_asli');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id');
        $query = $this->db->join('anggota_keluarga_detail as E', 'A.anggota_id=E.anggota_id');
        $query = $this->db->join('p_koperasi_aturan as F', 'A.aturan_id=F.id');
        $query = $this->db->join('sistem_login as G', 'A.login_id=G.id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'AKTIF');
        $query = $this->db->where('A.status_kontrak !=', 'MACET');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Mengambil data karyawan marketing
    function getDataKaryawanMarketing()
    {
        $query = $this->db->select('*, A.id as kode_login');
        $query = $this->db->from('sistem_login as A');
        $query = $this->db->where('A.role_id', '7');
        $query = $this->db->get();
        return $query->result();
    }
    // Mengambil data karyawan marketing
    function vd_KaryawanMarketing()
    {
        $query = $this->db->select('*, A.id as kode_login');
        $query = $this->db->from('sistem_login as A');
        $query = $this->db->where('A.status_akun', 'AKTIF');
        $query = $this->db->where('A.role_id !=', '1');
        $query = $this->db->where('A.role_id !=', '2');
        $query = $this->db->where('A.role_id !=', '3');
        $query = $this->db->where('A.role_id !=', '4');
        $query = $this->db->where('A.role_id !=', '5');
        $query = $this->db->where('A.role_id !=', '8');
        $query = $this->db->where('A.role_id !=', '9');
        $query = $this->db->where('A.role_id !=', '10');
        $query = $this->db->where('A.id !=', '5');
        $query = $this->db->where('A.id !=', '13');
        $query = $this->db->where('A.id !=', '24');
        $query = $this->db->where('A.id !=', '27');
        $query = $this->db->where('A.id !=', '33');
        $query = $this->db->where('A.id !=', '18');
        $query = $this->db->where('A.id !=', '25');
        $query = $this->db->where('A.id !=', '26');
        $query = $this->db->get();
        return $query->result();
    }
    // Menu Laporan
    // Bagian Menu Laporan Pinjaman
    // Menampilkan jumlah realisasi harian
    function vd_jmlRealisasiPinjamanTglLoginID()
    {
        $query = $this->db->select('A.login_id as marketing, count(A.id) jml_realisasi');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('B.tgl_realisasi', date('Y-m-d'));
        $query = $this->db->group_by('A.login_id');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan jumlah realisasi bulanan
    function vd_jmlRealisasiPinjamanBlnLoginID()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('A.login_id as marketing, count(A.id) jml_realisasi');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query =  $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query =  $this->db->group_by('A.login_id');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan jumlah realisasi tahunan
    function vd_jmlRealisasiPinjamanThnLoginID()
    {
        $tahun = date('Y');
        $query = $this->db->select('A.login_id as marketing, count(A.id) jml_realisasi');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query =  $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query =  $this->db->group_by('A.login_id');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan jumlah realisasi keseluruhan
    function vd_jmlRealisasiPinjamanAllLoginID()
    {
        $query = $this->db->select('A.login_id as marketing, count(A.id) jml_realisasi');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->group_by('A.login_id');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan jumlah pinjaman aktif harian
    function vd_jmlAktifPinjamanLoginID()
    {
        $query = $this->db->select('login_id as marketing, count(id) jml_aktif');
        $query = $this->db->from('p_koperasi_kontrak');
        $query = $this->db->where('status_kontrak', 'AKTIF');
        $query = $this->db->group_by('login_id');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan jumlah pinjaman lunas harian
    function vd_jmlLunasPinjamanLoginID()
    {
        $query = $this->db->select('login_id as marketing, count(id) jml_lunas');
        $query = $this->db->from('p_koperasi_kontrak');
        $query = $this->db->where('status_kontrak', 'LUNAS_LANCAR');
        $query = $this->db->or_where('status_kontrak', 'LUNAS_MACET');
        $query = $this->db->group_by('login_id');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan jumlah pinjaman lunas harian
    function vd_jmlMacetPinjamanLoginID()
    {
        $query = $this->db->select('login_id as marketing, count(id) jml_macet');
        $query = $this->db->from('p_koperasi_kontrak');
        $query = $this->db->where('status_kontrak', 'MACET');
        $query = $this->db->group_by('login_id');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan tahun tersedia di KAS
    function getDataTahunTransaksi()
    {
        $query = $this->db->select('YEAR(tgl_pembayaran) as tahun_nota_tersedia');
        $query = $this->db->from('nota');
        $query = $this->db->group_by('YEAR(tgl_pembayaran)', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan jumlah realisasi bulanan
    function vd_jmlRealisasiMarketing($marketing_id)
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('count(A.id) jml_realisasi');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.login_id', $marketing_id);
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan jumlah pinjaman aktif harian
    function vd_jmlAktifMarketing($marketing_id)
    {
        $query = $this->db->select('count(id) jml_aktif');
        $query = $this->db->from('p_koperasi_kontrak');
        $query = $this->db->where('status_kontrak', 'AKTIF');
        $query = $this->db->where('login_id', $marketing_id);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan jumlah pinjaman lunas harian
    function vd_jmlLunasMarketing($marketing_id)
    {
        $query = $this->db->select('count(id) jml_lunas');
        $query = $this->db->from('p_koperasi_kontrak');
        $query = $this->db->where('login_id', $marketing_id);
        $query = $this->db->where('status_kontrak', 'LUNAS_LANCAR');
        $query = $this->db->or_where('status_kontrak', 'LUNAS_MACET');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan jumlah pinjaman lunas harian
    function vd_jmlMacetMarketing($marketing_id)
    {
        $query = $this->db->select('count(id) jml_macet');
        $query = $this->db->from('p_koperasi_kontrak');
        $query = $this->db->where('status_kontrak', 'MACET');
        $query = $this->db->where('login_id', $marketing_id);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menu Storting Marketing
    // Storting Per Marketing Harian
    function vd_MarketingPinjaman($marketing_id)
    {
        $query = $this->db->select('*, A.id as nomor_kontrak, C.no_hp as nomor_nasabah');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id');
        $query = $this->db->join('anggota_keluarga_detail as E', 'A.anggota_id=E.anggota_id');
        $query = $this->db->join('p_koperasi_aturan as F', 'A.aturan_id=F.id');
        $query = $this->db->join('sistem_login as G', 'A.login_id=G.id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.login_id', $marketing_id);
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data storting marketing harian
    function vd_stortingMarketingHarian($marketing_id, $tgl)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->join('anggota as E', 'D.anggota_id=E.id');
        $query = $this->db->where('D.login_id', $marketing_id);
        $query = $this->db->where('A.tgl_pembayaran', $tgl);
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data storting marketing harian
    function vd_stortingMarketingHarianOrg($marketing_id, $tgl)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->where('D.login_id', $marketing_id);
        $query = $this->db->where('A.tgl_pembayaran', $tgl);
        $query = $this->db->group_by('D.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data total storting marketing harian
    function vd_stortingTotalMarketingHarian($marketing_id, $tgl)
    {
        $query = $this->db->select('SUM(C.bsr_bayar) as jml_storting');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->where('D.login_id', $marketing_id);
        $query = $this->db->where('A.tgl_pembayaran', $tgl);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data pokok storting marketing harian
    function vd_stortingPokokMarketingHarian($marketing_id, $tgl)
    {
        $query = $this->db->select('SUM(C.bsr_pokok) as jml_pokok');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->where('D.login_id', $marketing_id);
        $query = $this->db->where('A.tgl_pembayaran', $tgl);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data jasa storting marketing harian
    function vd_stortingJasaMarketingHarian($marketing_id, $tgl)
    {
        $query = $this->db->select('SUM(C.bsr_jasa) as jml_jasa');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->where('D.login_id', $marketing_id);
        $query = $this->db->where('A.tgl_pembayaran', $tgl);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data simpanan storting marketing harian
    function vd_stortingSimpananMarketingHarian($marketing_id, $tgl)
    {
        $query = $this->db->select('SUM(C.bsr_simpanan) as jml_simpanan');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->where('D.login_id', $marketing_id);
        $query = $this->db->where('A.tgl_pembayaran', $tgl);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data target storting marketing harian
    function vd_stortingTargetMarketingHarian($marketing_id, $tgl)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_angsuran as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->where('A.login_id', $marketing_id);
        $query = $this->db->where('B.tgl_tempo', $tgl);
        $query = $this->db->where('B.status_angsuran !=', 'LUNAS_LANCAR');
        $query = $this->db->where('B.status_angsuran !=', 'LUNAS_MACET');
        $query = $this->db->where('B.status_angsuran !=', 'PROSES');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan jumlah target storting marketing harian
    function vd_stortingJmlTargetMarketingHarian($marketing_id, $tgl)
    {
        $query = $this->db->select('sum(bsr_bayar) as jml_target');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_angsuran as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->where('A.login_id', $marketing_id);
        $query = $this->db->where('B.tgl_tempo', $tgl);
        $query = $this->db->where('B.status_angsuran !=', 'LUNAS_LANCAR');
        $query = $this->db->where('B.status_angsuran !=', 'LUNAS_MACET');
        $query = $this->db->where('B.status_angsuran !=', 'PROSES');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data realisasi marketing harian
    function vd_realisasiPinjamanMarketing($marketing_id, $tgl)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id');
        $query = $this->db->where('A.login_id', $marketing_id);
        $query = $this->db->where('B.tgl_realisasi', $tgl);
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan jumlah atau besar realisasi marketing harian
    function vd_realisasiJmlPinjamanMarketing($marketing_id, $tgl)
    {
        $query = $this->db->select('SUM(A.pokok_pinjaman) as jml_realisasi');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->where('A.login_id', $marketing_id);
        $query = $this->db->where('B.tgl_realisasi', $tgl);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan jumlah atau besar realisasi marketing harian
    function vd_realisasiJmlAdministrasiMarketing($marketing_id, $tgl)
    {
        $query = $this->db->select('SUM(A.bsr_admin) as jml_admin');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->where('A.login_id', $marketing_id);
        $query = $this->db->where('B.tgl_realisasi', $tgl);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan jumlah atau besar realisasi marketing harian
    function vd_realisasiJmlRKMarketing($marketing_id, $tgl)
    {
        $query = $this->db->select('SUM(A.bsr_rk) as jml_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->where('A.login_id', $marketing_id);
        $query = $this->db->where('B.tgl_realisasi', $tgl);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menu Storting Marketing
    // Menampilkan data storting marketing harian
    function vd_stortingMarketingBulanan($marketing_id, $bulan, $tahun)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->join('anggota as E', 'D.anggota_id=E.id');
        $query = $this->db->where('D.login_id', $marketing_id);
        $query = $this->db->where('MONTH(A.tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(A.tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data storting marketing harian
    function vd_stortingMarketingBulananOrg($marketing_id, $bulan, $tahun)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->where('D.login_id', $marketing_id);
        $query = $this->db->where('MONTH(A.tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(A.tgl_pembayaran)', $tahun);
        $query = $this->db->group_by('D.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data total storting marketing harian
    function vd_stortingTotalMarketingBulanan($marketing_id, $bulan, $tahun)
    {
        $query = $this->db->select('SUM(C.bsr_bayar) as jml_storting');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->where('D.login_id', $marketing_id);
        $query = $this->db->where('MONTH(A.tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(A.tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data pokok storting marketing harian
    function vd_stortingPokokMarketingBulanan($marketing_id, $bulan, $tahun)
    {
        $query = $this->db->select('SUM(C.bsr_pokok) as jml_pokok');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->where('D.login_id', $marketing_id);
        $query = $this->db->where('MONTH(A.tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(A.tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data jasa storting marketing harian
    function vd_stortingJasaMarketingBulanan($marketing_id, $bulan, $tahun)
    {
        $query = $this->db->select('SUM(C.bsr_jasa) as jml_jasa');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->where('D.login_id', $marketing_id);
        $query = $this->db->where('MONTH(A.tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(A.tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data simpanan storting marketing harian
    function vd_stortingSimpananMarketingBulanan($marketing_id, $bulan, $tahun)
    {
        $query = $this->db->select('SUM(C.bsr_simpanan) as jml_simpanan');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->where('D.login_id', $marketing_id);
        $query = $this->db->where('MONTH(A.tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(A.tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data target storting marketing harian
    function vd_stortingTargetMarketingBulanan($marketing_id, $bulan, $tahun)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_angsuran as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->where('A.login_id', $marketing_id);
        $query = $this->db->where('MONTH(B.tgl_tempo)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_tempo)', $tahun);
        $query = $this->db->where('B.status_angsuran !=', 'LUNAS_LANCAR');
        $query = $this->db->where('B.status_angsuran !=', 'LUNAS_MACET');
        $query = $this->db->where('B.status_angsuran !=', 'PROSES');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan jumlah target storting marketing harian
    function vd_stortingJmlTargetMarketingBulanan($marketing_id, $bulan, $tahun)
    {
        $query = $this->db->select('sum(bsr_bayar) as jml_target');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_angsuran as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->where('A.login_id', $marketing_id);
        $query = $this->db->where('MONTH(B.tgl_tempo)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_tempo)', $tahun);
        $query = $this->db->where('B.status_angsuran !=', 'LUNAS_LANCAR');
        $query = $this->db->where('B.status_angsuran !=', 'LUNAS_MACET');
        $query = $this->db->where('B.status_angsuran !=', 'PROSES');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data realisasi marketing harian
    function vd_realisasiPinjamanMarketingBulanan($marketing_id, $bulan, $tahun)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id');
        $query = $this->db->where('A.login_id', $marketing_id);
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan jumlah atau besar realisasi marketing harian
    function vd_realisasiJmlPinjamanMarketingBulanan($marketing_id, $bulan, $tahun)
    {
        $query = $this->db->select('SUM(A.pokok_pinjaman) as jml_realisasi');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->where('A.login_id', $marketing_id);
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan jumlah atau besar realisasi marketing harian
    function vd_realisasiJmlAdministrasiMarketingBulanan($marketing_id, $bulan, $tahun)
    {
        $query = $this->db->select('SUM(A.bsr_admin) as jml_admin');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->where('A.login_id', $marketing_id);
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan jumlah atau besar realisasi marketing harian
    function vd_realisasiJmlRKMarketingBulanan($marketing_id, $bulan, $tahun)
    {
        $query = $this->db->select('SUM(A.bsr_rk) as jml_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->where('A.login_id', $marketing_id);
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas masuk ( Storting ) harian
    function vd_TagihanKoperasiHarian()
    {
        $query = $this->db->select('SUM(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('substr(produk_id, 1, 2)=', '12');
        $query = $this->db->where('status_kas', 'MASUK');
        $query = $this->db->where('tgl_pembayaran', date('Y-m-d'));
        $query = $this->db->where('status_nota !=', 'PROSES');
        $query = $this->db->where('status_nota !=', 'TOLAK');
        $query = $this->db->where('status_nota !=', 'PROSES_TUNGGAKAN');
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas keluar ( realisasi ) harian
    function vd_RealisasiKoperasiHarian()
    {
        $query = $this->db->select('SUM(A.pokok_pinjaman) as saldo, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('B.tgl_realisasi', date('Y-m-d'));
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas masuk ( Storting ) bulanan
    function vd_TagihanKoperasiBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('substr(produk_id, 1, 2)=', '12');
        $query = $this->db->where('status_kas', 'MASUK');
        $query = $this->db->where('status_nota', 'TERIMA');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->where('status_nota !=', 'PROSES');
        $query = $this->db->where('status_nota !=', 'TOLAK');
        $query = $this->db->where('status_nota !=', 'PROSES_TUNGGAKAN');
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas keluar ( realisasi ) bulanan
    function vd_RealisasiKoperasiBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(A.pokok_pinjaman) as saldo, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }

    // menampilkan data kas masuk harian
    function vd_RealisasiKoperasiHarianBeranda()
    {
        $query = $this->db->select('SUM(A.pokok_pinjaman) as saldo, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('B.tgl_realisasi', date('Y-m-d'));
        $query = $this->db->get();
        return $query->row_array();
    }

    // menampilkan data kas masuk harian
    function vd_RealisasiKoperasiBulananBeranda()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(A.pokok_pinjaman) as saldo, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    function vd_transaksiKoperasiBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('*, A.id as kd_nota');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'B.nota_id=A.id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->join('anggota as E', 'D.anggota_id=E.id');
        $query = $this->db->join('sistem_alamat as F', 'E.id_alamat=F.id');
        $query = $this->db->where('substr(A.produk_id, 1, 2)=', '12');
        $query = $this->db->where('status_nota !=', 'TERIMA');
        $query = $this->db->where('status_nota !=', 'TOLAK');
        $query = $this->db->where('status_nota !=', 'TERIMA_TUNGGAKAN');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->result();
    }
    function vd_RiwayatTransaksiPengajuanPinjaman()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('*, A.id as nomor_kontrak');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id');
        $query = $this->db->join('anggota_keluarga as E', 'A.anggota_id=E.anggota_id');
        $query = $this->db->join('p_koperasi_aturan as F', 'A.aturan_id=F.id');
        $query = $this->db->join('sistem_login as G', 'A.login_id=G.id');
        $query = $this->db->where('A.status_kontrak', 'AKTIF');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_transaksiDataTagihan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('*, A.id as angsuran_id');
        $query = $this->db->from('p_koperasi_angsuran as A');
        $query = $this->db->join('p_koperasi_kontrak as B', 'A.kontrak_id=B.id');
        $query = $this->db->join('p_koperasi_aturan as C', 'B.aturan_id=C.id');
        $query = $this->db->join('anggota as D', 'B.anggota_id=D.id');
        $query = $this->db->join('sistem_alamat as E', 'D.id_alamat=E.id');
        $query = $this->db->where('A.status_angsuran !=', 'PROSES');
        $query = $this->db->where('A.status_angsuran !=', 'BELUM');
        $query = $this->db->where('A.status_angsuran !=', 'MACET');
        $query = $this->db->where('MONTH(A.tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(A.tgl_bayar)', $tahun);
        $query = $this->db->group_by('A.id', 'desc');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan semua anggota koperasi
    function vd_anggotaKoeprasi()
    {
        $query = $this->db->select('*, A.id as anggota_id, B.id alamat_id');
        $query = $this->db->from('anggota as A');
        $query = $this->db->join('sistem_alamat as B', 'A.id_alamat=B.id');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan semua anggota koperasi
    function vd_anggotaKoeprasiAktif()
    {
        $query = $this->db->select('*, A.id as anggota_id, B.id alamat_id');
        $query = $this->db->from('anggota as A');
        $query = $this->db->join('sistem_alamat as B', 'A.id_alamat=B.id');
        $query = $this->db->where('A.status_anggota', 'ANGGOTA');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan semua anggota koperasi
    function vd_anggotaKoeprasiPasif()
    {
        $query = $this->db->select('*, A.id as anggota_id, B.id alamat_id');
        $query = $this->db->from('anggota as A');
        $query = $this->db->join('sistem_alamat as B', 'A.id_alamat=B.id');
        $query = $this->db->where('A.status_anggota', 'CALON_ANGGOTA');
        $query = $this->db->get();
        return $query->result();
    }
    // MEnu Beranda
    // Bagian Penagihan Kerja Hari Ini
    function vd_tagihanHariIni()
    {
        $query = $this->db->select('*, A.id as angsuran_id, E.no_hp as nomor_hp_asli');
        $query = $this->db->from('p_koperasi_angsuran as A');
        $query = $this->db->join('p_koperasi_kontrak as B', 'A.kontrak_id=B.id');
        $query = $this->db->join('p_koperasi_aturan as C', 'B.aturan_id=C.id');
        $query = $this->db->join('sistem_produk_koperasi as D', 'C.produk_id=D.id');
        $query = $this->db->join('anggota as E', 'B.anggota_id=E.id');
        $query = $this->db->join('sistem_alamat as F', 'E.id_alamat=F.id');
        $query = $this->db->where('A.tgl_tempo', date('Y-m-d'));
        $query = $this->db->where('A.status_angsuran !=', 'LUNAS_LANCAR');
        $query = $this->db->where('A.status_angsuran !=', 'LUNAS_MACET');
        $query = $this->db->where('A.status_angsuran !=', 'LUNAS_MACET');
        $query = $this->db->or_where('A.status_angsuran', 'MACET');
        $query = $this->db->get();
        return $query->result();
    }
    function get_vdAngsuranBayar($data_kontrak)
    {
        // $this->db->get_where('p_koperasi_angsuran', ['kontrak_id' => $data_kontrak['id'], 'status_angsuran !=' => 'BELUM', 'status_angsuran !=' => 'MACET', 'status_angsuran !=' => 'PROSES'])->result()
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('kontrak_id', $data_kontrak['id']);
        $query = $this->db->where('status_angsuran !=', 'BELUM');
        $query = $this->db->where('status_angsuran !=', 'MACET');
        $query = $this->db->where('status_angsuran !=', 'PROSES');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data invoice
    function getDataInvoice($kd_invoice)
    {
        $query = $this->db->select('*, A.id as kd_invoice, B.no_hp as hp_anggota');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('anggota as B', 'A.anggota_id=B.id');
        $query = $this->db->join('sistem_alamat as C', 'B.id_alamat=C.id');
        $query = $this->db->join('sistem_login as D', 'A.petugas=D.id');
        $query = $this->db->where('A.id', $kd_invoice);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Data Invoice Rincian
    function getDataInvoiceRinci($kd_invoice)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'B.nota_id=A.id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->join('p_koperasi_aturan as E', 'D.aturan_id=E.id');
        $query = $this->db->where('A.id', $kd_invoice);
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan jumlah Rupiah realisasi bulanan
    function vd_totalJmlRealisasi($marketing_id, $bulan, $tahun)
    {
        $query = $this->db->select('sum(A.pokok_pinjaman) jml_realisasi');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak', 'AKTIF');
        $query = $this->db->where('A.login_id', $marketing_id);
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan jumlah Rupiah realisasi bulanan devisi
    function vd_totalJmlRealisasiDevisi1($bulan, $tahun)
    {
        $query = $this->db->select('sum(A.pokok_pinjaman) as jml_realisasi');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak', 'AKTIF');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->where('A.aturan_id', '1');
        $query = $this->db->get();
        return $query->row_array();
    }
    function vd_totalJmlRealisasiDevisi2($bulan, $tahun)
    {
        $query = $this->db->select('sum(A.pokok_pinjaman) as jml_realisasi');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak', 'AKTIF');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->where('A.aturan_id', '2');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan jumlah Rupiah storting bulanan Devisi
    function vd_totalJmlStortingDevisi1($bulan, $tahun)
    {
        $query = $this->db->select('sum(A.bsr_bayar) as jml_storting');
        $query = $this->db->from('p_koperasi_angsuran as A');
        $query = $this->db->join('p_koperasi_kontrak as B', 'A.kontrak_id=B.id');
        $query = $this->db->where('MONTH(A.tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(A.tgl_bayar)', $tahun);
        $query = $this->db->where('B.aturan_id', '1');
        $query = $this->db->get();
        return $query->row_array();
    }
    function vd_totalJmlStortingDevisi2($bulan, $tahun)
    {
        $query = $this->db->select('sum(A.bsr_bayar) as jml_storting');
        $query = $this->db->from('p_koperasi_angsuran as A');
        $query = $this->db->join('p_koperasi_kontrak as B', 'A.kontrak_id=B.id');
        $query = $this->db->where('MONTH(A.tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(A.tgl_bayar)', $tahun);
        $query = $this->db->where('B.aturan_id', '2');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan jumlah Rupiah storting bulanan
    function vd_totalJmlStorting($marketing_id, $bulan, $tahun)
    {
        $query = $this->db->select('sum(A.bsr_bayar) jml_storting');
        $query = $this->db->from('p_koperasi_angsuran as A');
        $query = $this->db->join('p_koperasi_kontrak as B', 'A.kontrak_id=B.id');
        $query = $this->db->where('MONTH(A.tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(A.tgl_bayar)', $tahun);
        $query = $this->db->where('B.login_id', $marketing_id);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan jumlah binatang review
    function vd_bintangReviewsPelanggan($marketing_id, $bulan, $tahun)
    {
        $query = $this->db->select('sum(rating) as rate_bintang');
        $query = $this->db->from('k_rkonsumen');
        $query = $this->db->where('login_id', $marketing_id);
        $query = $this->db->where('MONTH(tgl_review)', $bulan);
        $query = $this->db->where('YEAR(tgl_review)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data detail KPI
    function vd_detKPIMarketing($hasil_id)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('k_dhasil as A');
        $query = $this->db->join('k_faktor as B', 'A.faktor_id=B.id');
        $query = $this->db->join('k_komp as C', 'B.komp_id=C.id');
        $query = $this->db->where('A.hasil_id', $hasil_id);
        $query = $this->db->get();
        return $query->result();
    }
    // Menu KPI Marketing
    // Melihat data Komponen dan Faktor Nilai Marketing
    function vd_KompFaktor()
    {
        $query = $this->db->select('*, B.id as faktor_id');
        $query = $this->db->from('k_komp as A');
        $query = $this->db->join('k_faktor as B', 'A.id=B.komp_id');
        $query = $this->db->where('A.sts_komp', 'AKTIF');
        $query = $this->db->where('A.tgt', 'MARKETING');
        $query = $this->db->where('B.sts_faktor', 'AKTIF');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_persentaseKompFaktor()
    {
        $query = $this->db->select('SUM(B.pers_faktor) as jml_persentase');
        $query = $this->db->from('k_komp as A');
        $query = $this->db->join('k_faktor as B', 'A.id=B.komp_id');
        $query = $this->db->where('A.sts_komp', 'AKTIF');
        $query = $this->db->where('A.tgt', 'MARKETING');
        $query = $this->db->where('B.sts_faktor', 'AKTIF');
        $query = $this->db->get();
        return $query->row_array();
    }
    function vd_marketingAktif()
    {
        $query = $this->db->select('*, A.id as marketing_id');
        $query = $this->db->from('sistem_login as A');
        $query = $this->db->join('sistem_identitas as B', 'A.id=B.login_id');
        $query = $this->db->join('sistem_alamat as C', 'B.alamat_id=C.id');
        $query = $this->db->join('sistem_role_level as D', 'A.role_id=D.id');
        $query = $this->db->where('A.status_akun', 'AKTIF');
        $query = $this->db->where('A.role_id', '7');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_targetMarketingBulanan($faktor_id)
    {
        $query = $this->db->select('*, A.id as target_id');
        $query = $this->db->from('k_target as A');
        $query = $this->db->join('k_faktor as B', 'A.faktor_id=B.id');
        $query = $this->db->join('k_komp as C', 'B.komp_id=C.id');
        $query = $this->db->join('sistem_login as D', 'A.login_id=D.id');
        $query = $this->db->join('sistem_identitas as E', 'D.id=E.login_id');
        $query = $this->db->join('sistem_alamat as F', 'E.alamat_id=F.id');
        $query = $this->db->where('A.faktor_id', $faktor_id);
        $query = $this->db->where('A.sts_target', 'AKTIF');
        $query = $this->db->get();
        return $query->result();
    }
    // Menu laporan pinjaman koperasi
    // Data Marketing
    function vd_marketingAktf()
    {
        $query = $this->db->select('*, A.id as marketing_id');
        $query = $this->db->from('sistem_login as A');
        $query = $this->db->join('sistem_identitas as B', 'A.id=B.login_id');
        $query = $this->db->where('A.role_id', '6');
        $query = $this->db->where('A.role_id', '6');
        $query = $this->db->or_where('A.role_id', '7');
        $query = $this->db->get();
        return $query->result();
    }
    // Data Realisasi
    function vd_realisasiSemua($tgl)
    {
        $query = $this->db->select('A.login_id as marketing_id, SUM(A.pokok_pinjaman) as ttl_realisasi, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('B.tgl_realisasi', $tgl);
        $query = $this->db->group_by('A.login_id');
        $query = $this->db->get();
        return $query->result();
    }
    // Data Target Storting
    function vd_targetStortingSemua($tgl)
    {
        $query = $this->db->select('A.login_id as marketing_id, SUM(B.bsr_bayar) as ttl_target');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_angsuran as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('B.tgl_tempo', $tgl);
        $query = $this->db->group_by('A.login_id');
        $query = $this->db->get();
        return $query->result();
    }
    // Data Storting
    function vd_stortingSemua($tgl)
    {
        $query = $this->db->select('A.login_id as marketing_id, SUM(B.bsr_bayar) as ttl_bayar, SUM(B.bsr_pokok) as ttl_pokok, SUM(B.bsr_jasa) as ttl_jasa,SUM(B.bsr_simpanan) as ttl_simpanan');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_angsuran as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('B.tgl_bayar', $tgl);
        $query = $this->db->group_by('A.login_id');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah total realisasi
    function jml_realisasisemua($tgl)
    {
        $query = $this->db->select('SUM(A.pokok_pinjaman) as ttl_realisasi, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('B.tgl_realisasi', $tgl);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Jumlah total Target Storting
    function jml_targetStortingSemua($tgl)
    {
        $query = $this->db->select('SUM(B.bsr_bayar) as ttl_target');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_angsuran as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('B.tgl_tempo', $tgl);
        $query = $this->db->get();
        return $query->row_array();
    }
    function jml_stortingSemua($tgl)
    {
        $query = $this->db->select('SUM(B.bsr_bayar) as ttl_bayar, SUM(B.bsr_pokok) as ttl_pokok, SUM(B.bsr_jasa) as ttl_jasa,SUM(B.bsr_simpanan) as ttl_simpanan');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_angsuran as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('B.tgl_bayar', $tgl);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Laporan Bulanan
    // Data Realisasi
    function vd_realisasiSemuaBulanan($bulan, $tahun)
    {
        $query = $this->db->select('A.login_id as marketing_id, SUM(A.pokok_pinjaman) as ttl_realisasi, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->group_by('A.login_id');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah total realisasi
    function jml_realisasisemuaBulanan($bulan, $tahun)
    {
        $query = $this->db->select('SUM(A.pokok_pinjaman) as ttl_realisasi, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Data Target Storting
    function vd_targetStortingSemuaBulanan($bulan, $tahun)
    {
        $query = $this->db->select('A.login_id as marketing_id, SUM(B.bsr_bayar) as ttl_target');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_angsuran as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('MONTH(B.tgl_tempo)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_tempo)', $tahun);
        $query = $this->db->group_by('A.login_id');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah total Target Storting
    function jml_targetStortingSemuaBulanan($bulan, $tahun)
    {
        $query = $this->db->select('SUM(B.bsr_bayar) as ttl_target');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_angsuran as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('MONTH(B.tgl_tempo)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_tempo)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Data Storting
    function vd_stortingSemuaBulanan($bulan, $tahun)
    {
        $query = $this->db->select('A.login_id as marketing_id, SUM(B.bsr_bayar) as ttl_bayar, SUM(B.bsr_pokok) as ttl_pokok, SUM(B.bsr_jasa) as ttl_jasa,SUM(B.bsr_simpanan) as ttl_simpanan');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_angsuran as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('MONTH(B.tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_bayar)', $tahun);
        $query = $this->db->group_by('A.login_id');
        $query = $this->db->get();
        return $query->result();
    }
    function jml_stortingSemuaBulanan($bulan, $tahun)
    {
        $query = $this->db->select('SUM(B.bsr_bayar) as ttl_bayar, SUM(B.bsr_pokok) as ttl_pokok, SUM(B.bsr_jasa) as ttl_jasa,SUM(B.bsr_simpanan) as ttl_simpanan');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_angsuran as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('MONTH(B.tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_bayar)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
}
