3355 lines
121 KiB
PHP
3355 lines
121 KiB
PHP
<?php
|
|
/**
|
|
|
|
* User: velz
|
|
* This Controller deals with PD Related CRUD Operations
|
|
*/
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
|
|
require_once APPPATH . '/libraries/REST_Controller.php';
|
|
require_once APPPATH . '/libraries/Smartie.php';
|
|
//require BASEPATH.'core/Controller.php';
|
|
|
|
|
|
class PD_Controller extends REST_Controller {
|
|
//class PD_Controller extends CI_Controller {
|
|
|
|
function __construct()
|
|
{
|
|
// Construct the parent class
|
|
parent::__construct();
|
|
$this->load->model('PD_Model');
|
|
$this->load->library('AWS_S3');
|
|
$this->load->library('AWS_SNS');
|
|
$this->load->helper('GETPDFORMDETAILS');
|
|
$this->load->library('pdfgenerator');
|
|
//$this->load->library('pdfgen_tcpdf');
|
|
|
|
|
|
}
|
|
|
|
|
|
public function base_get()
|
|
{
|
|
$base64_img = "data:image/gif;base64,R0lGODlhPQBEAPeoAJosM//AwO/AwHVYZ/z595kzAP/s7P+goOXMv8+fhw/v739/f+8PD98fH/8mJl+fn/9ZWb8/PzWlwv///6wWGbImAPgTEMImIN9gUFCEm/gDALULDN8PAD6atYdCTX9gUNKlj8wZAKUsAOzZz+UMAOsJAP/Z2ccMDA8PD/95eX5NWvsJCOVNQPtfX/8zM8+QePLl38MGBr8JCP+zs9myn/8GBqwpAP/GxgwJCPny78lzYLgjAJ8vAP9fX/+MjMUcAN8zM/9wcM8ZGcATEL+QePdZWf/29uc/P9cmJu9MTDImIN+/r7+/vz8/P8VNQGNugV8AAF9fX8swMNgTAFlDOICAgPNSUnNWSMQ5MBAQEJE3QPIGAM9AQMqGcG9vb6MhJsEdGM8vLx8fH98AANIWAMuQeL8fABkTEPPQ0OM5OSYdGFl5jo+Pj/+pqcsTE78wMFNGQLYmID4dGPvd3UBAQJmTkP+8vH9QUK+vr8ZWSHpzcJMmILdwcLOGcHRQUHxwcK9PT9DQ0O/v70w5MLypoG8wKOuwsP/g4P/Q0IcwKEswKMl8aJ9fX2xjdOtGRs/Pz+Dg4GImIP8gIH0sKEAwKKmTiKZ8aB/f39Wsl+LFt8dgUE9PT5x5aHBwcP+AgP+WltdgYMyZfyywz78AAAAAAAD///8AAP9mZv///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAKgALAAAAAA9AEQAAAj/AFEJHEiwoMGDCBMqXMiwocAbBww4nEhxoYkUpzJGrMixogkfGUNqlNixJEIDB0SqHGmyJSojM1bKZOmyop0gM3Oe2liTISKMOoPy7GnwY9CjIYcSRYm0aVKSLmE6nfq05QycVLPuhDrxBlCtYJUqNAq2bNWEBj6ZXRuyxZyDRtqwnXvkhACDV+euTeJm1Ki7A73qNWtFiF+/gA95Gly2CJLDhwEHMOUAAuOpLYDEgBxZ4GRTlC1fDnpkM+fOqD6DDj1aZpITp0dtGCDhr+fVuCu3zlg49ijaokTZTo27uG7Gjn2P+hI8+PDPERoUB318bWbfAJ5sUNFcuGRTYUqV/3ogfXp1rWlMc6awJjiAAd2fm4ogXjz56aypOoIde4OE5u/F9x199dlXnnGiHZWEYbGpsAEA3QXYnHwEFliKAgswgJ8LPeiUXGwedCAKABACCN+EA1pYIIYaFlcDhytd51sGAJbo3onOpajiihlO92KHGaUXGwWjUBChjSPiWJuOO/LYIm4v1tXfE6J4gCSJEZ7YgRYUNrkji9P55sF/ogxw5ZkSqIDaZBV6aSGYq/lGZplndkckZ98xoICbTcIJGQAZcNmdmUc210hs35nCyJ58fgmIKX5RQGOZowxaZwYA+JaoKQwswGijBV4C6SiTUmpphMspJx9unX4KaimjDv9aaXOEBteBqmuuxgEHoLX6Kqx+yXqqBANsgCtit4FWQAEkrNbpq7HSOmtwag5w57GrmlJBASEU18ADjUYb3ADTinIttsgSB1oJFfA63bduimuqKB1keqwUhoCSK374wbujvOSu4QG6UvxBRydcpKsav++Ca6G8A6Pr1x2kVMyHwsVxUALDq/krnrhPSOzXG1lUTIoffqGR7Goi2MAxbv6O2kEG56I7CSlRsEFKFVyovDJoIRTg7sugNRDGqCJzJgcKE0ywc0ELm6KBCCJo8DIPFeCWNGcyqNFE06ToAfV0HBRgxsvLThHn1oddQMrXj5DyAQgjEHSAJMWZwS3HPxT/QMbabI/iBCliMLEJKX2EEkomBAUCxRi42VDADxyTYDVogV+wSChqmKxEKCDAYFDFj4OmwbY7bDGdBhtrnTQYOigeChUmc1K3QTnAUfEgGFgAWt88hKA6aCRIXhxnQ1yg3BCayK44EWdkUQcBByEQChFXfCB776aQsG0BIlQgQgE8qO26X1h8cEUep8ngRBnOy74E9QgRgEAC8SvOfQkh7FDBDmS43PmGoIiKUUEGkMEC/PJHgxw0xH74yx/3XnaYRJgMB8obxQW6kL9QYEJ0FIFgByfIL7/IQAlvQwEpnAC7DtLNJCKUoO/w45c44GwCXiAFB/OXAATQryUxdN4LfFiwgjCNYg+kYMIEFkCKDs6PKAIJouyGWMS1FSKJOMRB/BoIxYJIUXFUxNwoIkEKPAgCBZSQHQ1A2EWDfDEUVLyADj5AChSIQW6gu10bE/JG2VnCZGfo4R4d0sdQoBAHhPjhIB94v/wRoRKQWGRHgrhGSQJxCS+0pCZbEhAAOw==";
|
|
|
|
$output_file = APPPATH."/docs/temp_base64_image.png";
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < 5; $i++) {
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
}
|
|
$temp_file_name = $randomString.date('Y-m-d-H:m:s');
|
|
|
|
|
|
$ifp = fopen( $output_file, 'wb' );
|
|
|
|
// split the string on commas
|
|
// $data[ 0 ] == "data:image/png;base64"
|
|
// $data[ 1 ] == <actual base64 string>
|
|
$data = explode( ',', $base64_img );
|
|
print_r($data);
|
|
// we could add validation here with ensuring count( $data ) > 1
|
|
fwrite( $ifp, base64_decode( $data[ 1 ] ) );
|
|
|
|
// clean up the file resource
|
|
fclose( $ifp );
|
|
|
|
print_r($output_file);
|
|
|
|
$tempdoc = $output_file;
|
|
$tempdocname = $temp_file_name.'.png';
|
|
$bucketname = LENDER_BUCKET_NAME_PREFIX.'1';
|
|
$key = 'pd'.'1'.'/'.$tempdocname ;
|
|
$sourcefile = $tempdoc;
|
|
|
|
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile);
|
|
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
|
print_r($s3result);
|
|
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
|
|
{
|
|
// $record_data = array('fk_pd_id' => $pd_id,'pd_document_title'=>$title,'pd_document_name'=>$tempdocname);
|
|
// $this->PD_Model->saveRecords($record_data,PDDOCUMENTS);
|
|
}
|
|
}
|
|
/***********************Get get List Of Lenders Details for PD Trigger Page************************/
|
|
|
|
public function getListOfLenders_get()
|
|
{
|
|
$fields = array('entity_id','full_name','short_name');
|
|
$where_condition_array = array('isactive' => 1,'fk_entity_type_id' => 2);
|
|
$result_data = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,ENTITY);
|
|
if(count($result_data))
|
|
{
|
|
|
|
foreach($result_data as $key => $value)
|
|
{
|
|
$fields = array('*');
|
|
$where_condition_array = array('isactive' => 1,'fk_entity_id' => $value['entity_id']);
|
|
$result_data[$key]['billing_address'] = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,ENTITYBILLING);
|
|
}
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $result_data;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
|
|
}
|
|
}
|
|
|
|
/********************Get get List Of Products and SubProducts Name Details for PD Trigger Page*********/
|
|
|
|
public function getListOfProducts_get()
|
|
{
|
|
$fields = array('product_id','name as product_name','abbr as product_abbr');
|
|
$where_condition_array = array('isactive' => 1);
|
|
$result_data = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PRODUCTS);
|
|
if(count($result_data))
|
|
{
|
|
foreach($result_data as $key => $product)
|
|
{
|
|
$fields = array('subproduct_id','name as subproduct_name','abbr as subproduct_abbr');
|
|
$where_condition_array = array('isactive' => 1,'fk_product_id' => $product['product_id']);
|
|
$subproducts = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,SUBPRODUCTS);
|
|
//array_push($result_data[$key],$subproducts);
|
|
$result_data[$key]['subproducts'] = $subproducts;
|
|
}
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $result_data;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/********************Get get List Of CustomerSegments Details for PD Trigger Page*********/
|
|
|
|
public function getListOfCustomerSegments_get()
|
|
{
|
|
$fields = array('customer_segment_id','name as customer_segment','abbr');
|
|
$where_condition_array = array('isactive' => 1);
|
|
$result_data = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,CUSTOMERSEGMENT);
|
|
if(count($result_data))
|
|
{
|
|
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $result_data;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
|
|
}
|
|
}
|
|
|
|
/********************Get get List Of Both PD Allocation Types and PD Types Details for PD Trigger Page*********/
|
|
|
|
public function getListOfPDAllocationTypes_get()
|
|
{
|
|
$fields = array('pd_allocation_type_id','pd_allocation_type_name','pd_allocation_logic','default');
|
|
$where_condition_array = array('isactive' => 1);
|
|
$result_data['pd_allocation_type'] = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDALLOCATIONTYPE);
|
|
|
|
$fields1 = array('pd_type_id','type_name');
|
|
$where_condition_array1 = array('isactive' => 1);
|
|
$result_data['pd_type'] = $this->PD_Model->selectCustomRecords($fields1,$where_condition_array1,PDTYPE);
|
|
if(count($result_data))
|
|
{
|
|
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $result_data;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/********************Get get List Of States and Cities Name Details for PD Trigger Page*********/
|
|
|
|
public function getListOfStatesAndCities_get()
|
|
{
|
|
$fields = array('state_id','name as state_name','code');
|
|
$where_condition_array = array('isactive' => 1);
|
|
$result_data = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,STATE);
|
|
if(count($result_data))
|
|
{
|
|
foreach($result_data as $key => $state)
|
|
{
|
|
$fields = array('city_id','name as city_name');
|
|
$where_condition_array = array('isactive' => 1,'fk_state_id' => $state['state_id']);
|
|
$cities = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,CITY);
|
|
//array_push($result_data[$key],$cities);
|
|
$result_data[$key]['cities'] = $cities;
|
|
}
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $result_data;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********For Save New PD while Trigger****/
|
|
|
|
public function triggerNewPD_post()
|
|
{
|
|
|
|
|
|
$pd_details = json_decode($this->post('pd_details'),true);
|
|
$pd_addtional_requirements = array();
|
|
if($this->post('addtional_requirements'))
|
|
{
|
|
$pd_addtional_requirements = json_decode($this->post('addtional_requirements'),true);
|
|
}
|
|
$pd_applicant_details = json_decode($this->post('pd_applicant_details'),true);
|
|
$pd_document_titles = "";
|
|
$pd_document_from_mobile = "";
|
|
if($this->post('pd_document_titles')){ $pd_document_titles = json_decode($this->post('pd_document_titles'),true); }
|
|
|
|
if($this->post('pd_document_from_mobile')){ $pd_document_from_mobile = json_decode($this->post('pd_document_from_mobile'),true); }
|
|
|
|
$pd_documents = array();
|
|
|
|
$count = 0;
|
|
/***********************CHOOSE PD TEMPALATE*********************/
|
|
if($pd_details['pd_status'] == TRIGGERED)
|
|
{
|
|
$fields = array('fk_template_id');
|
|
|
|
$where_condition_array = array('fk_lender_id'=>$pd_details['fk_lender_id'] ,'fk_product_id'=> $pd_details['fk_product_id'],'fk_customer_segment'=> $pd_details['fk_customer_segment'],'isactive' => 1);
|
|
|
|
$table = LENDERTEMPLATE;
|
|
|
|
$choosed_template_id = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,$table);
|
|
|
|
if(count($choosed_template_id))
|
|
{
|
|
$pd_details['fk_pd_template_id'] = $choosed_template_id[0]['fk_template_id'];
|
|
}
|
|
}
|
|
|
|
/***********************PD ALLOCATION TYPE PROCESS **********/
|
|
|
|
// $pd_details['pd_status'] = TRIGGERED;
|
|
// $pd_details['fk_pd_allocated_to'] = null;
|
|
// $where_condition_array = array('fk_city_id' => $pd_details['fk_city'],'fk_lender_id' => $pd_details['fk_lender_id']);
|
|
// $temp_city_id = $this->PD_Model->selectRecords(PDTEAMMAP,$where_condition_array,$limit=0,$offset=0);
|
|
// //print_r($temp_city_id);
|
|
// if(count($temp_city_id))
|
|
// {
|
|
// if(isset($temp_city_id[0]['team_type']))
|
|
// {
|
|
// if($temp_city_id[0]['team_type'] == 0) // Allocate to Vendor
|
|
// {
|
|
// $pd_details['pd_agency_id'] = $temp_city_id[0]['fk_team_id'];
|
|
// $pd_details['pd_status'] = ALLOCATED_TO_PARTNER;
|
|
// $pd_details['fk_pd_allocated_to'] = null;
|
|
// }
|
|
// else //Allocate to SineEdge Team with allocation logics
|
|
// {
|
|
// //echo "SineEdge TEAm";
|
|
// $local_pd_allocation_type = $pd_details['fk_pd_allocation_type'];
|
|
// if($local_pd_allocation_type == 1)// AUTO - Load Balance Allocation
|
|
// {
|
|
|
|
// //echo "AUTO LOAD";
|
|
// //select list of pd officers based on pd type, product, customer segment, and team from table (t_pd_officiers_details) and choose minimun allocated one and assign pd Officer and change status form TRIGGERED to ALLOCATED
|
|
// $fields = array('fk_user_id','allocated');
|
|
|
|
// $where_condition_array = array('fk_pd_type_id' => $pd_details['fk_pd_type'],'fk_team_id' => $temp_city_id[0]['fk_team_id'],'fk_customer_segment' => $pd_details['fk_customer_segment'],'fk_product_id' => $pd_details['fk_product_id'],'isactive' => 1);
|
|
|
|
// $list_of_pd_officers = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDOFFICIERSDETAILS);
|
|
// //echo "PD OFF";
|
|
// //print_r($list_of_pd_officers);
|
|
// $allocated_values = array_column($list_of_pd_officers,'allocated');
|
|
|
|
// $min_allocated = min($allocated_values);
|
|
// $key = array_search($min_allocated,$allocated_values);
|
|
// $final_pd_officer_to_allocate = $list_of_pd_officers[$key]['fk_user_id'];
|
|
|
|
// //For Random Allocaiton not in use
|
|
// // $key = mt_rand(0, count($list_of_pd_officers) - 1);
|
|
// // $final_pd_officer_to_allocate = isset($list_of_pd_officers[$key])? $list_of_pd_officers[$key]: null;
|
|
|
|
// $pd_details['fk_pd_allocated_to'] = $final_pd_officer_to_allocate;
|
|
// $pd_details['pd_status'] = ALLOCATED;
|
|
// //echo "final".$final_pd_officer_to_allocate;
|
|
|
|
// }
|
|
// else if($local_pd_allocation_type == 2) // AUTO - NEAREST Allocation
|
|
// {
|
|
|
|
// }
|
|
// else // Manual Allocation
|
|
// {
|
|
// // Do nothing, cause fk_pd_allocated_to value comes from front end.
|
|
// }
|
|
|
|
// }
|
|
// }//End Of isset
|
|
// }
|
|
|
|
/***********************END OF PD ALLOCATION TYPE AND PROCESS***********/
|
|
|
|
$pd_details['pd_date_of_initiation'] = date("Y-m-d H:i:s");
|
|
// if($pd_details['pd_status'] == "" || $pd_details['pd_status'] == null)
|
|
// {
|
|
// $pd_details['pd_status'] = DRAFT;
|
|
// }
|
|
$pd_id = $this->PD_Model->saveRecords($pd_details,PDTRIGGER);
|
|
|
|
|
|
/***********************PD DOCUMENTS UPLOAD SECTION FROM WEB***********/
|
|
if($pd_id != null || $pd_id != '')
|
|
{
|
|
|
|
if(!empty($_FILES['pddocuments']) && !empty($pd_document_titles))
|
|
{
|
|
|
|
foreach($pd_document_titles as $iter => $title)
|
|
{
|
|
|
|
$tempdoc = $_FILES['pddocuments']['tmp_name'][$iter];
|
|
$tempdocname = $_FILES['pddocuments']['name'][$iter];
|
|
$bucketname = LENDER_BUCKET_NAME_PREFIX.$pd_details['fk_lender_id'];
|
|
$key = 'pd'.$pd_id.'/'.$tempdocname ;
|
|
$sourcefile = $tempdoc;
|
|
|
|
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile);
|
|
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
|
|
|
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
|
|
{
|
|
$record_data = array('fk_pd_id' => $pd_id,'pd_document_title'=>$title,'pd_document_name'=>$tempdocname);
|
|
$this->PD_Model->saveRecords($record_data,PDDOCUMENTS);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
/***********************END OF PD DOCUMENTS UPLOAD SECTION FROM WEB***********/
|
|
if($pd_id != null || $pd_id != '')
|
|
{
|
|
|
|
if(count($pd_applicant_details))
|
|
{
|
|
foreach($pd_applicant_details as $pd_applicant_detail)
|
|
{
|
|
$pd_applicant_detail['fk_pd_id'] = $pd_id;
|
|
$co_applicant_id = $this->PD_Model->saveRecords($pd_applicant_detail,PDAPPLICANTSDETAILS);
|
|
if($co_applicant_id != null || $co_applicant_id != '')
|
|
{
|
|
$count = $count + 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/***********************PD DOCUMENTS(base64 type) UPLOAD SECTION FROM MOBILE***********/
|
|
if($pd_id != null || $pd_id != '')
|
|
{
|
|
|
|
if(!empty($pd_document_from_mobile))
|
|
{
|
|
|
|
foreach($pd_document_from_mobile as $iter => $doc)
|
|
{
|
|
$temp_base64_string = $doc['image'];
|
|
$title = $doc['Name'];
|
|
$output_file = APPPATH."/docs/temp_base64_image.png";
|
|
|
|
//Generate Random File Name
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < 5; $i++) {
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
}
|
|
$temp_file_name = $randomString.date('Y-m-d-H:m:s').'.png';
|
|
|
|
|
|
$ifp = fopen( $output_file, 'wb' );
|
|
$temp_data = explode( ',', $temp_base64_string );
|
|
fwrite( $ifp, base64_decode( $temp_data[ 1 ] ) );
|
|
fclose( $ifp );
|
|
$tempdoc = $output_file;
|
|
$tempdocname = $temp_file_name;
|
|
$bucketname = LENDER_BUCKET_NAME_PREFIX.$pd_details['fk_lender_id'];
|
|
$key = 'pd'.$pd_id.'/'.$tempdocname ;
|
|
$sourcefile = $tempdoc;
|
|
|
|
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile);
|
|
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
|
|
|
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
|
|
{
|
|
$record_data = array('fk_pd_id' => $pd_id,'pd_document_title'=>$title,'pd_document_name'=>$tempdocname);
|
|
$this->PD_Model->saveRecords($record_data,PDDOCUMENTS);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
/***********************END OF PD DOCUMENTS(base64 type) UPLOAD SECTION FROM MOBILE***********/
|
|
|
|
|
|
/****************ADDTIONAL REQUIREMENTS SECTION*******************************************/
|
|
if($pd_id != null || $pd_id != '')
|
|
{
|
|
if(count($pd_addtional_requirements))
|
|
{
|
|
foreach($pd_addtional_requirements as $pd_addtional_requirement_key => $pd_addtional_requirement)
|
|
{
|
|
$pd_addtional_requirement['fk_pd_id'] = $pd_id;
|
|
$this->PD_Model->saveRecords($pd_addtional_requirement,PDADDTIONALREQUIREMENTS);
|
|
}
|
|
}
|
|
}
|
|
|
|
/****************END OF ADDTIONAL REQUIREMENTS SECTION*******************************************/
|
|
|
|
|
|
if($pd_id != null || $pd_id != '' && $count != 0)
|
|
{
|
|
// CALL pdnotification Helper function to send pd alerts @ params pdid,pdstatus
|
|
PDALERTS::pdnotification($pd_id);
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $pd_id;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
}
|
|
|
|
public function savePDAdditionalRequiremets_post()
|
|
{
|
|
$records = $this->post('records');
|
|
$pd_addtional_requirements = $records['addtional_requirements'];
|
|
$count = 0;
|
|
|
|
if(count($pd_addtional_requirements))
|
|
{
|
|
foreach($pd_addtional_requirements as $requirement_key => $pd_addtional_requirement)
|
|
{
|
|
if($pd_addtional_requirement['add_req_id'] != null || $pd_addtional_requirement['add_req_id'] != "")
|
|
{
|
|
$where_condition_array = array('add_req_id' => $pd_addtional_requirement['add_req_id']);
|
|
$pk_id = $this->PD_Model->updateRecords($pd_addtional_requirement,PDADDTIONALREQUIREMENTS,$where_condition_array);
|
|
if($pk_id != "" || $pk_id != null){ $count++; }
|
|
}
|
|
else
|
|
{
|
|
$pd_addtional_requirement['fk_pd_id'] = $records['pdid'];
|
|
$pk_id = $this->PD_Model->saveRecords($pd_addtional_requirement,PDADDTIONALREQUIREMENTS);
|
|
if($pk_id != "" || $pk_id != null){ $count++; }
|
|
}
|
|
}
|
|
}
|
|
if($count != 0 && $count == count($pd_addtional_requirements))
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = true;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = "Some thing went wrong";
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
*
|
|
*Update PD trigger Master Details(Web app only) from PD trigger Edit/view page
|
|
*/
|
|
public function updatePDMaster_post()
|
|
{
|
|
$pd_details = $this->post('records');
|
|
|
|
// OTP Generate Condition
|
|
if($pd_details['pd_status'] == INITIATED)
|
|
{
|
|
$msg = "Dear ".$pd_details['firstName'].", Officer ".$pd_details['officerName']." is on his way to meet you for a personal discussion with regards to your loan application. You can track his realtime location in this link.http://maps.google.com/?q=".$pd_details['link'];
|
|
$no = (string)$pd_details['mobile_no'];
|
|
unset($pd_details['mobile_no']);
|
|
unset($pd_details['firstName']);
|
|
unset($pd_details['officerName']);
|
|
unset($pd_details['link']);
|
|
$this->aws_sns->sendSMS($msg,$no);
|
|
|
|
}
|
|
if($pd_details['pd_status'] == STARTED)
|
|
{
|
|
$string2 = str_shuffle('1234567890');
|
|
$OTP = substr($string2,0,6);
|
|
$msg = "Code for starting your personal discussions with the verification officer is ".$OTP .". Pls share this only when the officer has reached your place in person";
|
|
$no = (string)$pd_details['mobile_no'];
|
|
unset($pd_details['mobile_no']);
|
|
$pd_details['OTP'] = $OTP;
|
|
$this->aws_sns->sendSMS($msg,$no);
|
|
|
|
}
|
|
|
|
|
|
if($pd_details['pd_status'] == TRIGGERED)
|
|
{
|
|
// Template Re assign Functionality
|
|
|
|
$fields = array('fk_lender_id','fk_product_id','fk_customer_segment','pd_status');
|
|
$where_condition_array = array('pd_id'=>$pd_details['pd_id']);
|
|
$res_array = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDTRIGGER);
|
|
|
|
/***********************CHOOSE PD TEMPALATE*********************/
|
|
|
|
if(count($res_array))
|
|
{
|
|
|
|
if($res_array[0]['pd_status'] == TRIGGERED || $res_array[0]['pd_status'] == DRAFT)
|
|
{
|
|
$fields = array('fk_template_id');
|
|
|
|
$where_condition_array = array('fk_lender_id'=>$res_array[0]['fk_lender_id'] ,'fk_product_id'=> $res_array[0]['fk_product_id'],'fk_customer_segment'=> $res_array[0]['fk_customer_segment'],'isactive' => 1);
|
|
|
|
$table = LENDERTEMPLATE;
|
|
|
|
$choosed_template_id = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,$table);
|
|
|
|
if(count($choosed_template_id))
|
|
{
|
|
$pd_details['fk_pd_template_id'] = $choosed_template_id[0]['fk_template_id'];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
unset($pd_details['pd_status']);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$where_condition_array = array('pd_id' => $pd_details['pd_id']);
|
|
$pd_id_modified = $this->PD_Model->updateRecords($pd_details,PDTRIGGER,$where_condition_array);
|
|
|
|
if($pd_id_modified != null || $pd_id_modified != '' && $count != 0)
|
|
{
|
|
PDALERTS::pdnotification($pd_details['pd_id']);
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = true;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Pd Discussion OTP Checking function
|
|
* sriram
|
|
*/
|
|
|
|
public function checkOTP_post()
|
|
{
|
|
$pdotp = $this->post('records');
|
|
|
|
$pdotpStatus = $this->PD_Model->checkotp($pdotp);
|
|
|
|
$pdotpStatus = $this->PD_Model->checkotp($pdotp);
|
|
$updatePd['pd_id'] = $pdotp['pd_id'];
|
|
$updatePd['pd_status'] = INPROGRESS;
|
|
$updatePd['fk_updatedby'] = $pdotp['pd_id'];
|
|
$updatePd['updatedon'] = date('Y-m-d h:m:00');
|
|
|
|
if($pdotpStatus != 0 || $pdotpStatus != '' && count($pdotpStatus) != 0)
|
|
{
|
|
$where_condition_array = array('pd_id' => $pdotp['pd_id']);
|
|
$pd_id_modified = $this->PD_Model->updateRecords($updatePd,PDTRIGGER,$where_condition_array);
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = true;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
|
|
/*
|
|
*
|
|
*Update PD trigger Applicats Details(Web app only) from PD trigger Edit/view page
|
|
*/
|
|
public function updatePDApplicants_post()
|
|
{
|
|
$pd_applicant_details = $this->post('pd_applicant_details');
|
|
$count = 0;
|
|
$pd_id = 0;
|
|
//print_r($this->post());die();
|
|
foreach($pd_applicant_details as $pd_applicant_detail)
|
|
{
|
|
if($pd_applicant_detail['pd_co_applicant_id'] != null || $pd_applicant_detail['pd_co_applicant_id'] != "")
|
|
{
|
|
//$pd_id = $pd_applicant_detail['fk_pd_id'];
|
|
$where_condition_array = array('pd_co_applicant_id' => $pd_applicant_detail['pd_co_applicant_id']);
|
|
$co_applicant_id = $this->PD_Model->updateRecords($pd_applicant_detail,PDAPPLICANTSDETAILS,$where_condition_array);
|
|
if($co_applicant_id != null || $co_applicant_id != '')
|
|
{
|
|
$count = $count + 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//$pd_applicant_detail['fk_pd_id'] = $pd_id;
|
|
$co_applicant_id = $this->PD_Model->saveRecords($pd_applicant_detail,PDAPPLICANTSDETAILS);
|
|
if($co_applicant_id != null || $co_applicant_id != '')
|
|
{
|
|
$count = $count + 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
if($count != 0 && count($pd_applicant_details) == $count)
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = true;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
*
|
|
*delete single PD Document - delete form table entry and S3 obj
|
|
*/
|
|
public function deletePDDoc_post()
|
|
{
|
|
$pd_document_details = $this->post('pd_document_details');
|
|
|
|
if(count($pd_document_details))
|
|
{
|
|
//Select lender_id userin pdid
|
|
$pdid = $pd_document_details[0]['fk_pd_id'];
|
|
$fields = array('fk_lender_id');
|
|
$where_condition_array = array('pd_id' => $pdid);
|
|
$lender_id = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDTRIGGER);
|
|
|
|
$bucketname = LENDER_BUCKET_NAME_PREFIX.$lender_id[0]['fk_lender_id'];
|
|
$key = 'pd'.$pd_document_details[0]['fk_pd_id'].'/'.$pd_document_details[0]['pd_document_name'];
|
|
$this->aws_s3->deleteSingleObjFromBucket($bucketname,$key);
|
|
|
|
//delete old entry
|
|
$modified = $this->db->where('pd_document_id',$pdid)->$this->db->delete(PDDOCUMENTS);
|
|
if($modified)
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = true;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
*
|
|
*Update PD Documents details from PD Trigger(Web application only) edit/view page
|
|
*/
|
|
public function updatePDDocs_post()
|
|
{
|
|
|
|
|
|
$pd_document_titles = json_decode($this->post('pd_document_titles'),true);
|
|
if(count($pd_document_titles))
|
|
{
|
|
//Get Lender id from PD Master
|
|
$pdid = $pd_document_titles[0]['fk_pd_id'];
|
|
$fields = array('fk_lender_id');
|
|
$where_condition_array = array('pd_id' => $pdid);
|
|
$lender_id = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDTRIGGER);
|
|
foreach($pd_document_titles as $iter => $doc)
|
|
{
|
|
if($doc['pd_document_id'] != null || $doc['pd_document_id'] != '')
|
|
{
|
|
|
|
$tempdoc = $_FILES['pddocuments']['tmp_name'][$iter];
|
|
$tempdocname = $_FILES['pddocuments']['name'][$iter];
|
|
$bucketname = LENDER_BUCKET_NAME_PREFIX.$lender_id[0]['fk_lender_id'];
|
|
$key = 'pd'.$doc['fk_pd_id'].'/'.$tempdocname ;
|
|
$sourcefile = $tempdoc;
|
|
|
|
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile);
|
|
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
|
|
|
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
|
|
{
|
|
|
|
//delete old doc from s3 bucket_data
|
|
$fields = array('pd_document_name');
|
|
$where_condition_array1 = array('pd_document_id' => $doc['pd_document_id']);
|
|
$old_doc_name = $this->PD_Model->selectCustomRecords($fields,$where_condition_array1,PDDOCUMENTS);
|
|
|
|
if($old_doc_name != "" || $old_doc_name != null)
|
|
{
|
|
$key = 'pd'.$doc['fk_pd_id'].'/'.$old_doc_name[0]['pd_document_name'];
|
|
$this->aws_s3->deleteSingleObjFromBucket($bucketname,$key);
|
|
}
|
|
|
|
//Update entry in PD Doc table
|
|
$record_data = array('pd_document_name'=>$tempdocname);
|
|
$where_condition_array = array('pd_document_id' => $doc['pd_document_id']);
|
|
$this->PD_Model->updateRecords($record_data,PDDOCUMENTS,$where_condition_array);
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
$tempdoc = $_FILES['pddocuments']['tmp_name'][$iter];
|
|
$tempdocname = $_FILES['pddocuments']['name'][$iter];
|
|
$bucketname = LENDER_BUCKET_NAME_PREFIX.$lender_id;
|
|
$key = 'pd'.$doc['fk_pd_id'].'/'.$tempdocname ;
|
|
$sourcefile = $tempdoc;
|
|
|
|
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile);
|
|
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
|
|
|
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
|
|
{
|
|
$record_data = array('fk_pd_id' => $pdid,'pd_document_title'=>$doc['pd_document_title'],'pd_document_name'=>$tempdocname);
|
|
$this->PD_Model->saveRecords($record_data,PDDOCUMENTS);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = true;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
*Allocate PD to Some PD officer
|
|
*/
|
|
public function allocatePD_post()
|
|
{
|
|
$records = $this->post('records');
|
|
|
|
//if($records['fk_pd_allocated_to'] != "" || $records['fk_pd_allocated_to'] != null)
|
|
//{
|
|
$records['pd_status'] = ALLOCATED;
|
|
//}
|
|
$where_condition_array = array('pd_id' => $records['pd_id']);
|
|
$pd_id_modified = $this->PD_Model->updateRecords($records,PDTRIGGER,$where_condition_array);
|
|
|
|
// $where_condition_array = array('fk_user_id' => $records['fk_pd_allocated_to']);
|
|
// $temp_array = array('');
|
|
// $pd_id_modified = $this->PD_Model->updateRecords($records,PDTRIGGER,$where_condition_array);
|
|
|
|
if($pd_id_modified != "" || $pd_id_modified != null)
|
|
{
|
|
PDALERTS::pdnotification($records['pd_id']);
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = true;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'Not Updated! Try Later';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
*Schedule PD by PD officer(only on Manual Schedule)
|
|
*/
|
|
public function schdulePD_post()
|
|
{
|
|
$records = $this->post('records');
|
|
if($records['schedule_time'] != "" || $records['schedule_time'] != null)
|
|
{
|
|
//$id = $this->PD_Model->saveRecords($records,PDSCHEDULE);
|
|
|
|
$where_condition_array = array('pd_id' => $records['fk_pd_id']);
|
|
$temp_array = array('pd_status' => SCHEDULED,'fk_updatedby'=>$records['fk_scheduled_by'],'updatedon'=>date('Y-m-d H:m:i'),'scheduled_on'=>$records['schedule_time']);
|
|
$pd_id_modified = $this->PD_Model->updateRecords($temp_array,PDTRIGGER,$where_condition_array);
|
|
|
|
/******* Code Snippt for Save Template Category Weightage info to PD category Info*/
|
|
$fields = array('fk_pd_template_id');
|
|
$where_condition_array = array('pd_id'=>$records['fk_pd_id']);
|
|
$res_array = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDTRIGGER);
|
|
|
|
if(count($res_array))
|
|
{
|
|
$fields = array('fk_pd_template_id');
|
|
$where_condition_array = array('pd_id'=>$records['fk_pd_id']);
|
|
$res_array = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDTRIGGER);
|
|
|
|
if(count($res_array))
|
|
{
|
|
$template_id = $res_array[0]['fk_pd_template_id'];
|
|
|
|
$fields = array('fk_question_category_id','weightage');
|
|
$where_condition_array = array('fk_template_id'=>$template_id);
|
|
$template_categories = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATECATEGORYWEIGHTAGE);
|
|
|
|
foreach($template_categories as $key => $category)
|
|
{
|
|
$temp_data = array('fk_pd_id'=>$records['fk_pd_id'],'fk_category_id'=>$category['fk_question_category_id'],'pd_category_weightage'=>$category['weightage']);
|
|
$this->PD_Model->saveRecords($temp_data,PDCATEGORYWEIGHTAGE);
|
|
}
|
|
}
|
|
}
|
|
/******* End of Code Snippt Save Template Category Weightage info to PD category Info*/
|
|
|
|
|
|
if($pd_id_modified != "" || $pd_id_modified != null)
|
|
{
|
|
PDALERTS::pdnotification($records['fk_pd_id']);
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = true;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'Not Updated! Try Later';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
*GET List of PD officers for PD edit/view page for manual allocation
|
|
*@param pd
|
|
*/
|
|
public function getListPDOfficers_post()
|
|
{
|
|
|
|
$pdid = $this->post('pdid');
|
|
//1.Get LenderID and CityID by using pdid
|
|
$fields = array('fk_lender_id','fk_city','fk_pd_type','fk_product_id','fk_customer_segment');
|
|
$where_condition_array = array('pd_id'=>$pdid);
|
|
$res_array = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDTRIGGER);
|
|
//print_r($res_array);
|
|
//2.Get Team ID based on Lender ID
|
|
if(count($res_array))
|
|
{
|
|
$where_condition_array = array('lender_id' => $res_array[0]['fk_lender_id'],'city_id' =>$res_array[0]['fk_city'] ,'cs_id' =>$res_array[0]['fk_customer_segment'] ,'product_id' =>$res_array[0]['fk_product_id']);
|
|
$temp_city_id = $this->PD_Model->selectRecords(PDTEAM_CTY_PRODUCT_CS_COMBINATIONS,$where_condition_array,$limit=0,$offset=0);
|
|
//print_r($temp_city_id);die();
|
|
if(count($temp_city_id))
|
|
{
|
|
if(isset($temp_city_id[0]['team_type']))
|
|
{
|
|
if($temp_city_id[0]['team_type'] == 0) // Allocate to Vendor
|
|
{
|
|
// $pd_details['pd_agency_id'] = $temp_city_id[0]['fk_team_id'];
|
|
// $pd_details['fk_pd_allocated_to'] = ALLOCATED_TO_PARTNER;
|
|
|
|
}
|
|
else //Allocate to SineEdge Team with allocation logics
|
|
{
|
|
|
|
//select list of pd officers based on pd type, product, customer segment, and team from table (t_pd_officiers_details) and choose minimun allocated one and assign pd Officer and change status form TRIGGERED to ALLOCATED
|
|
$fields = array('fk_user_id','fk_pd_type_id');
|
|
|
|
$where_condition_array = array('fk_team_id' => $temp_city_id[0]['pdteam_id'],'isactive' => 1);
|
|
|
|
$list_of_pd_officers = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDOFFICIERSDETAILS);
|
|
|
|
if(count($list_of_pd_officers))
|
|
{
|
|
foreach($list_of_pd_officers as $key => $pdofficer)
|
|
{
|
|
$this->db->SELECT('USERPROFILE.first_name,USERPROFILE.last_name,USERPROFILE.profilepic,USERPROFILE.mobile_no');
|
|
$this->db->FROM(USERPROFILE.' as USERPROFILE');
|
|
$this->db->WHERE('USERPROFILE.userid',$pdofficer['fk_user_id']);
|
|
$names = $this->db->GET()->result_array();
|
|
if(count($names)){
|
|
|
|
|
|
$list_of_pd_officers[$key]['first_name'] = $names[0]['first_name'];
|
|
$list_of_pd_officers[$key]['last_name'] = $names[0]['last_name'];
|
|
$list_of_pd_officers[$key]['mobile_no'] = $names[0]['mobile_no'];
|
|
$list_of_pd_officers[$key]['count'] = 0;
|
|
|
|
$this->db->SELECT('pd_id,pd_status,fk_pd_type,DATE_FORMAT(PDTRIGGER.scheduled_on,"%d/%m/%Y %H:%i:%s %p") as scheduled_on,PDAPPLICANTSDETAILS.applicant_name,PDTYPE.type_name as pd_type_name,PDTRIGGER.addressline1,PDTRIGGER.addressline2,PDTRIGGER.addressline3,PDTRIGGER.fk_city,CITY.name as city_name,PDTRIGGER.fk_state,STATE.name as state_name,PDTRIGGER.pincode');
|
|
$this->db->FROM(PDTRIGGER.' as PDTRIGGER');
|
|
$this->db->JOIN(PDAPPLICANTSDETAILS.' as PDAPPLICANTSDETAILS','PDTRIGGER.pd_id = PDAPPLICANTSDETAILS.fk_pd_id AND PDAPPLICANTSDETAILS.applicant_type = 1');
|
|
$this->db->JOIN(PDTYPE.' as PDTYPE','PDTRIGGER.fk_pd_type = PDTYPE.pd_type_id AND PDTYPE.isactive = 1');
|
|
$this->db->JOIN(STATE.' as STATE','PDTRIGGER.fk_state = STATE.state_id ','LEFT');
|
|
$this->db->JOIN(CITY.' as CITY','PDTRIGGER.fk_city = CITY.city_id','LEFT');
|
|
|
|
$this->db->OR_GROUP_START();
|
|
$this->db->OR_WHERE('PDTRIGGER.pd_status',SCHEDULED);
|
|
$this->db->OR_WHERE('PDTRIGGER.pd_status',INPROGRESS);
|
|
$this->db->OR_WHERE('PDTRIGGER.pd_status',ALLOCATED);
|
|
$this->db->GROUP_END();
|
|
if($pdofficer['fk_pd_type_id'] == 1)
|
|
{
|
|
$this->db->WHERE('PDTRIGGER.fk_pd_allocated_to',$pdofficer['fk_user_id']);
|
|
}
|
|
else
|
|
{
|
|
$this->db->WHERE('PDTRIGGER.executive_id',$pdofficer['fk_user_id']);
|
|
}
|
|
$pd_count = $this->db->GET()->result_array();
|
|
//print_r($this->db->last_query());
|
|
if(count($pd_count)){
|
|
$list_of_pd_officers[$key]['pd_details'] = $pd_count;
|
|
$list_of_pd_officers[$key]['count'] =count($pd_count); }
|
|
|
|
// Get Profile Pic from S3
|
|
|
|
$bucket_name = PROFILE_PICTURE_BUCKET_NAME;
|
|
$profilepics3path = 'sineedge/'.$names[0]['profilepic'];
|
|
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$profilepics3path,'+10 minutes');
|
|
$list_of_pd_officers[$key]['profile_url'] = $singed_uri;
|
|
}
|
|
}
|
|
// Get Central PD Officers List
|
|
$central_pd_officers = array();
|
|
if($res_array[0]['fk_pd_type'] == 2 || $res_array[0]['fk_pd_type'] == 3)
|
|
{
|
|
$this->db->SELECT('USERPROFILE.userid as fk_user_id,USERPROFILE.first_name,USERPROFILE.last_name,USERPROFILE.profilepic,USERPROFILE.mobile_no,USERPROFILEROLES.user_role,ROLES.role_name');
|
|
$this->db->FROM(USERPROFILE.' as USERPROFILE');
|
|
$this->db->JOIN(USERPROFILEROLES.' as USERPROFILEROLES','USERPROFILE.userid = USERPROFILEROLES.fk_userid');
|
|
$this->db->JOIN(ROLES.' as ROLES','USERPROFILEROLES.user_role = ROLES.role_id');
|
|
$this->db->WHERE('ROLES.role_id',2);
|
|
$central_pd_officers = $this->db->GET()->result_array();
|
|
//print_r($central_pd_officers);
|
|
if(count($central_pd_officers))
|
|
{
|
|
foreach($central_pd_officers as $k => $central_pd_officer)
|
|
{
|
|
|
|
//Get PD Details assigned to Central Officers
|
|
$this->db->SELECT('pd_id,pd_status,fk_pd_type,DATE_FORMAT(PDTRIGGER.scheduled_on,"%d/%m/%Y %H:%i:%s %p") as scheduled_on,PDAPPLICANTSDETAILS.applicant_name,PDTYPE.type_name as pd_type_name,PDTRIGGER.addressline1,PDTRIGGER.addressline2,PDTRIGGER.addressline3,PDTRIGGER.fk_city,CITY.name as city_name,PDTRIGGER.fk_state,STATE.name as state_name,PDTRIGGER.pincode');
|
|
$this->db->FROM(PDTRIGGER.' as PDTRIGGER');
|
|
$this->db->JOIN(PDAPPLICANTSDETAILS.' as PDAPPLICANTSDETAILS','PDTRIGGER.pd_id = PDAPPLICANTSDETAILS.fk_pd_id AND PDAPPLICANTSDETAILS.applicant_type = 1');
|
|
$this->db->JOIN(PDTYPE.' as PDTYPE','PDTRIGGER.fk_pd_type = PDTYPE.pd_type_id AND PDTYPE.isactive = 1');
|
|
$this->db->JOIN(STATE.' as STATE','PDTRIGGER.fk_state = STATE.state_id ','LEFT');
|
|
$this->db->JOIN(CITY.' as CITY','PDTRIGGER.fk_city = CITY.city_id','LEFT');
|
|
|
|
$this->db->OR_GROUP_START();
|
|
$this->db->OR_WHERE('PDTRIGGER.pd_status',SCHEDULED);
|
|
$this->db->OR_WHERE('PDTRIGGER.pd_status',INPROGRESS);
|
|
$this->db->OR_WHERE('PDTRIGGER.pd_status',ALLOCATED);
|
|
$this->db->GROUP_END();
|
|
$this->db->WHERE('PDTRIGGER.central_pd_officer_id',$central_pd_officer['fk_user_id']);
|
|
$pd_count = $this->db->GET()->result_array();
|
|
//print_r($this->db->last_query());
|
|
$central_pd_officers[$k]['count'] = 0;
|
|
if(count($pd_count)){
|
|
$central_pd_officers[$k]['pd_details'] = $pd_count;
|
|
$central_pd_officers[$k]['count'] = count($pd_count); }
|
|
//End Get PD Details assigned to Central Officers
|
|
|
|
|
|
$bucket_name = PROFILE_PICTURE_BUCKET_NAME;
|
|
$profilepics3path = 'sineedge/'.$central_pd_officer['profilepic'];
|
|
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$profilepics3path,'+10 minutes');
|
|
$central_pd_officers[$k]['profile_url'] = $singed_uri;
|
|
}
|
|
}
|
|
}
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = array('pdofficers' => $list_of_pd_officers,'centralpdofficers' => $central_pd_officers);
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'Officers Records Not Found!';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
else // Find Officers in General Team
|
|
{
|
|
|
|
|
|
|
|
//Find General Team ID
|
|
$fields = array('pdteam_id');
|
|
$where_condition_array = array('team_name' => "General");
|
|
$general_team_id = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDTEAM);
|
|
|
|
if(count($general_team_id))
|
|
{
|
|
|
|
|
|
$fields = array('fk_user_id','fk_pd_type_id');
|
|
$where_condition_array = array('fk_team_id' => $general_team_id[0]['pdteam_id'],'isactive' => 1);
|
|
$list_of_pd_officers = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDOFFICIERSDETAILS);
|
|
|
|
if(count($list_of_pd_officers))
|
|
{
|
|
foreach($list_of_pd_officers as $key => $pdofficer)
|
|
{
|
|
$this->db->SELECT('USERPROFILE.first_name,USERPROFILE.last_name,USERPROFILE.profilepic,USERPROFILE.mobile_no');
|
|
$this->db->FROM(USERPROFILE.' as USERPROFILE');
|
|
$this->db->WHERE('USERPROFILE.userid',$pdofficer['fk_user_id']);
|
|
$names = $this->db->GET()->result_array();
|
|
|
|
|
|
if(count($names)){
|
|
$list_of_pd_officers[$key]['first_name'] = $names[0]['first_name'];
|
|
$list_of_pd_officers[$key]['last_name'] = $names[0]['last_name'];
|
|
$list_of_pd_officers[$key]['mobile_no'] = $names[0]['mobile_no'];
|
|
$list_of_pd_officers[$key]['count'] = 0;
|
|
|
|
$this->db->SELECT('pd_id,pd_status,fk_pd_type,DATE_FORMAT(PDTRIGGER.scheduled_on,"%d/%m/%Y %H:%i:%s %p") as scheduled_on,PDAPPLICANTSDETAILS.applicant_name,PDTYPE.type_name as pd_type_name,PDTRIGGER.addressline1,PDTRIGGER.addressline2,PDTRIGGER.addressline3,PDTRIGGER.fk_city,CITY.name as city_name,PDTRIGGER.fk_state,STATE.name as state_name,PDTRIGGER.pincode');
|
|
$this->db->FROM(PDTRIGGER.' as PDTRIGGER');
|
|
$this->db->JOIN(PDAPPLICANTSDETAILS.' as PDAPPLICANTSDETAILS','PDTRIGGER.pd_id = PDAPPLICANTSDETAILS.fk_pd_id AND PDAPPLICANTSDETAILS.applicant_type = 1');
|
|
$this->db->JOIN(PDTYPE.' as PDTYPE','PDTRIGGER.fk_pd_type = PDTYPE.pd_type_id AND PDTYPE.isactive = 1');
|
|
$this->db->JOIN(STATE.' as STATE','PDTRIGGER.fk_state = STATE.state_id ','LEFT');
|
|
$this->db->JOIN(CITY.' as CITY','PDTRIGGER.fk_city = CITY.city_id','LEFT');
|
|
$this->db->OR_GROUP_START();
|
|
$this->db->OR_WHERE('PDTRIGGER.pd_status',SCHEDULED);
|
|
$this->db->OR_WHERE('PDTRIGGER.pd_status',INPROGRESS);
|
|
$this->db->OR_WHERE('PDTRIGGER.pd_status',ALLOCATED);
|
|
$this->db->GROUP_END();
|
|
if($pdofficer['fk_pd_type_id'] == 1)
|
|
{
|
|
$this->db->WHERE('PDTRIGGER.fk_pd_allocated_to',$pdofficer['fk_user_id']);
|
|
}
|
|
else
|
|
{
|
|
$this->db->WHERE('PDTRIGGER.executive_id',$pdofficer['fk_user_id']);
|
|
}
|
|
$pd_count = $this->db->GET()->result_array();
|
|
//print_r($this->db->last_query());
|
|
if(count($pd_count)){
|
|
$list_of_pd_officers[$key]['pd_details'] = $pd_count;
|
|
$list_of_pd_officers[$key]['count'] =count($pd_count);
|
|
}
|
|
|
|
// Get Profile Pic from S3
|
|
|
|
$bucket_name = PROFILE_PICTURE_BUCKET_NAME;
|
|
$profilepics3path = 'sineedge/'.$names[0]['profilepic'];
|
|
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$profilepics3path,'+10 minutes');
|
|
$list_of_pd_officers[$key]['profile_url'] = $singed_uri;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
// Get Central PD Officers List
|
|
$central_pd_officers = array();
|
|
if($res_array[0]['fk_pd_type'] == 2 || $res_array[0]['fk_pd_type'] == 3)
|
|
{
|
|
$this->db->SELECT('USERPROFILE.userid as fk_user_id,USERPROFILE.first_name,USERPROFILE.last_name,USERPROFILE.profilepic,USERPROFILE.mobile_no,USERPROFILEROLES.user_role,ROLES.role_name');
|
|
$this->db->FROM(USERPROFILE.' as USERPROFILE');
|
|
$this->db->JOIN(USERPROFILEROLES.' as USERPROFILEROLES','USERPROFILE.userid = USERPROFILEROLES.fk_userid');
|
|
$this->db->JOIN(ROLES.' as ROLES','USERPROFILEROLES.user_role = ROLES.role_id');
|
|
$this->db->WHERE('ROLES.role_id',2);
|
|
$central_pd_officers = $this->db->GET()->result_array();
|
|
|
|
if(count($central_pd_officers))
|
|
{
|
|
foreach($central_pd_officers as $k => $central_pd_officer)
|
|
{
|
|
|
|
|
|
//Get PD Details assigned to Central Officers
|
|
$this->db->SELECT('pd_id,pd_status,fk_pd_type,DATE_FORMAT(PDTRIGGER.scheduled_on,"%d/%m/%Y %H:%i:%s %p") as scheduled_on,PDAPPLICANTSDETAILS.applicant_name,PDTYPE.type_name as pd_type_name,PDTRIGGER.addressline1,PDTRIGGER.addressline2,PDTRIGGER.addressline3,PDTRIGGER.fk_city,CITY.name as city_name,PDTRIGGER.fk_state,STATE.name as state_name,PDTRIGGER.pincode');
|
|
$this->db->FROM(PDTRIGGER.' as PDTRIGGER');
|
|
$this->db->JOIN(PDAPPLICANTSDETAILS.' as PDAPPLICANTSDETAILS','PDTRIGGER.pd_id = PDAPPLICANTSDETAILS.fk_pd_id AND PDAPPLICANTSDETAILS.applicant_type = 1');
|
|
$this->db->JOIN(PDTYPE.' as PDTYPE','PDTRIGGER.fk_pd_type = PDTYPE.pd_type_id AND PDTYPE.isactive = 1');
|
|
$this->db->JOIN(STATE.' as STATE','PDTRIGGER.fk_state = STATE.state_id ','LEFT');
|
|
$this->db->JOIN(CITY.' as CITY','PDTRIGGER.fk_city = CITY.city_id','LEFT');
|
|
|
|
$this->db->OR_GROUP_START();
|
|
$this->db->OR_WHERE('PDTRIGGER.pd_status',SCHEDULED);
|
|
$this->db->OR_WHERE('PDTRIGGER.pd_status',INPROGRESS);
|
|
$this->db->OR_WHERE('PDTRIGGER.pd_status',ALLOCATED);
|
|
$this->db->GROUP_END();
|
|
$this->db->WHERE('PDTRIGGER.central_pd_officer_id',$central_pd_officer['fk_user_id']);
|
|
$pd_count = $this->db->GET()->result_array();
|
|
//print_r($this->db->last_query());
|
|
$central_pd_officers[$k]['count'] = 0;
|
|
if(count($pd_count)){
|
|
$central_pd_officers[$k]['pd_details'] = $pd_count;
|
|
$central_pd_officers[$k]['count'] = count($pd_count); }
|
|
//End Get PD Details assigned to Central Officers
|
|
|
|
|
|
$bucket_name = PROFILE_PICTURE_BUCKET_NAME;
|
|
$profilepics3path = 'sineedge/'.$central_pd_officer['profilepic'];
|
|
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$profilepics3path,'+10 minutes');
|
|
$central_pd_officers[$k]['profile_url'] = $singed_uri;
|
|
}
|
|
}
|
|
}
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = array('pdofficers' => $list_of_pd_officers,'centralpdofficers' => $central_pd_officers);
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'Officers Records Not Found in General Team!';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'General Team Not Found';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'PD Master Records Not Found!';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
|
|
/* PD_Triggerd and PD_Co_Applocants Details only for Listing Page
|
|
@param page/offset
|
|
@param limit
|
|
@param sorting order(ASC/DESC)
|
|
@param cid for category_id for filter question with category wise.
|
|
*/
|
|
public function listLessPDDetails_get()
|
|
{
|
|
$page = 0;$limit = 100;$sort = 'DESC';$pdofficerid = "";$datetype = "";$fdate ="";$tdate ="";
|
|
$lenderid = "";$status="";
|
|
if($this->get('page')) { $page = $this->get('page'); }
|
|
if($this->get('limit')){ $limit = $this->get('limit'); }
|
|
if($this->get('sort')) { $sort = $this->get('sort'); }
|
|
if($this->get('pdofficerid')) { $pdofficerid = $this->get('pdofficerid'); }
|
|
if($this->get('lenderid')) { $lenderid = $this->get('lenderid'); }
|
|
if($this->get('datetype')) { $datetype = $this->get('datetype'); }
|
|
if($this->get('fdate')) { $fdate = $this->get('fdate'); }
|
|
if($this->get('tdate')) { $tdate = $this->get('tdate'); }
|
|
if($this->get('status')) { $status = $this->get('status'); }
|
|
|
|
$result_data = $this->PD_Model->listLessPDDetails($page,$limit,$sort,$pdofficerid,$datetype,$fdate,$tdate,$lenderid,$status);
|
|
|
|
if($result_data['data_status'] == true)
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $result_data['data'];
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public function filterPDList_post()
|
|
{
|
|
//echo "Hi";
|
|
$records = $this->post('records');
|
|
//print_r($this->post('records'));die();
|
|
$pd_type = $records['pd_type'];
|
|
//print_r($pd_type);die();
|
|
$pd_status = $records['pd_status'];
|
|
$pd_from_date = $records['pd_from_date'];
|
|
$pd_to_date = $records['pd_to_date'];
|
|
$pd_city = $records['pd_city'];
|
|
$pd_products = $records['pd_products'];
|
|
$pd_lender = $records['pd_lender'];
|
|
$pd_applicant_name = $records['pd_name'];
|
|
$pd_applicant_lender_ref = $records['pd_applicant_id'];
|
|
$result_data = $this->PD_Model->PDListwithGlobalFilters($pd_type,$pd_status,$pd_from_date,$pd_to_date,$pd_city,$pd_products,$pd_lender,$pd_applicant_name,$pd_applicant_lender_ref);
|
|
|
|
if(count($result_data))
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $result_data;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
* Get Full PD Details like all applicant's details, all PD related documents, PD Template and
|
|
* answersd questions,PD History details.
|
|
*/
|
|
public function getFullPDDetails_post()
|
|
{
|
|
$pdid = $this->post('pdid');
|
|
|
|
// Get All PD Masters Details
|
|
$result_data['pd_master_details'] = $this->PD_Model->getPDMasterDetails($pdid);
|
|
|
|
// Get All Applicant's Details
|
|
$result_data['applicants_details'] = $this->PD_Model->getApplicantsDetails($pdid);
|
|
|
|
// Get All PD Related Documents
|
|
$result_data['pd_documnets'] = $this->PD_Model->getSignedPDDocsURL($pdid);
|
|
|
|
//Get All PD Template and It's Question with Answers
|
|
$result_data['pd_question_answer'] = $this->PD_Model->getPDQuestionAnswers($pdid);
|
|
|
|
//Get Addtional Requirements details
|
|
$result_data['pd_additional_requirements'] = $this->PD_Model->getPDAdditionalRequirements($pdid);
|
|
|
|
//Get All PD Logs
|
|
$result_data['pd_logs'] = $this->PD_Model->getPDLogs($pdid);
|
|
//print_r($result_data['pd_logs']);die();
|
|
$applicant_msg = '';
|
|
$pd_docs_msg = '';
|
|
$pd_question_answer_msg = '';
|
|
$pd_logs_msg = '';
|
|
|
|
if(!count($result_data['applicants_details']))
|
|
{
|
|
$applicant_msg = 'Applicant Details Not Found';
|
|
}
|
|
|
|
if(!count($result_data['pd_documnets']))
|
|
{
|
|
$pd_docs_msg = 'Documents Not Found';
|
|
}
|
|
|
|
if(!count($result_data['pd_question_answer']))
|
|
{
|
|
$pd_question_answer_msg = 'PD Details Not Found';
|
|
}
|
|
|
|
if(!count($result_data['pd_logs']['master']) || !count($result_data['pd_logs']['child']))
|
|
{
|
|
$pd_logs_msg = 'PD Logs Not Found';
|
|
}
|
|
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $result_data;
|
|
$data['msg'] = array('applicant_msg'=>$applicant_msg,'pd_docs_msg'=>$pd_docs_msg,'pd_question_answer_msg'=>$pd_question_answer_msg,'pd_logs_msg'=>$pd_logs_msg);
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
|
|
|
|
}
|
|
|
|
/******** for Load Whole PD Template for PD Screen @param template_id***************/
|
|
public function loadFullTemplate_get()
|
|
{
|
|
$pd_id = "";
|
|
$client = "";
|
|
if($this->get('pd_id')) { $pd_id = $this->get('pd_id'); }
|
|
if($this->get('client')) { $client = $this->get('client'); }
|
|
if($pd_id != "" || $pd_id != null)
|
|
{
|
|
|
|
$template_details = $this->PD_Model->getTemplateForPD($pd_id,$client);
|
|
if(count($template_details))
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $template_details;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'Template Not for PD ID'.$pd_id;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_BAD_REQUEST;
|
|
$data['msg'] = 'No Param Available';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
|
|
/******** Save Multiple/Single PD qustions ********/
|
|
public function saveActualPDQuestions_post()
|
|
{
|
|
//$records = json_decode($this->post('records'),true);
|
|
//echo "hi";
|
|
$records = $this->post('records');
|
|
$pd_detail_id = "";
|
|
$pd_detail_answer_id = "";
|
|
$image_count = "";
|
|
$answer_count = "";
|
|
$images_array = array();
|
|
$answers_array = array();
|
|
|
|
foreach($records as $record_key => $record)
|
|
{
|
|
|
|
if($record['pd_detail_id'] != "" || $record['pd_detail_id'] != null)
|
|
{
|
|
|
|
if($record['answers'] != "" || $record['answers'] != null)
|
|
{
|
|
$answers_array = $record['answers'];
|
|
unset($record['answers']);
|
|
}
|
|
|
|
if($record['images'] != "" || $record['images'] != null)
|
|
{
|
|
$images_array = $record['images'];
|
|
unset($record['images']);
|
|
}
|
|
|
|
$where_condition_array = array('pd_detail_id' => $record['pd_detail_id']);
|
|
$pd_detail_id = $this->PD_Model->updateRecords($record,PDDETAIL,$where_condition_array);
|
|
|
|
// ANSWERS SAVE - pd_detail_answer_id, fk_pd_id, fk_pd_detail_id, pd_answer_id, pd_answer, pd_answer_weightage, pd_answer_remark
|
|
if(count($answers_array))
|
|
{
|
|
|
|
|
|
//Deactivate Old Answers
|
|
$fields = array('pd_detail_answer_id');
|
|
$where_condition_array = array('fk_pd_id' => $record['fk_pd_id'],'fk_pd_detail_id' => $record['pd_detail_id']);
|
|
$old_answers = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDANSWER);
|
|
foreach($old_answers as $old)
|
|
{
|
|
$where_condition_array = array('pd_detail_answer_id'=>$old['pd_detail_answer_id']);
|
|
$temp_array = array('isactive' => 0);
|
|
$pd_detail_answer_id = $this->PD_Model->updateRecords($temp_array,PDANSWER,$where_condition_array);
|
|
}
|
|
|
|
foreach($answers_array as $answer_key => $answer)
|
|
{
|
|
if($answer['pd_detail_answer_id'] == "" || $answer['pd_detail_answer_id'] == null)
|
|
{
|
|
|
|
//INsert New Answers
|
|
$answer['fk_pd_detail_id'] = $record['pd_detail_id'];
|
|
$pd_detail_answer_id = $this->PD_Model->saveRecords($answer,PDANSWER);
|
|
if($pd_detail_answer_id != "" || $pd_detail_answer_id != null){ $answer_count++; }
|
|
|
|
}
|
|
else
|
|
{
|
|
// Update Current Answer
|
|
$where_condition_array = array('pd_detail_answer_id'=>$answer['pd_detail_answer_id']);
|
|
$answer['isactive'] = 1;
|
|
$pd_detail_answer_id = $this->PD_Model->updateRecords($answer,PDANSWER,$where_condition_array);
|
|
if($pd_detail_answer_id != "" || $pd_detail_answer_id != null){ $answer_count++; }
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//IMAGES SAVE - pd_document_id, fk_pd_id, fk_pd_detail_id, pd_document_title, pd_document_name, createdon, fk_createdby, updatedon, fk_updatedby
|
|
if(count($images_array))
|
|
{
|
|
foreach($images_array as $image_key => $image)
|
|
{
|
|
|
|
|
|
//Get Lender ID
|
|
$sql = 'SELECT fk_lender_id FROM '. PDTRIGGER .' WHERE pd_id ='.$record["fk_pd_id"];
|
|
$lender_id = $this->db->query($sql)->result_array();
|
|
|
|
$temp_base64_string = $image['pd_document_name'];
|
|
$title = $image['pd_document_title'];
|
|
$output_file = APPPATH."/docs/temp_base64_image.png";
|
|
|
|
//Generate Random File Name
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < 5; $i++) {
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
}
|
|
$temp_file_name = $randomString.date('Y-m-d-H:m:s').'.png';
|
|
|
|
|
|
$ifp = fopen( $output_file, 'wb' );
|
|
$temp_data = explode( ',', $temp_base64_string );
|
|
fwrite( $ifp, base64_decode( $temp_data[ 1 ] ) );
|
|
fclose( $ifp );
|
|
$tempdoc = $output_file;
|
|
$tempdocname = $temp_file_name;
|
|
$bucketname = LENDER_BUCKET_NAME_PREFIX.$lender_id[0]['fk_lender_id'];
|
|
$key = 'pd'.$record['fk_pd_id'].'/'.$tempdocname ;
|
|
$sourcefile = $tempdoc;
|
|
|
|
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile);
|
|
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
|
|
|
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
|
|
{
|
|
$image['pd_document_name'] = $tempdocname;
|
|
$image['fk_pd_detail_id'] = $record['pd_detail_id'];
|
|
$image['fk_pd_id'] = $record['fk_pd_id'];
|
|
$pd_document_id = $this->PD_Model->saveRecords($image,PDDOCUMENTS);
|
|
if($pd_document_id != "" || $pd_document_id != null){ $image_count++; }
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
if(($pd_detail_id != "" || $pd_detail_id != null) && count($images_array) == $image_count && count($answers_array) == $answer_count)
|
|
{
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = true;
|
|
$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);
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
|
|
|
|
if($record['answers'] != "" || $record['answers'] != null)
|
|
{
|
|
$answers_array = $record['answers'];
|
|
unset($record['answers']);
|
|
}
|
|
|
|
if($record['images'] != "" || $record['images'] != null)
|
|
{
|
|
$images_array = $record['images'];
|
|
unset($record['images']);
|
|
}
|
|
//print_r($record);die();
|
|
$pd_detail_id = $this->PD_Model->saveRecords($record,PDDETAIL);
|
|
|
|
// ANSWERS SAVE - pd_detail_answer_id, fk_pd_id, fk_pd_detail_id, pd_answer_id, pd_answer, pd_answer_weightage, pd_answer_remark
|
|
if(count($answers_array))
|
|
{
|
|
foreach($answers_array as $answer_key => $answer)
|
|
{
|
|
$answer['fk_pd_detail_id'] = $pd_detail_id;
|
|
$pd_detail_answer_id = $this->PD_Model->saveRecords($answer,PDANSWER);
|
|
if($pd_detail_answer_id != "" || $pd_detail_answer_id != null){ $answer_count++; }
|
|
}
|
|
}
|
|
|
|
//IMAGES SAVE - pd_document_id, fk_pd_id, fk_pd_detail_id, pd_document_title, pd_document_name, createdon, fk_createdby, updatedon, fk_updatedby
|
|
if(count($images_array))
|
|
{
|
|
foreach($images_array as $image_key => $image)
|
|
{
|
|
|
|
|
|
//Get Lender ID
|
|
$sql = 'SELECT fk_lender_id FROM '. PDTRIGGER .' WHERE pd_id ='.$record["fk_pd_id"];
|
|
$lender_id = $this->db->query($sql)->result_array();
|
|
|
|
$temp_base64_string = $image['pd_document_name'];
|
|
$title = $image['pd_document_title'];
|
|
$output_file = APPPATH."/docs/temp_base64_image.png";
|
|
|
|
//Generate Random File Name
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < 5; $i++) {
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
}
|
|
$temp_file_name = $randomString.date('Y-m-d-H:m:s').'.png';
|
|
|
|
|
|
$ifp = fopen( $output_file, 'wb' );
|
|
$temp_data = explode( ',', $temp_base64_string );
|
|
fwrite( $ifp, base64_decode( $temp_data[ 1 ] ) );
|
|
fclose( $ifp );
|
|
$tempdoc = $output_file;
|
|
$tempdocname = $temp_file_name;
|
|
$bucketname = LENDER_BUCKET_NAME_PREFIX.$lender_id[0]['fk_lender_id'];
|
|
$key = 'pd'.$record['fk_pd_id'].'/'.$tempdocname ;
|
|
$sourcefile = $tempdoc;
|
|
|
|
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile);
|
|
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
|
|
|
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
|
|
{
|
|
$image['pd_document_name'] = $tempdocname;
|
|
|
|
$image['fk_pd_detail_id'] = $record['pd_detail_id'];
|
|
$image['fk_pd_id'] = $record['fk_pd_id'];
|
|
$pd_document_id = $this->PD_Model->saveRecords($image,PDDOCUMENTS);
|
|
if($pd_document_id != "" || $pd_document_id != null){ $image_count++; }
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
if(($pd_detail_id != "" || $pd_detail_id != null) && count($images_array) == $image_count && count($answers_array) == $answer_count)
|
|
{
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $pd_detail_id;
|
|
$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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/************** Get Answers for PD @params question_id, pd_id, template_id, category_id**************/
|
|
public function getAnswersForPD_post()
|
|
{
|
|
$question_id = $this->post('question_id');
|
|
$pd_id = $this->post('pd_id');
|
|
$template_id = $this->post('template_id');
|
|
$category_id = $this->post('category_id');
|
|
|
|
$answers = $this->PD_Model->getAnswersForPD($question_id,$pd_id,$template_id,$category_id);
|
|
|
|
if(count($answers))
|
|
{
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $answers;
|
|
$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);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/********* Get Form Informations @param pd_id and pd_form_id ******/
|
|
public function getPDFormDetails_post()
|
|
{
|
|
$pd_id = $this->post('pd_id');
|
|
$pd_form_id = $this->post('pd_form_id');
|
|
|
|
//Get Pd masters etails usng PD ID
|
|
$pd_details = $this->PD_Model->getPDMasterDetails($pd_id);
|
|
|
|
$result_array = $this->PD_Model->getPDFormDetails($pd_id,$pd_form_id);
|
|
//print_r($result_array);die();
|
|
//call helper function for get structured key,value pairs
|
|
$final_array = GETPDFORMDETAILS::getPDFormDetailsStructured($result_array,$pd_id,$pd_form_id);
|
|
// *****************************Get Docs from bucket
|
|
// Get Alredy stored Images
|
|
$fields = array('pd_document_title', 'pd_document_name');
|
|
$where_condition_array = array('fk_pd_id' => $pd_id,'fk_form_id' => $pd_form_id);
|
|
|
|
$pd_docs = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDDOCUMENTS);
|
|
|
|
if(count($pd_docs))
|
|
{
|
|
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$pd_details[0]['fk_lender_id'];
|
|
foreach($pd_docs as $doc_key => $doc)
|
|
{
|
|
if($doc['pd_document_name'] != "" || $doc['pd_document_name'] != null)
|
|
{
|
|
$profilepics3path = 'pd'.$pd_details[0]['pd_id'].'/'.$doc['pd_document_name'];
|
|
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$profilepics3path,'+30 minutes');
|
|
$pd_docs[$doc_key]['pd_document_name'] = $singed_uri;
|
|
}
|
|
}
|
|
|
|
|
|
$final_array['base64images'] = $pd_docs;
|
|
}
|
|
|
|
|
|
|
|
// *************************End Get Docs from bucket
|
|
|
|
|
|
|
|
if($result_array)
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $final_array;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = "Details Not Available!";
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/********* Save Form Informations @param pd_id and pd_form_id ******/
|
|
public function savePDFormDetails_post()
|
|
{
|
|
$records = $this->post('records');
|
|
|
|
$pd_id = $records['pdid'];
|
|
|
|
//Get Pd masters etails usng PD ID
|
|
$pd_details = $this->PD_Model->getPDMasterDetails($pd_id);
|
|
|
|
|
|
$pd_form_id = $records['formid'];
|
|
$fk_createdby = $records['fk_createdby'];
|
|
$i = 0;
|
|
$base64images = array();
|
|
//seperate base64 images from records array
|
|
if(array_key_exists('base64images',$records))
|
|
{
|
|
$base64images = $records['base64images'];
|
|
unset($records['base64images']);
|
|
}
|
|
|
|
//If It is General Informatin Form Save New Co Applcants details
|
|
// by Passing records form to another(saveCoApplicantsFromGeneralInfoForm) internl function
|
|
if($records['formid'] == 18)
|
|
{
|
|
$this->saveCoApplicantsFromGeneralInfoForm($records);
|
|
}
|
|
|
|
if($records['formid'] == 1)// If formis supplier then omit parent level array keys
|
|
{
|
|
if(array_key_exists('manufacturing_details',$records))
|
|
{
|
|
$records['main_raw_materials'] = $records['manufacturing_details'][0]['main_raw_materials'];
|
|
$records['main_raw_materials_total_payments_percent_on_credit'] = $records['manufacturing_details'][0]['main_raw_materials_total_payments_percent_on_credit'];
|
|
unset($records['manufacturing_details']);
|
|
}
|
|
|
|
if(array_key_exists('trade_details',$records))
|
|
{
|
|
$records['trading_products'] = $records['trade_details'][0]['trading_products'];
|
|
$records['trading_products_total_payments_percent_on_credit'] = $records['trade_details'][0]['trading_products_total_payments_percent_on_credit'];
|
|
unset($records['trade_details']);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//Deactivate Old rec
|
|
$where_condition_array = array('fk_pd_id' => $pd_id,"fk_form_id"=>$pd_form_id);
|
|
$array = array('isactive'=>0);
|
|
$pd_id_modified = $this->PD_Model->updateRecords($array,PDFORMDETAILS,$where_condition_array);
|
|
|
|
|
|
foreach($records as $rec_key => $record)
|
|
{
|
|
$i++;
|
|
|
|
if($rec_key !='pdid' && $rec_key != 'formid' && $rec_key != 'fk_createdby')
|
|
{
|
|
|
|
if(!is_array($record))//check key and value pair is not an array
|
|
{
|
|
$temp_array = array('fk_pd_id'=>$pd_id,'fk_form_id'=>$pd_form_id,'column_name'=>$rec_key,'column_value'=>$record,'fk_createdby'=>$fk_createdby);
|
|
$id = $this->PD_Model->saveRecords($temp_array,PDFORMDETAILS);
|
|
}
|
|
else // array of key value pairs
|
|
{
|
|
$iter=0;
|
|
foreach($record as $mkey => $rec)
|
|
{
|
|
//print_r($rec);
|
|
$iter++;
|
|
if(!is_array($rec))
|
|
{
|
|
|
|
foreach($rec as $rkey => $r)
|
|
{
|
|
$temp_array = array('');
|
|
if($r != "" && $r != null)
|
|
{
|
|
|
|
$temp_array = array('fk_pd_id'=>$pd_id,'fk_form_id'=>$pd_form_id,'iter_column_name'=>$rec_key,'column_name'=>$rkey,'column_value'=>$r,'fk_createdby'=>$fk_createdby,'iteration'=>$iter);
|
|
$id = $this->PD_Model->saveRecords($temp_array,PDFORMDETAILS);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
foreach($rec as $child_key => $child_data)
|
|
{
|
|
//print_r($child_data);
|
|
// echo "$child_key-\n\n\n";
|
|
if(!is_array($child_data))
|
|
{
|
|
//echo "not array\n\n";
|
|
//print_r($child_data);
|
|
$temp_array = array('fk_pd_id'=>$pd_id,'fk_form_id'=>$pd_form_id,'column_name'=>$child_key,'column_value'=>$child_data,'iter_column_name'=>$rec_key,'fk_createdby'=>$fk_createdby,'iteration'=>$iter);
|
|
//print_r($temp_array);
|
|
$id = $this->PD_Model->saveRecords($temp_array,PDFORMDETAILS);
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
//echo "array";
|
|
//print_r($child_data);
|
|
//echo "$child_key-\n\n\n";
|
|
foreach($child_data as $last_key => $last_data)
|
|
{
|
|
foreach($last_data as $final_key => $final_data)
|
|
{
|
|
$temp_array = array('fk_pd_id'=>$pd_id,'fk_form_id'=>$pd_form_id,'column_name'=>$final_key,'column_value'=>$final_data,'iter_column_name'=>$rec_key,'iter_sub_column_name'=>$child_key,'fk_createdby'=>$fk_createdby,'iteration'=>$iter);
|
|
//print_r($temp_array);
|
|
$id = $this->PD_Model->saveRecords($temp_array,PDFORMDETAILS);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}// end of array of key value pairs
|
|
}
|
|
//}
|
|
//**************** End of handle form details logic***************//
|
|
|
|
}
|
|
|
|
//*****************************upload base64 images
|
|
if(count($base64images))
|
|
{
|
|
|
|
foreach($base64images as $iter => $doc)
|
|
{
|
|
$temp_base64_string = $doc['image'];
|
|
$title = $doc['Name'];
|
|
$output_file = APPPATH."/docs/temp_base64_image.png";
|
|
|
|
//Generate Random File Name
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < 5; $i++) {
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
}
|
|
$temp_file_name = $randomString.date('Y-m-d-H:m:s').'.png';
|
|
|
|
|
|
$ifp = fopen( $output_file, 'wb' );
|
|
$temp_data = explode( ',', $temp_base64_string );
|
|
fwrite( $ifp, base64_decode( $temp_data[ 1 ] ) );
|
|
fclose( $ifp );
|
|
$tempdoc = $output_file;
|
|
$tempdocname = $temp_file_name;
|
|
$bucketname = LENDER_BUCKET_NAME_PREFIX.$pd_details['fk_lender_id'];
|
|
$key = 'pd'.$pd_id.'/'.$tempdocname ;
|
|
$sourcefile = $tempdoc;
|
|
|
|
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile);
|
|
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
|
|
|
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
|
|
{
|
|
$record_data = array('fk_pd_id' => $pd_id,'fk_form_id'=>$pd_form_id,'pd_document_title'=>$title,'pd_document_name'=>$tempdocname);
|
|
$this->PD_Model->saveRecords($record_data,PDDOCUMENTS);
|
|
}
|
|
|
|
}
|
|
}
|
|
//*******************************upload base64 images
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
//$data['records'] = $result_array;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
|
|
}
|
|
|
|
|
|
//Save Co applicants details from General Form
|
|
public function saveCoApplicantsFromGeneralInfoForm($records)
|
|
{
|
|
|
|
if(count($records['co_applicant_details']))
|
|
{
|
|
//echo 'saveCoApplicantsFromGeneralInfoForm';
|
|
$exist_applicants = $this->PD_Model->getApplicantsDetails($records['pdid']);
|
|
//print_r($exist_applicants);
|
|
//echo "Yes";
|
|
$index_of_new_applicants = array();
|
|
foreach($records['co_applicant_details'] as $applicant_key => $new_applicant)
|
|
{
|
|
$count = 0;
|
|
|
|
foreach($exist_applicants as $exist_key => $exist_applicant)//,
|
|
{
|
|
if($exist_applicant['applicant_type'] != 1)
|
|
{
|
|
if(!strcmp($new_applicant['name_ans'],$exist_applicant['applicant_name']))
|
|
{
|
|
$count++;
|
|
$temp_array = array('fk_pd_id'=>$records['pdid'],'applicant_name'=>$new_applicant['name_ans'],'applicant_type'=>0,'relation'=>$new_applicant['relation_ans']);
|
|
$where_condition_array = array('fk_pd_id'=>$records['pdid'],'applicant_name'=>$exist_applicant['applicant_name']);
|
|
$this->PD_Model->updateRecords($temp_array,PDAPPLICANTSDETAILS,$where_condition_array);
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
if($count == 0)
|
|
{
|
|
$temp_array = array('fk_pd_id'=>$records['pdid'],'applicant_name'=>$new_applicant['name_ans'],'applicant_type'=>0,'relation'=>$new_applicant['relation_ans']);
|
|
$this->PD_Model->saveRecords($temp_array,PDAPPLICANTSDETAILS);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public function getAssessedIncome_post()
|
|
{
|
|
$pd_id = $this->post('pd_id');
|
|
$pd_form_id = $this->post('pd_form_id');
|
|
$result_array = $this->PD_Model->getAssessedIncome($pd_id);
|
|
//print_r($result_array);die();
|
|
$result_array['final_data'] = array();
|
|
$fine = $this->calculateAssessedIncome($pd_id);
|
|
if($fine != null)
|
|
{
|
|
$result_array['final_data'][] = $fine;
|
|
}
|
|
|
|
if(count($result_array['sales_declared_by_customer']) == 0 && count($result_array['sales_calculated_by_itemwise']) == 0 && count($result_array['sales_items_by_monthwise']) == 0 && count($result_array['purchase_details']) == 0 && count($result_array['business_expenses']) == 0 && count($result_array['house_hold_expenses']) == 0 && count($result_array['gross_profit_calculation_type']) == 0)
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $result_array;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $result_array;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
|
|
public function saveAssessedIncomeSalesDeclaredByCustomer_post()
|
|
{
|
|
$records = $this->post('records');
|
|
$pk = "";
|
|
if($records['sdc_id'] != null || $records['sdc_id'] != "")
|
|
{
|
|
|
|
$where_condition_array = array('sdc_id'=>$records['sdc_id']);
|
|
$pk = $this->PD_Model->updateRecords($records,SALESDECLAREDBYCUSTOMER,$where_condition_array);
|
|
}
|
|
else
|
|
{
|
|
$pk = $this->PD_Model->saveRecords($records,SALESDECLAREDBYCUSTOMER);
|
|
}
|
|
|
|
if($pk != "" || $pk != null)
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $pk;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'Something went wrong! Try Later';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
}
|
|
|
|
public function saveAssessedIncomeSalesCalculatedByItemwise_post()
|
|
{
|
|
$records = $this->post('records');
|
|
$count = 0;
|
|
foreach($records as $rec_key => $record)
|
|
{
|
|
if($record['sci_id'] != null || $record['sci_id'] != "")
|
|
{
|
|
$where_condition_array = array('sci_id'=>$record['sci_id']);
|
|
$id = $this->PD_Model->updateRecords($record,SALESCALCULATEDBYITEMWISE,$where_condition_array);
|
|
if($id != "" || $id != null){$count++;}
|
|
}
|
|
else
|
|
{
|
|
$id = $this->PD_Model->saveRecords($record,SALESCALCULATEDBYITEMWISE);
|
|
if($id != "" || $id != null){$count++;}
|
|
}
|
|
}
|
|
if($count == count($records))
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = true;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'Something went wrong! Try Later';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
|
|
public function saveAssessedIncomePurchaseDetails_post()
|
|
{
|
|
$records = $this->post('records');
|
|
$count = 0;
|
|
foreach($records as $rec_key => $record)
|
|
{
|
|
if($record['purchase_id'] != null || $record['purchase_id'] != "")
|
|
{
|
|
$where_condition_array = array('purchase_id'=>$record['purchase_id']);
|
|
$id = $this->PD_Model->updateRecords($record,PDPURCHASEDETAILS,$where_condition_array);
|
|
if($id != "" || $id != null){$count++;}
|
|
}
|
|
else
|
|
{
|
|
$id = $this->PD_Model->saveRecords($record,PDPURCHASEDETAILS);
|
|
if($id != "" || $id != null){$count++;}
|
|
}
|
|
}
|
|
if($count == count($records))
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = true;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'Something went wrong! Try Later';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
|
|
public function saveAssessedIncomeBusinessExpenses_post()
|
|
{
|
|
$records = $this->post('records');
|
|
$count = 0;
|
|
foreach($records as $rec_key => $record)
|
|
{
|
|
if($record['pd_expense_id'] != null || $record['pd_expense_id'] != "")
|
|
{
|
|
$where_condition_array = array('pd_expense_id'=>$record['pd_expense_id']);
|
|
$id = $this->PD_Model->updateRecords($record,PDBUSINESSEXPENSES,$where_condition_array);
|
|
if($id != "" || $id != null){$count++;}
|
|
}
|
|
else
|
|
{
|
|
$id = $this->PD_Model->saveRecords($record,PDBUSINESSEXPENSES);
|
|
if($id != "" || $id != null){$count++;}
|
|
}
|
|
}
|
|
|
|
if($count == count($records))
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = true;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'Something went wrong! Try Later';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
|
|
public function saveAssessedIncomeHouseholdExpenses_post()
|
|
{
|
|
$records = $this->post('records');
|
|
$count = 0;
|
|
foreach($records as $rec_key => $record)
|
|
{
|
|
if($record['household_expense_id'] != null || $record['household_expense_id'] != "")
|
|
{
|
|
$where_condition_array = array('household_expense_id'=>$record['household_expense_id']);
|
|
$id = $this->PD_Model->updateRecords($record,PDHOUSEHOLDEXPENSES,$where_condition_array);
|
|
if($id != "" || $id != null){$count++;}
|
|
}
|
|
else
|
|
{
|
|
$id = $this->PD_Model->saveRecords($record,PDHOUSEHOLDEXPENSES);
|
|
if($id != "" || $id != null){$count++;}
|
|
}
|
|
}
|
|
|
|
if($count == count($records))
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = true;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'Something went wrong! Try Later';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
|
|
|
|
/*********************************************************************************************
|
|
*********************************************************************************************/
|
|
public function saveAssessedIncomeMonthwiseItems_post()//SALESITEMMONTHWISECHILD
|
|
{
|
|
$records = $this->post('records');
|
|
$count = 0;
|
|
foreach($records as $key => $record)
|
|
{
|
|
|
|
$child_data = array();
|
|
if(array_key_exists('child',$record))
|
|
{
|
|
$child_data = $record['child'];
|
|
unset($record['child']);
|
|
}
|
|
$id = "";
|
|
if($record['sim_id'] != null || $record['sim_id'] != "")
|
|
{
|
|
$where_condition_array = array('sim_id'=>$record['sim_id']);
|
|
$id = $this->PD_Model->updateRecords($record,SALESITEMMONTHWISE,$where_condition_array);
|
|
if($id != "" || $id != null)
|
|
{
|
|
$count++;
|
|
foreach($child_data as $ckey => $child)
|
|
{
|
|
if($child['simc_id'] != "" || $child['simc_id'] != null)
|
|
{
|
|
$where_condition_array = array('simc_id'=>$child['simc_id']);
|
|
$child_id = $this->PD_Model->updateRecords($child,SALESITEMMONTHWISECHILD,$where_condition_array);
|
|
}
|
|
else
|
|
{
|
|
$child['fk_sim_id'] = $record['sim_id'];
|
|
$child_id = $this->PD_Model->saveRecords($child,SALESITEMMONTHWISECHILD);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
$id = $this->PD_Model->saveRecords($record,SALESITEMMONTHWISE);
|
|
if($id != "" || $id != null)
|
|
{
|
|
$count++;
|
|
foreach($child_data as $ckey => $child)
|
|
{
|
|
$child['fk_sim_id'] = $id;
|
|
$child_id = $this->PD_Model->saveRecords($child,SALESITEMMONTHWISECHILD);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if($count == count($records))
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $id;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'Something went wrong! Try Later';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
|
|
|
|
/*********************************************************************************************
|
|
*********************************************************************************************/
|
|
public function getFinalPDReportQuestions_post()
|
|
{
|
|
$pd_id = $this->post('pd_id');
|
|
|
|
$final_data_to_response = array();
|
|
$final_data_to_response['question_answers']['general_questions'] = "";
|
|
|
|
$pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id);
|
|
$final_data_to_response = $pd_master_details[0];
|
|
$final_data_to_response['pd_applicant_details'] = $this->PD_Model->getApplicantsDetails($pd_id);
|
|
|
|
//Get Template id
|
|
$fields = array('fk_pd_template_id');
|
|
$where_condition_array = array('pd_id' => $pd_id);
|
|
$template_details = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDTRIGGER);
|
|
$template_id = null;
|
|
if(count($template_details))
|
|
{
|
|
$template_id = $template_details[0]['fk_pd_template_id'];
|
|
}
|
|
|
|
// Get all assigned pd forms associated with this pd from template_forms table
|
|
if($template_id != null)
|
|
{
|
|
$columns = array('TEMPLATEFORMS.form_id','PDFORMS.pd_form_name');
|
|
$table = TEMPLATEFORMS.' as TEMPLATEFORMS';
|
|
$joins = array(array('table' => PDFORMS. ' as PDFORMS',
|
|
'condition' =>'TEMPLATEFORMS.form_id = PDFORMS.pd_form_id AND TEMPLATEFORMS.isactive = 1',
|
|
'jointype' => 'INNER'));
|
|
$where_condition_array = array('fk_template_id' => $template_id);
|
|
$template_form_details = $this->PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array);
|
|
//print_r($template_form_details);
|
|
if(count($template_form_details))
|
|
{
|
|
$temp_array = "";
|
|
foreach($template_form_details as $template_key => $template_form_detail)
|
|
{
|
|
$pd_form_raw_data = $this->PD_Model->getPDFormDetailsWithScoring($pd_id,$template_form_detail['form_id']);
|
|
|
|
$pd_score = $this->calculatePDScore($pd_form_raw_data);
|
|
$transformed_data = $this->transformKeyPairToQuestionAnswers($pd_form_raw_data,$template_form_detail['form_id']);
|
|
|
|
|
|
$final_data_to_response['question_answers']['form_details'][] = array('name' =>[$template_form_detail['pd_form_name']],'details' => $transformed_data);
|
|
|
|
//$final_data_to_response['question_answers']['form_details'] = array_merge($final_data_to_response['question_answers']['form_details'],array('name' =>[$template_form_detail['pd_form_name']],'details' => $transformed_data));
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$final_data_to_response['question_answers']['general_questions'] = array();
|
|
//$final_data_to_response['question_answers']['form_details'] = array();
|
|
|
|
$object = new stdClass();
|
|
foreach($final_data_to_response as $key => $value)
|
|
{
|
|
$object->$key = $value;
|
|
}
|
|
if(count($final_data_to_response))
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $final_data_to_response;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'Something went wrong! Try Later';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************************************
|
|
*********************************************************************************************/
|
|
public function transformKeyPairToQuestionAnswers($pd_form_raw_data,$form_id)
|
|
{
|
|
//field name array holds - field name of each masters table
|
|
$master_tables_field_names = $this->config->item('master_tables_field_names');
|
|
|
|
$master_tables_pkid = $this->config->item('master_tables_pkid');
|
|
|
|
//Get Question Key Mapping masters
|
|
$fields = array('question', 'key', 'ismaster', 'master_name');
|
|
$where_condition_array = array('fk_form_id' => $form_id,'isactive' => 1);
|
|
$question_key_master_data = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONKEYMAPPING);
|
|
//print_r($pd_form_raw_data);
|
|
$current_question_array = array();
|
|
foreach($pd_form_raw_data as $raw_key => $raw_data)
|
|
{
|
|
$que_key = $raw_data['column_name'];
|
|
if($que_key != null || $que_key != "")
|
|
{
|
|
foreach($question_key_master_data as $master_key => $master)
|
|
{
|
|
if($master['key'] == $que_key)
|
|
{
|
|
if($master['ismaster'] != 1)
|
|
{
|
|
$current_question_array[] = array('category_weightage' => $raw_data['category_weightage'],'question_weightage' => $raw_data['question_weightage'],'answer_score' => $raw_data['score'],'question'=>$master['question'],'answer'=>$raw_data['column_value']);
|
|
}
|
|
else
|
|
{
|
|
$table = constant($master['master_name']);
|
|
$temp_fields = array($master_tables_field_names[$master['master_name']].' as name');
|
|
$where_condition_array = array($master_tables_pkid[$master['master_name']] => $raw_data['column_value']);
|
|
$result_data = $this->PD_Model->selectCustomRecords($temp_fields,$where_condition_array,$table);
|
|
if(count($result_data))
|
|
{
|
|
//print_r($result_data);
|
|
$current_question_array[] = array('category_weightage' => $raw_data['category_weightage'],'question_weightage' => $raw_data['question_weightage'],'answer_score' => $raw_data['score'],'question'=>$master['question'],'answer'=>$result_data[0]['name']);
|
|
}
|
|
//
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $current_question_array ;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/*********************************************************************************************
|
|
*********************************************************************************************/
|
|
public function saveAssessedIncomeCalculateMode_post()
|
|
{
|
|
$records = $this->post('records');
|
|
$id = 0;
|
|
if($records['calc_type_id'] != "" || $records['calc_type_id'] != null)
|
|
{
|
|
|
|
$where_condition_array = array("calc_type_id" => $records['calc_type_id']);
|
|
$id = $this->PD_Model->updateRecords($records,PDASSESSEDINCOMEESTIMATIONOFGROSSPROFITTYPE,$where_condition_array);
|
|
}
|
|
else
|
|
{
|
|
|
|
$id = $this->PD_Model->saveRecords($records,PDASSESSEDINCOMEESTIMATIONOFGROSSPROFITTYPE);
|
|
}
|
|
|
|
if($id != 0)
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $id;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'Something went wrong! Try Later';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/*********************************************************************************************
|
|
*********************************************************************************************/
|
|
public function calculateAssessedIncome($pd_id)
|
|
{
|
|
|
|
|
|
$calculated_data = array();
|
|
|
|
$sales_declared_by_customer = array();
|
|
$sales_declared_by_customer_flag = 0;
|
|
|
|
$sales_calculated_by_itemwise = array();
|
|
$sales_calculated_by_itemwise_flag = 0;
|
|
|
|
$sales_by_item_monthwise = array();
|
|
$sales_by_item_monthwise_flag = 0;
|
|
$margin_value_from_monthwise_data = array();
|
|
|
|
$purchases = array();
|
|
$purchases_flag = 0;
|
|
|
|
$business_expenses = array();
|
|
$business_expenses_flag = 0;
|
|
|
|
$household_expenses = array();
|
|
$household_expenses_flag = 0;
|
|
|
|
$overall_purchase_total = 0;
|
|
$overall_business_total = 0;
|
|
$overall_household_total = 0;
|
|
$net_profit = 0;
|
|
$final_purchase_avg_value = 0;
|
|
|
|
//Get all Master Details
|
|
$result_array = $this->PD_Model->getAssessedIncome($pd_id);
|
|
//print_r($result_array);
|
|
$sales_declared_by_customer = $result_array['sales_declared_by_customer'];
|
|
$sales_calculated_by_itemwise = $result_array['sales_calculated_by_itemwise'];
|
|
$sales_by_item_monthwise = $result_array['sales_items_by_monthwise'];
|
|
$purchases = $result_array['purchase_details'];
|
|
$business_expenses = $result_array['business_expenses'];
|
|
$household_expenses = $result_array['house_hold_expenses'];
|
|
$gross_profit_calculation_type = $result_array['gross_profit_calculation_type'];
|
|
if(count($sales_declared_by_customer)){$sales_declared_by_customer_flag = 1;}
|
|
if(count($sales_calculated_by_itemwise)){$sales_calculated_by_itemwise_flag = 1;}
|
|
if(count($sales_by_item_monthwise)){$sales_by_item_monthwise_flag = 1;}
|
|
if(count($purchases)){$purchases_flag = 1;}
|
|
if(count($business_expenses)){$business_expenses_flag = 1;}
|
|
if(count($household_expenses)){$household_expenses_flag = 1;}
|
|
|
|
|
|
if(($household_expenses_flag == 1 && $business_expenses_flag == 1) && ($sales_declared_by_customer_flag == 1 || $sales_calculated_by_itemwise_flag == 1 || $sales_by_item_monthwise_flag == 1))
|
|
{
|
|
$total_sales_itemwise = 0;
|
|
$sales_monthwise = array();
|
|
|
|
$total_sales_monthwise = 0;
|
|
$total_sales_declared_by_customer = 0;
|
|
|
|
if($sales_calculated_by_itemwise_flag == 1)
|
|
{
|
|
foreach($sales_calculated_by_itemwise as $itemwise_key => $item)
|
|
{
|
|
$total_sales_itemwise = $total_sales_itemwise + $item['annual_sale_value'];
|
|
}
|
|
|
|
}
|
|
|
|
if($sales_by_item_monthwise_flag == 1)
|
|
{
|
|
|
|
foreach($sales_by_item_monthwise as $monthwise_key => $sales_by_item_month)
|
|
{
|
|
$month_total = 0;
|
|
$i = 0;
|
|
foreach($sales_by_item_month['items'] as $month_key => $month)
|
|
{
|
|
$temp = 0;
|
|
|
|
$i++;
|
|
foreach($month as $key => $m)
|
|
{
|
|
$temp = $temp + $m['sales_value'];
|
|
}
|
|
$month_total = $month_total + $temp;
|
|
}
|
|
$sales_monthwise[] = array('total' => $month_total,'no_of_months' => $i);
|
|
}
|
|
|
|
foreach($sales_monthwise as $sale)
|
|
{
|
|
$annual_multuplier = 12 / $sale['no_of_months'];
|
|
$total_sales_monthwise = $total_sales_monthwise + ($sale['total'] * $annual_multuplier);
|
|
}
|
|
//print_r($total_sales_monthwise);
|
|
}
|
|
|
|
if($sales_declared_by_customer_flag == 1)
|
|
{
|
|
$total_sales_declared_by_customer = $sales_declared_by_customer[0]['sales_declared_by_customer'];
|
|
}
|
|
//print_r($sales_monthwise);
|
|
//print_r($total_sales_monthwise);
|
|
|
|
|
|
foreach($business_expenses as $business_key => $business_expense)
|
|
{
|
|
$overall_business_total = $overall_business_total + $business_expense['annual_expenses_value'];
|
|
}
|
|
|
|
foreach($household_expenses as $household_key => $household_expense)
|
|
{
|
|
$overall_household_total = $overall_household_total + $household_expense['annual_expense_value'];
|
|
}
|
|
|
|
if($purchases_flag != 0)
|
|
{
|
|
foreach($purchases as $purchase_key => $purchase)
|
|
{
|
|
$overall_purchase_total = $overall_purchase_total + $purchase['annual_purchase_value'];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
//case 1 - (b:ref doc) If the difference between the lowest and highest of the 3 revenue (sales) figures arrived at above in step 1, is > 50% of lowest, then the revenue considered would be 125% of the lowest revenue
|
|
|
|
$temp_array = array();
|
|
|
|
if($sales_declared_by_customer_flag != 0){ $temp_array = array_merge($temp_array,array($total_sales_declared_by_customer));}
|
|
if($sales_calculated_by_itemwise_flag != 0){ $temp_array = array_merge($temp_array,array($total_sales_itemwise));}
|
|
if($sales_by_item_monthwise_flag != 0){ $temp_array = array_merge($temp_array,array($total_sales_monthwise));}
|
|
$height_value = max($temp_array);
|
|
$lowest_vaule = min($temp_array);
|
|
|
|
|
|
if($lowest_vaule != 0 && count($temp_array) > 1)
|
|
{
|
|
$diff = $height_value - $lowest_vaule;
|
|
if($diff > ($lowest_vaule * 0.5))
|
|
{
|
|
$final_purchase_avg_value = $lowest_vaule * 1.25;
|
|
}
|
|
|
|
}
|
|
else //case 2 - (a) ref doc - Normally Average of the above 3 sales estimates is considered. There may be situations where sales information is available only from a or b or c or any
|
|
{
|
|
$average = array_sum($temp_array)/count($temp_array);
|
|
$final_purchase_avg_value = $average;
|
|
|
|
}
|
|
|
|
//echo "\n\n".$final_purchase_avg_value;
|
|
|
|
/**************End of Purchase Calculations************************/
|
|
|
|
/**************************Gross Profit calculation start***************/
|
|
//print_r($gross_profit_calculation_type);
|
|
$estimation_of_gross_profit = 0;
|
|
if(isset($gross_profit_calculation_type[0]))
|
|
{
|
|
if($gross_profit_calculation_type[0]['mode'] == 1)
|
|
{
|
|
$estimation_of_gross_profit = $final_purchase_avg_value - $overall_purchase_total;
|
|
$net_profit = $estimation_of_gross_profit - $overall_business_total;
|
|
}
|
|
else
|
|
{
|
|
if($gross_profit_calculation_type[0]['margin'] == 1)
|
|
{
|
|
if($sales_declared_by_customer_flag != 0)
|
|
{
|
|
$estimation_of_gross_profit = $sales_declared_by_customer[0]['margin_value'];
|
|
}
|
|
else if($sales_calculated_by_itemwise_flag != 0)
|
|
{
|
|
foreach($sales_calculated_by_itemwise as $sci_key => $sci)
|
|
{
|
|
$estimation_of_gross_profit = $estimation_of_gross_profit+$sci['margin_final_value'];
|
|
}
|
|
}
|
|
else if($sales_by_item_monthwise_flag != 0)
|
|
{
|
|
foreach($sales_by_item_monthwise as $sim_key => $sim)
|
|
{
|
|
$estimation_of_gross_profit = $estimation_of_gross_profit+$sim['margin_value'];
|
|
}
|
|
}
|
|
|
|
$net_profit = $estimation_of_gross_profit - $overall_business_total;
|
|
$overall_purchase_total = $net_profit + $overall_business_total;
|
|
}
|
|
else
|
|
{
|
|
if($sales_declared_by_customer_flag != 0)
|
|
{
|
|
$net_profit = $sales_declared_by_customer[0]['margin_value'];
|
|
}
|
|
else if($sales_calculated_by_itemwise_flag != 0)
|
|
{
|
|
foreach($sales_calculated_by_itemwise as $sci_key => $sci)
|
|
{
|
|
$net_profit = $net_profit+$sci['margin_final_value'];
|
|
}
|
|
}
|
|
else if($sales_by_item_monthwise_flag != 0)
|
|
{
|
|
foreach($sales_by_item_monthwise as $sim_key => $sim)
|
|
{
|
|
$net_profit = $net_profit+ $sim['margin_value'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$overall_purchase_total = $final_purchase_avg_value - ($overall_business_total+$net_profit);
|
|
}
|
|
}
|
|
}
|
|
/**************************Gross Profit calculation end***************/
|
|
$calculated_data['income']['sales_revenue'] = $final_purchase_avg_value;
|
|
$calculated_data['expense']['purchase'] = $overall_purchase_total;
|
|
if(isset($gross_profit_calculation_type[0]))
|
|
{
|
|
if($gross_profit_calculation_type[0]['mode'] == 1 || $gross_profit_calculation_type[0]['margin'] == 1)
|
|
{
|
|
$calculated_data['gross_profit'] = $estimation_of_gross_profit;
|
|
}
|
|
else
|
|
{
|
|
$calculated_data['gross_profit'] =( $net_profit + $overall_business_total);
|
|
}
|
|
}
|
|
$calculated_data['expense']['business_expense'] = $overall_business_total;
|
|
$calculated_data['expense']['net_profit'] = $net_profit;
|
|
$calculated_data['net_margin'] = $net_profit / $final_purchase_avg_value;
|
|
|
|
|
|
|
|
// $data['dataStatus'] = true;
|
|
// $data['status'] = REST_Controller::HTTP_OK;
|
|
// $data['records'] = $calculated_data;
|
|
// $this->response($data,REST_Controller::HTTP_OK);
|
|
return $calculated_data;
|
|
}
|
|
else
|
|
{
|
|
// $data['dataStatus'] = false;
|
|
// $data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
// $data['msg'] = 'Not enough Data to Calculate Assessed Income';
|
|
// $this->response($data,REST_Controller::HTTP_OK);
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/*********************************************************************************************
|
|
*********************************************************************************************/
|
|
public function getLatestPDReportBlob_post()
|
|
{
|
|
$records = $this->post('records');
|
|
$pdid = $records['pd_id'];
|
|
$version_id = $records['version_id'];
|
|
|
|
$version_no = "";
|
|
|
|
if(is_numeric(substr($version_id,-7,3)))
|
|
{
|
|
$version_no = substr($version_id,-7,3);
|
|
|
|
}
|
|
else if(is_numeric(substr($version_id,-6,2)))
|
|
{
|
|
$version_no = substr($version_id,-6,2);
|
|
|
|
}else if(is_numeric(substr($version_id,-5,1)))
|
|
{
|
|
$version_no = substr($version_id,-5,1);
|
|
}
|
|
else
|
|
{
|
|
$version_no = 1;
|
|
}
|
|
|
|
$fields = array('content');
|
|
$where_condition_array = array('fk_pd_id'=>$pdid,'version_no'=>$version_no);
|
|
$result_array = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDREPORTSVERSIONBLOB);
|
|
if(count($result_array))
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $result_array;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'No Data Available';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*********************************************************************************************
|
|
*********************************************************************************************/
|
|
public function generatePDReport_post()
|
|
{
|
|
$records = $this->post('records');
|
|
$pdid = $records['pd_id'];
|
|
$fk_createdby = $records['fk_createdby'];
|
|
$original_template = "RAW";
|
|
$is_regenerate = 0;
|
|
if(isset($records['regenerate']))
|
|
{
|
|
$is_regenerate = 1;
|
|
}
|
|
|
|
$pd_master_details = $this->PD_Model->getPDMasterDetails($pdid);
|
|
|
|
//Get PD Report orginal blob
|
|
$fields = array('report_template_id', 'fk_template_id','content');
|
|
$where_condition_array = array('fk_template_id'=>$pd_master_details[0]['fk_pd_template_id'],'isactive'=>1);
|
|
$result_array = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,REPORTTEMPLATES);
|
|
$original_template = $result_array[0]['content'];
|
|
// //CHeck if already pd original version created
|
|
|
|
if(count($result_array))
|
|
{
|
|
preg_match_all("/{{(.*?)}}/",$result_array[0]['content'],$keys_from_template);
|
|
//print_r($keys_from_template);
|
|
$pd_form_raw_data = $this->PD_Model->getPDFormDetails($pdid);
|
|
//print_r($pd_form_raw_data);
|
|
|
|
foreach($keys_from_template[1] as $key_from_template => $template_key)
|
|
{
|
|
|
|
foreach($pd_form_raw_data as $pd_form_raw_data_key => $pd_form_raw)
|
|
|
|
{
|
|
if($temp_key = array_search($template_key,$pd_form_raw))
|
|
|
|
{
|
|
//echo $pd_form_raw_data[$pd_form_raw_data_key]['column_value'].'---'.$pd_form_raw_data[$pd_form_raw_data_key]['column_name'];
|
|
//echo "\n\n";
|
|
$result_array[0]['content'] = str_replace($keys_from_template[0][$key_from_template],$pd_form_raw_data[$pd_form_raw_data_key]['column_value'],$result_array[0]['content']);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$output_file = APPPATH."/docs/temp.html";
|
|
$ifp = fopen( $output_file, 'wb' );
|
|
//fwrite( $ifp, $original_template );
|
|
fwrite( $ifp, $result_array[0]['content'] );
|
|
fclose( $ifp );
|
|
//print_r($output_file);
|
|
$file= file_get_contents($output_file);
|
|
$pdf_doc = $this->pdfgenerator->generate($file, $filename='original_version', $stream=false, $paper = 'A4', $orientation = "portrait");
|
|
//print_r($pdf_doc);
|
|
|
|
|
|
$output_file2 = APPPATH."/docs/sample.pdf";
|
|
if(file_put_contents($output_file2, $pdf_doc))
|
|
{
|
|
$bucketname = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['fk_lender_id'];
|
|
$main_applicant_name = $pd_master_details[0]['main_applicant'];
|
|
$key = "";
|
|
if($is_regenerate == 0)
|
|
{
|
|
$key = 'pd'.$pdid.'/pd_reports/'.$main_applicant_name.'._version0.pdf';
|
|
}
|
|
else
|
|
{
|
|
$latest_version = $pd_master_details[0]['pd_report_latest_version'] + 1;
|
|
$key = 'pd'.$pdid.'/pd_reports/'.$main_applicant_name.'.version'.$latest_version.'.pdf';
|
|
}
|
|
$sourcefile = $output_file2;
|
|
|
|
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile);
|
|
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
|
//print_r($s3result);
|
|
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
|
|
{
|
|
|
|
$where_condition_array = array("pd_id" => $pdid);
|
|
$temp_array = array('is_original_report_created'=>1,'pd_report_latest_version_blob'=>$result_array[0]['content'],'pd_report_latest_version' => 0);
|
|
|
|
if($is_regenerate != 0)
|
|
{
|
|
$temp_array = array('is_original_report_created'=>1,'pd_report_latest_version_blob'=>$result_array[0]['content'],'pd_report_latest_version'=>$pd_master_details[0]['pd_report_latest_version'] + 1);
|
|
|
|
|
|
}
|
|
$id = $this->PD_Model->updateRecords($temp_array,PDTRIGGER,$where_condition_array);
|
|
|
|
$latest_version = 0;
|
|
if($is_regenerate != 0){ $latest_version = $pd_master_details[0]['pd_report_latest_version'] + 1; }
|
|
$blob_table_temp_array = array('version_no' => $latest_version,'content' => $result_array[0]['content'],'fk_pd_id' => $pdid,'fk_createdby' => $fk_createdby);
|
|
|
|
$id = $this->PD_Model->saveRecords($blob_table_temp_array,PDREPORTSVERSIONBLOB);
|
|
|
|
|
|
|
|
//call all reports functionality and send it.
|
|
$key = 'pd'.$pdid.'/pd_reports/';
|
|
$urls = $this->getALLPDReportsSingedURLs($bucketname,$key,$pdid);
|
|
|
|
if($id != null || $id != "" )
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $urls;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'Something Went Wrong..!Try later';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************************************
|
|
*********************************************************************************************/
|
|
public function saveNewVersionOfPDReport_post()
|
|
{
|
|
|
|
|
|
$records = $this->post('records');
|
|
$pdid = $records['pd_id'];
|
|
$blob = $records['content'];
|
|
$fk_updatedby = $records['fk_updatedby'];
|
|
$fk_createdby = $records['fk_createdby'];
|
|
//Get PD Master Details
|
|
$pd_master_details = $this->PD_Model->getPDMasterDetails($pdid);
|
|
$main_applicant_name = $pd_master_details[0]['main_applicant'];
|
|
//print_r($pd_master_details);
|
|
|
|
//update BLOB in pd trigger Table
|
|
$latest_version = $pd_master_details[0]['pd_report_latest_version'];
|
|
$where_condition_array = array('pd_id' => $pdid);
|
|
$temp_array = array('pd_report_latest_version_blob' => $blob,'fk_updatedby' => $fk_updatedby);
|
|
$mas_id = $this->PD_Model->updateRecords($temp_array,PDTRIGGER,$where_condition_array);
|
|
|
|
|
|
//store BLOB in t_pd_reports_version_blob Table
|
|
//$latest_version = $pd_master_details[0]['pd_report_latest_version'] + 1;
|
|
//$where_condition_array = array('pd_id' => $pdid);
|
|
$temp_array_one = array('content' => $blob,'fk_updatedby'=>$fk_updatedby);
|
|
$where_condition_array = array('fk_pd_id' => $pdid,'version_no' => $latest_version);
|
|
$id = $this->PD_Model->updateRecords($temp_array_one,PDREPORTSVERSIONBLOB,$where_condition_array);
|
|
|
|
//convert BLOB as html then pdf then store it s3.
|
|
$output_file = APPPATH."/docs/temp.html";
|
|
$ifp = fopen( $output_file, 'wb' );
|
|
//fwrite( $ifp, $original_template );
|
|
fwrite( $ifp, $blob );
|
|
fclose( $ifp );
|
|
//print_r($output_file);
|
|
$file= file_get_contents($output_file);
|
|
$pdf_doc = $this->pdfgenerator->generate($file, $filename='version', $stream=false, $paper = 'A4', $orientation = "portrait");
|
|
//print_r($pdf_doc);
|
|
|
|
|
|
$output_file2 = APPPATH."/docs/sample.pdf";
|
|
if(file_put_contents($output_file2, $pdf_doc))
|
|
{
|
|
$bucketname = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['fk_lender_id'];
|
|
$key = 'pd'.$pdid.'/pd_reports/'.$main_applicant_name.'_version'.$latest_version.'.pdf';
|
|
$sourcefile = $output_file2;
|
|
|
|
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile);
|
|
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
|
//print_r($s3result);
|
|
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
|
|
{
|
|
|
|
$urls = $this->getALLPDReportsSingedURLs($bucketname,$key);
|
|
if($id != null || $id != "" )
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $urls;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'Something Went Wrong..!Try later';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
|
|
|
|
//End of convert BLOB as html then pdf then store it s3.
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/*********************************************************************************************
|
|
*********************************************************************************************/
|
|
public function getListOfPDReportVersions_post()
|
|
{
|
|
$records = $this->post('records');
|
|
|
|
$pdid = $records['pd_id'];
|
|
|
|
|
|
//Get PD Master Details
|
|
$pd_master_details = $this->PD_Model->getPDMasterDetails($pdid);
|
|
$main_applicant_name = $pd_master_details[0]['main_applicant'];
|
|
$lender_id = $pd_master_details[0]['fk_lender_id'];
|
|
|
|
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$lender_id;
|
|
$key = 'pd'.$pdid.'/pd_reports';
|
|
//$key = 'pd'.$pdid;
|
|
$urls = $this->getALLPDReportsSingedURLs($bucket_name,$key,$pdid);
|
|
|
|
if(count($urls))
|
|
{
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $urls;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'PD Report Not Generated';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/*********************************************************************************************
|
|
*********************************************************************************************/
|
|
public function getALLPDReportsSingedURLs($bucket_name,$key,$pdid)
|
|
{
|
|
|
|
//Get Blob version
|
|
$fields = array('version_no','concat(USERPROFILE.first_name,USERPROFILE.last_name) as createdby','DATE_FORMAT(PDREPORTSVERSIONBLOB.createdon,"%d %b %Y at %h:%i:%s %p") as createdon','PDREPORTSVERSIONBLOB.fk_createdby');
|
|
$where_condition_array = array('fk_pd_id'=>$pdid);
|
|
$table = PDREPORTSVERSIONBLOB.' as PDREPORTSVERSIONBLOB';
|
|
$joins = array( array('table' => USERPROFILE. ' as USERPROFILE',
|
|
'condition' =>'PDREPORTSVERSIONBLOB.fk_createdby = USERPROFILE.userid',
|
|
'jointype' => 'INNER')
|
|
|
|
);
|
|
|
|
//Get Max No of blob version
|
|
$max_version = $this->db->SELECT('MAX(version_no) as max_version')->FROM(PDREPORTSVERSIONBLOB)->WHERE('fk_pd_id',$pdid)->GET()->result_array();
|
|
|
|
$blob_versions = $this->PD_Model->getJoinRecords($fields,$table,$joins,$where_condition_array);
|
|
|
|
//print_r($max_version);
|
|
$all_objects = $this->aws_s3->getAllObjectsInaBucket($bucket_name,$key);
|
|
$uri = array();
|
|
foreach($all_objects as $obj)
|
|
{
|
|
//print_r($obj);
|
|
$uri[]['doc_name'] = $obj['Key'];
|
|
}
|
|
//print_r($uri);
|
|
if(count($uri))
|
|
{
|
|
|
|
foreach($uri as $uri_key => $url)
|
|
{
|
|
$uri[$uri_key]['doc_uri'] = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$url['doc_name'],$time = '3600 seconds');
|
|
//echo $key;
|
|
$uri[$uri_key]['doc_name'] = str_replace($key.'/',"",$uri[$uri_key]['doc_name']);
|
|
|
|
//find version no from file
|
|
$version_no = 0;
|
|
|
|
if(is_numeric(substr($uri[$uri_key]['doc_name'],-7,3)))
|
|
{
|
|
$version_no = substr($uri[$uri_key]['doc_name'],-7,3);
|
|
|
|
}
|
|
else if(is_numeric(substr($uri[$uri_key]['doc_name'],-6,2)))
|
|
{
|
|
$version_no = substr($uri[$uri_key]['doc_name'],-6,2);
|
|
|
|
}else if(is_numeric(substr($uri[$uri_key]['doc_name'],-5,1)))
|
|
{
|
|
$version_no = substr($uri[$uri_key]['doc_name'],-5,1);
|
|
}
|
|
|
|
$uri[$uri_key]['version'] = (int)$version_no;
|
|
|
|
if(count($blob_versions))
|
|
{
|
|
foreach($blob_versions as $blob_key => $blob)
|
|
{
|
|
if($blob['version_no'] == $version_no)
|
|
{
|
|
$uri[$uri_key]['createdby'] = $blob['createdby'];
|
|
$uri[$uri_key]['createdon'] = $blob['createdon'];
|
|
}
|
|
$uri[$uri_key]['is_latest'] = 0;
|
|
if(($blob['version_no'] == $max_version[0]['max_version']) &&($version_no == $max_version[0]['max_version']))
|
|
{
|
|
$uri[$uri_key]['is_latest'] = 1;
|
|
}
|
|
}
|
|
}
|
|
// if($uri_key == (count($uri)-1))
|
|
// {
|
|
// $uri[$uri_key]['is_latest'] = 1;
|
|
// }else
|
|
// {
|
|
// $uri[$uri_key]['is_latest'] = 0;
|
|
// }
|
|
}
|
|
}
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
|
|
/*********************************************************************************************
|
|
*********************************************************************************************/
|
|
public function getTypeOfActivetyFromBusinessForm_post()
|
|
{
|
|
|
|
$records = $this->post('records');
|
|
$pdid = $records['pd_id'];
|
|
|
|
// $fields = array('column_name', 'column_value');
|
|
// $where_condition_array = array('column_name'=>'type_of_activity','isactive'=>1,'fk_form_id'=>13,'fk_pd_id'=>$pdid);
|
|
// $or_where_total = array(array('column_name'=>'profession_name'));
|
|
// $result_array = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDFORMDETAILS,$or_where_total);
|
|
|
|
$this->db->SELECT('column_name,column_value');
|
|
$this->db->FROM(PDFORMDETAILS);
|
|
$this->db->WHERE('isactive',1);
|
|
$this->db->WHERE('fk_form_id',13);
|
|
$this->db->WHERE('fk_pd_id',$pdid);
|
|
$this->db->GROUP_START();
|
|
$this->db->OR_WHERE('column_name','type_of_activity');
|
|
$this->db->OR_WHERE('column_name','profession_name');
|
|
$this->db->GROUP_END();
|
|
$result_array = $this->db->GET()->result_array();
|
|
|
|
//print_r($this->db->last_query());
|
|
|
|
if(count($result_array))
|
|
{
|
|
$final_data = array();
|
|
foreach($result_array as $res_key => $res)
|
|
{
|
|
if($res['column_name'] == 'profession_name')
|
|
{
|
|
$final_data['profession_name'] = $res['column_value'];
|
|
}
|
|
else
|
|
{
|
|
$final_data['type_of_activity'][] = $res['column_value'];
|
|
}
|
|
}
|
|
//print_r($final_data);
|
|
|
|
foreach($final_data['type_of_activity'] as $f_key => $f_value)
|
|
{
|
|
$fields = array('name');
|
|
$where_condition_array = array('type_of_activity_id'=>$f_value,'isactive'=>1);
|
|
$result = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,TYPEOFACTIVITY);
|
|
$final_data['type_of_activity'][$f_key] = array('type_of_activity_id' => $f_value,'name' =>$result[0]['name']);
|
|
}
|
|
|
|
if(count($final_data))
|
|
{
|
|
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $final_data;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = "Fill Business Details First/ No Data Available!";
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/*********************************************************************************************
|
|
*********************************************************************************************/
|
|
|
|
public function swapOlderPDReporttoLatest_post()
|
|
{
|
|
$records = $this->post('records');
|
|
|
|
$pdid = $records['pd_id'];
|
|
|
|
$pd_master_details = $this->PD_Model->getPDMasterDetails($pdid);
|
|
$main_applicant_name = $pd_master_details[0]['main_applicant'];
|
|
$doc_name = $records['doc_name'];
|
|
$fk_createdby = $records['fk_createdby'];
|
|
|
|
$version_no = "";
|
|
|
|
if(is_numeric(substr($doc_name,-7,3)))
|
|
{
|
|
$version_no = substr($doc_name,-7,3);
|
|
|
|
}
|
|
else if(is_numeric(substr($doc_name,-6,2)))
|
|
{
|
|
$version_no = substr($doc_name,-6,2);
|
|
|
|
}else if(is_numeric(substr($doc_name,-5,1)))
|
|
{
|
|
$version_no = substr($doc_name,-5,1);
|
|
}
|
|
else
|
|
{
|
|
$version_no = 1;
|
|
}
|
|
|
|
//Get Latest Version from PD Master Table
|
|
$pd_master_details = $this->PD_Model->getPDMasterDetails($pdid);
|
|
|
|
//Get Blob from blob table
|
|
$fields = array('content');
|
|
$where_condition_array = array('fk_pd_id'=>$pdid,'version_no'=>$version_no);
|
|
$result = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDREPORTSVERSIONBLOB);
|
|
|
|
if(count($result))
|
|
{
|
|
$temp_array = array('content' => $result[0]['content'],'fk_pd_id'=> $pdid,'fk_createdby'=>$fk_createdby,'version_no' => ($pd_master_details[0]['pd_report_latest_version'] + 1));
|
|
$id = $this->PD_Model->saveRecords($temp_array,PDREPORTSVERSIONBLOB);
|
|
|
|
if($id != null || $id != "")
|
|
{
|
|
$temp_array = array('pd_report_latest_version_blob' => $result[0]['content'],'pd_report_latest_version' => ($pd_master_details[0]['pd_report_latest_version'] + 1));
|
|
|
|
$where_condition_array = array('pd_id'=>$pdid);
|
|
$master_result = $this->PD_Model->updateRecords($temp_array,PDTRIGGER,$where_condition_array);
|
|
|
|
if($master_result != null || $master_result != "")
|
|
{
|
|
//do doc renegerate things here.....
|
|
|
|
$output_file = APPPATH."/docs/temp.html";
|
|
$ifp = fopen( $output_file, 'wb' );
|
|
//fwrite( $ifp, $original_template );
|
|
fwrite( $ifp, $result[0]['content'] );
|
|
fclose( $ifp );
|
|
//print_r($output_file);
|
|
$file= file_get_contents($output_file);
|
|
$pdf_doc = $this->pdfgenerator->generate($file, $filename='version', $stream=false, $paper = 'A4', $orientation = "portrait");
|
|
//print_r($pdf_doc);
|
|
|
|
|
|
$output_file2 = APPPATH."/docs/sample.pdf";
|
|
if(file_put_contents($output_file2, $pdf_doc))
|
|
{
|
|
$bucketname = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['fk_lender_id'];
|
|
$key = 'pd'.$pdid.'/pd_reports/'.$main_applicant_name.'_version'.($pd_master_details[0]['pd_report_latest_version'] + 1).'.pdf';
|
|
$sourcefile = $output_file2;
|
|
|
|
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile);
|
|
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
|
|
|
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
|
|
{
|
|
|
|
$urls = $this->getALLPDReportsSingedURLs($bucketname,$key);
|
|
if($id != null || $id != "" )
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $urls;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'Something Went Wrong..!Try later';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'Version Not Updated in Master Table! Contact System Admin';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'Version Not Updated!';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
$data['msg'] = 'No older Version Available for this PD!';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/*********************************************************************************************
|
|
*********************************************************************************************/
|
|
|
|
|
|
public function smartyTestFunction_post()
|
|
{
|
|
|
|
|
|
$this->smarty->assign('title','Test Title');
|
|
$this->smarty->assign('description', 'Test Description');
|
|
//$this->smarty->display('index.tpl');
|
|
$data['pdif'] = '10';
|
|
$data['main_applicant_name'] = 'Mr.Ram Kumar';
|
|
$data['cus_seg'] = 'SENP-AI';
|
|
$data['lender_name'] = 'HDFC';
|
|
$data['product'] = 'Home Loan';
|
|
$data['type_of_activity'] = 'Manufacturing';
|
|
$data['applicants'] = array(array('name' => 'Rajesh Kumar','age' => '56'),array('name' => 'santhosh Kumar','age' => '45'));
|
|
$this->smarty->assign("FirstName", array("John", "Mary", "James", "Henry"));
|
|
$fin = $this->smarty->view('index.tpl' , $data);
|
|
|
|
// echo "CON";
|
|
print_r($fin);
|
|
|
|
// $temp_array = array('content' => $fin,'fk_pd_id'=> 555);
|
|
// $id = $this->PD_Model->saveRecords($temp_array,PDREPORTSVERSIONBLOB);
|
|
|
|
// $data['dataStatus'] = true;
|
|
// $data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
|
// $data['msg'] = $fin;
|
|
// $this->response($data,REST_Controller::HTTP_OK);
|
|
|
|
$output_file = APPPATH."/docs/temp.html";
|
|
$ifp = fopen( $output_file, 'wb' );
|
|
//fwrite( $ifp, $original_template );
|
|
fwrite( $ifp, $fin );
|
|
fclose( $ifp );
|
|
//print_r($output_file);
|
|
$file= file_get_contents($output_file);
|
|
$pdf_doc = $this->pdfgenerator->generate($file, $filename='version', $stream=false, $paper = 'A4', $orientation = "portrait");
|
|
//print_r($pdf_doc);
|
|
|
|
|
|
$output_file2 = APPPATH."/docs/sample.pdf";
|
|
echo file_put_contents($output_file2, $pdf_doc);
|
|
|
|
|
|
}
|
|
|
|
|
|
public function codeigniterViewTest_post()
|
|
{
|
|
|
|
$data['pdid'] = '1256';
|
|
$data['main_applicant_name'] = 'Mr.Ram Kumar';
|
|
$data['cus_seg'] = 'SENP-AI';
|
|
$data['lender_name'] = 'HDFC';
|
|
$data['product'] = 'Home Loan';
|
|
$data['sub_product'] = 'Home Resale';
|
|
$data['type_of_activity'] = 'Manufacturing';
|
|
$data['applicants'] = array(
|
|
array('name' => 'Rajesh Kumar','age' => '56','relation'=>'Brother','es'=>'Salaried','cn'=>'TCS'),
|
|
array('name' => 'santhosh Kumar','age' => '45','relation'=>'Brother','es'=>'Selfemployee','cn'=>'ABC Pvt Ltd'),
|
|
array('name' => 'Jiv Kumar','age' => '65','relation'=>'Father','es'=>'No','cn'=>'-'),
|
|
array('name' => 'Selvi','age' => '60','relation'=>'Mother','es'=>'Housewife','cn'=>'-'),
|
|
);
|
|
$t = $this->load->view('report_templates/SALCASH',$data,true);
|
|
//print_r($t);
|
|
|
|
//PDF Gen using DOM PDF
|
|
$pdf_doc = $this->pdfgenerator->generate($t, $filename='version', $stream=false, $paper = 'A4', $orientation = "portrait");
|
|
//End of PDF Gen using DOM PDF
|
|
|
|
|
|
|
|
$output_file2 = APPPATH."/docs/sample.pdf";
|
|
echo file_put_contents($output_file2, $pdf_doc);
|
|
|
|
// echo $ci_instant;
|
|
}
|
|
|
|
public function calculatePDScore($pd_form_raw_data)
|
|
{
|
|
echo "calculatePDScore";
|
|
print_r($pd_form_raw_data);
|
|
//die();
|
|
echo "calculatePDScore\n\n\n\n";
|
|
|
|
|
|
}
|
|
|
|
} |