diff --git a/api/application/config/constants.php b/api/application/config/constants.php index 2eb2ad76..9e815e35 100644 --- a/api/application/config/constants.php +++ b/api/application/config/constants.php @@ -655,6 +655,7 @@ defined('SMC_CREDIT_PD_SECTION_DATA') OR define('SMC_CREDIT_PD_SECTION_DATA','t_ defined('VIDEO_ROOM_INFO') OR define('VIDEO_ROOM_INFO','t_video_room_info'); defined('SMC_EXCEL_FILELIST') OR define('SMC_EXCEL_FILELIST','t_smc_excel_filelist'); defined('EXCEL_COLUMN_REF_NAME') OR define('EXCEL_COLUMN_REF_NAME','t_excel_column_ref_name'); +defined('SMC_CREDIT_PD_FORMS') OR define('SMC_CREDIT_PD_FORMS','m_smc_credit_pd_forms'); diff --git a/api/application/config/routes.php b/api/application/config/routes.php index 13afb5c0..d609830f 100644 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -304,4 +304,5 @@ $route['saveSMCCreditPDImage'] = 'SMC_Credit_PD_Controller/saveSMCCreditPDImage' $route['saveSMCCreditPDsection'] = 'SMC_Credit_PD_Controller/saveSMCCreditPDsection'; $route['getSMCCreditPDSectionData'] = 'SMC_Credit_PD_Controller/getSMCCreditPDSectionData'; $route['getStakeHoldersInfo'] = 'SMC_Credit_PD_Controller/getStakeHoldersInfo'; +$route['loadSMCPDTemplate'] = 'SMC_Credit_PD_Controller/loadSMCPDTemplate'; diff --git a/api/application/controllers/SMC_Credit_PD_Controller.php b/api/application/controllers/SMC_Credit_PD_Controller.php index f5b6eeee..a1cfc973 100644 --- a/api/application/controllers/SMC_Credit_PD_Controller.php +++ b/api/application/controllers/SMC_Credit_PD_Controller.php @@ -18,6 +18,7 @@ class SMC_Credit_PD_Controller extends REST_Controller { // Construct the parent class parent::__construct(); $this->load->model('SMC_Credit_PD_Model'); + $this->load->model('PD_Model'); $this->external_path = $this->config->item('external_data_path'); $this->load->library('AWS_S3'); $this->load->library('pdfgenerator'); @@ -673,213 +674,302 @@ class SMC_Credit_PD_Controller extends REST_Controller { } + // public function saveSMCCreditPDsection_post() + // { + // $records = $this->post('records'); + // $smc_credit_pd = $records['smc_credit_pd']; + // $section_id = $records['section_id']; + // $fk_createdby = $records['fk_createdby']; + // //$status = $records['is_complete']; + // $status = 1; + // $section_data = json_encode($records); + + // //Get Sales PD master Data + + // $columns = array('SMC_CREDIT_PD.*','ENTITY.short_name','PRODUCT.abbr'); + // $table = SMC_CREDIT_PD.' as SMC_CREDIT_PD'; + // $joins = array( + // array('table' => ENTITY. ' as ENTITY', + // 'condition' =>'SMC_CREDIT_PD.lender_id = ENTITY.entity_id', + // 'jointype' => 'INNER'), + // array('table' => PRODUCTS. ' as PRODUCT', + // 'condition' =>'SMC_CREDIT_PD.product_id = PRODUCT.product_id', + // 'jointype' => 'INNER') + // ); + + // $where_condition_array = array('SMC_CREDIT_PD.smc_credit_pd' => $smc_credit_pd); + // $sales_pd_master_data = $this->SMC_Credit_PD_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 + // $applicant_id = null; + // $applicant_name = ''; + // 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']; + // } + + + // } + // } + + // $update_fields = array('applicant_name' => $applicant_name,'applicant_id' => $applicant_id); + // $this->SMC_Credit_PD_Model->updateRecords($update_fields,SMC_CREDIT_PD,array('smc_credit_pd' => $smc_credit_pd)); + + + // break; + + // case 2: //Fund Requirement + // break; + + // case 3: //stakeholders + // break; + + // case 4: //brief of business + // break; + + // case 5: //Financial + // break; + + // case 6: //property + // break; + + // case 7: //Officer self details + // break; + + // case 8: //final remarks of PD officer + // //update PD officer Name to sales pD master Table + // $officer = ''; + // if($records['questions']) + // { + // foreach($records['questions'] as $g_key => $g_value) + // { + // if($g_value['question_key'] == 'name_of_sales_team_member') + // { + // $officer = $g_value['answer_value']; + // break; + // } + + // } + // } + // $update_fields = array('officer_name' => $officer); + // $this->SMC_Credit_PD_Model->updateRecords($update_fields,SMC_CREDIT_PD,array('smc_credit_pd' => $smc_credit_pd)); + // break; + + // case 9: //photosection + // break; + + // default: + // } + + // //make inactive previous records + // $this->SMC_Credit_PD_Model->updateRecords(array('isactive' => 0),SMC_CREDIT_PD_SECTION_DATA,array('smc_credit_pd' =>$smc_credit_pd,'section_id' => $section_id )); + + // //insert new record + // $fields = array('smc_credit_pd' => $smc_credit_pd, 'section_id' => $section_id, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby); + // $is_entry_created = $this->SMC_Credit_PD_Model->saveRecords($fields,SMC_CREDIT_PD_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); + + // } + + + // } + public function saveSMCCreditPDsection_post() { $records = $this->post('records'); - $smc_credit_pd = $records['smc_credit_pd']; - $section_id = $records['section_id']; - $fk_createdby = $records['fk_createdby']; - //$status = $records['is_complete']; - $status = 1; - $section_data = json_encode($records); + //print_r($records); - //Get Sales PD master Data + //de active old entries + $is_updated = $this->SMC_Credit_PD_Model->updateRecords(array('isactive' => 0),SMC_CREDIT_PD_SECTION_DATA,array('fk_pd_id' => $records['fk_pd_id'],'fk_form_id' => $records['fk_form_id'])); - $columns = array('SMC_CREDIT_PD.*','ENTITY.short_name','PRODUCT.abbr'); - $table = SMC_CREDIT_PD.' as SMC_CREDIT_PD'; - $joins = array( - array('table' => ENTITY. ' as ENTITY', - 'condition' =>'SMC_CREDIT_PD.lender_id = ENTITY.entity_id', - 'jointype' => 'INNER'), - array('table' => PRODUCTS. ' as PRODUCT', - 'condition' =>'SMC_CREDIT_PD.product_id = PRODUCT.product_id', - 'jointype' => 'INNER') - ); + //make new entry + $new_json_id = $this->SMC_Credit_PD_Model->saveRecords($records,SMC_CREDIT_PD_SECTION_DATA); - $where_condition_array = array('SMC_CREDIT_PD.smc_credit_pd' => $smc_credit_pd); - $sales_pd_master_data = $this->SMC_Credit_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array); - - //pre process works - switch($section_id) + if($new_json_id) { - case 1: //General section - //update Applicant ID and applicant Name to sales pD master Table - $applicant_id = null; - $applicant_name = ''; - 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']; - } - - - } - } - - $update_fields = array('applicant_name' => $applicant_name,'applicant_id' => $applicant_id); - $this->SMC_Credit_PD_Model->updateRecords($update_fields,SMC_CREDIT_PD,array('smc_credit_pd' => $smc_credit_pd)); - - - break; - - case 2: //Fund Requirement - break; - - case 3: //stakeholders - break; - - case 4: //brief of business - break; - - case 5: //Financial - break; - - case 6: //property - break; - - case 7: //Officer self details - break; - - case 8: //final remarks of PD officer - //update PD officer Name to sales pD master Table - $officer = ''; - if($records['questions']) - { - foreach($records['questions'] as $g_key => $g_value) - { - if($g_value['question_key'] == 'name_of_sales_team_member') - { - $officer = $g_value['answer_value']; - break; - } - - } - } - $update_fields = array('officer_name' => $officer); - $this->SMC_Credit_PD_Model->updateRecords($update_fields,SMC_CREDIT_PD,array('smc_credit_pd' => $smc_credit_pd)); - break; - - case 9: //photosection - break; - - default: - } - - //make inactive previous records - $this->SMC_Credit_PD_Model->updateRecords(array('isactive' => 0),SMC_CREDIT_PD_SECTION_DATA,array('smc_credit_pd' =>$smc_credit_pd,'section_id' => $section_id )); - - //insert new record - $fields = array('smc_credit_pd' => $smc_credit_pd, 'section_id' => $section_id, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby); - $is_entry_created = $this->SMC_Credit_PD_Model->saveRecords($fields,SMC_CREDIT_PD_SECTION_DATA); - if($is_entry_created) - { - $data['dataStatus'] = true; + $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; - $data['records'] = $is_entry_created; + $data['records'] = $new_json_id; $this->response($data,REST_Controller::HTTP_OK); - } - else - { - $data['dataStatus'] = false; + } + 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 loadSMCPDTemplate_get() + { + $pd_id = ""; + $client = ""; + $random_string = ""; + $api = ""; + + if($this->get('pd_id')) { $pd_id = $this->get('pd_id'); } + if($this->get('client')) { $client = $this->get('client'); } + if($this->get('random_string')) { $random_string = $this->get('random_string'); } + if($this->get('api')) { $api = $this->get('api'); } + + if($pd_id != "" || $pd_id != null) + { + + $template_details = $this->SMC_Credit_PD_Model->getSMCTemplateForPD($pd_id,$client,$random_string,$api); + if(count($template_details)) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $template_details; + $this->response($data,REST_Controller::HTTP_OK); + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'Template Not Available'; + $this->response($data,REST_Controller::HTTP_OK); + } + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_BAD_REQUEST; + $data['msg'] = 'No Param Available'; + $this->response($data,REST_Controller::HTTP_OK); + } } public function getSMCCreditPDSectionData_post() { $records = $this->post('records'); - $section_data = array(); + $section_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('fk_pd_id' => $records['fk_pd_id'],'fk_form_id' => $records['fk_form_id'],'isactive' => 1),SMC_CREDIT_PD_SECTION_DATA); + + if(is_array($section_data )&& count($section_data)) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $section_data[0]; + $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); + } - if($records['section_id'] == 'all'){ - // die(); - $fields=array('id','smc_credit_pd','section_id','status','createdby','createdon'); - $section_data=$this->SMC_Credit_PD_Model->selectCustomRecords($fields,array('smc_credit_pd' => $records['smc_credit_pd'],'isactive' => 1),SMC_CREDIT_PD_SECTION_DATA); - } - else{ - $section_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('smc_credit_pd' => $records['smc_credit_pd'],'isactive' => 1,'section_id' => $records['section_id']),SMC_CREDIT_PD_SECTION_DATA); - //print_r( json_decode($section_data[0]['section_data'],true));die(); - if($records['section_id'] == 9 && count($section_data)) - { - $all_sales_pd_images = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('fk_smc_credit_pd' => $records['smc_credit_pd'],'img_name !=' => 'satellite','isactive' => 1),SALEPD_DOCS); - //print_r($all_sales_pd_images);die(); - $photo_questions = (json_decode(($section_data[0]['section_data']),true)); - // print_r($photo_questions); - foreach ($photo_questions['questions'] as $key => $value) - { - if(isset($value['answer_value']) && $value['answer_value'] && !$value['is_repeatable']) - { - $selfie = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('fk_smc_credit_pd' => $records['smc_credit_pd'],'img_name' => 'selfie_with_person_met','isactive' => 1),SALEPD_DOCS); - if(count($selfie)) - { - $photo_questions['questions'][$key]['answer_value'] = $selfie[0]['img']; - //$photo_questions['questions'][$key]['answer_value'] = "CHNAGED"; - } - } - else - { + } +// public function getSMCCreditPDSectionData_post() +// { +// $records = $this->post('records'); +// $section_data = array(); + + +// if($records['section_id'] == 'all'){ +// // die(); +// $fields=array('id','smc_credit_pd','section_id','status','createdby','createdon'); +// $section_data=$this->SMC_Credit_PD_Model->selectCustomRecords($fields,array('smc_credit_pd' => $records['smc_credit_pd'],'isactive' => 1),SMC_CREDIT_PD_SECTION_DATA); +// } +// else{ +// $section_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('smc_credit_pd' => $records['smc_credit_pd'],'isactive' => 1,'section_id' => $records['section_id']),SMC_CREDIT_PD_SECTION_DATA); +// //print_r( json_decode($section_data[0]['section_data'],true));die(); +// if($records['section_id'] == 9 && count($section_data)) +// { +// $all_sales_pd_images = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('fk_smc_credit_pd' => $records['smc_credit_pd'],'img_name !=' => 'satellite','isactive' => 1),SALEPD_DOCS); +// //print_r($all_sales_pd_images);die(); +// $photo_questions = (json_decode(($section_data[0]['section_data']),true)); +// // print_r($photo_questions); +// foreach ($photo_questions['questions'] as $key => $value) +// { +// if(isset($value['answer_value']) && $value['answer_value'] && !$value['is_repeatable']) +// { +// $selfie = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('fk_smc_credit_pd' => $records['smc_credit_pd'],'img_name' => 'selfie_with_person_met','isactive' => 1),SALEPD_DOCS); +// if(count($selfie)) +// { +// $photo_questions['questions'][$key]['answer_value'] = $selfie[0]['img']; +// //$photo_questions['questions'][$key]['answer_value'] = "CHNAGED"; +// } +// } +// else +// { - foreach ($value['questions_group'] as $v_key => $individual_value) - { - //print_r($individual_value);die(); - if($individual_value['questions'][0]['answer_value']) - { - //iterate all_sales_pd_images to get one - foreach ($all_sales_pd_images as $img_key => $img_value) - { - if($individual_value['questions'][0]['question_key'] == $img_value['img_name']) - { - $photo_questions['questions'][$key]['questions_group'][$v_key]['questions'][0]['answer_value'] = $img_value['img']; - //$photo_questions['questions'][$key]['questions_group'][$v_key]['questions'][0]['answer_value'] = "CHANGED"; - unset($all_sales_pd_images[$img_key]); - break; - } - } - } - } - } - } - //die(); - $photo_questions = json_encode($photo_questions); - $section_data[0]['section_data'] = $photo_questions; - } +// foreach ($value['questions_group'] as $v_key => $individual_value) +// { +// //print_r($individual_value);die(); +// if($individual_value['questions'][0]['answer_value']) +// { +// //iterate all_sales_pd_images to get one +// foreach ($all_sales_pd_images as $img_key => $img_value) +// { +// if($individual_value['questions'][0]['question_key'] == $img_value['img_name']) +// { +// $photo_questions['questions'][$key]['questions_group'][$v_key]['questions'][0]['answer_value'] = $img_value['img']; +// //$photo_questions['questions'][$key]['questions_group'][$v_key]['questions'][0]['answer_value'] = "CHANGED"; +// unset($all_sales_pd_images[$img_key]); +// break; +// } +// } +// } +// } +// } +// } +// //die(); +// $photo_questions = json_encode($photo_questions); +// $section_data[0]['section_data'] = $photo_questions; +// } - } +// } - if($section_data) - { - $data['dataStatus'] = true; - $data['status'] = REST_Controller::HTTP_OK; - $data['records'] = $section_data; - $this->response($data,REST_Controller::HTTP_OK); - } - else - { - $data['dataStatus'] = false; - $data['status'] = REST_Controller::HTTP_NO_CONTENT; - $data['msg'] = 'No Data Found'; - $this->response($data,REST_Controller::HTTP_OK); +// if($section_data) +// { +// $data['dataStatus'] = true; +// $data['status'] = REST_Controller::HTTP_OK; +// $data['records'] = $section_data; +// $this->response($data,REST_Controller::HTTP_OK); +// } +// else +// { +// $data['dataStatus'] = false; +// $data['status'] = REST_Controller::HTTP_NO_CONTENT; +// $data['msg'] = 'No Data Found'; +// $this->response($data,REST_Controller::HTTP_OK); - } +// } -} +// } public function testAPISalesPD_post() { @@ -1190,6 +1280,11 @@ public function filterSalesPDList_post() { $this->response($data,REST_Controller::HTTP_OK); } } + + function loadDataFromExcel_post() + { + + } } \ No newline at end of file diff --git a/api/application/helpers/readexceldata_helper.php b/api/application/helpers/readexceldata_helper.php index 1ec3e9ba..72434e7c 100644 --- a/api/application/helpers/readexceldata_helper.php +++ b/api/application/helpers/readexceldata_helper.php @@ -69,7 +69,7 @@ class readexceldata if($key == 8) { //print_r($value); - $temp['key_name'] = 'borrower_name'; + $temp['key_name'] = 'applicant_name'; $temp['value'] = $value['C']; $return_data[] = $temp; } diff --git a/api/application/models/SMC_Credit_PD_Model.php b/api/application/models/SMC_Credit_PD_Model.php index bf7e91af..30b01283 100644 --- a/api/application/models/SMC_Credit_PD_Model.php +++ b/api/application/models/SMC_Credit_PD_Model.php @@ -51,6 +51,22 @@ class SMC_Credit_PD_Model extends SPARQ_Model { // if(ENVIRONMENT == 'development'){echo 'LAST QUERY '. $this->db->last_query();} return $result; } + + + function getSMCTemplateForPD($pd_id,$client,$random_string,$api) + { + // $master_forms = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('isactive' => 1),SMC_CREDIT_PD_FORMS); + // print_r($master_forms); + $table = SMC_CREDIT_PD_FORMS.' as SMC_CREDIT_PD_FORMS'; + $fields = array('SMC_CREDIT_PD_FORMS.form_name','SMC_CREDIT_PD_SECTION_DATA.fk_form_id','SMC_CREDIT_PD_SECTION_DATA.fk_pd_id','SMC_CREDIT_PD_SECTION_DATA.json','if(SMC_CREDIT_PD_SECTION_DATA.json is not null,true,false) as is_answered'); + $joins = array( + array('table'=>SMC_CREDIT_PD_SECTION_DATA." as SMC_CREDIT_PD_SECTION_DATA",'condition'=>"SMC_CREDIT_PD_SECTION_DATA.fk_form_id = SMC_CREDIT_PD_FORMS.form_id AND SMC_CREDIT_PD_SECTION_DATA.fk_pd_id = $pd_id and SMC_CREDIT_PD_SECTION_DATA.fk_form_id = $pd_id and SMC_CREDIT_PD_SECTION_DATA.isactive = $pd_id" ,'jointype'=>'LEFT') + ); + $where_condition_array = array('SMC_CREDIT_PD_FORMS.isactive' => 1); + return $master_forms = $this->getJoinRecords($fields,$table,$joins,$where_condition_array); + + + }