From efd0eb7e517e00b68541a5553abc12e6d37cc034 Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Thu, 9 Jun 2022 18:21:08 +0530 Subject: [PATCH] Save flyhi : ps --- .../controllers/Flyhi_Controller.php | 262 +++++++++++------- 1 file changed, 155 insertions(+), 107 deletions(-) diff --git a/api/application/controllers/Flyhi_Controller.php b/api/application/controllers/Flyhi_Controller.php index 575ae5f0..bd1c2d49 100644 --- a/api/application/controllers/Flyhi_Controller.php +++ b/api/application/controllers/Flyhi_Controller.php @@ -15,9 +15,12 @@ class Flyhi_Controller extends REST_Controller { public function listFlyhiPD_get(){ - $user_id = $this->uri->segment(3); + $user_id = $this->uri->segment(1); $columns = array('SALES_PD_DATA.sales_pd_id','SALES_PD_DATA.sales_pd_sno','SALES_PD_DATA.applicant_name','concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as officer_name','SALES_PD_DATA.applicant_id','SALES_PD_DATA.lender_id','SALES_PD_DATA.is_pdf','SALES_PD_DATA.is_edited','ENTITY.full_name','ENTITY.short_name','SALES_PD_DATA.status','SALES_PD_DATA.sales_pd_type','SALES_PD_DATA.rand_string','SALES_PD_DATA.isactive','SALES_PD_DATA.city_id','CITY.name as city_name', + 'SALES_PD_DATA.lender_sales_person','concat(LENDERSALESPERSON.first_name," ",LENDERSALESPERSON.last_name) as lender_sales_person_name','LENDERSALESPERSON.mobile_no as lender_sales_contact_mobileno','LENDERSALESPERSON.email as lender_sales_person_email', + 'SALES_PD_DATA.lender_credit_person','concat(LENDERCREDITPERSON.first_name," ",LENDERCREDITPERSON.last_name) as lender_credit_person_name','LENDERCREDITPERSON.mobile_no as lender_credit_person_contact_mobileno','LENDERCREDITPERSON.email as lender_credit_person_email', + 'SALES_PD_DATA.pd_branch_id,ENTITYLENDERBRANCH.branch_name','SALES_PD_DATA.loan_amount', '(CASE WHEN SALES_PD_DATA.status = "STARTED" THEN SALES_PD_DATA.createdon WHEN SALES_PD_DATA.status = "COMPLETED" THEN SALES_PD_DATA.completed_date ELSE NULL END) AS createdon'); $table = SALES_PD_DATA.' as SALES_PD_DATA'; @@ -30,6 +33,15 @@ class Flyhi_Controller extends REST_Controller { 'jointype' => 'LEFT'), array('table' => USERPROFILE. ' as USERPROFILE', 'condition' =>'SALES_PD_DATA.createdby = USERPROFILE.userid', + 'jointype' => 'LEFT'), + array('table' => USERPROFILE. ' as LENDERSALESPERSON', + 'condition' =>'SALES_PD_DATA.lender_sales_person = LENDERSALESPERSON.userid', + 'jointype' => 'LEFT'), + array('table' => USERPROFILE. ' as LENDERCREDITPERSON', + 'condition' =>'SALES_PD_DATA.lender_credit_person = LENDERCREDITPERSON.userid', + 'jointype' => 'LEFT'), + array('table' => ENTITYLENDERBRANCH. ' as ENTITYLENDERBRANCH', + 'condition' =>'SALES_PD_DATA.pd_branch_id = ENTITYLENDERBRANCH.entity_lender_branch_id', 'jointype' => 'LEFT') ); @@ -70,24 +82,29 @@ class Flyhi_Controller extends REST_Controller { public function saveFlyhiPD_post() { - $records = $this->post('records'); - $is_entry_done = null; - $id = null; - - log_message('ERROR','####FLYHI-PD SAVE CALLED'); - $lender_short_name = $this->Flyhi_Model->selectCustomRecords(array('short_name'),array('entity_id' => $records['lender_id']),ENTITY); + $records = $this->post('records'); + $is_entry_done = null; + $flyhi_pd_id = null; + $section_data = json_encode($records); + $fk_createdby = $records['fk_createdby']; + $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; - // $section_names = array('1' => 'General Section','2' => 'Photography'); - $section_names = array('1' => 'General Section'); + log_message('ERROR','####FLYHI-PD SAVE CALLED'); + + // $section_names = array('1' => 'General Section','2' => 'Photography'); + $section_names = array('1' => 'General Section'); - // here i get the counts. - $count = $this->Flyhi_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $records['lender_id'],'isactive' => 1),SALES_PD_DATA); + if($records['sales_pd_id'] == '' || $records['sales_pd_id'] == null) + { - // If Condition inserting Data in Master Table - if($records['sales_pd_id'] == '' || $records['sales_pd_id'] == null) - { - - /************ASSIGN Random URL******************/ + /************ASSIGN Random URL******************/ $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-'; $charactersLength = strlen($characters); $randomString = ''; @@ -95,110 +112,141 @@ class Flyhi_Controller extends REST_Controller { { $randomString .= $characters[rand(0, $charactersLength - 1)]; } + $records['rand_string'] = $randomString; log_message('ERROR','####INSERT NEW FLYHIPD'); - $salepd_serial_no .= 'FHFSL-'.(++$count[0]['count']); - - $records['sales_pd_sno'] = $salepd_serial_no; - // print_r($records);die(); - $id = $this->Flyhi_Model->saveRecords($records,SALES_PD_DATA); - - //start camunda process - //CAMUNDA::startSalesPDInstance($id); - } - else - { + if($records['questions']) + { + foreach ($records['questions'] as $g_key => $g_value) + { + if($g_value['question_key'] == 'application_id') + { + $applicant_id = $g_value['answer_value'] ? $g_value['answer_value'] : 'Not Provided'; + } + if($g_value['question_key'] == 'company_name') + { + $applicant_name = $g_value['answer_value']; + } + if($g_value['question_key'] == 'city') + { + $city = $g_value['answer_value']; + } + if($g_value['question_key'] == 'lender_id') + { + $lender_id = $g_value['answer_value']; + } + if($g_value['question_key'] == 'loan_amount') + { + $loan_amount = $g_value['answer_value']; + } + if($g_value['question_key'] == 'pd_branch_id') + { + $pd_branch_id = $g_value['answer_value']; + } + if($g_value['question_key'] == 'lender_sales_person') + { + $lender_sales_person = $g_value['answer_value']; + } + if($g_value['question_key'] == 'lender_credit_person') + { + $lender_credit_person = $g_value['answer_value']; + } + + } + } + $count = $this->Flyhi_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $lender_id,'isactive' => 1),SALES_PD_DATA); + $lender_short_name = $this->Flyhi_Model->selectCustomRecords(array('short_name'),array('entity_id' => $lender_id),ENTITY); + $salepd_serial_no = 'FHFSL-'.(++$count[0]['count']); + + $FLYHI_PD['applicant_id'] = $applicant_id; + $FLYHI_PD['city_id']=$city; + $FLYHI_PD['sales_pd_sno'] = $salepd_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_id = $this->Flyhi_Model->saveRecords($FLYHI_PD,SALES_PD_DATA); + $section_data = json_encode($records); + $this->Sales_PD_Model->updateRecords(array('isactive' => 0),SALESPD_SECTION_DATA,array('sales_pd_id' =>$flyhi_pd_id,'section_id' => 1 )); + $status = $records['is_complete']; + $fields = array('sales_pd_id' => $flyhi_pd_id, 'section_id' => 1, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby); + $is_entry_done = $this->Sales_PD_Model->saveRecords($fields,SALESPD_SECTION_DATA); + } + + else + { if(isset($records['status']) && $records['status'] == 'COMPLETED') { log_message('ERROR','####COMPLETE FLYHI-PD'.$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); + $records['status'] = 'COMPLETED'; + $records['is_cus_link_disabled'] = 1; + $records['completed_date'] = date('Y-m-d H:i:s'); + $flyhi_pd_id = $this->Flyhi_Model->updateRecords($records,SALES_PD_DATA,array('sales_pd_id' => $records['sales_pd_id'])); $completed_sections = $this->Flyhi_Model->selectCustomRecords(array('section_id'),array('status' => 1,'sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALESPD_SECTION_DATA); - // print_r($completed_sections);die(); - - $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'] ]); - } - } - - unset($dup_of_section_names[9]);//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); - - 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 - { - $records['status'] = 'COMPLETED'; - $records['is_cus_link_disabled'] = 1; - $records['completed_date'] = date('Y-m-d H:i:s'); - $id = $this->Flyhi_Model->updateRecords($records,SALES_PD_DATA,array('sales_pd_id' => $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'] == 'city') - { - $city = $g_value['answer_value']; - } - } - }//gen_form closed here. - } - } 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'])); + // $gen_form = json_decode($form[0]['section_data'],true); + $flyhi_pd_id = $records['sales_pd_id']; - } - - } - - if($id) + if($records['questions']){ + foreach ($records['questions'] as $g_key => $g_value) + { + if($g_value['question_key'] == 'application_id') + { + $applicant_id = $g_value['answer_value'] ? $g_value['answer_value'] : 'Not Provided'; + } + if($g_value['question_key'] == 'company_name') + { + $applicant_name = $g_value['answer_value']; + } + if($g_value['question_key'] == 'city') + { + $city = $g_value['answer_value']; + } + if($g_value['question_key'] == 'lender_id') + { + $lender_id = $g_value['answer_value']; + } + if($g_value['question_key'] == 'loan_amount') + { + $loan_amount = $g_value['answer_value']; + } + if($g_value['question_key'] == 'pd_branch_id') + { + $pd_branch_id = $g_value['answer_value']; + } + if($g_value['question_key'] == 'lender_sales_person') + { + $lender_sales_person = $g_value['answer_value']; + } + if($g_value['question_key'] == 'lender_credit_person') + { + $lender_credit_person = $g_value['answer_value']; + } + } + } + $FLYHI_PD['applicant_name'] = $applicant_name; + $FLYHI_PD['applicant_id'] = $applicant_id; + $FLYHI_PD['city_id']=$city; + $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_id = $this->Flyhi_Model->updateRecords($FLYHI_PD,SALES_PD_DATA,array('sales_pd_id' => $records['sales_pd_id'])); + $status = $records['is_complete']; + $fields = array('sales_pd_id' => $flyhi_pd_id, 'section_id' => 1, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby); + $is_entry_done = $this->Sales_PD_Model->saveRecords($fields,SALESPD_SECTION_DATA); + } // else 179 + } // else 167 + if($flyhi_pd_id) { $data['dataStatus'] = true; - $data['records'] = $id; + $data['records'] = $flyhi_pd_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);