From 38474870aa952515e4d5b82e9efb25c26ff49509 Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Fri, 17 Jun 2022 15:55:45 +0530 Subject: [PATCH] Saveflyhi pd api is changed as per savesales pd --- api/application/config/routes.php | 1 + .../controllers/Flyhi_Controller.php | 323 +++++++++++++++++- 2 files changed, 323 insertions(+), 1 deletion(-) diff --git a/api/application/config/routes.php b/api/application/config/routes.php index 0d0721bd..a27daeb8 100755 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -388,5 +388,6 @@ $route['getFlyhiProductList'] = 'Flyhi_Controller/productMasterForFlyhiPD'; $route['getFlyhiLenderList'] = 'Flyhi_Controller/lenderMasterForFlyhiPD'; $route['saveFlyhiPDImage'] = 'Flyhi_Controller/saveFlyhiPDImage'; $route['getFlyhiPDImgDataCusLink']='Flyhi_Controller/getFlyhiPDImgDataCusLink'; +$route['saveFlyhiPDsection'] = 'Flyhi_Controller/saveFlyhiPDsection'; diff --git a/api/application/controllers/Flyhi_Controller.php b/api/application/controllers/Flyhi_Controller.php index 264352f1..e0b3b292 100644 --- a/api/application/controllers/Flyhi_Controller.php +++ b/api/application/controllers/Flyhi_Controller.php @@ -243,7 +243,7 @@ class Flyhi_Controller extends REST_Controller { } } - public function saveFlyhiPD_post() + public function saveFlyhiPDOLD_post() { $records = $this->post('records'); $is_entry_done = null; @@ -1049,5 +1049,326 @@ class Flyhi_Controller extends REST_Controller { $this->response($data,REST_Controller::HTTP_OK); } + public function saveFlyhiPD_post() + { + $records = $this->post('records'); + + $applicant_id = null; + $applicant_name = null; + $city = null; + $lender_id = null; + $loan_amount = null; + $pd_branch_id = null; + $lender_sales_person = null; + $lender_credit_person = null; + $product_id = null; + $is_entry_done = null; + $id = null; + // print_r($records);//die(); + log_message('ERROR','####FLYHIPD SAVE CALLED'); + $lender_short_name = $this->Flyhi_Model->selectCustomRecords(array('short_name'),array('entity_id' => $records['lender_id']),ENTITY); + + $product_short_name = $this->Flyhi_Model->selectCustomRecords(array('abbr'),array('product_id' => $records['product_id']),PRODUCTS); + + $section_names = array('1' => 'General Section','2' => 'Photography'); + + $count = $this->Flyhi_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $records['lender_id'],'product_id' => $records['product_id'],'isactive' => 1),SALES_PD_DATA); + + if($records['sales_pd_id'] == '' || $records['sales_pd_id'] == null) + { + /************ASSIGN Random URL******************/ + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < 16; $i++) + { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + $records['rand_string'] = $randomString; + log_message('ERROR','####INSERT NEW FLYHIPD'); + $salepd_serial_no = count($lender_short_name)? $lender_short_name[0]['short_name']:'UNKNOWN'; + $salepd_serial_no .= count($product_short_name)? '-'.$product_short_name[0]['abbr']:'-UNKNOWN'; + $salepd_serial_no .= '-'.(++$count[0]['count']); + + $records['sales_pd_sno'] = $salepd_serial_no; + + $id = $this->Flyhi_Model->saveRecords($records,SALES_PD_DATA); + + } + else + { + //echo $product_short_name[0]['abbr']; + if(isset($records['status']) && $records['status'] == 'COMPLETED') + { + log_message('ERROR','####COMPLETE FLYHIPD'.$records['sales_pd_id']); + $drafted_sections = $this->Flyhi_Model->selectCustomRecords(array('section_id'),array('status' => 0,'sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALESPD_SECTION_DATA); + + $completed_sections = $this->Flyhi_Model->selectCustomRecords(array('section_id'),array('status' => 1,'sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALESPD_SECTION_DATA); + + $img_satellite_check = $this->Flyhi_Model->selectCustomRecords(array('count(*) as count'),array('img_name' => 'satellite','fk_sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALEPD_DOCS); + + $img_selfile_check = $this->Flyhi_Model->selectCustomRecords(array('count(*) as count'),array('img_name' => 'selfie_with_person_met','fk_sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALEPD_DOCS); + + + $dup_of_section_names = $section_names; + // print_r($dup_of_section_names); + foreach ($completed_sections as $completed_section_key => $completed_section_value) + { + if($dup_of_section_names [ $completed_section_value['section_id'] ] ) + { + unset($dup_of_section_names [ $completed_section_value['section_id'] ]); + } + } + + // print_r($dup_of_section_names); + unset($dup_of_section_names[2]);//unset photograph always + + + if(count($dup_of_section_names)) + { + $res_data = array(); + foreach ($dup_of_section_names as $key => $value) + { + $res_data[] = array('section_id' => $key,'sectin_name' => $section_names[$key]); + } + $data['dataStatus'] = true; + $data['records'] = $res_data; + $data['pd_status'] = 'DRAFT'; + $data['status'] = REST_Controller::HTTP_OK; + $this->response($data,REST_Controller::HTTP_OK); + } + + + + if(count($drafted_sections) ) + { + + + + $drafted_sections = array_map(function($single) use ($section_names) + { + return array('section_id' => $single['section_id'],'sectin_name' => $section_names [ $single['section_id'] ]); + }, + $drafted_sections); + + //print_r($drafted_sections);die(); + + unset($records['status']); + $data['dataStatus'] = true; + $data['records'] = $drafted_sections; + $data['pd_status'] = 'DRAFT'; + $data['status'] = REST_Controller::HTTP_OK; + $this->response($data,REST_Controller::HTTP_OK); + } + else if($img_satellite_check[0]['count'] == 0 || $img_selfile_check[0]['count'] == 0) + { + unset($records['status']); + $data['dataStatus'] = true; + $data['records'][] = array('section_id' => 2,'section_name' => 'selfie image'); + $data['pd_status'] = 'DRAFT'; + $data['status'] = REST_Controller::HTTP_OK; + $this->response($data,REST_Controller::HTTP_OK); + } + + + else + { + $records['status'] = 'COMPLETED'; + $records['is_cus_link_disabled'] = 1; + $records['completed_date'] = date('Y-m-d H:i:s'); + //echo 'final';die(); + $id = $this->Flyhi_Model->updateRecords($records,SALES_PD_DATA,array('sales_pd_id' => $records['sales_pd_id'])); + + //CAMUNDA::completeSalesPDTask($records['sales_pd_id']); + + $this->prepareFlyhiPDReport($records['sales_pd_id'],false); + sleep(10); + log_message('ERROR','####FlyHiPD AFTER 10 PREPARED REPORT'.$records['sales_pd_id']); + + // $city = ''; + // $form = $this->Flyhi_Model->selectCustomRecords(array(),array('isactive' => 1,'sales_pd_id' => $records['sales_pd_id'],'section_id' => 1,'status' => 1),SALESPD_SECTION_DATA); + // $gen_form = json_decode($form[0]['section_data'],true); + // if(!empty($gen_form)){ + // foreach ($gen_form['questions'] as $g_key => $g_value) + // { + // // if($g_value['question_key'] == 'state') + // // { + // // $ids_to_send_mail['state'] = $g_value['answer_value']; + // // } + // if($g_value['question_key'] == 'city') + // { + // $city = $g_value['answer_value']; + // } + // } + // }//gen_form closed here. + // PDALERTS::sendSalesPDMail($this,$records['sales_pd_id'],$city); + } + + } + else + { + log_message('ERROR','####UPDATE FLYHIPD'.$records['sales_pd_id']); + $id = $this->Flyhi_Model->updateRecords($records,SALES_PD_DATA,array('sales_pd_id' => $records['sales_pd_id'])); + + } + + } + + if($id) + { + $data['dataStatus'] = true; + $data['records'] = $id; + $data['status'] = REST_Controller::HTTP_OK; + if(isset($records['rand_string'])){ $data['rand_string'] = $records['rand_string']; } + $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); + } + + } + + public function saveFlyhiPDsection_post() + { + $records = $this->post('records'); + $sales_pd_id = $records['sales_pd_id']; + $section_id = $records['section_id']; + $fk_createdby = $records['fk_createdby']; + $status = $records['is_complete']; + $section_data = json_encode($records); + + //Get Sales PD master Data + + $columns = array('SALES_PD_DATA.*','ENTITY.short_name','PRODUCT.abbr'); + $table = SALES_PD_DATA.' as SALES_PD_DATA'; + $joins = array( + array('table' => ENTITY. ' as ENTITY', + 'condition' =>'SALES_PD_DATA.lender_id = ENTITY.entity_id', + 'jointype' => 'INNER'), + array('table' => PRODUCTS. ' as PRODUCT', + 'condition' =>'SALES_PD_DATA.product_id = PRODUCT.product_id', + 'jointype' => 'INNER') + ); + + $where_condition_array = array('SALES_PD_DATA.sales_pd_id' => $sales_pd_id); + $sales_pd_master_data = $this->Flyhi_Model->getJoinRecords($columns,$table,$joins,$where_condition_array); + + //pre process works + switch($section_id) + { + case 1: //General section + //update Applicant ID and applicant Name to sales pD master Table + $city = ''; + if($records['questions']) + { + foreach ($records['questions'] as $g_key => $g_value) + { + if(isset($g_value['question_key']) && $g_value['question_key'] === 'loan_application_id') + { + $applicant_id = $g_value['answer_value'] ? $g_value['answer_value'] : 'Not Provided'; + } + if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_name') + { + $lender_id = $g_value['answer_value']; + } + if(isset($g_value['question_key']) && $g_value['question_key'] == 'loan_amount') + { + $loan_amount = $g_value['answer_value']; + } + if(isset($g_value['question_key']) && $g_value['question_key'] == 'branch') + { + $pd_branch_id = $g_value['answer_value']; + } + if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_sales_person') + { + $lender_sales_person = $g_value['answer_value']; + } + if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_credit_person') + { + $lender_credit_person = $g_value['answer_value']; + } + if(isset($g_value['question_key']) && $g_value['question_key'] == 'product_name') + { + $product_id = $g_value['answer_value']; + } + if(isset($g_value['question_key']) && $g_value['question_key'] == 'verification_type') + { + if(isset($g_value['onchange_properties'])) + { + foreach ($g_value['onchange_properties'] as $h_key => $h_value) + { + foreach ($h_value['form_controls'] as $i_key => $i_value) + { + foreach ($i_value['questions'] as $j_key => $j_value) + { + if($g_value['answer_value'] == 'Residence verification' && $j_value['question_key'] == 'residence_city'){ + $city = $j_value['answer_value']; + $flyhi_pd_type = 4; + } + if($g_value['answer_value'] == 'Office verification' && $j_value['question_key'] == 'officer_city'){ + $city = $j_value['answer_value']; + $flyhi_pd_type = 3; + } + // if($g_value['answer_value'] == 'Office verification' && $j_value['question_key'] == 'employer_business_name') + // { + // $applicant_name = $j_value['answer_value']; + // } + } + } + } + } + } + + } + + } + + $FLYHI_PD['applicant_id'] = $applicant_id; + $FLYHI_PD['city_id']=$city; + $FLYHI_PD['sales_pd_sno'] = $flyhipd_serial_no; + $FLYHI_PD['loan_amount'] = $loan_amount; + $FLYHI_PD['lender_sales_person'] = $lender_sales_person ; + $FLYHI_PD['lender_credit_person'] = $lender_credit_person ; + $FLYHI_PD['pd_branch_id'] = $pd_branch_id; + $FLYHI_PD['lender_id'] = $lender_id; + $FLYHI_PD['sales_pd_type'] = $flyhi_pd_type; + $FLYHI_PD['product_id'] = $product_id ? $product_id : (ENVIRONMENT == 'production' ? 27 : 26); + $this->Flyhi_Model->updateRecords($FLYHI_PD,SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id)); + + + break; + + case 2: //photosection + break; + + default: + } + + //make inactive previous records + $this->Flyhi_Model->updateRecords(array('isactive' => 0),SALESPD_SECTION_DATA,array('sales_pd_id' =>$sales_pd_id,'section_id' => $section_id )); + + //insert new record + $fields = array('sales_pd_id' => $sales_pd_id, 'section_id' => $section_id, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby); + $is_entry_created = $this->Flyhi_Model->saveRecords($fields,SALESPD_SECTION_DATA); + if($is_entry_created) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $is_entry_created; + $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); + } + } + }// Class Ends