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(){ // $logger = MYLOG::logFunction(null,"Gsheet"); log_message('ERROR','#/# G-Sheet Fns Entered - '.date('Y-m-d H:i:s A')); // $sheetData = $this->post(); // $sheetData = json_decode($this->post(),true); $sheetData = $this->post(); log_message('ERROR','#/# Params Count - '.count($sheetData)); if(count($sheetData) > 0){ $pd_id = $this->modificationGsheetData($sheetData); if($pd_id != null || $pd_id != '') { $pd_serial_no = $this->Data_Dump_Model->getPDSerialNO($pd_id); log_message('ERROR',"#/# G-Sheet For PD ID : ".$pd_id); // PDALERTS::pdnotification($pd_id); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['pdid'] = $pd_serial_no." / ".$pd_id; $data['msg'] = "Successfully Inserted PD.NO/ID : ".$pd_serial_no." / ".$pd_id; $this->response($data,REST_Controller::HTTP_OK); } else { log_message("ERROR","#/# G-Sheet SomeThing went Wrong mistake on Gsheet-data PDID not Founded"); $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = "Some thing went wrong"; $this->response($data,REST_Controller::HTTP_OK); } }else{ log_message("ERROR","#/# G-Sheet Data Not Founded"); $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = "Some thing went wrong !"; $this->response($data,REST_Controller::HTTP_OK); } // if($reponse){ // $data['dataStatus'] = true; // $data['status'] = REST_Controller::HTTP_OK; // $data['pdid'] = $reponse; // $data['sheetData'] = $sheetData; // $data['modifiedData'] = $modified; // } } public function modificationGsheetData($GSdata){ // $logger = MYLOG::logFunction(null,"Gsheet"); log_message('ERROR',"G-Sheet For PD Step 1 (G-sheet Data)"); $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}] log_message('ERROR',"G-Sheet For PD Step 2 (Processing data for-loop)"); if(isset($GSdata["LenderName"]) && $GSdata["LenderName"] != ""){ $fk_lender_id = $this->Data_Dump_Model->getId(1,trim($GSdata["LenderName"])); $pd_details['fk_lender_id']=$fk_lender_id; $pd_details['sub_entity_id']=$fk_lender_id; log_message('ERROR',"G-Sheet For PD Step 2.1 (lender/casebookedin) GSheet data : ".$GSdata["LenderName"]." PD :".$pd_details['fk_lender_id']." ".$pd_details['sub_entity_id']); // $lender_contact_persons = $this->PD_Model->getLenderContactPersons($fk_lender_id,null); // if(!empty($lender_contact_persons)){ // $pd_details['lender_credit_person'] = $lender_contact_persons[0]['role_type'] == "CREDIT" ? $lender_contact_persons[0]['userid'] : null; // $pd_details['lender_sales_person'] = $lender_contact_persons[0]['role_type'] == "SALES" ? $lender_contact_persons[0]['userid'] : null; // } } if(isset($GSdata["LAN"]) && $GSdata["LAN"] != ""){ $LAN = trim(str_replace(" ", "", $GSdata["LAN"])); $pd_details['lender_applicant_id'] =$LAN; log_message('ERROR',"G-Sheet For PD Step 2.2 (loan applicantid) GSheet data : ".$LAN." PD :".$pd_details['lender_applicant_id']); } // $applicatantParts =""; // if(isset($GSdata["ApplicantName_CompanyName"]) && $GSdata["ApplicantName_CompanyName"] != ""){ // $applicatantParts = explode(',',$GSdata["ApplicantName_CompanyName"]); // if(count($applicatantParts)>1){ // for($j=0;$j1){ // $pd_applicant_details[0]['applicant_name'] = $splitCompanyandApplicant[0]; // $pd_applicant_details[0]['company_name'] = isset($splitCompanyandApplicant[1]) ? $splitCompanyandApplicant[1] : null; // } // else{ // $pd_applicant_details[0]['applicant_name'] = $splitCompanyandApplicant[0]; // $pd_applicant_details[0]['company_name'] = null; // } // } // $pd_applicant_details[0]['mobile_no'] = isset($GSdata['ContactNumber']) ? $GSdata['ContactNumber'] : null; // $pd_applicant_details[0]['applicant_type'] = 1; // log_message('ERROR',"G-Sheet For PD Step 2.3 (Third Cell applicantdetails) GSheet data : ".$GSdata['ContactNumber']); // log_message('ERROR',"G-Sheet For PD Step 2.4 (Fourth Cell mobilenumber) GSheet data : ".$GSdata['ContactNumber']); // } $applicatantParts =""; if(isset($GSdata["ApplicantName"]) && $GSdata["ApplicantName"] != ""){ $applicatantParts = explode(',',$GSdata["ApplicantName"]); if(count($applicatantParts)>1){ for($j=0;$j1){ for($j=0;$jData_Dump_Model->getId(5,$splitStateAndPincode[0]); $pd_details['fk_state'] =$addresses['fk_state']; $pin = $this->Data_Dump_Model->getId(6,trim($splitStateAndPincode[1])); $addresses['pincode'] = ($pin != "" ? $pin : 1); $pd_details['pincode'] = $addresses['pincode']; $addresses['other_pincode']=($pin == "" ? trim($splitStateAndPincode[1]) : null); $pd_details['other_pincode'] = $addresses['other_pincode']; $city = array_slice($NormalParts, -2, 1); $addresses['fk_city']=$this->Data_Dump_Model->getId(7,$city[0]); $pd_details['fk_city']=$addresses['fk_city']; array_splice($NormalParts, -2);//removing city state and pincode. // $reversedParts = explode('-', strrev($GSdataata[$i]), 2); // array_push($result_data["Pincode"],strrev($reversedParts[0])); // print_r($NormalParts); // print_r(array_filter($NormalParts));// removing Null values $modifyaddress = implode(",",array_filter($NormalParts)); $addresses['addressline1'] = implode(",",array_filter($NormalParts)); $pd_details['addressline1']=$addresses['addressline1']; // echo "Original Address : ".$GSdataata[$i]; // echo "Modified Address : ".$address; log_message('ERROR',"G-Sheet For PD Step 2.6 (address) GSheet data : ".$GSdata["PDLocation"]); } if(isset($GSdata["PersonDoing"]) && $GSdata["PersonDoing"] != ""){ // $pd_details['fk_createdby'] = $this->Data_Dump_Model->getId(8,$GSdata["PersonDoing"]); log_message('ERROR',"G-Sheet For PD Step 2.7 (Allocated Person) GSheet data : ".$GSdata["PersonDoing"]); } if(isset($GSdata["LoanAmount"]) && ($GSdata["LoanAmount"] != "" || $GSdata["LoanAmount"] != 0)){ // $amount = strtolower($GSdata["LoanAmount"]); // $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"; // }} // $pd_details['loan_amount'] = implode("",$amount); $pd_details['loan_amount'] = (int)$GSdata["LoanAmount"]; log_message('ERROR',"G-Sheet For PD Step 2.8 (Amount) GSheet data : ".$GSdata["LoanAmount"]." PD details :".$pd_details['loan_amount']); } $fk_product_id =""; if(isset($GSdata["Product"]) && $GSdata["Product"] != ""){ $fk_product_id = $this->Data_Dump_Model->getId(2,trim($GSdata["Product"])); $pd_details['fk_product_id'] = $GSdata["Product"] ? $fk_product_id : null ; log_message('ERROR',"G-Sheet For PD Step 2.9 (Product) GSheet data : ".$GSdata["Product"]." pd details : ".$fk_product_id); } if(isset($GSdata["SubProduct"]) && $GSdata["SubProduct"] != ""){ $pd_details['fk_subproduct_id'] = $this->Data_Dump_Model->getId(3,$GSdata["SubProduct"]); log_message('ERROR',"G-Sheet For PD Step 2.10 (SubProduct) GSheet data : ".$GSdata["SubProduct"]." pd details : ".$pd_details['fk_subproduct_id']); } if(isset($GSdata["Type"]) && $GSdata["Type"] != ""){ $type = $GSdata["Type"]; $modifytype = ($type != "") ? strtoupper(str_replace(' ', '', $type)) : "FULLPD"; $pd_details['fk_pd_type'] = $modifytype == "FULLPD" ? 1 : ($modifytype == "SMARTPD" ? 2 :($modifytype == "TELEPD" ? 3 : 0) ) ; log_message('ERROR',"G-Sheet For PD Step 2.11 (pd-type) GSheet data : ".$GSdata["Type"]." PD details :".$pd_details['fk_pd_type']); } $fk_customer_segment = ""; if(isset($GSdata["CustomerSegment"]) && $GSdata["CustomerSegment"] != ""){ $modifycustomerSegment = ($GSdata["CustomerSegment"] != "") ? $GSdata["CustomerSegment"] : null; $fk_customer_segment = $this->Data_Dump_Model->getId(4,trim($modifycustomerSegment)); $pd_details['fk_customer_segment'] = $fk_customer_segment; log_message('ERROR',"G-Sheet For PD Step 2.12 (customer segment) GSheet data : ".$GSdata["CustomerSegment"]." PD details :".$fk_customer_segment); } // if(isset($GSdata["DateofReceivingPDRequest"]) && $GSdata["DateofReceivingPDRequest"] != ""){ // $new_date_format = date('Y-m-d H:i:s', strtotime($GSdata["DateofReceivingPDRequest"])); // $pd_details['pd_date_of_initiation'] = $new_date_format; // log_message('ERROR',"G-Sheet For PD Step 2.10 (tenth Cell initiationdate) GSheet data : ".$GSdata["DateofReceivingPDRequest"]." PD :".$pd_details['pd_date_of_initiation']); // } if(isset($GSdata["AdditionalRequirements"]) && $GSdata["AdditionalRequirements"] != ""){ $requirements = explode(',',$GSdata["AdditionalRequirements"]); if(count($requirements)>1){ for($j=0;$jData_Dump_Model->getId(8,$GSdata["LenderCreditName"]); log_message('ERROR',"G-Sheet For PD Step 2.15 (Lender Credit Person) GSheet data : ".$GSdata["LenderCreditName"]); } // print_r($pd_applicant_details); // die(); ## Default Status section; $pd_details['pd_status'] = TRIGGERED; $pd_details['pd_date_of_initiation'] = date('Y-m-d H-i-s'); $pd_details['fk_createdby'] = 379; // default user created for admin. ## 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->Data_Dump_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->Data_Dump_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; $url = OFFICER_TRACKING_URL.$randomString; $pd_details['encrypted_url'] = $url; $pd_details['is_notify_enabled'] = 1; log_message('ERROR',"G-Sheet For PD Step 3 (Before Inserting Trigger)"); try { $pd_id = $this->Data_Dump_Model->saveRecords($pd_details,PDTRIGGER); log_message('ERROR',"G-Sheet For PD Step 4 (PDID gotten) PDID : ".$pd_id); if(empty($pd_id)) { throw new Exception('Error On Inserting TRIGGER details'); } } catch (Exception $e) { log_message('ERROR',"G-Sheet For PD Step 4 (PDID gotten) ERR : ".$e->getMessage()); // var_dump($e->getMessage()); } // $pd_id = 3149; if($pd_id != null || $pd_id != '') { if($pd_applicant_details != "" || $pd_applicant_details != null) { log_message('ERROR',"G-Sheet For PD Step 5 (applicant)"); // Applicant : ".$pd_applicant_details); foreach($pd_applicant_details as $pd_applicant_detail) { $pd_applicant_detail['fk_pd_id'] = $pd_id; $pd_applicant_detail['applicant_name'] = trim(MYUTIL::applicantNameCamelCaseConvertion($pd_applicant_detail['applicant_name'])); if(isset($pd_applicant_detail['company_name'])){ $pd_applicant_detail['company_name'] = trim(MYUTIL::applicantNameCamelCaseConvertion($pd_applicant_detail['company_name'])); } try { $co_applicant_id = $this->Data_Dump_Model->saveRecords($pd_applicant_detail,PDAPPLICANTSDETAILS); log_message('ERROR',"G-Sheet For PD Step 5.1 (applicant pkid) Applicant-ID : ".$co_applicant_id); if(empty($co_applicant_id)) { throw new Exception('Error On Inserting Applicant details'); } } catch (Exception $e) { //alert the user. log_message('ERROR',"G-Sheet For PD Step 5.1 (applicant pkid) ERR : ".$e->getMessage()); // var_dump($e->getMessage()); } } } } ## Credit Manager’s Specific Queries if($pd_id != ""){ if($addi_requirements != "" || $addi_requirements != null) { log_message('ERROR',"G-Sheet For PD Step 6 (credit manager queries)"); foreach($addi_requirements as $pd_addtional_requirement) { try { $pd_addtional_requirement['isactive'] = 1; $pd_addtional_requirement['fk_pd_id'] = $pd_id; $requirement_id = $this->Data_Dump_Model->saveRecords($pd_addtional_requirement,PDADDTIONALREQUIREMENTS); log_message('ERROR',"G-Sheet For PD Step 6.1 (credit manager queries/additional requirements pkid) REQUIREMENTS-ID : ".$requirement_id); if(empty($requirement_id)) { throw new Exception('Error On Inserting Additional Requirements'); } } catch (Exception $e) { //alert the user. log_message('ERROR',"G-Sheet For PD Step 6.1 (credit manager queries/additional requirements pkid) ERR : ".$e->getMessage()); // var_dump($e->getMessage()); } } } } ## Address Section. if($pd_id != ""){ $addresses['fk_pd_id'] = $pd_id; $addresses['is_primary'] = 1 ; $addresses['assigned_pd'] = $pd_id; try { $address_id = $this->Data_Dump_Model->saveRecords($addresses,PDADDRESS); log_message('ERROR',"G-Sheet For PD Step 6 (Addresses) addressId : ".$address_id); if(empty($address_id)) { throw new Exception('Error On Inserting Adresses details'); } } catch (Exception $e) { log_message('ERROR',"G-Sheet For PD Step 6 (Addresses) ERR : ".$e->getMessage()); // var_dump($e->getMessage()); } // $triggertbl_records = array('fk_primary_address_id'=>$address_id,'fk_address_id'=>$address_id); $triggertbl_records = array('fk_primary_address_id'=>$address_id,'fk_address_id'=>$address_id,'parent_pd_id'=>$pd_id); try { $this->Data_Dump_Model->updateRecords($triggertbl_records,PDTRIGGER,array('pd_id' => $pd_id)); log_message('ERROR',"G-Sheet For PD Step 7 (updateAddresses in trigger)"); if(empty($this->Data_Dump_Model->updateRecords($triggertbl_records,PDTRIGGER,array('pd_id' => $pd_id)))) { throw new Exception('Error On updated Adresses Details in trigger table'); } } catch (Exception $e) { log_message('ERROR',"G-Sheet For PD Step 7 (updateAddresses in trigger) ERR : ".$e->getMessage()); // var_dump($e->getMessage()); } } log_message('ERROR',"#/# G-Sheet Final PDID : ".$pd_id); return $pd_id; } }