sparqapi/api/application/models/SMC_Credit_PD_Model.php
2021-11-09 18:48:11 +05:30

156 lines
11 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . '/libraries/SPARQ_Model.php';
class SMC_Credit_PD_Model extends SPARQ_Model {
public function __construct() {
parent::__construct();
}
public function getSalesPDListwithFilters($pd_status = '',$pd_from_date = '',$pd_to_date = '',$pd_products = '',$pd_lender = '',$pd_applicant_name = '',$pd_officer_name = '',$sales_pd_officer_id) {
// SALES_PD_DATA.sales_pd_sno, SALES_PD_DATA.sales_pd_id, SALES_PD_DATA.applicant_name,concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as officer_name,SALES_PD_DATA.applicant_id,SALES_PD_DATA.lender_id,SALES_PD_DATA.product_id,SALES_PD_DATA.is_pdf,SALES_PD_DATA.is_edited,ENTITY.short_name,PRODUCTS.abbr,DATE_FORMAT(SALES_PD_DATA.createdon, "%d/%m/%Y") as pd_createdon,SALES_PD_DATA.status
$this->db->SELECT(' SALES_PD_DATA.sales_pd_sno, SALES_PD_DATA.sales_pd_id, SALES_PD_DATA.applicant_name,concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as officer_name,SALES_PD_DATA.applicant_id,SALES_PD_DATA.lender_id,SALES_PD_DATA.product_id,SALES_PD_DATA.is_pdf,SALES_PD_DATA.is_edited,ENTITY.short_name,PRODUCTS.abbr,SALES_PD_DATA.createdon,
DATE_FORMAT(SALES_PD_DATA.createdon, "%Y-%m-%d") as pd_createdon, SALES_PD_DATA.status,SALES_PD_DATA.sales_pd_type,SALES_PD_DATA.rand_string');
$this->db->from(SALES_PD_DATA.' as SALES_PD_DATA');
$this->db->join(ENTITY.' as ENTITY','ENTITY.entity_id = SALES_PD_DATA.lender_id','INNER');
$this->db->join(PRODUCTS.' as PRODUCTS', 'PRODUCTS.product_id = SALES_PD_DATA.product_id','INNER');
$this->db->join(USERPROFILE.' as USERPROFILE', 'USERPROFILE.userid = SALES_PD_DATA.createdby','INNER');
if(!empty($pd_status)){
$this->db->where_in('SALES_PD_DATA.status',$pd_status);
}
if(($pd_from_date != "" || $pd_from_date != null) && ($pd_to_date != "" || $pd_to_date != null)) {
$this->db->where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d') BETWEEN ". "'$pd_from_date'". ' AND '. "'$pd_to_date'" );
}
else if($pd_from_date != "" && $pd_from_date != null) {
$this->db->where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d')",$pd_from_date);
}
else if($pd_to_date != "" && $pd_to_date != null) {
$this->db->where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d')",$pd_to_date);
}
if(!empty($pd_products)){
$this->db->where_in('SALES_PD_DATA.product_id',$pd_products);
}
if(!empty($pd_lender)) {
$this->db->where_in('SALES_PD_DATA.lender_id',$pd_lender);
}
if(!empty($pd_applicant_name)) {
$this->db->like('SALES_PD_DATA.applicant_name',$pd_applicant_name);
}
if(!empty($pd_officer_name)) {
$this->db->like('SALES_PD_DATA.officer_name',$pd_officer_name);
}
if(!empty($sales_pd_officer_id)) {
$this->db->WHERE('SALES_PD_DATA.createdby',$sales_pd_officer_id);
}
$this->db->WHERE('SALES_PD_DATA.isactive',1);
$this->db->order_by('SALES_PD_DATA.sales_pd_id','desc');
$this->db->limit(1000,0);
$result = $this->db->get()->result_array();
// if(ENVIRONMENT == 'development'){echo 'LAST QUERY '. $this->db->last_query();}
return $result;
}
function getSMCTemplateForPD_old($pd_id,$product_id,$client,$random_string,$api)
{
//echo $product_id;die();
// $master_forms = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('isactive' => 1),SMC_CREDIT_PD_FORMS);
// print_r($master_forms);
$table = CREDITPDTEMPLATE.' as CREDITPDTEMPLATE';
// $table = SMC_CREDIT_PD_FORMS.' as SMC_CREDIT_PD_FORMS';
$fields = array('SMC_CREDIT_PD_FORMS.form_name','CREDITPDTEMPLATE.pd_form_id as fk_form_id','CREDITPDTEMPLATE.fk_product_id','SMC_CREDIT_PD_SECTION_DATA.fk_pd_id','if(SMC_CREDIT_PD_SECTION_DATA.json is not null,true,false) as is_answered','SMC_CREDIT_PD_SECTION_DATA.is_reupload_data_fetched','SMC_CREDIT_PD_FORMS.complete_check_enabled');
if($api == 'REPORT')
{
$fields = array('SMC_CREDIT_PD_FORMS.form_name','CREDITPDTEMPLATE.pd_form_id as fk_form_id','CREDITPDTEMPLATE.fk_product_id','SMC_CREDIT_PD_SECTION_DATA.fk_pd_id','SMC_CREDIT_PD_SECTION_DATA.json','if(SMC_CREDIT_PD_SECTION_DATA.json is not null,true,false) as is_answered','SMC_CREDIT_PD_SECTION_DATA.is_reupload_data_fetched','SMC_CREDIT_PD_FORMS.complete_check_enabled');
}
$joins = array(
array('table'=>SMC_CREDIT_PD_SECTION_DATA." as SMC_CREDIT_PD_SECTION_DATA",'condition'=>"SMC_CREDIT_PD_SECTION_DATA.fk_form_id = CREDITPDTEMPLATE.pd_form_id AND CREDITPDTEMPLATE.fk_product_id = $product_id AND SMC_CREDIT_PD_SECTION_DATA.fk_pd_id = $pd_id and SMC_CREDIT_PD_SECTION_DATA.isactive = 1 " ,'jointype'=>'LEFT'),
array('table'=>SMC_CREDIT_PD_FORMS." as SMC_CREDIT_PD_FORMS",'condition'=>"CREDITPDTEMPLATE.pd_form_id = SMC_CREDIT_PD_FORMS.form_id" ,'jointype'=>'INNER JOIN')
);
$where_condition_array = array('CREDITPDTEMPLATE.isactive' => 1,'CREDITPDTEMPLATE.fk_product_id' => $product_id);
return
$master_forms = $this->getJoinRecords($fields,$table,$joins,$where_condition_array,'CREDITPDTEMPLATE.pd_form_id','ASC');
print_r($this->db->last_query());die();
}
function getSMCTemplateForPD($pd_id,$product_id,$client,$random_string,$api)
{
$table = SMC_PRODUCT_WISE_FORM_MAPPING.' as SMC_PRODUCT_WISE_FORM_MAPPING';
$fields = array('SMC_CREDIT_PD_FORMS.form_name','SMC_PRODUCT_WISE_FORM_MAPPING.fk_form_id as fk_form_id','SMC_PRODUCT_WISE_FORM_MAPPING.fk_product_id','SMC_CREDIT_PD_SECTION_DATA.fk_pd_id','if(SMC_CREDIT_PD_SECTION_DATA.json is not null,true,false) as is_answered','SMC_CREDIT_PD_SECTION_DATA.is_reupload_data_fetched','SMC_PRODUCT_WISE_FORM_MAPPING.complete_check_enabled');
if($api == 'REPORT')
{
$fields = array('SMC_CREDIT_PD_FORMS.form_name','SMC_PRODUCT_WISE_FORM_MAPPING.fk_form_id as fk_form_id','SMC_PRODUCT_WISE_FORM_MAPPING.fk_product_id','SMC_CREDIT_PD_SECTION_DATA.fk_pd_id','SMC_CREDIT_PD_SECTION_DATA.json','if(SMC_CREDIT_PD_SECTION_DATA.json is not null,true,false) as is_answered','SMC_CREDIT_PD_SECTION_DATA.is_reupload_data_fetched','SMC_PRODUCT_WISE_FORM_MAPPING.complete_check_enabled');
}
$joins = array(
array('table'=>SMC_CREDIT_PD_SECTION_DATA." as SMC_CREDIT_PD_SECTION_DATA",'condition'=>"SMC_CREDIT_PD_SECTION_DATA.fk_form_id = SMC_PRODUCT_WISE_FORM_MAPPING.fk_form_id AND SMC_PRODUCT_WISE_FORM_MAPPING.fk_product_id = $product_id AND SMC_CREDIT_PD_SECTION_DATA.fk_pd_id = $pd_id and SMC_CREDIT_PD_SECTION_DATA.isactive = 1 " ,'jointype'=>'LEFT'),
array('table'=>SMC_CREDIT_PD_FORMS." as SMC_CREDIT_PD_FORMS",'condition'=>"SMC_PRODUCT_WISE_FORM_MAPPING.fk_form_id = SMC_CREDIT_PD_FORMS.form_id AND SMC_CREDIT_PD_FORMS.isactive = 1 " ,'jointype'=>'INNER JOIN')
);
$where_condition_array = array('SMC_PRODUCT_WISE_FORM_MAPPING.isactive' => 1,'SMC_PRODUCT_WISE_FORM_MAPPING.fk_product_id' => $product_id);
return
$master_forms = $this->getJoinRecords($fields,$table,$joins,$where_condition_array,'SMC_PRODUCT_WISE_FORM_MAPPING.form_order_level','ASC');
// print_r($this->db->last_query());die();
}
function getSMCFlowUsers($state,$role)
{
$fields = array('RCM_STATE_MAPPING.fk_user_id as userid','USERPROFILE.first_name','USERPROFILE.last_name','USERPROFILEROLES.user_role','USERPROFILE.smc_emp_code');
$table = RCM_STATE_MAPPING.' as RCM_STATE_MAPPING';
$where_condition_array = array('RCM_STATE_MAPPING.isactive '=>1,'RCM_STATE_MAPPING.fk_state_id' => $state);
$joins = array(
array('table'=>USERPROFILE." as USERPROFILE",'condition'=>"USERPROFILE.userid = RCM_STATE_MAPPING.fk_user_id " ,'jointype'=>'INNER JOIN'),
array('table'=>USERPROFILEROLES.' as USERPROFILEROLES','condition'=>"RCM_STATE_MAPPING.fk_user_id = USERPROFILEROLES.fk_userid and USERPROFILEROLES.user_role = 27 and USERPROFILEROLES.isactive = 1" ,'jointype'=>'INNER JOIN')
);
$RCMusers = $this->SMC_Credit_PD_Model->getJoinRecords($fields,$table,$joins,$where_condition_array);
// print_r($this->db->last_query());exit();
$result = array();
if($role == 26){
# To Find the CM users (Using RCM user's-state-ID )
if(!empty($RCMusers)){
$temp1 = array(); // to filter RCM user's id we using Temp1 array.
foreach($RCMusers as $rcm){array_push($temp1,$rcm['userid']);}
$this->db->select('RCM_STATE_MAPPING.fk_state_id');
$this->db->from(RCM_STATE_MAPPING.' as RCM_STATE_MAPPING');
$this->db->where_in('RCM_STATE_MAPPING.fk_user_id',$temp1);
$this->db->group_by('RCM_STATE_MAPPING.fk_state_id');
$RCMUsersStateId = $this->db->get()->result_array();
$temp2 = array(); // to filter RCM user's state id we using Temp2 array.
foreach($RCMUsersStateId as $stid){array_push($temp2,$stid['fk_state_id']);}
$this->db->select('USERPROFILE.userid,USERPROFILE.first_name,USERPROFILE.last_name,USERPROFILEROLES.user_role,USERPROFILE.smc_emp_code');
$this->db->from(USERPROFILE.' as USERPROFILE');
$this->db->join(USERPROFILEROLES.' as USERPROFILEROLES',"USERPROFILE.userid = USERPROFILEROLES.fk_userid and USERPROFILEROLES.user_role = $role and USERPROFILEROLES.isactive = 1",'INNER');
$this->db->where_in('USERPROFILE.fk_state',$temp2);
$this->db->where('USERPROFILE.isactive',1);
$CMusers = $this->db->get()->result_array();
$result = $CMusers;
}
}else if($role == 27){
$result = $RCMusers;
}
return $result;
// Don't Remove Existing Query.
// $fields = array('USERPROFILE.userid','USERPROFILE.first_name','USERPROFILE.last_name','USERPROFILEROLES.user_role');
// $table = USERPROFILE.' as USERPROFILE';
// $where_condition_array = array('USERPROFILE.fk_state' => $state);
// $joins = array(
// array('table'=>USERPROFILEROLES.' as USERPROFILEROLES','condition'=>"USERPROFILE.userid = USERPROFILEROLES.fk_userid and USERPROFILEROLES.user_role = $role and USERPROFILEROLES.isactive = 1" ,'jointype'=>'INNER JOIN')
// );
// $users = $this->SMC_Credit_PD_Model->getJoinRecords($fields,$table,$joins,$where_condition_array);
// return $users;
}
}