<?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_ReviewCustomers($id = null)
    {
        if ($id === null) {
            $query = $this->db->select('*');
            $query = $this->db->from('k_rkonsumen as A');
            $query = $this->db->join('sistem_login as B', 'A.login_id=B.id');
            $query = $this->db->get();
            return $query->result();
        } else {
            $query = $this->db->select('*');
            $query = $this->db->from('k_rkonsumen as A');
            $query = $this->db->join('sistem_login as B', 'A.login_id=B.id');
            $query = $this->db->where('B.id', $id);
            $query = $this->db->get();
            return $query->result();
        }
    }

    function vd_KontrakPinjaman($kd_kontrak)
    {
        $query = $this->db->select('*');
        $query = $this->db->from('p_koperasi_kontrak');
        $query = $this->db->where('id', $kd_kontrak);
        $query = $this->db->get();
        return $query->row_array();
    }
    function vd_Anggota($id)
    {
        $query = $this->db->select('*, C.id as kontrak_id');
        $query = $this->db->from('anggota as A');
        $query = $this->db->join('sistem_alamat as B', 'A.id_alamat=B.id');
        $query = $this->db->join('p_koperasi_kontrak as C', 'A.id=C.anggota_id');
        $query = $this->db->where('C.id', $id);
        $query = $this->db->where('C.status_kontrak !=', 'KONFIRMASI');
        $query = $this->db->where('C.status_kontrak !=', 'TERIMA');
        $query = $this->db->where('C.status_kontrak !=', 'TOLAK');
        $query = $this->db->where('C.status_kontrak !=', 'REALISASI');
        $query = $this->db->where('C.status_kontrak !=', 'PROSES');
        $query = $this->db->where('C.status_kontrak !=', 'KASIR');
        $query = $this->db->where('C.status_kontrak !=', 'SURVEY');
        $query = $this->db->get();
        return $query->row_array();
    }
    function vd_TotalReview($hp_konsumen)
    {
        $bulan = date('m');
        $tahun = date('Y');
        $query = $this->db->select('*');
        $query = $this->db->from('k_rkonsumen');
        $query = $this->db->where('hp_konsumen', $hp_konsumen);
        $query = $this->db->where('MONTH(tgl_review)', $bulan);
        $query = $this->db->where('YEAR(tgl_review)', $tahun);
        $query = $this->db->get();
        return $query->result();
    }
        function vd_Angsuran($kd_kontrak)
    {
        $query = $this->db->select('angs_ke, tgl_tempo, tgl_bayar, bsr_bayar, status_angsuran');
        $query = $this->db->from('p_koperasi_angsuran');
        $query = $this->db->where('kontrak_id', $kd_kontrak);
        $query = $this->db->get();
        return $query->result();
    }
}