array('Person met', '18', 0, 0), 'person_met_id' => array('Person met ID Proof', '18', 0, 0), 'address_proof_visited' => array('Address Proof', '5', 0, 0), 'name_board_seen' => array('Name Board Seen', '13', 0, 0), 'machinery_image' => array('Machinery Image', '22', 0, 0), 'gst_Regn_cert_pic' => array('GST Regn Cert', '13', 0, 0), 'pf_regn_pic' => array('PF Regn', '13', 0, 0), 'esic_regn_pic' => array('ESIC Regn', '13', 0, 0), 'export_import_cert_pic' => array('Export Import Cert', '13', 0, 0), 'factory_cert_pic' => array('Factory Cert', '13', 0, 0), 'shop_eat_act_cert_pic' => array('Shop Est Act Cert', '13', 0, 0), 'eb_bill_pic' => array('EB Bill', '13', 0, 0), 'practice_cert_pic' => array('Cert of Practice', '13', 0, 0), 'fire_noc_pic' => array('Fire NOC', '13', 0, 0), 'stock_image' => array('Stock image', '11', 1, 1), 'client_image' => array('Client Bills', '2', 1, 1), 'supplier_image' => array('Supplier Bills', '1', 1, 1), 'office_setup' => array('Office/Business Setup', '13', 1, 1), 'additional_photos' => array('Additional Photographs', '13', 1, 1),'Video' => array('Video', null, 1, 1));
private $existing_imges = array();
function __construct()
{
// Construct the parent class
parent::__construct();
$this->external_path = $this->config->item('external_data_path');
$this->load->model('PD_Model');
$this->load->library('AWS_S3');
$this->load->library('AWS_COGNITO');
$this->load->library('AWS_SNS');
$this->load->helper('GETPDFORMDETAILS');
$this->load->helper('GETPROCESSEDJSON');
$this->load->helper('MYUTIL');
$this->load->helper('satellite_image');
$this->load->library('pdfgenerator');
$this->load->helper('faceapi');
//$this->load->library('excel');
$this->load->library('phpmailer_library');
}
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:i:s');
$ifp = fopen($output_file, 'wb');
// split the string on commas
// $data[ 0 ] == "data:image/png;base64"
// $data[ 1 ] ==
$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, array(), '', 'full_name');
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);
$fields = array('entity_lender_branch_id', 'branch_name');
$where_condition_array = array('fk_entity_id' => $value['entity_id'], 'isactive' => 1);
$result_data[$key]['branches'] = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, ENTITYLENDERBRANCH);
}
$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 Vendor Details for allocation************************/
public function getListOfvendors_get()
{
$fields = array('entity_id', 'full_name', 'short_name');
$where_condition_array = array('isactive' => 1, 'fk_entity_type_id' => 3);
if ($this->get('vendor_name')) {
$where_condition_array['full_name like'] = '%' . $this->get('vendor_name') . '%';
}
//if($this->get('location')){$where_condition_array['location like'] = '%'.$this->get('vendor_name').'%';}
//print_r($where_condition_array);die();
//die();
$result_data = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, ENTITY);
// if()
// {
// }
//print_r($this->db->last_query());
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);
// $fields = array('entity_lender_branch_id', 'branch_name');
// $where_condition_array = array('fk_entity_id' => $value['entity_id'],'isactive'=>1);
// $result_data[$key]['branches'] = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,ENTITYLENDERBRANCH);
// }
$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 Vendor Details for allocation************************/
public function getListVendorPDOfficers_get()
{
$fk_entity_id = $this->uri->segment(2); //die();
$columns = array('USERPROFILE.userid', 'concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as officer_name', 'USERPROFILE.email', 'USERPROFILE.mobile_no', 'USERPROFILEROLES.user_role');
$table = USERPROFILE . ' as USERPROFILE';
$joins = array(array(
'table' => USERPROFILEROLES . ' as USERPROFILEROLES',
'condition' => 'USERPROFILE.userid = USERPROFILEROLES.fk_userid AND USERPROFILEROLES.isactive = 1 AND USERPROFILEROLES.user_role = 22',
'jointype' => 'INNER'
));
$where_condition_array = array('USERPROFILE.fk_entity_id' => $fk_entity_id);
$vendor_officer_details = $this->PD_Model->getJoinRecords($columns, $table, $joins, $where_condition_array);
if (count($vendor_officer_details)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $vendor_officer_details;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'No Officers Found...!';
$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', 'prod_catagory');
$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', 'is_others');
$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 and Pincodes Details for PD Trigger Page*********/
public function getListOfStatesAndCities_post()
{
$records = $this->post('records');
$stateid = $records['state_id'];
// $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);
$fields = array('city_id', 'name as city_name');
$where_condition_array = array('isactive' => 1, 'fk_state_id' => $stateid);
$cities = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, CITY);
//array_push($result_data[$key],$cities);
$result_data['cities'] = $cities;
// $fields = array('pincode_id','pincode');
// $where_condition_array = array('isactive' => 1,'fk_state_id' => $stateid);
// $pincode = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PINCODE);
//echo "sds";
$pincode = $this->db->DISTINCT()->SELECT('pincode,pincode_id')->FROM(PINCODE)->WHERE('fk_state_id', $stateid)->OR_WHERE('fk_state_id is null')->ORDER_BY('is_others')->GROUP_BY('pincode')->ORDER_BY('pincode')->GET()->result_array();
//print_r($this->db->last_query());
$result_data['pincode'] = $pincode;
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result_data;
$this->response($data, REST_Controller::HTTP_OK);
}
//For RI form list display
public function getStateCityNamesAndPincode_post()
{
$records = $this->post('records');
//get state name
$fields = array('name as state_name');
$where_condition_array = array('isactive' => 1, 'state_id' => $records['state_id']);
$state = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, STATE);
//get city name
$fields = array('name as city_name');
$where_condition_array = array('isactive' => 1, 'city_id' => $records['city_id']);
$city = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, CITY);
//get pincode
$fields = array('pincode');
$where_condition_array = array('isactive' => 1, 'pincode_id' => $records['pincode_id']);
$pincode = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PINCODE);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = array('state_name' => $state[0]['state_name'], 'city_name' => $city[0]['city_name'], 'pincode' => $pincode[0]['pincode']);
$this->response($data, REST_Controller::HTTP_OK);
}
/********************Get get List Of States and Cities Name only for Business form *********/
public function getListOfStatesCities_post()
{
$records = $this->post('records');
$stateid = $records['state_id'];
$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 => $res) {
// $fields = array('city_id','name as city_name');
// $where_condition_array = array('isactive' => 1,'fk_state_id' => $res['state_id']);
// $cities = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,CITY);
//array_push($result_data[$key],$cities);
$cities = $this->db->DISTINCT()->SELECT('city_id,name as city_name')->FROM(CITY)->WHERE('fk_state_id', $res['state_id'])->OR_WHERE('fk_state_id is null')->ORDER_BY('fk_state_id,city_name')->GET()->result_array();
$result_data[$key]['cities'] = $cities;
//print_r($this->db->last_query());
// $fields = array('pincode_id','pincode');
// $where_condition_array = array('isactive' => 1,'fk_state_id' => $stateid);
// $pincode = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PINCODE);
// //array_push($result_data[$key],$cities);
// $result_data['pincode'] = $pincode;
}
}
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result_data;
$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();
$docs_to_be_collected = array();
unset($pd_details['createdon']);
$addresses = array();
$company = array();
if ($this->post('addtional_requirements')) {
$pd_addtional_requirements = json_decode($this->post('addtional_requirements'), true);
}
if ($this->post('docs_to_be_collected')) {
$docs_to_be_collected = json_decode($this->post('docs_to_be_collected'), true);
}
if ($this->post('addresses')) {
$addresses = json_decode($this->post('addresses'), true);
}
if ($this->post('company')) {
$company = json_decode($this->post('company'), 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)) // CHOOSE FILTERED TEMPLATE//
{
$pd_details['fk_pd_template_id'] = $choosed_template_id[0]['fk_template_id'];
} else // CHOOSE GENERIC TEMPLATE//
{
//get customer segment abbrvations
$customer_segment_abbr = $this->PD_Model->selectCustomRecords(array('*'), array('customer_segment_id' => $pd_details['fk_customer_segment'], 'isactive' => 1), CUSTOMERSEGMENT);
//print_r($this->db->last_query());die();
$customer_segment_abbr = $customer_segment_abbr[0]['abbr'];
//echo $customer_segment_abbr;
if (!strcasecmp($customer_segment_abbr, 'SAL')) // || !strcasecmp($customer_segment_abbr,'SAL-CHQ'))
{
//SAL - (CASH/CHQ)
$pd_details['fk_pd_template_id'] = 1;
} else if (!strcasecmp($customer_segment_abbr, 'SE-DI') || !strcasecmp($customer_segment_abbr, 'SEP-DI') || !strcasecmp($customer_segment_abbr, 'SEP_INDV')) {
//* SENP/SEP - (DI)
$pd_details['fk_pd_template_id'] = 2;
} else if (!strcasecmp($customer_segment_abbr, 'SE-AI') || !strcasecmp($customer_segment_abbr, 'SEP-AI')) {
//* SENP/SEP - (DI)
$pd_details['fk_pd_template_id'] = 3;
} else if (!strcasecmp($customer_segment_abbr, 'SE-RI')) {
//* SENP/SEP - (RI)
$pd_details['fk_pd_template_id'] = 4;
}
}
}
// /ie();
/***********************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");
//Generate Random string
/************ASSIGN Random URL******************/
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < 16; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
$pd_details['random_string'] = $randomString;
$url = OFFICER_TRACKING_URL . $randomString;
/* $ch = curl_init();
$timeout = 5;
$url = 'https://ssa.sineedge.com/ot/#/officertracking/'.$randomString;
//echo "$url";
curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$tinyurl = curl_exec($ch);
curl_close($ch); */
$pd_details['encrypted_url'] = $url;
//echo $tinyurl;
/************ASSIGN Random URL******************/
//End of Generate Random string
//implement SMC related stuffs
if ($pd_details['pd_status'] == TRIGGERED) {
$pd_details = $this->smcStuffs($pd_details);
}
// echo 'final';
// die();
$pd_details['parent_pd_id'] = isset($pd_details['parent_pd_id']) ? $pd_details['parent_pd_id'] : NULL;
// $lender_id = ENVIRONMENT == 'production' ? 6 : 37; // IndusInd Bank Limited lender means notify enabled.
// if($pd_details['fk_lender_id'] == $lender_id){
// // $pd_details['is_notify_enabled'] = isset($pd_details['is_notify_enabled']) ? (!is_null($pd_details['is_notify_enabled']) ? $pd_details['is_notify_enabled'] : 1) : 1;
// $pd_details['is_notify_enabled'] = 1;
// }
$lender_short_name = $this->PD_Model->selectCustomRecords(array('*'), array('entity_id' => $pd_details['fk_lender_id'], 'isactive' => 1), ENTITY);
$lender_short_name = $lender_short_name[0]['short_name'];
$pd_details['is_notify_enabled'] = isset($pd_details['is_notify_enabled'])
? (!is_null($pd_details['is_notify_enabled']) ? $pd_details['is_notify_enabled'] : 1 )
: ($lender_short_name == 'IIB' ? 0 : 1 );
if($lender_short_name == 'IIB'){
// IIB means 0
$pd_details['is_notify_enabled'] = 0;
}else{
if(isset($pd_details['is_notify_enabled']) && (!is_null($pd_details['is_notify_enabled']))){
$pd_details['is_notify_enabled'] = $pd_details['is_notify_enabled'];
}
else{
// Default 1
$pd_details['is_notify_enabled'] = 1;
}
}
$pd_id = $this->PD_Model->saveRecords($pd_details, PDTRIGGER);
/***********************PD DOCUMENTS UPLOAD SECTION FROM WEB***********/
if ($pd_id != null || $pd_id != '') {
// if it is SMC PD check excel file id , if not store address in smc address
// temprary table against pd id
if (!isset($pd_details[0]['excel_file_id'])) // && $pd_details[0]['excel_file_id'] != '')
{
$this->saveSMCTempAddress($pd_id, $addresses);
}
//If PD created sucessfully then create a externa folder named with pd_id
if (!file_exists($this->external_path . '/pd_reports/' . $pd_id)) {
mkdir($this->external_path . '/pd_reports/' . $pd_id, 0777);
}
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, 'img_type' => 3, '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 ($pd_applicant_details != "" || $pd_applicant_details != null) {
foreach ($pd_applicant_details as $pd_applicant_detail) {
$pd_applicant_detail['fk_pd_id'] = $pd_id;
$pd_applicant_detail['applicant_name'] = trim(MYUTIL::applicantNameCamelCaseConvertion($pd_applicant_detail['applicant_name']));
$pd_applicant_detail['company_name'] = trim(MYUTIL::applicantNameCamelCaseConvertion($pd_applicant_detail['company_name']));
$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)) {
$this->saveBase64Images($pd_id, null, null, null, $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:i: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) {
if ($pd_addtional_requirement['add_requirement'] != null) {
$pd_addtional_requirement['fk_pd_id'] = $pd_id;
$this->PD_Model->saveRecords($pd_addtional_requirement, PDADDTIONALREQUIREMENTS);
}
}
}
if (count($docs_to_be_collected)) {
foreach ($docs_to_be_collected as $docs_to_be_collected_key => $docs_to_be_collect) {
if ($docs_to_be_collect['doc_name'] != null) {
$docs_to_be_collect['fk_pd_id'] = $pd_id;
$this->PD_Model->saveRecords($docs_to_be_collect, PDDOCSTOBECOLLECTED);
}
}
}
$temp_address_id = null;
if (count($addresses)) {
foreach ($addresses as $address_key => $address) {
$address['fk_pd_id'] = $pd_id;
$address['is_primary'] = count($addresses) == 1 ? 1 : 0;
$address['assigned_pd'] = count($addresses) == 1 ? $pd_id : null;
$address_id = $this->PD_Model->saveRecords($address, PDADDRESS);
if ($address_key == 0) {
$temp_address_id = $address_id;
}
}
}
//update parent pd id for same pd itself after PK generated
$temp = array('parent_pd_id' => $pd_id);
if (count($addresses) == 1) {
$temp['fk_primary_address_id'] = $temp_address_id;
$temp['fk_address_id'] = $temp_address_id;
}
$where_condition_array = array('pd_id' => $pd_id);
$this->PD_Model->updateRecords($temp, PDTRIGGER, $where_condition_array);
if (count($company)) {
foreach ($company as $company_key => $new_company) {
$new_company['fk_pd_id'] = $pd_id;
$this->PD_Model->saveRecords($new_company, PDCOMPANY);
}
}
}
/****************END OF ADDTIONAL REQUIREMENTS SECTION*******************************************/
//create gmeet link
// if($pd_id != null && $pd_id != '' && ($pd_details['fk_pd_type'] == 2 || $pd_details['fk_pd_type'] == 3))
// {
// $this->createGmeetLink($pd_id);
// }
if ($pd_id != null || $pd_id != '' && $count != 0) {
// CALL pdnotification Helper function to send pd alerts @ params pdid,pdstatus
$logger = MYLOG::logFunction(null, $pd_id);
$logger->info("NEW PD Trigged : " . $pd_id, array('ENV' => ENVIRONMENT, 'DATA' => $pd_details));
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');
//print_r($records);die();
$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'] != "") // && ($pd_addtional_requirement['add_requirement'] != null) )
{
$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 {
if ($pd_addtional_requirement['add_requirement'] != null || $pd_addtional_requirement['add_requirement'] != "") {
$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);
}
}
public function savePDDocsToBeCollected_post()
{
$records = $this->post('records');
$docs_to_be_collected = $records['docs_to_be_collected'];
$count = 0;
if (count($docs_to_be_collected)) {
foreach ($docs_to_be_collected as $pd_doc_key => $pd_doc_requirement) {
if ($pd_doc_requirement['pd_doc_to_be_collect_id'] != null || $pd_doc_requirement['pd_doc_to_be_collect_id'] != "" && ($pd_doc_requirement['doc_name'] != null)) {
$where_condition_array = array('pd_doc_to_be_collect_id' => $pd_doc_requirement['pd_doc_to_be_collect_id']);
$pk_id = $this->PD_Model->updateRecords($pd_doc_requirement, PDDOCSTOBECOLLECTED, $where_condition_array);
if ($pk_id != "" || $pk_id != null) {
$count++;
}
} else {
if ($pd_doc_requirement['doc_name'] != null) {
$pd_doc_requirement['fk_pd_id'] = $records['pdid'];
$pk_id = $this->PD_Model->saveRecords($pd_doc_requirement, PDDOCSTOBECOLLECTED);
if ($pk_id != "" || $pk_id != null) {
$count++;
}
}
}
}
}
if ($count != 0 && $count == count($docs_to_be_collected)) {
$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 = [];
$exist_pd_details = [];
clearstatcache();
$pd_details = $this->post('records');
//print_r($pd_details);die();
$pd_cancel_remark = '';
log_message('ERROR', "UpdatePD Called");
// log_message('ERROR',print_r($pd_details));
if ((isset($pd_details['pd_id']) && $pd_details['pd_id'] != "") && (isset($pd_details['random_string']) && $pd_details['random_string'] != " ")) {
$logger = MYLOG::logFunction(null, $pd_details['pd_id']);
EXTERNAL_DIR_CHECK::checkExternalDirectory($pd_details['pd_id']);
$exist_pd_details = $this->PD_Model->getPDMasterDetails($pd_details['pd_id']);
// print_r($pd_details);
if (!file_exists($this->external_path . '/pd_reports/' . $pd_details['pd_id'])) {
mkdir($this->external_path . '/pd_reports/' . $pd_details['pd_id'], 0777);
}
if (isset($pd_details['pd_status']) && $pd_details['pd_status'] == INITIATED) {
unset($pd_details['mobile_no']);
unset($pd_details['firstName']);
unset($pd_details['officerName']);
$pd_details['initiate_location'] = isset($pd_details['link']) ? $pd_details['link'] : null;;
unset($pd_details['link']);
}
if (isset($pd_details['pd_status']) && $pd_details['pd_status'] == STARTED) {
// echo 'STARTED';
if ($exist_pd_details[0]['fk_pd_type'] == 1 || $exist_pd_details[0]['fk_pd_type'] == 4) {
$pd_details['start_location'] = $pd_details['link'];
}
unset($pd_details['link']);
$string2 = str_shuffle('1234567890');
$OTP = substr($string2, 0, 6);
$msg = "OTP 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;
//$pd_details['OTP'] = '123456';
// $client = new \GuzzleHttp\Client();
// $response = $client->post($url);
if ($exist_pd_details[0]['is_otp_enabled'] == 1) {
SMS_GUPSHUP::sendSMS($msg, $no, array('pd_id' => $pd_details['pd_id'], 'status' => 'STARTED', 'msg' => 'Started OTP msg from PD controlller'));
}
// if($exist_pd_details[0]['fk_pd_type'] == 3)
// {
// // echo 'JBDJS';
// $msg = "Dear Applicant, Please click the link to upload the photographs. " . CUSTOMER_IMG_URL .$exist_pd_details[0]['random_string'];
// SMS_GUPSHUP::sendSMS($msg,$no,array('pd_id' => $exist_pd_details[0]['pd_id'],'status' => 'STARTED','msg' => 'Cus Link from PD controlller'));
// }
} // started if condition closed here.
// die();
if (isset($pd_details['pd_status']) && (($pd_details['pd_status'] == COMPLETED) || ($pd_details['pd_status'] == ADD_ON_PENDING))) {
if ($pd_details['pd_status'] == COMPLETED) {
$pd_details['complete_override_data'] = isset($pd_details['complete_override_data']) ? json_encode($pd_details['complete_override_data']) : null;
$pd_details['completed_on'] = date('Y-m-d H:i:s');
log_message('ERROR', "In PD Ctrl (When Completed status means calling to Make FaceBoundingBox fns below");
// $this->toMakeFaceBoundingBox($exist_pd_details);
$this->toMakeFaceBoundingBox($pd_details['pd_id'],$exist_pd_details[0]['fk_lender_id']);
if(isset($pd_details['is_this_smc_pd']) && $pd_details['is_this_smc_pd'] == 1 && $pd_details['pd_status'] == COMPLETED){
$this->load->helper('smc_creditpd');
if(isset($pd_details['random_string'])){
$random_string = $pd_details['random_string'];
}else{
$random_string = $this->PD_Model->selectCustomRecords(array('random_string'),array('pd_id' => $pd_details['pd_id']),PDTRIGGER);
$random_string = $random_string[0]['random_string'];}
$ZIP = smc_creditpd::covertSMCImgs2ZIP($pd_details['pd_id'],$random_string,array(),0);
log_message('ERROR','####COMPLETE SMC IMAGE ZIP = '.$ZIP);
$PDF = smc_creditpd::covertSMCImgs2PDF($pd_details['pd_id'],$random_string,array(),0);
log_message('ERROR','####COMPLETE SMC IMAGE PDF = '.$PDF);
unset($pd_details['is_this_smc_pd']);
}
}
if (array_key_exists('link', $pd_details)) {
$pd_details['complete_location'] = isset($pd_details['link']) ? $pd_details['link'] : null;
unset($pd_details['link']);
}
if ($pd_details['pd_status'] == COMPLETED) {
if (($exist_pd_details[0]['pd_status'] != COMPLETED) && ($exist_pd_details[0]['pd_status'] != QC_COMPLETED)) {
if ($exist_pd_details[0]['fk_pd_type'] != 2 && (!isset($pd_details['is_revert_status']))) {
$pd_details['pd_visit_date'] = date('Y-m-d H:i:s');
}
}
}
// else{
// $pd_details['pd_visit_date'] = $exist_pd_details[0]['pd_visit_date'];
// }
unset($pd_details['is_revert_status']);
//get satellite image blob and store it in DB
//$pd_details['satellite_image_base64_blob'] = $this->getSatelliteImage($pd_details['pd_id']);
if ($exist_pd_details[0]['fk_pd_type'] == 1) {
$pd_details['satellite_image_base64_blob'] = satellite_image::getSatelliteImage($pd_details['pd_id']);
}
//die();
//If it is Addtional PD ,then update 'COMPLETE' status for primary and all other addtional PD's
if ($exist_pd_details[0]['is_child'] == 1) {
//echo "child";
$all_pd_id = array();
//get all associated PD ID's from address table
$all_associated_addresses = $this->PD_Model->getPDAddress($exist_pd_details[0]['parent_pd_id']);
//print_r($all_associated_addresses);
if (count($all_associated_addresses)) {
foreach ($all_associated_addresses as $address) {
if ($address['assigned_pd'] != $pd_details['pd_id']) {
$all_pd_id[] = array('pd_id' => $address['assigned_pd'], 'pd_status' => COMPLETED, 'fk_updatedby' => $pd_details['fk_updatedby']);
}
}
}
//print_r($all_pd_id);
foreach ($all_pd_id as $single_pd) {
$this->PD_Model->updateRecords($single_pd, PDTRIGGER, array('pd_id' => $single_pd['pd_id']));
}
}
//print_r($pd_details);
}
//die();
if ((isset($pd_details['pd_status']) && $pd_details['pd_status'] == QC_COMPLETED)) {
$pd_details['is_cus_link_disabled'] = 1;
//call delete google calender event
$this->deleteCalenderEvent($exist_pd_details[0]['gmeet_id']);
}
if (isset($pd_details['pd_status']) && ($pd_details['pd_status'] == TRIGGERED || $pd_details['pd_status'] == INITIATED || $pd_details['pd_status'] == INPROGRESS)) {
/***********************CHOOSE PD TEMPALATE*********************/
$pd_details['fk_pd_template_id'] = $this->assignPDTempalate($pd_details['pd_id']);
//echo $pd_details['fk_pd_template_id'];
}
/*********************** vendor status if it is allocated to partner*********************/
if (isset($pd_details['pd_status']) && ($pd_details['pd_status'] == ALLOCATED_TO_FIA)) {
$pd_details['vendor_status'] = TRIGGERED;
}
//die();
$primary_address_id = null;
if ($exist_pd_details[0]['fk_primary_address_id'] == null && $exist_pd_details[0]['is_child'] == 0) //Master PD only
{
$primary_address_id = isset($pd_details['fk_primary_address_id']) ? $pd_details['fk_primary_address_id'] : null;
$pd_details['fk_address_id'] = $primary_address_id;
}
if ($exist_pd_details[0]['is_child'] == 0) {
if (isset($pd_details['parent_pd_id']) && ($pd_details['parent_pd_id'] == null || $pd_details['parent_pd_id'] == "")) {
$pd_details['parent_pd_id'] = $exist_pd_details[0]['pd_id'] != "" || $exist_pd_details[0]['pd_id'] != null ? $exist_pd_details[0]['pd_id'] : $pd_details['pd_id'];
}
}
// Before update if this is ssmart pd, then when vevndor status is completed but still pd status changing between to allocated or scheduling then keep
//main pd status as in progress
if ($exist_pd_details[0]['fk_pd_type'] == 2 && $exist_pd_details[0]['pd_status'] == INPROGRESS && $exist_pd_details[0]['vendor_status'] == COMPLETED && isset($pd_details['pd_status']) && ($pd_details['pd_status'] == ALLOCATED || $pd_details['pd_status'] == SCHEDULED)) {
$pd_details['pd_status'] == INPROGRESS;
}
if (isset($pd_details['pd_status']) && ($pd_details['pd_status'] == CANCELLED)) {
$pd_details['cancel_pd_remark'] = $pd_details['remark'];
unset($pd_details['remark']);
}
//if(isset($pd_details['pd_status']) && $pd_details['pd_status'] == BOUNCED || $pd_details['pd_status'] == TRIGGERED)
//{
//implement smc related stuffs
$pd_details = $this->smcStuffs($pd_details, $exist_pd_details);
//}
// echo 'after';
// print_r($pd_details);
// die();
$temp_data = $this->PD_Model->selectCustomRecords(array('pd_agency_id', 'fk_lender_id'), array('pd_id' => $pd_details['pd_id']), PDTRIGGER);
$agency_id = isset($pd_details['pd_agency_id']) ? $pd_details['pd_agency_id'] : $temp_data[0]['pd_agency_id'];
$mwise_lender_id = (ENVIRONMENT == 'production' ? 7 : 35);
$current_lender_id = (isset($pd_details['fk_lender_id']) && $pd_details['fk_lender_id'] != '' ? $pd_details['fk_lender_id'] : $temp_data[0]['fk_lender_id']);
$is_mwise_lender = ($current_lender_id == $mwise_lender_id ? true : false);
$this->load->model('User_Management_Model');
$user_details = $this->User_Management_Model->getUserDetails($pd_details['fk_updatedby']);
$role = $user_details['data'][0]['user_role'];
if ($is_mwise_lender && (!empty($agency_id)) && ($agency_id != null) && ((int)$agency_id != 0) && ($pd_details['pd_status'] == "TRIGGERED") && ($role == 30)) {
$pd_details['vendor_status'] = null;
$pd_details['pd_agency_id'] = null;
$pd_details['pd_status'] = $pd_details['pd_status'];
}
if ($is_mwise_lender && (!empty($agency_id)) && ($agency_id != null) && ((int)$agency_id != 0) && ($pd_details['pd_status'] != "TRIGGERED" || $pd_details['pd_status'] != "QC_COMPLETED")) {
//newly implemented
if (($pd_details['pd_status'] == "CANCELLED") && ($role == 27 || $role == 26 || $role == 30)) {
$pd_details['vendor_status'] = null;
$pd_details['pd_agency_id'] = null;
$pd_details['pd_status'] = $pd_details['pd_status'];
} else {
$pd_details['vendor_status'] = $pd_details['pd_status'];
$pd_details['pd_status'] = ALLOCATED_TO_FIA;
}
}
$where_condition_array = array('pd_id' => $pd_details['pd_id'], 'random_string' => $pd_details['random_string']);
$pd_id_modified = $this->PD_Model->updateRecords($pd_details, PDTRIGGER, $where_condition_array);
// print_r($this->db->last_query());
//update pd cancel remrks if any
if ($pd_cancel_remark) {
$this->PD_Model->saveRecords(array('fk_pd_id' => $pd_details['pd_id'], 'remark' => $pd_cancel_remark, 'createdby' => $pd_details['fk_updatedby'],), PDREMARKS);
}
//Update Address table,if primary address choosed
if ($primary_address_id != null) {
$where_condition_array = array('pd_address_id' => $primary_address_id);
$temp_data = array('is_primary' => 1, 'assigned_pd' => $pd_details['pd_id']);
$id = $this->PD_Model->updateRecords($temp_data, PDADDRESS, $where_condition_array);
}
if ($pd_id_modified != null || $pd_id_modified != '' && $count != 0) {
$logger->info("PD UPDATED", array('ENV' => ENVIRONMENT, 'DATA' => $pd_details, 'Pre-Status' => $exist_pd_details[0]['pd_status'], 'Current_status' => isset($pd_details['pd_status']) ? $pd_details['pd_status'] : ''));
if (isset($pd_details['pd_status'])) {
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);
}
} //end of normal PD
else //#################### Handle Addtional PD
{
//echo 'else';
if (($pd_details['parent_pd_id'] != "" || $pd_details['parent_pd_id'] != null) &&
(($pd_details['fk_customer_segment'] != "" || $pd_details['fk_customer_segment'] != null)) &&
(($pd_details['fk_address_id'] != "" || $pd_details['fk_address_id'] != null)) &&
(($pd_details['pd_status'] != "" || $pd_details['pd_status'] != null)) &&
(($pd_details['fk_updatedby'] != "" || $pd_details['fk_updatedby'] != null))
) {
//GET PArent PD Details
$parent_pd_details = $this->PD_Model->getPDMasterDetails($pd_details['parent_pd_id']);
if (count($parent_pd_details)) {
$newpd['fk_lender_id'] = $parent_pd_details[0]['fk_lender_id'];
$newpd['pd_date_of_initiation'] = date('Y-m-d H-i-s');
$newpd['fk_entity_billing_id'] = $parent_pd_details[0]['fk_entity_billing_id'];
$newpd['lender_applicant_id'] = $parent_pd_details[0]['lender_applicant_id'];
$newpd['fk_product_id'] = $parent_pd_details[0]['fk_product_id'];
$newpd['fk_subproduct_id'] = $parent_pd_details[0]['fk_subproduct_id'];
$newpd['fk_pd_type'] = $parent_pd_details[0]['fk_pd_type'];
$newpd['pd_branch_id'] = $parent_pd_details[0]['pd_branch_id'];
$newpd['is_child'] = 1;
$newpd['loan_amount'] = $parent_pd_details[0]['loan_amount'];
$newpd['fk_pd_allocated_to'] = $parent_pd_details[0]['fk_pd_allocated_to'];
$newpd['pd_status'] = $pd_details['pd_status'];
$newpd['fk_updatedby'] = $pd_details['fk_updatedby'];
$newpd['fk_customer_segment'] = $pd_details['fk_customer_segment'];
$newpd['fk_address_id'] = $pd_details['fk_address_id'];
$newpd['parent_pd_id'] = $pd_details['parent_pd_id'];
//Generate Random string
/************ASSIGN Random URL******************/
$newpd['random_string'] = $parent_pd_details[0]['random_string'];
$url = OFFICER_TRACKING_URL . $randomString;
$newpd['encrypted_url'] = $url;
$newpd['fk_pd_template_id'] = $this->assignPDTempalate(array('lender' => $newpd['fk_lender_id'], 'product' => $newpd['fk_product_id'], 'customer_segment' => $newpd['fk_customer_segment']));
//print_r($newpd);die();
$pd_id = $this->PD_Model->saveRecords($newpd, PDTRIGGER);
if ($pd_id != "" || $pd_id != null) {
if (!file_exists($this->external_path . '/pd_reports/' . $pd_id)) {
mkdir($this->external_path . '/pd_reports/' . $pd_id, 0777);
}
//update Applicant details
$fields = array('pd_co_applicant_id' => $pd_details['pd_co_applicant_id'], 'mobile_no' => $pd_details['mobile_no']);
$where_condition_array = array('additional_pd_id' => $pd_id);
$this->PD_Model->updateRecords($fields, PDAPPLICANTSDETAILS, $where_condition_array);
//update Assiged PD to Address Table
$where_condition_array = array('pd_address_id' => $newpd['fk_address_id']);
$temp_data = array('assigned_pd' => $pd_id);
$id = $this->PD_Model->updateRecords($temp_data, PDADDRESS, $where_condition_array);
$logger = MYLOG::logFunction(null, $pd_id);
$logger->info("TEMPLATE ASSIGN FUNCTIONALTIY CALLED AND TEMPLATED ID - " . $newpd['fk_pd_template_id'] . " CHOOSED", array('ENV' => ENVIRONMENT, 'Parent-PDID' => $newpd['parent_pd_id'], 'Addresss ID' => $newpd['fk_address_id'], 'PDID' => $pd_id, 'PD Type' => "Addtional PD", 'Current_status' => $newpd['pd_status']));
//PDALERTS::pdnotification($newpd['pd_id']);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $pd_id;
$data['msg'] = "Addtional PD Created!";
$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_NO_CONTENT;
$data['msg'] = 'Parent PD Details Not available!';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'Addtional PD :- ParentPD ID,Customer Segment, Address,, PD Status, Created by Required!';
$this->response($data, REST_Controller::HTTP_OK);
}
}
}
//While PD Completion stage, send lenth of PD address
public function getPDCompleteDetails_post()
{
$records = $this->post('records');
$pdid = $records['pd_id'];
$pd_master_detials = $this->PD_Model->getPDMasterDetails($pdid);
$address_count = $this->db->SELECT('count(*) as count')->FROM(PDADDRESS . ' as PDADDRESS')->WHERE('PDADDRESS.fk_pd_id', $pd_master_detials[0]['parent_pd_id'])->WHERE('assigned_pd is null')->WHERE('PDADDRESS.isactive', 1)->GET()->result_array();
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = array('address_count' => (int)$address_count[0]['count']);
$this->response($data, REST_Controller::HTTP_OK);
}
public function assignPDTempalate($data)
{
//print_r($data);
$customer_segment_abbr = '';
$res_array = array();
if (!is_array($data)) {
$logger = MYLOG::logFunction(null, $data);
$logger->info("TEMPLATE ASSIGN FUNCTIONALTIY CALLED", array('ENV' => ENVIRONMENT, 'DATA' => $data));
// $fields = array('fk_lender_id','fk_product_id','fk_customer_segment','pd_status');
// $where_condition_array = array('pd_id' => $data);
$res_array = $this->PD_Model->getPDMasterDetails($data);
$customer_segment_abbr = $res_array[0]['customer_segment_abbr'];
}
$templateid = null;
$fields = array('fk_template_id');
$where_condition_array = array();
//print_r($res_array[0]['fk_customer_segment']);die();
if (!is_array($data)) {
$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);
//$customer_segment_abbr = $this->PD_Model->selectCustomRecords(array('*'),array('customer_segment_id' => $res_array[0]['fk_customer_segment'], 'isactive' => 1),CUSTOMERSEGMENT);
//$customer_segment_abbr = $customer_segment_abbr[0]['abbr'];
//print_r($customer_segment_abbr);
} else {
//print_r('else');
$logger = MYLOG::logFunction(null, $data['pd_id']);
$logger->info("TEMPLATE ASSIGN FUNCTIONALTIY CALLED", array('ENV' => ENVIRONMENT, 'DATA' => $data));
$where_condition_array = array('fk_lender_id' => $data['lender'], 'fk_product_id' => $data['product'], 'fk_customer_segment' => $data['customer_segment'], 'isactive' => 1);
}
$table = LENDERTEMPLATE;
$choosed_template_id = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, $table);
if (count($choosed_template_id)) // CHOOSE FILTERED TEMPLATE//
{
$templateid = $choosed_template_id[0]['fk_template_id'];
} else // CHOOSE GENERIC TEMPLATE//
{
//echo "CHOOSE GENERIC ";
if (!strcasecmp($customer_segment_abbr, 'SAL')) // || !strcasecmp($customer_segment_abbr,'SAL-CHQ'))
{
//SAL - (CASH/CHQ)
$templateid = 1;
} else if (!strcasecmp($customer_segment_abbr, 'SE-DI') || !strcasecmp($customer_segment_abbr, 'SEP-DI') || !strcasecmp($customer_segment_abbr, 'SEP_INDV')) {
//* SENP/SEP - (DI)
$templateid = 2;
} else if (!strcasecmp($customer_segment_abbr, 'SE-AI') || !strcasecmp($customer_segment_abbr, 'SEP-AI')) {
//* SENP/SEP - (DI)
$templateid = 3;
} else if (!strcasecmp($customer_segment_abbr, 'SE-RI')) {
//* SENP/SEP - (RI)
$templateid = 4;
}
}
// echo $templateid;die();
return $templateid;
}
public function updatePDAddress_post()
{
$records = $this->post('records');
$count = 0;
foreach ($records as $key => $value) {
unset($value['stateSearch']);
unset($value['citySearch']);
unset($value['pinSearch']);
if (count($records) == 1) {
$value['is_primary'] = 1;
}
if ($value['pd_address_id'] != "" || $value['pd_address_id'] != null) {
$where_condition_array = array('pd_address_id' => $value['pd_address_id']);
$id = $this->PD_Model->updateRecords($value, PDADDRESS, $where_condition_array);
if ($id != "" || $id != null) {
$count++;
}
} else {
$id = $this->PD_Model->saveRecords($value, PDADDRESS);
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);
}
}
/**
* Pd Discussion OTP Checking function
* sriram
*/
public function checkOTP_post()
{
$pdotp = $this->post('records');
$pdotpStatus = 0;
if (!array_key_exists('reason', $pdotp)) {
$pdotpStatus = $this->PD_Model->checkotp($pdotp);
$updatePd['pd_id'] = $pdotp['pd_id'];
$updatePd['pd_status'] = INPROGRESS;
$updatePd['is_otp_done'] = 1;
$updatePd['fk_updatedby'] = $pdotp['fk_updatedby'];
//$updatePd['updatedon'] = date('Y-m-d h:i: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);
}
} else {
//echo "WITHOUT OTP CALLED";
$updatePd['pd_id'] = $pdotp['pd_id'];
$updatePd['pd_status'] = INPROGRESS;
$updatePd['is_otp_done'] = 0;
$updatePd['otp_reject_reason'] = $pdotp['reason'];
$updatePd['otp_reject_other_reason'] = $pdotp['other_reason'];
//$updatePd['updatedon'] = date('Y-m-d h:m:00');
$updatePd['fk_updatedby'] = $pdotp['fk_updatedby'];
$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);
}
}
/*
*
*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) {
$pd_applicant_detail['applicant_name'] = trim($pd_applicant_detail['applicant_name']);
$pd_applicant_detail['company_name'] = trim(MYUTIL::applicantNameCamelCaseConvertion($pd_applicant_detail['company_name']));
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');
// print_r($records);die();
//if($records['fk_pd_allocated_to'] != "" || $records['fk_pd_allocated_to'] != null)
//{
// $records['pd_agency_id'] =isset($records['pd_agency_id']) ? $records['pd_agency_id'] : null;
$fields = array('fk_lender_id', 'pd_agency_id');
$where_condition_array = array('pd_id' => $records['pd_id']);
$lender_id = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDTRIGGER);
$smc_lender_id = ENVIRONMENT == 'production' ? 7 : 35; //SMC lender id MWISE in live and demo
// IF Condition - PD AGENCY ID means SMC VENDOR FLOW
if (isset($records['pd_agency_id'])) {
// IF Condition - using PDID get the lender and mapped with SMC_lender_id macthed means Vendor status dynamically assigned
// {"records":{"pd_id":"2795","fk_pd_allocated_to":"383","pd_agency_id":"2","fk_updatedby":"395"}}
if ($smc_lender_id == $lender_id[0]['fk_lender_id'] && isset($records['pd_agency_id']) && $records['pd_agency_id'] != null) {
$records['vendor_status'] = isset($records['pd_status']) ? $records['pd_status'] : ALLOCATED; //Here vendor_status is dynamic (ALLOCATED,SCHEDULED,COMPLETED like that)
//Mail - SMC Vendor.
if ($records['vendor_status'] == ALLOCATED) {
$records['pd_status'] = ALLOCATED_TO_FIA;
}
}
} else {
//Normal FLOW
$records['pd_status'] = isset($records['pd_status']) ? $records['pd_status'] : ALLOCATED;
if (isset($records['pd_status']) && ($records['pd_status'] == ALLOCATED_TO_FIA)) {
$records['vendor_status'] = TRIGGERED;
}
}
// if($smc_lender_id != $lender_id[0]['fk_lender_id']){
// $records['pd_status'] = isset($records['pd_status']) ? $records['pd_status'] : ALLOCATED ;
// }
// IF Condition - using PDID get the lender and mapped with SMC_lender_id macthed means Vendor status dynamically assigned
// if($smc_lender_id == $lender_id[0]['fk_lender_id'] && isset($records['pd_agency_id']) && $records['pd_agency_id'] != null){
// $records['vendor_status'] = isset($records['pd_status']) ? $records['pd_status'] : ALLOCATED ; //Here vendor_status is dynamic (ALLOCATED,SCHEDULED,COMPLETED like that)
// }
// else if(isset($records['pd_status']) && ($records['pd_status'] == ALLOCATED_TO_FIA ))
// {
// $records['pd_status'] = isset($records['pd_status']) ? $records['pd_status'] : ALLOCATED ;
// $records['vendor_status'] = TRIGGERED;
// }
//}
// $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) {
$logger = MYLOG::logFunction(null, $records['pd_id']);
$logger->info("PD UPDATED", array('ENV' => ENVIRONMENT, 'DATA' => $records, 'Pre-Status' => 'TRIGGERED', 'Current_status' => isset($records['pd_status']) ? $records['pd_status'] : ALLOCATED));
PDALERTS::pdnotification($records['pd_id']);
if (isset($records['pd_agency_id']) && $records['vendor_status'] == ALLOCATED) {
PDALERTS::sendMWcreditPDMail($this, $records, 1);
PDALERTS::sendMWcreditPDMail($this, $records, 2);
}
$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');
//print_r($records['app_client']);die();
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('fk_updatedby' => $records['fk_scheduled_by'], 'scheduled_on' => $records['schedule_time']);
if (isset($records['app_client']) && $records['app_client'] == 3) {
$temp_array['vendor_status'] = SCHEDULED;
} else {
$temp_array['pd_status'] = SCHEDULED;
}
//print_r($temp_array);die();
$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']);
$logger = MYLOG::logFunction();
$logger->info("PD UPDATED", array('ENV' => ENVIRONMENT, 'DATA' => $records, 'Pre-Status' => 'NA', 'Current_status' => SCHEDULED));
$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,PDTRIGGER.lender_applicant_id,ENTITY.short_name');
$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->JOIN(ENTITY . ' as ENTITY', 'PDTRIGGER.fk_lender_id = ENTITY.entity_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,PDTRIGGER.lender_applicant_id,ENTITY.short_name');
$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->JOIN(ENTITY . ' as ENTITY', 'PDTRIGGER.fk_lender_id = ENTITY.entity_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
{
//echo 'Find General Team ID';die();
$fields = array('pdteam_id');
$where_condition_array = array('team_name' => "General");
$general_team_id = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDTEAM);
// print_r($general_team_id);die();
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,PDTRIGGER.lender_applicant_id,ENTITY.short_name');
$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->JOIN(ENTITY . ' as ENTITY', 'PDTRIGGER.fk_lender_id = ENTITY.entity_id', 'LEFT');
$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()
{
//print_r($_GET);die();
//check empty query params
$this->checkEmptyQueryParams($_GET);
$page = 0;
$limit = 1000;
$sort = 'DESC';
$pdofficerid = "";
$datetype = "";
$fdate = "";
$tdate = "";
$lenderid = "";
$status = "";
$lender_details = array();
$pdagencyid = "";
$vendor_pdofficer = "";
$user_type = "";
$createdby = "";
$client = "";
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('pdagencyid')) {
$pdagencyid = $this->get('pdagencyid');
}
if ($this->get('vendor_pdofficer')) {
$vendor_pdofficer = $this->get('vendor_pdofficer');
}
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');
}
if ($this->get('user_type')) {
$user_type = $this->get('user_type');
}
if ($this->get('client')) {
$client = $this->get('client');
}
$is_smc_vendor = $this->get('is_smc_vendor') ? $this->get('is_smc_vendor') : null;
//if lender id exists, then make custom filter for only SMC usage
if ($this->get('createdby')) {
$createdby = $this->get('createdby');
}
if ($this->get('lenderid')) {
$lenderid = $this->get('lenderid');
$smc_lender_id = ENVIRONMENT == 'production' ? 7 : 35; //pk id of SMC in live and demo
if ($lenderid == $smc_lender_id) {
// $this->load->model('User_Management_Model');
// $user_details = $this->User_Management_Model->getUserDetails($createdby);
// if($user_details['data'][0]['user_role'] == 26)//Credit Manager
// {
// $pdofficerid = $createdby;
// }
// else if($user_details['data'][0]['user_role'] == 27)//Reg Credit Manager
// {
// $lender_details = array('city' => $user_details['data'][0]['fk_city']);
// }
$createdby = '';
}
// $lender_details = $this->getLenderHierarchyForPDListing($lenderid);
}
// die();
$result_data = $this->PD_Model->listLessPDDetails($page, $limit, $sort, $pdofficerid, $datetype, $fdate, $tdate, $lenderid, $status, $lender_details, $pdagencyid, $vendor_pdofficer, $user_type, $createdby, $client, $is_smc_vendor);
// echo count($result_data['data']);die();
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);
}
}
function checkEmptyQueryParams($arr)
{
if (count($arr)) {
foreach ($arr as $key => $value) {
if (!$value) {
//exit('CATUTION');
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_UNPROCESSABLE_ENTITY;
$data['msg'] = 'Unprocessable Params';
$this->response($data, REST_Controller::HTTP_OK);
}
}
}
}
// PD listing based on lender role hierarchy
function getLenderHierarchyForPDListing($lender_user_id)
{
//get role of lender_user_id`
$user_role_details = $this->PD_Model->getLenderHierarchyForPDListing($lender_user_id);
//print_r($user_role_details);die();
if (count($user_role_details)) {
$role_id = $user_role_details[0]['user_role'];
switch ($role_id) {
case 11: // National Sales Head
case 12: // National Credit Head
//Get all PD's which were triggered in this entity id
return array('entity' => $user_role_details[0]['fk_entity_id']);
case 13: // Zonal Sales Head
case 14: // Zonal Credit Head
//Get all cities id's from m_entity_region_mapping table using region_id / zone id
$temp_array = $this->PD_Model->selectCustomRecords(array('fk_city_id'), array('fk_region_id' => $user_role_details[0]['fk_region_id']), ENTITYREGION);
//Get all PD's which were triggered in this entity id and city id's in current zone
//$citiesInCurrentZone = array(10,20);
$citiesInCurrentZone = array();
if (count($temp_array)) {
foreach ($temp_array as $key => $value) {
$citiesInCurrentZone = array_merge($citiesInCurrentZone, array($value['fk_city_id']));
}
}
return array('entity' => $user_role_details[0]['fk_entity_id'], 'zone' => $citiesInCurrentZone);
case 15: //Area Sales Head
case 16: //Area Credit Head
//Get all PD's which were triggered in this entity id and city id's in current zone
return array('entity' => $user_role_details[0]['fk_entity_id'], 'state' => $user_role_details[0]['fk_state']);
case 17: //City Sales Head
case 18: //City Credit Head
//Get all PD's which were triggered in this entity id and current city
return array('entity' => $user_role_details[0]['fk_entity_id'], 'city' => $user_role_details[0]['fk_city']);
case 19: //Branch Sales
case 20: //Branch Credit
//Get all PD's which were triggered in this entity id and current lender user id
return array('entity' => $user_role_details[0]['fk_entity_id'], 'lender_credit_person' => $lender_user_id);
default:
return array();
}
}
}
public function filterPDList_post()
{
//echo "Hi";
$records = $this->post('records');
//print_r($this->post('records'));die();
$pd_type = $records['pd_type'];
//print_r($records);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 = strtolower($records['pd_name']);
$pd_applicant_lender_ref = strtolower($records['pd_applicant_id']);
$pd_officer_name = isset($records['pd_officer']) ? $records['pd_officer'] : null;
$pd_officer_id = isset($records['pd_officer_id']) ? $records['pd_officer_id'] : null;
$include_archive = isset($records['is_include_archived']) ? $records['is_include_archived'] : null;
$pd_agency_id = isset($records['pd_agency_id']) ? $records['pd_agency_id'] : null;
$vendor_pdofficer = isset($records['vendor_pdofficer']) ? $records['vendor_pdofficer'] : null;
$user_type = isset($records['user_type']) ? $records['user_type'] : null;
$createdby = $records['createdby'];
// echo "B4 date_type ".$records['date_type']." and my return type is ".gettype($records['date_type'])."\n";
$date_type = isset($records['date_type']) ? (int)$records['date_type'] : null;
// echo "After date_type ".$date_type." and my return type is ".gettype($date_type)."\n";
$client = isset($records['client']) ? $records['client'] : null;
// $smc_agency_id = isset($records['smc_agency_id']) ? $records['smc_agency_id'] : null;
$is_smc_vendor = isset($records['is_smc_vendor']) ? $records['is_smc_vendor'] : null;
$lender_details = array();
//if lender id exists, then make custom filter for only SMC usage
if ($pd_lender) {
$smc_lender_id = ENVIRONMENT == 'production' ? 7 : 35; //pk id of SMC in live and demo
if ($pd_lender == $smc_lender_id) {
$createdby = '';
// $this->load->model('User_Management_Model');
// $user_details = $this->User_Management_Model->getUserDetails($createdby);
// if($user_details['data'][0]['user_role'] == 26)//Credit Manager
// {
// $pd_officer_id = $createdby;
// }
// else if($user_details['data'][0]['user_role'] == 27)//Reg Credit Manager
// {
// $pd_city = array( $user_details['data'][0]['fk_city'] );
// }
}
// $lender_details = $this->getLenderHierarchyForPDListing($lenderid);
}
$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, $pd_officer_name, $include_archive, $pd_officer_id, $pd_agency_id, $vendor_pdofficer, $user_type, $createdby, $date_type, $client, $is_smc_vendor);
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');
$random_string = $this->post('random_string');
// Get All PD Masters Details
$result_data['pd_master_details'] = $this->PD_Model->getPDMasterDetails($pdid, $random_string);
//Get All existing PD details of same applicants
$result_data['exist_pd_details'] = $this->PD_Model->getExistPDdetails($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, null, null, 1);
//Get All PD Template and It's Question with Answers
$result_data['pd_question_answer'] = $this->PD_Model->getPDQuestionAnswers($pdid);
//Get All PD Address
$result_data['pd_address'] = $this->PD_Model->getPDAddress($pdid);
//Get All PD COmpanies
$result_data['pd_company'] = $this->PD_Model->getPDCompany($pdid);
//Get Addtional Requirements details
$result_data['pd_additional_requirements'] = $this->PD_Model->getPDAdditionalRequirements($pdid);
//Get Docs to be collected array
$result_data['docs_to_be_collected'] = $this->PD_Model->getDocsToBeCollected($pdid);
if ($result_data['pd_master_details'][0]['fk_pd_type'] == 2 && !$result_data['pd_master_details'][0]['is_vendor_visit_disabled']) //smart pd get vendor forms status
{
$result_data['vendor_form_status'] = $this->PD_Model->getVendorFormStatus($pdid, $result_data['pd_master_details']);
}
//Get All PD Logs
$result_data['pd_logs'] = $this->PD_Model->getPDLogs($pdid);
//print_r($result_data['pd_logs']);die();
if (count($result_data['pd_logs']) && isset($result_data['pd_logs']['last_status_update_date'])) {
$result_data['pd_master_details'][0]['maser_updatedon'] = $result_data['pd_master_details'][0]['updatedon'];
$result_data['pd_master_details'][0]['updatedon'] = DATE_FORMAT(date_create_from_format("Y-m-d H:i:s", $result_data['pd_logs']['last_status_update_date']), "d/m/Y h:i:s a");
}
//print_r($result_data['pd_master_details']);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 = "";
$random_string = "";
$api = "";
if ($this->get('pd_id')) {
$pd_id = $this->get('pd_id');
}
if ($this->get('client')) {
$client = $this->get('client');
}
if ($this->get('random_string')) {
$random_string = $this->get('random_string');
}
if ($this->get('api')) {
$api = $this->get('api');
}
if ($pd_id != "" || $pd_id != null) {
$template_details = $this->PD_Model->getTemplateForPD($pd_id, $client, $random_string, $api);
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.jpeg";
//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-i-s') . '.jpeg';
$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.jpeg";
//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-i-s') . '.jpeg';
$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);
}
}
public function savePDFormDetailsJSON_post()
{
//ini_set('max_execution_time', 60);
//$this->load->helper('INLINEPHOTOTRANSFORM');
// $size = mb_strlen(json_encode($this->post('records'), JSON_NUMERIC_CHECK), '8bit');
// echo $size;
// die();
$records = $this->post('records');
$pdid = $records['pdid'];
$formid = $records['formid'];
$templateid = isset($records['template_id']) ? $records['template_id'] : null;
$createdby = $records['fk_createdby'];
$company_id = null;
$processed_json = null;
$rental_count_id = isset($records['rental_count_id']) ? $records['rental_count_id'] : null;
//print_r($records);die();
$parent_pdid = $records['parent_pdid'];
$parent_form_index = null;
$parent_forms = $this->config->item('parent_forms');
$additional_pd_id = $pdid;
$custom_log_info = '###Payload Size - ' . (int) $_SERVER['CONTENT_LENGTH'] . ' ###savePDFormDetailsJSON Function Called - PDID - (' . $pdid . ' - ' . $formid . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
$logger = MYLOG::logFunction(null, $pdid);
$log_info_array['pdid'] = $pdid;
$log_info_array['formid'] = $formid;
$log_info_array['payload_size'] = (int) $_SERVER['CONTENT_LENGTH'];
$log_info_array['payload_data'] = json_encode($records);
$logger->info("SAVE FORM JSON FUNCTION CALLED - ENV (" . ENVIRONMENT . ")", $log_info_array); //die();
///die();
//$inline_forms_photo_status_check = $this->PD_Model->selectCustomRecords(array('*'),array('fk_pd_id' => $pdid),T_PD_INLINE_PHOTO_FORM_STATUS);
// print_r($inline_forms_photo_status_check);
// echo count($inline_forms_photo_status_check);
if ($pdid != $parent_pdid) {
$parent_form_index = array_search($formid, $parent_forms);
$pdid = $parent_form_index != null ? $parent_pdid : $pdid;
$records['pdid'] = $pdid;
}
// print_r($records);
// die();
if (isset($records['company_id'])) {
$company_id = $records['company_id'];
}
//Save Any New Applicants Details From General Form
// if($formid == 18)
// {
// $records = $this->saveCoApplicantsFromGeneralInfoForm($records);
// if(!count($inline_forms_photo_status_check))
// {
// $records = INLINEPHOTOTRANSFORM::retransformGeneralFormInlinePhotos($records);
// //update general form photos saved once
// $this->PD_Model->saveRecords(array('fk_pd_id' => $pdid,'is_general_photo_saved' => 1),T_PD_INLINE_PHOTO_FORM_STATUS);
// }
// }
if ($formid == 10) {
$this->updateSubProductFromLoanDetailsForm($records);
$custom_log_info = '###updateSubProductFromLoanDetailsForm Function Called PDID - (' . $pdid . ' - ' . $formid . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
}
//From Business form save Employee Salary as Business Expenses
if ($formid == 13) {
$this->saveEmpSalaryAsBusinessExpensesFromBusinessForm($records);
$custom_log_info = '###saveEmpSalaryAsBusinessExpensesFromBusinessForm Function Called PDID - (' . $pdid . ' - ' . $formid . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
// if(count($inline_forms_photo_status_check) && $inline_forms_photo_status_check[0]['is_business_photo_saved'] != 1)
// {
// $records = INLINEPHOTOTRANSFORM::retransformBusinessFormInlinePhotos($records);
// $this->PD_Model->updateRecords(array('is_business_photo_saved' => 1),T_PD_INLINE_PHOTO_FORM_STATUS,array('fk_pd_id' => $pdid));
// }
}
if ($formid == 22) {
$this->saveAssetRentAsBusinessExpensesFromBusinessAssestForm($records);
$custom_log_info = '###saveAssetRentAsBusinessExpensesFromBusinessAssestForm Function Called PDID - (' . $pdid . ' - ' . $formid . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
}
$fields = array('isactive' => 0);
$where_condition_array = array('fk_form_id' => $formid, 'fk_pd_id' => $pdid);
if ($company_id != null) {
$where_condition_array = array('fk_form_id' => $formid, 'fk_pd_id' => $pdid, 'company_id' => $company_id);
}
if ($rental_count_id != null) {
$where_condition_array['rental_count_id'] = $rental_count_id;
}
$id = $this->PD_Model->updateRecords($fields, PDFORMDETAILSJSON, $where_condition_array);
$custom_log_info = '###OLD Entries Deactivated PDID - (' . $pdid . ' - ' . $formid . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
/*****Call Form Specific funcitons to convert RAW JSON Data to Processed JSON DATA******/
if (PROCESSJSON == true) {
switch ($formid) {
case 1:
$processed_json = GETPROCESSEDJSON::convertSupplierForm($records, $formid);
break;
case 2:
$processed_json = GETPROCESSEDJSON::convertClientForm($records, $formid);
break;
case 4:
$processed_json = GETPROCESSEDJSON::convertOtherAssetForm($records, $formid);
//$processed_json = $records;
break;
case 5:
$processed_json = GETPROCESSEDJSON::convertAddressForm($records, $formid);
break;
case 6:
$processed_json = GETPROCESSEDJSON::convertOtherFamilyDetailsForm($records, $formid);
break;
case 8:
$processed_json = GETPROCESSEDJSON::convertExistingLoanDetailsForm($records, $formid);
break;
case 7:
$processed_json = GETPROCESSEDJSON::convertBankingInfoDetailsForm($records, $formid);
break;
case 9:
$processed_json = GETPROCESSEDJSON::convertOtherIncomeDetailsForm($records, $formid);
break;
case 10:
$processed_json = GETPROCESSEDJSON::convertLoanDetailsForm($records, $formid);
break;
case 11: //In Stock UOM Only - also coming Text - right now No need to convert.
$processed_json = GETPROCESSEDJSON::convertStockDetailsForm($records, $formid);
//print_r($processed_json);die();
break;
case 12:
$processed_json = GETPROCESSEDJSON::convertEmploymetForm($records, $formid);
break;
case 14: // There is no master Data in Financial Form
$processed_json = $records;
break;
case 13:
$processed_json = GETPROCESSEDJSON::convertBusinessDetailsForm($records, $formid);
break;
case 15:
$processed_json = $records;
break;
case 17:
$processed_json = GETPROCESSEDJSON::convertRentalIncomeDetailsForm($records, $formid);
break;
case 18:
$processed_json = GETPROCESSEDJSON::convertGeneralDetailsForm($records, $formid);
break;
case 19:
$processed_json = GETPROCESSEDJSON::convertNeighbourDetailsForm($records, $formid);
break;
case 20:
$processed_json = GETPROCESSEDJSON::convertFinalRemarksForm($records, $formid);
break;
// Buiness Banking Form
case 21:
$processed_json = GETPROCESSEDJSON::convertBankingInfoDetailsForm($records, $formid);
break;
case 22:
$processed_json = GETPROCESSEDJSON::convertBusinessAssetsForm($records, $formid);
break;
case 23:
$processed_json = $records;
break;
case 24:
$processed_json = GETPROCESSEDJSON::convertCreditManagerQueriesForm($records, $formid);
$records['docs_to_be_sighted'] = isset($processed_json['docs_to_be_sighted']) ? $processed_json['docs_to_be_sighted'] : null;
unset($processed_json['docs_to_be_sighted']);
case 27:
$processed_json = GETPROCESSEDJSON::convertFIGeneralDetailsForm($records, $formid);
break;
case 28:
$processed_json = GETPROCESSEDJSON::convertFIAddressForm($records, $formid);
break;
case 29:
$processed_json = $records;
break;
case 30:
$processed_json = $records;
break;
case 31:
$processed_json = GETPROCESSEDJSON::convertCreditManagerQueriesForm($records, $formid);
$records['docs_to_be_sighted'] = isset($processed_json['docs_to_be_sighted']) ? $processed_json['docs_to_be_sighted'] : null;
unset($processed_json['docs_to_be_sighted']);
break;
case 32:
$processed_json = $records;
break;
case 33:
$processed_json = GETPROCESSEDJSON::convertFinalRemarksForm($records, $formid);
break;
case 34:
$processed_json = $records['photograph_details'];
break;
//default:
//echo "Something Wrong! Form ID did not match, Contact System Administrator";
}
}
$custom_log_info = '###Processed JSON Function Executed PDID - (' . $pdid . ' - ' . $formid . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
/*****End of Form Specific funcitons to convert RAW JSON Data to Processed JSON DATA*******/
unset($records['pdid']);
unset($records['formid']);
unset($records['fk_createdby']);
unset($records['company_id']);
unset($records['parent_pdid']);
//unset($records['rental_count_id']);
$records = json_encode($records);
if ($processed_json != null) {
$processed_json = json_encode($processed_json);
}
$temp_array = array('fk_form_id' => $formid, 'company_id' => $company_id, 'fk_pd_id' => $pdid, 'fk_createdby' => $createdby, 'json' => $records, 'processed_json' => $processed_json, 'rental_count_id' => $rental_count_id, 'template_id' => $templateid);
// $temp_array = array('fk_form_id'=>$formid,'company_id' => $company_id,'fk_pd_id'=>$pdid,'fk_createdby'=>$createdby,'json'=>$records,'processed_json' => $processed_json,'rental_count_id' => $rental_count_id);
$id = $this->PD_Model->saveRecords($temp_array, PDFORMDETAILSJSON);
$logger->info("SAVE FORM JSON FUNCTION RESPONSE - ENV (" . ENVIRONMENT . ")", $log_info_array);
if ($id != "" || $id != null) {
// Update form dummy entry against Additional PD common form ID to avoid every time fetch data from additional PD forms - scenarios like exist loan obligations, other family details
// if($formid == 4)//other asset - here this should happen for only if it is additional PD.
// {
// $temp_array = array('fk_form_id'=>$formid,'company_id' => $company_id,'fk_pd_id'=>$additional_pd_id,'fk_createdby'=>$createdby,'json'=>$records,'processed_json' => $processed_json,'rental_count_id' => $rental_count_id);
// $id = $this->PD_Model->saveRecords($temp_array,PDFORMDETAILSJSON);
// }
// End Of update Additional Entry
if ($temp_array['fk_form_id'] == 25) //vendor form id
{
$custom_log_info = '### Disable all forms VENDOR_FORMS_STATUS to zero - (' . $pdid . ' - ' . $formid . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
$this->PD_Model->updateRecords(array('form_status' => 0), VENDORFORMSTATUS, array('fk_pd_id' => $pdid));
}
$custom_log_info = '### JSON Saved Successfully PDID - (' . $pdid . ' - ' . $formid . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
$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 getPDFormDetailsJSON_post()
{
$pd_id = $this->post('pd_id');
$pd_form_id = $this->post('pd_form_id');
$parent_pd_id = $this->post('parent_pdid'); // ? $this->post('parent_pd_id') : null;
$company_id = $this->post('company_id') ? $this->post('company_id') : null;
$parent_form_index = null;
$parent_forms = $this->config->item('parent_forms');
$is_addtional_pd = 0;
$additional_pd_id = null;
$custom_log_info = '###getPDFormDetailsJSON Function Executed PDID - (' . $pd_id . ' - ' . $pd_form_id . ') - ' . date('Y-m-d H:i:s A');
// echo "getPDFormDetails".$custom_log_info;die();
log_message('ERROR', $custom_log_info);
if ($pd_id != $parent_pd_id) {
$is_addtional_pd = 1;
// list of common forms for addtional PD (Other Assets,Family Details,Banking Details of Individuals,Existing Loan Obligations,Other Income Details,Loan Details,Final Remarks Form)
$parent_form_index = array_search($pd_form_id, $parent_forms);
$additional_pd_id = $pd_id;
$pd_id = $parent_form_index != null ? $parent_pd_id : $pd_id;
}
$logger = MYLOG::logFunction(null, $pd_id);
$log_info_array['pdid'] = $pd_id;
$log_info_array['formid'] = $pd_form_id;
$logger->info("GET FORM JSON FUNCTION CALLED - ENV (" . ENVIRONMENT . ")", $log_info_array);
if ($pd_form_id == 18) {
$fields = array('json');
$where_condition_array = array('fk_pd_id' => $pd_id, 'fk_form_id' => $pd_form_id, 'isactive' => 1);
$form_count = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
//print_r($form_count);
if (!count($form_count)) {
//echo "dsjsbsdj";
$fields = array('json');
$where_condition_array = array('isactive' => 1, 'fk_form_id' => $pd_form_id, 'fk_pd_id' => $parent_pd_id);
$rec = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
if (count($rec)) {
$temp_json = $this->renewGeneralFormForAddtionalPD($rec[0]['json']);
$logger->info("GET FORM JSON FUNCTION RESPONSE - ENV (" . ENVIRONMENT . ")", $log_info_array);
$custom_log_info = '###renewGeneralFormForAddtionalPD Function Called (ADDItional PD ) - (' . $pd_id . ' - ' . $pd_form_id . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $temp_json;
$this->response($data, REST_Controller::HTTP_OK);
}
}
}
if ($is_addtional_pd == 1 && $pd_form_id == 5) //address form && ($parent_pd_id != $pd_id)
{
$fields = array('json');
$where_condition_array = array('fk_pd_id' => $pd_id, 'fk_form_id' => $pd_form_id, 'isactive' => 1);
$form_count = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
if (count($form_count)) {
$logger->info("GET FORM JSON FUNCTION RESPONSE - ENV (" . ENVIRONMENT . ")", $log_info_array);
$custom_log_info = '###Return Response FROM GET PD FORM JSON - (' . $pd_id . ' - ' . $pd_form_id . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = json_decode($form_count[0]['json']);
$this->response($data, REST_Controller::HTTP_OK);
} else {
//echo "get address details from address form";
$fields = array('*');
$where_condition_array = array('assigned_pd' => $pd_id);
$assigned_address = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDADDRESS);
if (count($assigned_address)) {
$temp_address = $assigned_address[0];
//print_r($temp_address);
//construct address form jsn format here
$address = array();
$address[] = array('address' => $temp_address['addressline1'], 'address_type' => "", 'address_type_others' => '', 'state' => $temp_address['fk_state'], 'city' => $temp_address['fk_city'], 'citySearch' => '', 'stateSearch' => '', 'citySearch' => '', 'pinSearch' => '', 'pincode' => $temp_address['pincode'], 'pincode_others' => '', 'locality' => '', 'locality_others' => '', 'pd_location' => '', 'comment_locality' => '', 'estimated_area' => '', 'uom' => '', 'uom_others' => '');
$records['addresses'] = $address;
$records['address_form_remark'] = '';
$logger->info("GET FORM JSON FUNCTION RESPONSE - ENV (" . ENVIRONMENT . ")", $log_info_array);
$custom_log_info = '###Return Response FROM GET PD FORM JSON (ADDRESS FORM ADDITIONAL PD) - (' . $pd_id . ' - ' . $pd_form_id . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $records;
$this->response($data, REST_Controller::HTTP_OK);
}
}
}
$fields = array('json');
$where_condition_array = array('isactive' => 1, 'fk_form_id' => $pd_form_id, 'fk_pd_id' => $pd_id);
//print_r($where_condition_array);
if ($company_id != null) {
$where_condition_array = array('fk_form_id' => $pd_form_id, 'fk_pd_id' => $pd_id, 'company_id' => $company_id, 'isactive' => 1);
}
$rec = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
// echo "I have";
// print_r($rec);die();
if (isset($rec[0]['json'])) {
$temp_rec = json_decode($rec[0]['json'], true);
if (($temp_rec)) {
$pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id);
$bucketname = LENDER_BUCKET_NAME_PREFIX . $pd_master_details[0]['fk_lender_id'];
if ($pd_form_id == 18) //General form
{
$custom_log_info = '###Get General FOrm IMG AWS urls & attach into JSON Function Called - (' . $pd_id . ' - ' . $pd_form_id . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
$result_data = $this->PD_Model->getSignedPDDocsURL($pd_id, 18, null, null, null);
foreach ($temp_rec['individuals'] as $g_key => $g_value) {
//print_r( $g_value);
if ($g_value['is_person_met'] == true) {
if (count($result_data)) {
foreach ($result_data as $img_key => $img_value) {
//$temp_rec['individuals'][$g_key]['is_person_met_pic'] = "";
//$temp_rec['individuals'][$g_key]['is_person_met_id_proof'] = "";
$applicant_name = trim($g_value['applicant_name']);
if (!strcasecmp($applicant_name, trim($img_value['pd_document_title']))) {
$temp_rec['individuals'][$g_key]['is_person_met_pic'] = $img_value['doc_url'];
//echo 'SAME-'.$applicant_name.'-'.trim($img_value['pd_document_title']);
//echo $img_value['doc_url'];die();
}
if (!strcasecmp(($applicant_name . '-id_proof'), trim($img_value['pd_document_title']))) {
$temp_rec['individuals'][$g_key]['is_person_met_id_proof'] = $img_value['doc_url'];
}
}
}
} else {
$temp_rec['individuals'][$g_key]['is_person_met_id_proof'] = "";
$temp_rec['individuals'][$g_key]['is_person_met_pic'] = "";
}
}
//print_r($temp_rec);die();
$rec[0]['json'] = json_encode($temp_rec);
$custom_log_info = '###Get General FOrm IMG AWS urls & attach into JSON Function End - (' . $pd_id . ' - ' . $pd_form_id . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
}
if ($pd_form_id == 13) //ABout Business form
{
$custom_log_info = '###Get Business IMG AWS urls & attach into JSON Function Called - (' . $pd_id . ' - ' . $pd_form_id . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
$result_data = $this->PD_Model->getSignedPDDocsURL($pd_id, 13, $company_id, null, null, null, 'report');
foreach ($result_data as $b_key => $b_value) {
if ($b_value['pd_document_title'] == 'shop_eat_act_cert_pic') {
$temp_rec['shop_eat_act_cert_pic'] = $b_value['doc_url'];
}
if ($b_value['pd_document_title'] == 'gst_Regn_cert_pic') {
$temp_rec['gst_Regn_cert_pic'] = $b_value['doc_url'];
}
if ($b_value['pd_document_title'] == 'pf_regn_pic') {
$temp_rec['pf_regn_pic'] = $b_value['doc_url'];
}
if ($b_value['pd_document_title'] == 'esic_regn_pic') {
$temp_rec['esic_regn_pic'] = $b_value['doc_url'];
}
if ($b_value['pd_document_title'] == 'export_import_cert_pic') {
$temp_rec['export_import_cert_pic'] = $b_value['doc_url'];
}
if ($b_value['pd_document_title'] == 'factory_cert_pic') {
$temp_rec['factory_cert_pic'] = $b_value['doc_url'];
}
if ($b_value['pd_document_title'] == 'practice_cert_pic') {
$temp_rec['practice_cert_pic'] = $b_value['doc_url'];
}
if ($b_value['pd_document_title'] == 'fire_noc_pic') {
$temp_rec['fire_noc_pic'] = $b_value['doc_url'];
}
if ($b_value['pd_document_title'] == 'eb_bill_pic') {
$temp_rec['eb_bill_pic'] = $b_value['doc_url'];
}
if (isset($temp_rec['documents']) && count($temp_rec['documents'])) {
$temp_iter = $temp_rec['documents'];
foreach ($temp_iter as $key => $value) {
if (!strcasecmp($value['document'], trim($b_value['pd_document_title'])) && $value['document_pic']) {
$temp_rec['documents'][$key]['document_pic'] = $b_value['doc_url'];
//unset($temp_iter[$key]);
//print_r($temp_iter);
break;
}
// else
// {
// $temp_rec['documents'][$key]['document_pic'] = false;
// }
}
}
}
//die();
$rec[0]['json'] = json_encode($temp_rec);
$custom_log_info = '###Get Business IMG AWS urls & attach into JSON Function End - (' . $pd_id . ' - ' . $pd_form_id . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
}
if ($pd_form_id == 12) //Employeement
{
$custom_log_info = '###Get EMployee IMG AWS urls & attach into JSON Function Called - (' . $pd_id . ' - ' . $pd_form_id . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
$result_data = $this->PD_Model->getSignedPDDocsURL($pd_id, 12, null, null, null, null, 'report');
foreach ($result_data as $b_key => $b_value) {
if ($b_value['pd_document_title'] == 'attendance_seen_pic') {
$temp_rec['attendance_seen_pic'] = $b_value['doc_url'];
}
if ($b_value['pd_document_title'] == 'sal_reg_seen_pic') {
$temp_rec['sal_reg_seen_pic'] = $b_value['doc_url'];
}
if ($b_value['pd_document_title'] == 'name_board_img') {
$temp_rec['name_board_img'] = $b_value['doc_url'];
}
if ($b_value['pd_document_title'] == 'id_card_image') {
$temp_rec['id_card_image'] = $b_value['doc_url'];
}
}
//die();
$rec[0]['json'] = json_encode($temp_rec);
$custom_log_info = '###Get Employeement IMG AWS urls & attach into JSON Function End - (' . $pd_id . ' - ' . $pd_form_id . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
}
}
}
// print_r($rec);die();
// if(count($rec))
// {
// if($pd_form_id == 8 && $is_addtional_pd == 1)
// {
// //echo "add";
// $additional_count = $this->PD_Model->selectCustomRecords(array('*'),array('fk_form_id'=>8,'fk_pd_id'=>$additional_pd_id,'company_id' => $company_id,'isactive' => 1),PDFORMDETAILSJSON);
// if(!count($additional_count))
// {
// //get addtional PD business and other assets details and attach it with existing loan Obligation From(Parent PD existing Loan JSON Details).
// $json = $this->getAddtionalPDAssetsWithLoanFromBusinessAndOtherAssets($rec[0]['json'],$pd_id,$additional_pd_id,$company_id);
// $data['dataStatus'] = true;
// $data['status'] = REST_Controller::HTTP_OK;
// $data['records'] = $json;
// $this->response($data,REST_Controller::HTTP_OK);
// }
// }
// }
if (count($rec)) {
$json = null;
if ($pd_form_id == 17) {
foreach ($rec as $r) {
$json[] = json_decode($r['json'], true);
}
} else if ($pd_form_id == 24) //// common form credit managers specific queries
{
$json = $this->getDocsToBeSightedImagesS3URL(json_decode($rec[0]['json'], true), $pd_id);
} else {
$json = json_decode($rec[0]['json']);
}
$logger->info("GET FORM JSON FUNCTION RESPONSE - ENV (" . ENVIRONMENT . ")", $log_info_array);
$custom_log_info = '###Return Response FROM GET PD FORM JSON - (' . $pd_id . ' - ' . $pd_form_id . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $json;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$logger->info("GET FORM JSON FUNCTION RESPONSE - ENV (" . ENVIRONMENT . ")", $log_info_array);
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'No Data Available';
$this->response($data, REST_Controller::HTTP_OK);
}
}
//get documents to be sight form images S3 url's and fetch it to frond end form
function getDocsToBeSightedImagesS3URL($credit_manager_form_data, $pd_id)
{
$pd_documnets = $this->PD_Model->selectCustomRecords(array('*'), array('fk_pd_id' => $pd_id, 'fk_form_id' => 24), PDDOCUMENTS);
$pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id);
if (count($pd_documnets)) {
$bucketname = LENDER_BUCKET_NAME_PREFIX . $pd_master_details[0]['fk_lender_id'];
//echo $bucketname;
//print_r($credit_manager_form_data);die();
foreach ($pd_documnets as $doc_key => $doc_value) {
if (is_array($credit_manager_form_data['docs_to_be_sighted']) && count($credit_manager_form_data['docs_to_be_sighted'])) {
foreach ($credit_manager_form_data['docs_to_be_sighted'] as $docs_to_be_sighted_key => $docs_to_be_sighted_value) {
if (isset($docs_to_be_sighted_value['img']) && $docs_to_be_sighted_value['img'] == $doc_value['pd_document_id']) {
$key = 'pd' . $pd_id . '/' . $doc_value['pd_document_name'];
//echo $key;die();
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname, $key, '+30 minutes');
//echo $doc_value['pd_document_id'] .'********'.$singed_uri.'*******';
$credit_manager_form_data['docs_to_be_sighted'][$docs_to_be_sighted_key]['img'] = $singed_uri;
}
}
}
}
}
return $credit_manager_form_data;
}
public function getAddtionalPDAssetsWithLoanFromBusinessAndOtherAssets($parentpd_existing_loan_details, $pd_id, $additional_pd_id, $company_id = null)
{
$parentpd_existing_loan_details = json_decode($parentpd_existing_loan_details, true);
//echo 'getAddtionalPDAssetsWithLoanFromBusinessAndOtherAssets';
//Get Other Assets
$fields = array('json', 'processed_json');
$where_condition_array = array('isactive' => 1, 'fk_form_id' => 4, 'fk_pd_id' => $pd_id);
$other_assests = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
//Get Business Assets
$fields = array('json', 'processed_json');
$where_condition_array = array('isactive' => 1, 'fk_form_id' => 22, 'fk_pd_id' => $additional_pd_id);
if ($company_id != null) {
$where_condition_array['company_id'] = $company_id;
}
$business_assests = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
if (count($other_assests)) {
$other_assests = json_decode($other_assests[0]['json'], true);
//print_r($other_assests);
foreach ($other_assests['assets_details'] as $other_assest) {
if ($other_assest['emi'] == 'yes') {
$converted_data = $this->convertOtherAssetAsExistingLoanParams($other_assest);
//print_r($converted_data);
$parentpd_existing_loan_details['loan_details'][] = $converted_data;
}
}
}
if (count($business_assests)) {
$business_assests = json_decode($business_assests[0]['json'], true);
//print_r($other_assests);
if (isset($business_assests['business_assets_for_address'])) {
if ($business_assests['business_assets_for_address'][0]['business_emi'] == 'yes') {
$data['loan_amount'] = "";
$data['frequency'] = "";
$data['other_frequency'] = "";
$data['emi'] = "";
$data['loan_type'] = "";
$data['others_loan_type'] = "";
$data['loan_taken_by'] = "";
$data['lender'] = "";
$data['others_lender'] = "";
$data['original_tenure'] = "";
$data['current_balance_tenure'] = "";
$data['elapsed_tenure'] = "";
$data['label'] = $business_assests['business_assets_for_address'][0]['address_label'];
$parentpd_existing_loan_details['loan_details'][] = $data;
}
}
foreach ($business_assests['business_assets_details'] as $business_assest) {
if ($business_assest['business_emi'] == 'yes') {
$converted_data = $this->convertBusinessAssetAsExistingLoanParams($business_assest);
$parentpd_existing_loan_details['loan_details'][] = $converted_data;
}
}
}
return $parentpd_existing_loan_details;
}
function convertBusinessAssetAsExistingLoanParams($business_assest)
{
$data['loan_amount'] = "";
$data['frequency'] = "";
$data['other_frequency'] = "";
$data['emi'] = "";
$data['loan_type'] = "";
$data['others_loan_type'] = "";
$data['loan_taken_by'] = "";
$data['lender'] = "";
$data['others_lender'] = "";
$data['original_tenure'] = "";
$data['current_balance_tenure'] = "";
$data['elapsed_tenure'] = "";
$label = null;
$fields = array('*');
$where_condition_array = array('isactive' => 1);
$investment_types = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, INVESTMENTTYPE);
$fields = array('*');
$where_condition_array = array('isactive' => 1);
$property_types = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PROPERTIES);
// print_r($investment_types);
//print_r($other_assest);
switch ($business_assest['business_assets_mode']) {
case 7:
$label = $business_assest['business_name_of_the_owner'][0]['name'] . ' - Investments (' . $investment_types[($business_assest['details'][0]['investments_type'] - 1)]['name'] . ')';
break;
case 4:
$label = $business_assest['business_name_of_the_owner'][0]['name'] . ' - Equipment & Machinary (' . ($business_assest['details'][0]['equipment_manufacturing_description']) . ')';
break;
case 6:
$label = $business_assest['business_name_of_the_owner'][0]['name'] . ' - Life Insurance Policy';
break;
case 2:
$label = $business_assest['business_name_of_the_owner'][0]['name'] . ' - Property (' . ($property_types[$business_assest['details'][0]['property_type'] - 1]['name']) . ')';
break;
}
$data['label'] = $label;
return $data;
}
function convertOtherAssetAsExistingLoanParams($other_assest)
{
//echo 'convertOtherAssetAsExistingLoanParams';
$data['loan_amount'] = "";
$data['frequency'] = "";
$data['other_frequency'] = "";
$data['emi'] = "";
$data['loan_type'] = "";
$data['others_loan_type'] = "";
$data['loan_taken_by'] = "";
$data['lender'] = "";
$data['others_lender'] = "";
$data['original_tenure'] = "";
$data['current_balance_tenure'] = "";
$data['elapsed_tenure'] = "";
$label = null;
$fields = array('*');
$where_condition_array = array('isactive' => 1);
$investment_types = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, INVESTMENTTYPE);
$fields = array('*');
$where_condition_array = array('isactive' => 1);
$property_types = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PROPERTIES);
// print_r($investment_types);
//print_r($other_assest);
switch ($other_assest['assets_mode']) {
case 7:
$label = $other_assest['name_of_the_owner'][0]['name'] . ' - Investments (' . $investment_types[($other_assest['details'][0]['investments_type'] - 1)]['name'] . ')';
break;
case 4:
$label = $other_assest['name_of_the_owner'][0]['name'] . ' - Equipment & Machinary (' . ($other_assest['details'][0]['equipment_manufacturing_description']) . ')';
break;
case 6:
$label = $other_assest['name_of_the_owner'][0]['name'] . ' - Life Insurance Policy';
break;
case 2:
$label = $other_assest['name_of_the_owner'][0]['name'] . ' - Property (' . ($property_types[$other_assest['details'][0]['property_type'] - 1]['name']) . ')';
break;
//case
}
$data['label'] = $label;
return $data;
}
public function renewGeneralFormForAddtionalPD($json)
{
//echo 'renewGeneralFormForAddtionalPD';
$json = json_decode($json, true);
if (array_key_exists('individuals', $json)) {
foreach ($json['individuals'] as $individual_key => $individual) {
$json['individuals'][$individual_key]['is_person_met'] = false;
}
}
if (array_key_exists('companies', $json)) {
foreach ($json['companies'] as $company_key => $compnay) {
//print_r($company);
$json['companies'][$company_key]['is_company_applicant'] = false;
$json['companies'][$company_key]['business_entity_type'] = null;
$json['companies'][$company_key]['business_years'] = "";
$json['companies'][$company_key]['business_month'] = "";
$json['companies'][$company_key]['business_date_object'] = "";
//$json['companies'][$company_key]['business_date_object'] = "";
}
}
$json['company_with_relationships'][] = array('applicant_name' => "", 'company_relationship' => '', 'relation_to_company' => "");
$json['general_remark'] = "";
return (($json));
}
public function downloadExcel_get()
{
$this->excel->setActiveSheetIndex(0)->mergeCells('F3:M3');
$this->excel->getActiveSheet()->setTitle('Material Master');
$this->excel->getActiveSheet()->setCellValue('F3', 'SIDDHARTH INDUSTRIES Material Master');
$filename = 'MaterialMaster' . '.xls'; //save our workbook as this file name
header('Content-Type: application/vnd.ms-excel'); //mime type
header('Access-Control-Expose-Headers:Content-Disposition'); //mime type
header('Content-Disposition: attachment;filename="' . $filename . '"'); //tell browser what's the file name
header('Cache-Control: max-age=0'); //no cache
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
if (ob_get_contents()) ob_end_clean();
ob_start();
$objWriter->save('php://output');
}
//Save Co applicants details from General Form
public function saveCoApplicantsFromGeneralInfoForm($records)
{
//print_r($records);die();
if (count($records['individuals'])) {
//echo 'saveCoApplicantsFromGeneralInfoForm';
$exist_applicants = $this->PD_Model->getApplicantsDetails($records['pdid']);
//print_r($exist_applicants);
//echo "Yes";
$index_of_new_applicants = array();
foreach ($records['individuals'] as $applicant_key => $new_applicant) {
$count = 0;
if ($new_applicant['is_new'] == true && ($new_applicant['is_applicant'] == true || $new_applicant['is_person_met'] == true)) {
$current_temp_id = $new_applicant['pd_co_applicant_id'];
$temp_array = array();
if ($new_applicant['is_person_met'] == true) {
$temp_array = array('fk_pd_id' => $records['pdid'], 'applicant_name' => $new_applicant['applicant_name'], 'applicant_type' => 3, 'applicant_title_name' => $new_applicant['applicant_title_name']);
}
if ($new_applicant['is_applicant'] == true) {
$temp_array = array('fk_pd_id' => $records['pdid'], 'applicant_name' => $new_applicant['applicant_name'], 'applicant_type' => 0, 'applicant_title_name' => $new_applicant['applicant_title_name']);
}
$new_co_appliacant_id = $this->PD_Model->saveRecords($temp_array, PDAPPLICANTSDETAILS);
if ($new_co_appliacant_id != null || $new_co_appliacant_id != "") {
$records['individuals'][$applicant_key]['pd_co_applicant_id'] = $new_co_appliacant_id;
$records['individuals'][$applicant_key]['is_new'] = false;
if (array_key_exists('persons_with_relationships', $records)) {
foreach ($records['persons_with_relationships'] as $persons_with_relationship_key => $persons_with_relationship) {
if ($persons_with_relationship['pd_co_applicant_id'] == $current_temp_id) {
$records['persons_with_relationships'][$persons_with_relationship_key]['pd_co_applicant_id'] = $new_co_appliacant_id;
}
if ($persons_with_relationship['relation_to'] == $current_temp_id) {
$records['persons_with_relationships'][$persons_with_relationship_key]['relation_to'] = $new_co_appliacant_id;
}
}
}
if (array_key_exists('company_with_relationships', $records)) {
foreach ($records['company_with_relationships'] as $company_with_relationship_key => $company_with_relationship) {
if ($company_with_relationship['applicant_name'] == $current_temp_id) {
$records['company_with_relationships'][$company_with_relationship_key]['applicant_name'] = $new_co_appliacant_id;
}
}
}
/*################### LOGGING #########################*/
$logger = MYLOG::logFunction(null, $records['pdid']);
$temp_array['pd_co_applicant_id'] = $new_co_appliacant_id;
$logger->info("APPLICANT ADDED FROM GENERAL FORM - ENV (" . ENVIRONMENT . ")", $temp_array);
/*################### LOGGING #########################*/
}
}
// if($new_applicant['is_new'] == false)
// {
// $temp_array = array();
// $where_condition_array = array('pd_co_applicant_id'=>$new_applicant['pd_co_applicant_id']);
// if($new_applicant['is_person_met'] == true)
// {
// $temp_array = array('applicant_name'=>$new_applicant['applicant_name'],'applicant_type'=>3,'applicant_title_name'=>$new_applicant['applicant_title_name']);
// }
// if($new_applicant['is_applicant'] == true)
// {
// $temp_array = array('applicant_name'=>$new_applicant['applicant_name'],'applicant_type'=>0,'applicant_title_name'=>$new_applicant['applicant_title_name']);
// }
// if($new_applicant['is_main_applicant'] == true)
// {
// $temp_array = array('applicant_name'=>$new_applicant['applicant_name'],'applicant_type'=>1,'applicant_title_name'=>$new_applicant['applicant_title_name']);
// }
// $new_co_appliacant_id = $this->PD_Model->updateRecords($temp_array,PDAPPLICANTSDETAILS,$where_condition_array);
// if($new_co_appliacant_id != "" || $new_co_appliacant_id != null)
// {
// /*################### LOGGING #########################*/
// $logger = MYLOG::logFunction();
// $temp_array['pd_co_applicant_id'] = $new_applicant['pd_co_applicant_id'];
// $logger->info("APPLICANT EDITED FROM GENERAL FORM ENV (".ENVIRONMENT.")",$temp_array);
// /*################### LOGGING #########################*/
// }
// }
if (array_key_exists('is_active', $new_applicant)) {
if ($new_applicant['is_active'] == false) {
$rows_afftecd = $this->db->where('pd_co_applicant_id', $new_applicant['pd_co_applicant_id'])->delete(PDAPPLICANTSDETAILS);
if ($rows_afftecd != "" && $rows_afftecd != null) {
/*################### LOGGING #########################*/
$logger = MYLOG::logFunction(null, $records['pdid']);
$logger->info("APPLICANT DELETED FROM GENERAL FORM ENV (" . ENVIRONMENT . ")", $new_applicant);
/*################### LOGGING #########################*/
}
}
}
}
foreach ($records['companies'] as $company_key => $company) {
if ($company['is_company_applicant'] == true && $company['is_new'] == true) {
$temp_array = array('fk_pd_id' => $records['pdid'], 'applicant_name' => $company['company_name'], 'applicant_type' => 2, 'applicant_title_name' => $company['company_messrs_name']);
$new_co_appliacant_id = $this->PD_Model->saveRecords($temp_array, PDAPPLICANTSDETAILS);
$records['companies'][$company_key]['is_new'] = false;
$records['companies'][$company_key]['pd_co_applicant_id'] = $new_co_appliacant_id;
/*################### LOGGING #########################*/
$logger = MYLOG::logFunction(null, $records['pdid']);
$temp_array['pd_co_applicant_id'] = $new_co_appliacant_id;
$logger->info("COMPANY ADDED AS APPLICANT FROM GENERAL FORM ENV (" . ENVIRONMENT . ")", $temp_array);
/*################### LOGGING #########################*/
}
if (array_key_exists('is_active', $company)) {
if ($company['is_active'] == false && $company['is_company_applicant'] == true) {
$rows_afftecd = $this->db->where('applicant_name', $company['company_name'])->where('fk_pd_id', $records['pdid'])->delete(PDAPPLICANTSDETAILS);
if ($rows_afftecd != "" || $rows_afftecd != null) {
/*################### LOGGING #########################*/
$logger = MYLOG::logFunction(null, $records['pdid']);
//$temp_array['pd_co_applicant_id'] = $new_co_appliacant_id;
$logger->info("COMPANY(APPLICANT) DELETED FROM GENERAL FORM ENV (" . ENVIRONMENT . ")", $company);
/*################### LOGGING #########################*/
}
}
}
}
}
return $records;
}
public function getAssessedIncome_post()
{
$pd_id = $this->post('pd_id');
$pd_form_id = $this->post('pd_form_id');
$company_id = $this->post('company_id') ? $this->post('company_id') : null;
$result_array = $this->PD_Model->getAssessedIncome($pd_id, $company_id);
$result_array['final_data'] = array();
$fine = $this->calculateAssessedIncome($pd_id, $company_id);
//print_r($fine);die();
//print_r($fine);die();
if ($fine != null) {
$fine['purchase_declared_by_customer'] = $result_array['purchase_declared_by_customer'];
$fine['sales_revenue_details'] = $result_array['sales_calculated_by_itemwise'];
$fine['other_business_income_details'] = $result_array['othre_business_income'];
$fine['purchase_details'] = $result_array['purchase_details'];
//$fine['purchase_billwise'] = $result_array['purchase_billwise'];
$fine['business_expense_details'] = $result_array['business_expenses'];
$fine['house_hold_expense_details'] = $result_array['house_hold_expenses'];
$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['purchase_details']) == 0 && count($result_array['purchase_declared_by_customer']) == 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 saveAssessedIncomePurchaseDeclaredByCustomer_post()
{
$records = $this->post('records');
$pk = "";
if ($records['pdc_id'] != null || $records['pdc_id'] != "") {
$where_condition_array = array('pdc_id' => $records['pdc_id']);
$pk = $this->PD_Model->updateRecords($records, PURCHASEDECLAREDBYCUSTOMER, $where_condition_array);
} else {
$pk = $this->PD_Model->saveRecords($records, PURCHASEDECLAREDBYCUSTOMER);
}
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 saveOtherBusinessIncome_post()
{
$records = $this->post('records');
$count = 0;
foreach ($records as $rec_key => $record) {
if ($record['pd_business_income_id'] != null || $record['pd_business_income_id'] != "") {
$where_condition_array = array('pd_business_income_id' => $record['pd_business_income_id']);
$id = $this->PD_Model->updateRecords($record, PDBUSINESSINCOME, $where_condition_array);
if ($id != "" || $id != null) {
$count++;
}
} else {
$id = $this->PD_Model->saveRecords($record, PDBUSINESSINCOME);
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 saveAssessedIncomeSalesCalculatedByItemwise_post()
{
$records = $this->post('records');
$count = 0;
foreach ($records as $rec_key => $record) {
$child_data = array();
if (array_key_exists('child', $record)) {
$child_data = $record['child'];
unset($record['child']);
}
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++;
}
if ($record['sales_type'] == 3) {
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 {
if (($child['sales_date'] != null || $child['sales_date'] != "")) {
$child['fk_sci_id'] = $record['sci_id'];
$child_id = $this->PD_Model->saveRecords($child, SALESITEMMONTHWISECHILD);
}
}
}
}
} else {
$id = $this->PD_Model->saveRecords($record, SALESCALCULATEDBYITEMWISE);
if ($id != "" || $id != null) {
$count++;
}
if ($record['sales_type'] == 3) {
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 {
if (($child['sales_date'] != null || $child['sales_date'] != "")) {
$child['fk_sci_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'] = 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) {
$child_data = "";
if (array_key_exists('child', $record)) {
$child_data = $record['child'];
unset($record['child']);
}
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++;
}
if ($record['purchase_type'] == 3) {
if ($id != "" || $id != null) {
foreach ($child_data as $ckey => $child) {
if ($child['pbwc_id'] != "" || $child['pbwc_id'] != null) {
$where_condition_array = array('pbwc_id' => $child['pbwc_id']);
$child_id = $this->PD_Model->updateRecords($child, PDPURCHASEBILLWISECHILD, $where_condition_array);
} else {
$child['fk_purchase_id'] = $record['purchase_id'];
$child_id = $this->PD_Model->saveRecords($child, PDPURCHASEBILLWISECHILD);
}
}
}
}
} else {
$id = $this->PD_Model->saveRecords($record, PDPURCHASEDETAILS);
if ($id != "" || $id != null) {
$count++;
}
if ($record['purchase_type'] == 3) {
if ($id != "" || $id != null) {
foreach ($child_data as $ckey => $child) {
if ($child['pbwc_id'] != "" || $child['pbwc_id'] != null) {
$where_condition_array = array('pbwc_id' => $child['pbwc_id']);
$child_id = $this->PD_Model->updateRecords($child, PDPURCHASEBILLWISECHILD, $where_condition_array);
} else {
$child['fk_purchase_id'] = $id;
$child_id = $this->PD_Model->saveRecords($child, PDPURCHASEBILLWISECHILD);
}
}
}
}
}
}
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);
}
}
/*************NOT IN USE***********NOT IN USE*************************NOT IN USE************
*************NOT IN USE*********NOT IN USE*****************NOT IN USE***********************/
public function saveAssessedIncomeMonthwiseItems($item) //SALESITEMMONTHWISECHILD - NOT IN USE
{
//$records = $this->post('records');
$record = $item;
$count = 0;
//foreach($records as $key => $record)
//{
//$record['sales_type']
$child_data = array();
if (array_key_exists('child', $record)) {
$child_data = $record['child'];
unset($record['child']);
}
$id = "";
//Remove other than DB fields
if (array_key_exists('margin_final_value', $record)) {
$record['margin_value'] = $record['margin_final_value'];
unset($record['margin_final_value']);
}
// array_key_exists('sales_qty', $record) ? unset($record['sales_qty']) : '';
// array_key_exists('fk_uom_id', $record) ? unset($record['fk_uom_id']) : '';
// array_key_exists('rate_per_unit', $record) ? unset($record['rate_per_unit']) : '';
// array_key_exists('fk_frequency_id', $record) ? unset($record['fk_frequency_id']) : '';
// array_key_exists('annual_sale_value', $record) ? unset($record['annual_sale_value']) : '';
// array_key_exists('margin_per_uom', $record) ? unset($record['margin_per_uom']) : '';
// CURD Operations
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 {
if (($child['sales_date'] != null || $child['sales_date'] != "")) {
$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) {
if ((($child['sales_date'] != null || $child['sales_date'] != ""))) {
//echo 'true';
$child['fk_sim_id'] = $id;
$child_id = $this->PD_Model->saveRecords($child, SALESITEMMONTHWISECHILD);
}
}
}
}
//}
if ($id != "") {
return 1;
}
}
//Save Purcahse Items billwise - NOT IN USE
public function saveAssessedIncomePurchaseBillwise_post() //SALESITEMMONTHWISECHILD - NOT IN USE
{
$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['pbw_id'] != null || $record['pbw_id'] != "") {
$where_condition_array = array('pbw_id' => $record['pbw_id']);
$id = $this->PD_Model->updateRecords($record, PDPURCHASEBILLWISE, $where_condition_array);
if ($id != "" || $id != null) {
$count++;
foreach ($child_data as $ckey => $child) {
if ($child['pbwc_id'] != "" || $child['pbwc_id'] != null) {
$where_condition_array = array('pbwc_id' => $child['pbwc_id']);
$child_id = $this->PD_Model->updateRecords($child, PDPURCHASEBILLWISECHILD, $where_condition_array);
} else {
$child['fk_pbw_id'] = $record['pbw_id'];
$child_id = $this->PD_Model->saveRecords($child, PDPURCHASEBILLWISECHILD);
}
}
}
} else {
$id = $this->PD_Model->saveRecords($record, PDPURCHASEBILLWISE);
if ($id != "" || $id != null) {
$count++;
foreach ($child_data as $ckey => $child) {
$child['fk_pbw_id'] = $id;
$child_id = $this->PD_Model->saveRecords($child, PDPURCHASEBILLWISECHILD);
}
}
}
}
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');
$random_string = $this->post('random_string');
$final_data_to_response = array();
$final_data_to_response['question_answers']['general_questions'] = "";
$pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id, $random_string);
$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, 'PDFORMS.pd_form_order');
//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_form_raw_data_with_score = $this->calculatePDScore($pd_form_raw_data);
$transformed_data = $this->transformKeyPairToQuestionAnswers($pd_form_raw_data, $template_form_detail['form_id']);
if($final_data_to_response['fk_pd_type'] != 4){
$final_data_to_response['question_answers']['form_details'][] = array('name' => [$template_form_detail['pd_form_name']], 'details' => $transformed_data);
}else{$final_data_to_response['question_answers']['form_details'] = array(); }
//$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);die();
$current_question_array = array();
if (count($pd_form_raw_data)) {
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_id' => $raw_data['fk_category_id'], 'category_name' => $raw_data['category_name'], 'category_weightage' => $raw_data['category_weightage'], 'question_weightage' => $raw_data['question_weightage'], 'answer_score' => $raw_data['score'], 'max_score' => $raw_data['max_score'], 'question' => $master['question'], 'answer' => $raw_data['column_value'], 'actual_score' => $raw_data['actual_score'], 'exact_score' => $raw_data['exact_score']);
} 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_id' => $raw_data['fk_category_id'], 'category_name' => $raw_data['category_name'], 'category_weightage' => $raw_data['category_weightage'], 'question_weightage' => $raw_data['question_weightage'], 'answer_score' => $raw_data['score'], 'max_score' => $raw_data['max_score'], 'question' => $master['question'], 'answer' => $result_data[0]['name'], 'actual_score' => $raw_data['actual_score'], 'exact_score' => $raw_data['exact_score']);
}
//
}
}
}
}
}
}
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, $company_id)
{
$overall_summary_report = array();
$overall_summary_report['sales_calculated_by_itemwise'] = null;
$overall_summary_report['sales_declared_by_customer'] = null;
$sales_declared_by_customer = array();
$sales_declared_by_customer_flag = 0;
$sales_calculated_by_itemwise = array();
$sales_calculated_by_itemwise_flag = 0;
$purchases = array();
$purchases_flag = 0;
$purchase_declared_by_customer = array();
$purchase_declared_by_customer_flag = 0;
$business_expenses = array();
$business_expenses_flag = 0;
$household_expenses = array();
$household_expenses_flag = 0;
$other_business_income = array();
$other_business_income_flag = 0;
$overall_purchase_total = 0;
$overall_business_expenses_total = 0;
$overall_other_business_income_total = 0;
$overall_household_total = 0;
$net_profit = 0;
$final_sales_avg_value = 0;
//Get all Master Details
$result_array = $this->PD_Model->getAssessedIncome($pd_id, $company_id);
$sales_declared_by_customer = $result_array['sales_declared_by_customer'];
$sales_calculated_by_itemwise = $result_array['sales_calculated_by_itemwise'];
$purchases = $result_array['purchase_details'];
$purchase_declared_by_customer = $result_array['purchase_declared_by_customer'];
$business_expenses = $result_array['business_expenses'];
$other_business_income = $result_array['othre_business_income'];
$household_expenses = $result_array['house_hold_expenses'];
$gross_profit_calculation_type = $result_array['gross_profit_calculation_type'];
$othre_business_income = $result_array['othre_business_income'];
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($purchases)) {
$purchases_flag = 1;
}
//echo $sales_calculated_by_itemwise_flag.$purchases_flag;
if (count($purchase_declared_by_customer)) {
$purchase_declared_by_customer_flag = 1;
}
if (count($business_expenses)) {
$business_expenses_flag = 1;
}
if (count($household_expenses)) {
$household_expenses_flag = 1;
}
if (count($other_business_income)) {
$other_business_income_flag = 1;
}
// if(($business_expenses_flag == 1) && ($sales_declared_by_customer_flag == 1 || $purchase_declared_by_customer_flag) || ($sales_calculated_by_itemwise_flag == 1 || $purchases_flag == 1))
if ($gross_profit_calculation_type[0]['is_completed']) {
$total_sales_itemwise = 0;
$sales_monthwise = array();
$total_sales_monthwise = 0;
$total_sales_declared_by_customer = 0;
foreach ($other_business_income as $other_business_key => $other_business) {
$overall_other_business_income_total = $overall_other_business_income_total + $other_business['annual_income_value'];
}
foreach ($business_expenses as $business_key => $business_expense) {
$overall_business_expenses_total = $overall_business_expenses_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 += $purchase['annual_purchase_value'];
}
}
if ($sales_calculated_by_itemwise_flag == 1) {
$temp_purchases = 0;
$temp_netprofit = 0;
$temp_grossprofit = 0;
$temp_netmargin = 0;
$month_total = 0;
$i = 0;
foreach ($sales_calculated_by_itemwise as $itemwise_key => $item) {
$total_sales_itemwise = $total_sales_itemwise + $item['annual_sale_value'];
$temp_netprofit = $temp_netprofit + $item['margin_final_value'];
}
$total_sales_monthwise = 0;
//calculatin part
if ($gross_profit_calculation_type[0]['mode'] == 1) {
$temp_purchases = $overall_purchase_total;
$temp_grossprofit = ($total_sales_itemwise + $total_sales_monthwise) - $temp_purchases;
$temp_netprofit = $temp_grossprofit - $overall_business_expenses_total;
if ($temp_netprofit != 0 && ($total_sales_itemwise + $total_sales_monthwise) != 0) {
$temp_netmargin = ($temp_netprofit / ($total_sales_itemwise + $total_sales_monthwise)) * 100;
} else {
$temp_netmargin = 0;
}
} else {
// This one changes as per 15/03/2019 Excel Review changes
$temp_grossprofit = $temp_netprofit; // + $overall_business_expenses_total;
$temp_netprofit = $temp_grossprofit - $overall_business_expenses_total;
$temp_purchases = ($total_sales_itemwise + $total_sales_monthwise) - $temp_grossprofit;
if ($temp_netprofit != 0 && ($total_sales_itemwise + $total_sales_monthwise) != 0) {
$temp_netmargin = ($temp_netprofit / ($total_sales_itemwise + $total_sales_monthwise) * 100);
} else {
$temp_netmargin = 0;
}
}
$overall_summary_report['sales_calculated_by_itemwise']['sales_revenue'] = round($total_sales_itemwise + $total_sales_monthwise);
($gross_profit_calculation_type[0]['mode'] == 1) ? $overall_summary_report['sales_calculated_by_itemwise']['purchases'] = round($temp_purchases, 2) : $overall_summary_report['sales_calculated_by_itemwise']['cost_of_goods_sold'] = round($temp_purchases);
$overall_summary_report['sales_calculated_by_itemwise']['grossprofit'] = round($temp_grossprofit);
$overall_summary_report['sales_calculated_by_itemwise']['business_expenses'] = round($overall_business_expenses_total);
$overall_summary_report['sales_calculated_by_itemwise']['netprofit'] = round($temp_netprofit);
$overall_summary_report['sales_calculated_by_itemwise']['house_hold_expenses'] = round($overall_household_total);
$overall_summary_report['sales_calculated_by_itemwise']['disposable_income'] = round($temp_netprofit - $overall_household_total);
$overall_summary_report['sales_calculated_by_itemwise']['netmargin'] = round($temp_netmargin, 2);
}
if ($sales_declared_by_customer_flag == 1) {
$temp_purchases = 0;
$temp_netprofit = 0;
$temp_grossprofit = 0;
$temp_netmargin = 0;
$total_sales_declared_by_customer = $sales_declared_by_customer[0]['sales_declared_by_customer'];
$temp_netprofit = $sales_declared_by_customer[0]['margin_value'];
if ($gross_profit_calculation_type[0]['mode'] == 1) {
$total_purchase_declared_by_customer = $purchase_declared_by_customer[0]['purchase_declared_by_customer'];
$temp_purchases = $total_purchase_declared_by_customer;
$temp_grossprofit = $total_sales_declared_by_customer - $temp_purchases;
$temp_netprofit = $temp_grossprofit - $overall_business_expenses_total;
$temp_netmargin = $total_sales_declared_by_customer > 0 ? ($temp_netprofit / $total_sales_declared_by_customer) * 100 : 0;
} else {
$temp_grossprofit = $temp_netprofit + $overall_business_expenses_total;
$temp_purchases = $total_sales_declared_by_customer - $temp_grossprofit;
$temp_netmargin = $total_sales_declared_by_customer > 0 ? ($temp_netprofit / $total_sales_declared_by_customer) * 100 : 0;
}
$overall_summary_report['sales_declared_by_customer']['sales_revenue'] = round($total_sales_declared_by_customer);
($gross_profit_calculation_type[0]['mode'] == 1) ? $overall_summary_report['sales_declared_by_customer']['purchases'] = round($temp_purchases) : $overall_summary_report['sales_declared_by_customer']['cost_of_goods_sold'] = round($temp_purchases);
$overall_summary_report['sales_declared_by_customer']['grossprofit'] = round($temp_grossprofit);
$overall_summary_report['sales_declared_by_customer']['business_expenses'] = round($overall_business_expenses_total);
$overall_summary_report['sales_declared_by_customer']['netprofit'] = round($temp_netprofit);
$overall_summary_report['sales_declared_by_customer']['house_hold_expenses'] = round($overall_household_total);
$overall_summary_report['sales_declared_by_customer']['disposable_income'] = round($temp_netprofit - $overall_household_total);
$overall_summary_report['sales_declared_by_customer']['netmargin'] = round($temp_netmargin, 2);
}
$temp_sales_array = array();
if (isset($overall_summary_report['sales_declared_by_customer']['sales_revenue'])) {
$temp_sales_array = array_merge($temp_sales_array, array($overall_summary_report['sales_declared_by_customer']['sales_revenue']));
}
//if(isset($overall_summary_report['sales_calculated_by_monthwise']['sales_revenue'])){ $temp_sales_array = array_merge($temp_sales_array,array($overall_summary_report['sales_calculated_by_monthwise']['sales_revenue'])); }
if (isset($overall_summary_report['sales_calculated_by_itemwise']['sales_revenue'])) {
$temp_sales_array = array_merge($temp_sales_array, array($overall_summary_report['sales_calculated_by_itemwise']['sales_revenue']));
}
$temp_netmargin_array = array();
if (isset($overall_summary_report['sales_declared_by_customer']['netprofit'])) {
$temp_netmargin_array = array_merge($temp_netmargin_array, array($overall_summary_report['sales_declared_by_customer']['netprofit']));
}
//if(isset($overall_summary_report['sales_calculated_by_monthwise']['netprofit'])){ $temp_netmargin_array = array_merge($temp_netmargin_array,array($overall_summary_report['sales_calculated_by_monthwise']['netprofit'])); }
if (isset($overall_summary_report['sales_calculated_by_itemwise']['netprofit'])) {
$temp_netmargin_array = array_merge($temp_netmargin_array, array($overall_summary_report['sales_calculated_by_itemwise']['netprofit']));
}
if (count($temp_sales_array)) {
$overall_summary_report['consolidated_report']['consolidated_sales_revenue'] = round(array_sum($temp_sales_array) / count($temp_sales_array));
} else {
$overall_summary_report['consolidated_report']['consolidated_sales_revenue'] = 0.0;
}
if (count($temp_netmargin_array)) {
$overall_summary_report['consolidated_report']['consolidated_nerprofit'] = round(array_sum($temp_netmargin_array) / count($temp_netmargin_array));
} else {
$overall_summary_report['consolidated_report']['consolidated_nerprofit'] = 0.0;
}
if ($overall_summary_report['consolidated_report']['consolidated_nerprofit'] != 0 && $overall_summary_report['consolidated_report']['consolidated_sales_revenue'] != 0) {
$overall_summary_report['consolidated_report']['consolidated_nermagin'] = round((($overall_summary_report['consolidated_report']['consolidated_nerprofit'] / $overall_summary_report['consolidated_report']['consolidated_sales_revenue']) * 100), 2);
} else {
$overall_summary_report['consolidated_report']['consolidated_nermagin'] = 0;
}
return ($overall_summary_report);
} else {
return null;
}
}
/*********************************************************************************************
*********************************************************************************************/
public function getLatestPDReportBlob_post()
{
$records = $this->post('records');
//print_r($records);die();
$records = $records['pd_id'];
$pdid = $records['startId'];
$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);
}
}
/*********************************************************************************************
*********************************************************************************************/
//Generate Report AS PDF
public function generatePDReportPDF_post()
{
$records = $this->post('records');
$pdid = $records['pd_id'];
$fk_createdby = $records['fk_createdby'];
$is_generate = isset($records['is_generate']) ? 1 : 0;
$random_string = $records['random_string'];
$is_qc_edited = 0;
//echo "step1.Function Entered";
$this->load->helper('report_attachments');
if (!file_exists($this->external_path . '/pd_reports/' . $pdid)) {
mkdir($this->external_path . '/pd_reports/' . $pdid, 0777);
}
$pd_master_details = $this->PD_Model->getPDMasterDetails($pdid, $random_string);
// print_r($pd_master_details);
// var_dump($pd_master_details[0]['is_img_pdf_created']);
// check img zip link, img pdf link and vide links
if (!$pd_master_details[0]['is_img_pdf_created']) {
$data['msg'] = isset($data['msg']) ? ($data['msg'] . 'Image PDF' . ', ') : 'Image PDF, ';
}
if (!$pd_master_details[0]['is_zip_created']) {
$data['msg'] = isset($data['msg']) ? ($data['msg'] . 'Image ZIP' . ', ') : 'Image ZIP, ';
}
// if($pd_master_details[0]['fk_pd_type'] == 2)
// {
// $video_status = $this->PD_Model->selectCustomRecords(array('count(*) as count'),array('isactive' => 1,'twilo_status' => 'enqueued','fk_pd_id' => $pdid),VIDEO_ROOM_INFO);
// if($video_status[0]['count'] != 0)
// {
// $data['msg'] = isset($data['msg']) ? ($data['msg'] . 'Some videos'.', ') : 'Some videos, ';
// }
// }
// print_r($data);
// echo strrpos($data['msg'], ',');
if (isset($data['msg']) && $data['msg'] != '') {
$data['msg'] = substr_replace($data['msg'], '', -2);
if (strrpos($data['msg'], ',')) {
$data['msg'] = substr_replace($data['msg'], ' and ', strrpos($data['msg'], ','), 2);
}
$data['msg'] = ('The following item(s) yet to be complete :- ' . $data['msg']);
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$this->response($data, REST_Controller::HTTP_OK);
}
$bucketname = LENDER_BUCKET_NAME_PREFIX . $pd_master_details[0]['fk_lender_id'];
$main_applicant_name = $pd_master_details[0]['main_applicant'];
$pdf_name = 'PD_Report_' . $main_applicant_name;
$key = 'pd' . $pdid . '/pd_reports/' . $main_applicant_name . '.pdf';
$newkey = 'pd' . $pdid . '/pd_reports/' . $pdf_name . '.pdf';
if ($pd_master_details[0]['is_qc_edited']) {
$is_qc_edited = $pd_master_details[0]['is_qc_edited'];
}
if ($is_qc_edited == 1 || $is_qc_edited == 2) {
//Get Latest PD Report Html file and convert it into PDF
$latest_pd_report_html_file_name = $pd_master_details[0]['pd_report_html_filename'];
$latest_pd_report_html_file_path = $this->external_path . '/pd_reports/' . $pdid . '/' . $latest_pd_report_html_file_name . '.html';
$temp = file_get_contents($latest_pd_report_html_file_path);
//Replace Span tags from HTML File
$total_replaces = substr_count($temp, '');
for ($i = 0; $i < $total_replaces; $i++) {
$start_pos = strpos($temp, '');
$end_pos = strpos($temp, '', strpos($temp, ''));
$end_pos = $end_pos + 14;
//echo $start_pos.'-';echo $end_pos.'-';echo ($end_pos - $start_pos).'-';
$temp = substr_replace($temp, '', $start_pos, ($end_pos - $start_pos));
$temp = substr_replace($temp, '', strpos($temp, ''), (strlen('')));
}
//End Of Replace Span tags from HTML File
//Get attachment links and embed here...
//get img pdf
$report_attachments = (new report_attachments)->getReportAttchments($pd_master_details[0]['pd_id'], $pd_master_details[0]['random_string'], $pd_master_details);
$temp = substr_replace($temp, $report_attachments, strpos($temp, '
// $sql = "SELECT email FROM sineedgeprod.m_user_profile where email like '%imgc%'";
// $u = $this->db->query($sql)->result_array();
// print_r($u);
// die();
// foreach($u as $v)
// {
//$this->aws_cognito->adminSetUserPassword('harshita.nadigatla@imgc.com');
// }
//die();
$is_regenerate = 0;
if (isset($records['regenerate'])) {
$is_regenerate = 1;
}
//print_r($records);
$add_on_pd = $this->PD_Model->selectCustomRecords(array('pd_id'), array('parent_pd_id' => $pdid, 'is_child' => 1), PDTRIGGER);
$data['pd_master_details'] = $this->PD_Model->getPDMasterDetails($pdid);
$data['applicants_details'] = $this->PD_Model->getApplicantsDetails($pdid);
// print_r($data['pd_master_details']);die();
//$data['satellite_path'] = $this->external_path.'/pd_reports/'. $pdid .'/satellite.png';
// $data['pd_master_details'][0]['lender_short_name'] = 'CLIXH';
// $data['pd_master_details'][0]['product_abbr'] = 'HL';
// if($data['pd_master_details'][0]['lender_short_name'] == 'CHFPL' && ($data['pd_master_details'][0]['product_abbr'] == 'LAP' || $data['pd_master_details'][0]['product_abbr'] == 'NRPL'))
// {
// // echo 'XXX';
// $clix_lender_id = ENVIRONMENT == 'production' ? 5 : 16; //clix lender id based on env
// $data['lender_disclaimer'] = $this->PD_Model->selectRecords(ENTITYDISCLAIMER,array('fk_entity_id' => $clix_lender_id));
// //print_r($this->db->last_query());
// }
// else
// {
// echo 'NOR';
// print_r($data['pd_master_details']);die();
$entity_geo_location = $this->PD_Model->getEntityAddr($data['pd_master_details'][0]['fk_lender_id']);
if ($entity_geo_location != 0) {
$pd_location = $data['pd_master_details'][0]['start_location'];
$data['distances'] = satellite_image::getdistancematrix($entity_geo_location, $pd_location);
} else {
$data['distances'] = "";
}
$pd_type = $data['pd_master_details'][0]['fk_pd_type'] == 3 ? 3 : 1;
$data['lender_disclaimer'] = $this->PD_Model->selectRecords(ENTITYDISCLAIMER, array('fk_entity_id' => ($data['pd_master_details'][0]['sub_entity_id'] ? $data['pd_master_details'][0]['sub_entity_id'] : $data['pd_master_details'][0]['fk_lender_id']), 'fk_pd_type' => $pd_type));
//}
//print_r($data['lender_disclaimer']);die();
//$GLOBALS['footer_lender_disclaimer'] = $data['lender_disclaimer'][0]['type'] == 2 ? $data['lender_disclaimer'][0]['disclaimer'] : (isset($data['lender_disclaimer'][1]) && $$data['lender_disclaimer'][1]['type'] == 2 ? $$data['lender_disclaimer'][1]['disclaimer'] : '');
$data['pd_additional_requirements'] = $this->PD_Model->getPDAdditionalRequirements($pdid);
$data['score_questions_display'] = $this->PD_Model->getScoreableQuestionToDispaly();
// print_r($data['pd_score']);
// die();
$data['assessed_income_details'] = $this->getAssessedIncomeForPDReport($pdid);
//print_r($data['pd_master_details'][0]['is_score_card_enabled']);die();
// echo "**************************";
//$data['dsc_cards'] = $this->getDetailedScoreCardChart( $data['pd_score'] );
if ($data['pd_master_details'][0]['is_score_card_enabled'] == 1 && ($data['pd_master_details'][0]['customer_segment_abbr'] != "SAL" && $data['pd_master_details'][0]['customer_segment_abbr'] != "SE-RI")) // && $data['pd_master_details'][0]['customer_segment_abbr'] != "SAL-CHQ")) //&& ($data['pd_master_details'][0]['customer_segment_abbr'] != ''))
{
//echo $data['pd_master_details'][0]['is_score_card_enabled'].'-'.$data['pd_master_details'][0]['customer_segment_abbr'];die();
if ($data['pd_master_details'][0]['fk_pd_type'] != 4) {
$data['pd_score'] = $this->calculateScore($pdid);
$score_for_chart = $data['pd_score']['score_summary']['overall_score']['final_score'] ? round($data['pd_score']['score_summary']['overall_score']['final_score'], 1) : 0;
//echo $score_for_chart;die();
//GET phantom script from DB
$phantom_script = $this->PD_Model->selectCustomRecords(array('*'), array('script_name' => 'phantomjs_local'), SCRIPTS);
$exact_script = $phantom_script[0]['script_content'];
//print_r($exact_script);
$apppath = str_replace('\\', '/', $this->external_path . '/pd_reports/' . $pdid);
$exact_script = str_replace('{{APPPATH}}', $apppath, $exact_script);
$exact_script = str_replace('{{place_score_here}}', $score_for_chart, $exact_script);
//print_r($exact_script);die();
//GENERATE CHART PART
file_put_contents(APPPATH . '/views/js/phantomchart.js', $exact_script, LOCK_EX);
$str = 'phantomjs ' . APPPATH . '/views/js/phantomchart.js';
// exec($str,$ou);
// exec('phantom.exit();');
//print_r($ou);
$chart_img_path = $this->external_path . '/pd_reports/' . $pdid . '/chart.png';
$type = pathinfo($chart_img_path, PATHINFO_EXTENSION);
$chart_img_content = file_get_contents($chart_img_path);
$base64_pdscore_chart_url = 'data:image/' . $type . ';base64,' . base64_encode($chart_img_content);
$data['base64_pdscore_chart_url'] = $base64_pdscore_chart_url;
//echo $data['base64_pdscore_chart_url'];
}
//GENERATE CHART PART
}
//die();
//GET ALL PROCESSED JSON
for ($i = 1; $i <= 35; $i++) {
$fields = array('processed_json');
if ($i == 25) {
$fields = array('json');
}
$where_condition_array = array('isactive' => 1, 'fk_pd_id' => $pdid, 'fk_form_id' => $i);
$data['pd_processed_forms'][$i] = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON, array(), '', 'company_id', 'ASC');
$fields2 = array('*');
$data['pd_images'][$i] = $this->PD_Model->getSignedPDDocsURL($pdid, $i, null, null, null, 'report');
// $this->getPDImages_post``($fields2,array('fk_pd_id'=>$pdid,'fk_form_id' => $i),PDDOCUMENTS,array(),'','company_id','ASC');
// print_r($this->db->last_query());
}
//print_r(json_decode($data['pd_processed_forms'][25][0]['json'],true));die();
//echo $data['pd_master_details'][0]['customer_segment_abbr'].$data['pd_master_details'][0]['fk_pd_type'];
// $data['pd_master_details'][0]['fk_pd_type'] = 3;
if ($data['pd_master_details'][0]['customer_segment_abbr'] == "SAL" && $data['pd_master_details'][0]['fk_pd_type'] != 3) // && $data['pd_master_details'][0]['fk_pd_type'] != 1)
{
$data['pd_images']['common_images'] = $this->PD_Model->getSignedPDDocsURL($pdid, null, null, null, null, 'report');
} else {
$data['pd_images']['common_images'] = $this->PD_Model->getSignedPDDocsURL($pdid, null, null, 'common', null, 'report');
}
// echo "i ahve image";
// print_r($data['pd_images']);die();
// die();
//print_r(json_decode($data['pd_processed_forms'][24][0]['processed_json']));//die();
// $it = array_filter($data['pd_images'][11],function($d){ if($d['company_id'] == 2){ echo $d['company_id'].'TRUE';return 1;}else {echo $d['company_id'].'FALSE'; return 0;} });
// print_r($it);
// die(); //print_r(json_decode($data['pd_processed_forms'][14][0]['processed_json'],true));
// die();
//echo "*******************************************";
//get add on forms and images
if (count($add_on_pd)) {
$data['add_on_pd_forms'] = array();
$data['add_on_pd_images'] = array();
$data['add_on_pd_master_details'] = array();
$add_on_forms = array(18, 5, 19, 1, 2, 22, 23, 1, 11); //
foreach ($add_on_pd as $add_on_pd_key => $add_on_pd_value) {
foreach ($add_on_forms as $add_on_forms_key => $add_on_forms_value) {
$fields = array('processed_json');
$where_condition_array = array('isactive' => 1, 'fk_pd_id' => $add_on_pd_value['pd_id'], 'fk_form_id' => $add_on_forms_value);
$data['add_on_pd_forms'][$add_on_pd_value['pd_id']][$add_on_forms_value] = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON, array(), '', 'company_id', 'ASC');
$fields2 = array('*');
$data['add_on_pd_images'][$add_on_pd_value['pd_id']][$add_on_forms_value] = $this->PD_Model->getSignedPDDocsURL($add_on_pd_value['pd_id'], $add_on_forms_value, null, null, null, 'report');
$data['add_on_pd_master_details'][$add_on_pd_value['pd_id']] = $this->PD_Model->getPDMasterDetails($pdid);
}
}
}
$db_result = $this->PD_Model->selectCustomRecords(array('facecrop'), array('fk_pd_id' => $pdid,'isactive'=>1,'facemark_image_generated'=>1), PDAPPLICANTSDETAILS);
$fc_array = array();
if(!empty($db_result)){
for ($dinx = 0; $dinx < count($db_result); $dinx++) {
$string = $db_result[$dinx]['facecrop'];
// echo gettype($string);
$fc_array[$dinx] = json_decode($string, true);
}
}
$data['facecrop'] = $fc_array;
// print_r($db_result);
// print_r($data['facecrop']);
// die();
// print_r($data);die();
$t = "";
if (!count($add_on_pd)) {
if ($data['pd_master_details'][0]['fk_pd_type'] == 1) {
if ($data['pd_master_details'][0]['lender_short_name'] == 'CLIX' || ($data['pd_master_details'][0]['lender_short_name'] == 'MWISE')) // && $data['pd_master_details'][0]['product_abbr'] == 'BL'))
{
$t = $this->load->view('report_templates/JSONTOREPORT_CLIX', $data, true);
} else if ($data['pd_master_details'][0]['customer_segment_abbr'] == 'SE-RI') {
$t = $this->load->view('report_templates/JSONTOREPORT_RI', $data, true);
} else if ($data['pd_master_details'][0]['customer_segment_abbr'] == 'SE-DI' || $data['pd_master_details'][0]['customer_segment_abbr'] == 'SE-AI' || $data['pd_master_details'][0]['customer_segment_abbr'] == 'SEP_INDV') {
$t = $this->load->view('report_templates/JSONTOREPORT_DI_AI', $data, true);
} else if ($data['pd_master_details'][0]['customer_segment_abbr'] == 'SAL') {
$t = $this->load->view('report_templates/JSONTOREPORT_SAL', $data, true);
}
} else if ($data['pd_master_details'][0]['fk_pd_type'] == 2) {
if ($data['pd_master_details'][0]['lender_short_name'] == 'CLIX' || ($data['pd_master_details'][0]['lender_short_name'] == 'MWISE')) // && $data['pd_master_details'][0]['product_abbr'] == 'BL'))
{
$t = $this->load->view('report_templates/JSONTOREPORT_CLIX_SMARTPD', $data, true);
} else if ($data['pd_master_details'][0]['customer_segment_abbr'] == 'SE-RI') {
$t = $this->load->view('report_templates/JSONTOREPORT_RI_SMARTPD', $data, true);
} else if ($data['pd_master_details'][0]['customer_segment_abbr'] == 'SE-DI' || $data['pd_master_details'][0]['customer_segment_abbr'] == 'SE-AI' || $data['pd_master_details'][0]['customer_segment_abbr'] == 'SEP_INDV') {
$t = $this->load->view('report_templates/JSONTOREPORT_DI_AI_SMARTPD', $data, true);
} else if ($data['pd_master_details'][0]['customer_segment_abbr'] == 'SAL') {
$t = $this->load->view('report_templates/JSONTOREPORT_SAL_SMARTPD', $data, true);
}
} else if ($data['pd_master_details'][0]['fk_pd_type'] == 3) //Tele PD
{
if ($data['pd_master_details'][0]['lender_short_name'] == 'CLIX' || ($data['pd_master_details'][0]['lender_short_name'] == 'MWISE')) // && $data['pd_master_details'][0]['product_abbr'] == 'BL'))
{
$t = $this->load->view('report_templates/JSONTOREPORT_CLIX_TELE_PD', $data, true);
} else if ($data['pd_master_details'][0]['customer_segment_abbr'] == 'SAL') {
$t = $this->load->view('report_templates/JSONTOREPORT_SAL_TELE_PD', $data, true);
} else if ($data['pd_master_details'][0]['customer_segment_abbr'] == 'SE-RI') {
$t = $this->load->view('report_templates/JSONTOREPORT_RI_TELE_PD', $data, true);
} else if ($data['pd_master_details'][0]['customer_segment_abbr'] == 'SE-DI' || $data['pd_master_details'][0]['customer_segment_abbr'] == 'SE-AI' || $data['pd_master_details'][0]['customer_segment_abbr'] == 'SEP_INDV') {
$t = $this->load->view('report_templates/JSONTOREPORT_DI_AI_TELE_PD', $data, true);
}
} else if ($data['pd_master_details'][0]['fk_pd_type'] == 4){ //FI PD
if ($data['pd_master_details'][0]['fk_fi_type_id'] == 1 ){
$t = $this->load->view('report_templates/JSONTOREPORT_FI_OV_DI', $data, true);
} else if ($data['pd_master_details'][0]['fk_fi_type_id'] == 2 ){
$t = $this->load->view('report_templates/JSONTOREPORT_FI_OV_SAL', $data, true);
} else if ($data['pd_master_details'][0]['fk_fi_type_id'] == 3 ){
$t = $this->load->view('report_templates/JSONTOREPORT_FI_RV', $data, true);
}
}
} else {
$t = $this->load->view('report_templates/JSONTOREPORT_DI_AI_ADDON', $data, true);
}
//$t = $this->load->view('temp_html.html',null,true);
// echo $data['pd_master_details'][0]['customer_segment_abbr'];
// echo $data['pd_master_details'][0]['fk_pd_type'];
echo $t;
die();
$total_replaces = substr_count($t, '');
for ($i = 0; $i < $total_replaces; $i++) {
$start_pos = strpos($t, '');
$end_pos = strpos($t, '', strpos($t, ''));
$end_pos = $end_pos + 14;
//echo $start_pos.'-';echo $end_pos.'-';echo ($end_pos - $start_pos).'-';
$t = substr_replace($t, '', $start_pos, ($end_pos - $start_pos));
$t = substr_replace($t, '', strpos($t, ''), (strlen('')));
}
//echo $t;die();
//$t = file_get_contents($this->external_path ."/pd_reports/" . $pdid . "/sample.html");
// $start_pos = strpos($t,'');
// $end_pos = $start_pos + 10;
// $t = substr_replace($t,'',$end_pos,0);
// $t = substr_replace($t,'',0,0);
// $t = substr_replace($t,'',-1,0);
//file_put_contents($this->external_path ."/pd_reports/" . $pdid . "/sample2.html",$t);
//PDF Gen using DOM PDF
//$this->pdfgenerator->setEncryption('test1234');
$pdf_doc = $this->pdfgenerator->generate($t, $filename = 'version', $stream = false, $paper = 'A4', $orientation = "portrait");
//End of PDF Gen using DOM PDF
$output_file2 = $this->external_path . "/pd_reports/" . $pdid . "/sample.pdf";
// $output_file2 = $this->external_path . "/pd_reports/sample.pdf";
$ti = file_put_contents($output_file2, $pdf_doc);
echo $output_file2;
echo $ti;
die();
$dat['dataStatus'] = true;
$dat['status'] = REST_Controller::HTTP_OK;
$dat['records'] = $ti;
$this->response($dat, REST_Controller::HTTP_OK);
}
public function notify_get()
{
PDALERTS::pdnotification(2854);
}
public function calculatePDScore($data)
{
$pd_form_raw_data = $data;
$actual_score = 0;
$exact_score = 0;
foreach ($pd_form_raw_data as $raw_key => $raw_data) {
if ($raw_data['category_weightage'] != '' && $raw_data['question_weightage'] != '' && $raw_data['score'] != '' && $raw_data['max_score'] != '') {
$pd_form_raw_data[$raw_key]['actual_score'] = (($raw_data['category_weightage'] / 100) * ($raw_data['question_weightage'] / 100) * $raw_data['max_score']);
$pd_form_raw_data[$raw_key]['exact_score'] = (($raw_data['category_weightage'] / 100) * ($raw_data['question_weightage'] / 100) * $raw_data['score']);
// $actual_score = $actual_score + ($raw_data['category_weightage'] * $raw_data['question_weightage'] * $raw_data['max_score']);
// $exact_score = $exact_score + ($raw_data['category_weightage'] * $raw_data['question_weightage'] * $raw_data['score']);
} else {
$pd_form_raw_data[$raw_key]['actual_score'] = null;
$pd_form_raw_data[$raw_key]['exact_score'] = null;
}
}
return $pd_form_raw_data;
}
public function getQCLenderRemarks_post()
{
$records = $this->post('records');
$pdid = $records['pd_id'];
$fields = array();
if ($records['flag'] == 'QC') {
$fields = array('qc_feedback', 'qc_rating', 'pd_status');
} else if ($records['flag'] == 'LENDER') {
$fields = array('lender_remarks', 'lender_rating', 'pd_status');
} else if ($records['flag'] == 'QC_REMARKS') {
$fields = array('qc_remarks', 'pd_status');
} else if ($records['flag'] == 'OFFICER_REMARKS') {
$fields = array('pd_qc_note');
} else if ($records['flag'] == 'ALL_REMARKS') // Get All Other remarks from pd remarks table
{
$this->db->SELECT('PDREMARKS.remark,DATE_FORMAT(PDREMARKS.createdon,"%d/%m/%Y %r") as log_time,concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as createdby')->FROM(PDREMARKS . ' as PDREMARKS');
$this->db->JOIN(USERPROFILE . ' as USERPROFILE', 'USERPROFILE.userid = PDREMARKS.createdby', 'LEFT');
$this->db->WHERE('PDREMARKS.fk_pd_id', $pdid);
$res = $this->db->GET()->result_array();
if (count($res)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $res;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'No Remarks Available for this PD!';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'InAppropriate Params!';
$this->response($data, REST_Controller::HTTP_OK);
}
$where_condition_array = array('pd_id' => $pdid);
$result = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDTRIGGER);
if (count($result)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'No Remarks Available for this PD!';
$this->response($data, REST_Controller::HTTP_OK);
}
}
##v1
public function getCompaniesListsFromGeneralFormRawJSON_post()
{
$records = $this->post('records');
$pd_id = $records['pd_id'];
$ai_flag = 0;
//GET TEMPALE ID FROM MASTER
$pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id);
$lender_short_name = $pd_master_details[0]['lender_short_name'];
$product_abbr = $pd_master_details[0]['product_abbr'];
//print_r($lender_short_name);
$str = substr($pd_master_details[0]['customer_segment_abbr'], -2);
//echo $str;
if (!strcmp($str, 'AI')) {
$ai_flag = 1;
}
//echo $ai_flag;
$company_list = array();
$fields = array('json');
$where_condition_array = array('isactive' => 1, 'fk_form_id' => 18, 'fk_pd_id' => $pd_id);
$rec = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
if (count($rec)) {
$temp_data = json_decode($rec[0]['json'], true);
// print_r($temp_data);die();
foreach ($temp_data['companies'] as $company) {
if ($company['associate_pd_id'] == $pd_id) {
$temp_array = array('company_order_id' => $company['company_order_id'], 'company_name' => $company['company_name'], 'is_active' => $company['is_active'], 'is_company_applicant' => $company['is_company_applicant'], 'business_entity_type' => $company['business_entity_type'], 'business_years' => $company['business_years'], 'business_month' => $company['business_month'], 'business_month' => $company['business_month'], 'business_date_object' => $company['business_date_object']);
if (isset($company['business_entity_type_other'])) {
$temp_array['business_entity_type_other'] = $company['business_entity_type_other'];
}
$company_list[] = $temp_array;
}
}
// $company_list = array( array('company_order_id' => 1));
//print_r($company_list);die();
$form_array = array();
if ($ai_flag == 0) // DI case
{
$form_array[] = array('form_id' => 13, 'form_name' => 'About Business');
$form_array[] = array('form_id' => 22, 'form_name' => 'Business Assets');
if (!strcasecmp($lender_short_name, 'CLIX')) {
$form_array[] = array('form_id' => 21, 'form_name' => 'Business Banking');
}
$form_array[] = array('form_id' => 14, 'form_name' => 'Financial Information');
$form_array[] = array('form_id' => 1, 'form_name' => 'Supplier Details');
$form_array[] = array('form_id' => 2, 'form_name' => 'Client Details');
$form_array[] = array('form_id' => 11, 'form_name' => 'Stock Details');
if (!strcasecmp($lender_short_name, 'CLIX') || (!strcasecmp($lender_short_name, 'MWISE'))) {
$form_array[] = array('form_id' => 23, 'form_name' => 'Future Plans & Business Environments');
}
} else // AI Case
{
$form_array[] = array('form_id' => 13, 'form_name' => 'About Business');
$form_array[] = array('form_id' => 22, 'form_name' => 'Business Assets');
if (!strcasecmp($lender_short_name, 'CLIX')) {
$form_array[] = array('form_id' => 21, 'form_name' => 'Business Banking');
}
$form_array[] = array('form_id' => 14, 'form_name' => 'Financial Information');
$form_array[] = array('form_id' => 1, 'form_name' => 'Supplier Details');
$form_array[] = array('form_id' => 2, 'form_name' => 'Client Details');
$form_array[] = array('form_id' => 11, 'form_name' => 'Stock Details');
$form_array[] = array('form_id' => 16, 'form_name' => 'Assessed Income');
if (!strcasecmp($lender_short_name, 'CLIX') || (!strcasecmp($lender_short_name, 'MWISE'))) // && !strcasecmp($product_abbr,'LFMP'))
{
$form_array[] = array('form_id' => 23, 'form_name' => 'Future Plans & Business Environments');
}
}
//print_r($form_array);//die();
foreach ($company_list as $list_key => $company) {
$temp = array();
$business_form_status = 0;
$supplier_form_status = 0;
$client_form_status = 0;
foreach ($form_array as $form) {
$template_forms_count = 0;
if ($form['form_id'] != 16) {
$this->db->SELECT('count(*) as count');
$this->db->FROM(PDFORMDETAILSJSON . ' as PDFORMDETAILSJSON');
$this->db->WHERE('PDFORMDETAILSJSON.fk_pd_id', $pd_id);
$this->db->WHERE('PDFORMDETAILSJSON.fk_form_id', $form['form_id']);
$this->db->WHERE('PDFORMDETAILSJSON.company_id', $company['company_order_id']);
$this->db->WHERE('PDFORMDETAILSJSON.isactive', 1);
$template_forms_count = $this->db->GET()->result_array();
//print_r($this->db->last_query());die();
} else {
$fields = array('count(*) as count');
$where_condition_array = array('fk_pd_id' => $pd_id, 'company_id' => $company['company_order_id'], 'is_completed' => 1);
$template_forms_count = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDASSESSEDINCOMEESTIMATIONOFGROSSPROFITTYPE);
}
// print_r($this->db->last_query());
// print_r($template_forms_count);echo $form['form_id'];
if ($template_forms_count[0]['count'] != 0) {
if ($form['form_id'] == 13 || $form['form_id'] == 22 || $form['form_id'] == 23) {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => true, 'isAnswerable' => true);
if ($form['form_id'] == 22) {
$business_form_status = 1;
}
} else {
if ($business_form_status == 1) {
if ($form['form_id'] == 1) //if supplier form answered set supplier_form_status = 1
{
$supplier_form_status = 1;
}
if ($form['form_id'] == 2) //if client form answered set client_form_status = 1
{
$client_form_status = 1;
}
if ($form['form_id'] == 11 || $form['form_id'] == 22 || $form['form_id'] == 23) {
//echo "COUNT YES STOCK"
if ($client_form_status == 1 && $supplier_form_status == 1) {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => true, 'isAnswerable' => true);
}
} else {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => true, 'isAnswerable' => true);
}
} else //busienss false
{
//echo "business false".$form['form_id'];
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => true, 'isAnswerable' => false);
}
}
} else //Not previously answered
{
//echo "else-- " .$form['form_id'];
if ($form['form_id'] == 13 || $form['form_id'] == 22 || $form['form_id'] == 23) {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => false, 'isAnswerable' => true);
} else {
if ($business_form_status == 1) {
if ($form['form_id'] == 11 || $form['form_id'] == 22 || $form['form_id'] == 23) {
//echo "BUSISTOCk";
if ($client_form_status == 1 && $supplier_form_status == 1) {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => false, 'isAnswerable' => true);
} else {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => false, 'isAnswerable' => false);
}
} else {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => false, 'isAnswerable' => true);
}
} else {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => false, 'isAnswerable' => false);
}
}
}
}
$company_list[$list_key]['form_status'] = $temp;
}
}
// print_r($company_list);die();
if (count($company_list)) {
if ($pd_master_details[0]['fk_pd_type'] == 2) {
$vendor_form_status = $this->PD_Model->getVendorFormStatus($pd_id);
$company_list[0]['vendor_form_status'] = $vendor_form_status;
}
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $company_list;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'No Comapany Details Found!';
$this->response($data, REST_Controller::HTTP_OK);
}
}
### V2
public function getCompaniesListsFromGeneralFormRawJSONV2_post()
{
$records = $this->post('records');
$pd_id = $records['pd_id'];
$ai_flag = 0;
//GET TEMPALE ID FROM MASTER
$pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id);
$lender_short_name = $pd_master_details[0]['lender_short_name'];
$product_abbr = $pd_master_details[0]['product_abbr'];
//print_r($lender_short_name);
$str = substr($pd_master_details[0]['customer_segment_abbr'], -2);
//echo $str;
if (!strcmp($str, 'AI')) {
$ai_flag = 1;
}
//echo $ai_flag;
$map_fields = array('id');
$map_where_condition_array = array('entity_id' => $pd_master_details[0]['fk_lender_id'], 'product_id' => $pd_master_details[0]['fk_product_id'], 'customer_segment_id' => $pd_master_details[0]['fk_customer_segment'], 'isactive' => 1);
$map_table = $this->PD_Model->selectCustomRecords($map_fields, $map_where_condition_array, TEMPLATE_MAP_V2);
if (count($map_table) > 0) {
$map_pk_id = (int)$map_table[0]['id'];
} else {
$map_pk_id = null;
}
$company_list = array();
$fields = array('json');
$where_condition_array = array('isactive' => 1, 'fk_form_id' => 18, 'fk_pd_id' => $pd_id);
$rec = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
if (count($rec)) {
$temp_data = json_decode($rec[0]['json'], true);
// print_r($temp_data);die();
foreach ($temp_data['companies'] as $company) {
if ($company['associate_pd_id'] == $pd_id) {
$temp_array = array('company_order_id' => $company['company_order_id'], 'company_name' => $company['company_name'], 'is_active' => $company['is_active'], 'is_company_applicant' => $company['is_company_applicant'], 'business_entity_type' => $company['business_entity_type'], 'business_years' => $company['business_years'], 'business_month' => $company['business_month'], 'business_month' => $company['business_month'], 'business_date_object' => $company['business_date_object']);
if (isset($company['business_entity_type_other'])) {
$temp_array['business_entity_type_other'] = $company['business_entity_type_other'];
}
$company_list[] = $temp_array;
}
}
// $company_list = array( array('company_order_id' => 1));
//print_r($company_list);die();
$form_array = array();
if ($ai_flag == 0) // DI case
{
$form_array[] = array('form_id' => 13, 'form_name' => 'About Business', 'map_id' => $map_pk_id);
$form_array[] = array('form_id' => 22, 'form_name' => 'Business Assets', 'map_id' => $map_pk_id);
if (!strcasecmp($lender_short_name, 'CLIX')) {
$form_array[] = array('form_id' => 21, 'form_name' => 'Business Banking', 'map_id' => $map_pk_id); // this is temporary have to Remove ( step 2 )
}
$form_array[] = array('form_id' => 14, 'form_name' => 'Financial Information', 'map_id' => $map_pk_id);
$form_array[] = array('form_id' => 1, 'form_name' => 'Supplier Details', 'map_id' => $map_pk_id);
$form_array[] = array('form_id' => 2, 'form_name' => 'Client Details', 'map_id' => $map_pk_id);
$form_array[] = array('form_id' => 11, 'form_name' => 'Stock Details', 'map_id' => $map_pk_id);
if (!strcasecmp($lender_short_name, 'CLIX') || (!strcasecmp($lender_short_name, 'MWISE'))) {
$form_array[] = array('form_id' => 23, 'form_name' => 'Future Plans & Business Environments', 'map_id' => $map_pk_id);
}
} else // AI Case
{
$form_array[] = array('form_id' => 13, 'form_name' => 'About Business', 'map_id' => $map_pk_id);
$form_array[] = array('form_id' => 22, 'form_name' => 'Business Assets', 'map_id' => $map_pk_id);
if (!strcasecmp($lender_short_name, 'CLIX')) {
$form_array[] = array('form_id' => 21, 'form_name' => 'Business Banking', 'map_id' => $map_pk_id); //Removed ( step 2 )
}
$form_array[] = array('form_id' => 14, 'form_name' => 'Financial Information', 'map_id' => $map_pk_id);
$form_array[] = array('form_id' => 1, 'form_name' => 'Supplier Details', 'map_id' => $map_pk_id);
$form_array[] = array('form_id' => 2, 'form_name' => 'Client Details', 'map_id' => $map_pk_id);
$form_array[] = array('form_id' => 11, 'form_name' => 'Stock Details', 'map_id' => $map_pk_id);
$form_array[] = array('form_id' => 16, 'form_name' => 'Assessed Income', 'map_id' => $map_pk_id);
if (!strcasecmp($lender_short_name, 'CLIX') || (!strcasecmp($lender_short_name, 'MWISE'))) // && !strcasecmp($product_abbr,'LFMP'))
{
$form_array[] = array('form_id' => 23, 'form_name' => 'Future Plans & Business Environments', 'map_id' => $map_pk_id);
}
}
//print_r($form_array);//die();
foreach ($company_list as $list_key => $company) {
$temp = array();
$business_form_status = 0;
$supplier_form_status = 0;
$client_form_status = 0;
foreach ($form_array as $form) {
$template_forms_count = 0;
if ($form['form_id'] != 16) {
$this->db->SELECT('count(*) as count');
$this->db->FROM(PDFORMDETAILSJSON . ' as PDFORMDETAILSJSON');
$this->db->WHERE('PDFORMDETAILSJSON.fk_pd_id', $pd_id);
$this->db->WHERE('PDFORMDETAILSJSON.fk_form_id', $form['form_id']);
$this->db->WHERE('PDFORMDETAILSJSON.company_id', $company['company_order_id']);
$this->db->WHERE('PDFORMDETAILSJSON.isactive', 1);
$template_forms_count = $this->db->GET()->result_array();
//print_r($this->db->last_query());die();
} else {
$fields = array('count(*) as count');
$where_condition_array = array('fk_pd_id' => $pd_id, 'company_id' => $company['company_order_id'], 'is_completed' => 1);
$template_forms_count = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDASSESSEDINCOMEESTIMATIONOFGROSSPROFITTYPE);
}
// print_r($this->db->last_query());
// print_r($template_forms_count);echo $form['form_id'];
if ($template_forms_count[0]['count'] != 0) {
if ($form['form_id'] == 13 || $form['form_id'] == 22 || $form['form_id'] == 23) {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => true, 'isAnswerable' => true);
if ($form['form_id'] == 22) {
$business_form_status = 1;
}
} else {
if ($business_form_status == 1) {
if ($form['form_id'] == 1) //if supplier form answered set supplier_form_status = 1
{
$supplier_form_status = 1;
}
if ($form['form_id'] == 2) //if client form answered set client_form_status = 1
{
$client_form_status = 1;
}
if ($form['form_id'] == 11 || $form['form_id'] == 22 || $form['form_id'] == 23) {
//echo "COUNT YES STOCK"
if ($client_form_status == 1 && $supplier_form_status == 1) {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => true, 'isAnswerable' => true, 'map_id' => $form['map_id']);
}
} else {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => true, 'isAnswerable' => true, 'map_id' => $form['map_id']);
}
} else //busienss false
{
//echo "business false".$form['form_id'];
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => true, 'isAnswerable' => false, 'map_id' => $form['map_id']);
}
}
} else //Not previously answered
{
//echo "else-- " .$form['form_id'];
if ($form['form_id'] == 13 || $form['form_id'] == 22 || $form['form_id'] == 23) {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => false, 'isAnswerable' => true, 'map_id' => $form['map_id']);
} else {
if ($business_form_status == 1) {
if ($form['form_id'] == 11 || $form['form_id'] == 22 || $form['form_id'] == 23) {
//echo "BUSISTOCk";
if ($client_form_status == 1 && $supplier_form_status == 1) {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => false, 'isAnswerable' => true, 'map_id' => $form['map_id']);
} else {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => false, 'isAnswerable' => false, 'map_id' => $form['map_id']);
}
} else {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => false, 'isAnswerable' => true, 'map_id' => $form['map_id']);
}
} else {
$temp[] = array('form_id' => $form['form_id'], 'form_name' => $form['form_name'], 'isAnswered' => false, 'isAnswerable' => false, 'map_id' => $form['map_id']);
}
}
}
}
$company_list[$list_key]['form_status'] = $temp;
}
}
// print_r($company_list);die();
if (count($company_list)) {
if ($pd_master_details[0]['fk_pd_type'] == 2) {
$vendor_form_status = $this->PD_Model->getVendorFormStatus($pd_id);
$company_list[0]['vendor_form_status'] = $vendor_form_status;
}
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $company_list;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'No Comapany Details Found!';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function getPDAddress_post()
{
$pdid = $this->post('pd_id');
$address = $this->PD_Model->getPDAddress($pdid);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $address;
$this->response($data, REST_Controller::HTTP_OK);
}
public function getEndUseOfLoan_post()
{
$records = $this->post('records');
$pdid = $records['pd_id'];
$sub_product_id = null;
if (isset($records['sub_product_id'])) {
$sub_product_id = $records['sub_product_id'];
}
if ($sub_product_id != null) {
$fields = array('*');
$where_condition_array = array('isactive' => 1, 'fk_subproduct_id' => $sub_product_id);
$result_data = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, ENDUSEOFLOAN);
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;
$data['msg'] = 'No Data Found for Selected Sub Product!';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$pd_master_details = $this->PD_Model->getPDMasterDetails($pdid);
if ($pd_master_details[0]['fk_subproduct_id'] != "" || $pd_master_details[0]['fk_subproduct_id'] != null) {
$fields = array('*');
$where_condition_array = array('isactive' => 1, 'fk_subproduct_id' => $pd_master_details[0]['fk_subproduct_id']);
$result_data = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, ENDUSEOFLOAN);
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;
$data['msg'] = 'No Data Found for Selected Sub Product!';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$fields = array('*');
$where_condition_array = array('isactive' => 1, 'fk_subproduct_id' => null);
$result_data = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, ENDUSEOFLOAN);
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['records'] = $result_data;
$data['msg'] = 'Sub Product Not Applicable for this PD!';
$this->response($data, REST_Controller::HTTP_OK);
}
}
}
public function savePDOfficerCurrentLocation_post()
{
$pdid = $this->post('pd_id');
$current_location = $this->post('link');
$record_data = array('fk_pd_id' => $pdid, 'current_location' => $current_location);
$id = $this->PD_Model->saveRecords($record_data, PDOFFICERCURRENTLOCATION);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['record'] = $id;
$this->response($data, REST_Controller::HTTP_OK);
}
public function getPDOfficerCurrentLocation_post()
{
$enc_string = $this->post('pd_id');
$pdid = $this->db->SELECT('pd_id')->FROM(PDTRIGGER)->WHERE('random_string', $enc_string)->ORDER_BY(PDTRIGGERID, 'DESC')->LIMIT(1)->GET()->result_array();
//print_r($this->db->last_query());
//print_r($pdid);
$pd_master_details = $this->PD_Model->getPDMasterDetails($pdid[0]['pd_id']);
$offcier_name = $pd_master_details[0]['pd_allocated_to'];
$result_data['officer_details']['officer_name'] = $offcier_name;
$result_data['location'] = $this->db->SELECT('*')->FROM(PDOFFICERCURRENTLOCATION)->WHERE('fk_pd_id', $pdid[0]['pd_id'])->ORDER_BY(PDOFFICERCURRENTLOCATIONID, 'DESC')->LIMIT(1)->GET()->result_array();
if (count($result_data)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['record'] = $result_data;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'No Records Found!';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function getFamilyDetailsFromBusinessAndGeneral_post()
{
$pdid = $this->post('pd_id');
//echo $pdid;
//Get Details From General Full
$fields = array('json');
$where_condition_array = array('isactive' => 1, 'fk_form_id' => 18, 'fk_pd_id' => $pdid);
$general_data = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
//print_r($general_data);die();
$temp_array = array();
if (count($general_data)) {
$json = json_decode($general_data[0]['json'], true);
//print_r($json);die();
if (array_key_exists('persons_with_relationships', $json)) {
foreach ($json['persons_with_relationships'] as $key => $relation) {
foreach ($json['individuals'] as $ind) {
if ($relation['applicant_name'] == $ind['applicant_name']) {
$relation['age'] = $ind['age'];
$relation['applicant_title_name'] = $ind['applicant_title_name'];
}
}
$temp_array = array_merge($temp_array, array($relation));
}
}
}
$final_data['from_general_form'] = $temp_array;
//Get Details from All Business Froms
$fields = array('json', 'company_id');
$where_condition_array = array('isactive' => 1, 'fk_form_id' => 13, 'fk_pd_id' => $pdid);
$business_data = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
//print_r($business_data);
if (count($business_data)) {
$temp_array = array();
foreach ($business_data as $business_data_key => $business) {
$json = json_decode($business['json'], true);
//print_r($json);
if (array_key_exists('persons_with_relationships', $json)) {
foreach ($json['persons_with_relationships'] as $person => $value) {
if (count($general_data)) {
$genjson = json_decode($general_data[0]['json'], true);
foreach ($genjson['companies'] as $company_key => $company) {
//print_r($compan);
if ($value['relationship_with_company_id'] == $company['company_order_id']) {
$json['persons_with_relationships'][$person]['company_name'] = $company['company_name'];
$json['persons_with_relationships'][$person]['business_years'] = $company['business_years'];
$json['persons_with_relationships'][$person]['business_month'] = $company['business_month'];
$json['persons_with_relationships'][$person]['business_date_formation'] = $company['business_date_object'];
}
}
}
}
$temp_array = array_merge($temp_array, $json['persons_with_relationships']);
}
}
}
$final_data['from_business_form'] = $temp_array;
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['record'] = $final_data;
$this->response($data, REST_Controller::HTTP_OK);
}
public function getAssetsWithLoanFromBusiness_post()
{
$pdid = $this->post('pd_id');
// GET Assest Types and Properties type from Master
$fields = array('*');
$where_condition_array = array('isactive' => 1);
$assest_types = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, ASSETTYPE);
$fields = array('*');
$where_condition_array = array('isactive' => 1);
$property_types = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PROPERTIES);
$fields = array('json', 'company_id');
$where_condition_array = array('isactive' => 1, 'fk_form_id' => 22, 'fk_pd_id' => $pdid);
$assest_data = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
$business_assest_data = array();
$other_assest_data = array();
$business_address_assest_data = array();
//print_r($assest_data);die();
if (count($assest_data)) {
//print_r($property_types);die();
foreach ($assest_data as $key => $assest) {
$json = json_decode($assest['json'], true);
//print_r($json);die();
if (array_key_exists('business_assets_details', $json)) {
foreach ($json['business_assets_details'] as $asset_key => $business_asset) {
//print_r($business_asset);
if (!strcmp($business_asset['business_emi'], 'yes')) {
$business_assets_mode_name = "";
foreach ($assest_types as $asset_type) {
if ($asset_type['id'] == $business_asset['business_assets_mode']) {
$business_assets_mode_name = $asset_type['name'];
}
}
if ($business_asset['business_assets_mode'] == 2) {
//echo $business_asset['business_details'][0]['property_type'];
foreach ($property_types as $property_type) {
if ($property_type['id'] == $business_asset['business_details'][0]['property_type']) {
$business_asset['business_details'][0]['property_type_name'] = $property_type['name'];
}
}
}
$business_assest_data[] = array('business_assets_mode' => $business_asset['business_assets_mode'], 'business_assets_mode_name' => $business_assets_mode_name, 'business_details' => $business_asset['business_details'], 'business_name_of_the_owner' => $business_asset['business_name_of_the_owner'], 'business_name_of_the_other_owner' => $business_asset['business_name_of_the_other_owner']);
}
}
}
if (array_key_exists('business_assets_for_address', $json)) {
foreach ($json['business_assets_for_address'] as $address_key => $address_asset) {
if (!strcasecmp($address_asset['business_emi'], 'yes')) {
//echo $address_asset['address_label'];
$business_address_assest_data[] = $address_asset;
}
}
}
}
}
//Get Other Assets with Loan
$fields = array('json');
$where_condition_array = array('isactive' => 1, 'fk_form_id' => 4, 'fk_pd_id' => $pdid);
$other_assest = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
// print_r($this->db->last_query());
// print_r($other_assest);die();
if (count($other_assest)) {
foreach ($other_assest as $key => $assest) {
$json = json_decode($assest['json'], true);
//print_r($json);die();
if (array_key_exists('assets_details', $json)) {
foreach ($json['assets_details'] as $asset_key => $asset) {
if (!strcmp($asset['emi'], 'yes')) {
$assets_mode_name = "";
foreach ($assest_types as $asset_type) {
if ($asset_type['id'] == $asset['assets_mode']) {
$assets_mode_name = $asset_type['name'];
}
}
if ($asset['assets_mode'] == 2) {
//echo $business_asset['business_details'][0]['property_type'];
foreach ($property_types as $property_type) {
if ($property_type['id'] == $asset['details'][0]['property_type']) {
$asset['details'][0]['property_type_name'] = $property_type['name'];
}
}
}
$other_assest_data[] = array('assets_mode' => $asset['assets_mode'], 'assets_mode_name' => $assets_mode_name, 'details' => $asset['details'], 'name_of_the_owner' => $asset['name_of_the_owner'], 'other_owner' => $asset['other_owner']);
}
}
}
}
}
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['record'] = array('business_assets' => $business_assest_data, 'other_assests' => $other_assest_data, 'business_address_asset' => $business_address_assest_data);
$this->response($data, REST_Controller::HTTP_OK);
}
public function getProductsWithTypeofActivityFromBusiness_post()
{
$pdid = $this->post('pd_id');
$company_id = $this->post('company_id');
//echo $pdid.$company_id;die();
//Get Details From General Full
$fields = array('json');
$where_condition_array = array('isactive' => 1, 'fk_form_id' => 13, 'fk_pd_id' => $pdid, 'company_id' => $company_id);
$business_data = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
$final_data_from_business = array();
//print_r($business_data);
if (count($business_data)) {
$json = json_decode($business_data[0]['json'], true);
//print_r($json);
if (array_key_exists('manufacturing_activity_details', $json)) {
$temp_data['type_of_activity_id'] = 2;
$temp_data['name'] = 'Manufacturing';
foreach ($json['manufacturing_activity_details'] as $key => $manufacturing_activity_details) {
$temp_data['products'][] = $manufacturing_activity_details['main_products'];
}
$final_data_from_business[] = $temp_data;
$temp_data = array();
}
if (array_key_exists('retail_trading_activity_details', $json)) {
$temp_data['type_of_activity_id'] = 3;
$temp_data['name'] = 'Retail trading';
foreach ($json['retail_trading_activity_details'] as $key => $retail_trading_activity_details) {
$temp_data['products'][] = $retail_trading_activity_details['main_products'];
}
$final_data_from_business[] = $temp_data;
$temp_data = array();
}
if (array_key_exists('wholesale_trading_activity_details', $json)) {
$temp_data['type_of_activity_id'] = 4;
$temp_data['name'] = 'Wholesale Trade';
foreach ($json['wholesale_trading_activity_details'] as $key => $wholesale_trading_activity_details) {
$temp_data['products'][] = $wholesale_trading_activity_details['main_products'];
}
$final_data_from_business[] = $temp_data;
$temp_data = array();
}
if (array_key_exists('service_provider_activity_details', $json)) {
$temp_data['type_of_activity_id'] = 5;
$temp_data['name'] = 'Service Provider';
foreach ($json['service_provider_activity_details'] as $key => $service_provider_activity_details) {
$temp_data['products'][] = $service_provider_activity_details['main_products'];
}
$final_data_from_business[] = $temp_data;
$temp_data = array();
}
}
//GET RAW MATERIALS FROM SUPPLIER Form
$fields = array('json');
$where_condition_array = array('isactive' => 1, 'fk_form_id' => 1, 'fk_pd_id' => $pdid, 'company_id' => $company_id);
$supplier_data = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
$final_data_from_supplier = array();
//print_r($supplier_data);
if (count($supplier_data)) {
$supplier_data = json_decode($supplier_data[0]['json'], true);
//print_r($supplier_data);
if (array_key_exists('manufacturing_details', $supplier_data)) {
foreach ($supplier_data['manufacturing_details'] as $manufacturing_activity_detail_key => $manufacturing_activity_detail) {
$temp_data = $manufacturing_activity_detail['main_raw_materials'];
//print_r($temp_data);die();
// print_r(count($temp_data));
// print_r($temp_data[0]);
// print_r($temp_data[1]);
if ($temp_data != "" || $temp_data != null) {
foreach ($temp_data as $raw_material) {
//print_r($raw_material);
$final_data_from_supplier['raw_material'][] = $raw_material['manufacturing_raw_material_name'];
}
}
}
}
if (array_key_exists('trade_details', $supplier_data)) {
foreach ($supplier_data['trade_details'] as $trade_detail_key => $trade_detail) {
$temp_data = $trade_detail['trading_products'];
//print_r($temp_data);die();
// print_r(count($temp_data));
// print_r($temp_data[0]);
// print_r($temp_data[1]);
if ($temp_data != "" || $temp_data != null) {
foreach ($temp_data as $trade) {
//print_r($raw_material);
$final_data_from_supplier['trading_product'][] = $trade['trade_product_name'];
}
}
}
}
}
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['record'] = array('from_business' => $final_data_from_business, 'from_supplier' => $final_data_from_supplier);
$this->response($data, REST_Controller::HTTP_OK);
}
//Get All Persons Name Invloved In a PD, includes Applicants,Invloved in Business
public function getAllPersonsName_post()
{
$pdid = $this->post('pd_id');
//echo $pdid;
//Get Details From General Form
$final_names = array();
$fields = array('json');
$where_condition_array = array('isactive' => 1, 'fk_form_id' => 18, 'fk_pd_id' => $pdid);
$general_data = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
//print_r($general_data);die();
if (count($general_data)) {
$json = json_decode($general_data[0]['json'], true);
//print_r($json);
if (array_key_exists('individuals', $json)) {
foreach ($json['individuals'] as $key => $persons) {
// if($persons['is_applicant'] == true || $persons['is_person_met'] == true)
// {
// $type = 1;
// }
$final_names[] = array('applicant_name' => $persons['applicant_name'], 'applicant_type' => 1, 'applicant_id' => $persons['pd_co_applicant_id']);
}
}
if (array_key_exists('companies', $json)) {
foreach ($json['companies'] as $key => $persons) {
// if($persons['is_applicant'] == true || $persons['is_person_met'] == true)
// {
// $type = 1;
// }
$final_names[] = array('applicant_name' => $persons['company_name'], 'applicant_type' => 2, 'applicant_id' => $persons['company_name']);
}
}
}
//print_r($final_names);die();
//Get Details from All Business Froms
$fields = array('json', 'company_id');
$where_condition_array = array('isactive' => 1, 'fk_form_id' => 13, 'fk_pd_id' => $pdid);
$business_data = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
//print_r($business_data);die();
if (count($business_data)) {
foreach ($business_data as $business_data_key => $business) {
$json = json_decode($business['json'], true);
//print_r($json);
if (array_key_exists('persons_with_relationships', $json)) {
foreach ($json['persons_with_relationships'] as $key => $persons) {
$final_names[] = array('applicant_name' => $persons['family_member_name'], 'applicant_type' => 3, 'applicant_id' => $persons['family_member_name']);
}
}
}
}
//Get Memebers from Other Family Members form
$fields = array('json', 'company_id');
$where_condition_array = array('isactive' => 1, 'fk_form_id' => 6, 'fk_pd_id' => $pdid);
$family_data = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDFORMDETAILSJSON);
if (count($family_data)) {
$family_data = json_decode($family_data[0]['json'], true);
// echo "familty";
// print_r($family_data);die();
foreach ($family_data as $family_data_key => $family) {
if (is_array($family)) {
if (array_key_exists('family_members_details', $family)) {
foreach ($family['family_members_details'] as $key => $persons) {
$final_names[] = array('applicant_name' => $persons['applicant_name'], 'applicant_type' => 3, 'applicant_id' => $persons['applicant_name']);
}
}
}
}
}
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['record'] = $final_names;
$this->response($data, REST_Controller::HTTP_OK);
}
// Get List of Cities from PD TriggeredTabel to Frond End Filter.
public function getListOfCities_get()
{
$this->db->DISTINCT();
$this->db->SELECT('CITY.city_id,CITY.name');
$this->db->FROM(PDTRIGGER . ' as PDTRIGGER');
$this->db->JOIN(CITY . ' as CITY', 'PDTRIGGER.fk_city = CITY.city_id');
$city = $this->db->GET()->result_array();
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $city;
$this->response($data, REST_Controller::HTTP_OK);
}
public function savePDPhotos_post()
{
$records = $this->post('records');
$company_id = isset($records['company_id']) && $records['company_id'] ? $records['company_id'] : null;
$rental_count_id = isset($records['rental_count_id']) && $records['rental_count_id'] ? $records['rental_count_id'] : null;
$content_type = isset($records['content_type']) && $records['content_type'] ? $records['content_type'] : 1;
//$location = isset($records['link']) ? $records['link'] : null;
//echo $rental_count_id;die();
if (isset($records['images'][0]['pd_document_id']) && $records['images'][0]['pd_document_id'] != null && $records['images'][0]['pd_document_id'] != "") {
$where_condition_array = array('pd_document_id' => $records['images'][0]['pd_document_id']);
$to_update = array("pd_image_alias_name" => $records['images'][0]['pd_image_alias_name']);
$res['count'] = $this->PD_Model->updateRecords($to_update, PDDOCUMENTS, $where_condition_array);
$res['msg'] = "Updated";
$data['uri'] = null;
} else if (isset($records['images'][0]['image'])) {
$res = $this->saveBase64Images($records['pd_id'], $records['formid'], $company_id, $rental_count_id, $records['images']);
}
//print_r($res);
if (count($res)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $res['count'];
$data['uri'] = $res['records'];
$data['msg'] = $res['msg'];
$this->response($data, REST_Controller::HTTP_OK, true);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'Something Went Wrong!';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function getPDImages_post()
{
$records = $this->post('records');
$result_data = $this->PD_Model->getSignedPDDocsURL($records['pd_id'], isset($records['form_id']) ? $records['form_id'] : null, isset($records['company_id']) ? $records['company_id'] : null, isset($records['is_common']) ? $records['is_common'] : null, isset($records['rental_count_id']) ? $records['rental_count_id'] : null);
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'] = true;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$data['msg'] = 'No Data Available';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function saveBase64Images($pd_id, $form_id = null, $company_id = null, $rental_count_id = null, $data)
{
log_message('ERROR', '###PDIMAGE saveBase64Images function called' . $pd_id . ' - ' . $form_id);
$count = 0;
$result = array();
$pks = array();
$uri = null;
$pd_details = $this->PD_Model->getPDMasterDetails($pd_id);
//print_r($data);die();
EXTERNAL_DIR_CHECK::checkExternalDirectory($pd_id);
foreach ($data as $iter => $doc) {
//make location for water mark helper function
$this->location_for_watermark = $doc['link'];
$temp_base64_string = $doc['image'];
$title = $doc['Name'];
$is_show_report = isset($doc['is_show_report']) ? $doc['is_show_report'] : null;
if ($pd_details[0]['fk_pd_type'] == 2 && strpos($title, 'Approach to PD Location') !== false) {
$is_show_report = 1;
}
//$external_path = $this->config->item('external_data_path');
//echo $title.'-'.$is_show_report;die();
$co_applicant_id = isset($doc['co_applicant_id']) ? $doc['co_applicant_id'] : null;
$img_type = isset($doc['img_type']) ? $doc['img_type'] : null;
$output_file = $this->external_path . "/pd_reports/" . $pd_id . "/temp_base64_image.jpeg";
$this->temp_path_for_watermark = $output_file;
//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-i-s') . '.jpeg';
log_message('ERROR', '###PDIMAGE writing started' . $pd_id . ' - ' . $form_id);
$ifp = fopen($output_file, 'wb');
$temp_data = explode(',', $temp_base64_string);
fwrite($ifp, base64_decode($temp_data[1]));
fclose($ifp);
log_message('ERROR', '###PDIMAGE writing done' . $pd_id . ' - ' . $form_id);
// // ################### start img water marking with text
// $imagetobewatermark = imagecreatefromstring(file_get_contents($output_file));
// $location_watermarktext="Location: ".$doc['link'];
// $font = APPPATH."docs/robold.ttf"; //metion font and it's location
// $fontsize="12";
// $x = imagesx($imagetobewatermark);
// $y = imagesy($imagetobewatermark);
// $water_mark_text_color = imagecolorallocate($imagetobewatermark, 225, 0, 0);
// imagettftext($imagetobewatermark, $fontsize, 0, 120, ($y - 30), $water_mark_text_color, $font, $location_watermarktext);
// imagettftext($imagetobewatermark, $fontsize, 0, 120, ($y - 10), $water_mark_text_color, $font, 'Date: '.date('Y-m-d h:i:s a'));
// imagejpeg($imagetobewatermark,$output_file,100);//save as png file in ouputfile location
// //################# end img water marking with text
// //###########image water marking with logo
// $pd_logo = imagecreatefromstring(file_get_contents(APPPATH.'docs/icon.png'));
// $curret_file = imagecreatefromstring(file_get_contents($output_file));
// $sx = imagesx($curret_file);
// $sy = imagesy($curret_file);
// // imagecopyresized ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h ) : bool
// imagecopyresampled ( $curret_file , $pd_logo ,5, ($sy - 54) , 0 , 0 , 50 , 50 , 50 , 54 );
// imagejpeg($curret_file,$output_file,100);// save png image in specified location
// //###########end of image water marking with logo
log_message('ERROR', '###PDIMAGE uploading to S3' . $pd_id . ' - ' . $form_id);
$tempdoc = $output_file;
$tempdocname = $temp_file_name;
$bucketname = LENDER_BUCKET_NAME_PREFIX . $pd_details[0]['fk_lender_id'];
$key = 'pd' . $pd_id . '/' . $tempdocname;
// if($form_id != null)
// {
// $key = 'pd'.$pd_id.'/'.'form'.$form_id.'/'.$tempdocname;
// }
$sourcefile = $tempdoc;
$bucket_data = array('bucket_name' => $bucketname, 'key' => $key, 'sourcefile' => $sourcefile);
//this line make this bucket data values in obj level so can access in helpers and hook files
$this->bucket_data_for_watermark = $bucket_data;
$s3result = $this->aws_s3->uploadFileToS3Bucket($bucket_data);
if (is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) {
log_message('ERROR', '###PDIMAGE stored in S3' . $pd_id . ' - ' . $form_id);
// $record_data = array('fk_pd_id' => $pd_id,'pd_document_title'=>$title,'pd_document_name'=>$tempdocname,'fk_form_id'=>$form_id,'is_show_report' =>$is_show_report,'rental_count_id' => $rental_count_id,'location' => isset($doc['link']) ? $doc['link'] : null,'co_applicant_id' => $co_applicant_id,'img_type' => $img_type,'image_key' => (isset($doc['image_key']) ? $doc['image_key'] : null));
$record_data = array('fk_pd_id' => $pd_id, 'pd_document_title' => $title, 'pd_document_name' => $tempdocname, 'fk_form_id' => $form_id, 'is_show_report' => $is_show_report, 'rental_count_id' => $rental_count_id, 'location' => isset($doc['link']) ? $doc['link'] : null, 'co_applicant_id' => $co_applicant_id, 'img_type' => $img_type, 'image_key' => (isset($doc['image_key']) ? $doc['image_key'] : null), "pd_image_alias_name" => (isset($doc['pd_image_alias_name']) ? $doc['pd_image_alias_name'] : null));
$record_data['company_id'] = $company_id ? $company_id : null;
$id = $this->PD_Model->saveRecords($record_data, PDDOCUMENTS);
if ($id != null || $id != "") {
$count++;
$pks[] = $id;
}
$uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname, $key, $time = '+1 week');
$this->img_url_for_watermark = $uri;
//print_r($uri);
}
}
if ($count == count($data)) {
//$logger->info('All Images Saved Sucessfully',array($pd_id,$form_id,$company_id));
$result['status'] = true;
$result['count'] = $count;
$result['pks'] = $pks;
$result['records'] = $uri;
$result['msg'] = "All Images Saved Successfully";
} else {
//$logger->info('Some Images Not Saved',array($pd_id,$form_id,$company_id));
$result['status'] = true;
$result['count'] = $count;
$result['pks'] = $pks;
$result['msg'] = "Some Images Not Saved!";
}
return $result;
}
public function saveBase64Images_new($pd_id, $form_id = null, $company_id = null, $rental_count_id = null, $data)
{
$count = 0;
$result = array();
$pks = array();
$pd_details = $this->PD_Model->getPDMasterDetails($pd_id);
//print_r($data);die();
EXTERNAL_DIR_CHECK::checkExternalDirectory($pd_id);
foreach ($data as $iter => $doc) {
$temp_base64_string = $doc['image'];
$title = $doc['Name'];
$is_show_report = isset($doc['is_show_report']) ? $doc['is_show_report'] : null;
//$external_path = $this->config->item('external_data_path');
$output_file = $this->external_path . "/pd_reports/" . $pd_id . "/temp_base64_image.jpeg";
//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-i-s') . '.jpeg';
$ifp = fopen($output_file, 'wb');
$temp_data = explode(',', $temp_base64_string);
// fwrite( $ifp, base64_decode( $temp_data[ 1 ] ) );
//fclose( $ifp );
$image_p = imagecreatetruecolor(500, 375);
// ################### start img water marking with text
//echo $temp_base64_string;
$imagetobewatermark = imagecreatefromstring(base64_decode($temp_data[1]));
$location_watermarktext = "Location: " . $doc['link'];
$font = APPPATH . "docs/robold.ttf"; //metion font and it's location
$fontsize = "12";
$x = imagesx($imagetobewatermark);
$y = imagesy($imagetobewatermark);
$water_mark_text_color = imagecolorallocate($imagetobewatermark, 225, 0, 0);
imagettftext($imagetobewatermark, $fontsize, 0, 120, ($y - 30), $water_mark_text_color, $font, $location_watermarktext);
imagettftext($imagetobewatermark, $fontsize, 0, 120, ($y - 10), $water_mark_text_color, $font, 'Date: ' . date('Y-m-d h:i:s a'));
//imagejpeg($imagetobewatermark,$output_file,100);//save as png file in ouputfile location
// die();
//################# end img water marking with text
//###########image water marking with logo
$pd_logo = imagecreatefromstring(file_get_contents(APPPATH . 'docs/icon.png'));
$curret_file = $imagetobewatermark;
$sx = imagesx($curret_file);
$sy = imagesy($curret_file);
// imagecopyresized ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h ) : bool
//imagecopyresized ( $curret_file , $pd_logo ,5, ($sy - 54) , 0 , 0 , 50 , 50 , 50 , 54 );
// imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h ) : bool
imagecopyresampled($curret_file, $pd_logo, 5, ($sy - 54), 0, 0, 50, 50, 50, 54);
imagejpeg($curret_file, $output_file, 100); // save png image in specified location
//###########end of image water marking with logo
//die();
$tempdoc = $output_file;
$tempdocname = $temp_file_name;
$bucketname = LENDER_BUCKET_NAME_PREFIX . $pd_details[0]['fk_lender_id'];
$key = 'pd' . $pd_id . '/' . $tempdocname;
// if($form_id != null)
// {
// $key = 'pd'.$pd_id.'/'.'form'.$form_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, 'fk_form_id' => $form_id, 'is_show_report' => $is_show_report, 'rental_count_id' => $rental_count_id, 'location' => $doc['link']);
$record_data['company_id'] = $company_id ? $company_id : null;
$id = $this->PD_Model->saveRecords($record_data, PDDOCUMENTS);
if ($id != null || $id != "") {
$count++;
$pks[] = $id;
}
}
}
if ($count == count($data)) {
//$logger->info('All Images Saved Sucessfully',array($pd_id,$form_id,$company_id));
$result['status'] = true;
$result['count'] = $count;
$result['pks'] = $pks;
$result['msg'] = "All Images Saved Successfully";
} else {
//$logger->info('Some Images Not Saved',array($pd_id,$form_id,$company_id));
$result['status'] = true;
$result['count'] = $count;
$result['pks'] = $pks;
$result['msg'] = "Some Images Not Saved!";
}
return $result;
}
public function calculateScore($pdid)
{
//echo $pdid;die();
//GET JSON FORM DATA
$pd_master_details = $this->PD_Model->getPDMasterDetails($pdid);
//print_r($pd_master_details);
$form_data = $this->PD_Model->getScorablePDFormDetailsJSON($pdid);
//print_r($form_data);
//Get Latest Loan Amount form loan form.
$loan_amt_from_loam_form = json_decode($form_data[10][0]['processed_json'], true);
$loan_amt_from_loam_form = $loan_amt_from_loam_form['loan_amount'];
//echo $loan_amt_from_loam_form;
//seperate PD Scorable quesitons from JSON
$score_questions = $this->seperateScoreQuestions($form_data, $pd_master_details);
// echo "###################################";
//Get Pesrsonal Assets Grid Masters Details
if ((int)$loan_amt_from_loam_form >= 100000000) {
$this->db->SELECT('*');
$this->db->FROM(PERSONALASSETGRID);
$this->db->WHERE('isactive', 1);
$this->db->ORDER_BY('personal_asset_grid_id', 'DESC');
$this->db->LIMIT(1);
$personal_asset_grid['master_grid'] = $this->db->GET()->result_array();
} else {
$this->db->SELECT('*');
$this->db->FROM(PERSONALASSETGRID);
$this->db->WHERE('isactive', 1);
$this->db->WHERE('loan_amount_from<=', (int)$loan_amt_from_loam_form);
$this->db->WHERE('loan_amount_to>=', (int)$loan_amt_from_loam_form);
$personal_asset_grid['master_grid'] = $this->db->GET()->result_array();
}
// print_r($this->db->last_query());
// print_r($personal_asset_grid['master_grid']);
// die();
$this->db->SELECT('*');
$this->db->FROM(PERSONALASSETGRIDVARIANCE);
$this->db->WHERE('isactive', 1);
$personal_asset_grid['variance_grid'] = $this->db->GET()->result_array();
// echo "calculateScore";
// print_r($personal_asset_grid);die();
// Call PD score functions
$combination = $pd_master_details[0]['fk_lender_id'] . $pd_master_details[0]['fk_product_id'] . $pd_master_details[0]['fk_customer_segment'];
switch ($combination) {
case 111111:
PDSCORE::calculatePDScore111($score_questions, $loan_amt_from_loam_form, $personal_asset_grid);
break;
default:
switch ($pd_master_details[0]['fk_pd_type']) {
case 1: //FULL PD
$score_questions = PDSCORE::genericDIPDScoreCalculate($score_questions, $loan_amt_from_loam_form, $personal_asset_grid, $pd_master_details);
break;
case 2: //SMART PD
$score_questions = PDSCORE::genericDISmartPDScoreCalculate($score_questions, $loan_amt_from_loam_form, $personal_asset_grid, $pd_master_details);
break;
case 3: //tele PD
$score_questions = PDSCORE::genericTelePDScoreCalculate($score_questions, $loan_amt_from_loam_form, $personal_asset_grid, $pd_master_details);
break;
}
}
return $score_questions;
}
//Get All Score able Question from various PD Forms - 3 Questions Pending
public function seperateScoreQuestions($form_data, $pd_master_details)
{
$score_questions = array();
$OTP = $pd_master_details[0]['is_otp_done'];
$is_this_tele_pd = $pd_master_details[0]['fk_pd_type'] == 3 ? true : null;
#####General Form Questions########
$general_form = (json_decode($form_data[18][0]['processed_json'], true));
// echo "seperateScoreQuestions";
// - QNO (1.7) OTP AUTHENDICATION DONE
$score_questions['general']['otp_done'] = $OTP ? 'Yes' : 'No';
// 1 - QNO(1.1) - Is Person Met, One Of the Applicant's
$qualification_temp_array = array();
$score_questions['general']['person_met_is_applicant'] = 'no';
foreach ($general_form['individuals'] as $person) {
//print_r($person);
$qualification_temp_array = array_merge($qualification_temp_array, array($person['qualification']));
if ($person['is_applicant'] == true && $person['is_person_met'] == true) {
//echo $person['applicant_name'];
$score_questions['general']['person_met_is_applicant'] = 'yes';
}
}
//if tele pd remove person_met_is_applicant
if ($is_this_tele_pd) {
unset($score_questions['general']['person_met_is_applicant']);
}
//print_r($qualification_temp_array);
$qualification_temp_array = array_map(function ($item) {
return $item != "" || $item != null ? $item : 6;
}, $qualification_temp_array);
//print_r($qualification_temp_array);
$min = count($qualification_temp_array) ? min($qualification_temp_array) : 6;
//die();
// 2 - QNO(1.8) - Qualification
$score_questions['general']['qualification'] = $min;
// 3 - QNO(2.1) - No of Years Business Run
if (array_key_exists('companies', $general_form)) {
$score_questions['business']['no_of_years_business_run'] = isset($general_form['companies'][0]['business_years']) ? $general_form['companies'][0]['business_years'] : 0;
}
#####End of General Form Questions########
#####Address Form Questions########
$address_form = (json_decode($form_data[5][0]['processed_json'], true));
//print_r($address_form);die();
if (!$is_this_tele_pd) {
if (isset($address_form['is_pd_done_on_initiated_address']) && $address_form['is_pd_done_on_initiated_address'] != 1) {
// 4 - QNO(1.2) - Comment on locality
$score_questions['general']['comment_locality'] = $address_form['alternative_addresses'][0]['comment_locality_master'];
// 5 - QNO(1.3) - pd location approach
$score_questions['general']['pd_location_approach'] = $address_form['alternative_addresses'][0]['pd_location_master'];
} else //get it from alternative address
{
// 4 - QNO(1.2) - Comment on locality
$score_questions['general']['comment_locality'] = $address_form['addresses'][0]['comment_locality_master'];
// 5 - QNO(1.3) - pd location approach
$score_questions['general']['pd_location_approach'] = $address_form['addresses'][0]['pd_location_master'];
}
}
#####ENd Of Address Form Questions########
//print_r($score_questions['general']);die();
#####Final Remarks Form Questions########
$final_remarks_form = (json_decode($form_data[20][0]['processed_json'], true));
//print_r($final_remarks_form);
// 6 - QNO(1.4) - customer behaviour
$score_questions['general']['customer_behaviour'] = $final_remarks_form['final_custormer_remark_type_master'];
// 7 - QNO(3.1) - pd_officer_recommadations
$score_questions['final_remarks']['pd_officer_recommandations'] = $final_remarks_form['pd_officers_recommendation_master'];
// 8 - QNO(2.11) - pd location approach
if (!$is_this_tele_pd) {
$score_questions['business']['location_suited_for_busienss'] = $final_remarks_form['is_service_provided'];
}
#####End of Final Remarks Form Questions########
#####Neighbourhood Form Questions########
if (!$is_this_tele_pd) {
$neighbourhood_form = (json_decode($form_data[19][0]['processed_json'], true));
//print_r($neighbourhood_form);
// 9 - QNO(1.5) - neibourhood_check_as_per_pd_officer
$score_questions['general']['neibourhood_check_as_per_pd_officer'] = isset($neighbourhood_form['neighbourhood_status']) ? $neighbourhood_form['neighbourhood_status'] : 'Negative';
}
#####End of Neighbourhood Form Questions########
#####Business Form Questions########
$business_form = (json_decode($form_data[13][0]['processed_json'], true));
//print_r($business_form);die();
// 10 - QNO(1.6) - was_the_company_name_board_sighted
$score_questions['general']['was_the_company_name_board_sighted'] = isset($business_form['was_the_company_name_board_sighted']) ? $business_form['was_the_company_name_board_sighted'] : 'No';
// 11 - QNO(2.2) - seasonality
$score_questions['business']['business_seasonality'] = $business_form['seasonality'];
// 12 - QNO(2.3) - employees_total
if (!$is_this_tele_pd) {
$score_questions['business']['employees_total'] = $business_form['employees_total'];
}
// 13 - QNO(2.4) - all business certificate
$temp = array();
$temp['shop_eat_act_cert'] = isset($business_form['shop_eat_act_cert']) ? $business_form['shop_eat_act_cert'] : 'not applicable';
$temp['gst_Regn_cert'] = isset($business_form['gst_Regn_cert']) ? $business_form['gst_Regn_cert'] : 'not applicable';
$temp['pf_regn'] = isset($business_form['pf_regn']) ? $business_form['pf_regn'] : 'not applicable';
$temp['esic_regn'] = isset($business_form['esic_regn']) ? $business_form['esic_regn'] : 'not applicable';
$temp['export_import_cert'] = isset($business_form['export_import_cert']) ? $business_form['export_import_cert'] : 'not applicable';
$temp['factory_cert'] = isset($business_form['factory_cert']) ? $business_form['factory_cert'] : 'not applicable';
$temp['cert_of_practice'] = isset($business_form['practice_cert']) ? $business_form['practice_cert'] : 'not applicable';
$score_questions['business']['cerificates'] = $temp;
#####End of Business Form Questions########
#####Business Assets Form Questions########
$business_assest_form = (json_decode($form_data[22][0]['processed_json'], true));
//print_r($business_assest_form);//die();
$property_count = 0;
$vechile_count = 0;
if (array_key_exists('business_assets_for_address', $business_assest_form) && isset($business_assest_form['business_assets_for_address'][0])) {
$property_count = (!strcasecmp($business_assest_form['business_assets_for_address'][0]['business_ownership_type'], 'owned')) ? (++$property_count) : $property_count;
}
if (array_key_exists('business_assets_details', $business_assest_form)) {
foreach ($business_assest_form['business_assets_details'] as $value) {
if (isset($value['business_assets_mode']) && $value['business_assets_mode'] == 2 && $value['business_ownership_type'] == 'owned') {
$property_count++;
}
if (isset($value['business_assets_mode']) && $value['business_assets_mode'] == 3 && $value['business_ownership_type'] == 'owned') {
$vechile_count++;
}
}
//echo
// 14 - QNO(2.5) - owned_property
$score_questions['business']['owned_property'] = $property_count ? 'yes' : 'no';
// 15 - QNO(2.6) - owned_vechile
$score_questions['business']['owned_vechile'] = $vechile_count ? 'yes' : 'no';
// - QNO (2.12) - business_activity seen
if (!$is_this_tele_pd) {
$score_questions['business']['business_activity_has_seen'] = isset($business_assest_form['business_assets_for_address'][0]['business_is_pd_visited']) ? $business_assest_form['business_assets_for_address'][0]['business_is_pd_visited'] : 'no';
}
}
#####End of Business Assets Form Questions########
#####supplier Form Questions########
$supplier_form = isset($form_data[1][0]['processed_json']) ? (json_decode($form_data[1][0]['processed_json'], true)) : array();
$supplier_count = 0;
if (count($supplier_form)) {
if ($supplier_form['supplier_info_available'] == 1) {
if (array_key_exists('manufacturing_details', $supplier_form)) {
if (isset($supplier_form['manufacturing_details'][0]['main_raw_materials'])) {
foreach ($supplier_form['manufacturing_details'][0]['main_raw_materials'] as $manu_key => $manu_value) {
if ($manu_value['manufacturing_raw_material_name'] != "" && $manu_value['manufacturing_supplier_name'] != "") {
$supplier_count++;
}
}
}
}
if (array_key_exists('trade_details', $supplier_form)) {
if (isset($supplier_form['trade_details'][0]['trading_products'])) {
foreach ($supplier_form['trade_details'][0]['trading_products'] as $trading_key => $trading_value) {
if ($trading_value['trade_product_name'] != "" && $trading_value['trade_supplier_name'] != "") {
$supplier_count++;
}
}
}
}
if (array_key_exists('servicing_details', $supplier_form)) {
if (isset($supplier_form['servicing_details'][0]['service_providers'])) {
foreach ($supplier_form['servicing_details'][0]['service_providers'] as $serivce_key => $service_value) {
if ($service_value['service_provider_name'] != "" && $service_value['service_provider_supplier_name'] != "") {
$supplier_count++;
}
}
}
}
$score_questions['business']['minimum_supplier_info'] = $supplier_count ? 'Provided' : 'Not Provided';
} else {
$score_questions['business']['minimum_supplier_info'] = 'Not Applicable';
}
} else {
$score_questions['business']['minimum_supplier_info'] = 'Not Applicable';
}
#####End of supplier Form Questions########
#####client Form Questions########
$client_form = isset($form_data[2][0]['processed_json']) ? (json_decode($form_data[2][0]['processed_json'], true)) : array();
$client_count = 0;
//print_r($client_form);die();
if (count($client_form)) {
if (isset($client_form['client_info_available']) && $client_form['client_info_available'] == 1) {
if (array_key_exists('manufacturing_details', $client_form)) {
if (isset($client_form['manufacturing_details'][0]['main_raw_materials'])) {
foreach ($client_form['manufacturing_details'][0]['main_raw_materials'] as $key => $value) {
if ($value['manufacturing_product_name'] != "" && $value['manufacturing_client_name'] != "") {
$client_count++;
}
}
}
}
if (array_key_exists('trade_details', $client_form)) {
if (isset($client_form['trade_details'][0]['trading_products'])) {
foreach ($client_form['trade_details'][0]['trading_products'] as $key => $value) {
//print_r($value);die();
if ($value['trade_product_name'] != "" && (isset($value['trade_client_name'])) && $value['trade_client_name'] != "") {
$client_count++;
}
}
}
}
if (array_key_exists('service_provider_details', $client_form)) {
if (isset($client_form['service_provider_details'][0]['service_products'])) {
foreach ($client_form['service_provider_details'][0]['service_products'] as $key => $value) {
if ($value['service_provider_product_name'] != "" && $value['service_provider_client_name'] != "") {
$client_count++;
}
}
}
}
$score_questions['business']['minimum_client_info'] = $client_count ? 'Provided' : 'Not Provided';
} else {
$score_questions['business']['minimum_client_info'] = 'Not Provided';
}
} else {
$score_questions['business']['minimum_client_info'] = 'Not Applicable';
}
#####End of client Form Questions########
#####Stock Form Questions########
$stock_form = isset($form_data[11][0]['processed_json']) ? (json_decode($form_data[11][0]['processed_json'], true)) : array();
//print_r($stock_form);
if (count($stock_form)) {
//print_r($stock_form);die();
if (isset($stock_form['manufacturing_details']) && ($stock_form['manufacturing_details'] != null || $stock_form['manufacturing_details'] != "")) {
$score_questions['business']['stock_raw_material_enough'] = isset($stock_form['manufacturing_details'][0]['is_sufficiant_raw']) ? $stock_form['manufacturing_details'][0]['is_sufficiant_raw'] : 'Not Applicable';
}
$score_questions['business']['stock_finished_goods_enough'] = isset($stock_form['is_sufficiant_finished_and_traded_goods']) && ($stock_form['is_sufficiant_finished_and_traded_goods'] != "" || $stock_form['is_sufficiant_finished_and_traded_goods'] != null) ? $stock_form['is_sufficiant_finished_and_traded_goods'] : 'Not Applicable';
} else {
$score_questions['business']['stock_raw_material_enough'] = 'Not Applicable';
$score_questions['business']['stock_finished_goods_enough'] = 'Not Applicable';
//$score_questions['general']['value_of_other_assets'] = 'Not Applicable';
}
#####End of Stock Form Questions########
#####Other Assest Form Questions########
if ($pd_master_details[0]['lender_short_name'] != 'CFPL') {
$other_asset_form = (json_decode($form_data[4][0]['processed_json'], true));
//print_r($other_asset_form);
$over_all_asset_value = 0;
if (array_key_exists('assets_details', $other_asset_form)) {
//print_r($other_asset_form['assets_details']);die();
foreach ($other_asset_form['assets_details'] as $asset) {
//echo 'Value - '.$asset['approximate_market_value'];
$over_all_asset_value += is_numeric($asset['approximate_market_value']) ? $asset['approximate_market_value'] : 0;
if ($asset['assets_mode'] == 6) //LIC
{
$over_all_asset_value += $asset['details'][0]['sum_assured'];
}
if ($asset['assets_mode'] == 7) //Investments
{
$over_all_asset_value += $asset['details'][0]['amount_of_invest'];
}
}
}
//echo 'over_all_asset_value from FUN - '.$over_all_asset_value;die();
// 18 Q.NO(1.9)
$score_questions['general']['value_of_other_assets'] = $over_all_asset_value;
}
#####End of Other Assest Form Questions########
######Business Banking ##############
//here IF Else is Temporary CLix
//here i am changed to 21 form-id to 7 form-id
$temp_flag = isset($form_data[21][0]['processed_json']) ? 1 : 0;
if ($temp_flag == 0) {
$business_bank_form = (json_decode($form_data[7][0]['processed_json'], true));
$vintage = array();
if (array_key_exists('business_details', $business_bank_form)) {
foreach ($business_bank_form['business_details'] as $banking) {
$year = $banking['vintage_year_business'] ? $banking['vintage_year_business'] : 0;
$month = $banking['vintage_month_business'] ? $banking['vintage_month_business'] : 0;
$temp = $year . '.' . $month;
$vintage = array_merge($vintage, array($temp));
}
}
} else {
$business_bank_form = (json_decode($form_data[21][0]['processed_json'], true));
$vintage = array();
if (array_key_exists('banking_details', $business_bank_form)) {
foreach ($business_bank_form['banking_details'] as $banking) {
$year = $banking['vintage_year'] ? $banking['vintage_year'] : 0;
$month = $banking['vintage_month'] ? $banking['vintage_month'] : 0;
$temp = $year . '.' . $month;
$vintage = array_merge($vintage, array($temp));
}
}
}
$score_questions['business']['vintage_of_business_account'] = count($vintage) ? max($vintage) : 0;
//echo $vintage_of_business_account_for_display;
//$score_questions['business']['vintage_of_business_account_for_display'] = $vintage_of_business_account_for_display;
######End of Business Banking ##############
return $score_questions;
}
public function updateSubProductFromLoanDetailsForm($records)
{
$pd_master_details = $this->PD_Model->getPDMasterDetails($records['pdid']);
$new_sub_product = $records['sub_product'];
$old_sub_product = $pd_master_details[0]['fk_subproduct_id'];
if ($new_sub_product != $old_sub_product) {
$where_condition_array = array('pd_id' => $records['pdid']);
$temp = array('fk_subproduct_id' => $new_sub_product, 'fk_updatedby' => $records['fk_createdby']);
$pk_id = $this->PD_Model->updateRecords($temp, PDTRIGGER, $where_condition_array);
}
}
public function saveEmpSalaryAsBusinessExpensesFromBusinessForm($records)
{
//echo "FROM saveEmpSalaryAsBusinessExpensesFromBusinessForm";
if (isset($records['employees_appx_salary']) && ($records['employees_appx_salary'] != null || $records['employees_appx_salary'] != '')) {
//pd_expense_id, fk_pd_id, expense_item_id, expense_value, fk_frequency_id, annual_expenses_value, isactive, fk_createdby, createdon, company_id, comments
$annual_emp_salary = ($records['employees_appx_salary'] * 12);
//echo $annual_emp_salary;
$temp_array = array('fk_pd_id' => $records['pdid'], 'expense_item_id' => 3, 'expense_value' => $records['employees_appx_salary'], 'fk_frequency_id' => 7, 'annual_expenses_value' => $annual_emp_salary, 'fk_createdby' => $records['fk_createdby'], 'company_id' => $records['company_id'], 'comments' => 'Derived from Business Form');
$fields = array('pd_expense_id', 'expense_item_id', 'fk_frequency_id', 'expense_value', 'annual_expenses_value', 'comments');
$table = PDBUSINESSEXPENSES . ' as PDBUSINESSEXPENSES';
$where_condition_array = array('fk_pd_id' => $records['pdid'], 'isactive' => 1, 'expense_item_id' => 3, 'fk_frequency_id' => 7, 'company_id' => $records['company_id'], 'comments' => 'Derived from Business Form');
$business_expenses = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, $table);
//print_r($business_expenses);
if (count($business_expenses)) {
//echo "Update";
if ($annual_emp_salary != 0) {
$where_condition_array = array('pd_expense_id' => $business_expenses[0]['pd_expense_id']);
$this->PD_Model->updateRecords($temp_array, $table, $where_condition_array);
}
} else {
//echo "insert";
if ($annual_emp_salary != 0) {
$this->PD_Model->saveRecords($temp_array, PDBUSINESSEXPENSES);
}
}
}
}
public function saveAssetRentAsBusinessExpensesFromBusinessAssestForm($records)
{
//echo "saveAssetRentAsBusinessExpensesFromBusinessAssestForm";
$over_all_rent_amt = 0;
if (isset($records['business_assets_for_address']) && ($records['business_assets_for_address'] != "" || $records['business_assets_for_address'] != null)) {
foreach ($records['business_assets_for_address'] as $business_asset) {
if ($business_asset['business_monthly_rented_amt'] != "" || $business_asset['business_monthly_rented_amt'] != null) {
$over_all_rent_amt += $business_asset['business_monthly_rented_amt'];
}
}
}
if (isset($records['business_assets_details']) && ($records['business_assets_details'] != "" || $records['business_assets_details'] != null)) {
foreach ($records['business_assets_details'] as $business_asset) {
if ($business_asset['business_monthly_rented_amt'] != "" || $business_asset['business_monthly_rented_amt'] != null) {
$over_all_rent_amt += $business_asset['business_monthly_rented_amt'];
}
}
}
//echo $over_all_rent_amt;
$temp_array = array('fk_pd_id' => $records['pdid'], 'expense_item_id' => 9, 'expense_value' => $over_all_rent_amt, 'fk_frequency_id' => 7, 'annual_expenses_value' => ($over_all_rent_amt * 12), 'fk_createdby' => $records['fk_createdby'], 'company_id' => $records['company_id'], 'comments' => 'Derived from Business Form');
$fields = array('pd_expense_id', 'expense_item_id', 'fk_frequency_id', 'expense_value', 'annual_expenses_value', 'comments');
$table = PDBUSINESSEXPENSES . ' as PDBUSINESSEXPENSES';
$where_condition_array = array('fk_pd_id' => $records['pdid'], 'isactive' => 1, 'expense_item_id' => 9, 'fk_frequency_id' => 7, 'company_id' => $records['company_id'], 'comments' => 'Derived from Business Form');
$business_expenses = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, $table);
//print_r($business_expenses);
if (count($business_expenses)) {
//echo "Update";
if ($over_all_rent_amt != 0) {
$where_condition_array = array('pd_expense_id' => $business_expenses[0]['pd_expense_id']);
$this->PD_Model->updateRecords($temp_array, $table, $where_condition_array);
}
} else {
//echo "insert";
if ($over_all_rent_amt != 0) {
$this->PD_Model->saveRecords($temp_array, PDBUSINESSEXPENSES);
}
}
}
public function saveHTMLReport_post()
{
$records = $this->post('records');
$pdid = $records['pdid'];
$content = $records['content'];
//print_r($content);die();
if ($content != "") {
$report_data = $content;
$start_pos = strpos($report_data, '');
$end_pos = $start_pos + 10;
$report_data = substr_replace($report_data, '', $end_pos, 0);
$report_data = substr_replace($report_data, '', 0, 0);
$report_data = substr_replace($report_data, '', strlen($report_data), 0);
$content = $report_data;
}
$fk_createdby = $records['fk_createdby'];
$random_string = $records['random_string'];
$pd_report_time = date('Y-m-d-h-i-s');
$pd_report_store = $this->external_path . '/pd_reports/' . $pdid . '/' . $pd_report_time . '.html';
file_put_contents($pd_report_store, $content);
//Update Latest File name and qc edited status into trigger table
$update = $this->PD_Model->updateRecords(array('pd_report_html_filename' => $pd_report_time, 'fk_createdby' => $fk_createdby, 'is_qc_edited' => 1), PDTRIGGER, array('pd_id' => $pdid, 'random_string' => $random_string));
//Update previous versions as 0
$update_reports_version_blob = $this->PD_Model->updateRecords(array('is_latest' => 0), PDREPORTSVERSIONBLOB, array('fk_pd_id' => $pdid, 'is_latest' => 1));
//insert current PD report html file name as latest
$pd_reports_version_blob_new = $this->PD_Model->saveRecords(array('html_file_name' => $pd_report_time, 'fk_createdby' => $fk_createdby, 'is_latest' => 1, 'fk_pd_id' => $pdid), PDREPORTSVERSIONBLOB);
if ($update && $update_reports_version_blob && $pd_reports_version_blob_new) {
$logger = MYLOG::logFunction(null, $pdid);
$logger->info('QC Edit Called', array('Edited by' => $fk_createdby, 'DB Result' => $update . '-' . $update_reports_version_blob . '-' . $pd_reports_version_blob_new));
$dat['dataStatus'] = true;
$dat['status'] = REST_Controller::HTTP_OK;
$dat['msg'] = 'Report Generated Successfully..!';
$this->response($dat, REST_Controller::HTTP_OK);
}
}
public function getPDReportHTML_get()
{
$pdid = $this->uri->segment(3);
$random_string = $this->uri->segment(2);
$this->getLatestPDReportHTMLFile($pdid, $random_string);
}
function getLatestPDReportHTMLFile($pdid, $random_string, $return_type = false)
{
// echo $pdid;echo $random_string;die;
// echo "now i am in child function ";
// exit();
if (($pdid != null || $pdid != "")) //&& (strlen($pdid) == 16) &&(is_string($pdid)))
{
$pd_data = $this->PD_Model->selectCustomRecords(array('pd_id', 'pd_report_html_filename'), array('random_string' => $random_string, 'pd_id' => $pdid), PDTRIGGER);
// print_r($pd_data);exit();
if (count($pd_data)) {
$report_data = file_get_contents($this->external_path . '/pd_reports/' . $pd_data[0]['pd_id'] . '/' . $pd_data[0]['pd_report_html_filename'] . '.html');
$temp_file_path = APPPATH . 'views/pd_reports/' . $pd_data[0]['pd_id'] . '/temp.html';
if (!file_exists($temp_file_path)) {
mkdir(APPPATH . 'views/pd_reports', 0777);
mkdir(APPPATH . 'views/pd_reports/' . $pd_data[0]['pd_id'], 0777);
}
file_put_contents($temp_file_path, $report_data);
$view_name = 'pd_reports/' . $pd_data[0]['pd_id'] . '/temp.html';
// echo $view_name;
// die();
return $this->load->view($view_name, array(), $return_type);
} else {
echo " Not Found
";
}
} else {
echo " Not Found
";
}
}
public function getPDReportPDFpreview_post()
{
$pdid = $this->uri->segment(3);
log_message('DEBUG', "getPDReportPDFpreview_post called "); //die();
$random_string = $this->uri->segment(2);
EXTERNAL_DIR_CHECK::checkExternalDirectory($pdid);
$records = $this->post('myData');
$report_data = '';
if ($records) {
$report_data = $records;
//attach outer HTML tags
$start_pos = strpos($report_data, '');
$end_pos = $start_pos + 10;
$report_data = substr_replace($report_data, '', $end_pos, 0);
$report_data = substr_replace($report_data, '', 0, 0);
$report_data = substr_replace($report_data, '', -1, 0);
//replace tooltip and span tags
$total_replaces = substr_count($report_data, '');
for ($i = 0; $i < $total_replaces; $i++) {
$start_pos = strpos($report_data, '');
$end_pos = strpos($report_data, '', strpos($report_data, ''));
$end_pos = $end_pos + 14;
//echo $start_pos.'-';echo $end_pos.'-';echo ($end_pos - $start_pos).'-';
$report_data = substr_replace($report_data, '', $start_pos, ($end_pos - $start_pos));
$report_data = substr_replace($report_data, '', strpos($report_data, ''), (strlen('')));
}
} else {
$report_data = $this->getLatestPDReportHTMLFile($pdid, $random_string, true);
//replace tooltip and span tags
$total_replaces = substr_count($report_data, '');
for ($i = 0; $i < $total_replaces; $i++) {
$start_pos = strpos($report_data, '');
$end_pos = strpos($report_data, '', strpos($report_data, ''));
$end_pos = $end_pos + 14;
//echo $start_pos.'-';echo $end_pos.'-';echo ($end_pos - $start_pos).'-';
$report_data = substr_replace($report_data, '', $start_pos, ($end_pos - $start_pos));
$report_data = substr_replace($report_data, '', strpos($report_data, ''), (strlen('')));
}
}
$pdf_doc = $this->pdfgenerator->generate($report_data, $filename = 'version', $stream = false, $paper = 'A4', $orientation = "portrait");
//End of PDF Gen using DOM PDF
$output_file2 = $this->external_path . "/pd_reports/" . $pdid . "/sample.pdf";
$link_to_send = 'https://' . $this->config->item('full_server_name') . '/ssa_external_data/' . ENVIRONMENT . '/pd_reports/' . $pdid . "/sample.pdf";
//$link_to_be_create = '/var/www/html/ssa_external_data/'. ENVIRONMENT.'/pd_reports/'. $pdid . "/sample.pdf";
file_put_contents($output_file2, $pdf_doc);
$this->load->helper('SYMLINKS');
SYMLINKS::createSymLinks($pdid, $output_file2);
echo json_encode(array('link' => $link_to_send));
}
public function pdFormsCompletenessCheck_post()
{
$pdid = $this->post('pd_id');
$client = $this->post('client') ? $this->post('client') : 'WEB';
$pd_master_details = $this->PD_Model->getPDMasterDetails($pdid);
$res_array = array();
$this->load->helper('pdcompletenesscheck');
switch ($pd_master_details[0]['fk_pd_type']) {
case 1: //FUll PD
case 2: //smartPD
$res_array = pdcompletenesscheck::fullPDCompletenessCheck($pdid, $pd_master_details, $client);
break;
case 3: //tele PD
$res_array = pdcompletenesscheck::telePDCompletenessCheck($pdid, $pd_master_details, $client);
break;
}
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $res_array;
$data['msg'] = count($res_array) ? 'PD Details are incomplete' : 'All forms were answered';
$this->response($data, REST_Controller::HTTP_OK);
}
public function convertImgUrlToBase64_post()
{
$img_url = $this->post('img_url');
$b64image = base64_encode(file_get_contents($img_url));
if ($b64image) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $b64image;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$data['msg'] = 'Something Went Wrong / Can`t convet given URL';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function updateBase64Images_post()
{
$records = $this->post('records');
$pd_details = $this->PD_Model->getPDMasterDetails($records['fk_pd_id']);
//print_r($records);
// if(isset($records['isactive']) && ($records['isactive'] == 0 || $records['isactive'] == 1))//de activate the image
// {
// unset($records['image']);
// $where_condition_array = array('pd_document_id' => $records['pd_document_id']);
// $id = $this->PD_Model->updateRecords($records,PDDOCUMENTS,$where_condition_array);
// $master = $this->PD_Model->updateRecords(array('is_zip_created' => 0),PDTRIGGER,array('pd_id' => $records['fk_pd_id']));
// if($id != null || $id != "")
// {
// $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);
// }
// }
if (isset($records['image']) && ($records['image'] != '' && !substr_count($records['image'], 'https'))) {
$output_file = APPPATH . "/docs/temp_base64_image.jpeg";
$temp_file_name = $records['pd_document_name'];
$ifp = fopen($output_file, 'wb');
$temp_data = explode(',', $records['image']);
fwrite($ifp, base64_decode($temp_data[1]));
fclose($ifp);
$tempdoc = $output_file;
$tempdocname = $temp_file_name;
$bucketname = LENDER_BUCKET_NAME_PREFIX . $pd_details[0]['fk_lender_id'];
$key = 'pd' . $records['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_updatedby' => $records['fk_updatedby']);
if (isset($records['is_show_report'])) {
$record_data['is_show_report'] = $records['is_show_report'];
}
if (isset($records['pd_document_title'])) {
$record_data['pd_document_title'] = $records['pd_document_title'];
}
if (isset($records['isactive'])) {
$record_data['isactive'] = $records['isactive'];
}
if (isset($records['pd_image_alias_name'])) {
$record_data['pd_image_alias_name'] = $records['pd_image_alias_name'];
}
$where_condition_array = array('pd_document_id' => $records['pd_document_id']);
$id = $this->PD_Model->updateRecords($record_data, PDDOCUMENTS, $where_condition_array);
if ($id != null || $id != "") {
$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);
}
// }
// 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);
// }
}
//Get Firebase Notification from fron end and update into userprofile
public function updateNotificationToken_post()
{
$records = $this->post('records');
$fk_user_id = $records['fk_user_id'];
$select_data = array('notification_token_id');
$where_condition_array = array('fk_user_id' => $fk_user_id);
$exist_data = $this->PD_Model->selectCustomRecords($select_data, $where_condition_array, USERNOTIFICATIONTOKENS);
if (!count($exist_data)) {
$insert_data = array('fk_user_id' => $fk_user_id);
if ($records['client'] == 'MOB') {
$insert_data['mob_token'] = $records['token'];
} else if ($records['client'] == 'WEB') {
$insert_data['web_token'] = $records['token'];
}
$id = $this->PD_Model->saveRecords($insert_data, USERNOTIFICATIONTOKENS);
if ($id) {
$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);
}
} else {
$exist_notification_token_id = $exist_data[0]['notification_token_id'];
$where_condition_array = array('notification_token_id' => $exist_notification_token_id);
$update_data = array();
if ($records['client'] == 'MOB') {
$update_data['mob_token'] = $records['token'];
} else if ($records['client'] == 'WEB') {
$update_data['web_token'] = $records['token'];
}
$id = $this->PD_Model->updateRecords($update_data, USERNOTIFICATIONTOKENS, $where_condition_array);
if ($id) {
$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 getPDScoreForDisplay_post()
{
$pdid = $this->post('pd_id');
//CHeck whether this PD is scoreable or not
$is_score_card_enabled = $this->PD_Model->getScoreCardEnabledStatusByPDID($pdid);
$t = '';
if (count($is_score_card_enabled) && $is_score_card_enabled[0]['is_score_card_enabled'] == 1) {
$score = $this->calculateScore($pdid);
//print_r($score);die();
$score_questions_display = $this->PD_Model->getScoreableQuestionToDispaly($pdid);
$t = $this->load->view('report_templates/scorecard', array('pd_score' => $score, 'score_questions_display' => $score_questions_display), true);
//echo $t;die();
}
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $t;
$this->response($data, REST_Controller::HTTP_OK);
}
public function savePDRemark_post()
{
$pd_id = $this->post('pd_id');
$remark = $this->post('remark');
$createdby = $this->post('createdby');
$is_revert_remark = $this->post('is_revert_remark') ? $this->post('is_revert_remark') : 0;
if ($pd_id != null && $remark != null && $createdby != null) {
$res = $this->PD_Model->saveRecords(array('fk_pd_id' => $pd_id, 'remark' => $remark, 'createdby' => $createdby, 'is_revert_remark' => $is_revert_remark), PDREMARKS);
if ($res) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $res;
$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'] = 'In Appropriate call!';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function getLenderContactPersons_post()
{
$records = $this->post('records');
$lender_contact_persons = $this->PD_Model->getLenderContactPersons($records['fk_lender_id'], isset($records['pd_branch_id']) ? $records['pd_branch_id'] : null);
if (count($lender_contact_persons)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $lender_contact_persons;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$data['msg'] = 'Credit Person Lender Profile was not found?. Create Credit Person Lender profile';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function adminSetUserPassword_post()
{
//$email = $this
//$sql = "SELECT email FROM sineedgeprod.m_user_profile where email like '%imgc%'";
// $u = $this->db->query($sql)->result_array();
// print_r($u);
// die();
// foreach($u as $v)
// {
// $this->aws_cognito->adminSetUserPassword($v['email']);
// }
// die();
}
public function saveApplicantFromGeneralForm_post()
{
$records = $this->post();
$current_operation = null;
$applicant_id = null;
$custom_log_info = '###Payload Size - ' . (int) $_SERVER['CONTENT_LENGTH'] . ' ###saveApplicantFromGeneralForm - PDID - (' . $records['fk_pd_id'] . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
$applicant_type = ($records['is_person_met'] ? 3 : ($records['is_applicant'] ? 0 : '')); //3 - person met,0 - co applicant
$applicant_details = array('fk_pd_id' => $records['fk_pd_id'], 'applicant_name' => trim($records['applicant_name']), 'applicant_title_name' => $records['applicant_title_name'], 'applicant_type' => $applicant_type);
//print_r($applicant_details);
if ($records['pd_co_applicant_id'] == "" || $records['pd_co_applicant_id'] == null) {
$applicant_id = $this->PD_Model->saveRecords($applicant_details, PDAPPLICANTSDETAILS);
$current_operation = 1; // 1 means INSERT
} else {
//pull applicant details from master
$curret_applicant_type = $this->PD_Model->selectCustomRecords(array('*'), array('pd_co_applicant_id' => $records['pd_co_applicant_id']), PDAPPLICANTSDETAILS);
//print_r($curret_applicant_type);//die();
if ($curret_applicant_type[0]['applicant_type'] == 1) {
unset($applicant_details['applicant_type']);
}
//print_r($applicant_details);die();
$applicant_id = $this->PD_Model->updateRecords($applicant_details, PDAPPLICANTSDETAILS, array('pd_co_applicant_id' => $records['pd_co_applicant_id']));
$current_operation = 2; // 2 means UPDATE
}
//echo $current_operation.$applicant_id;
//die();
if ($records['is_person_met']) {
$img_data = array();
if ($current_operation == 1) {
if ($records['is_person_met_pic'] != "") {
$img_data[] = array('Name' => trim($records['applicant_name']), 'image' => $records['is_person_met_pic'], 'link' => $records['link'], 'co_applicant_id' => $applicant_id, 'img_type' => 1, 'image_key' => 'selfie_with_person_met');
}
if ($records['is_person_met_id_proof'] != "") {
$img_data[] = array('Name' => (trim($records['applicant_name']) . '-id_proof'), 'image' => $records['is_person_met_id_proof'], 'link' => $records['link'], 'co_applicant_id' => $applicant_id, 'img_type' => 2, 'image_key' => 'person_met_id');
}
}
///print_r( $img_data );
if ($current_operation == 2) {
if ($records['is_person_met_pic'] != "" && !substr_count($records['is_person_met_pic'], 'https')) {
$img_data[] = array('Name' => trim($records['applicant_name']), 'image' => $records['is_person_met_pic'], 'link' => $records['link'], 'co_applicant_id' => $records['pd_co_applicant_id'], 'img_type' => 1,'image_key' => 'selfie_with_person_met');
// Make inactive old entries with same data
$sql = 'UPDATE ' . PDDOCUMENTS . ' SET isactive = 0 where fk_pd_id = ' . $records['fk_pd_id'] . ' and co_applicant_id = ' . $records['pd_co_applicant_id'] . ' and img_type = 1';
$this->db->query($sql);
} else {
$this->PD_Model->updateRecords(array('pd_document_title' => trim($records['applicant_name'])), PDDOCUMENTS, array('fk_pd_id' => $records['fk_pd_id'], 'fk_form_id' => 18, 'co_applicant_id' => $records['pd_co_applicant_id'], 'img_type' => 1, 'isactive' => 1,'image_key' => 'selfie_with_person_met')); // 1- person met img
}
if ($records['is_person_met_id_proof'] != "" && !substr_count($records['is_person_met_id_proof'], 'https')) {
$img_data[] = array('Name' => (trim($records['applicant_name']) . '-id_proof'), 'image' => $records['is_person_met_id_proof'], 'link' => $records['link'], 'co_applicant_id' => $records['pd_co_applicant_id'], 'img_type' => 2,'image_key' => 'person_met_id');
// Make inactive old entries with same data
$sql = 'UPDATE ' . PDDOCUMENTS . ' SET isactive = 0 where fk_pd_id = ' . $records['fk_pd_id'] . ' and co_applicant_id = ' . $records['pd_co_applicant_id'] . ' and img_type = 2';
$this->db->query($sql);
} else {
$this->PD_Model->updateRecords(array('pd_document_title' => (trim($records['applicant_name']) . '-id_proof')), PDDOCUMENTS, array('fk_pd_id' => $records['fk_pd_id'], 'fk_form_id' => 18, 'co_applicant_id' => $records['pd_co_applicant_id'], 'img_type' => 2, 'isactive' => 1,'image_key' => 'person_met_id')); // 2- person met ID proof img
}
}
if (count($img_data)) {
$d = $this->saveBase64Images($records['fk_pd_id'], 18, null, null, $img_data);
//print_r($d);
}
}
$is_person_met_id_proof = '';
$is_person_met_pic = '';
$lender_id = $this->PD_Model->selectCustomRecords(array('fk_lender_id'), array('pd_id' => $records['fk_pd_id']), PDTRIGGER);
$bucket_name = LENDER_BUCKET_NAME_PREFIX . $lender_id[0]['fk_lender_id'];
$applicant_name = $this->PD_Model->selectCustomRecords(array('pd_document_name'), array('fk_pd_id' => $records['fk_pd_id'], 'pd_document_title' => (trim($records['applicant_name'])), 'isactive' => 1, 'co_applicant_id is not null' => null, 'img_type' => 1), PDDOCUMENTS);
//print_r($this->db->last_query());
if (count($applicant_name)) {
$profilepics3path = 'pd' . $records['fk_pd_id'] . '/' . ($applicant_name[0]['pd_document_name']);
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name, $profilepics3path, '30 minutes');
$is_person_met_pic = $singed_uri;
}
$applicant_name_id = $this->PD_Model->selectCustomRecords(array('pd_document_name'), array('fk_pd_id' => $records['fk_pd_id'], 'pd_document_title' => (trim($records['applicant_name']) . '-id_proof'), 'isactive' => 1, 'co_applicant_id is not null' => null, 'img_type' => 2), PDDOCUMENTS);
//print_r($this->db->last_query());
if (count($applicant_name_id)) {
$profilepics3path = 'pd' . $records['fk_pd_id'] . '/' . ($applicant_name_id[0]['pd_document_name']);
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name, $profilepics3path, '30 minutes');
$is_person_met_id_proof = $singed_uri;
}
$custom_log_info = ' ###Response saveApplicantFromGeneralForm - PDID - (' . $records['fk_pd_id'] . ') - ' . date('Y-m-d H:i:s A');
log_message('ERROR', $custom_log_info);
if ($applicant_id != null) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = array("pd_co_applicant_id" => $applicant_id, "is_person_met_pic" => $is_person_met_pic, "is_person_met_id_proof" => $is_person_met_id_proof);
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$data['msg'] = 'Data Not Updated, Try one more!';
$this->response($data, REST_Controller::HTTP_OK);
}
//pd_co_applicant_id, fk_pd_id, , applicant_type, mobile_no, landline, email, isactive, addressline1, addressline2, addressline3, fk_city, fk_state, pincode, relation, company_name, applicant_title_name, additional_pd_id
}
public function checkExistPDDetails_post()
{
$records = $this->post('records');
$client = $this->post('client');
$lender_applicant_id = isset($records['lender_applicant_id']) ? $records['lender_applicant_id'] : null;
$applicant_name = isset($records['applicant_name']) ? strtolower(trim($records['applicant_name'])) : null;
$mobile_no = isset($records['mobile_no']) ? $records['mobile_no'] : null;
$params = array();
$table = null;
if ($lender_applicant_id) {
$params['lender_applicant_id'] = $lender_applicant_id;
$table = PDTRIGGER;
}
if ($applicant_name) {
$params['applicant_name'] = $applicant_name;
$table = PDAPPLICANTSDETAILS;
}
if ($mobile_no) {
$params['mobile_no'] = $mobile_no;
$table = PDAPPLICANTSDETAILS;
}
$result_data = $this->PD_Model->checkExistPDDetails($params, $table, $client);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result_data;
$this->response($data, REST_Controller::HTTP_OK);
}
public function deactiveFormData_post()
{
//$records = $this->post('records');
$records = $this->post('records');
$fk_pd_id = $records['fk_pd_id'];
$fk_form_id = $records['fk_form_id'];
$company_id = $records['company_id'];
$fk_createdby = $records['fk_createdby'];
$rental_count_id = $records['rental_count_id'];
$fields = array('isactive' => 0, 'fk_updatedby' => $fk_createdby);
$where_condition_array = array('fk_pd_id' => $fk_pd_id, 'fk_form_id' => $fk_form_id);
if ($company_id) {
$where_condition_array['company_id'] = $company_id;
}
if ($rental_count_id) {
$where_condition_array['rental_count_id'] = $rental_count_id;
}
//print_r($where_condition_array);die();
$id = $this->PD_Model->updateRecords($fields, PDFORMDETAILSJSON, $where_condition_array);
//print_r($this->db->last_query());
if ($id) {
$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);
}
// }
// else
// {
// $data['dataStatus'] = false;
// $data['status'] = REST_Controller::HTTP_NOT_FOUND;
// $data['msg'] = 'Wrong Call...!';
// $this->response($data,REST_Controller::HTTP_OK);
// }
}
public function getNextRentalCount_get()
{
$pdid = $this->get('pdid');
$nxt_rental_count_id = $this->PD_Model->selectCustomRecords(array('max(rental_count_id) as nxt_rental_count'), array('fk_pd_id' => $pdid, 'fk_form_id' => 17), PDFORMDETAILSJSON);
if (is_array($nxt_rental_count_id) && count($nxt_rental_count_id)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = ($nxt_rental_count_id[0]['nxt_rental_count'] + 1);
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = 1;
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function putSalCheck_post()
{
$records = $this->post('records');
$id = null;
if ($records['id']) {
$id = $this->PD_Model->updateRecords($records, XTRA_CHECK, array('id' => $records['id']));
} else {
$id = $this->PD_Model->saveRecords($records, XTRA_CHECK);
}
if ($id) {
$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 renewSatellite_post()
{
$records = $this->post('records');
$id = $this->PD_Model->updateRecords(array('start_location' => $records['geo_location'], 'fk_updatedby' => $records['fk_updatedby']), PDTRIGGER, array('pd_id' => $records['pd_id']));
if ($id) {
$is_gen = satellite_image::getSatelliteImage($records['pd_id'], 1, true);
if ($is_gen) {
$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);
}
} 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);
}
}
//CUstomer Link for Tele PD to upload photos
public function uploadPDPhotosByApplicant_post()
{
$records = $this->post('records');
$img_array = array();
$current_doc_title = null;
$pd_master_details = $this->PD_Model->getPDMasterDetails($records['fk_pd_id']);
// for business related images
$company_id = null;
if ($records['image_key'] == 'selfie_with_person_met' || $records['image_key'] == 'person_met_id') {
//get main applicant name
$main_applicant_name = $this->PD_Model->selectCustomRecords(array('fk_pd_id', 'applicant_name', 'pd_co_applicant_id','facemark_image_generated'), array('fk_pd_id' => $records['fk_pd_id'], 'applicant_type' => 1), PDAPPLICANTSDETAILS);
//print_r($main_applicant_name);
if ($records['image_key'] == 'selfie_with_person_met') {
$img_array['img_type'] = 1;
$img_array['co_applicant_id'] = $main_applicant_name[0]['pd_co_applicant_id'];
$img_array['image'] = $records['image'];
$img_array['Name'] = $main_applicant_name[0]['applicant_name'];
$current_doc_title = $main_applicant_name[0]['applicant_name'];
if ($pd_master_details[0]['fk_pd_type'] == 2 || $pd_master_details[0]['fk_pd_type'] == 4) // if smard pd and fi pd
{
$this->PD_Model->updateRecords(array('start_location' => $records['link']), PDTRIGGER, array('pd_id' => $records['fk_pd_id']));
satellite_image::getSatelliteImage($records['fk_pd_id']);
}
} else if ($records['image_key'] == 'person_met_id') {
$img_array['img_type'] = 2;
$img_array['co_applicant_id'] = $main_applicant_name[0]['pd_co_applicant_id'];
$img_array['image'] = $records['image'];
$img_array['Name'] = $main_applicant_name[0]['applicant_name'] . '-id_proof';
$current_doc_title = $main_applicant_name[0]['applicant_name'] . '-id_proof';
}
} else if (strpos($records['image_key'], 'approach') !== false) {
$img_array['image'] = $records['image'];
$img_array['Name'] = $records['name'];
$img_array['is_show_report'] = 1;
$current_doc_title = $records['image_key'];
} else if (strpos($records['image_key'], 'name_board_seen') !== false) {
$img_array['image'] = $records['image'];
$img_array['Name'] = $records['name'];
$current_doc_title = $records['image_key'];
//update geo location to pd master table
if ($pd_master_details[0]['fk_pd_type'] == 3) //tele pd
{
$this->PD_Model->updateRecords(array('start_location' => $records['link']), PDTRIGGER, array('pd_id' => $records['fk_pd_id']));
satellite_image::getSatelliteImage($records['fk_pd_id']);
}
} else if (strpos($records['image_key'], 'common_image') !== false) {
$img_array['image'] = $records['image'];
$img_array['Name'] = $records['name'];
$current_doc_title = $records['image_key'];
} else if (strpos($records['image_key'], 'stock_image') !== false) {
$img_array['image'] = $records['image'];
$img_array['Name'] = $records['image_key'];
$current_doc_title = $records['image_key'];
$company_id = 1;
} else if (strpos($records['image_key'], 'docs_to_be_collected') !== false) {
$img_array['image'] = $records['image'];
$img_array['Name'] = $records['name'];
$current_doc_title = $records['name'];
} else {
$img_array['image'] = $records['image'];
$img_array['Name'] = $records['image_key'];
$current_doc_title = $records['image_key'];
}
$img_array['pd_image_alias_name'] = $records['pd_image_alias_name'];
$img_array['image_key'] = $records['image_key'];
$img_array['link'] = isset($records['link']) ? $records['link'] : null;
//set company id for business related forms
$business_forms = array(1, 2, 13, 14, 11, 16, 21, 22, 23);
if (in_array($records['fk_form_id'], $business_forms)) {
$company_id = 1;
}
// echo $company_id;die();
//de activate previous one
if (!$records['is_multiple'] || isset($records['pd_document_id'])) {
$where_condition_array = array('fk_pd_id' => $records['fk_pd_id'], 'fk_form_id' => $records['fk_form_id'], 'pd_document_title' => $current_doc_title);
if (isset($records['pd_document_id']) && isset($records['retake_flag']) && $records['retake_flag']) {
$where_condition_array = array('pd_document_id' => $records['pd_document_id']);
unset($records['pd_document_id']);
unset($records['retake_flag']);
$to_update = array('isactive' => 0, 'retake_flag' => 0);
} else if (isset($records['pd_document_id']) && $records['pd_document_id'] != null && $records['pd_document_id'] != "" && $records['image'] == "") {
$where_condition_array = array('pd_document_id' => $records['pd_document_id']);
$to_update = array("pd_image_alias_name" => $records['pd_image_alias_name']);
} else {
$to_update = array('isactive' => 0, 'retake_flag' => 0);
}
if(($records['image_key'] == 'selfie_with_person_met' || $records['image_key'] == 'person_met_id') && $main_applicant_name[0]['facemark_image_generated'] == 1){
// 'face_api_result_image_'$main_applicant_name[0]['pd_co_applicant_id'];
// $where_condition_array[];
$this->db->WHERE('pd_co_applicant_id', $main_applicant_name[0]['pd_co_applicant_id'])->UPDATE(PDAPPLICANTSDETAILS, array('facemark_image_generated' => 0 ,'facecrop'=>null));
}
$res = $this->PD_Model->updateRecords($to_update, PDDOCUMENTS, $where_condition_array);
}
if ($records['image'] != "") {
$res = $this->saveBase64Images($records['fk_pd_id'], ($records['fk_form_id'] ? $records['fk_form_id'] : null), $company_id, $rental_count_id = null, array($img_array));
}
if ($res) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $res;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = "Something Went Wrong! Try Later";
$this->response($data, REST_Controller::HTTP_OK);
}
}
//Applicant Link Check and Get Image Details
public function getPDImgDetails_post()
{
// echo "\n Parent function entry";
$random_string = $this->post('random_string');
$pd_id = $this->post('pd_id');
$where_condition_array = array('random_string' => $random_string);
if ($pd_id) {
$where_condition_array['pd_id'] = $pd_id;
}
//Get PD ID by Random String
$pd_id = $this->PD_Model->selectCustomRecords(array('pd_id', 'is_cus_link_valid', 'cus_link_count', 'is_cus_link_disabled'), $where_condition_array, PDTRIGGER);
if (count($pd_id) && count($pd_id) == 1) {
//check and update link meta data
if ($pd_id[0]['is_cus_link_valid']) {
//$this->updateLinkMetaData($pd_id[0]['pd_id'],$pd_id[0]['cus_link_count'],$random_string);
//get img Data// echo "\n i have PDID IF cond.";
$this->getPDImgData($pd_id[0]['pd_id'], $random_string, $pd_id[0]['is_cus_link_disabled']);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Link Expired';
$this->response($data, REST_Controller::HTTP_OK);
}
} else if (count($pd_id) > 1 || !count($pd_id)) {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Invalid Link';
$this->response($data, REST_Controller::HTTP_OK);
}
}
//update link meta data
public function updateLinkMetaData($pd_id, $link_count, $random_string)
{
//echo 'updateLinkMetaData';
$this->load->library('user_agent');
$agent = 'DEFAULT';
if ($this->agent->is_browser()) {
$agent = $this->agent->browser() . ' ' . $this->agent->version();
} elseif ($this->agent->is_robot()) {
$agent = $this->agent->robot();
} elseif ($this->agent->is_mobile()) {
$agent = $this->agent->mobile();
} else {
$agent = 'Unidentified User Agent';
}
//echo $agent;echo $this->input->ip_address();echo $this->agent->platform();
//$this->PD_Model->saveRecords(array('fk_pd_id' => $pd_id,'browser' => $agent,'ip_address' => $this->input->ip_address(),'platform' => $this->agent->platform()),CUS_LINK_META_DATA);
//update link access count in PD trigger table
//$this->PD_Model->updateRecords(array('cus_link_count' =>($link_count + 1) ),PDTRIGGER,array('pd_id' => $pd_id,'random_string' => $random_string));
}
public function getPDImgData($pd_id, $random_string, $is_cus_link_disabled)
{
// echo "\n i am at child Fns";
$this->existing_imges = $this->PD_Model->getSignedPDDocsURL($pd_id, null, null, null, null, 'customer_app');
// echo "\n external images".count($this->existing_imges);
$docs_to_be_collected = $this->PD_Model->selectCustomRecords(array('*'), array('fk_pd_id' => $pd_id), PDDOCSTOBECOLLECTED);
// echo "\n Collected Docs".count($docs_to_be_collected);
$pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id);
if ($pd_master_details[0]['customer_segment_abbr'] == 'SAL') {
$this->photo_names['attendance_seen_pic'] = array('Attendance Img', '13');
}
// print_r($this->existing_imges);die();
// print_r($this->photo_names);die();
$final_data = array();
$common_images = array();
if (count($this->existing_imges)) {
foreach ($this->photo_names as $key => $value) {
$temp = $this->photoMapping($key, $value);
if (is_array($temp) && count($temp)) {
//echo count($temp);
// if($temp['is_multiple'])
// {
// if(!array_key_exists($temp['img_key'], $final_data))
// {
// $temp['img_data'][] = array('img_url' => $temp['img_url']);
// unset($temp['img_url']);
// $final_data[$temp['img_key']] = $temp;
// }
// else
// {
// $final_data[$temp['img_key']]['img_data'] = array('img_url' => $temp['img_url']);
// }
// }
// else
// {
// $final_data[] = $temp;
// }
// if($temp['is_multiple'])
// {
// $temp = array_values($temp);
// }
$final_data[] = $temp;
} else {
$temp_array = array('img_key' => $key, 'img_name' => $value[0], 'fk_form_id' => $value[1],"is_multiple" => $value[2], 'pd_image_alias_name' => "", 'is_name_editable' => $value[3],'content_type'=>($key =='Video' ? "2" : "1"));
$temp_array[($value[2] ? 'img_data' : 'img_url')] = ($value[2] ? array() : '' );
$final_data[] = $temp_array;
}
}
// print_r($final_data);
// echo "\n FInal Data".count($final_data);
foreach ($this->existing_imges as $key => $value) {
// print_r($this->existing_imges);
// echo "I have CT \n".$value['content_type'];
if (!$value['fk_form_id'] && ($value['pd_document_title'] != 'satellite')) {
// echo "I have CT if cond \n".$value['content_type'];
$final_data[] = array('img_key' => 'common_image', 'img_name' => $value['pd_document_title'], 'img_url' => $value['doc_url'], 'fk_form_id' => null, 'pd_document_id' => $value['pd_document_id'], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $value['is_name_editable']);
unset($this->existing_imges[$key]);
} elseif ($value['pd_document_title'] != 'satellite' && ($value['fk_form_id'] == 24 || $value['fk_form_id'] == 34)) {
// echo "I have CT ifelse cond \n".$value['content_type'];
// doc to be collected img check add it to final data
if (is_array($docs_to_be_collected) && count($docs_to_be_collected)) {
//print_r(count($this->existing_imges));
$is_listed = false;
foreach ($docs_to_be_collected as $dc_key => $dc_value) {
// echo 'before if check - '.$dc_value['doc_name'].'#'.$value['pd_document_title'].'****';
if ($dc_value['doc_name'] == $value['pd_document_title']) {
$is_listed = true;
unset($docs_to_be_collected[$dc_key]);
unset($this->existing_imges[$key]);
//echo 'inside if check - '.$dc_value['doc_name'].'#'.$value['pd_document_title'].'****';
}
}
if ($is_listed) {
$final_data[] = array('img_key' => 'docs_to_be_collected', 'img_name' => $value['pd_document_title'], 'img_url' => $value['doc_url'], 'fk_form_id' => 24, 'is_multiple' => 0, 'pd_document_id' => $value['pd_document_id'], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $value['is_name_editable']);
//break;
}
}
}
// else if($value['image_key'] == 'video'){
// $final_data[] = array('img_key' => $value['image_key'], 'img_name' => $value['pd_document_title'], 'img_url' => $value['doc_url'], 'fk_form_id' => $value['fk_form_id'], 'pd_document_id' => $value['pd_document_id'], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $value['is_name_editable']);
// }
}
//print_r(($this->existing_imges));die();
//add remaining docs_to_be_collected into final array
if (is_array($docs_to_be_collected) && count($docs_to_be_collected)) {
foreach ($docs_to_be_collected as $key => $value) {
$final_data[] = array('img_key' => 'docs_to_be_collected', 'img_name' => $value['doc_name'], 'img_url' => "", 'fk_form_id' => "24", 'pd_document_id' => $value['pd_document_id'], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $value['is_name_editable']);
}
}
} else {
foreach ($this->photo_names as $key => $value) {
$final_data[] = array('img_key' => $key, 'img_name' => $value[0], 'img_url' => "", 'fk_form_id' => $value[1], "is_multiple" => $value[2], 'pd_image_alias_name' => "", 'is_name_editable' => $value[3]);
}
if (is_array($docs_to_be_collected) && count($docs_to_be_collected)) {
foreach ($docs_to_be_collected as $key => $value) {
$final_data[] = array('img_key' => 'docs_to_be_collected', 'img_name' => $value['doc_name'], 'img_url' => "", 'fk_form_id' => "24", "is_multiple" => 0, 'pd_image_alias_name' => "", 'is_name_editable' => 0);
}
}
}
//print_r($final_data);die();
//$final_data[] = array('imag_data' => $common_images,'is_multiple' => 1);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = array('pd_id' => $pd_id, 'random_string' => $random_string, 'is_cus_link_disabled' => $is_cus_link_disabled, 'img_data' => $final_data);
$this->response($data, REST_Controller::HTTP_OK);
}
function photoMapping($current_img_key, $current_img)
{
///echo $img_key;die();
//;die();
$multiple_img_data = array();
$current_multiple_img_key = null;
// print_r($this->existing_imges);
foreach ($this->existing_imges as $key => $value) {
//print_r($value);die();
// echo $current_img_key.'***'.$value['pd_document_title'];
// echo '
';
// echo '
';
// print_r(count($this->existing_imges));
// echo $value['pd_document_title'];
if ($current_img_key == 'selfie_with_person_met' && $value['img_type'] == 1) {
// echo "SELFIE";
$arr = array('img_key' => 'selfie_with_person_met', 'img_name' => $this->photo_names['selfie_with_person_met'][0], 'fk_form_id' => $this->photo_names['selfie_with_person_met'][1], 'img_url' => $value['doc_url'], 'is_multiple' => 0, 'pd_document_id' => $value['pd_document_id'], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $this->photo_names['selfie_with_person_met'][3],'content_type'=> $value['content_type']);
unset($this->existing_imges[$key]);
return $arr;
} else if ($current_img_key == 'person_met_id' && $value['img_type'] == 2) {
//echo 'HOLD';
$arr = array('img_key' => 'person_met_id', 'img_name' => $this->photo_names['person_met_id'][0], 'img_url' => $value['doc_url'], 'fk_form_id' => $this->photo_names['person_met_id'][1], 'is_multiple' => 0, 'pd_document_id' => $value['pd_document_id'], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $this->photo_names['person_met_id'][3],'content_type'=> $value['content_type']);
unset($this->existing_imges[$key]);
return $arr;
// unset($this->photo_names['selfie_with_person_met']);
// return $arr;
} else if ($current_img_key == 'approach_to_pd_location' && strpos($value['pd_document_title'], 'Approach') !== false) {
//echo "APPROACH";
$arr = array('img_key' => 'approach_to_pd_location', 'img_name' => $this->photo_names['approach_to_pd_location'][0], 'img_url' => $value['doc_url'], 'fk_form_id' => $this->photo_names['approach_to_pd_location'][1], 'is_multiple' => 0, 'pd_document_id' => $value['pd_document_id'], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $this->photo_names['person_met_id'][3],'content_type'=> $value['content_type']);
unset($this->existing_imges[$key]);
return $arr;
// unset($this->photo_names['selfie_with_person_met']);
// return $arr;
} else if ($current_img_key == 'name_board_seen' && strpos($value['pd_document_title'], 'Name Board Seen') !== false) {
//echo "APPROACH";
$arr = array('img_key' => 'name_board_seen', 'img_name' => $this->photo_names['name_board_seen'][0], 'img_url' => $value['doc_url'], 'fk_form_id' => $this->photo_names['name_board_seen'][1], 'is_multiple' => 0, 'pd_document_id' => $value['pd_document_id'], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $this->photo_names['name_board_seen'][3],'content_type'=> $value['content_type']);
unset($this->existing_imges[$key]);
return $arr;
// unset($this->photo_names['selfie_with_person_met']);
// return $arr;
} else if ($current_img_key == 'Video') {
if ($current_img[2]) {
// echo "\n in if".$current_img_key;
// echo '\n before '.$current_multiple_img_key;
$current_multiple_img_key = $current_img_key;
if (!array_key_exists($current_img_key, $multiple_img_data)) {
$multiple_img_data[$current_img_key] = array('img_key' => $value['image_key'], 'img_name' => "Videos", 'img_data' => array(array('img_url' => $value['doc_url'], 'img_name' => $value['pd_document_title'], 'pd_document_id' => $value['pd_document_id'], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $value['is_name_editable'],'fk_form_id' => $this->photo_names[$current_img_key][1])), 'form_id' => $value['fk_form_id'], 'is_multiple' => $current_img[2], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $this->photo_names[$current_img_key][3],'content_type'=> $value['content_type']);
} else {
$multiple_img_data[$current_img_key]['img_data'][] = array('img_url' => $value['doc_url'], 'img_name' => $value['pd_document_title'], 'pd_document_id' => $value['pd_document_id'], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $value['is_name_editable'],'form_id' => $value['fk_form_id']);
}
} else {
$arr = array('img_key' => $value['pd_document_title'], 'img_name' => $value['pd_document_title'], 'img_url' => $value['doc_url'], 'fk_form_id' => $this->photo_names[$value['pd_document_title']][1], 'is_multiple' => $current_img[2], 'pd_document_id' => $value['pd_document_id'], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $value['is_name_editable'],'content_type'=> $value['content_type']);
return $arr;
}
unset($this->existing_imges[$key]);
}
else if (strpos($current_img_key, $value['pd_document_title']) !== false) {
//unset($this->existing_imges[$key]);
//echo "OTHER";
if ($current_img[2]) {
$current_multiple_img_key = $current_img_key;
if (!array_key_exists($current_img_key, $multiple_img_data)) {
$multiple_img_data[$current_img_key] = array('img_key' => $value['pd_document_title'], 'img_name' => $this->photo_names[$value['pd_document_title']][0], 'img_data' => array(array('img_url' => $value['doc_url'], 'img_name' => $value['pd_document_title'], 'pd_document_id' => $value['pd_document_id'], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $value['is_name_editable'])), 'fk_form_id' => $this->photo_names[$value['pd_document_title']][1], 'is_multiple' => $current_img[2], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $this->photo_names[$value['pd_document_title']][3],'content_type'=> $value['content_type']);
} else {
$multiple_img_data['VIDEO']['img_data'][] = array('img_url' => $value['doc_url'], 'img_name' => $value['pd_document_title'], 'pd_document_id' => $value['pd_document_id'], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $value['is_name_editable'],'content_type'=> $value['content_type']);
}
} else {
$arr = array('img_key' => $value['pd_document_title'], 'img_name' => $value['pd_document_title'], 'img_url' => $value['doc_url'], 'content_type'=> $value['content_type'],'fk_form_id' => $this->photo_names[$value['pd_document_title']][1], 'is_multiple' => $current_img[2], 'pd_document_id' => $value['pd_document_id'], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $value['is_name_editable'],'content_type'=> $value['content_type']);
return $arr;
}
unset($this->existing_imges[$key]);
// unset($this->photo_names['selfie_with_person_met']);
// return $arr;
}
// else
// {
// //unset($this->existing_imges[$key]);
// echo "ELSE";
// return array('img_key' =>$current_img_key,'img_name' => $current_img_key,'img_url' => '','fk_form_id' => $current_img[1]);
// }
}
return $current_multiple_img_key ? $multiple_img_data[$current_multiple_img_key] : $multiple_img_data;
//return $multiple_img_data;
}
function sendCusLinkViaSMS_post()
{
$mobile_no = $this->post('mobile_no');
$random_string = $this->post('random_string');
$pd_id = $this->post('pd_id');
$response = false;
$sms_flag = $this->post('sms_flag');
$msg = "Dear Applicant, Please click the link to upload the photographs. " . CUSTOMER_IMG_URL . $random_string;
if ($sms_flag == 2) //recapture
{
$msg .= "/recapture";
}
//SALESPD_CUSTOMER_IMG_URL
$res = SMS_GUPSHUP::sendSMS($msg, $mobile_no, array('pd_id' => $pd_id, 'status' => 'STARTED', 'msg' => 'Cus Link from PD controlller'), true);
//print_r($res);
$res = explode('|', $res);
if (is_array($res) && count($res)) {
if (trim($res[0]) == "success") {
$response = true;
}
}
if ($response) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = 'SMS Sent Successfully';
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'SMS Sent Falied. Try Later!';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function saveCusVideo_post()
{
$records = json_decode($this->post('records'), true);
$id = null;
//log_message('ERROR','hi');
// print_r($records);
// print_r($_FILES);
// die();
$pd_category = $records['pd_category'] ? $records['pd_category'] : "1";
$lender_id = $records['pd_category'] == "1" ? $pd_master_details[0]['fk_lender_id'] : $pd_master_details[0]['lender_id'];
$file_folder = $records['pd_category'] == "2" ? "sales_pd" : "pd_reports";
if (!empty($_FILES['video_file'])) {
if ($pd_category == '2') {
$pd_master_details = $this->PD_Model->selectCustomRecords(array('sales_pd_id as pd_id', 'lender_id as fk_lender_id', 'product_id', 'sales_pd_type', 'isactive', 'rand_string as random_string', 'pd_branch_id'), array('sales_pd_id' => $pd_id, 'rand_string' => $random_string), SALES_PD_DATA);
}
if ($pd_category == '1') {
$pd_master_details = $this->PD_Model->getPDMasterDetails($records['pd_id']);
}
$bucketname = LENDER_BUCKET_NAME_PREFIX . $pd_master_details[0]['fk_lender_id'];
$key = 'pd' . $records['pd_id'] . '/video/' . $records['filename'];
$file_name_wo_extension = explode('.', ($records['filename']))[0];
$file_type = explode('/', ($_FILES['video_file']['type']))[1];
$folder_to_check = XLPATH . '/' . $file_folder . '/' . $records['pd_id'] . '/videos';
//echo $folder_to_check;//die();
if (!file_exists($folder_to_check)) {
mkdir(XLPATH . '/' . $file_folder . '/' . $records['pd_id'], 0777);
mkdir($folder_to_check, 0777);
}
//die();
$config = array('upload_path' => $folder_to_check, 'overwrite' => TRUE, 'allowed_types' => '*', 'file_name' => $file_name_wo_extension . '.' . $file_type);
$this->load->library('upload', $config);
if ($this->upload->do_upload('video_file')) {
$upload_data = $this->upload->data();
//$this->load->view('upload_success',$data);
//print_r($upload_data);
$command_to_execute = FFMPEG_PATH . ' -i ' . $folder_to_check . '/' . $file_name_wo_extension . '.' . $file_type . ' ' . $folder_to_check . '/' . $file_name_wo_extension . '.mp4' . ' 2>&1';
//print_r($command_to_execute);die();
exec($command_to_execute, $o, $v);
// print_r($o);
// echo $command_to_execute;die();
if ($o) {
$sourcefile = $folder_to_check . '/' . $file_name_wo_extension . '.mp4';
$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) {
log_message('ERROR', '###PDVIDEO stored in S3' . $records['pd_id']);
$record_data = array('fk_pd_id' => $records['pd_id'], 'video_part_name' => $records['filename'], 'video_key' => $records['video_key'], 'pd_category' => $pd_category);
$id = $this->PD_Model->saveRecords($record_data, CUS_VIDEO);
unlink($folder_to_check . '/' . $file_name_wo_extension . '.webm');
unlink($folder_to_check . '/' . $file_name_wo_extension . '.mp4');
}
// if it is last part of a video call, then call video merge functionality
if (isset($records['is_call_ended']) && $records['is_call_ended'] == 1) {
$final_video_name = $records['pd_id'] . '-' . $records['video_key'];
sleep(10);
$this->mergeVideo($records['pd_id'], $pd_master_details, $final_video_name, $records['video_key'], $pd_category);
}
if ($id != null || $id != "") {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = 'Video Saved Successfully';
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Something Wrong. Try Later!';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Something Wrong. Try Later!';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Something Wrong. Try Later!';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'No Image found to upload';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function saveShortsVideo_post()
{
log_message('ERROR', "saveShortsVideo FNS called");
$records = json_decode($this->post('records'), true);
$file_folder = "pd_reports";
if (!empty($_FILES['video_file'])) {
$form_id = $records['form_id'];
$pd_id = $records['pd_id'];
$pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id);
if(isset($records['filename']) && $records['filename'] !=""){
$file_exsiting = $this->db->SELECT('count(*) as count')->FROM(PDDOCUMENTS . ' as PDDOCUMENTS')->WHERE('PDDOCUMENTS.fk_pd_id', $pd_id)->WHERE('PDDOCUMENTS.pd_document_name',$records['filename'])->WHERE('PDDOCUMENTS.isactive', 1)->GET()->result_array();
//File Name Already Available
if((int)$file_exsiting[0]['count'] > 0){
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'File name already exists';
$this->response($data, REST_Controller::HTTP_OK);
}
$temp_file_name = $records['filename'];
}else{
//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-i-s') . '.mp4';
}
log_message('ERROR', "filename = ".$temp_file_name);
$lender_id = $pd_master_details[0]['fk_lender_id'];
$bucketname = LENDER_BUCKET_NAME_PREFIX . $lender_id;
$key = 'pd' . $records['pd_id'] . '/video/' . $temp_file_name;
log_message('ERROR', "bucket key = ".$bucketname);
$file_name_wo_extension = explode('.', ($temp_file_name))[0];
log_message('ERROR', "file_name_extension = ".$file_name_wo_extension);
$file_type = explode('/', ($_FILES['video_file']['type']))[1];
log_message('ERROR', "file_type ".$file_type);
$folder_to_check = XLPATH . '/' . $file_folder . '/' . $records['pd_id'] . '/videos';
// echo $folder_to_check;//die();
if (!file_exists($folder_to_check)) {
mkdir(XLPATH . '/' . $file_folder . '/' . $records['pd_id'], 0777);
mkdir($folder_to_check, 0777);
}
$config = array('upload_path' => $folder_to_check, 'overwrite' => TRUE, 'allowed_types' => '*', 'file_name' => $file_name_wo_extension . '.' . $file_type);
$this->load->library('upload', $config);
if ($this->upload->do_upload('video_file')) {
$sourcefile = $folder_to_check . '/' . $file_name_wo_extension . '.mp4';
$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) {
$uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname, $key, $time = '+1 week');
log_message('ERROR', '###PD SHORTS VIDEO stored in S3 uri = ' . $uri);
$doc_count = $this->db->SELECT('count(*) as count')->FROM(PDDOCUMENTS . ' as PDDOCUMENTS')->WHERE('PDDOCUMENTS.fk_pd_id', $pd_id)->WHERE('PDDOCUMENTS.content_type',2)->WHERE('PDDOCUMENTS.isactive', 1)->GET()->result_array();
$pd_document_title = 'Videos '.((int)$doc_count[0]['count']+1);
$record_data = array('fk_pd_id' => $pd_id, 'pd_document_title' => $pd_document_title, 'pd_document_name' => $temp_file_name, 'fk_form_id' => $form_id, 'is_show_report' => 1, 'rental_count_id' => null, 'location' => null, 'co_applicant_id' => null, 'img_type' => null, 'image_key' => "video", "pd_image_alias_name" => null,"content_type"=>2);
$record_data['company_id'] = null;
$id = $this->PD_Model->saveRecords($record_data, PDDOCUMENTS);
if(file_exists($folder_to_check . '/' . $file_name_wo_extension . '.webm')){unlink($folder_to_check . '/' . $file_name_wo_extension . '.webm');}
if(file_exists($folder_to_check . '/' . $file_name_wo_extension . '.mp4')){unlink($folder_to_check . '/' . $file_name_wo_extension . '.mp4');}
if ($id != null || $id != "") {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = 'Video Saved Successfully';
$data['records'] = array('id'=>$id,'uri'=>$uri);
$this->response($data, REST_Controller::HTTP_OK);
}
else{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Something Wrong. Try Later!';
$this->response($data, REST_Controller::HTTP_OK);
}
}else{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Something Wrong. Try Later!';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Something Wrong. Try Later!';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'No Video found to upload';
$this->response($data, REST_Controller::HTTP_OK);
}
}
//merge all splitted videos
public function getVideoURL_post()
{
$pd_id = $this->post('pd_id');
$random_string = $this->post('random_string');
$pd_category = $this->post('pd_category') ? $this->post('pd_category') : "1";
$this->load->helper('video_grabber_helper');
if ($pd_category == '1') { //normal Credit PD;
$pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id, $random_string);
}
if ($pd_category == '2') { //Sales PD;
$pd_master_details = $this->PD_Model->selectCustomRecords(array('sales_pd_id as pd_id', 'lender_id as fk_lender_id', 'product_id', 'sales_pd_type', 'isactive', 'rand_string as random_string', 'pd_branch_id'), array('sales_pd_id' => $pd_id, 'rand_string' => $random_string), SALES_PD_DATA);
}
$result_data = (new video_grabber_helper)->grabAllVideo($pd_master_details[0]['pd_id'], $pd_master_details[0]['random_string'], $pd_master_details, $pd_category);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result_data;
$this->response($data, REST_Controller::HTTP_OK);
}
// To Inactive Video Recorded.
public function deleteVideo_get()
{
$id = $this->get('id');
// $id = (int) $id;
// if(!empty($id)){
// // $multipleWhere['fk_pd_id'] = $multipleWhere['pd_id'];
// // unset($multipleWhere['pd_id']);
$this->load->helper('video_grabber_helper');
$result_data = (new video_grabber_helper)->deleteVideo($id);
// }else{
// $result_data = "ID Not Available. Unable to Delete";
// }
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = $result_data;
$this->response($data, REST_Controller::HTTP_OK);
}
function updateTwlioVideoStatus_post()
{
$pd_id = $this->post('pd_id');
$random_string = $this->post('random_string');
$room_id = $this->post('room_id');
$pd_category = $this->post('pd_category') ? $this->post('pd_category') : "1";
$result_data = $this->getTwiloVideoStatus($pd_id, $random_string, $room_id, $pd_category);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result_data;
$this->response($data, REST_Controller::HTTP_OK);
}
function getTwiloVideoStatus($pd_id, $random_string, $room_id = '', $pd_category)
{
$this->load->library('twlio');
$result_data = 0;
// $query = "SELECT * FROM ".VIDEO_ROOM_INFO." where fk_pd_id = $pd_id and twilo_status = 'enqueued' and composition_id is not null;";
if ($pd_category == "1") {
$pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id, $random_string);
} else {
$pd_master_details = $this->PD_Model->selectCustomRecords(array('sales_pd_id as pd_id', 'lender_id as fk_lender_id', 'product_id', 'sales_pd_type', 'isactive', 'rand_string as random_string', 'pd_branch_id'), array('sales_pd_id' => $pd_id, 'rand_string' => $random_string), SALES_PD_DATA);
}
$query = "SELECT * FROM " . VIDEO_ROOM_INFO . " where fk_pd_id = $pd_id and isactive = 1 and is_uploaded = 0 and pd_category = $pd_category"; // and twilo_status = 'enqueued' and composition_id is not null;";
if ($room_id) {
$query .= " and room_id = '$room_id'";
}
$video_info = $this->db->query($query);
if ($video_info->num_rows()) {
$video_info = $video_info->result_array();
foreach ($video_info as $key => $value) {
if ($value['composition_id'] && $value['vsp'] != 'google') {
$res = $this->twlio->getCompositionStatus($value['composition_id']);
if (count($res) && $res['status'] == 'completed') {
$is_copied = $this->copyMediaFromTwiloToS3($pd_master_details, $value, $pd_category); // copy media from twlio s3 to our s3
$fields_to_update = array('twilo_status' => 'completed');
if ($is_copied) {
$fields_to_update['s3_copied'] = 1;
}
$id = $this->PD_Model->updateRecords($fields_to_update, VIDEO_ROOM_INFO, array('video_room_info_id' => $value['video_room_info_id']));
if ($id) {
if ($room_id) {
$result_data = $is_copied;
} else {
$result_data++;
}
}
}
} else {
$room_status = $this->twlio->getRoomDataByRoomID($value['room_id']);
if ($room_status == 'completed') {
$composition_result_data = $this->twlio->startComposistion($value['room_id']);
// $composition_result_data = $this->twlio->startComposistion('RM23b8d502434e46e696d1fbd5d64c59c8');
// print_r($composition_result_data);
$composition_result_data_json = json_encode($composition_result_data);
// print_r($composition_result_data_json);
$records['res_json'] = $composition_result_data_json;
$records['twilo_status'] = $composition_result_data['status'];
$records['composition_id'] = $composition_result_data['compositionId'];
$records['is_call_ended'] = 1;
$where_condition_array = array('fk_pd_id' => $pd_id);
if ($value['room_id']) {
$where_condition_array['room_id'] = $value['room_id'];
}
$id = $this->PD_Model->updateRecords($records, VIDEO_ROOM_INFO, $where_condition_array);
}
}
}
}
return $result_data;
}
function copyMediaFromTwiloToS3($pd_master_details, $value, $pd_catgory) // copy media from twlio s3 to our s3
{
EXTERNAL_DIR_CHECK::checkExternalDirectory($pd_master_details[0]['pd_id']);
//get media uri from twlio
$singed_uri = $this->twlio->compositionVideoFile($value['composition_id']);
//echo $singed_uri;
$file_folder = $pd_catgory == "2" ? "sales_pd" : "pd_reports";
$lender_id = $pd_master_details[0]['fk_lender_id'];
$internal_server_tmp_location = XLPATH . '/' . $file_folder . '/' . $pd_master_details[0]['pd_id'] . '/videos';
if ($pd_catgory == "2") {
EXTERNAL_DIR_CHECK::checkExternalDirectory($pd_master_details[0]['pd_id'], $internal_server_tmp_location);
}
$internal_server_tmp_location_filename = ($internal_server_tmp_location . '/' . $value['composition_id'] . '.mp4');
if (!file_exists($internal_server_tmp_location)) {
mkdir($internal_server_tmp_location, 0777);
};
$is_writed = file_put_contents($internal_server_tmp_location_filename, file_get_contents($singed_uri));
//upload it to aws s3
$bucket_name = LENDER_BUCKET_NAME_PREFIX . $lender_id;
$final_key = 'pd' . $pd_master_details[0]['pd_id'] . '/video/' . $value['composition_id'] . '.mp4';
$bucket_data = array('bucket_name' => $bucket_name, 'key' => $final_key, 'sourcefile' => ($internal_server_tmp_location_filename));
$s3result = $this->aws_s3->uploadFileToS3Bucket($bucket_data);
if (is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) {
log_message('ERROR', '###TWLIO TO S3 STARTED' . $value['composition_id']);
unlink($internal_server_tmp_location_filename);
return $temp_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name, $final_key, '+7 days');
//unlink($folder_to_check.'/'.$final_video_name.'.mp4');
}
return null;
}
function mergeVideo($pd_id, $pd_master_details, $final_video_name, $video_key, $pd_category)
{
$pd_category = $pd_category ? $pd_category : "1";
$file_folder = $pd_category == "2" ? "sales_pd" : "pd_reports";
// $pd_id = $this->post('pd_id');
// $random_string = $this->post('random_string');
//$final_video_name = $pd_id.'-'.$random_string;
//echo $final_video_name;die();
//Get PD master DEtails
//$pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id,$random_string);
//$is_video_merged = $this->PD_Model->selectCustomRecords(array('*'),array('fk_pd_id' => $pd_id,'video_part_name' => $final_video_name),CUS_VIDEO);
//prit_r($pd_master_details);die();
// if(count($pd_master_details) && isset($pd_master_details[0]['pd_id']))
// {
$bucket_name = LENDER_BUCKET_NAME_PREFIX . $pd_master_details[0]['fk_lender_id'];
$final_key = 'pd' . $pd_master_details[0]['pd_id'] . '/video/' . $final_video_name . '.mp4';
//Get all video info
$qu = "SELECT *,convert(substr(substring_index(video_part_name,'-',1),6),UNSIGNED INTEGER) as sno FROM sineedgedemo.t_cus_video
where fk_pd_id = $pd_id and video_key = '$video_key' and is_active = 1 order by sno";
$video_info = $this->db->query($qu)->result_array();
$folder_to_check = XLPATH . '/' . $file_folder . '/' . $pd_id . '/videos';
$file_list = $folder_to_check . '/filelist.txt';
//Get All video and temp store it in xlpath
$file_pointer = fopen($file_list, 'w+');
$all_input_files_names_with_path = '';
foreach ($video_info as $video_info_key => $video_info_value) {
$key = 'pd' . $pd_id . '/video/' . $video_info_value['video_part_name'];
$temp_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name, $key, '+10 minutes');
$file_to_create = $folder_to_check . '/' . $video_info_value['video_part_name'];
$output = file_put_contents($file_to_create, file_get_contents($temp_uri));
if ($output) {
$file_name_wo_extension = explode('.', ($video_info_value['video_part_name']))[0];
//fwrite($file_pointer,"file "."'".$file_name_wo_extension.".mp4"."'\n");
fwrite($file_pointer, "file " . "'" . $file_name_wo_extension . "'\n");
}
}
fclose($file_pointer);
// echo '***************************************';//die();
$merge_cmd = FFMPEG_PATH . ' -f concat -safe 0 -i ' . $folder_to_check . '/' . 'filelist.txt -c copy ' . $folder_to_check . '/' . $final_video_name . '.mp4 2>&1';
//echo '#########################################';
//echo $merge_cmd;//die();
exec($merge_cmd, $ou, $v);
//print_r($ou);//die();
if ($ou && file_exists($folder_to_check . '/' . $final_video_name . '.mp4')) {
//echo 'upload to s3';
$bucket_data = array('bucket_name' => $bucket_name, 'key' => $final_key, 'sourcefile' => ($folder_to_check . '/' . $final_video_name . '.mp4'));
$s3result = $this->aws_s3->uploadFileToS3Bucket($bucket_data);
if (is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) {
log_message('ERROR', '###PDVIDEO merged video stored in S3' . $pd_id);
$record_data = array('is_video_merged' => 1);
$id = $this->PD_Model->updateRecords($record_data, PDTRIGGER, array('pd_id' => $pd_id));
unlink($folder_to_check . '/' . $final_video_name . '.mp4');
}
foreach ($video_info as $video_info_key => $video_info_value) {
$file_name_wo_extension = explode('.', ($video_info_value['video_part_name']))[0];
//unlink($folder_to_check.'/'.$file_name_wo_extension.'.ts');
unlink($folder_to_check . '/' . $file_name_wo_extension);
}
// $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$final_key,'+3 hrs');
// $data['dataStatus'] = true;
// $data['status'] = REST_Controller::HTTP_OK;
// $data['url'] = $singed_uri;
// $this->response($data,REST_Controller::HTTP_OK);
} else {
log_message('ERROR', '###PDVIDEO merged video not stored in S3' . $pd_id);
}
}
//make duplicate of a exist pd
public function duplicatePD_post()
{
$pdid = $this->post('pd_id');
$lender_applicant_id = $this->post('lender_applicant_id');
$fk_createdby = $this->post('fk_createdby');
$new_pd_id = null;
$address_id = null;
$applicants_ids_array = array();
$docs_to_be_uploads_ids_array = array();
$add_req_ids_array = array();
$form_ids_to_replace_new_co_applicants_id = array(18, 4, 6, 7, 8, 9, 10, 13, 17, 19, 21, 22);
$logger = MYLOG::logFunction(null, $pdid);
$logger->info("duplicatePD_post called: " . $pdid, array('ENV' => ENVIRONMENT, 'DATA' => $lender_applicant_id));
// Get All PD Masters Details
log_message('ERROR', '####duplicatePD_post called:-' . $pdid . '-' . $lender_applicant_id);
$pd_fields = array('fk_lender_id', 'sub_entity_id', 'imgc_fin_institute', 'fk_entity_billing_id', 'fk_product_id', 'fk_subproduct_id', 'fk_pd_type', 'fk_pd_template_id', 'fk_customer_segment', 'loan_amount', 'addressline1', 'fk_city', 'fk_state', 'pincode', 'lender_sales_person', 'lender_credit_person', 'pd_contact_person', 'pd_contact_mobileno', 'pd_contact_person_mail', 'pd_branch_id', 'pd_contact_landline', 'other_pincode', 'is_notify_enabled');
$pd_master_details = $this->PD_Model->selectCustomRecords($pd_fields, array('pd_id' => $pdid), PDTRIGGER);
if (count($pd_master_details)) {
$pd_master_details = $pd_master_details[0];
$pd_master_details['lender_applicant_id'] = $lender_applicant_id;
$pd_master_details['pd_date_of_initiation'] = date('Y-m-d H-i-s');
//$pd_master_details['pd_date_of_initiation'] = '2020-07-07 12:24:00';
$pd_master_details['createdon'] = date('Y-m-d H-i-s');
$pd_master_details['pd_status'] = 'TRIGGERED';
$pd_master_details['fk_createdby'] = $fk_createdby;
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomIter = rand(0, 15);
for ($i = 0; $i < 16; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
if ($i == $randomIter) {
$randomString .= 'cc';
}
}
$pd_master_details['random_string'] = $randomString;
$url = OFFICER_TRACKING_URL . $randomString;
$pd_master_details['encrypted_url'] = $url;
//print_r($pd_master_details);
$new_pd_id = $this->PD_Model->saveRecords($pd_master_details, PDTRIGGER);
log_message('ERROR', '####NEW PD Trigged by dup funciton:-' . $new_pd_id);
}
//Get All Applicant's Details
$applicants_details = $this->PD_Model->selectCustomRecords(array('pd_co_applicant_id', 'applicant_name', 'applicant_type', 'mobile_no', 'relation', 'company_name', 'applicant_title_name', 'landline'), array('fk_pd_id' => $pdid), PDAPPLICANTSDETAILS);
//print_r($applicants_details);
if ($new_pd_id && count($applicants_details)) {
log_message('ERROR', '####Copying Applicants started:-' . $new_pd_id);
foreach ($applicants_details as $key => $value) {
$current_applicant_id = $value['pd_co_applicant_id'];
unset($value['pd_co_applicant_id']);
$value['fk_pd_id'] = $new_pd_id;
$new_applicant_id = $this->PD_Model->saveRecords($value, PDAPPLICANTSDETAILS);
//$new_applicant_id = $current_applicant_id + 10;
$applicants_ids_array[$current_applicant_id] = $new_applicant_id;
//print_r($value);
}
log_message('ERROR', '####Copying Applicants end:-' . $new_pd_id);
}
//Get All PD Related Documents
// $pd_documnets = $this->PD_Model->selectCustomRecords(array('fk_pd_id','fk_form_id', 'co_applicant_id', 'img_type', 'pd_document_title', 'pd_document_name','company_id', 'is_show_report', 'rental_count_id','location', 'isactive'),array('isactive' => 1,'fk_pd_type' => $pdid),PDDOCUMENTS);
// if(!$new_pd_id && count($applicants_details))
// {
// log_message('ERROR','####Copying ALl Images started:-'.$new_pd_id);
// foreach ($pd_documnets as $key => $value)
// {
// $value['fk_pd_id'] = $new_pd_id;
// $this->PD_Model->saveRecords($value,PDDOCUMENTS);
// //print_r($value);
// }
// log_message('ERROR','####Copying All Images END:-'.$new_pd_id);
// // log_message('ERROR','####Copying S3 started:-'.$new_pd_id);
// // log_message('ERROR','####Copying S3 END:-'.$new_pd_id);
// }
//Get All PD Address
$pd_address = $this->PD_Model->selectCustomRecords(array('addressline1', 'fk_city', 'fk_state', 'pincode', 'isactive', 'is_visited', 'other_pincode', 'is_primary'), array('isactive' => 1, 'fk_pd_id' => $pdid), PDADDRESS);
if ($new_pd_id && count($pd_address)) {
log_message('ERROR', '####Copying address started:-' . $new_pd_id);
foreach ($pd_address as $key => $value) {
$value['fk_pd_id'] = $new_pd_id;
$value['assigned_pd'] = $new_pd_id;
$address_id = $this->PD_Model->saveRecords($value, PDADDRESS);
//print_r($value);
}
log_message('ERROR', '####Copying address end:-' . $new_pd_id);
}
//Get Addtional Requirements details
$pd_additional_requirements = $this->PD_Model->selectCustomRecords(array('add_req_id', 'add_requirement', 'isactive'), array('isactive' => 1, 'fk_pd_id' => $pdid), PDADDTIONALREQUIREMENTS);
if ($new_pd_id && count($pd_additional_requirements)) {
log_message('ERROR', '####Copying Additional Req started:-' . $new_pd_id);
foreach ($pd_additional_requirements as $key => $value) {
$current_add_req_id = $value['add_req_id'];
unset($value['add_req_id']);
$value['fk_pd_id'] = $new_pd_id;
$new_add_req_id = $this->PD_Model->saveRecords($value, PDADDTIONALREQUIREMENTS);
//print_r($value);
//$new_add_req_id = $current_add_req_id + 100;
$add_req_ids_array[$current_add_req_id] = $new_add_req_id;
}
log_message('ERROR', '####Copying Addtional Req end:-' . $new_pd_id);
}
//Get Docs to be collected array
$docs_to_be_collected = $this->PD_Model->selectCustomRecords(array('pd_doc_to_be_collect_id', 'doc_name'), array('isactive' => 1, 'fk_pd_id' => $pdid), PDDOCSTOBECOLLECTED);
if ($new_pd_id && count($docs_to_be_collected)) {
log_message('ERROR', '####Copying Docs to be collected started:-' . $new_pd_id);
foreach ($docs_to_be_collected as $key => $value) {
$current_doc_id = $value['pd_doc_to_be_collect_id'];
unset($value['pd_doc_to_be_collect_id']);
$value['fk_pd_id'] = $new_pd_id;
$new_doc_id = $this->PD_Model->saveRecords($value, PDDOCSTOBECOLLECTED);
//print_r($value);
//$new_doc_id = $current_doc_id + 100;
$docs_to_be_uploads_ids_array[$current_doc_id] = $new_doc_id;
}
log_message('ERROR', '####Copying Docs to be collected end:-' . $new_pd_id);
}
//Get all JSON
$json_data = $this->PD_Model->getAllJSONFormData($pdid);
if ($new_pd_id && count($json_data)) {
log_message('ERROR', '####Copying All JSON Data started:-' . $new_pd_id);
foreach ($json_data as $key => $value) {
$value['fk_pd_id'] = $new_pd_id;
if (in_array($value['fk_form_id'], $form_ids_to_replace_new_co_applicants_id)) {
$current_form_string = ($value['json']);
foreach ($applicants_ids_array as $old_value => $new_value) {
$current_form_string = str_replace($old_value, $new_value, $current_form_string);
}
//replace pd id
$current_form_string = str_replace($pdid, $new_pd_id, $current_form_string);
$value['json'] = $current_form_string;
}
if ($value['fk_form_id'] == 24) //credit managers query form
{
$current_form_string = ($value['json']);
//print_r($gen_form_string);
//
foreach ($docs_to_be_uploads_ids_array as $old_value => $new_value) {
$current_form_string = str_replace($old_value, $new_value, $current_form_string);
}
foreach ($add_req_ids_array as $old_value => $new_value) {
$current_form_string = str_replace($old_value, $new_value, $current_form_string);
}
$current_form_string = str_replace($pdid, $new_pd_id, $current_form_string);
$value['json'] = $current_form_string;
}
//replace old img string from gen & busi forms
if ($value['fk_form_id'] == 18 || $value['fk_form_id'] == 13 || $value['fk_form_id'] == 24) {
//print_r($value);
$value = $this->emptyImgStringsInsideJSON($value);
//print_r($value);
}
//die();
$this->PD_Model->saveRecords($value, PDFORMDETAILSJSON);
}
log_message('ERROR', '####Copying ALL JSON END:-' . $new_pd_id);
}
// die();
//copy Assessed Income Tables
if ($pd_master_details['fk_customer_segment'] == 4 && $new_pd_id) //AI
{
$this->dupAssessedIncomeInfo($pdid, $new_pd_id, $fk_createdby);
}
//copy all s3 into new pd folder
if ($new_pd_id) {
//update some master info
$this->PD_Model->updateRecords(array('parent_pd_id' => $new_pd_id, 'fk_primary_address_id' => $address_id, 'fk_address_id' => $address_id, 'dupof' => $pdid), PDTRIGGER, array('pd_id' => $new_pd_id));
log_message('ERROR', '####UPDATE PD:-' . $new_pd_id);
$logger->info("NEW PD Trigged by dup funciton : " . $new_pd_id, array('ENV' => ENVIRONMENT));
PDALERTS::pdnotification($new_pd_id);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $new_pd_id;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Something Went Wrong! Try Later';
$this->response($data, REST_Controller::HTTP_OK);
}
}
function emptyImgStringsInsideJSON($value)
{
if ($value['fk_form_id'] == 18) {
$temp_json = (json_decode($value['json'], true));
if (isset($temp_json['individuals']) && count($temp_json['individuals'])) {
foreach ($temp_json['individuals'] as $tj_key => $tj_value) {
if ($tj_value['is_applicant'] == 1) {
$temp_json['individuals'][$tj_key]['is_person_met_pic'] = '';
$temp_json['individuals'][$tj_key]['is_person_met_id_proof'] = '';
}
}
}
$value['json'] = json_encode($temp_json);
}
if ($value['fk_form_id'] == 24) {
$temp_json = (json_decode($value['json'], true));
//print_r($temp_json);//die();
if (isset($temp_json['docs_to_be_sighted']) && count($temp_json['docs_to_be_sighted'])) {
foreach ($temp_json['docs_to_be_sighted'] as $dskey => $ds_value) {
if (isset($ds_value['img'])) {
$temp_json['docs_to_be_sighted'][$dskey]['img'] = '';
}
}
}
//print_r($temp_json);
$value['json'] = json_encode($temp_json);
}
if ($value['fk_form_id'] == 13) {
$temp_json = (json_decode($value['json'], true));
if (isset($temp_json['shop_eat_act_cert_pic'])) {
$temp_json['shop_eat_act_cert_pic'] = "";
}
if (isset($temp_json['practice_cert_pic'])) {
$temp_json['practice_cert_pic'] = "";
}
if (isset($temp_json['gst_Regn_cert_pic'])) {
$temp_json['gst_Regn_cert_pic'] = '';
}
if (isset($temp_json['pf_regn_pic'])) {
$temp_json['pf_regn_pic'] = '';
}
if (isset($temp_json['esic_regn_pic'])) {
$temp_json['esic_regn_pic'] = '';
}
if (isset($temp_json['export_import_cert_pic'])) {
$temp_json['export_import_cert_pic'] = '';
}
if (isset($temp_json['factory_cert_pic'])) {
$temp_json['factory_cert_pic'] = '';
}
if (isset($temp_json['practice_cert_pic'])) {
$temp_json['practice_cert_pic'] = '';
}
if (isset($temp_json['fire_noc_pic'])) {
$temp_json['fire_noc_pic'] = '';
}
if (isset($temp_json['eb_bill_pic'])) {
$temp_json['eb_bill_pic'] = '';
}
if (isset($temp_json['documents']) && count($temp_json['documents'])) {
$temp_iter = $temp_json['documents'];
foreach ($temp_iter as $tikey => $itvalue) {
$temp_json['documents'][$tikey]['document_pic'] = '';
}
}
$value['json'] = json_encode($temp_json);
}
return $value;
//die();
}
function dupAssessedIncomeInfo($pdid, $new_pd_id, $fk_createdby)
{
//$new_pd_id = 9999;
//echo $pdid.'/'.$new_pd_id;//die();
$grossprofittype = $this->PD_Model->selectCustomRecords(array('mode', 'margin', 'company_id', 'purchase_type'), array('fk_pd_id' => $pdid), PDASSESSEDINCOMEESTIMATIONOFGROSSPROFITTYPE);
if (count($grossprofittype)) {
$grossprofittype = $grossprofittype[0];
$grossprofittype['fk_createdby'] = $fk_createdby;
$grossprofittype['fk_pd_id'] = $new_pd_id;
//print_r($grossprofittype);
$this->PD_Model->saveRecords($grossprofittype, PDASSESSEDINCOMEESTIMATIONOFGROSSPROFITTYPE);
}
$purchasedeclaredbycustomer = $this->PD_Model->selectCustomRecords(array('purchase_declared_by_customer', 'comments', 'company_id'), array('fk_pd_id' => $pdid, 'isactive' => 1), PURCHASEDECLAREDBYCUSTOMER);
if (count($purchasedeclaredbycustomer)) {
$purchasedeclaredbycustomer = $purchasedeclaredbycustomer[0];
$purchasedeclaredbycustomer['fk_pd_id'] = $new_pd_id;
$purchasedeclaredbycustomer['fk_createdby'] = $fk_createdby;
$this->PD_Model->saveRecords($purchasedeclaredbycustomer, PURCHASEDECLAREDBYCUSTOMER);
//print_r($purchasedeclaredbycustomer);
}
$salesdeclaredbycustomer = $this->PD_Model->selectCustomRecords(array('sales_declared_by_customer', 'margin_per', 'company_id', 'margin_value', 'comments'), array('fk_pd_id' => $pdid, 'isactive' => 1), SALESDECLAREDBYCUSTOMER);
if (count($salesdeclaredbycustomer)) {
$salesdeclaredbycustomer = $salesdeclaredbycustomer[0];
$salesdeclaredbycustomer['fk_pd_id'] = $new_pd_id;
$salesdeclaredbycustomer['fk_createdby'] = $fk_createdby;
$this->PD_Model->saveRecords($salesdeclaredbycustomer, SALESDECLAREDBYCUSTOMER);
//print_r($salesdeclaredbycustomer);
}
// $salesdeclaredbycustomer = $this->PD_Model->selectCustomRecords(array('sales_declared_by_customer', 'margin_per','company_id','margin_value','comments'),array('fk_pd_id' => $pdid,'isactive' => 1),SALESDECLAREDBYCUSTOMER);
// if(count($salesdeclaredbycustomer))
// {
// $salesdeclaredbycustomer = $salesdeclaredbycustomer[0];
// $salesdeclaredbycustomer['fk_pd_id'] = $new_pd_id;
// $salesdeclaredbycustomer['fk_createdby'] = $fk_createdby;
// $this->PD_Model->saveRecords($salesdeclaredbycustomer,SALESDECLAREDBYCUSTOMER);
// //print_r($salesdeclaredbycustomer);
// }
$pdhouseholdexpenses = $this->PD_Model->selectCustomRecords(array('expense_item', 'expense_value', 'fk_frequency_id', 'annual_expense_value', 'comments', 'company_id'), array('fk_pd_id' => $pdid, 'isactive' => 1), PDHOUSEHOLDEXPENSES);
if (count($pdhouseholdexpenses)) {
foreach ($pdhouseholdexpenses as $key => $value) {
$value['fk_pd_id'] = $new_pd_id;
$value['fk_createdby'] = $fk_createdby;
$this->PD_Model->saveRecords($value, PDHOUSEHOLDEXPENSES);
//print_r($value);
}
}
$pdbusinessexpenses = $this->PD_Model->selectCustomRecords(array('expense_item_id', 'expense_value', 'fk_frequency_id', 'annual_expenses_value', 'comments', 'company_id', 'other_expense_item'), array('fk_pd_id' => $pdid, 'isactive' => 1), PDBUSINESSEXPENSES);
if (count($pdbusinessexpenses)) {
foreach ($pdbusinessexpenses as $key => $value) {
$value['fk_pd_id'] = $new_pd_id;
$value['fk_createdby'] = $fk_createdby;
$this->PD_Model->saveRecords($value, PDBUSINESSEXPENSES);
//print_r($value);
}
}
//sales itemwise
$salescalculatedbyitemwise = $this->PD_Model->selectCustomRecords(array('sci_id', 'sales_item', 'sales_qty', 'fk_uom_id', 'rate_per_unit', 'fk_frequency_id', 'annual_sale_value', 'margin_per', 'margin_per_uom', 'margin_final_value', 'company_id', 'uom_other', 'comments', 'sales_type', 'other_sales_item'), array('fk_pd_id' => $pdid, 'isactive' => 1), SALESCALCULATEDBYITEMWISE);
if (count($salescalculatedbyitemwise)) {
foreach ($salescalculatedbyitemwise as $salescalculatedbyitemwise_key => $salescalculatedbyitemwise_value) {
$pre_sci_id = $salescalculatedbyitemwise_value['sci_id'];
unset($salescalculatedbyitemwise_value['sci_id']);
$salescalculatedbyitemwise_value['fk_pd_id'] = $new_pd_id;
$salescalculatedbyitemwise_value['fk_createdby'] = $fk_createdby;
$new_sci_id = $this->PD_Model->saveRecords($salescalculatedbyitemwise_value, SALESCALCULATEDBYITEMWISE);
//get child values if any
if ($salescalculatedbyitemwise_value['sales_type'] == 3) {
$salesitemmonthwisechild = $this->PD_Model->selectCustomRecords(array('sales_date', 'sales_value', 'fk_frequency_id', 'frequency_value'), array('fk_sci_id' => $pre_sci_id, 'isactive' => 1), SALESITEMMONTHWISECHILD);
if (count($salesitemmonthwisechild)) {
foreach ($salesitemmonthwisechild as $child_key => $child_value) {
$child_value['fk_sci_id'] = $new_sci_id;
$this->PD_Model->saveRecords($child_value, SALESITEMMONTHWISECHILD);
}
}
}
}
}
//purchase details
$pdpurchasedetails = $this->PD_Model->selectCustomRecords(array('purchase_id', 'purchase_item', 'purchase_qty', 'fk_uom_id', 'rate_per_unit', 'fk_frequency_id', 'annual_purchase_value', 'company_id', 'uom_other', 'comments', 'purchase_type', 'other_purchase_item'), array('fk_pd_id' => $pdid, 'isactive' => 1), PDPURCHASEDETAILS);
if (count($pdpurchasedetails)) {
foreach ($pdpurchasedetails as $pdpurchasedetails_key => $pdpurchasedetails_value) {
$pre_purchase_id = $pdpurchasedetails_value['purchase_id'];
unset($pdpurchasedetails_value['purchase_id']);
$pdpurchasedetails_value['fk_pd_id'] = $new_pd_id;
$pdpurchasedetails_value['fk_createdby'] = $fk_createdby;
$new_purchase_id = $this->PD_Model->saveRecords($pdpurchasedetails_value, PDPURCHASEDETAILS);
//get child values if any
if ($pdpurchasedetails_value['purchase_type'] == 3) {
$pdpurchasebillwisechild = $this->PD_Model->selectCustomRecords(array('purchase_date', 'purchase_value'), array('fk_purchase_id' => $pre_purchase_id, 'isactive' => 1), PDPURCHASEBILLWISECHILD);
if (count($pdpurchasebillwisechild)) {
foreach ($pdpurchasebillwisechild as $child_key => $child_value) {
$child_value['fk_purchase_id'] = $new_purchase_id;
$this->PD_Model->saveRecords($child_value, PDPURCHASEBILLWISECHILD);
}
}
}
}
}
}
public function saveApplicantImgFromVendorForm_post()
{
//print_r($this->post());
$pd_id = $this->post('fk_pd_id');
$uri = null;
EXTERNAL_DIR_CHECK::checkExternalDirectory($pd_id);
$temp_base64_string = $this->post('is_person_met_pic') !== null ? $this->post('is_person_met_pic') : $this->post('is_person_met_id_proof');
$title = $this->post('is_person_met_pic') !== null ? trim($this->post('applicant_name')) : (trim($this->post('applicant_name')) . '-id_proof');
//$external_path = $this->config->item('external_data_path');
$co_applicant_id = $this->post('pd_co_applicant_id');
$img_type = $this->post('is_person_met_pic') !== null ? 1 : 2;
$output_file = $this->external_path . "/pd_reports/" . $pd_id . "/temp_base64_image.jpeg";
//echo $img_type;die();
//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-i-s') . '.jpeg';
log_message('ERROR', '###PDIMAGE writing started' . $pd_id . ' - ' . '13');
$ifp = fopen($output_file, 'wb');
$temp_data = explode(',', $temp_base64_string);
fwrite($ifp, base64_decode($temp_data[1]));
fclose($ifp);
log_message('ERROR', '###PDIMAGE writing done' . $pd_id . ' - ' . '13');
$pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id);
$bucketname = LENDER_BUCKET_NAME_PREFIX . $pd_master_details[0]['fk_lender_id'];
$key = 'pd' . $pd_id . '/' . $temp_file_name;
$bucket_data = array('bucket_name' => $bucketname, 'key' => $key, 'sourcefile' => $output_file);
// die();
$s3result = $this->aws_s3->uploadFileToS3Bucket($bucket_data);
if (is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) {
log_message('ERROR', '###PDIMAGE stored in S3' . $pd_id . ' - ' . '18');
$record_data = array('fk_pd_id' => $pd_id, 'pd_document_title' => $title, 'fk_form_id' => 18, 'co_applicant_id' => $co_applicant_id, 'img_type' => $img_type);
//de activate older one
$this->PD_Model->updateRecords(array('isactive' => 0), PDDOCUMENTS, $record_data);
$record_data['pd_document_name'] = $temp_file_name;
$id = $this->PD_Model->saveRecords($record_data, PDDOCUMENTS);
$uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname, $key, $time = '+1 week');
if ($id) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $id;
$data['uri'] = $uri;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Something Went Wrong! Try Later';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Something Went Wrong! Try Later';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function updateVendorStatus_post()
{
$records = $this->post('records');
$exist_pd_details = $this->PD_Model->getPDMasterDetails($records['pd_id']);
//print_r($exist_pd_details);die();
//print_r($records);
$fields_to_update = array('vendor_status' => $records['vendor_status'], 'fk_updatedby' => $records['fk_updatedby']);
if (isset($records['vendor_pdofficer'])) {
$fields_to_update['vendor_pdofficer'] = $records['vendor_pdofficer'];
}
// if(isset($records['vendor_status']) && $records['vendor_status'] == STARTED)
// {
// $fields_to_update['start_location'] = $records['link'];
// }
if (isset($records['vendor_status']) && ($records['vendor_status'] == BOUNCED)) {
unset($records['bounce_reason']);
unset($records['bounce_reason_others']);
}
if (isset($records['vendor_status']) && ($records['vendor_status'] == SCHEDULED)) {
$fields_to_update['vendor_scheduled_on'] = $records['vendor_scheduled_on'];
}
if (isset($records['vendor_status']) && ($records['vendor_status'] == COMPLETED || $records['vendor_status'] == QC_COMPLETED)) {
//echo 'sanskl';
$smc_lender_id = ENVIRONMENT == 'production' ? 7 : 35; //SMC lender id MWISE in live and demo
$current_lender_id = $exist_pd_details[0]['fk_lender_id'];
$agency_id = $exist_pd_details[0]['pd_agency_id'];
// IF Condition - using PDID get the lender and mapped with SMC_lender_id macthed means Vendor status dynamically assigned
// is_smc_vendor(true/false) - here this api called both smart pd(vendor) and SMC(vendor) also but we using this key only for SMC(vendor module).
if ($smc_lender_id == $current_lender_id && isset($agency_id) && $agency_id != null && $records['is_smc_vendor'] == true) {
if (isset($records['vendor_status']) && ($records['vendor_status'] == QC_COMPLETED)) {
$fields_to_update['pd_status'] = COMPLETED; //Here vendor_status is (QC_COMPLETED) means i have to update the Normal Status as COMPLETED.
$this->load->helper('smc_creditpd');
if(isset($records['random_string'])){
$random_string = $records['random_string'];
}else{
$random_string = $this->PD_Model->selectCustomRecords(array('random_string'),array('pd_id' => $records['pd_id']),PDTRIGGER);
$random_string = $random_string[0]['random_string'];}
$ZIP = smc_creditpd::covertSMCImgs2ZIP($records['pd_id'],$random_string,array(),0);
log_message('ERROR','####COMPLETE SMC IMAGE ZIP = '.$ZIP);
$PDF = smc_creditpd::covertSMCImgs2PDF($records['pd_id'],$random_string,array(),0);
log_message('ERROR','####COMPLETE SMC IMAGE PDF = '.$PDF);
}
// else{ $fields_to_update['vendor_status'] = $records['pd_status']; }
}
if (!isset($records['complete_override_data']) && isset($records['is_smc_vendor']) && $records['is_smc_vendor'] == false) {
$vendor_form = $this->PD_Model->selectCustomRecords(
array('json'),
array('isactive' => 1, 'fk_form_id' => 25, 'fk_pd_id' => $records['pd_id']),
PDFORMDETAILSJSON
);
if (count($vendor_form)) {
//echo 'sanskl';
$vendor_form = json_decode($vendor_form[0]['json'], true);
if (isset($vendor_form['is_form_validated']) && !$vendor_form['is_form_validated']) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$data['enable_complete'] = true;
$data['msg'] = 'Form Saved as Draft! Please Fill and submit the form';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
$data['msg'] = 'Form Not filled !';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$fields_to_update['complete_override_data'] = $exist_pd_details[0]['complete_override_data'] . '[Vendor Complete Check Overrided]';
}
// print_r($vendor_form);
if ($records['vendor_status'] == COMPLETED) {
$fields_to_update['pd_visit_date'] = date('Y-m-d H:i:s');
}
}
// die();
// print_r($fields_to_update);die();
$id = $this->PD_Model->updateRecords($fields_to_update, PDTRIGGER, array('pd_id' => $records['pd_id']));
if ($id) {
// if(isset($records['vendor_status']) && $records['vendor_status'] == STARTED)
// {
// satellite_image::getSatelliteImage($records['fk_pd_id']);
// }
$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_FOUND;
$data['msg'] = 'Something Went Wrong! Try Later';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function getVendorAnswers_post()
{
//print_r($this->post());
$fk_pd_id = $this->post('fk_pd_id');
$fk_form_id = $this->post('fk_form_id');
$pd_master_details = $this->PD_Model->getPDMasterDetails($fk_pd_id);
if (($pd_master_details[0]['is_qc_enabled'] && $pd_master_details[0]['vendor_status'] == QC_COMPLETED) || (!$pd_master_details[0]['is_qc_enabled'] && $pd_master_details[0]['vendor_status'] == COMPLETED)) {
$vendor_pd_form = $this->PD_Model->selectCustomRecords(array('*'), array('fk_pd_id' => $fk_pd_id, 'fk_form_id' => 25, 'isactive' => 1), PDFORMDETAILSJSON);
if (count($vendor_pd_form)) {
$business_forms = array(1, 2, 13, 14, 11, 16, 21, 22, 23);
$vendor_pd_form = json_decode($vendor_pd_form[0]['json'], true);
$is_business_form = in_array($fk_form_id, $business_forms);
//print_r($vendor_pd_form['questions']);die();
foreach ($vendor_pd_form['questions'] as $key => $value) {
if ($is_business_form && is_string($value['form_id']) && !strcasecmp($value['form_id'], 'BUSINESS_GROUP')) {
//echo 'busienss';break;
//print_r($value);die();
foreach ($value['business_group'] as $bkey => $bvalue) {
if ($bvalue['form_id'] == $fk_form_id) {
//echo 'nor';break;
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $bvalue;
$this->response($data, REST_Controller::HTTP_OK);
}
}
} else if ($value['form_id'] == $fk_form_id) {
//echo 'nor';break;
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $value;
$this->response($data, REST_Controller::HTTP_OK);
}
}
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Vendor Form Not Found!';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
if (($pd_master_details[0]['is_qc_enabled'] && $pd_master_details[0]['vendor_status'] != QC_COMPLETED)) {
$data['msg'] = 'Vendor yet to QC Complete the PD';
} else if ((!$pd_master_details[0]['is_qc_enabled'] && $pd_master_details[0]['vendor_status'] != COMPLETED)) {
$data['msg'] = 'Vendor yet to Complete the PD';
}
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function loadCreditPDTemplate_post()
{
$where_condition_array = array('isactive' => 1);
if ($this->post('fk_entity_id')) {
$where_condition_array['fk_entity_id'] = $this->post('fk_entity_id');
} else {
$where_condition_array['fk_entity_id'] = NULL;
}
if ($this->post('fk_product_id')) {
$where_condition_array['fk_product_id'] = $this->post('fk_product_id');
} else {
$where_condition_array['fk_product_id'] = NULL;
}
if ($this->post('pd_form_id')) {
$where_condition_array['pd_form_id'] = $this->post('pd_form_id');
}
$fk_pd_id = $this->post('fk_pd_id');
//print_r($where_condition_array);die();
$pd_master_details = $this->PD_Model->getPDMasterDetails($fk_pd_id);
if ($pd_master_details[0]['customer_segment_abbr'] != 'SAL') {
$template = $this->PD_Model->selectCustomRecords(array('credit_pd_template_id', 'template_name', 'template_desc', 'template', 'fk_entity_id', 'fk_product_id', 'pd_form_id'), $where_condition_array, CREDITPDTEMPLATE);
if (count($template)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $template[0];
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Template Not Found!';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Template Not Found!';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function auditSmartPDImages_post()
{
$docs = ($this->post());
//print_r($docs);die();
$result_array = array();
$is_api_processed = false;
$total_affected_rows = null;
$where_condition_array = array();
if (count($docs)) {
foreach ($docs as $key => $value) {
if (isset($value['pd_document_id']) && is_numeric($value['pd_document_id'])) {
$where_condition_array[] = $value['pd_document_id'];
}
}
$ids = $this->db->WHERE_IN('pd_document_id', $where_condition_array)->UPDATE(PDDOCUMENTS, array('retake_flag' => 1));
$total_affected_rows = $this->db->affected_rows();
$is_api_processed = $total_affected_rows == count($docs) ? true : false;
//print_r($this->db->last_query());
}
//echo count($docs);echo($total_affected_rows);echo ($is_api_processed);
if ($ids) // && $is_api_processed)
{
//$this->PD_Model->updateRecords(array('is_cus_link_disabled' => 0),PDTRIGGER,array());
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $total_affected_rows;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Something Went Wrong! Try Later!';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function getAuditedImages_post()
{
$random_string = $this->post('random_string');
$pd_id = $this->post('pd_id');
$result_array = array();
$where_condition_array = array('random_string' => $random_string);
if ($pd_id) {
$where_condition_array['pd_id'] = $pd_id;
}
//Get PD ID by Random String
$pd_id = $this->PD_Model->selectCustomRecords(array('pd_id', 'fk_lender_id', 'is_cus_link_valid', 'cus_link_count', 'is_cus_link_disabled'), $where_condition_array, PDTRIGGER);
if (count($pd_id) && count($pd_id) == 1) {
//check and update link meta data
// echo $pd_id[0]['is_cus_link_valid'];echo $pd_id[0]['is_cus_link_disabled'];
// if($pd_id[0]['is_cus_link_valid'] && !$pd_id[0]['is_cus_link_disabled'])
// {
$where_condition_array = array('fk_pd_id' => $pd_id[0]['pd_id'], 'retake_flag' => 1);
$document_lists = $this->db->SELECT('*')->FROM(PDDOCUMENTS)->WHERE($where_condition_array)->get()->result_array();
// print_r($this->db->last_query());
$bucket_name = LENDER_BUCKET_NAME_PREFIX . $pd_id[0]['fk_lender_id'];
foreach ($document_lists as $key => $value) {
$profilepics3path = 'pd' . $pd_id[0]['pd_id'] . '/' . $value['pd_document_name'];
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name, $profilepics3path, '+5 minutes');
//$document_lists[$key]['doc_url'] = $singed_uri;
#######################################################################################################################
if ($value['img_type'] == 1) {
//echo "SELFIE";
$arr = array('img_key' => 'selfie_with_person_met', 'img_name' => $this->photo_names['selfie_with_person_met'][0], 'fk_form_id' => $this->photo_names['selfie_with_person_met'][1], 'img_url' => $singed_uri, 'is_multiple' => 0, 'pd_document_id' => $value['pd_document_id']);
// unset($this->existing_imges[$key]);
$result_array[] = $arr;
// return $arr;
} else if ($value['img_type'] == 2) {
//echo 'HOLD';
$arr = array('img_key' => 'person_met_id', 'img_name' => $this->photo_names['person_met_id'][0], 'img_url' => $singed_uri, 'fk_form_id' => $this->photo_names['person_met_id'][1], 'is_multiple' => 0, 'pd_document_id' => $value['pd_document_id']);
$result_array[] = $arr;
} else if (strpos($value['pd_document_title'], 'Approach') !== false) {
//echo "APPROACH";
$arr = array('img_key' => 'approach_to_pd_location', 'img_name' => $this->photo_names['approach_to_pd_location'][0], 'img_url' => $singed_uri, 'fk_form_id' => $this->photo_names['approach_to_pd_location'][1], 'is_multiple' => 0, 'pd_document_id' => $value['pd_document_id']);
$result_array[] = $arr;
} else if (strpos($value['pd_document_title'], 'Name Board Seen') !== false) {
//echo "APPROACH";
$arr = array('img_key' => 'name_board_seen', 'img_name' => $this->photo_names['name_board_seen'][0], 'img_url' => $singed_uri, 'fk_form_id' => $this->photo_names['name_board_seen'][1], 'is_multiple' => 0, 'pd_document_id' => $value['pd_document_id']);
$result_array[] = $arr;
// unset($this->photo_names['selfie_with_person_met']);
// return $arr;
} else {
$img_key = isset($this->photo_names[$value['pd_document_title']]) ? $this->photo_names[$value['pd_document_title']][0] : ($value['fk_form_id'] == 24 ? 'docs_to_be_collected' : 'common_image');
$arr = array('img_key' => $img_key, 'img_name' => $value['pd_document_title'], 'img_url' => $singed_uri, 'fk_form_id' => $value['fk_form_id'], 'is_multiple' => 0, 'pd_document_id' => $value['pd_document_id']);
//if(!$value['fk_form_id']){ $arr }
$result_array[] = $arr;
}
#######################################################################################################################
}
if (count($result_array)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = array('pd_id' => $pd_id[0]['pd_id'], 'img_data' => $result_array, 'is_cus_link_disabled' => $pd_id[0]['is_cus_link_disabled'], 'random_string' => $random_string);
$this->response($data, REST_Controller::HTTP_OK);
}
//}
// else
// {
// $data['dataStatus'] = false;
// $data['status'] = REST_Controller::HTTP_NOT_FOUND;
// $data['msg'] = 'Link Expired';
// $this->response($data,REST_Controller::HTTP_OK);
// }
} else if (count($pd_id) > 1 || !count($pd_id)) {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Invalid Link';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function updateVendorFormStatus_post()
{
//print_r($this->post());
$id = $this->PD_Model->updateRecords(array('form_status' => 1), VENDORFORMSTATUS, array('fk_pd_id' => $this->post('fk_pd_id'), 'fk_form_id' => $this->post('fk_form_id')));
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $id;
$this->response($data, REST_Controller::HTTP_OK);
}
function getBusinessDocsToVendorForm_get()
{
$pd_id = $this->get('pdid');
$business_form = $this->PD_Model->selectCustomRecords(array('json'), array('fk_pd_id' => $pd_id, 'fk_form_id' => 13, 'isactive' => 1, 'company_id' => 1), PDFORMDETAILSJSON);
if (count($business_form)) {
$records = array();
$business_form = json_decode($business_form[0]['json'], true);
//print_r($business_form);
if (isset($business_form['shop_eat_act_cert']) && strtoupper($business_form['shop_eat_act_cert']) == 'YES') {
$records[] = 'shop_eat_act_cert';
}
if (isset($business_form['gst_Regn_cert']) && strtoupper($business_form['gst_Regn_cert']) == 'YES') {
$records[] = 'gst_Regn_cert';
}
if (isset($business_form['pf_regn']) && strtoupper($business_form['pf_regn']) == 'YES') {
$records[] = 'pf_regn';
}
if (isset($business_form['esic_regn']) && strtoupper($business_form['esic_regn']) == 'YES') {
$records[] = 'esic_regn';
}
if (isset($business_form['factory_cert']) && strtoupper($business_form['factory_cert']) == 'YES') {
$records[] = 'factory_cert';
}
if (isset($business_form['export_import_cert']) && strtoupper($business_form['export_import_cert']) == 'YES') {
$records[] = 'export_import_cert';
}
if (isset($business_form['practice_cert']) && strtoupper($business_form['practice_cert']) == 'YES') {
$records[] = 'practice_cert';
}
if (count($records)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $records;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'No Records Found!';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'No Records Found!';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function saveRoomInfo_post()
{
// $this->load->library('twlio');
// $tata = $this->twlio->compositionVideoFile('CJ89555fef0f0e70c18d22cbae1d812daa');
// //print_r($tata);
// die();
$records = $this->post('records');
$id = null;
//print_r($records);
if (!$records['is_call_ended']) // != '' || $records['video_room_info_id'] != null)
{
$id = $this->PD_Model->saveRecords($records, VIDEO_ROOM_INFO);
// print_r($this->db->last_query());
} else {
$this->load->library('twlio');
$composition_result_data = $this->twlio->startComposistion($records['room_id']);
// $composition_result_data = $this->twlio->startComposistion('RM23b8d502434e46e696d1fbd5d64c59c8');
// print_r($composition_result_data);
$composition_result_data_json = json_encode($composition_result_data);
// print_r($composition_result_data_json);
$records['res_json'] = $composition_result_data_json;
$records['twilo_status'] = $composition_result_data['status'];
$records['composition_id'] = $composition_result_data['compositionId'];
$id = $this->PD_Model->updateRecords($records, VIDEO_ROOM_INFO, array('room_id' => $records['room_id'], 'fk_pd_id' => $records['fk_pd_id']));
}
if ($id) {
$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_FOUND;
$data['msg'] = 'Something went wrong!';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function uploadVideoFile_post()
{
$records = json_decode($this->post('records'), true);
$pd_category = $records['pd_category'] ? $records['pd_category'] : "1";
$file_folder = $pd_category == "2" ? "sales_pd" : "pd_reports";
if ($pd_category == '1') { //normal Credit PD;
$pd_master_details = $this->PD_Model->getPDMasterDetails($records['fk_pd_id'], $records['random_string']);
}
if ($pd_category == '2') { //Sales PD;
$pd_master_details = $this->PD_Model->selectCustomRecords(array('sales_pd_id as pd_id', 'lender_id as fk_lender_id', 'product_id', 'sales_pd_type', 'isactive', 'rand_string as random_string', 'pd_branch_id'), array('sales_pd_id' => $records['fk_pd_id'], 'rand_string' => $records['random_string']), SALES_PD_DATA);
}
$bucket_name = LENDER_BUCKET_NAME_PREFIX . $pd_master_details[0]['fk_lender_id'];
// echo XLPATH;
// print_r($records);die();
// print_r($pd_master_details);die();
$is_bucket_upload_sucess = false;
$id = null;
//die();
if (!empty($_FILES['video_file'])) {
$folder_to_check = XLPATH . '/' . $file_folder . '/' . $records['fk_pd_id'] . '/videos';
if (!file_exists($folder_to_check)) {
mkdir($folder_to_check, 0777);
}
// die();
// $modified_fname = $records['rand_key'].'~'.str_replace(' ','_',($_FILES['pd_excel_data']['name']));
$modified_fname = str_replace(' ', '_', ($_FILES['video_file']['name']));
// echo file_exists($folder_to_check);die();
$config = array('upload_path' => $folder_to_check, 'overwrite' => TRUE, 'allowed_types' => '*', 'file_name' => $modified_fname);
$this->load->library('upload', $config);
$this->upload->initialize($config);
try {
if ($this->upload->do_upload('video_file')) {
log_message('ERROR', 'video uplaod done :' . $folder_to_check);
$sourcefile = $folder_to_check . '/' . $modified_fname;
// echo $sourcefile;
$key = 'pd' . $records['fk_pd_id'] . '/video/' . $modified_fname;
$bucket_data = array('bucket_name' => $bucket_name, 'key' => $key, 'sourcefile' => $sourcefile);
// print_r($bucket_data);die();
$s3result = $this->aws_s3->uploadFileToS3Bucket($bucket_data);
//print_r($s3result);die();
if (is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) {
$is_bucket_upload_sucess = 1;
$id = $this->PD_Model->saveRecords(array('fk_pd_id' => $records['fk_pd_id'], 'room_id' => $modified_fname, 'composition_id' => $modified_fname, 'twilo_status' => 'completed', 'is_call_ended' => 1, 's3_copied' => 1, 'is_uploaded' => 1), VIDEO_ROOM_INFO);
unlink($sourcefile);
}
} else {
log_message('ERROR', 'video uplaod failed :' . $folder_to_check);
}
} catch (Exception $e) {
log_message('ERROR', 'video uplaod failed exception:' . $folder_to_check . ' - ' . $e->getMessage());
}
// die();
if ($is_bucket_upload_sucess && $id) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = 'File Uploaded Successfully';
// $data['excel_file_id'] = $id;
// $data['records'] = $result_data;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Something Wrong. Try Later!';
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'No Data File Found!';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function checkAfterResponse_post()
{
$this->myvariable = 10;
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'No Data File Found!';
$this->response($data, REST_Controller::HTTP_OK, true);
// echo 'Hi';
}
public function smcStuffs($pd_details, $existing_pd_details = array())
{
// echo "i am here";
// echo $pd_details['pd_status'];
//if is this MWISE (SMC Credit PD) lender then auto allocate to RCM users and make pd status as allocated
//get RCM user for auto allocation based on pd address
// $pd_details['fk_lender_id'] = 35;
// $addresses[0]['fk_city'] = 3374;
$mwise_lender_id = (ENVIRONMENT == 'production' ? 7 : 35);
$current_lender_id = (isset($pd_details['fk_lender_id']) && $pd_details['fk_lender_id'] != '' ? $pd_details['fk_lender_id'] : $existing_pd_details[0]['fk_lender_id']);
$is_mwise_lender = ($current_lender_id == $mwise_lender_id ? true : false);
// echo !$is_mwise_lender;
// echo "curr".$current_lender_id;die();
if ($is_mwise_lender && (($pd_details['pd_status'] == TRIGGERED) || ($pd_details['pd_status'] == ALLOCATED))) {
$regional_credit_manager = $this->PD_Model->getRCM($pd_details['fk_state']); //pass pd address city as param
$agency_id = $pd_details['pd_agency_id'];
if ((!empty($agency_id)) && ($agency_id != null) && ((int)$agency_id != 0)) {
$pd_details['pd_status'] = ALLOCATED_TO_FIA;
$pd_details['vendor_status'] = ALLOCATED;
$sudhirbaranwal = (ENVIRONMENT == 'production' ? 187 : 324);
if ($pd_details['fk_pd_allocated_to'] != $sudhirbaranwal) {
PDALERTS::sendMWcreditPDMail($this, $pd_details, 3);
}
} else if (count($regional_credit_manager)) {
$pd_details['fk_pd_allocated_to'] = $regional_credit_manager[0]['userid'];
$pd_details['pd_status'] = ALLOCATED;
} else {
log_message('ERROR', ('### Couldnot find RCM users - ' . $pd_details['fk_state']));
}
} else if ($is_mwise_lender && $pd_details['pd_status'] == BOUNCED) {
//find current user role
$this->load->model('User_Management_Model');
$this->load->model('SMC_Credit_PD_Model');
$user_details = $this->User_Management_Model->getUserDetails($pd_details['fk_updatedby']);
if ($user_details['data'][0]['user_role'] == 26) //Credit Manager
{
//get RCM and allocate to RCM
$rcm = $this->SMC_Credit_PD_Model->getSMCFlowUsers($existing_pd_details[0]['fk_state'], 27);
if (count($rcm)) {
$pd_details['fk_pd_allocated_to'] = $rcm[0]['userid'];
} else {
log_message('ERROR', ('### Couldnot find RCM users in BOUNCED status - ' . $existing_pd_details[0]['fk_state']));
}
} else if ($user_details['data'][0]['user_role'] == 27) //Reg Credit Manager
{
// //get CPA and allocate to CPA
// $cpa = $this->SMC_Credit_PD_Model->getSMCFlowUsers($existing_pd_details[0]['fk_city'],25);
// if(count($cpa))
// {
// $pd_details['fk_pd_allocated_to'] = $rcm[0]['userid'];
// }
// else
// {
// log_message('ERROR',('### Couldnot find RCPACM users in BOUNCED status - '.$existing_pd_details[0]['fk_city']));
// }
//now allocated to pd triggered to user
$pd_details['fk_pd_allocated_to'] = $existing_pd_details[0]['fk_createdby'];
}
}
// echo $pd_details['fk_pd_allocated_to'];die();
return $pd_details;
}
function getAdditionalRequirements_get()
{
$pdid = $this->get('pdid');
if (!isset($pdid) && empty($pdid)) {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'PDID Not Found! Try again';
}
$result_data['pd_additional_requirements'] = $this->PD_Model->getPDAdditionalRequirements($pdid);
$result_data['docs_to_be_collected'] = $this->PD_Model->getDocsToBeCollected($pdid);
if (!empty($result_data)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result_data;
} else if (empty($result_data['pd_additional_requirements']) && empty($result_data['docs_to_be_collected'])) {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Data Not Found';
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Something Went Wrong! Try Later';
}
$this->response($data, REST_Controller::HTTP_OK);
}
function saveSMCTempAddress($pd_id, $addresses)
{
$records = array('file_id' => $pd_id, 'addressline' => $addresses[0]['addressline1'], 'city' => $addresses[0]['fk_city'], 'state' => $addresses[0]['fk_state'], 'pincode' => $addresses[0]['pincode']);
$this->PD_Model->saveRecords($records, SMC_TEMP_ADDRESS);
}
function distancematrix_get()
{
$pd_loc = $this->get('loc');
$lender = $this->get('lender');
$entity_loc = $this->PD_Model->getEntityAddr($lender);
$this->response(satellite_image::getdistancematrix($entity_loc, $pd_loc), REST_Controller::HTTP_OK, true);
}
function PDjson_get()
{
$data = $this->PD_Model->testSection($this->get('id'), $this->get('fid'));
$this->response($data, REST_Controller::HTTP_OK);
}
function checkmail_post()
{
$records = $this->post('records');
PDALERTS::sendMWcreditPDMail($this, $records, 1);
PDALERTS::sendMWcreditPDMail($this, $records, 2);
}
function optimizeImages_get()
{
$this->load->helper('MYHTTPCLIENT');
$pd_id = $this->uri->segment(2);
$lender_id = $this->PD_Model->selectCustomRecords(array('fk_lender_id'), array('pd_id' => $pd_id), PDTRIGGER);
$sourceBucket = LENDER_BUCKET_NAME_PREFIX . $lender_id[0]['fk_lender_id'];
//echo $sourceBucket;
$result = MYHTTPCLIENT::startOptimizeImages($sourceBucket, $pd_id);
//print_r($result);die();
// $code = $result->getStatusCode();
// echo $code;
// $body = $result->getBody();
// //$body = $body->getContents();
// print_r($body);die();
if ($result['statusCode'] == 200) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result['body'];
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Something Went Wrong! Try Later';
$this->response($data, REST_Controller::HTTP_OK);
}
//print_r($result);
}
public function downloadSMCExcelFile_get()
{
$pd_id = $this->uri->segment(2);
$pd_master_data = $this->PD_Model->getPDMasterDetails($pd_id);
// print_r($pd_master_details);die();
$bucketname = LENDER_BUCKET_NAME_PREFIX . $pd_master_data[0]['fk_lender_id'];
$key = 'tmp/' . ($pd_master_data[0]['re_uploaded'] ? $pd_master_data[0]['re_uploaded_file_name'] : $pd_master_data[0]['modified_fname']);
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname, $key, '+30 minutes');
if ($singed_uri) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $singed_uri;
$this->response($data, REST_Controller::HTTP_OK);
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Something Went Wrong! Try Later';
$this->response($data, REST_Controller::HTTP_OK);
}
}
public function getListPDOfficersForNotification_get()
{
log_message('ERROR', "getListPDOfficers Function");
$fields = array('fk_user_id');
$where_condition_array = array('isactive' => 1);
$list_of_pd_officers = $this->PD_Model->selectCustomRecords($fields, $where_condition_array, PDOFFICIERSDETAILS);
if (!empty($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,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('USERPROFILE.userid', $pdofficer['fk_user_id']);
$this->db->WHERE_IN("USERPROFILEROLES.user_role", [5]); //pd officer role only
$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]['user_role'] = $names[0]['user_role'];
$list_of_pd_officers[$key]['role_name'] = $names[0]['role_name'];
} else {
unset($list_of_pd_officers[$key]);
}
}
}
Sort($list_of_pd_officers);
log_message('ERROR', "getListPDOfficers PDofficer list : " . json_encode($list_of_pd_officers));
// Get Central PD Officers List
$central_pd_officers = array();
$this->db->SELECT('USERPROFILE.userid as fk_user_id,USERPROFILE.first_name,USERPROFILE.last_name,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();
log_message('ERROR', "getListPDOfficers CentralPDofficer list : " . json_encode($central_pd_officers));
if (!empty($list_of_pd_officers) && !empty($central_pd_officers)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = 'PD-Officer and Central PD-Officer Records Available!';
$data['records'] = array('pdofficers' => $list_of_pd_officers, 'centralpdofficers' => $central_pd_officers);
} else if (empty($list_of_pd_officers) && !empty($central_pd_officers)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = 'PD-Officer Records Not Found!';
$data['records'] = array('pdofficers' => array(), 'centralpdofficers' => $central_pd_officers);
} else if (empty($central_pd_officers) && !empty($list_of_pd_officers)) {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = 'Central PD-Officer Records Not Found!';
$data['records'] = array('pdofficers' => $list_of_pd_officers, 'centralpdofficers' => array());
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'Officers Records Not Found!';
}
$this->response($data, REST_Controller::HTTP_OK);
}
public function sendNotificationToOfficers_post()
{
log_message('ERROR', "send Notification To Officers ");
$records = $this->post('records');
$users = $records['user_id']; // alluser,multiuser,particularuser
$msg = $records['msg']; // alluser,multiuser,particularuser
// print_r($this->post());die();
if (!empty($msg) && !empty($users)) {
// $fields = array('notification_token_id','mob_token');
// $where_condition_array = array();
// $tokens = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,USERNOTIFICATIONTOKENS);
// pd offier's mobile token get form notification table
$resp = PDALERTS::sendNotificationToOfficers($records);
log_message('ERROR', "send Notification To Officers : " . json_encode($resp));
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = 'Notification Sended';
$data['details'] = $resp;
} else {
if (empty($msg)) {
log_message('ERROR', "send Notification To Officers : Message Not Found ");
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'Message Data Not Found!';
} else if (empty($users)) {
log_message('ERROR', "send Notification To Officers : Officer List Not Found ");
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'Users Not Found!';
} else {
log_message('ERROR', "send Notification To Officers : No Content ");
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'Records Not Found!';
}
}
$this->response($data, REST_Controller::HTTP_OK);
}
/****
create gmeet link for smart and tele pd and update it in pd trigger table
*/
function createGmeetLink_get()
// function createGmeetLink($pdid)
{
// echo Date('Y-m-d').'T'. Date('H:i:s', (strtotime(Date('H:i:s') . '+ 1 hour')));
// die();
$pdid = $this->get('pdid');
$this->load->library('Googleapi');
$pd_details = $this->PD_Model->getPDMasterDetails($pdid);
// print_r($pd_details);
if (!$pd_details[0]['gmeet_code'] && ($pd_details[0]['fk_pd_type'] == 2 || $pd_details[0]['fk_pd_type'] == 3)) {
$event = array(
'summary' => 'PD for ' . $pd_details[0]['title_name'] . ' ' . $pd_details[0]['main_applicant'] . ' & case no -' . $pd_details[0]['pd_sno'] . ' & Applicant ID - ' . $pd_details[0]['lender_applicant_id'],
'start' => Date('Y-m-d') . 'T' . Date('H:i:s'),
'end' => Date('Y-m-d') . 'T' . Date('H:i:s', (strtotime(Date('H:i:s') . '+ 1 hour'))),
'pdid' => $pdid,
);
// print_r($event);die();
$event_data = $this->googleapi->addGoogleCalenterEvent($event);
if (is_object($event_data)) {
$meet_code = isset($event_data['conferenceData']['conferenceId']) ? $event_data['conferenceData']['conferenceId'] : null;
$meet_id = isset($event_data['id']) ? $event_data['id'] : null;
$where_condition_array = array('pd_id' => $pdid);
$this->PD_Model->updateRecords(['gmeet_code' => $meet_code, 'gmeet_id' => $meet_id], PDTRIGGER, $where_condition_array);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['data'] = ['gmeet_code' => $meet_code];
$this->response($data, REST_Controller::HTTP_OK);
}
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'gmeet already created';
$this->response($data, REST_Controller::HTTP_OK);
}
}
/****
delete Calender Event from google calender
*/
// function deleteCalenderEvent_get()
function deleteCalenderEvent($eventID)
{
// $eventID = $this->get('eventID');
$this->load->library('Googleapi');
$event_data = $this->googleapi->deleteGoogleCalenderEvent($eventID);
}
// public function toMakeFaceBoundingBox_get(){
public function toMakeFaceBoundingBox($pdid,$len_id){
// $pdid = $this->get('pd'); //comment this bcoz test purpose
// $master_details = $this->PD_Model->getPDMasterDetails($pdid); //comment this bcoz test purpose
// $len_id = $master_details[0]['fk_lender_id']; //comment this bcoz test purpose
log_message('ERROR', "In PD Ctrl (to Make FaceBoundingBox called ) PDID : " . $pdid);
$where = array('isactive' => 1, 'fk_form_id' => 18, 'fk_pd_id' => $pdid);
$details = $this->PD_Model->selectCustomRecords(array('json'), $where, PDFORMDETAILSJSON);
## Here i am get person met applicant id's
$applicant_id_arr = array();
if (isset($details[0]['json'])) {
$json = json_decode($details[0]['json'], true);
foreach ($json['individuals'] as $key => $value) {
if ($value['is_person_met'] == 1) {
array_push($applicant_id_arr, $value['pd_co_applicant_id']);
}
}
}
## Here i am using that applicant id's to get facemark api result.(in applicant table)
$where_condition_array = array('fk_pd_id' => $pdid, 'isactive' => 1);
$where_condition_array['faceapi_result is NOT NULL'] = null;
if(!empty($applicant_id_arr)){
$where_condition_array['pd_co_applicant_id in ('.implode(",",$applicant_id_arr).')'] = null;
}
$applicants_details = $this->PD_Model->selectCustomRecords(array('pd_co_applicant_id', 'applicant_name', 'faceapi_result', 'facemark_image_generated', 'facecrop'), $where_condition_array, PDAPPLICANTSDETAILS);
// echo "working fine";
## Here i am check applicant id and applicant details and pdid.
if (!empty($applicant_id_arr) && !empty($applicants_details) && !empty($pdid)) {
log_message('ERROR', "In PD Ctrl (to Make FaceBoundingBox called ) Total Applicant : " . count($applicants_details));
log_message('ERROR', "In PD Ctrl (to Make FaceBoundingBox called ) Total Person Met Applicant : " . count($applicant_id_arr));
for ($j = 0; $j < count($applicants_details); $j++) {
$bounding_box = array();
$img_response = array();
$apcntid = $applicants_details[$j]['pd_co_applicant_id'];
// $master_details = $this->PD_Model->getPDMasterDetails($pdid);//comment this
if (!$applicants_details[$j]['facemark_image_generated']) {
log_message('ERROR', $applicants_details[$j]['applicant_name'] . " Facemark Image Generated : " . $applicants_details[$j]['facemark_image_generated']);
$string = $applicants_details[$j]['faceapi_result'];
// echo gettype($string);
$faceapi_result_decode = json_decode($string, true);
if (!empty($faceapi_result_decode) && !empty($faceapi_result_decode["FaceMatches"])) {
$arr = $faceapi_result_decode["FaceMatches"];
log_message('ERROR', $applicants_details[$j]['applicant_name'] . " FaceMatched array cnt : " . count($arr));
for ($i = 0; $i < count($arr); $i++) {
$bounding_box['compare_image'][$i] = $arr[$i]['Face']['BoundingBox'];
$bounding_box['compare_image'][$i]['Similarity'] = $arr[$i]['Similarity'];
}
}
if (!empty($faceapi_result_decode) && !empty($faceapi_result_decode["SourceImageFace"])) {
$bounding_box['source_image'] = $faceapi_result_decode["SourceImageFace"]['BoundingBox'];
}
// print_r($bounding_box);//working fine
$where_condition_array = array('fk_pd_id' => $pdid, 'isactive' => 1,'co_applicant_id'=>$apcntid);
$where_condition_array['image_key in ("selfie_with_person_met","person_met_id")'] = null;
$select_col = array('pd_document_id', 'pd_document_name', 'pd_document_title', 'image_key','img_type');
$img_result = $this->PD_Model->selectCustomRecords($select_col, $where_condition_array, PDDOCUMENTS);
if (count($img_result) > 0) {
for ($k = 0; $k < count($img_result); $k++) {
$bucketname = LENDER_BUCKET_NAME_PREFIX . $len_id;
$file_name = $img_result[$k]['pd_document_name'];
$key = 'pd' . $pdid . '/' . $file_name;
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname, $key, '+30 minutes');
$destination_path = $this->external_path . "/pd_reports/" . $pdid . "/";
if (!file_exists($destination_path . $file_name)) {
(!is_dir($destination_path)) ? mkdir($destination_path, 0777) : '';
file_put_contents($destination_path . $file_name, file_get_contents($singed_uri));
}
$info = getimagesize($destination_path . $file_name);
$extension = image_type_to_extension($info[2]);
// echo '-- extension'.$extension.$file_name;
log_message('ERROR', "In PD Ctrl to Make FaceBoundingBox FaceMatches inx " . $k . " singed_uri : " . $singed_uri);
// echo $j.$k;
$response = faceapi::toMakeFaceBoundingBox($bounding_box, $destination_path, $file_name, $img_result[$k]['image_key'], $apcntid);
array_push($img_response, $response);
if (($img_result[$k]['image_key'] == 'selfie_with_person_met')) {
$this->uploadPicInS3($pdid, $destination_path, $bucketname, $applicants_details[$j]['pd_co_applicant_id'],$extension);
}
// faceapi::toMakeFaceBoundingBox($bounding_box,$destination_path,$file_name);
// $this->uploadPicInS3($pdid,$comparisonImages[$i],$destination_path,$bucketname);
// $comparisonImages = faceapi::toGetFaceComparison($temp_image_name, $bounding_box, $destination_path,$source_image_bounding_box);
// if(count($comparisonImages)>0){
// for ($i = 0; $i < count($comparisonImages); $i++) {
// // $this->uploadPicInS3($pdid,$comparisonImages[$i],$destination_path,$bucketname);
// }
// }
}
$update_where = array('fk_pd_id' => $pdid, 'pd_co_applicant_id' => $apcntid);
$this->PD_Model->updateRecords(['facecrop' => json_encode($img_response)], PDAPPLICANTSDETAILS, $update_where);
// log_message('ERROR', "In PD Ctrl to Make FaceBoundingBox Done");
// $data['dataStatus'] = true;
// $data['status'] = REST_Controller::HTTP_OK;
// $data['msg'] = 'Success ';
// $data['dbRecords'] = $img_result;
// $data['arrDetails'] = $bounding_box;
// $data['imgResponse'] = $img_response;
} else {
log_message('ERROR', "In PD Ctrl to Make FaceBoundingBox No Images On DB");
// $data['dataStatus'] = false;
// $data['status'] = REST_Controller::HTTP_NO_CONTENT;
// $data['msg'] = 'Faceapi Image Already Generated';
}
} else {
log_message('ERROR', "In PD Ctrl to Make FaceBoundingBox Faceapi Image Already Generated");
// $data['dataStatus'] = false;
// $data['status'] = REST_Controller::HTTP_NO_CONTENT;
// $data['msg'] = 'Faceapi Image Already Generated 2';
}
} // for @ $applicants_details = j
} else {
log_message('ERROR', "In PD Ctrl to Make FaceBoundingBox Applicant is Not Available");
// $data['dataStatus'] = false;
// $data['status'] = REST_Controller::HTTP_NO_CONTENT;
// $data['msg'] = 'Applicant is Not Available';
}
// $this->response($data, REST_Controller::HTTP_OK);
}
public function uploadPicInS3($pdid,$destination_path,$bucketname,$apcntid,$extension){
log_message('ERROR', "In PD Ctrl uploadPicInS3 destinationPath : " . $destination_path);
$file = "face_api_image_".$apcntid.$extension;
$dbfile = "face_api_image_".$apcntid.".jpeg";
$key = 'pd' . $pdid . '/' . $dbfile;
$image = imagecreatefrompng($destination_path.$file);
imagejpeg($image, $destination_path.$dbfile, '70');
// imagedestroy($image);
// $output_file = $this->external_path . "/pd_reports/" . $pdid . "/".$dbfile;
// log_message('ERROR', "In PD Ctrl uploadPicInS3 sourcefilename : " . $destination_path.$dbfile);
// $sourcefile = imagejpeg($destination_path.$file, $destination_path.$dbfile,'70');
$bucket_data = array('bucket_name' => $bucketname, 'key' => $key, 'sourcefile' => $destination_path.$dbfile);
$s3result = $this->aws_s3->uploadFileToS3Bucket($bucket_data);
log_message('ERROR', "In PD Ctrl uploadPicInS3 s3 status : " . $s3result['@metadata']['statusCode']);
// log_message('ERROR', "In PD Ctrl uploadPicInS3 s3 result : " .json_encode($s3result));
if (is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) {
log_message('ERROR', "In PD Ctrl uploadPicInS3 updating pdapplicant table facemark_image_generated as 1");
// Make inactive old entries with same data
$this->db->WHERE('fk_pd_id', $pdid)
->WHERE('pd_document_title', 'face_api_result_image_'.$apcntid)->UPDATE(PDDOCUMENTS, array('isactive' => 0));
// then update
$this->db->WHERE('fk_pd_id', $pdid)->WHERE('pd_co_applicant_id', $apcntid)->UPDATE(PDAPPLICANTSDETAILS, array('facemark_image_generated' => 1));
log_message('ERROR', "In PD Ctrl uploadPicInS3 save document table face_api_result_image after unlink");
$record_data = array('fk_pd_id' => $pdid, 'pd_document_title' => 'face_api_result_image_'.$apcntid, 'pd_document_name' => $dbfile ,'co_applicant_id'=>$apcntid,'image_key'=>'face_mark');
$this->PD_Model->saveRecords($record_data, PDDOCUMENTS);
unlink($destination_path.$file);
unlink($destination_path.$dbfile);
}
}
}