289 lines
12 KiB
PHP
289 lines
12 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 listFlyhiPD_get(){
|
|
|
|
$user_id = $this->uri->segment(1);
|
|
|
|
$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.is_pdf','SALES_PD_DATA.is_edited','ENTITY.full_name','ENTITY.short_name','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',
|
|
'SALES_PD_DATA.lender_sales_person','concat(LENDERSALESPERSON.first_name," ",LENDERSALESPERSON.last_name) as lender_sales_person_name','LENDERSALESPERSON.mobile_no as lender_sales_contact_mobileno','LENDERSALESPERSON.email as lender_sales_person_email',
|
|
'SALES_PD_DATA.lender_credit_person','concat(LENDERCREDITPERSON.first_name," ",LENDERCREDITPERSON.last_name) as lender_credit_person_name','LENDERCREDITPERSON.mobile_no as lender_credit_person_contact_mobileno','LENDERCREDITPERSON.email as lender_credit_person_email',
|
|
'SALES_PD_DATA.pd_branch_id,ENTITYLENDERBRANCH.branch_name','SALES_PD_DATA.loan_amount',
|
|
'(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' => 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'),
|
|
array('table' => USERPROFILE. ' as LENDERSALESPERSON',
|
|
'condition' =>'SALES_PD_DATA.lender_sales_person = LENDERSALESPERSON.userid',
|
|
'jointype' => 'LEFT'),
|
|
array('table' => USERPROFILE. ' as LENDERCREDITPERSON',
|
|
'condition' =>'SALES_PD_DATA.lender_credit_person = LENDERCREDITPERSON.userid',
|
|
'jointype' => 'LEFT'),
|
|
array('table' => ENTITYLENDERBRANCH. ' as ENTITYLENDERBRANCH',
|
|
'condition' =>'SALES_PD_DATA.pd_branch_id = ENTITYLENDERBRANCH.entity_lender_branch_id',
|
|
'jointype' => 'LEFT')
|
|
);
|
|
|
|
$or_where = array();
|
|
$where_condition_array['SALES_PD_DATA.isactive'] = 1;
|
|
|
|
// 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;
|
|
// ----END OF FILTERING THE LAST 10 DAYS RECORDS---
|
|
|
|
$FHFSL_lender = (ENVIRONMENT == 'production' ? 0 : 49);
|
|
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';
|
|
|
|
$Flyhi_pd_data = $this->Flyhi_Model->getJoinRecords($columns,$table,$joins,$where_condition_array,$order_by,'DESC','',$or_where);
|
|
//print_r($this->db->last_query());die();
|
|
|
|
if(count($Flyhi_pd_data))
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $Flyhi_pd_data;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'FlyHI PD Data Not Found! Try Later';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
|
|
public function saveFlyhiPD_post()
|
|
{
|
|
$records = $this->post('records');
|
|
$is_entry_done = null;
|
|
$flyhi_pd_id = null;
|
|
$section_data = json_encode($records);
|
|
$fk_createdby = $records['fk_createdby'];
|
|
$applicant_id = null;
|
|
$applicant_name = null;
|
|
$city = null;
|
|
$lender_id = null;
|
|
$loan_amount = null;
|
|
$pd_branch_id = null;
|
|
$lender_sales_person = null;
|
|
$lender_credit_person = null;
|
|
|
|
log_message('ERROR','####FLYHI-PD SAVE CALLED');
|
|
|
|
// $section_names = array('1' => 'General Section','2' => 'Photography');
|
|
$section_names = array('1' => 'General Section');
|
|
|
|
if($records['sales_pd_id'] == '' || $records['sales_pd_id'] == null)
|
|
{
|
|
|
|
/************ASSIGN Random URL******************/
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < 16; $i++)
|
|
{
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
}
|
|
|
|
$records['rand_string'] = $randomString;
|
|
log_message('ERROR','####INSERT NEW FLYHIPD');
|
|
if($records['questions'])
|
|
{
|
|
foreach ($records['questions'] as $g_key => $g_value)
|
|
{
|
|
if($g_value['question_key'] == 'application_id')
|
|
{
|
|
$applicant_id = $g_value['answer_value'] ? $g_value['answer_value'] : 'Not Provided';
|
|
}
|
|
if($g_value['question_key'] == 'company_name')
|
|
{
|
|
$applicant_name = $g_value['answer_value'];
|
|
}
|
|
if($g_value['question_key'] == 'city')
|
|
{
|
|
$city = $g_value['answer_value'];
|
|
}
|
|
if($g_value['question_key'] == 'lender_id')
|
|
{
|
|
$lender_id = $g_value['answer_value'];
|
|
}
|
|
if($g_value['question_key'] == 'loan_amount')
|
|
{
|
|
$loan_amount = $g_value['answer_value'];
|
|
}
|
|
if($g_value['question_key'] == 'pd_branch_id')
|
|
{
|
|
$pd_branch_id = $g_value['answer_value'];
|
|
}
|
|
if($g_value['question_key'] == 'lender_sales_person')
|
|
{
|
|
$lender_sales_person = $g_value['answer_value'];
|
|
}
|
|
if($g_value['question_key'] == 'lender_credit_person')
|
|
{
|
|
$lender_credit_person = $g_value['answer_value'];
|
|
}
|
|
|
|
}
|
|
}
|
|
$count = $this->Flyhi_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $lender_id,'isactive' => 1),SALES_PD_DATA);
|
|
$lender_short_name = $this->Flyhi_Model->selectCustomRecords(array('short_name'),array('entity_id' => $lender_id),ENTITY);
|
|
$flyhipd_serial_no = $lender_short_name.'-'.(++$count[0]['count']);
|
|
$FLYHI_PD['applicant_name'] = $applicant_name;
|
|
$FLYHI_PD['applicant_id'] = $applicant_id;
|
|
$FLYHI_PD['city_id']=$city;
|
|
$FLYHI_PD['sales_pd_sno'] = $flyhipd_serial_no;
|
|
$FLYHI_PD['loan_amount'] = $loan_amount;
|
|
$FLYHI_PD['lender_sales_person'] = $lender_sales_person ;
|
|
$FLYHI_PD['lender_credit_person'] = $lender_credit_person ;
|
|
$FLYHI_PD['pd_branch_id'] = $pd_branch_id;
|
|
$FLYHI_PD['lender_id'] = $lender_id;
|
|
$FLYHI_PD['createdby'] = $fk_createdby;
|
|
$FLYHI_PD['rand_string'] = $randomString;
|
|
$flyhi_pd_id = $this->Flyhi_Model->saveRecords($FLYHI_PD,SALES_PD_DATA);
|
|
$section_data = json_encode($records);
|
|
$this->Sales_PD_Model->updateRecords(array('isactive' => 0),SALESPD_SECTION_DATA,array('sales_pd_id' =>$flyhi_pd_id,'section_id' => 1 ));
|
|
$status = $records['is_complete'];
|
|
$fields = array('sales_pd_id' => $flyhi_pd_id, 'section_id' => 1, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby);
|
|
$is_entry_done = $this->Sales_PD_Model->saveRecords($fields,SALESPD_SECTION_DATA);
|
|
}
|
|
|
|
else
|
|
{
|
|
if(isset($records['status']) && $records['status'] == 'COMPLETED')
|
|
{
|
|
log_message('ERROR','####COMPLETE FLYHI-PD'.$records['sales_pd_id']);
|
|
$records['status'] = 'COMPLETED';
|
|
$records['is_cus_link_disabled'] = 1;
|
|
$records['completed_date'] = date('Y-m-d H:i:s');
|
|
$flyhi_pd_id = $this->Flyhi_Model->updateRecords($records,SALES_PD_DATA,array('sales_pd_id' => $records['sales_pd_id']));
|
|
$completed_sections = $this->Flyhi_Model->selectCustomRecords(array('section_id'),array('status' => 1,'sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALESPD_SECTION_DATA);
|
|
}
|
|
else
|
|
{
|
|
|
|
log_message('ERROR','####UPDATE FLYHIPD'.$records['sales_pd_id']);
|
|
// $gen_form = json_decode($form[0]['section_data'],true);
|
|
$flyhi_pd_id = $records['sales_pd_id'];
|
|
|
|
if($records['questions']){
|
|
foreach ($records['questions'] as $g_key => $g_value)
|
|
{
|
|
if($g_value['question_key'] == 'application_id')
|
|
{
|
|
$applicant_id = $g_value['answer_value'] ? $g_value['answer_value'] : 'Not Provided';
|
|
}
|
|
if($g_value['question_key'] == 'company_name')
|
|
{
|
|
$applicant_name = $g_value['answer_value'];
|
|
}
|
|
if($g_value['question_key'] == 'city')
|
|
{
|
|
$city = $g_value['answer_value'];
|
|
}
|
|
if($g_value['question_key'] == 'lender_id')
|
|
{
|
|
$lender_id = $g_value['answer_value'];
|
|
}
|
|
if($g_value['question_key'] == 'loan_amount')
|
|
{
|
|
$loan_amount = $g_value['answer_value'];
|
|
}
|
|
if($g_value['question_key'] == 'pd_branch_id')
|
|
{
|
|
$pd_branch_id = $g_value['answer_value'];
|
|
}
|
|
if($g_value['question_key'] == 'lender_sales_person')
|
|
{
|
|
$lender_sales_person = $g_value['answer_value'];
|
|
}
|
|
if($g_value['question_key'] == 'lender_credit_person')
|
|
{
|
|
$lender_credit_person = $g_value['answer_value'];
|
|
}
|
|
}
|
|
}
|
|
$FLYHI_PD['applicant_name'] = $applicant_name;
|
|
$FLYHI_PD['applicant_id'] = $applicant_id;
|
|
$FLYHI_PD['city_id']=$city;
|
|
$FLYHI_PD['loan_amount'] = $loan_amount;
|
|
$FLYHI_PD['lender_sales_person'] = $lender_sales_person ;
|
|
$FLYHI_PD['lender_credit_person'] = $lender_credit_person ;
|
|
$FLYHI_PD['pd_branch_id'] = $pd_branch_id;
|
|
$FLYHI_PD['lender_id'] = $lender_id;
|
|
$flyhi_pd_id = $this->Flyhi_Model->updateRecords($FLYHI_PD,SALES_PD_DATA,array('sales_pd_id' => $flyhi_pd_id));
|
|
$status = $records['is_complete'];
|
|
$fields = array('sales_pd_id' => $flyhi_pd_id, 'section_id' => 1, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby);
|
|
$is_entry_done = $this->Sales_PD_Model->saveRecords($fields,SALESPD_SECTION_DATA);
|
|
} // else 179
|
|
} // else 167
|
|
if($flyhi_pd_id)
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['records'] = $flyhi_pd_id;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
if(isset($records['rand_string'])){ $data['rand_string'] = $records['rand_string']; }
|
|
$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);
|
|
}
|
|
}
|
|
|
|
public function getFlyhiPD_get()
|
|
{
|
|
$Flyhi_pdid = $this->get('pd_id');
|
|
$section_data = array();
|
|
if(isset($Flyhi_pdid) || $Flyhi_pdid != "" || $Flyhi_pdid != null)
|
|
{
|
|
$section_data = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $Flyhi_pdid,'isactive' => 1,'section_id' => 1),SALESPD_SECTION_DATA);
|
|
}
|
|
if($section_data)
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $section_data;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'No Data Found';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
}// Class Ends
|