<?php
namespace App\Models\interest;

use CodeIgniter\Model;

class RatesModel extends Model
{

  public function getLists()
  {

    $builder = $this->db->table("tb_lender AS a");

    $builder->select("a.seq
                              , IFNULL(CASE 
                                WHEN a.bank_type = 'B' THEN (SELECT cd_nm FROM codes WHERE cd = a.bank AND category = 'BANK')
                                WHEN a.bank_type =  'I' THEN (SELECT cd_nm FROM codes WHERE cd = a.bank AND category = 'INSURANCE') END, a.bank_nm) AS bank
                              , a.bank_type
                              , a.product
                              , a.tel
                              , a.min_rate
                              , a.avg_rate
                              , a.max_rate
                              , a.chg_yn
                              , a.split_yn
                              , b.extra_fee
                              , b.late_rate
                              , b.join_method
                              , b.prepay_fee
                              , b.loan_limit
                              , IFNULL(DATE_FORMAT(b.prov_date, '%Y-%m-%d'), '') AS prov_date");

    $builder->join("tb_lender_dtl AS b", "b.seq = a.seq", "LEFT");


    $builder->where("a.use_yn", "Y");


    //  $builder->orderBy('a.seq', 'DESC');

    return $builder->get()->getResultArray();
  }

}