<?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();
    }
    // Menu Beranda kasir
    // 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 lelang
    function getDataSemuaKasLelang()
    {
        $query = $this->db->select('(SUM(saldo_masuk)-SUM(saldo_pemenang)) 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();
    }
    // Mengambil data semua pendapatan kelompok
    function getDataSemuaPendapatanKelompok()
    {
        $query = $this->db->select('(SUM(administrasi)) as pendapatan_kelompok');
        $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 pendapatan kelompok
    function getDataSemuaPendapatanLelang()
    {
        $query = $this->db->select('(SUM(administrasi))+(SUM(dn_kehilangan))+(SUM(fee_dealer)) as pendapatan_lelang');
        $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();
    }
    // menampilkan data kas masuk ( Storting ) harian
    function vd_TagihanKoperasiHarian()
    {
        $query = $this->db->select('SUM(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('substr(produk_id, 1, 2)=', '12');
        $query = $this->db->where('status_kas', 'MASUK');
        $query = $this->db->where('tgl_pembayaran', date('Y-m-d'));
        $query = $this->db->where('status_nota !=', 'PROSES');
        $query = $this->db->where('status_nota !=', 'TOLAK');
        $query = $this->db->where('status_nota !=', 'PROSES_TUNGGAKAN');
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas keluar ( realisasi ) harian
    function vd_RealisasiKoperasiHarian()
    {
        $query = $this->db->select('SUM(A.pokok_pinjaman) as saldo, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('B.tgl_realisasi', date('Y-m-d'));
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas masuk ( Storting ) bulanan
    function vd_TagihanKoperasiBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('substr(produk_id, 1, 2)=', '12');
        $query = $this->db->where('status_kas', 'MASUK');
        $query = $this->db->where('status_nota', 'TERIMA');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->where('status_nota !=', 'PROSES');
        $query = $this->db->where('status_nota !=', 'TOLAK');
        $query = $this->db->where('status_nota !=', 'PROSES_TUNGGAKAN');
        $query = $this->db->get();
        return $query->row_array();
    }
    // menampilkan data kas keluar ( realisasi ) bulanan
    function vd_RealisasiKoperasiBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(A.pokok_pinjaman) as saldo, SUM(A.bsr_admin) as ttl_admin,SUM(A.bsr_rk) as ttl_rk');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'A.id=B.kontrak_id');
        $query = $this->db->where('A.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'PROSES');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    function vd_transaksiKoperasiBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('*, A.id as kd_nota');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'B.nota_id=A.id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->join('anggota as E', 'D.anggota_id=E.id');
        $query = $this->db->join('sistem_alamat as F', 'E.id_alamat=F.id');
        $query = $this->db->where('substr(A.produk_id, 1, 2)=', '12');
        $query = $this->db->where('status_nota !=', 'TERIMA');
        $query = $this->db->where('status_nota !=', 'TOLAK');
        $query = $this->db->where('status_nota !=', 'TERIMA_TUNGGAKAN');
        $query = $this->db->where('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->get();
        return $query->result();
    }
    function vd_verifTransaksiKoperasi()
    {
        $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->join('sistem_login as G', 'G.id=A.petugas');
        $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->get();
        return $query->result();
    }
    // Menampilkan data pinjaman aktif
    // View Data Pengajuan Pinjaman
    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();
    }
    // View Data Pengajuan Pinjaman
    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();
    }
    // 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();
    }
    function vd_kontrakBeranda($data_identitas)
    {
        $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->join('anggota as D', 'B.anggota_id=D.id');
        $query = $this->db->join('sistem_alamat as E', 'D.id_alamat=E.id');
        $query = $this->db->where('A.angs_ke', $data_identitas['angs_ke']);
        $query = $this->db->where('A.kontrak_id', $data_identitas['kontrak_id']);
        $query = $this->db->get();
        return $query->row_array();
    }
    // 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();
    }
    function vd_AngsuranAktif()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('status_angsuran', 'BELUM');
        $query = $this->db->order_by('id', 'ASC');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_AngsuranMacet()
    {
        $query = $this->db->select('kontrak_id, count(*) as jml_macet');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('status_angsuran', 'MACET');
        $query = $this->db->order_by('id', 'ASC');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan angsuran seakrang
    function getDataAngsuranSekarang($kontrak_id)
    {
        $query = $this->db->select('*');
        $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->group_by('kontrak_id', 'ASC');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan angsuran Akhir
    function getDataAngsuranAkhir($kontrak_id)
    {
        $query = $this->db->select('*');
        $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->order_by('id', 'DESC');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan total angsuran
    function getDataTotalAngsuranLunas($kontrak_id)
    {
        $query = $this->db->select('SUM(bsr_bayar) as ttl_lunas');
        $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();
    }
    // Menampilkan tunggakan seakrang
    function getDataTunggakanSekarang($kontrak_id)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('kontrak_id', $kontrak_id);
        $query = $this->db->where('status_angsuran', 'MACET');
        $query = $this->db->order_by('id', 'ASC');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan tunggakan Akhir
    function getDataTunggakanAkhir($kontrak_id)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('kontrak_id', $kontrak_id);
        $query = $this->db->where('status_angsuran', 'MACET');
        $query = $this->db->order_by('id', 'DESC');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan total tunggakan
    function getDataTotalTunggakanLunas($kontrak_id)
    {
        $query = $this->db->select('SUM(bsr_bayar) as ttl_lunas');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('kontrak_id', $kontrak_id);
        $query = $this->db->where('status_angsuran', 'MACET');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data angsuran
    function vd_DataAngsuranKontrak($kontrak_id)
    {
        $query = $this->db->select('*');
        $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->result();
    }
    // Menampilkan data angsuran
    function vd_TotalDataAngsuranKontrak($kontrak_id)
    {
        $query = $this->db->select('SUM(bsr_bayar) as total_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();
    }
    // Menampilkan data tunggakan
    function vd_DataTunggakanKontrak($kontrak_id)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('kontrak_id', $kontrak_id);
        $query = $this->db->where('status_angsuran', 'MACET');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data tunggakan
    function vd_TotalDataTunggakanKontrak($kontrak_id)
    {
        $query = $this->db->select('SUM(bsr_bayar) as total_bayar');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('kontrak_id', $kontrak_id);
        $query = $this->db->where('status_angsuran', 'MACET');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menu Kas
    // Bagian Menu Kas
    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('MONTH(tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(tgl_pembayaran)', $tahun);
        $query = $this->db->order_by('tgl_pembayaran', 'desc');
        $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();
    }
    // Bagian Menu Kas
    function getDataARusKasArisanMasukHarian()
    {
        // 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', 10);
        $query = $this->db->where('date(tgl_pembayaran)', $tanggal_hari);
        $query = $this->db->where('status_kas !=', 'KELUAR');
        $query = $this->db->where('status_kas !=', 'OPERASIONAL');
        $query = $this->db->where('status_nota', 'TERIMA');
        $query = $this->db->get();
        return $query->row_array();
    }
    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 !=', 'KELUAR');
        $query = $this->db->where('status_kas !=', 'OPERASIONAL');
        $query = $this->db->where('status_nota', 'TERIMA');
        $query = $this->db->get();
        return $query->row_array();
    }
    function getDataARusKasArisanKeluarHarian()
    {
        $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', 10);
        $query = $this->db->where('date(tgl_pembayaran)', $tanggal_hari);
        $query = $this->db->where('status_kas !=', 'MASUK');
        $query = $this->db->where('status_kas !=', 'OMSET');
        $query = $this->db->where('status_nota', 'TERIMA');
        $query = $this->db->get();
        return $query->row_array();
    }
    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 !=', 'MASUK');
        $query = $this->db->where('status_kas !=', 'OMSET');
        $query = $this->db->where('status_nota', 'TERIMA');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menu Anggota
    // 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();
    }
    // 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();
    }
    // Bagian Menu Anggota
    // Menu Anggota
    // 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();
    }
    // Data Arisan
    function getDataArisanAktif()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('tbl_arisan');
        $query = $this->db->where('status', 'AKTIF');
        $query = $this->db->get();
        return $query->result();
    }
    function getDataARusKasArisanFilterTanggal($bulan, $tahun)
    {
        $query = $this->db->select('*');
        $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->get();
        return $query->result();
    }
    function getDataARusKasArisanMasukFilterTanggal($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('status_kas !=', 'KELUAR');
        $query = $this->db->where('status_kas !=', 'OPERASIONAL');
        $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->get();
        return $query->row_array();
    }
    function getDataARusKasArisanKeluarFilterTanggal($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('status_kas !=', 'MASUK');
        $query = $this->db->where('status_kas !=', 'OMSET');
        $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->get();
        return $query->row_array();
    }
    // Menu Pembayaran Arisan
    // Menu Arisan Heboh
    // Mengambil Semua daftar verifikasi pembayaran arisan
    function getTagihanArisanVerifikasi()
    {
        $query = $this->db->select('*, count(B.nota_id) as jml_keluarga, A.id as kd_invoice');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_arisan_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_arisan as C', 'B.regist_arisan=C.id');
        $query = $this->db->join('p_arisan_anggota as D', 'B.regist_undian=D.regist_undian');
        $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('A.status_nota', 'PROSES');
        $query = $this->db->group_by('A.id');
        $query = $this->db->get();
        return $query->result();
    }
    // mengambil data pengajuan pembayaran Heoh
    function getTagihanArisanHeboh()
    {
        // , count(B.tagihan_id) as jml_keluarga, A.id as kd_invoice
        $query = $this->db->select('*, count(B.nota_id) as jml_keluarga, A.id as kd_invoice');
        $query = $this->db->from('nota A');
        $query = $this->db->join('p_arisan_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_arisan as C', 'B.regist_arisan=C.id');
        $query = $this->db->join('p_arisan_anggota as D', 'B.regist_undian=D.regist_undian');
        $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('C.produk_id', 21);
        $query = $this->db->where('A.status_nota', 'PROSES');
        $query = $this->db->group_by('A.id');
        $query = $this->db->get();
        return $query->result();
    }
    // mengambil data pengajuan pembayaran Heoh
    function getTagihanArisanHebohBulanan($bulan, $tahun)
    {
        // , count(B.tagihan_id) as jml_keluarga, A.id as kd_invoice
        $query = $this->db->select('*, count(B.nota_id) as jml_keluarga, A.id as kd_invoice');
        $query = $this->db->from('nota A');
        $query = $this->db->join('p_arisan_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_arisan as C', 'B.regist_arisan=C.id');
        $query = $this->db->join('p_arisan_anggota as D', 'B.regist_undian=D.regist_undian');
        $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('MONTH(A.tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(A.tgl_pembayaran)', $tahun);
        $query = $this->db->where('C.produk_id', 21);
        $query = $this->db->where('A.status_nota !=', 'PROSES');
        $query = $this->db->where('A.status_nota !=', 'TOLAK');
        $query = $this->db->where('A.status_nota !=', 'PROSES_TUNGGAKAN');
        $query = $this->db->group_by('A.id');
        $query = $this->db->get();
        return $query->result();
    }
    // mengambil data pengajuan pembayaran Heoh
    function getTagihanArisanMotorBulanan($bulan, $tahun)
    {
        // , count(B.tagihan_id) as jml_keluarga, A.id as kd_invoice
        $query = $this->db->select('*, count(B.nota_id) as jml_keluarga, A.id as kd_invoice');
        $query = $this->db->from('nota A');
        $query = $this->db->join('p_arisan_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_arisan as C', 'B.regist_arisan=C.id');
        $query = $this->db->join('p_arisan_anggota as D', 'B.regist_undian=D.regist_undian');
        $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('MONTH(A.tgl_pembayaran)', $bulan);
        $query = $this->db->where('YEAR(A.tgl_pembayaran)', $tahun);
        $query = $this->db->where('C.produk_id', 22);
        $query = $this->db->where('A.status_nota !=', 'PROSES');
        $query = $this->db->where('A.status_nota !=', 'TOLAK');
        $query = $this->db->where('A.status_nota !=', 'PROSES_TUNGGAKAN');
        $query = $this->db->group_by('A.id');
        $query = $this->db->get();
        return $query->result();
    }
    // mengambil data pengajuan pembayaran Heoh
    function getTagihanArisanSemua()
    {
        $query = $this->db->select('*, count(B.nota_id) as jml_keluarga, A.id as kd_invoice');
        $query = $this->db->from('nota A');
        $query = $this->db->join('p_arisan_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_arisan as C', 'B.regist_arisan=C.id');
        $query = $this->db->join('p_arisan_anggota as D', 'B.regist_undian=D.regist_undian');
        $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('A.tgl_pembayaran', date('Y-m-d'));
        $query = $this->db->where('B.status_bayar', 'LANCAR');
        $query = $this->db->or_where('B.status_bayar', 'TUNGGAKAN');
        $query = $this->db->or_where('B.status_bayar', 'TITIPAN');
        $query = $this->db->group_by('A.id');
        $query = $this->db->get();
        return $query->result();
    }
    // mengambil data pengajuan pembayaran Heoh tunggakan
    function getTagihanArisanHebohTunggakan()
    {
        // , count(B.tagihan_id) as jml_keluarga, A.id as kd_invoice
        $query = $this->db->select('*, count(A.id) as jml_keluarga, A.id as kd_invoice');
        $query = $this->db->from('nota A');
        $query = $this->db->join('p_arisan_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_arisan as C', 'B.regist_arisan=C.id');
        $query = $this->db->join('p_arisan_anggota as D', 'B.regist_undian=D.regist_undian');
        $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('C.produk_id', 21);
        $query = $this->db->where('A.status_nota', 'PROSES_TUNGGAKAN');
        $query = $this->db->group_by('A.id');
        $query = $this->db->get();
        return $query->result();
    }
    // mengambil data pengajuan pembayaran Heoh tunggakan
    function getTagihanArisanMotorTunggakan()
    {
        // , count(B.tagihan_id) as jml_keluarga, A.id as kd_invoice
        $query = $this->db->select('*, count(A.id) as jml_keluarga, A.id as kd_invoice');
        $query = $this->db->from('nota A');
        $query = $this->db->join('p_arisan_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_arisan as C', 'B.regist_arisan=C.id');
        $query = $this->db->join('p_arisan_anggota as D', 'B.regist_undian=D.regist_undian');
        $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('C.produk_id', 22);
        $query = $this->db->where('A.status_nota', 'PROSES_TUNGGAKAN');
        $query = $this->db->group_by('A.id');
        $query = $this->db->get();
        return $query->result();
    }
    function getSemuaVerifikasiArisan()
    {
        $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('sistem_produk_koperasi as B', 'A.produk_id=B.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->join('p_arisan_nota as D', 'A.id=D.nota_id');
        $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('substr(produk_id, 1, 1)=', '2');
        $query = $this->db->order_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // mengambil data pengajuan pembayaran Heoh
    function getTagihanArisanMotor()
    {
        // , count(B.tagihan_id) as jml_keluarga, A.id as kd_invoice
        $query = $this->db->select('*, count(B.nota_id) as jml_keluarga, A.id as kd_invoice');
        $query = $this->db->from('nota A');
        $query = $this->db->join('p_arisan_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_arisan as C', 'B.regist_arisan=C.id');
        $query = $this->db->join('p_arisan_anggota as D', 'B.regist_undian=D.regist_undian');
        $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('C.produk_id', 22);
        $query = $this->db->where('A.status_nota', 'PROSES');
        $query = $this->db->group_by('A.id');
        $query = $this->db->get();
        return $query->result();
    }
    // Mengambil data besaran pengajuan verifikasi Heboh
    function getBesarTagihanArisanHeboh()
    {
        $query = $this->db->select('sum(A.ttl_bayar) as besaran');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_arisan_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_arisan as C', 'B.regist_arisan=C.id');
        $query = $this->db->join('p_arisan_anggota as D', 'B.regist_undian=D.regist_undian');
        $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('C.produk_id', 21);
        $query = $this->db->where('A.status_nota', 'PROSES');
        $query = $this->db->or_where('A.status_nota', 'PROSES_TUNGGAKAN');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Mengambil data besaran pengajuan verifikasi Motor
    function getBesarTagihanArisanMotor()
    {
        $query = $this->db->select('sum(A.ttl_bayar) as besaran');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_arisan_nota as B', 'A.id=B.nota_id');
        $query = $this->db->join('p_arisan as C', 'B.regist_arisan=C.id');
        $query = $this->db->join('p_arisan_anggota as D', 'B.regist_undian=D.regist_undian');
        $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('A.status_nota', 'PROSES');
        $query = $this->db->where('C.produk_id', 22);
        $query = $this->db->or_where('A.status_nota', 'PROSES_TUNGGAKAN');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Mengambil data pendapatan Arisan Heboh Dari Awal
    function getPendapatanArisanHeboh()
    {
        $query = $this->db->select('*, SUM(A.administrasi) as hg_arisanheboh');
        $query = $this->db->from('lap_arisan as A');
        $query = $this->db->join('p_arisan as B', 'A.regist_arisan=B.id');
        $query = $this->db->where('B.produk_id', 21);
        $query = $this->db->where('A.status_laporan', 'VERIFIED');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Mengambil data pendapatan Arisan Motor Dari Awal
    function getPendapatanArisanMotor()
    {
        $query = $this->db->select('*, SUM(A.administrasi) as ttl_fee_admin, SUM(A.dn_kehilangan) as ttl_dn_kehilangan, SUM(A.fee_dealer) as ttl_fee_dealer');
        $query = $this->db->from('lap_arisan as A');
        $query = $this->db->join('p_arisan as B', 'A.regist_arisan=B.id');
        $query = $this->db->where('B.produk_id', 22);
        $query = $this->db->where('A.status_laporan', 'VERIFIED');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Mengambil data Invoice, Detail Invoice, Bayar Invoice, Keluarga Invoice
    function getDataInvoice($kd_invoice)
    {
        $query = $this->db->select('*, A.id as kd_invoice');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('anggota as B', 'A.anggota_id=B.id');
        $query = $this->db->join('sistem_alamat as C', 'B.id_alamat=C.id');
        $query = $this->db->where('A.id', $kd_invoice);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Data Invoice Rincian
    function getDataInvoiceRinci($kd_invoice)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_arisan_nota as B', 'B.nota_id=A.id');
        $query = $this->db->join('p_arisan_jadwal as C', 'B.jadwal_id=C.id');
        $query = $this->db->join('p_arisan as D', 'B.regist_arisan=D.id');
        $query = $this->db->join('p_arisan_anggota as E', 'B.regist_undian=E.regist_undian');
        $query = $this->db->where('A.id', $kd_invoice);
        $query = $this->db->get();
        return $query->result();
    }
    function getDataInvoiceRinciAngsuran($kd_invoice)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('p_koperasi_nota as B', 'B.nota_id=A.id');
        $query = $this->db->join('p_koperasi_angsuran as C', 'B.angsuran_id=C.id');
        $query = $this->db->join('p_koperasi_kontrak as D', 'C.kontrak_id=D.id');
        $query = $this->db->join('p_koperasi_aturan as E', 'D.aturan_id=E.id');
        $query = $this->db->join('anggota as F', 'D.anggota_id=F.id');
        $query = $this->db->where('A.id', $kd_invoice);
        $query = $this->db->get();
        return $query->result();
    }
    // Data Identitas Marketing
    function getDataMarketing($kd_invoice)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('sistem_login as B', 'A.petugas=B.id');
        $query = $this->db->where('A.id', $kd_invoice);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Data Identitas Kasir
    function getDataKasir($kd_invoice)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('nota as A');
        $query = $this->db->join('sistem_login as B', 'A.kasir=B.id');
        $query = $this->db->where('A.id', $kd_invoice);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Total Kas Arisan Heboh Bulanan
    function getDataKasArisanHebohBulan()
    {
        $query = $this->db->select('SUM(ttl_bayar) as kas_arisanheboh_bulan');
        $query = $this->db->from('nota');
        $query = $this->db->where('SUBSTRING(id, 7, 2)=', '21');
        $query = $this->db->where('status_nota', 'TERIMA');
        $query = $this->db->where('MONTH(tgl_pembayaran)', date('m'));
        $query = $this->db->where('YEAR(tgl_pembayaran)', date('Y'));
        $query = $this->db->get();
        return $query->row_array();
    }
    // Total Kas Arisan Heboh Bulanan
    function getDataKasArisanHebohBulanPemenang()
    {
        $query = $this->db->select('SUM(saldo_pemenang) as dana_pemenang');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('SUBSTRING(id, 5, 2)=', '21');
        $query = $this->db->where('MONTH(tgl_laporan)', date('m'));
        $query = $this->db->where('YEAR(tgl_laporan)', date('Y'));
        $query = $this->db->get();
        return $query->row_array();
    }
    // Total Kas Arisan Heboh Bulanan
    function getDataKasArisanHebohSeluruhPemenang()
    {
        $query = $this->db->select('SUM(saldo_pemenang) as dana_pemenang');
        $query = $this->db->from('lap_arisan');
        $query = $this->db->where('SUBSTRING(id, 5, 2)=', '21');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Total Kas Arisan Motor Bulanan
    function getDataKasArisanMotorBulan()
    {
        $query = $this->db->select('SUM(ttl_bayar) as kas_arisanmotor_bulan');
        $query = $this->db->from('nota');
        $query = $this->db->where('SUBSTRING(id, 7, 2)=', '22');
        $query = $this->db->where('status_nota', 'TERIMA');
        $query = $this->db->where('MONTH(tgl_pembayaran)', date('m'));
        $query = $this->db->where('YEAR(tgl_pembayaran)', date('Y'));
        $query = $this->db->get();
        return $query->row_array();
    }
    // Total Kas Arisan Heboh Keseluruhan
    function getDataKasArisanHebohSeluruh()
    {
        $query = $this->db->select('SUM(ttl_bayar) as kas_arisanheboh_seluruh');
        $query = $this->db->from('nota');
        $query = $this->db->where('SUBSTRING(id, 7, 2)=', '21');
        $query = $this->db->where('status_nota', 'LUNAS');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Total Kas Arisan Heboh Keseluruhan
    function getDataKasArisanMotorSeluruh()
    {
        $query = $this->db->select('SUM(ttl_bayar) as kas_arisanmotor_seluruh');
        $query = $this->db->from('nota');
        $query = $this->db->where('SUBSTRING(id, 7, 2)=', '22');
        $query = $this->db->where('status_nota', 'LUNAS');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Data Arisan Heboh Aktif
    function getDataArisanModelAktif()
    {
        $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 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();
    }
    // Data Arisan Heboh Aktif
    function getDataArisanModelBelum()
    {
        $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 getDataArisanMotorAktif()
    {
        $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();
    }
    // Data Arisan Heboh Aktif
    function getDataArisanMotorBelum()
    {
        $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();
    }
    // Cek data anggota terdaftar dalam kelompok arisan atau tidak berdasarkan nomor HP
    function getDataAnggotaNohp($regist_undian, $id_arisan)
    {
        $query = $this->db->select('*, A.id as kd_anggota');
        $query = $this->db->from('tbl_anggota as A');
        $query = $this->db->join('tbl_arisan_anggota as B', 'A.id=B.id_anggota');
        $query = $this->db->where('A.no_hp', $regist_undian);
        $query = $this->db->where('B.id_arisan', $id_arisan);
        $query = $this->db->get();
        return $query->row_array();
    }
    function getDataAnggotaNik($regist_undian, $id_arisan)
    {
        $query = $this->db->select('*, A.id as kd_anggota');
        $query = $this->db->from('tbl_anggota as A');
        $query = $this->db->join('tbl_arisan_anggota as B', 'A.id=B.id_anggota');
        $query = $this->db->where('A.nik', $regist_undian);
        $query = $this->db->where('B.id_arisan', $id_arisan);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan detail ragihan
    function setDataAnggota($id_anggota, $id_arisan)
    {
        $query = $this->db->select('*, A.no_regist as regist_undian');
        $query = $this->db->from('tbl_arisan_anggota as A');
        $query = $this->db->where('A.id_arisan', $id_arisan);
        $query = $this->db->where('A.id_anggota', $id_anggota);
        $query = $this->db->where('A.status', 'AKTIF');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan detail ragihan
    function gsetDataAnggota($id_anggota, $arisan_id)
    {
        $query = $this->db->select('*, A.regist_undian as regist_undian');
        $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->where('A.regist_arisan', $arisan_id);
        $query = $this->db->where('A.anggota_id', $id_anggota);
        $query = $this->db->where('A.status', 'AKTIF');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data tunggakan anggota
    function getDataTunggakanSebelumnya($id_anggota, $arisan_id)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('lap_arisan_nunggak as A');
        $query = $this->db->from('p_arisan_anggota as B', 'A.regist_undian=B.regist_undian');
        $query = $this->db->where('A.regist_arisan', $arisan_id);
        $query = $this->db->where('A.status_tunggakan', 'AKTIF');
        $query = $this->db->where('B.anggota_id', $id_anggota);
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan nomor urut invoice paling besar 
    function getDataTagihanUrutHeboh()
    {
        $date = date('Y-m-d');
        $query = $this->db->select('*, id as kd_invoice');
        $query = $this->db->from('nota');
        $query = $this->db->where('tgl_pembayaran', $date);
        $query = $this->db->where('produk_id', '21');
        $query = $this->db->order_by('id', 'DESC');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan nomor urut invoice paling besar
    function getDataTagihanUrutMotor()
    {
        $date = date('Y-m-d');
        $query = $this->db->select('*, id as kd_invoice');
        $query = $this->db->from('nota');
        $query = $this->db->where('tgl_pembayaran', $date);
        $query = $this->db->where('produk_id', '22');
        $query = $this->db->order_by('id', 'DESC');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data apakah anggota sudah bayar atau belum bulan ini
    function getDataTagihanAnggota($jadwal_id, $arisan_id, $id_anggota)
    {
        $query = $this->db->select('*');
        $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.jadwal_id', $jadwal_id);
        $query = $this->db->where('A.regist_arisan', $arisan_id);
        $query = $this->db->where('B.anggota_id', $id_anggota);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data identitas anggota dengan Nomor Undian
    function getDataAnggotaNoUndian($inputan, $regist_arisan)
    {
        $query = $this->db->select('*, A.id as id_anggota');
        $query = $this->db->from('anggota as A');
        $query = $this->db->join('p_arisan_anggota as C', 'A.id=C.anggota_id');
        $query = $this->db->join('sistem_alamat as B', 'A.id_alamat=B.id');
        $query = $this->db->where('C.no_urut', $inputan);
        $query = $this->db->where('C.regist_arisan', $regist_arisan);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data identitas anggota dengan Nomor Undian
    function getDataAnggotaRegistUndian($inputan)
    {
        $query = $this->db->select('*, A.id as id_anggota');
        $query = $this->db->from('anggota as A');
        $query = $this->db->join('p_arisan_anggota as C', 'A.id=C.anggota_id');
        $query = $this->db->join('sistem_alamat as B', 'A.id_alamat=B.id');
        $query = $this->db->where('C.regist_undian', $inputan);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data identitas anggota dengan Nomor HP
    function getDataAnggotaNomorHP($inputan)
    {
        $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.no_hp', $inputan);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data identitas anggota dengan NIK
    function getDataAnggotaNik2($inputan)
    {
        $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', $inputan);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data arisan sesuai nomor ID anggota dan nomor arisan
    function getDataArisanAnggota($id_anggota, $regist_arisan)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_arisan_anggota as A');
        $query = $this->db->where('A.regist_arisan', $regist_arisan);
        $query = $this->db->where('A.anggota_id', $id_anggota);
        $query = $this->db->where('A.status', 'AKTIF');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data identitas arisan
    function getDataArisanIdentitas($regist_arisan)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_arisan as A');
        $query = $this->db->where('A.id', $regist_arisan);
        $query = $this->db->where('A.status_arisan', 'AKTIF');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan data tunggakan arisan sesuai nomor ID dan registrasi arisan
    function getDataArisanAnggotaTunggakan($id_anggota, $regist_arisan)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_arisan_anggota as A');
        $query = $this->db->join('lap_arisan_nunggak as B', 'A.regist_undian=B.regist_undian');
        $query = $this->db->where('A.regist_arisan', $regist_arisan);
        $query = $this->db->where('A.anggota_id', $id_anggota);
        $query = $this->db->where('A.status', 'AKTIF');
        $query = $this->db->where('B.status_tunggakan', 'AKTIF');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_anggotaArisanHeboh()
    {
        $query = $this->db->select('*');
        $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('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.status', 'AKTIF');
        $query = $this->db->where('B.status_arisan', 'AKTIF');
        $query = $this->db->where('B.produk_id', '21');
        $query = $this->db->group_by('A.anggota_id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_detailanggotaArisanHeboh()
    {
        $query = $this->db->select('*');
        $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('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.status', 'AKTIF');
        $query = $this->db->where('B.status_arisan', 'AKTIF');
        $query = $this->db->where('B.produk_id', '21');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_anggotaArisanMotor()
    {
        $query = $this->db->select('*');
        $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('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.status !=', 'MUNDUR');
        $query = $this->db->where('B.status_arisan', 'AKTIF');
        $query = $this->db->where('B.produk_id', '22');
        $query = $this->db->group_by('A.anggota_id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_detailanggotaArisanMotor()
    {
        $query = $this->db->select('*');
        $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('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.status !=', 'MUNDUR');
        $query = $this->db->where('B.status_arisan', 'AKTIF');
        $query = $this->db->where('B.produk_id', '22');
        $query = $this->db->get();
        return $query->result();
    }
    // Bagian Produk Pinjaman
    // Menu Realisasi Pinjaman
    function vd_RiwayatPengajuanPinjaman()
    {
        $query = $this->db->select('*, A.id as nomor_kontrak');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id');
        $query = $this->db->join('anggota_keluarga as E', 'A.anggota_id=E.anggota_id');
        $query = $this->db->join('p_koperasi_aturan as F', 'A.aturan_id=F.id');
        $query = $this->db->join('sistem_login as G', 'A.login_id=G.id');
        $query = $this->db->where('A.status_kontrak', 'TERIMA');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Menu Realisasi Pinjaman
    function vd_verifPengajuanPinjaman()
    {
        $query = $this->db
            ->select('*, A.id as nomor_kontrak')
            ->from('p_koperasi_kontrak as A')
            ->join('p_koperasi_progres as B', 'B.kontrak_id=A.id')
            ->join('anggota as C', 'A.anggota_id=C.id')
            ->join('sistem_alamat as D', 'C.id_alamat=D.id')
            ->join('anggota_keluarga_detail as E', 'A.anggota_id=E.anggota_id')
            ->join('p_koperasi_aturan as F', 'A.aturan_id=F.id')
            ->join('sistem_login as G', 'A.login_id=G.id')
            ->where('A.status_kontrak', 'TERIMA')
            // Menambahkan pengurutan berdasarkan B.tgl_konfirmasi (dari terbaru ke terlama)
            ->order_by('B.tgl_konfirmasi', 'DESC')
            // group_by('A.id') harusnya berada di sini (jika memang diperlukan)
            ->group_by('A.id')
            ->get();

        return $query->result();
    }
    function vd_RiwayatTransaksiPengajuanPinjaman()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('*, A.id as nomor_kontrak');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id');
        $query = $this->db->join('anggota_keluarga as E', 'A.anggota_id=E.anggota_id');
        $query = $this->db->join('p_koperasi_aturan as F', 'A.aturan_id=F.id');
        $query = $this->db->join('sistem_login as G', 'A.login_id=G.id');
        $query = $this->db->where('A.status_kontrak', 'AKTIF');
        $query = $this->db->where('MONTH(B.tgl_realisasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_realisasi)', $tahun);
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan semuda identitas kontrak pinjaman
    function getDataIdentitasKontrak($kontrak_id)
    {
        $query = $this->db->select('*, A.id as nomor_kontrak');
        $query = $this->db->from('p_koperasi_kontrak as A');
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id');
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id');
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id');
        $query = $this->db->join('anggota_keluarga as E', 'A.anggota_id=E.anggota_id');
        $query = $this->db->join('p_koperasi_aturan as F', 'A.aturan_id=F.id');
        $query = $this->db->join('sistem_login as G', 'A.login_id=G.id');
        $query = $this->db->where('A.id', $kontrak_id);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan jumlah uang verifikasi realisasi bulanan
    function vd_jmlVerifRealisasiBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(A.pokok_pinjaman) as ttl_pengajuan');
        $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', 'TERIMA');
        $query = $this->db->where('MONTH(B.tgl_konfirmasi)', $bulan);
        $query = $this->db->where('YEAR(B.tgl_konfirmasi)', $tahun);
        $query = $this->db->get();
        return $query->row_array();
    }
    // Menampilkan jumlah pencairan bulan
    function vd_jmlRealisasiBulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(A.pokok_pinjaman) as ttl_pencairan, 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();
    }
    // Bagian Anggota Koperasi
    // 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();
    }
    // Menampilkan total permintaan verifikasi storting Bulanan
    function vd_stortingbulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('count(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('status_nota', 'TERIMA');
        $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->get();
        return $query->row_array();
    }
    // Menampilkan total permintaan verifikasi storting Bulanan
    function vd_stortingharian()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('count(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('status_nota', 'PROSES');
        $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->get();
        return $query->row_array();
    }
    // Menampilkan total permintaan verifikasi storting Bulanan
    function v_stortingbulanan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('SUM(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('status_nota', 'DITERIMA');
        $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->get();
        return $query->row_array();
    }
    // Menampilkan total permintaan verifikasi storting Bulanan
    function v_stortingharian()
    {
        $query = $this->db->select('SUM(ttl_bayar) as saldo');
        $query = $this->db->from('nota');
        $query = $this->db->where('status_nota', 'DITERIMA');
        $query = $this->db->where('substr(produk_id, 1, 2)=', '12');
        $query = $this->db->where('tgl_pembayaran', date('Y-m-d'));
        $query = $this->db->get();
        return $query->row_array();
    }
    function vd_verifDataTagihan()
    {
        $query = $this->db->select('*, A.id as angsuran_id');
        $query = $this->db->from('p_koperasi_angsuran as A');
        $query = $this->db->join('p_koperasi_kontrak as B', 'A.kontrak_id=B.id');
        $query = $this->db->join('p_koperasi_aturan as C', 'B.aturan_id=C.id');
        $query = $this->db->join('anggota as D', 'B.anggota_id=D.id');
        $query = $this->db->join('sistem_alamat as E', 'D.id_alamat=E.id');
        $query = $this->db->where('A.status_angsuran', 'PROSES');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_transaksiDataTagihan()
    {
        $query = $this->db->select('*, A.id as angsuran_id');
        $query = $this->db->from('p_koperasi_angsuran as A');
        $query = $this->db->join('p_koperasi_kontrak as B', 'A.kontrak_id=B.id');
        $query = $this->db->join('p_koperasi_aturan as C', 'B.aturan_id=C.id');
        $query = $this->db->join('anggota as D', 'B.anggota_id=D.id');
        $query = $this->db->join('sistem_alamat as E', 'D.id_alamat=E.id');
        $query = $this->db->where('A.status_angsuran !=', 'PROSES');
        $query = $this->db->where('A.status_angsuran !=', 'BELUM');
        $query = $this->db->where('A.status_angsuran !=', 'MACET');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_historiTransaksiDataTagihan()
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('*, A.id as angsuran_id');
        $query = $this->db->from('p_koperasi_angsuran as A');
        $query = $this->db->join('p_koperasi_kontrak as B', 'A.kontrak_id=B.id');
        $query = $this->db->join('p_koperasi_aturan as C', 'B.aturan_id=C.id');
        $query = $this->db->join('anggota as D', 'B.anggota_id=D.id');
        $query = $this->db->join('sistem_alamat as E', 'D.id_alamat=E.id');
        $query = $this->db->where('A.status_angsuran !=', 'PROSES');
        $query = $this->db->where('A.status_angsuran !=', 'BELUM');
        $query = $this->db->where('A.status_angsuran !=', 'MACET');
        $query = $this->db->where('MONTH(A.tgl_bayar)', $bulan);
        $query = $this->db->where('YEAR(A.tgl_bayar)', $tahun);
        $query = $this->db->get();
        return $query->result();
    }
    function get_vdAngsuranBayar($data_kontrak)
    {
        // $this->db->get_where('p_koperasi_angsuran', ['kontrak_id' => $data_kontrak['id'], 'status_angsuran !=' => 'BELUM', 'status_angsuran !=' => 'MACET', 'status_angsuran !=' => 'PROSES'])->result()
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('kontrak_id', $data_kontrak['id']);
        $query = $this->db->where('status_angsuran !=', 'BELUM');
        $query = $this->db->where('status_angsuran !=', 'MACET');
        $query = $this->db->where('status_angsuran !=', 'PROSES');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data jaminan pinjaman
    function vd_jaminanPinjaman()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_agungan');
        $query = $this->db->get();
        return $query->result();
    }
    // Macet
    function vd_AngsuranMacetS($data_kontrak)
    {
        // $this->db->get_where('p_koperasi_angsuran', ['kontrak_id' => $data_kontrak['id'], 'status_angsuran' => 'LUNAS_MACET'])->result()
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('kontrak_id', $data_kontrak['id']);
        $query = $this->db->where('status_angsuran !=', 'LUNAS_MACET');
        $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();
    }
    // 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();
    }
    // 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();
    }
    // 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_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_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 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 Pengajuan Pinjaman
    // Menampilkan data jenis pinjaman yang untuk marketing
    function vd_jenisPinjamanAktif()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_aturan as A');
        $query = $this->db->join('sistem_produk_koperasi as B', 'A.produk_id=B.id');
        $query = $this->db->where('produk_id !=', '126');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan semua data arisan aktif
    function getDataAllArisanAktif()
    {
        $query = $this->db->select('*, C.id as jadwal_id');
        $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->join('p_arisan_jadwal as C', 'C.regist_arisan=A.id');
        $query = $this->db->where('A.status_arisan', 'AKTIF');
        $query = $this->db->where('C.status_undian !=', 'SELESAI');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data anggota aktif arisan
    function getDataAnggotaAktif()
    {
        $query = $this->db->select('regist_arisan, count(A.regist_arisan) as anggota_aktif');
        $query = $this->db->from('p_arisan_anggota as A');
        $query = $this->db->where('A.status', 'AKTIF');
        $query = $this->db->group_by('A.regist_arisan');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data anggota menang arisan
    function getDataAnggotaMenang()
    {
        $query = $this->db->select('regist_arisan, count(A.regist_arisan) as anggota_menang');
        $query = $this->db->from('p_arisan_anggota as A');
        $query = $this->db->where('A.status', 'MENANG');
        $query = $this->db->group_by('A.regist_arisan');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan data anggota menang arisan
    function getDataAnggotaMundur()
    {
        $query = $this->db->select('regist_arisan, count(A.regist_arisan) as anggota_mundur');
        $query = $this->db->from('p_arisan_anggota as A');
        $query = $this->db->where('A.status', 'MUNDUR');
        $query = $this->db->group_by('A.regist_arisan');
        $query = $this->db->get();
        return $query->result();
    }
    function getDataAnggotaArisanMotorAktifTerus($kode_arisan)
    {
        $query = $this->db->select('*');
        $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('regist_arisan', $kode_arisan);
        $query = $this->db->where('status !=', 'MUNDUR');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan Data Tagihan Anggota Yang Belum Bayar Bulan ini
    function getDataAnggotaTagihanMotor($jadwal_id, $kode_arisan)
    {
        $query = $this->db->query("Select * from p_arisan_anggota as A 
            Join anggota as B ON A.anggota_id = B.id 
            Join sistem_alamat as C ON B.id_alamat = C.id 
            Where A.regist_arisan=" . $kode_arisan . " 
            and A.status != 'MUNDUR' 
            and NOT EXISTS (Select * from p_arisan_nota as D 
            where jadwal_id=" . $jadwal_id . " 
            and D.regist_undian=A.regist_undian)");
        return $query->result();
    }
    function getDataAnggotaTagihanMotorSelesai($jadwal_id, $kode_arisan)
    {
        $query = $this->db->query("Select *, D.id as kd_nota from 
        p_arisan_anggota as A 
        Join anggota as B ON A.anggota_id = B.id 
        Join sistem_alamat as C ON B.id_alamat = C.id 
        Join p_arisan_nota as Z ON A.regist_undian = Z.regist_undian 
        join nota as D ON Z.nota_id=D.id
        Where A.regist_arisan=" . $kode_arisan . " and A.status != 'MUNDUR' and EXISTS (Select * from p_arisan_nota as D where jadwal_id=" . $jadwal_id . " and D.regist_undian=A.regist_undian)
        group by A.regist_undian");
        return $query->result();
    }
    // Menampilkan anggota arisan heboh Aktif
    function getDataAnggotaArisanHebohAktif($kode_arisan)
    {
        $query = $this->db->select('*');
        $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('regist_arisan', $kode_arisan);
        $query = $this->db->where('status', 'AKTIF');
        $query = $this->db->get();
        return $query->result();
    }
    // Menampilkan Data Tagihan Anggota Yang Belum Bayar Bulan ini
    function getDataAnggotaTagihan($jadwal_id, $kode_arisan)
    {
        $query = $this->db->query("Select * from p_arisan_anggota as A 
            Join anggota as B ON A.anggota_id = B.id 
            Join sistem_alamat as C ON B.id_alamat = C.id 
            Where A.regist_arisan=" . $kode_arisan . " 
            and A.status= 'AKTIF' 
            and NOT EXISTS (Select * from p_arisan_nota as D 
            where jadwal_id=" . $jadwal_id . " 
            and D.regist_undian=A.regist_undian)");
        return $query->result();
    }
    // Menampilkan Data Anggota Sudah Bayar Bulan Ini / Sesuai Kode Jadwal
    function getDataAnggotaTagihanSelesai($jadwal_id, $kode_arisan)
    {
        $query = $this->db->query("Select *, D.id as kd_nota from 
            p_arisan_anggota as A 
            Join anggota as B ON A.anggota_id = B.id 
            Join sistem_alamat as C ON B.id_alamat = C.id 
            Join p_arisan_nota as Z ON A.regist_undian = Z.regist_undian 
            join nota as D ON Z.nota_id=D.id
            Where A.regist_arisan=" . $kode_arisan . " and A.status= 'AKTIF' and EXISTS (Select * from p_arisan_nota as D where jadwal_id=" . $jadwal_id . " and D.regist_undian=A.regist_undian)
            group by A.regist_undian");
        return $query->result();
    }
    function vd_jenisPinjamanKabag()
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_aturan as A');
        $query = $this->db->join('sistem_produk_koperasi as B', 'A.produk_id=B.id');
        $query = $this->db->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'); // ADA
        $query = $this->db->join('p_koperasi_progres as B', 'B.kontrak_id=A.id'); // Ada
        $query = $this->db->join('anggota as C', 'A.anggota_id=C.id'); // Ada
        $query = $this->db->join('sistem_alamat as D', 'C.id_alamat=D.id'); // Ada
        $query = $this->db->join('p_koperasi_aturan as F', 'A.aturan_id=F.id');
        $query = $this->db->where('A.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('A.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('A.status_kontrak !=', 'AKTIF');
        $query = $this->db->where('A.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('A.status_kontrak !=', 'LUNAS_LANCAR');
        $query = $this->db->where('A.status_kontrak !=', 'MACET');
        $query = $this->db->where('A.status_kontrak !=', 'LUNAS_MACET');
        $query = $this->db->group_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    function vd_logsWA($tgl)
    {
        $query = $this->db->select('*, A.no_hp as hp_nasabah, A.id as logs_id');
        $query = $this->db->from('logs_wa 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->where('A.tgl_kirim', $tgl);
        $query = $this->db->order_by('A.id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
}
