<?php

use Google\Service\CloudSearch\Resource\Query;

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

class Select_model extends CI_Model
{
    // Alamat Baru
    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();
    }
    // Mengambil data semua karyawan
    function vd_anggotaKaryawan()
    {
        $query = $this->db->select('*, A.id as login_id');
        $query = $this->db->from('sistem_login as A');
        $query = $this->db->join('sistem_role_level as B', 'A.role_id=B.id');
        $query = $this->db->where('A.id !=', '1');
        $query = $this->db->where('A.id !=', $this->session->userdata('isloggedin'));
        $query = $this->db->get();
        return $query->result();
    }
    function vd_KaryawanAktifKerja()
    {
        $query = $this->db->select('*');
        $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->get();
        return $query->result();
    }
    // Mengambil data role level
    function getDataRoleLevel()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('sistem_role_level');
        $query = $this->db->where('id !=', '1');
        $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();
    }
    // Mengambil semua data anggota terdaftar koperasi
    function getDataAnggotaArisan()
    {
        $query = $this->db->select('*, B.id as anggota_id');
        $query = $this->db->from('tbl_anggota as B');
        $query = $this->db->join('sistem_alamat as C', 'B.id_alamat=C.id');
        $query = $this->db->get();
        return $query->result();
    }
    // Mengambil data semua kas kelompok
    function getDataSemuaKasKelompok()
    {
        $query = $this->db->select('(SUM(saldo_masuk))-(SUM(saldo_pemenang)) as saldo_kaskelompok');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('substr(regist_arisan, 3, 2)=', '21');
        $query = $this->db->where('status_laporan', 'VERIFIED');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Mengambil data semua kas kelompok
    function filter_getDataSemuaKasKelompok($bulan, $tahun)
    {
        $query = $this->db->select('(SUM(saldo_masuk))-(SUM(saldo_pemenang)) as saldo_kaskelompok');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('substr(regist_arisan, 3, 2)=', '21');
        $query = $this->db->where('status_laporan', 'VERIFIED');
        $query = $this->db->where('MONTH(tgl_laporan)', $bulan);
        $query = $this->db->where('YEAR(tgl_laporan)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Mengambil data semua kas lelang
    function getDataSemuaKasLelang()
    {
        $query = $this->db->select('(SUM(saldo_masuk)-SUM(saldo_pemenang)-SUM(administrasi)-SUM(dn_kehilangan)) as saldo_kaslelang');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('substr(regist_arisan, 3, 2)=', '22');
        $query = $this->db->where('status_laporan', 'VERIFIED');
        $query = $this->db->get();
        return $query->row_array();
    }
    function filter_getDataSemuaKasLelang($bulan, $tahun)
    {
        $query = $this->db->select('(SUM(saldo_masuk)-SUM(saldo_pemenang)-SUM(administrasi)-SUM(dn_kehilangan)) as saldo_kaslelang');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('substr(regist_arisan, 3, 2)=', '22');
        $query = $this->db->where('status_laporan', 'VERIFIED');
        $query = $this->db->where('MONTH(tgl_laporan)', $bulan);
        $query = $this->db->where('YEAR(tgl_laporan)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Mengambil data semua pendapatan kelompok
    function getDataSemuaPendapatanKelompok()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('(SUM(administrasi)) as saldo');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('substr(regist_arisan, 3, 2)=', '21');
        $query = $this->db->where('status_laporan', 'VERIFIED');
        $query = $this->db->where('MONTH(tgl_laporan)', $bulan);
        $query = $this->db->where('YEAR(tgl_laporan)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    function filter_getDataSemuaPendapatanKelompok($bulan, $tahun)
    {
        $query = $this->db->select('(SUM(administrasi)) as saldo');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('substr(regist_arisan, 3, 2)=', '21');
        $query = $this->db->where('status_laporan', 'VERIFIED');
        $query = $this->db->where('MONTH(tgl_laporan)', $bulan);
        $query = $this->db->where('YEAR(tgl_laporan)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Mengambil data semua pendapatan kelompok
    function getDataSemuaPendapatanLelang()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('(SUM(administrasi))+(SUM(dn_kehilangan))+(SUM(fee_dealer)) as saldo');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('substr(regist_arisan, 3, 2)=', '22');
        $query = $this->db->where('status_laporan', 'VERIFIED');
        $query = $this->db->where('MONTH(tgl_laporan)', $bulan);
        $query = $this->db->where('YEAR(tgl_laporan)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    function filter_getDataSemuaPendapatanLelang($bulan, $tahun)
    {
        $query = $this->db->select('(SUM(administrasi))+(SUM(dn_kehilangan))+(SUM(fee_dealer)) as saldo');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('substr(regist_arisan, 3, 2)=', '22');
        $query = $this->db->where('status_laporan', 'VERIFIED');
        $query = $this->db->where('MONTH(tgl_laporan)', $bulan);
        $query = $this->db->where('YEAR(tgl_laporan)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan semua laporan arisan heboh
    function getDataSemuaLaporanVerifikasi()
    {
        $query = $this->db->select('*, A.id as kd_laporan, A.tgl_undian as undian_tenan');
        $query = $this->db->from('lap_arisan as A');
        $query = $this->db->join('lap_arisan_menang as E', 'A.id=E.laporan_id');
        $query = $this->db->join('p_arisan_jadwal as F', 'A.jadwal_id=F.id');
        $query = $this->db->join('p_arisan_anggota as B', 'E.regist_undian=B.regist_undian');
        $query = $this->db->join('anggota as C', 'B.anggota_id=C.id');
        $query = $this->db->join('p_arisan as D', 'A.regist_arisan=D.id');
        $query = $this->db->where('A.status_laporan', 'MANAGER');
        $query = $this->db->get();
        return $query->result();
    }
    function filter_getDataSemuaLaporanVerifikasi($bulan, $tahun)
    {
        $query = $this->db->select('*, A.id as kd_laporan, A.tgl_undian as undian_tenan');
        $query = $this->db->from('lap_arisan as A');
        $query = $this->db->join('lap_arisan_menang as E', 'A.id=E.laporan_id');
        $query = $this->db->join('p_arisan_jadwal as F', 'A.jadwal_id=F.id');
        $query = $this->db->join('p_arisan_anggota as B', 'E.regist_undian=B.regist_undian');
        $query = $this->db->join('anggota as C', 'B.anggota_id=C.id');
        $query = $this->db->join('p_arisan as D', 'A.regist_arisan=D.id');
        $query = $this->db->where('A.status_laporan', 'MANAGER');
        $query = $this->db->where('MONTH(A.tgl_laporan)', $bulan);
        $query = $this->db->where('YEAR(A.tgl_laporan)', $tahun);
        $query = $this->db->get();
        return $query->result();
    }
    function getDataSemuaLaporanHeboh()
    {
        $query = $this->db->select('*, A.id as kd_laporan, A.tgl_undian as undian_tenan');
        $query = $this->db->from('lap_arisan as A');
        $query = $this->db->join('lap_arisan_menang as E', 'A.id=E.laporan_id');
        $query = $this->db->join('p_arisan_jadwal as F', 'A.jadwal_id=F.id');
        $query = $this->db->join('p_arisan_anggota as B', 'E.regist_undian=B.regist_undian');
        $query = $this->db->join('anggota as C', 'B.anggota_id=C.id');
        $query = $this->db->join('p_arisan as D', 'A.regist_arisan=D.id');
        $query = $this->db->where('substr(A.regist_arisan, 3, 2)=', '21');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan semua laporan arisan motor
    function getDataSemuaLaporanLelang()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('lap_arisan as A');
        $query = $this->db->join('lap_arisan_menang as E', 'A.id=E.laporan_id');
        $query = $this->db->join('p_arisan_anggota as B', 'E.regist_undian=B.regist_undian');
        $query = $this->db->join('anggota as C', 'B.anggota_id=C.id');
        $query = $this->db->join('p_arisan as D', 'A.regist_arisan=D.id');
        $query = $this->db->where('substr(A.regist_arisan, 3, 2)=', '22');
        $query = $this->db->get();
        return $query->result();
    }
    function filter_getDataSemuaLaporanLelang($bulan, $tahun)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('lap_arisan as A');
        $query = $this->db->join('lap_arisan_menang as E', 'A.id=E.laporan_id');
        $query = $this->db->join('p_arisan_anggota as B', 'E.regist_undian=B.regist_undian');
        $query = $this->db->join('anggota as C', 'B.anggota_id=C.id');
        $query = $this->db->join('p_arisan as D', 'A.regist_arisan=D.id');
        $query = $this->db->where('substr(A.regist_arisan, 3, 2)=', '22');
        $query = $this->db->where('MONTH(A.tgl_laporan)', $bulan);
        $query = $this->db->where('YEAR(A.tgl_laporan)', $tahun);
        $query = $this->db->get();
        return $query->result();
    }
    // Data Arisan Heboh Belum
    function getProdukArisanHebohBelum()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_arisan');
        $query = $this->db->where('produk_id', 21);
        $query = $this->db->where('status_arisan', 'PROSES');
        $query = $this->db->get();
        return $query->result();
    }
    // Data Arisan Heboh Aktif
    function getProdukArisanMotorBelum()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_arisan');
        $query = $this->db->where('produk_id', 22);
        $query = $this->db->where('status_arisan', 'PROSES');
        $query = $this->db->get();
        return $query->result();
    }
    // Data Arisan Heboh Aktif
    function getProdukArisanHeboh()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_arisan');
        $query = $this->db->where('produk_id', 21);
        $query = $this->db->where('status_arisan', 'AKTIF');
        $query = $this->db->get();
        return $query->result();
    }
    // Data Arisan Heboh Aktif
    function getProdukArisanMotor()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_arisan');
        $query = $this->db->where('produk_id', 22);
        $query = $this->db->where('status_arisan', 'AKTIF');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan semua anggota yang menunggak
    function getDataTunggakanArisan()
    {
        $query = $this->db->select('*, D.tgl_undian as undian_tenanan');
        $query = $this->db->from('lap_arisan_nunggak as A');
        $query = $this->db->join('p_arisan_anggota as B', 'A.regist_undian=B.regist_undian');
        $query = $this->db->join('anggota as C', 'B.anggota_id=C.id');
        $query = $this->db->join('p_arisan_jadwal as D', 'A.jadwal_id=D.id');
        $query = $this->db->join('p_arisan as E', 'A.regist_arisan=E.id');
        $query = $this->db->join('sistem_login as F', 'B.login_id=F.id');
        $query = $this->db->where('A.status_tunggakan', 'AKTIF');
        $query = $this->db->get();
        return $query->result();
    }
    // Menu Arisan Sub Menu Arisan Heboh
    // Mengambil semua data arisan kategori heboh
    function getAllDataArisanHeboh()
    {
        $query = $this->db->select('*, A.id as regist_arisan');
        $query = $this->db->from('p_arisan as A');
        $query = $this->db->join('sistem_produk_koperasi as B', 'A.produk_id=B.id');
        $query = $this->db->where('A.produk_id', 21);
        $query = $this->db->where('A.status_arisan !=', 'PROSES');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan jumlah anggota aktif setiap kelompok
    function getDataJmlAnggotaHeboh()
    {
        $query = $this->db->select('B.regist_arisan as regist_arisan, count(B.regist_arisan) as anggota');
        $query = $this->db->from('p_arisan as A');
        $query = $this->db->join('p_arisan_anggota as B', 'A.id=B.regist_arisan');
        $query = $this->db->where('B.status', 'AKTIF');
        $query = $this->db->group_by('B.regist_arisan');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan jumlah anggota aktif setiap kelompok
    function getDataJmlAnggotaHebohMenang()
    {
        $query = $this->db->select('B.regist_arisan as regist_arisan, count(B.regist_arisan) as anggota');
        $query = $this->db->from('p_arisan as A');
        $query = $this->db->join('p_arisan_anggota as B', 'A.id=B.regist_arisan');
        $query = $this->db->where('B.status', 'MENANG');
        $query = $this->db->group_by('B.regist_arisan');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan jumlah anggota aktif setiap kelompok
    function getDataJmlAnggotaHebohMundur()
    {
        $query = $this->db->select('B.regist_arisan as regist_arisan, count(B.regist_arisan) as anggota');
        $query = $this->db->from('p_arisan as A');
        $query = $this->db->join('p_arisan_anggota as B', 'A.id=B.regist_arisan');
        $query = $this->db->where('B.status', 'MUNDUR');
        $query = $this->db->group_by('B.regist_arisan');
        $query = $this->db->get();
        return $query->result();
    }
    // Mengambil data pendapatan Arisan Heboh Dari Awal
    function getPendapatanArisanHebohKelompok($regist_arisan)
    {
        $query = $this->db->select('SUM(administrasi) as pendapatan_arisan');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('regist_arisan', $regist_arisan);
        $query = $this->db->where('status_laporan', 'VERIFIED');
        $query = $this->db->get();
        return $query->row_array();
    }
    function getPendapatanArisanMotorKelompok($regist_arisan)
    {
        $query = $this->db->select('(SUM(administrasi)+SUM(dn_kehilangan)+SUM(fee_dealer)) as pendapatan_arisan');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('regist_arisan', $regist_arisan);
        $query = $this->db->where('status_laporan', 'VERIFIED');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Total Kas Arisan Heboh Bulanan
    function getDataKasArisanHebohBulanKelompok($regist_arisan)
    {
        $query = $this->db->select('SUM(A.bayar) as Kas_bulanan');
        $query = $this->db->from('p_arisan_nota as A');
        $query = $this->db->join('nota as B', 'A.nota_id=B.id');
        $query = $this->db->where('A.regist_arisan', $regist_arisan);
        $query = $this->db->where('MONTH(B.tgl_pembayaran)', date('m'));
        $query = $this->db->where('YEAR(B.tgl_pembayaran)', date('Y'));
        $query = $this->db->where('B.status_nota', 'TERIMA');
        $query = $this->db->or_where('B.status_nota', 'TERIMA_TUNGGAKAN');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Total Kas Arisan Heboh Bulanan
    function getDataKasArisanMotorBulanKelompok($regist_arisan)
    {
        $query = $this->db->select('((SUM(A.bayar)+(C.hg_standar-D.saldo_pemenang)-D.saldo_pemenang)-(D.administrasi+D.dn_kehilangan)) as Kas_bulanan');
        $query = $this->db->from('p_arisan_nota as A');
        $query = $this->db->join('nota as B', 'A.nota_id=B.id');
        $query = $this->db->join('p_arisan as C', 'A.regist_arisan=C.id');
        $query = $this->db->join('lap_arisan as D', 'D.regist_arisan=C.id');
        $query = $this->db->where('A.regist_arisan', $regist_arisan);
        $query = $this->db->where('MONTH(B.tgl_pembayaran)', date('m'));
        $query = $this->db->where('YEAR(B.tgl_pembayaran)', date('Y'));
        $query = $this->db->where('B.status_nota', 'TERIMA');
        $query = $this->db->or_where('B.status_nota', 'TERIMA_TUNGGAKAN');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Total Kas Arisan Heboh Keseluruhan
    function getDataKasArisanHebohSeluruhKelompok($regist_arisan)
    {
        $query = $this->db->select('(SUM(saldo_masuk) - SUM(saldo_pemenang)) as Kas_seluruh');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('regist_arisan', $regist_arisan);
        $query = $this->db->where('status_laporan', 'VERIFIED');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Total Kas Arisan Heboh Keseluruhan
    function getDataKasArisanMotorSeluruhKelompok($regist_arisan)
    {
        $query = $this->db->select('(SUM(saldo_masuk) - (SUM(administrasi)+SUM(dn_kehilangan)) - SUM(saldo_pemenang)) as Kas_seluruh');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('regist_arisan', $regist_arisan);
        $query = $this->db->where('status_laporan', 'VERIFIED');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data laporan Arisan Heboh
    // Menampilkan anggota arisan heboh Menang
    function getSemuaLaporanArisanHebohKelompok($regist_arisan)
    {
        $query = $this->db->select('*, A.id as kd_laporan, B.regist_undian as regist_undian');
        $query = $this->db->from('lap_arisan as A');
        $query = $this->db->join('lap_arisan_menang as B', 'A.id=B.laporan_id');
        $query = $this->db->join('p_arisan_anggota as C', 'B.regist_undian=C.regist_undian');
        $query = $this->db->join('anggota as D', 'C.anggota_id=D.id');
        $query = $this->db->where('A.regist_arisan', $regist_arisan);
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan Laporan Verifikasi
    function getVerifikasiLaporanArisanHebohKelompok($regist_arisan)
    {
        $query = $this->db->select('*, A.id as kd_laporan, B.regist_undian as regist_undian');
        $query = $this->db->from('lap_arisan as A');
        $query = $this->db->join('lap_arisan_menang as B', 'A.id=B.laporan_id');
        $query = $this->db->join('p_arisan_anggota as C', 'B.regist_undian=C.regist_undian');
        $query = $this->db->join('anggota as D', 'C.anggota_id=D.id');
        $query = $this->db->where('A.regist_arisan', $regist_arisan);
        $query = $this->db->where('A.status_laporan', 'MANAGER');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data identitas arisan
    function getDataArisanHebohKelompok($regist_arisan)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_arisan');
        $query = $this->db->where('id', $regist_arisan);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data identitas arisan
    function getDataArisanMotorKelompok($regist_arisan)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_arisan');
        $query = $this->db->where('id', $regist_arisan);
        $query = $this->db->get();
        return $query->row_array();
    }
    function getDataDetailLaporan($kd_laporan)
    {
        $query = $this->db->select('*, B.id as kd_laporan');
        $query = $this->db->from('lap_arisan_menang as A');
        $query = $this->db->join('lap_arisan as B', 'A.laporan_id=B.id');
        $query = $this->db->join('p_arisan_anggota as C', 'A.regist_undian=C.regist_undian');
        $query = $this->db->join('anggota as D', 'C.anggota_id=D.id');
        $query = $this->db->join('sistem_alamat as E', 'D.id_alamat=E.id');
        $query = $this->db->where('A.laporan_id', $kd_laporan);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data identitas anggota dengan NIK
    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 getDataLaporanAnggotaTunggakan($kd_laporan)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('lap_arisan_nunggak as A');
        $query = $this->db->join('lap_arisan as B', 'A.laporan_id=B.id');
        $query = $this->db->join('p_arisan_anggota as C', 'A.regist_undian=C.regist_undian');
        $query = $this->db->join('anggota as D', 'C.anggota_id=D.id');
        $query = $this->db->join('sistem_alamat as E', 'D.id_alamat=E.id');
        $query = $this->db->where('A.laporan_id', $kd_laporan);
        $query = $this->db->where('A.status_tunggakan', 'AKTIF');
        $query = $this->db->get();
        return $query->result();
    }
    function getDataLaporanAnggotaTunggakanBayar($kd_laporan)
    {
        $query = $this->db->select('*, F.id as kd_tagihan');
        $query = $this->db->from('lap_arisan_nunggak as A');
        $query = $this->db->join('lap_arisan as B', 'A.laporan_id=B.id');
        $query = $this->db->join('p_arisan_anggota as C', 'A.regist_undian=C.regist_undian');
        $query = $this->db->join('anggota as D', 'C.anggota_id=D.id');
        $query = $this->db->join('sistem_alamat as E', 'D.id_alamat=E.id');
        $query = $this->db->join('nota as F', 'D.id=F.anggota_id');
        $query = $this->db->where('A.laporan_id', $kd_laporan);
        $query = $this->db->where('A.status_tunggakan', 'LUNAS');
        $query = $this->db->where('F.status_nota', 'PROSES_TUNGGAKAN');
        $query = $this->db->or_where('F.status_nota', 'TERIMA_TUNGGAKAN');
        $query = $this->db->get();
        return $query->result();
    }
    // Mengambil semua data arisan kategori Motor
    function getAllDataArisanMotor()
    {
        $query = $this->db->select('*, A.id as regist_arisan');
        $query = $this->db->from('p_arisan as A');
        $query = $this->db->join('sistem_produk_koperasi as B', 'A.produk_id=B.id');
        $query = $this->db->where('A.produk_id', 22);
        $query = $this->db->where('A.status_arisan !=', 'PROSES');
        $query = $this->db->get();
        return $query->result();
    }
    // 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();
    }
    // 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();
    }
    // Menu Kas
    // Bagian Menu Kas Umum
    // Menampilkan transaksi umum koperasi
    function getDataARusKasArisanBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('*');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', 10);
        $query = $this->db->where('status_kas !=', 'OMSET');
        $query = $this->db->where('status_kas !=', 'OPERASIONAL');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->result();
    }
    // menampilkan data kas masuk umum harian
    function getDataARusKasArisanMasukHarian()
    {
        $query = $this->db->select('sum(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', 10);
        $query = $this->db->where('date(tgl_pembayaran)', date('Y-m-d'));
        $query = $this->db->where('status_kas', 'MASUK');
        $query = $this->db->where('status_nota', 'TERIMA');
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas masuk umum bulanan
    function getDataARusKasArisanMasukBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('sum(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', 10);
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->where('status_kas', 'MASUK');
        $query = $this->db->where('status_nota', 'TERIMA');
        $query = $this->db->get();
        return $query->row_array();
    }
    function filter_getDataARusKasArisanMasukBulanan($bulan, $tahun)
    {
        $query = $this->db->select('sum(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', 10);
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->where('status_kas', 'MASUK');
        $query = $this->db->where('status_nota', 'TERIMA');
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas keluar umum harian
    function getDataARusKasArisanKeluarHarian()
    {
        $query = $this->db->select('sum(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', 10);
        $query = $this->db->where('date(tgl_pembayaran)', date('Y-m-d'));
        $query = $this->db->where('status_kas', 'KELUAR');
        $query = $this->db->where('status_nota', 'TERIMA');
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas keluar umum bulanan
    function getDataARusKasArisanKeluarBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('sum(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', 10);
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->where('status_kas', 'KELUAR');
        $query = $this->db->where('status_nota', 'TERIMA');
        $query = $this->db->get();
        return $query->row_array();
    }
    function filter_getDataARusKasArisanKeluarBulanan($bulan, $tahun)
    {
        $query = $this->db->select('sum(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', 10);
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->where('status_kas', 'KELUAR');
        $query = $this->db->where('status_nota', 'TERIMA');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Bagian Menu Kas Koperasi
    // Menampilkan transaksi pinjaman koperasi ( Storting dan Realisasi)
    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();
    }
    // Menampilkan transaksi pinjaman koperasi ( Storting dan Realisasi)
    function vd_transaksiKoperasiBulananTerima()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('*');
        $query = $this->db->from('nota');
        $query = $this->db->where('substr(produk_id, 1, 2)=', '12');
        $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->result();
    }
    // Menampilkan detail nota koperasi
    function vd_detailTransaksiKoperasiBulanan()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_nota as A');
        $query = $this->db->join('p_koperasi_angsuran as B', 'A.angsuran_id=B.id');
        $query = $this->db->join('p_koperasi_kontrak as C', 'B.kontrak_id=C.id');
        $query = $this->db->join('anggota as D', 'C.anggota_id=D.id');
        $query = $this->db->get();
        return $query->result();
    }
    // 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();
    }
    function filter_vd_TagihanKoperasiBulanan($bulan, $tahun)
    {
        $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 keluar ( realisasi ) bulanan
    function filter_vd_RealisasiKoperasiBulanan($bulan, $tahun)
    {
        $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 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();
    }
    // Bagian Menu Kas Arisan
    // Menampilkan transaksi arisan
    function vd_kasMasukArisanBulananHebohMotor()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('*');
        $query = $this->db->from('kas as A');
        $query = $this->db->join('kas_kategori as B', 'A.kas_id=B.id');
        $query = $this->db->join('sistem_subkategori as C', 'B.sistem_kategori=C.sub_idkategori');
        $query = $this->db->join('sistem_login as D', 'A.login_id=D.id');
        $query = $this->db->where('MONTH(tgl_transaksi)', $bulan);
        $query = $this->db->where('YEAR(tgl_transaksi)', $tahun);
        $query = $this->db->get();
        return $query->result();
    }
    // menampilkan data kas masuk umum harian
    function vd_kasMasukArisanHarianHeboh()
    {
        // SELECT date_format(tgl_transaksi, '%Y-%m-%d') FROM `kas`
        $tanggal_hari = date('Y-m-d');
        $query = $this->db->select('sum(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', 21);
        $query = $this->db->where('date(tgl_pembayaran)', $tanggal_hari);
        $query = $this->db->where('status_kas', 'MASUK');
        $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 masuk umum bulanan
    function vd_kasMasukArisanBulananHeboh()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('sum(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', 21);
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->where('status_kas', 'MASUK');
        $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();
    }
    function filter_vd_kasMasukArisanBulananHeboh($bulan, $tahun)
    {
        $query = $this->db->select('SUM(saldo_masuk) as saldo');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('substr(regist_arisan, 3, 2)=', '21');
        $query = $this->db->where('MONTH(tgl_laporan)', $bulan);
        $query = $this->db->where('YEAR(tgl_laporan)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas keluar umum harian
    function vd_kasMasukArisanHarianMotor()
    {
        $tanggal_hari = date('Y-m-d');
        $query = $this->db->select('sum(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', 22);
        $query = $this->db->where('date(tgl_pembayaran)', $tanggal_hari);
        $query = $this->db->where('status_kas', 'MASUK');
        $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 umum bulanan
    function vd_kasMasukArisanBulananMotor()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('sum(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', 22);
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->where('status_kas', 'MASUK');
        $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();
    }
    function filter_vd_kasMasukArisanBulananMotor($bulan, $tahun)
    {
        $query = $this->db->select('SUM(saldo_masuk) as saldo');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('substr(regist_arisan, 3, 2)=', '22');
        $query = $this->db->where('MONTH(tgl_laporan)', $bulan);
        $query = $this->db->where('YEAR(tgl_laporan)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Bagian Menu Omset atau Pendapatan
    // Menampilkan transaksi arisan

    // menampilkan Omset Koperasi Pembayaran Lancar
    function vd_omsetKoperasiLancar()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('sum(bsr_jasa) as saldo');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('status_angsuran', 'LUNAS_LANCAR');
        $query = $this->db->where('MONTH(tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(tgl_bayar)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    function filter_vd_omsetKoperasiLancar($bulan, $tahun)
    {
        $query = $this->db->select('sum(bsr_jasa) as saldo');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('status_angsuran', 'LUNAS_LANCAR');
        $query = $this->db->where('MONTH(tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(tgl_bayar)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan Omset Koperasi Pembayaran Macet
    function vd_omsetKoperasiMacet()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('sum(bsr_jasa) as saldo');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('status_angsuran', 'LUNAS_MACET');
        $query = $this->db->where('MONTH(tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(tgl_bayar)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    function filter_vd_omsetKoperasiMacet($bulan, $tahun)
    {
        $query = $this->db->select('sum(bsr_jasa) as saldo');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('status_angsuran', 'LUNAS_MACET');
        $query = $this->db->where('MONTH(tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(tgl_bayar)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan Omset Koperasi Pembayaran Macet
    function vd_omsetKoperasiRealisasi()
    {
        $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', 'OMSET');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    function filter_vd_omsetKoperasiRealisasi($bulan, $tahun)
    {
        $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', 'OMSET');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // 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 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();
    }
    // Bagian Menu Laporan
    // Menu laporan arisan heboh
    function getJumlahLaporanArisan()
    {
        $this->db->select('regist_arisan, count(regist_arisan) as ttl_laporan');
        $this->db->from('lap_arisan');
        $this->db->where('status_laporan', 'VERIFIED');
        $this->db->group_by('regist_arisan');
        $query = $this->db->get();
        return $query->result();
    }
    function getJumlahLaporanArisanVerif()
    {
        $this->db->select('regist_arisan, count(regist_arisan) as ttl_laporan');
        $this->db->from('lap_arisan');
        $this->db->where('status_laporan', 'MANAGER');
        $this->db->group_by('regist_arisan');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Bagian Menu Kelola Kas
    // Anggaran Dasar Koperasi
    // Saldo Awal
    function v_saldoAwalKoperasi()
    {
        $query = $this->db->select('ttl_bayar as ad_koperasi');
        $query = $this->db->from('nota');
        $query = $this->db->where('id', '999999999');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Penambahan saldo koperasi
    function v_saldoMasukKoperasi()
    {
        $query = $this->db->select('sum(ttl_bayar) as saldo_masuk');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', '99');
        $query = $this->db->where('status_kas', 'MASUK');
        $query = $this->db->where('id !=', '999999999');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Pengurangan Saldo Koperasi
    function v_saldoKeluarKoperasi()
    {
        $query = $this->db->select('sum(ttl_bayar) as saldo_keluar');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', '99');
        $query = $this->db->where('status_kas', 'KELUAR');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Arus Kas Anggaran Dasar Saldo Koperasi
    function v_transaksiADKoperasi()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', '99');
        $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 total transaksi masuk bulanan
    function vd_saldoMasukFilterKoperasiBulanan($bulan, $tahun)
    {
        $query = $this->db->select('sum(ttl_bayar) as masuk_bulanan');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', '10');
        $query = $this->db->where('status_kas', 'MASUK');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan total transaksi keluar bulanan
    function vd_saldoKeluarFilterKoperasiBulanan($bulan, $tahun)
    {
        $query = $this->db->select('sum(ttl_bayar) as keluar_bulanan');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', '10');
        $query = $this->db->where('status_kas', 'KELUAR');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan arus transaksi bulanan
    function vd_transaksiBulananFilterKoperasi($bulan, $tahun)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('nota');
        $query = $this->db->where('produk_id', '10');
        $query = $this->db->where('status_kas !=', 'OMSET');
        $query = $this->db->where('status_kas !=', 'OPERASIONAL');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan total transaksi masuk bulanan
    function vd_saldoMasukFilterPArisanBulanan($bulan, $tahun)
    {
        $query = $this->db->select('sum(ttl_bayar) as masuk_bulanan');
        $query = $this->db->from('nota');
        $query = $this->db->where('substr(produk_id, 1, 1)=', '2');
        $query = $this->db->where('status_kas', 'MASUK');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan total transaksi keluar bulanan
    function vd_saldoKeluarFilterPArisanBulanan($bulan, $tahun)
    {
        $query = $this->db->select('sum(ttl_bayar) as keluar_bulanan');
        $query = $this->db->from('nota');
        $query = $this->db->where('substr(produk_id, 1, 1)=', '2');
        $query = $this->db->where('status_kas', 'KELUAR');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan arus transaksi bulanan
    function vd_transaksiBulananFilterPArisan($bulan, $tahun)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('nota');
        $query = $this->db->where('substr(produk_id, 1, 1)=', '2');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->where('status_kas !=', 'OMSET');
        $query = $this->db->where('status_kas !=', 'OPERASIONAL');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data jumlah Pokok Pinjaman yang kembali
    function vd_kembaliPokokPinjaman()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(bsr_pokok) as jml_dana');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('MONTH(tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(tgl_bayar)', $tahun);
        $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->row_array();
    }
    // Menampilkan data omset Administrasi dan Resiko Kredit
    function vd_omsetAdminRKPinjaman()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(ttl_bayar) as jml_dana');
        $query = $this->db->from('nota');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->where('status_kas', 'OMSET');
        $query = $this->db->where('substr(produk_id, 1, 2)=', '12');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data jumlah omset jasa Pinjaman
    function vd_omsetJasaPinjaman()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(bsr_jasa) as jml_dana');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('MONTH(tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(tgl_bayar)', $tahun);
        $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->row_array();
    }
    // Menampilkan data jumlah omset jasa Pinjaman
    function vd_simpananAnggotaKoperasiPinjaman()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(bsr_simpanan) as jml_dana');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('MONTH(tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(tgl_bayar)', $tahun);
        $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->row_array();
    }
    // menampilkan data kas masuk ( Storting ) bulanan sesuai filter
    function vd_TagihanKoperasiBulananFilter($bulan, $tahun)
    {
        $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('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 filter
    function vd_RealisasiKoperasiBulananFilter($bulan, $tahun)
    {
        $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 transaksi pinjaman koperasi ( Storting dan Realisasi) filter
    function vd_transaksiKoperasiBulananTerimaFilter($bulan, $tahun)
    {
        $query = $this->db->select('*, id as nota_id');
        $query = $this->db->from('nota');
        $query = $this->db->where('substr(produk_id, 1, 2)=', '12');
        $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->result();
    }
    // Menampilkan data jumlah Pokok Pinjaman yang kembali
    function vd_kembaliPokokPinjamanFilter($bulan, $tahun)
    {
        $query = $this->db->select('SUM(bsr_pokok) as jml_dana');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('MONTH(tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(tgl_bayar)', $tahun);
        $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->row_array();
    }
    // Menampilkan data omset Administrasi dan Resiko Kredit
    function vd_omsetAdminRKPinjamanFilter($bulan, $tahun)
    {
        $query = $this->db->select('SUM(ttl_bayar) as jml_dana');
        $query = $this->db->from('nota');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->where('status_kas', 'OMSET');
        $query = $this->db->where('substr(produk_id, 1, 2)=', '12');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data jumlah omset jasa Pinjaman
    function vd_omsetJasaPinjamanFilter($bulan, $tahun)
    {
        $query = $this->db->select('SUM(bsr_jasa) as jml_dana');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('MONTH(tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(tgl_bayar)', $tahun);
        $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->row_array();
    }
    // Menampilkan data jumlah omset jasa Pinjaman
    function vd_simpananAnggotaKoperasiPinjamanFilter($bulan, $tahun)
    {
        $query = $this->db->select('SUM(bsr_simpanan) as jml_dana');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('MONTH(tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(tgl_bayar)', $tahun);
        $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->row_array();
    }
    // Kas Produk Arisan
    // Arus Kas Operasional atau umum
    function vd_transaksiBulananPArisan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('*');
        $query = $this->db->from('nota');
        $query = $this->db->where('substr(produk_id, 1, 1)=', '2');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->where('status_kas !=', 'OMSET');
        $query = $this->db->where('status_kas !=', 'OPERASIONAL');
        $query = $this->db->get();
        return $query->result();
    }
    // Total transaksi masuk koperasi operasional umum harian
    function vd_saldoMasukPArisanHarian()
    {
        $tgl_ini = date('Y-m-d');
        $query = $this->db->select('sum(ttl_bayar) as masuk_harian');
        $query = $this->db->from('nota');
        $query = $this->db->where('substr(produk_id, 1, 1)=', '2');
        $query = $this->db->where('status_kas', 'MASUK');
        $query = $this->db->where('tgl_pembayaran', $tgl_ini);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Total transaksi keluar koperasi operasional umum harian
    function vd_saldoKeluarPArisanHarian()
    {
        $tgl_ini = date('Y-m-d');
        $query = $this->db->select('sum(ttl_bayar) as keluar_harian');
        $query = $this->db->from('nota');
        $query = $this->db->where('substr(produk_id, 1, 1)=', '2');
        $query = $this->db->where('status_kas', 'KELUAR');
        $query = $this->db->where('tgl_pembayaran', $tgl_ini);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Total transaksi masuk koperasi operasional umum bulanan
    function vd_saldoMasukPArisanBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('sum(ttl_bayar) as masuk_bulanan');
        $query = $this->db->from('nota');
        $query = $this->db->where('substr(produk_id, 1, 1)=', '2');
        $query = $this->db->where('status_kas', 'MASUK');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Total transaksi keluar koperasi operasional umum bulanan
    function vd_saldoKeluarPArisanBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('sum(ttl_bayar) as keluar_bulanan');
        $query = $this->db->from('nota');
        $query = $this->db->where('substr(produk_id, 1, 1)=', '2');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data produk arisan
    function vd_produkArisanAktif()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('sistem_produk_koperasi');
        $query = $this->db->where('substr(id, 1, 1)=', '2');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data arisan heboh aktif
    function vd_produkArisanHebohAktif()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_arisan');
        $query = $this->db->where('produk_id', '21');
        $query = $this->db->where('status_arisan', 'AKTIF');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data arisan motor aktif
    function vd_produkArisanMotorAktif()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_arisan');
        $query = $this->db->where('produk_id', '22');
        $query = $this->db->where('status_arisan', 'AKTIF');
        $query = $this->db->get();
        return $query->result();
    }
    // 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', 'KONFIRMASI');
        $query = $this->db->or_where('A.status_kontrak', 'TERIMA');
        $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();
    }
    // 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();
    }
    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 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 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 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->or_where('A.role_id', '6');
        $query = $this->db->get();
        return $query->result();
    }
    // Storting Per Marketing Harian 
    function vd_MarketingPinjaman($marketing_id)
    {
        $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 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 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 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 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 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 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();
    }
    // Mylu
    // 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();
    }
    // 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();
    }
    // 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();
    }
    // 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();
    }
    // 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();
    }
    // 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();
    }
    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();
    }
    // Bagian Menu Arisan
    // Menampilkan data anggota arisan motor
    function getDataAnggotaArisanMotor($regist_arisan)
    {
        $query = $this->db->select('*, B.id as anggota_id');
        $query = $this->db->from('p_arisan_anggota 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->where('A.regist_arisan', $regist_arisan);
        $query = $this->db->get();
        return $query->result();
    }
    // Bagian identitas anggota
    // Produk koperasi
    // data koperasi aktif  
    function vd_produkKoperasiAktif($id_anggota)
    {
        $query = $this->db->select('*');
        $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.anggota_id', $id_anggota);
        $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 !=', 'LUNAS_LANCAR');
        $query = $this->db->where('A.status_kontrak !=', 'LUNAS_MACET');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_produkKoperasiSelesai($id_anggota)
    {
        $query = $this->db->select('*');
        $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.anggota_id', $id_anggota);
        $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->get();
        return $query->result();
    }
    // Bagian Aktif
    // Jumlah Pinjaman Mingguan Aktif
    function vd_PinjamanAktifMingguan()
    {
        $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 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('A.aturan_id', '1');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_tagihanPinjamanMingguan()
    {
        $query = $this->db->select('*, C.no_hp as nomor_anggota, B.id as nomor_kontrak, 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('anggota as C', 'B.anggota_id=C.id');
        $query = $this->db->join('sistem_login as D', 'B.login_id=D.id');
        $query = $this->db->join('p_koperasi_progres as E', 'E.kontrak_id=B.id');
        $query = $this->db->where('B.aturan_id', '1');
        $query = $this->db->where('A.tgl_tempo', date('Y-m-d'));
        $query = $this->db->get();
        return $query->result();
    }
    function vd_tagihanFilterPinjamanMingguan($tgl_filter)
    {
        $query = $this->db->select('*, C.no_hp as nomor_anggota, B.id as nomor_kontrak, 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('anggota as C', 'B.anggota_id=C.id');
        $query = $this->db->join('sistem_login as D', 'B.login_id=D.id');
        $query = $this->db->join('p_koperasi_progres as E', 'E.kontrak_id=B.id');
        $query = $this->db->where('B.aturan_id', '1');
        $query = $this->db->where('A.tgl_tempo', $tgl_filter);
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman 2 Mingguan Aktif
    function vd_PinjamanAktif2Mingguan()
    {
        $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 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('A.aturan_id', '2');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_tagihanPinjaman2Mingguan()
    {
        $query = $this->db->select('*, C.no_hp as nomor_anggota, B.id as nomor_kontrak, 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('anggota as C', 'B.anggota_id=C.id');
        $query = $this->db->join('sistem_login as D', 'B.login_id=D.id');
        $query = $this->db->join('p_koperasi_progres as E', 'E.kontrak_id=B.id');
        $query = $this->db->where('B.aturan_id', '2');
        $query = $this->db->where('A.tgl_tempo', date('Y-m-d'));
        $query = $this->db->get();
        return $query->result();
    }
    function vd_tagihanFilterPinjaman2Mingguan($tgl_filter)
    {
        $query = $this->db->select('*, C.no_hp as nomor_anggota, B.id as nomor_kontrak, 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('anggota as C', 'B.anggota_id=C.id');
        $query = $this->db->join('sistem_login as D', 'B.login_id=D.id');
        $query = $this->db->join('p_koperasi_progres as E', 'E.kontrak_id=B.id');
        $query = $this->db->where('B.aturan_id', '2');
        $query = $this->db->where('A.tgl_tempo', $tgl_filter);
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman Bulanan Semua Aktif
    function vd_PinjamanAktifBulanan()
    {
        $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 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('A.aturan_id', '3');
        $query = $this->db->or_where('A.aturan_id', '5');
        $query = $this->db->or_where('A.aturan_id', '6');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_tagihanPinjamanBulanan()
    {
        $query = $this->db->select('*, C.no_hp as nomor_anggota, B.id as nomor_kontrak, 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('anggota as C', 'B.anggota_id=C.id');
        $query = $this->db->join('sistem_login as D', 'B.login_id=D.id');
        $query = $this->db->join('p_koperasi_progres as E', 'E.kontrak_id=B.id');
        $query = $this->db->where('B.aturan_id !=', '1');
        $query = $this->db->where('B.aturan_id !=', '2');
        $query = $this->db->where('B.aturan_id !=', '4');
        $query = $this->db->where('A.tgl_tempo', date('Y-m-d'));
        $query = $this->db->get();
        return $query->result();
    }
    function vd_tagihanFilterPinjamanBulanan($tgl_filter)
    {
        $query = $this->db->select('*, C.no_hp as nomor_anggota, B.id as nomor_kontrak, 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('anggota as C', 'B.anggota_id=C.id');
        $query = $this->db->join('sistem_login as D', 'B.login_id=D.id');
        $query = $this->db->join('p_koperasi_progres as E', 'E.kontrak_id=B.id');
        $query = $this->db->where('B.aturan_id !=', '1');
        $query = $this->db->where('B.aturan_id !=', '2');
        $query = $this->db->where('B.aturan_id !=', '4');
        $query = $this->db->where('A.tgl_tempo', $tgl_filter);
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman Bulanan Calon Anggota
    function vd_PinjamanAktifBulananC()
    {
        $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 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('A.aturan_id', '3');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman Bulanan Anggota
    function vd_PinjamanAktifMusiman()
    {
        $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 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('A.aturan_id', '4');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_tagihanPinjamanMusiman()
    {
        $query = $this->db->select('*, C.no_hp as nomor_anggota, B.id as nomor_kontrak, 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('anggota as C', 'B.anggota_id=C.id');
        $query = $this->db->join('sistem_login as D', 'B.login_id=D.id');
        $query = $this->db->join('p_koperasi_progres as E', 'E.kontrak_id=B.id');
        $query = $this->db->where('B.aturan_id', '4');
        $query = $this->db->where('A.tgl_tempo', date('Y-m-d'));
        $query = $this->db->get();
        return $query->result();
    }
    function vd_tagihanFilterPinjamanMusiman($tgl_filter)
    {
        $query = $this->db->select('*, C.no_hp as nomor_anggota, B.id as nomor_kontrak, 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('anggota as C', 'B.anggota_id=C.id');
        $query = $this->db->join('sistem_login as D', 'B.login_id=D.id');
        $query = $this->db->join('p_koperasi_progres as E', 'E.kontrak_id=B.id');
        $query = $this->db->where('B.aturan_id', '4');
        $query = $this->db->where('A.tgl_tempo', $tgl_filter);
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman Bulanan Anggota
    function vd_PinjamanAktifBulananA()
    {
        $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 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('A.aturan_id', '5');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman Bulanan Anggota
    function vd_PinjamanAktifBulananK()
    {
        $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 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('A.aturan_id', '6');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Bagian Macet
    // Jumlah Pinjaman Mingguan Aktif
    function vd_PinjamanMacetBulanan()
    {
        $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 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->where('A.aturan_id', '3');
        $query = $this->db->or_where('A.aturan_id', '5');
        $query = $this->db->or_where('A.aturan_id', '6');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman Mingguan Aktif
    function vd_PinjamanMacetMingguan()
    {
        $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 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->where('A.aturan_id', '1');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman 2 Mingguan Aktif
    function vd_PinjamanMacet2Mingguan()
    {
        $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 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->where('A.aturan_id', '2');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman Bulanan Calon Anggota
    function vd_PinjamanMacetBulananC()
    {
        $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 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->where('A.aturan_id', '3');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman Bulanan Anggota
    function vd_PinjamanMacetMusiman()
    {
        $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 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->where('A.aturan_id', '4');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman Bulanan Anggota
    function vd_PinjamanMacetBulananA()
    {
        $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 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->where('A.aturan_id', '5');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman Bulanan Anggota
    function vd_PinjamanMacetBulananK()
    {
        $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 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->where('A.aturan_id', '6');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Bagian Lunas
    // Jumlah Pinjaman Mingguan Aktif
    function vd_PinjamanLunasBulanan()
    {
        $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 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->where('A.aturan_id', '1');
        $query = $this->db->or_where('A.aturan_id', '5');
        $query = $this->db->or_where('A.aturan_id', '6');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman Mingguan Aktif
    function vd_PinjamanLunasMingguan()
    {
        $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 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->where('A.aturan_id', '1');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman 2 Mingguan Aktif
    function vd_PinjamanLunas2Mingguan()
    {
        $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 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->where('A.aturan_id', '2');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman Bulanan Calon Anggota
    function vd_PinjamanLunasBulananC()
    {
        $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 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->where('A.aturan_id', '3');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman Bulanan Anggota
    function vd_PinjamanLunasMusiman()
    {
        $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 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->where('A.aturan_id', '4');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman Bulanan Anggota
    function vd_PinjamanLunasBulananA()
    {
        $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 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->where('A.aturan_id', '5');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Jumlah Pinjaman Bulanan Anggota
    function vd_PinjamanLunasBulananK()
    {
        $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 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->where('A.aturan_id', '6');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Bagian Laporan
    // Remake Laporan
    function vd_pemenangArisanMotor($laporan_id)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('lap_arisan_menang as A');
        $query = $this->db->join('p_arisan_anggota as B', 'A.regist_undian=B.regist_undian');
        $query = $this->db->join('anggota as C', 'B.anggota_id=C.id');
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id');
        $query = $this->db->where('A.laporan_id', $laporan_id);
        $query = $this->db->get();
        return $query->row_array();
    }
    // 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();
    }
    // Data Marketing
    function vd_marketingAktfNew()
    {
        $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', '7');
        $query = $this->db->where('A.status_akun', 'AKTIF');
        $query = $this->db->get();
        return $query->result();
    }
    // Data KPI Marketing Target
    function vd_marketingKPITarget($faktor_id)
    {
        $query = $this->db->select('*, A.id as faktor_marketing');
        $query = $this->db->from('k_target as A');
        $query = $this->db->join('sistem_login as B', 'A.login_id=B.id');
        $query = $this->db->join('sistem_identitas as C', 'B.id=C.login_id');
        $query = $this->db->join('sistem_alamat as D', 'C.alamat_id=D.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();
    }
    function vd_jmlPersFaktor($komp_id)
    {
        $query = $this->db->select('sum(pers_faktor) as jml_faktor');
        $query = $this->db->from('k_faktor');
        $query = $this->db->where('sts_faktor', 'AKTIF');
        $query = $this->db->where('komp_id', $komp_id);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Data KPI
    // Target KPI
    function vd_tgtMarketingKPI($hasil)
    {
        $query = $this->db->select('*, A.id as faktor_marketing');
        $query = $this->db->from('k_target as A');
        $query = $this->db->join('k_faktor as B', 'A.faktor_id=B.id');
        $query = $this->db->where('A.login_id', $hasil['login_id']);
        $query = $this->db->where('A.sts_target', 'AKTIF');
        $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();
    }
}
