sparqapi/api/application/controllers/Flyhi_Controller.php
2022-06-08 13:50:52 +05:30

93 lines
3.7 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . '/libraries/REST_Controller.php';
require APPPATH . 'vendor/autoload.php';
class Flyhi_Controller extends REST_Controller {
function __construct()
{
parent::__construct();
$this->load->model('Flyhi_Model','Flyhi_Model');
$this->load->model('Sales_PD_Model','Sales_PD_Model');
}
public function listFlyhiSalesPD_get(){
$lender_id = $this->uri->segment(2);
$user_id = $this->uri->segment(3);
$role = $this->uri->segment(4);
$columns = array('SALES_PD_DATA.sales_pd_id','SALES_PD_DATA.sales_pd_sno','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','PRODUCT.abbr','SALES_PD_DATA.status','SALES_PD_DATA.sales_pd_type','SALES_PD_DATA.rand_string','SALES_PD_DATA.isactive','SALES_PD_DATA.city_id','CITY.name as city_name',
'(CASE WHEN SALES_PD_DATA.status = "STARTED" THEN SALES_PD_DATA.createdon WHEN SALES_PD_DATA.status = "COMPLETED" THEN SALES_PD_DATA.completed_date ELSE NULL END) AS createdon');
$table = SALES_PD_DATA.' as SALES_PD_DATA';
$joins = array(
array('table' => ENTITY. ' as ENTITY',
'condition' =>'SALES_PD_DATA.lender_id = ENTITY.entity_id',
'jointype' => 'INNER'),
array('table' => PRODUCTS. ' as PRODUCT',
'condition' =>'SALES_PD_DATA.product_id = PRODUCT.product_id',
'jointype' => 'INNER'),
array('table' => CITY. ' as CITY',
'condition' =>'SALES_PD_DATA.city_id = CITY.city_id',
'jointype' => 'LEFT'),
array('table' => USERPROFILE. ' as USERPROFILE',
'condition' =>'SALES_PD_DATA.createdby = USERPROFILE.userid',
'jointype' => 'LEFT')
);
$or_where = array();
$where_condition_array['SALES_PD_DATA.isactive'] = 1;
if(is_numeric($lender_id))
{
$where_condition_array['SALES_PD_DATA.lender_id'] = $lender_id;
}
// FILTERING THE LAST 10 DAYS RECORDS
$key_date='SALES_PD_DATA.createdon BETWEEN DATE_SUB(NOW(), INTERVAL 60 DAY) AND NOW()';
$condition_value=null;
$where_condition_array[$key_date] = $condition_value;
// print_r ($where_condition_array);
// ----END OF FILTERING THE LAST 10 DAYS RECORDS---
$MWISELender = (ENVIRONMENT == 'production' ? 7 : 35);
if($role && is_numeric($role) && $role == 11 && $MWISELender == $lender_id){
// $where_condition_array['SALES_PD_DATA.product_id'] = (ENVIRONMENT == 'production' ? 23 : 22);
}else{
if($role && is_numeric($role) && $role == 15) //if role area sales head the pull all meq cases
{
$where_condition_array['SALES_PD_DATA.product_id'] = (ENVIRONMENT == 'production' ? 23 : 22);
$or_where['SALES_PD_DATA.createdby'] = $user_id;
}
else if($user_id && is_numeric($user_id))
{
$where_condition_array['SALES_PD_DATA.createdby'] = $user_id;
}
}
$where_condition_array['SALES_PD_DATA.sales_pd_type in (3,4)'] = null;
$order_by = 'SALES_PD_DATA.sales_pd_id';
$sales_pd_data = $this->Sales_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array,$order_by,'DESC','',$or_where);
//print_r($this->db->last_query());die();
if(count($sales_pd_data))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $sales_pd_data;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'Something went wrong! Try Later';
$this->response($data,REST_Controller::HTTP_OK);
}
}
}// Class Ends