sparqapi/api/application/controllers/Data_Dump_Controller.php
2022-04-04 10:12:40 +05:30

343 lines
14 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: kms
* Date: 11/13/17
* Time: 7:40 PM
*/
defined('BASEPATH') OR exit('No direct script access allowed');
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
/** @noinspection PhpIncludeInspection */
require_once APPPATH . '/libraries/REST_Controller.php';
include_once APPPATH.'/vendor/autoload.php';
/**
* This is an example of a few basic user interaction methods you could use
* all done with a hardcoded array
*
* @package CodeIgniter
* @subpackage Rest Server
* @category Controller
* @author
* @license MIT
* @link
*/
class Data_Dump_Controller extends REST_Controller {
function __construct()
{
parent::__construct();
$this->load->model('PD_Model','PD_Model');
$this->load->model('Data_Dump_Model','Data_Dump_Model');
//$this->load->library('AWS_S3');
}
public function getRawData_get()
{
$pdid = $this->get('pdid');
$rs = $this->get('rs');
$pd_processed_forms = array();
$master = $this->PD_Model->getPDMasterDetails($pdid);
if($pdid != '')// && $rs != '')
{
$this->load->helper('data_dump');
for($i = 1;$i<=30;$i++)
{
$fields = array('processed_json');
$where_condition_array = array('isactive' => 1,'fk_pd_id'=>$pdid,'fk_form_id' => $i);
$pd_processed_forms[$i] = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDFORMDETAILSJSON,array(),'','company_id','ASC');
// $fields2 = array('*');
// $data['pd_images'][$i] = $this->PD_Model->getSignedPDDocsURL($pdid,$i,null,null,null,'report');
}
//get General form dump
$gen_data_dump = array();
if(isset($pd_processed_forms[18]))
{
$gen_data = (json_decode($pd_processed_forms[18][0]['processed_json'],TRUE));
//print_r($gen_data);die();
$gen_data_dump = DATA_DUMP::convertGeneralDetailsForm($gen_data,$master);
print_r($gen_data_dump);
$this->Data_Dump_Model->saveGenDumpData($gen_data_dump);
}
if(isset($pd_processed_forms[13]))
{
if(array_key_exists('company_data', $gen_data_dump) && count($gen_data_dump))
{
$business_data = (json_decode($pd_processed_forms[13][0]['processed_json'],TRUE));
//print_r($business_data);die();
$business_data_dump = DATA_DUMP::convertBusinessDetailsForm($business_data,$master,$gen_data_dump['company_data']);
print_r($business_data_dump);
$this->Data_Dump_Model->saveBusinessDUmpData($business_data_dump);
}
}
}
}
//[true,"IIB","A50397621","Kamal Kumar Garg","9773522518","M/s Bhawani Matel,,,F-3, Kh. No. 105/72, New Mandoli Industrial Area, East Delhi New Delhi, Delhi-110093","Mukund","50 lacs","LAP PD","Tue Jul 06 16:18:00 GMT+05:30 2021","Fix for tomorrow morning 11-12 Pm...08 June",null,null,null,null]
public function googleSheet_post(){
$sheetData = $this->post();
// $reponse = $this->Data_Dump_Model->GsheetData($sheetData);
$modified = $this->modificationGsheetData($sheetData);
$reponse = $this->Data_Dump_Model->GsheetData($modified);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['sheetData'] = $sheetData;
$data['modifiedData'] = $modified;
$data['reponseData'] = $reponse;
$this->response($data,REST_Controller::HTTP_OK);
}
public function modificationGsheetData($GSdata){
// echo count($GSdata);
$modifiedData = array();
$pd_details = array();
$pd_applicant_details = array();
$addresses = array();
// pd_details
// {"fk_lender_id":"42","sub_entity_id":"42","lender_applicant_id":"SR201819351","pd_branch_id":null,"lender_sales_person":"376","lender_credit_person":"350","imgc_fin_institute":null,"fk_product_id":"24","fk_subproduct_id":null,"fk_pd_type":"1","is_notify_enabled":null,"fk_customer_segment":"5","loan_amount":"3000000","addressline1":"Third Floor Right Side Bal K 83-84 Udyan Road Uttam Nagar New Delhi","fk_city":"869","fk_state":"5","pincode":"27491","other_pincode":null,"remarks":null,"pd_status":"TRIGGERED","fk_createdby":"397"}
// pd_applicant_details
// [{"applicant_name":"Ranjit Kumar Sharma","applicant_title_name":"5","company_name":"Kr Tourist Services Pvt Ltd","mobile_no":"9717361459","additional_mobile_no":null,"landline":null,"applicant_type":1,"relation":""}]
// addresses
// [{"addressline1":"Third Floor Right Side Bal K 83-84 Udyan Road Uttam Nagar New Delhi","fk_city":"869","fk_state":"5","pincode":"27491","other_pincode":null}]
for($i=0;$i<count($GSdata);$i++){
if($i==1 && $GSdata[$i] != ""){
$modifiedData['lender'] = $GSdata[$i];
$fk_lender_id = $this->Data_Dump_Model->getId(1,$GSdata[$i]);
$pd_details['fk_lender_id']=$fk_lender_id;
// $pd_details['sub_entity_id'] ="42";
}
if($i==2 && $GSdata[$i] != ""){
$modifiedData['lender_applicant_id'] = str_replace(" ", "", $GSdata[$i]);
$pd_details['lender_applicant_id'] =str_replace(" ", "", $GSdata[$i]);
}
$mobile_no = "";
if($i==4 && $GSdata[$i] != ""){
$modifiedData['mobileNumber'] = $GSdata[$i];
$mobile_no = $GSdata[$i];
}
if($i==3 && $GSdata[$i] != ""){
$flag = 0;
$companyParts = explode('/', $GSdata[$i]);
if(count($companyParts)>1){
$applicatantParts = explode(',', $companyParts[0]);
if(count($applicatantParts)>1){
for($j=0;$j<count($applicatantParts);$j++){
$pd_applicant_details[$j]['applicant_name'] = $applicatantParts[$j];
$modifiedData['pd_applicant_details'][$j]['applicant'] = $applicatantParts[$j];
}
}else{
$pd_applicant_details[0]['applicant_name'] = $companyParts[0];
$pd_applicant_details[0]['company_name'] = $companyParts[1];
$modifiedData['pd_applicant_details'][0]['applicant'] = $companyParts[0];
; $modifiedData['pd_applicant_details'][0]['company_name'] = $companyParts[1];
}
}else $flag++;
if($mobile_no != ""){
$pd_applicant_details[0]['mobile_no'] = $mobile_no;
$modifiedData['pd_applicant_details'][0]['mobile_no'] = $mobile_no;
}
if($flag > 0){
$pd_applicant_details[0]['applicant_name'] = $GSdata[$i];
$modifiedData['pd_applicant_details'][0]['applicant'] = $GSdata[$i];
}
}
if($i==5 && $GSdata[$i] != ""){//address section.
$NormalParts = explode(',', $GSdata[$i]);
$stateAndPincode = end($NormalParts);
$splitStateAndPincode = explode('-',$stateAndPincode , 2);
$modifiedData['state'] = $splitStateAndPincode[0];
$addresses['fk_state']=$this->Data_Dump_Model->getId(5,$splitStateAndPincode[0]);
$modifiedData['pincode'] = $splitStateAndPincode[1];
$pin = $this->Data_Dump_Model->getId(6,$splitStateAndPincode[1]);
$addresses['pincode'] = ($pin != "" ? $pin : 1);
$addresses['other_pincode']=($pin == "" ? $splitStateAndPincode[1] : null);
$city = array_slice($NormalParts, -2, 1);
$modifiedData['city'] = $city[0];
$addresses['fk_city']=$this->Data_Dump_Model->getId(7,$city[0]);
array_splice($NormalParts, -2);//removing city state and pincode.
// $reversedParts = explode('-', strrev($GSdata[$i]), 2);
// array_push($result_data["Pincode"],strrev($reversedParts[0]));
// print_r($NormalParts);
// print_r(array_filter($NormalParts));// removing Null values
$modifiedData['address'] = implode(",",array_filter($NormalParts));
$addresses['addressline1'] = implode(",",array_filter($NormalParts));
// echo "Original Address : ".$GSdata[$i];
// echo "Modified Address : ".$address;
}
if($i==6 && $GSdata[$i] != ""){
$modifiedData['createdPerson'] = $GSdata[$i];
$pd_details['fk_createdby'] = $this->Data_Dump_Model->getId(8,$GSdata[$i]);
}
if($i==7 && ($GSdata[$i] != "" || $GSdata[$i] != 0)){
$amount = strtolower($GSdata[$i]);
$amount = explode(' ', $amount);
// 3 zeros in 1,000 - One Thousand
// 4 zeros in 10,000 - Ten Thousand
// 5 zeros in 100,000 - 1 Lakh / 100 Thousand
// 6 zeros in 1,000,000 - 10 Lakh / 1 Million
// 7 zeros in 10,000,000 - 1 Crore / 10 Million
// 8 zeros in 100,000,000 - 10 Crore / 100 Million
// 9 zeros in 1,000,000,000 - 100 Crore / 1 Billion
// 10 zeros in 10,000,000,000 - 1,000 Crore / 10 Billion
// 11 zeros in 100,000,000,000 - 10,000 Crore / 100 Billion
// 12 zeros in 1,000,000,000,000 - 1 Lakh Crore / 1 Trillion
// 13 zeros in 10,000,000,000,000 - 10 Lakh Crore / 10 Trillion
if(gettype($amount[1]) == 'string'){
if($amount[1] == 'cr' || $amount[1] == 'crore'){
$amount[1] = "0000000";
}
if($amount[1] == 'lac' || $amount[1] == 'lacs' || $amount[1] == 'lakh'){
$amount[1] = "000000";
}
if($amount[1] =='k' ||$amount[1] == 'thousand'){
$amount[1] = "000";
}}
$modifiedData['loanAmount'] = implode("",$amount);
$pd_details['loan_amount'] = implode("",$amount);
}
if($i==8 && $GSdata[$i] != ""){
$product = explode('/', $GSdata[$i]);
if(count($product)>1){
$modifiedData['product'] = $product[0] ? $product[0] : null;
$modifiedData['subproduct'] = $product[1] ? $product[1] : null ;
$fk_product_id = $this->Data_Dump_Model->getId(2,$product[0]);
$pd_details['fk_product_id'] = $fk_product_id;
$pd_details['fk_subproduct_id'] = $this->Data_Dump_Model->getId(3,$product[1]);
}
else{
$modifiedData['product'] = $product[0] ? $product[0] : null ;
$fk_product_id = $this->Data_Dump_Model->getId(2,$product[0]);
$pd_details['fk_product_id'] = $product[0] ? $fk_product_id : null ;
}
}
if($i==9 && $GSdata[$i] != ""){
$type = explode('/', $GSdata[$i]);
$modifiedData['type'] = ($type[0] != "") ? strtoupper(str_replace(' ', '', $type[0])) : "FULLPD";
if(count($type)>1){
$pd_details['fk_pd_type'] = $modifiedData['type'] == "FULLPD" ? 1 : ($modifiedData['type'] == "SMARTPD" ? 2 :($modifiedData['type'] == "TELEPD" ? 3 : 0) ) ;
$modifiedData['customerSegment'] = ($type[1] != "") ? $type[1] : null;
$fk_customer_segment = $this->Data_Dump_Model->getId(4,$modifiedData['customerSegment']);
$pd_details['fk_customer_segment'] = $fk_customer_segment;
}else{
$pd_details['fk_pd_type'] = $modifiedData['type'] == "FULLPD" ? 1 : ($modifiedData['type'] == "SMARTPD" ? 2 :($modifiedData['type'] == "TELEPD" ? 3 : 0) ) ;
}
}
if($i==10 && $GSdata[$i] != ""){
// $modifiedData['date'] = $GSdata[$i];
$new_date_format = date('Y-m-d H:i:s', strtotime($GSdata[$i]));
$modifiedData['date'] = $new_date_format;
$pd_details['pd_date_of_initiation'] = $new_date_format;
}
if($i==11 && $GSdata[$i] != ""){
$modifiedData['remarks'] = $GSdata[$i];
$pd_details['remarks'] = $GSdata[$i];
}
}
## Default Status section;
$pd_details['pd_status'] = TRIGGERED;
## Template ID Section.
$fields = array('fk_template_id');
$where_condition_array = array('fk_lender_id'=>$fk_lender_id ,'fk_product_id'=> $fk_product_id,'fk_customer_segment'=> $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
{ $customer_segment_abbr = $this->PD_Model->selectCustomRecords(array('*'),array('customer_segment_id' => $pd_details['fk_customer_segment'],'isactive' => 1),CUSTOMERSEGMENT);
$customer_segment_abbr = $customer_segment_abbr[0]['abbr'];
if( !strcasecmp($customer_segment_abbr,'SAL'))// || !strcasecmp($customer_segment_abbr,'SAL-CHQ'))
{$pd_details['fk_pd_template_id'] = 1;## SAL-(CASH/CHQ)
}
else if( !strcasecmp($customer_segment_abbr,'SE-DI') || !strcasecmp($customer_segment_abbr,'SEP-DI') || !strcasecmp($customer_segment_abbr,'SEP_INDV'))
{$pd_details['fk_pd_template_id'] = 2;## SENP/SEP-(DI)
}
else if( !strcasecmp($customer_segment_abbr,'SE-AI') || !strcasecmp($customer_segment_abbr,'SEP-AI') )
{$pd_details['fk_pd_template_id'] = 3;## SENP/SEP-(DI)
}
else if( !strcasecmp($customer_segment_abbr,'SE-RI'))
{$pd_details['fk_pd_template_id'] = 4;## SENP/SEP-(RI)
}
}
## Random URL Section.
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < 16; $i++)
{
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
$pd_details['random_string'] = $randomString;
$pd_details['is_notify_enabled'] = 1;
$pd_id = $this->PD_Model->saveRecords($pd_details,PDTRIGGER);
// $pd_id = 0;
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'] = null;
$pd_applicant_detail['applicant_name'] = trim(MYUTIL::applicantNameCamelCaseConvertion($pd_applicant_detail['applicant_name']));
$pd_applicant_detail['company_name'] = trim(MYUTIL::applicantNameCamelCaseConvertion($pd_applicant_detail['company_name']));
$co_applicant_id = $this->PD_Model->saveRecords($pd_applicant_detail,PDAPPLICANTSDETAILS);
if($co_applicant_id != null || $co_applicant_id != '')
{
$count = $count + 1;
}
}
}
}
## Address Section.
// print_r($addresses);
if($pd_id != null || $pd_id != '')
{
if(count($addresses))
{
foreach($addresses as $address_key => $address)
{
// $address->fk = 7 ;
$address['fk_pd_id'] = $pd_id;
$address['is_primary'] = count($addresses) == 1 ? 1 :0 ;
$address['assigned_pd'] = count($addresses) == 1 ? 0 :null ;
$address_id = $this->PD_Model->saveRecords($address,PDADDRESS);
// if($address_key == 0)
// {
// $temp_address_id = $address_id;
// }
}
}}
// print_r($pd_details);
// print_r($modifiedData);
// print_r($addresses);
// print_r($pd_applicant_details);
// print_r($address);
// die();
return $pd_id;
}
}