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