diff --git a/api/application/controllers/Data_Dump_Controller.php b/api/application/controllers/Data_Dump_Controller.php index 3cea4004..5757df71 100644 --- a/api/application/controllers/Data_Dump_Controller.php +++ b/api/application/controllers/Data_Dump_Controller.php @@ -85,10 +85,44 @@ class Data_Dump_Controller extends REST_Controller { //[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("G-Sheet Fns Entered"); $sheetData = $this->post(); - // $reponse = $this->Data_Dump_Model->GsheetData($sheetData); - $modified = $this->modificationGsheetData($sheetData); - $reponse = $this->Data_Dump_Model->GsheetData($modified); + if(count($sheetData) > 0){ + $pd_id = $this->modificationGsheetData($sheetData); + if($pd_id != null || $pd_id != '') + { + + log_message("G-Sheet For PD ID : ".$pd_id,array('ENV'=>ENVIRONMENT)); + // PDALERTS::pdnotification($pd_id); + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['pdid'] = $pd_id; + $data['records'] = $pd_id; + $this->response($data,REST_Controller::HTTP_OK); + } + else + { + log_message("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("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; + // } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; @@ -100,7 +134,8 @@ class Data_Dump_Controller extends REST_Controller { } public function modificationGsheetData($GSdata){ - // echo count($GSdata); + // $logger = MYLOG::logFunction(null,"Gsheet"); + log_message("G-Sheet For PD Step 1 (G-sheet Data)",array('ENV'=>ENVIRONMENT,'DATA' => $GSdata)); $modifiedData = array(); $pd_details = array(); $pd_applicant_details = array(); @@ -112,63 +147,60 @@ class Data_Dump_Controller extends REST_Controller { // 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;$iENVIRONMENT,'MSG' => "INSIDE for Loop")); 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"; + $pd_details['sub_entity_id']=$fk_lender_id; + log_message("G-Sheet For PD Step 2.1 (First Cell lender/casebookedin)",array('ENV'=>ENVIRONMENT,'DATA' => $GSdata[$i],'ModifiedData'=>$modifiedData['lender'],'PDDetails'=>$pd_details)); } 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]; + log_message("G-Sheet For PD Step 2.2 (Second Cell - loan applicantid)",array('ENV'=>ENVIRONMENT,'DATA' => $GSdata[$i],'ModifiedData'=>$modifiedData,'PDDetails'=>$pd_details)); } 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;$j1){ + for($j=0;$j 0){ - $pd_applicant_details[0]['applicant_name'] = $GSdata[$i]; - $modifiedData['pd_applicant_details'][0]['applicant'] = $GSdata[$i]; - } + $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]['applicant_type'] = 1; + $modifiedData['pd_applicant_details'][0]['applicant_type'] = 1; + log_message("G-Sheet For PD Step 2.3 (Third Cell applicantdetails)",array('ENV'=>ENVIRONMENT,'DATA' => $GSdata[$i],'ModifiedData'=>$modifiedData,'Applicants'=>$pd_applicant_details)); } - + if($i==4 && $GSdata[$i] != ""){ $modifiedData['mobileNumber'] = $GSdata[$i]; + log_message("G-Sheet For PD Step 2.4 (Fourth Cell mobilenumber)",array('ENV'=>ENVIRONMENT,'DATA' => $GSdata[$i],'ModifiedData'=>$modifiedData['mobileNumber']));} 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]); + $pd_details['fk_state'] =$addresses['fk_state']; $modifiedData['pincode'] = $splitStateAndPincode[1]; $pin = $this->Data_Dump_Model->getId(6,$splitStateAndPincode[1]); $addresses['pincode'] = ($pin != "" ? $pin : 1); + $pd_details['pincode'] = $addresses['pincode']; $addresses['other_pincode']=($pin == "" ? $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,$city[0]); + $pd_details['fk_city']=$addresses['fk_city']; array_splice($NormalParts, -2);//removing city state and pincode. // $reversedParts = explode('-', strrev($GSdata[$i]), 2); // array_push($result_data["Pincode"],strrev($reversedParts[0])); @@ -176,13 +208,15 @@ class Data_Dump_Controller extends REST_Controller { // print_r(array_filter($NormalParts));// removing Null values $modifiedData['address'] = implode(",",array_filter($NormalParts)); $addresses['addressline1'] = implode(",",array_filter($NormalParts)); + $pd_details['addressline1']=$addresses['addressline1']; // echo "Original Address : ".$GSdata[$i]; // echo "Modified Address : ".$address; + log_message("G-Sheet For PD Step 2.5 (Fifth Cell address)",array('ENV'=>ENVIRONMENT,'DATA' => $GSdata[$i],'ModifiedData'=>$modifiedData['mobileNumber'],'PDDetails'=>$pd_details,'Address'=>$addresses)); } if($i==6 && $GSdata[$i] != ""){ $modifiedData['createdPerson'] = $GSdata[$i]; $pd_details['fk_createdby'] = $this->Data_Dump_Model->getId(8,$GSdata[$i]); - + log_message("G-Sheet For PD Step 2.6 (Sixth Cell createdPerson)",array('ENV'=>ENVIRONMENT,'DATA' => $GSdata[$i],'ModifiedData'=>$modifiedData['createdPerson'],'PDDetails'=>$pd_details)); } if($i==7 && ($GSdata[$i] != "" || $GSdata[$i] != 0)){ $amount = strtolower($GSdata[$i]); @@ -210,6 +244,7 @@ class Data_Dump_Controller extends REST_Controller { }} $modifiedData['loanAmount'] = implode("",$amount); $pd_details['loan_amount'] = implode("",$amount); + log_message("G-Sheet For PD Step 2.7 (Seventh Cell Amount)",array('ENV'=>ENVIRONMENT,'DATA' => $GSdata[$i],'ModifiedData'=>$modifiedData['loanAmount'],'PDDetails'=>$pd_details)); } if($i==8 && $GSdata[$i] != ""){ $product = explode('/', $GSdata[$i]); @@ -226,6 +261,7 @@ class Data_Dump_Controller extends REST_Controller { $fk_product_id = $this->Data_Dump_Model->getId(2,$product[0]); $pd_details['fk_product_id'] = $product[0] ? $fk_product_id : null ; } + log_message("G-Sheet For PD Step 2.8 (eighth Cell Product/SubProduct)",array('ENV'=>ENVIRONMENT,'DATA' => $GSdata[$i],'ModifiedData'=>$modifiedData,'PDDetails'=>$pd_details)); } if($i==9 && $GSdata[$i] != ""){ $type = explode('/', $GSdata[$i]); @@ -238,19 +274,23 @@ class Data_Dump_Controller extends REST_Controller { }else{ $pd_details['fk_pd_type'] = $modifiedData['type'] == "FULLPD" ? 1 : ($modifiedData['type'] == "SMARTPD" ? 2 :($modifiedData['type'] == "TELEPD" ? 3 : 0) ) ; } + log_message("G-Sheet For PD Step 2.9 (ninth Cell type/cs)",array('ENV'=>ENVIRONMENT,'DATA' => $GSdata[$i],'ModifiedData'=>$modifiedData,'PDDetails'=>$pd_details)); } 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("G-Sheet For PD Step 2.10 (tenth Cell initiationdate)",array('ENV'=>ENVIRONMENT,'DATA' => $GSdata[$i],'ModifiedData'=>$modifiedData['date'],'PDDetails'=>$pd_details)); } if($i==11 && $GSdata[$i] != ""){ $modifiedData['remarks'] = $GSdata[$i]; $pd_details['remarks'] = $GSdata[$i]; + log_message("G-Sheet For PD Step 2.11 (eleventh Cell Remarks)",array('ENV'=>ENVIRONMENT,'DATA' => $GSdata[$i],'ModifiedData'=>$GSdata[$i],'PDDetails'=>$pd_details)); } } + ## Default Status section; $pd_details['pd_status'] = TRIGGERED; @@ -258,13 +298,13 @@ class Data_Dump_Controller extends REST_Controller { $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); + $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->PD_Model->selectCustomRecords(array('*'),array('customer_segment_id' => $pd_details['fk_customer_segment'],'isactive' => 1),CUSTOMERSEGMENT); + { $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) @@ -291,53 +331,82 @@ class Data_Dump_Controller extends REST_Controller { } $pd_details['random_string'] = $randomString; $pd_details['is_notify_enabled'] = 1; - $pd_id = $this->PD_Model->saveRecords($pd_details,PDTRIGGER); - // $pd_id = 0; + log_message("G-Sheet For PD Step 3 (Before Inserting Trigger)",array('ENV'=>ENVIRONMENT,'DATA' => $pd_details)); + try { + $pd_id = $this->Data_Dump_Model->saveRecords($pd_details,PDTRIGGER); + log_message("G-Sheet For PD Step 4 (PDID gotten)",array('ENV'=>ENVIRONMENT,'PDID' => $pd_id)); + if(empty($pd_id)) { + throw new Exception('Error On Inserting TRIGGER details'); + } + } catch (Exception $e) { + log_message("G-Sheet For PD Step 4 (PDID gotten)",array('ENV'=>ENVIRONMENT,'ERR' => $e->getMessage())); + var_dump($e->getMessage()); + } + // $pd_id = 3073; + + if($pd_id != null || $pd_id != '') { if($pd_applicant_details != "" || $pd_applicant_details != null) { + log_message("G-Sheet For PD Step 5 (applicant)",array('ENV'=>ENVIRONMENT,'Applicant' => $pd_applicant_details)); foreach($pd_applicant_details as $pd_applicant_detail) { - $pd_applicant_detail['fk_pd_id'] = null; + $pd_applicant_detail['fk_pd_id'] = $pd_id; $pd_applicant_detail['applicant_name'] = trim(MYUTIL::applicantNameCamelCaseConvertion($pd_applicant_detail['applicant_name'])); - $pd_applicant_detail['company_name'] = trim(MYUTIL::applicantNameCamelCaseConvertion($pd_applicant_detail['company_name'])); - - $co_applicant_id = $this->PD_Model->saveRecords($pd_applicant_detail,PDAPPLICANTSDETAILS); - if($co_applicant_id != null || $co_applicant_id != '') - { - $count = $count + 1; - } + if($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("G-Sheet For PD Step 5.1 (applicant pkid)",array('ENV'=>ENVIRONMENT,'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("G-Sheet For PD Step 5.1 (applicant pkid)",array('ENV'=>ENVIRONMENT,'ERR' => $e->getMessage())); + var_dump($e->getMessage()); + } + } + } } - ## 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; - // } - } - }} + 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("G-Sheet For PD Step 6 (Addresses)",array('ENV'=>ENVIRONMENT,'addresses' => $addresses,"addressId"=>$address_id)); + if(empty($address_id)) { + throw new Exception('Error On Inserting Adresses details'); + } + } catch (Exception $e) { + log_message("G-Sheet For PD Step 6 (Addresses)",array('ENV'=>ENVIRONMENT,'ERR'=>$e->getMessage())); + var_dump($e->getMessage()); + } + $triggertbl_records = array('fk_primary_address_id'=>$address_id,'fk_address_id'=>$address_id); + + try { + $this->Data_Dump_Model->updateRecords($triggertbl_records,PDTRIGGER,array('pd_id' => $pd_id)); + log_message("G-Sheet For PD Step 7 (updateAddresses in trigger)",array('ENV'=>ENVIRONMENT)); + 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) { + //alert the user. + log_message("G-Sheet For PD Step 7 (updateAddresses in trigger)",array('ENV'=>ENVIRONMENT,'ERR'=>$e->getMessage())); + var_dump($e->getMessage()); + } + } + // print_r($pd_details); // print_r($modifiedData); // print_r($addresses); // print_r($pd_applicant_details); - // print_r($address); - // die(); + // die(); return $pd_id; } } \ No newline at end of file diff --git a/api/application/models/Data_Dump_Model.php b/api/application/models/Data_Dump_Model.php index db539205..f492128d 100755 --- a/api/application/models/Data_Dump_Model.php +++ b/api/application/models/Data_Dump_Model.php @@ -123,14 +123,15 @@ class Data_Dump_Model extends SPARQ_Model { public function getId($flag,$keyword){ // echo "flag".$flag; - $keyword = str_replace(" ", "",$keyword); + $value = str_replace(" ", "",$keyword); if($flag == 1){ // "entity_id": "16", // "full_name": "Clix Capital Services Private Limited", // "short_name": "CLIX", $select = "entity_id";$table = "m_entity";$where = "short_name";} if($flag == 2){$select = "product_id"; $table = "m_products"; $where = "abbr";} - if($flag == 3){$select = "subproduct_id"; $table = "m_subproducts"; $where = "abbr";} + if($flag == 3){$value = $keyword; + $select = "subproduct_id"; $table = "m_subproducts"; $where = "abbr";} if($flag == 4){$select = "customer_segment_id"; $table = "m_customer_segment"; $where = "abbr";} if($flag ==5 ){$select = "state_id"; $table = "m_states"; $where = "name";} if($flag ==6 ){$select = "pincode_id";$where = "pincode";$table = "m_pincode";} @@ -139,9 +140,9 @@ class Data_Dump_Model extends SPARQ_Model { $this->db->select($select); $this->db->from($table); - $this->db->where($where." LIKE '%$keyword%'"); + $this->db->where($where." LIKE '%$value%'"); $this->db->where("isactive",1); - + // print_r($this->db->last_query());die(); $row = $this->db->get()->row(); if (isset($row)) { $id = $row->$select;