Google sheet 7: ps

This commit is contained in:
VE10-Sanjeev 2022-04-09 13:23:48 +05:30
parent fbe7aedacf
commit 19fb47ca2c

View File

@ -89,7 +89,7 @@ class Data_Dump_Controller extends REST_Controller {
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 = json_decode($_POST['data']);
$sheetData = $this->post();
log_message('ERROR','#/# Params Count - '.count($sheetData));
if(count($sheetData) > 0){
$pd_id = $this->modificationGsheetData($sheetData);
@ -126,20 +126,12 @@ class Data_Dump_Controller extends REST_Controller {
// $data['sheetData'] = $sheetData;
// $data['modifiedData'] = $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){
// $logger = MYLOG::logFunction(null,"Gsheet");
log_message('ERROR',"G-Sheet For PD Step 1 (G-sheet Data)");
$modifiedData = array();
$pd_details = array();
$pd_applicant_details = array();
$addresses = array();
@ -149,85 +141,77 @@ class Data_Dump_Controller extends REST_Controller {
// [{"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++){
log_message('ERROR',"G-Sheet For PD Step 2 (Processing data for-loop)");
if($i==1 && $GSdata[$i] != ""){
$modifiedData['lender'] = $GSdata[$i];
$fk_lender_id = $this->Data_Dump_Model->getId(1,trim($GSdata[$i]));
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 (First Cell lender/casebookedin) GSheet data : ".$GSdata[$i]." Modify : ".$modifiedData['lender']." PD :".$pd_details['fk_lender_id']." ".$pd_details['sub_entity_id']);
log_message('ERROR',"G-Sheet For PD Step 2.1 (First Cell lender/casebookedin) GSheet data : ".$GSdata["LenderName"]." PD :".$pd_details['fk_lender_id']." ".$pd_details['sub_entity_id']);
}
if($i==2 && $GSdata[$i] != ""){
$modifiedData['lender_applicant_id'] = trim(str_replace(" ", "", $GSdata[$i]));
$pd_details['lender_applicant_id'] =trim(str_replace(" ", "", $GSdata[$i]));
log_message('ERROR',"G-Sheet For PD Step 2.2 (Second Cell - loan applicantid)GSheet data : ".$GSdata[$i]." Modify : ".$modifiedData['lender_applicant_id']." PD :".$pd_details['lender_applicant_id']);
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 (Second Cell - loan applicantid)GSheet data : ".$LAN." PD :".$pd_details['lender_applicant_id']);
}
if($i==3 && $GSdata[$i] != ""){
$applicatantParts = explode(',',$GSdata[$i]);
$applicatantParts ="";
if(isset($GSdata["ApplicantName_CompanyName"]) && $GSdata["ApplicantName_CompanyName"] != ""){
$applicatantParts = explode(',',$GSdata["ApplicantName_CompanyName"]);
if(count($applicatantParts)>1){
for($j=0;$j<count($applicatantParts);$j++){
$splitCompanyandApplicant = explode('/',$applicatantParts[$j]);
$pd_applicant_details[$j]['applicant_name'] = $splitCompanyandApplicant[0];
$modifiedData['pd_applicant_details'][$j]['applicant'] = $splitCompanyandApplicant[0];
$pd_applicant_details[$j]['company_name'] = isset($splitCompanyandApplicant[1]) ? $splitCompanyandApplicant[1] : null;
$modifiedData['pd_applicant_details'][$j]['company_name'] = isset($splitCompanyandApplicant[1]) ? $splitCompanyandApplicant[1] : null;
}
}else{
$pd_applicant_details[0]['applicant_name'] = $applicatantParts[0];
$splitCompanyandApplicant = explode('/',$applicatantParts[0]);
if(count($splitCompanyandApplicant)>1){
$pd_applicant_details[$j]['applicant_name'] = $splitCompanyandApplicant[0];
$pd_applicant_details[$j]['company_name'] = isset($splitCompanyandApplicant[1]) ? $splitCompanyandApplicant[1] : null;
}
else{
$pd_applicant_details[0]['applicant_name'] = $splitCompanyandApplicant[0];
$pd_applicant_details[0]['company_name'] = null;
$modifiedData['pd_applicant_details'][0]['applicant'] = $applicatantParts[0];
$modifiedData['pd_applicant_details'][0]['company_name'] = null;
}
}
$pd_applicant_details[0]['mobile_no'] = $GSdata[4] ? $GSdata[4] : null;
$modifiedData['pd_applicant_details'][0]['mobile_no'] = $GSdata[4] ? $GSdata[4] : null;
$pd_applicant_details[0]['mobile_no'] = isset($GSdata['ContactNumber']) ? $GSdata['ContactNumber'] : null;
$pd_applicant_details[0]['applicant_type'] = 1;
$modifiedData['pd_applicant_details'][0]['applicant_type'] = 1;
log_message('ERROR',"G-Sheet For PD Step 2.3 (Third Cell applicantdetails) GSheet data : ".$GSdata[$i]);
//." Modify : ".$modifiedData." PD :".$pd_details);
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']);
}
if($i==4 && $GSdata[$i] != ""){ $modifiedData['mobileNumber'] = $GSdata[$i];
log_message('ERROR',"G-Sheet For PD Step 2.4 (Fourth Cell mobilenumber) GSheet data : ".$GSdata[$i]);
//." Modify : ".$modifiedData." PD :".$pd_details);
}
if($i==5 && $GSdata[$i] != ""){//address section.
$NormalParts = explode(',', $GSdata[$i]);
//address section.
if(isset($GSdata["PDLocation"]) && $GSdata["PDLocation"] != ""){
$NormalParts = explode(',', $GSdata["PDLocation"]);
$stateAndPincode = end($NormalParts);
$splitStateAndPincode = explode('-',$stateAndPincode , 2);
$modifiedData['state'] = $splitStateAndPincode[0];
$addresses['fk_state']=$this->Data_Dump_Model->getId(5,trim($splitStateAndPincode[0]));
$pd_details['fk_state'] =trim($addresses['fk_state']);
$modifiedData['pincode'] = trim($splitStateAndPincode[1]);
$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);
$modifiedData['city'] = $city[0];
$addresses['fk_city']=$this->Data_Dump_Model->getId(7,trim($city[0]));
$pd_details['fk_city']=$addresses['fk_city'];
array_splice($NormalParts, -2);//removing city state and pincode.
// $reversedParts = explode('-', strrev($GSdata[$i]), 2);
// $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
$modifiedData['address'] = implode(",",array_filter($NormalParts));
$modifyaddress = implode(",",array_filter($NormalParts));
$addresses['addressline1'] = implode(",",array_filter($NormalParts));
$pd_details['addressline1']=$addresses['addressline1'];
// echo "Original Address : ".$GSdata[$i];
// echo "Original Address : ".$GSdataata[$i];
// echo "Modified Address : ".$address;
log_message('ERROR',"G-Sheet For PD Step 2.5 (Fifth Cell address) GSheet data : ".$GSdata[$i]);
//." Modify : ".$modifiedData." PD :".$pd_details);
log_message('ERROR',"G-Sheet For PD Step 2.5 (Fifth Cell address) GSheet data : ".$GSdata["PDLocation"]);
}
if($i==6 && $GSdata[$i] != ""){
$modifiedData['createdPerson'] = $GSdata[$i];
$pd_details['fk_createdby'] = $this->Data_Dump_Model->getId(8,trim($GSdata[$i]));
log_message('ERROR',"G-Sheet For PD Step 2.6 (Sixth Cell createdPerson) GSheet data : ".$GSdata[$i]);
// ." Modify : ".$modifiedData." PD :".$pd_details);
if(isset($GSdata["PersonDoing"]) && $GSdata["PersonDoing"] != ""){
$pd_details['fk_createdby'] = $this->Data_Dump_Model->getId(8,trim($GSdata["PersonDoing"]));
log_message('ERROR',"G-Sheet For PD Step 2.6 (Sixth Cell createdPerson) GSheet data : ".$GSdata["PersonDoing"]);
}
if($i==7 && ($GSdata[$i] != "" || $GSdata[$i] != 0)){
$amount = strtolower($GSdata[$i]);
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
@ -250,59 +234,57 @@ class Data_Dump_Controller extends REST_Controller {
if($amount[1] =='k' ||$amount[1] == 'thousand'){
$amount[1] = "000";
}}
$modifiedData['loanAmount'] = implode("",$amount);
$pd_details['loan_amount'] = implode("",$amount);
log_message('ERROR',"G-Sheet For PD Step 2.7 (Seventh Cell Amount) GSheet data : ".$GSdata[$i]." Modify : ".$modifiedData['loanAmount']." PD :".$pd_details['loan_amount']);
log_message('ERROR',"G-Sheet For PD Step 2.7 (Seventh Cell Amount) GSheet data : ".$GSdata["LoanAmount"]." PD :".$pd_details['loan_amount']);
}
if($i==8 && $GSdata[$i] != ""){
$product = explode('/', $GSdata[$i]);
$fk_product_id ="";
if(isset($GSdata["Product_SubProduct"]) && $GSdata["Product_SubProduct"] != ""){
$product = explode('/', $GSdata["Product_SubProduct"]);
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,trim($product[0]));
$pd_details['fk_product_id'] = $fk_product_id;
$pd_details['fk_subproduct_id'] = $this->Data_Dump_Model->getId(3,trim($product[1]));
$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,trim($product[0]));
$pd_details['fk_product_id'] = $product[0] ? $fk_product_id : null ;
}
log_message('ERROR',"G-Sheet For PD Step 2.8 (eighth Cell Product/SubProduct) GSheet data : ".$GSdata[$i]);
//." Modify : ".$modifiedData." PD :".$pd_details);
log_message('ERROR',"G-Sheet For PD Step 2.8 (eighth Cell Product/SubProduct) GSheet data : ".$GSdata["Product_SubProduct"]);
}
if($i==9 && $GSdata[$i] != ""){
$type = explode('/', $GSdata[$i]);
$modifiedData['type'] = ($type[0] != "") ? strtoupper(str_replace(' ', '', $type[0])) : "FULLPD";
$fk_customer_segment = "";
if(isset($GSdata["Type_CustomerSegment"]) && $GSdata["Type_CustomerSegment"] != ""){
$type = explode('/', $GSdata["Type_CustomerSegment"]);
$modifytype = ($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,trim($modifiedData['customerSegment']));
$pd_details['fk_pd_type'] = $modifytype == "FULLPD" ? 1 : ($modifytype == "SMARTPD" ? 2 :($modifytype == "TELEPD" ? 3 : 0) ) ;
$modifycustomerSegment = ($type[1] != "") ? $type[1] : null;
$fk_customer_segment = $this->Data_Dump_Model->getId(4,trim($modifycustomerSegment));
$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) ) ;
$pd_details['fk_pd_type'] = $modifytype == "FULLPD" ? 1 : ($modifytype == "SMARTPD" ? 2 :($modifytype == "TELEPD" ? 3 : 0) ) ;
}
log_message('ERROR',"G-Sheet For PD Step 2.9 (ninth Cell type/cs) GSheet data : ".$GSdata[$i]." Modify : ".$modifiedData['type']." PD :".$pd_details['fk_pd_type']);
}
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;
log_message('ERROR',"G-Sheet For PD Step 2.10 (tenth Cell initiationdate) GSheet data : ".$GSdata[$i]." Modify : ".$modifiedData['date']." PD :".$pd_details['pd_date_of_initiation']);
}
if($i==11 && $GSdata[$i] != ""){
$modifiedData['remarks'] = $GSdata[$i];
$pd_details['remarks'] = $GSdata[$i];
log_message('ERROR',"G-Sheet For PD Step 2.11 (eleventh Cell Remarks) GSheet data : ".$GSdata[$i]." Modify : ".$modifiedData['remarks']." PD :".$pd_details['remarks']);
log_message('ERROR',"G-Sheet For PD Step 2.9 (ninth Cell type/cs) GSheet data : ".$GSdata["Type_CustomerSegment"]." Modify : ".$modifytype." PD :".$pd_details['fk_pd_type']);
}
}
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["RemarksonCurrentStatus"]) && $GSdata["RemarksonCurrentStatus"] != ""){
$pd_details['remarks'] = "`Remarks on Current Status` : ".$GSdata["RemarksonCurrentStatus"];
log_message('ERROR',"G-Sheet For PD Step 2.11 (eleventh Cell Remarks) GSheet data : ".$GSdata["RemarksonCurrentStatus"]." PD :".$pd_details['remarks']);
}
if(isset($GSdata["PreviousRemarks"]) && $GSdata["PreviousRemarks"] != ""){
$pd_details['remarks'] = $pd_details['remarks']."\r\n `Previous Remarks` : ".$GSdata["PreviousRemarks"];
log_message('ERROR',"G-Sheet For PD Step 2.11 (eleventh Cell Remarks) GSheet data : ".$GSdata["RemarksonCurrentStatus"]." PD :".$pd_details['remarks']);
}
## 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);
@ -341,7 +323,6 @@ class Data_Dump_Controller extends REST_Controller {
$pd_details['random_string'] = $randomString;
$pd_details['is_notify_enabled'] = 1;
log_message('ERROR',"G-Sheet For PD Step 3 (Before Inserting Trigger)");
// PDdetails :".$pd_details);
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);
@ -350,7 +331,7 @@ class Data_Dump_Controller extends REST_Controller {
}
} catch (Exception $e) {
log_message('ERROR',"G-Sheet For PD Step 4 (PDID gotten) ERR : ".$e->getMessage());
var_dump($e->getMessage());
// var_dump($e->getMessage());
}
// $pd_id = 3073;
@ -375,7 +356,7 @@ class Data_Dump_Controller extends REST_Controller {
} 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());
// var_dump($e->getMessage());
}
}
@ -396,7 +377,7 @@ class Data_Dump_Controller extends REST_Controller {
}
} catch (Exception $e) {
log_message('ERROR',"G-Sheet For PD Step 6 (Addresses) ERR : ".$e->getMessage());
var_dump($e->getMessage());
// var_dump($e->getMessage());
}
$triggertbl_records = array('fk_primary_address_id'=>$address_id,'fk_address_id'=>$address_id);
@ -407,16 +388,11 @@ class Data_Dump_Controller extends REST_Controller {
throw new Exception('Error On updated Adresses Details in trigger table');
}
} catch (Exception $e) {
//alert the user.
log_message('ERROR',"G-Sheet For PD Step 7 (updateAddresses in trigger) ERR : ".$e->getMessage());
var_dump($e->getMessage());
// var_dump($e->getMessage());
}
}
// print_r($pd_details);
// print_r($modifiedData);
// print_r($addresses);
// print_r($pd_applicant_details);
// die();
log_message('ERROR',"#/# G-Sheet Final PDID : ".$pd_id);
return $pd_id;
}