From d7e6da982a479970cdfd195a0486d1760148a501 Mon Sep 17 00:00:00 2001 From: Velz2020 Date: Mon, 17 Aug 2020 00:46:52 +0530 Subject: [PATCH] SMC CREDIT PD 1 --- api/application/config/constants.php | 4 + api/application/config/routes.php | 6 + .../controllers/SMC_Credit_PD_Controller.php | 1165 +++++++++++++++++ .../controllers/Sales_PD_Controller.php | 5 +- .../models/SMC_Credit_PD_Model.php | 57 + 5 files changed, 1235 insertions(+), 2 deletions(-) create mode 100644 api/application/controllers/SMC_Credit_PD_Controller.php create mode 100644 api/application/models/SMC_Credit_PD_Model.php diff --git a/api/application/config/constants.php b/api/application/config/constants.php index aa445980..3d6f758f 100644 --- a/api/application/config/constants.php +++ b/api/application/config/constants.php @@ -631,5 +631,9 @@ defined('CREDITPDTEMPLATE') OR define('CREDITPDTEMPLATE','m_credit_pd_template') defined('VENDORFORMSTATUS') OR define('VENDORFORMSTATUS','t_vendor_form_status'); +defined('SMC_CREDIT_PD') OR define('SMC_CREDIT_PD','t_smc_credit_pd'); +defined('SMC_CREDIT_PD_DOCS') OR define('SMC_CREDIT_PD_DOCS','t_smc_credit_pd_docs'); +defined('SMC_CREDIT_PD_SECTION_DATA') OR define('SMC_CREDIT_PD_SECTION_DATA','t_smc_credit_pd_section_data'); + diff --git a/api/application/config/routes.php b/api/application/config/routes.php index f81055b7..3742d79e 100644 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -290,3 +290,9 @@ $route['generateSatelliteImg']='Sales_PD_Controller/generateSatelliteImg'; $route['getSalesPDImgDataCusLink']='Sales_PD_Controller/getSalesPDImgDataCusLink'; $route['sendSalesCusLinkViaSMS']='Sales_PD_Controller/sendSalesCusLinkViaSMS'; + +$route['listSMCCreditPD/(:num)']='SMC_Credit_PD_Controller/listSMCCreditPD'; +$route['saveSMCCreditPD'] = 'SMC_Credit_PD_Controller/saveSMCCreditPD'; +$route['saveSMCCreditPDImage'] = 'SMC_Credit_PD_Controller/saveSMCCreditPDImage'; +$route['saveSMCCreditPDsection'] = 'SMC_Credit_PD_Controller/saveSMCCreditPDsection'; + diff --git a/api/application/controllers/SMC_Credit_PD_Controller.php b/api/application/controllers/SMC_Credit_PD_Controller.php new file mode 100644 index 00000000..d9f1974e --- /dev/null +++ b/api/application/controllers/SMC_Credit_PD_Controller.php @@ -0,0 +1,1165 @@ +load->model('SMC_Credit_PD_Model'); + $this->external_path = $this->config->item('external_data_path'); + $this->load->library('AWS_S3'); + $this->load->library('pdfgenerator'); + $this->load->helper('satellite_image'); + $this->load->library('phpmailer_library'); + + + } + + public function loadSalesPDTemplate_post() + { + $records = $this->post('records'); + $lender_id = $records['lender_id']; + $product = $records['product_id']; + $sales_pd_type = $records['sales_pd_type']; + + $template = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('lender_id' => $lender_id,'product_id' => $product,'sales_pd_type' => $sales_pd_type,'isactive' => 1),SALESPDTEMPLATE); + if(is_array($template) && count($template)) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $template[0]; + $this->response($data,REST_Controller::HTTP_OK); + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'No Tempate Found!'; + $this->response($data,REST_Controller::HTTP_OK); + + } + } + + + // public function saveSalesPDOld_post() + // { + // $records = $this->post('records'); + // $applicant_name = ''; + // $applicant_id = ''; + // $officer = ''; + // //satellite_image::getSatelliteImage(22,2);//die(); + // foreach (json_decode($records['pd_json'],true) as $key => $value) + // { + // //print_r($value);die(); + // if($value['section_id'] == 1) + // { + // foreach ($value['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($records['product_id'] == 4) + // { + // if($g_value['question_key'] == 'company_name') + // { + // $applicant_name = $g_value['answer_value']; + // } + // } + // else + // { + // if($g_value['question_key'] == 'person_met_during_visit') + // { + // $applicant_name = $g_value['answer_value']; + + // } + // } + + // } + // } + // if($value['section_id'] == 8) + // { + // foreach ($value['questions'] as $g_key => $g_value) + // { + // if($g_value['question_key'] == 'name_of_sales_team_member') + // { + // $officer = $g_value['answer_value']; + // } + + // } + // } + // } + + // $records['applicant_id'] = $applicant_id; + // $records['applicant_name'] = $applicant_name; + // $records['officer_name'] = $officer; + + // $id = null; + // if(!$records['smc_credit_pd']) + // { + // //generate sales pd serial no + + // $count = $this->SMC_Credit_PD_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $records['lender_id'],'product_id' => $records['product_id']),SMC_CREDIT_PD); + + // $lender_short_name = $this->SMC_Credit_PD_Model->selectCustomRecords(array('short_name'),array('entity_id' => $records['lender_id']),ENTITY); + + // $product_short_name = $this->SMC_Credit_PD_Model->selectCustomRecords(array('abbr'),array('product_id' => $records['product_id']),PRODUCTS); + // //print_r($product_short_name); + + // $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']); + // //echo $salepd_serial_no; + // //end generate sales pd serial no + // // echo $salepd_serial_no; + // // die(); + // $records['sales_pd_sno'] = $salepd_serial_no; + // $id = $this->SMC_Credit_PD_Model->saveRecords($records,SMC_CREDIT_PD); + // satellite_image::getSatelliteImage($id,2); + // } + // else + // { + // $id = $this->SMC_Credit_PD_Model->updateRecords($records,SMC_CREDIT_PD,array('smc_credit_pd' => $records['smc_credit_pd'])); + // } + + // if($id) + // { + // $data['dataStatus'] = true; + // $data['status'] = REST_Controller::HTTP_OK; + // $data['records'] = $id; + // $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); + // } + + // } + function prepareSalesPDReport($smc_credit_pd,$api = true) + { + log_message('ERROR','####PREPARE SALESPD REPORT CALLED'.$smc_credit_pd); + $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); + $SMC_CREDIT_PD = $this->SMC_Credit_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array); + //print_r($SMC_CREDIT_PD);die(); + + if($SMC_CREDIT_PD) + { + ini_set('max_execution_time', 0); + $bucket_name = LENDER_BUCKET_NAME_PREFIX.$SMC_CREDIT_PD[0]['lender_id']; + $pdf_name = strtolower(trim($SMC_CREDIT_PD[0]['applicant_name'])); + $pdf_name .= '-'.$SMC_CREDIT_PD[0]['abbr']; + $pdf_name .= '-'.(date('dmY',strtotime($SMC_CREDIT_PD[0]['completed_date']))); + //$pdf_name = str_replace(' ', '_', $pdf_name); + + + $key = 'sales_pd/'.$smc_credit_pd.'/'.$pdf_name.'.pdf'; + + if(!file_exists($this->external_path.'/sales_pd/'.$smc_credit_pd)) + { + mkdir($this->external_path.'/sales_pd/'.$smc_credit_pd,0777); + } + + if(!$SMC_CREDIT_PD[0]['is_pdf'] || $SMC_CREDIT_PD[0]['is_edited']) + { + + + + $all_section_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('smc_credit_pd' => $smc_credit_pd,'isactive' => 1),SMC_CREDIT_PD_SECTION_DATA); + // print_r($this->db->last_query());die(); + $view_data['master'] = $SMC_CREDIT_PD; + foreach ($all_section_data as $sec_key => $section) + { + //print_r($section);die(); + $view_data['section'.$section['section_id'] ] = $this->processSalesPDJSON($section); + } + //print_r($view_data['section1']);die(); + $view_data['section9'] = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('fk_smc_credit_pd' => $smc_credit_pd,'img_name !=' => 'satellite','isactive' => 1),SALEPD_DOCS); + $view_data['satellite_image'] = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('fk_smc_credit_pd' => $smc_credit_pd,'img_name' => 'satellite','isactive' => 1),SALEPD_DOCS); + $view_data['product_id'] = $SMC_CREDIT_PD[0]['product_id']; + $view_data['geo_location'] = $SMC_CREDIT_PD[0]['geo_location']; + //print_r($this->db->last_query());die(); + //$view_name = $SMC_CREDIT_PD[0]['short_name'].'_'.$SMC_CREDIT_PD[0]['abbr']; + $view_name = $SMC_CREDIT_PD[0]['short_name']; + $html_content = $this->load->view('sale_pd_templates/'.$view_name,$view_data,true); + //echo $html_content;die(); + $pdf_doc = $this->pdfgenerator->generate($html_content, $filename='version', $stream=false, $paper = 'A4', $orientation = "portrait"); + //End of PDF Gen using DOM PDF + $output_file = $this->external_path ."/sales_pd/" . $smc_credit_pd . "/temp.pdf"; + $bytes = file_put_contents($output_file, $pdf_doc); + // echo $bytes; + // die(); + $bucket_data = array('bucket_name'=>$bucket_name,'key'=>$key,'sourcefile'=>$this->external_path.'/sales_pd/'.$smc_credit_pd.'/temp.pdf'); + log_message('ERROR','####SALES PD REPORT UPLOAD TO S3'.$smc_credit_pd); + $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); + + if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) + { + + $this->SMC_Credit_PD_Model->updateRecords(array('is_pdf' => 1, 'is_edited' => 0),SMC_CREDIT_PD,array('smc_credit_pd' => $smc_credit_pd)); + if($api) + { + $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $singed_uri; + $this->response($data,REST_Controller::HTTP_OK); + } + } + } + else + { + if($api) + { + $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $singed_uri; + $this->response($data,REST_Controller::HTTP_OK); + } + } + } + } + public function getSalesPDReport_get() + { + $smc_credit_pd = $this->uri->segment(2); + $this->prepareSalesPDReport($smc_credit_pd); + + + } + + public function listSMCCreditPD_get() + { + $lender_id = $this->uri->segment(2); + $user_id = $this->uri->segment(3); + $columns = array('SMC_CREDIT_PD.smc_credit_pd','SMC_CREDIT_PD.fk_sales_pd_id','SALES_PD_DATA.sales_pd_sno','SMC_CREDIT_PD.smc_credit_pd_sno','SMC_CREDIT_PD.applicant_name','concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as officer_name','SMC_CREDIT_PD.applicant_id','SMC_CREDIT_PD.lender_id','SMC_CREDIT_PD.product_id','SMC_CREDIT_PD.is_pdf','SMC_CREDIT_PD.is_edited','ENTITY.short_name','PRODUCT.abbr','SMC_CREDIT_PD.createdon','SMC_CREDIT_PD.status','SMC_CREDIT_PD.smc_credit_pd_type','SMC_CREDIT_PD.rand_string','SMC_CREDIT_PD.isactive' + // ,"DATE_FORMAT(SMC_CREDIT_PD.createdon,'%Y-%m-%d') as modify","DATE_ADD(CURDATE(),INTERVAL '-10' DAY) as currd", + // "(CURDATE()) as daye10" + ); + $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' => SALES_PD_DATA. ' as SALES_PD_DATA', + 'condition' =>'SMC_CREDIT_PD.fk_sales_pd_id = SALES_PD_DATA.sales_pd_id', + 'jointype' => 'INNER'), + array('table' => PRODUCTS. ' as PRODUCT', + 'condition' =>'SMC_CREDIT_PD.product_id = PRODUCT.product_id', + 'jointype' => 'INNER'), + array('table' => USERPROFILE. ' as USERPROFILE', + 'condition' =>'SMC_CREDIT_PD.createdby = USERPROFILE.userid', + 'jointype' => 'LEFT') + ); + + $where_condition_array['SMC_CREDIT_PD.isactive'] = 1; + if(is_numeric($lender_id)) + { + $where_condition_array['SMC_CREDIT_PD.lender_id'] = $lender_id; + } + // FILTERING THE LAST 10 DAYS RECORDS + + $key_date='SMC_CREDIT_PD.createdon BETWEEN DATE_SUB(NOW(), INTERVAL 60 DAY) AND NOW()'; + $condition_value=null; + $where_condition_array[$key_date] = $condition_value; + // print_r ($where_condition_array); + + // ----END OF FILTERING THE LAST 10 DAYS RECORDS--- + + if($user_id && is_numeric($user_id)) + { + $where_condition_array['SMC_CREDIT_PD.createdby'] = $user_id; + } + $order_by = 'SMC_CREDIT_PD.smc_credit_pd'; + $SMC_CREDIT_PD = $this->SMC_Credit_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array,$order_by,'DESC'); + + //print_r($this->db->last_query());die(); + if(count($SMC_CREDIT_PD)) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $SMC_CREDIT_PD; + $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); + } + + + } + + + function processSalesPDJSON($section_array) + { + // + //print_r($section_array);die(); + //echo '###'.$section_array['section_id'].'####'; + if($section_array['section_id'] == 6) + { + // print_r(json_decode($section_array['section_data'],true)); + // die(); + } + if($section_array['section_id']) + { + //print_r($section_array);//die(); + $questions = json_decode($section_array['section_data'],true); + return $this->processSalesPDQuestions($questions['questions'],$section_array['section_id']); + + } + // die(); + // $general_section_dta = array(); + // foreach ($section_array as $sec_key => $section) + // { + + //} + } + + function processSalesPDQuestions($questions,$section_id) + { + //print_r($questions);die(); + $temp_array = array(); + foreach ($questions as $ques_key => $question) + { + //if($question['section_id']){} + if($question['is_repeatable'] == null && ($question['type'] == 1 || $question['type'] == 2 || $question['type'] == 3 || $question['type'] == 4 || $question['type'] == 6 || $question['type'] == 7 || $question['type'] == 8))//text,radio,SDD,MDD,camera,txt area, searchable dd + { + + $temp_array[ $question['question_key'] ] = isset($question['answer_value']) ? $question['answer_value'] : null; + if($question['question_key'] == 'state' || $question['question_key'] == 'city' || $question['question_key'] == 'pincode' || $question['question_key'] == 'loan_purpose') + { + //if($question['type'] == 4) { print_r($question['answer_value']); } + $temp_array[ $question['question_key'] ] = $this->getMasterData($question['answer_value'],$question['answers']); + //if($question['type'] == 4) { print_r($temp_array[ $question['question_key'] ]); } + } + if(isset($question['subfield_key'])) + { + + $temp_array[ $question['question_key'] ] .= $question['subfield_value'].','; + + } + + if(substr_count($temp_array[ $question['question_key'] ], ',')) + { + $temp_array[ $question['question_key'] ] = substr_replace($temp_array[ $question['question_key'] ],'', strrpos($temp_array[ $question['question_key'] ],','),1); + } + + if(substr_count($temp_array[ $question['question_key'] ], ',')) + { + + $temp_array[ $question['question_key'] ] = substr_replace($temp_array[ $question['question_key'] ],' and ', strrpos($temp_array[ $question['question_key'] ],','),1); + + } + } + else if($question['is_repeatable'] == 1 ) + { + //print_r($question['questions_group']);die(); + if($section_id != 9) + { + foreach ($question['questions_group'] as $group_key => $group_value) + { + //print_r($group_value['questions']);//die(); + $group_temp = array(); + foreach ($group_value['questions'] as $q_key => $q_value) + { + //print_r($q_value);die(); + //echo $group_key; + $group_temp[ $q_value['question_key'] ] = $q_value['answer_value']; + + if(isset($q_value['subfield_key'])){ $group_temp[ $q_value['question_key'] ] = $q_value['subfield_value']; } + //print_r($group_temp); + } + //print_r($group_temp); + $temp_array[ $group_key ] = $group_temp; + + } + } + else + { +//echo "SDKJHKSJ**"; + $group_temp = array(); + foreach ($question['questions_group'] as $group_key => $group_value) + { + + $temp_array[ $group_value['questions'][0]['question_key'] ][] = isset($group_value['questions'][0]['subfield_key']) ? $group_value['questions'][0]['subfield_value'] : $group_value['questions'][0]['answer_value']; + + } + } + } + } + // //print_r($temp_array);die(); + // if($section_id == 2) + // { + // //print_r(json_decode($section_array['section_data'],true)); die(); + // die(); + // } + return $temp_array; + } + + function getMasterData($id,$array) + { + + //print_r($id); + if(!is_array($id)) + { + foreach($array as $value) + { + if($id == $value['answer_id']) + { + return $value['answer']; + break; + } + } + } + else + { + $final_string = ''; + + foreach($id as $value) + { + foreach($array as $mas_value) + { + if( !strcasecmp($value,$mas_value['answer_id']) && (substr_count($value,'Others') == 0)) + { + $final_string .= $mas_value['answer'] . ','; + } + } + } + //print_r($final_string);die(); + return $final_string; + } + + } + + public function saveSMCCreditPDImage_post() + { + $records = $this->post('records'); + $is_customer_app = isset($records['is_customer_app']) ? $records['is_customer_app'] : null; + unset($records['is_customer_app']); + + if($records['img_name'] == 'selfie_with_person_met') + { + //$location = $records['location']; + //$update_fields = array('geo_location' => $records['location']); + //$this->SMC_Credit_PD_Model->updateRecords($update_fields,SMC_CREDIT_PD,array('smc_credit_pd' => $records['fk_smc_credit_pd'])); + + + //satellite_image::getSatelliteImage($records['fk_smc_credit_pd'],2); + + // //disable previous selfie img + // $update_fields2 = array('isactive' => 0); + // $this->SMC_Credit_PD_Model->updateRecords($update_fields2,SALEPD_DOCS,array('img_name' => 'selfie_with_person_met','fk_smc_credit_pd' => $records['fk_smc_credit_pd'])); + // if($is_customer_app) + // { + // $this->SMC_Credit_PD_Model->updateRecords(array('isactive' => 0),SMC_CREDIT_PD_SECTION_DATA,array('section_id' => 9,'smc_credit_pd' => $records['fk_smc_credit_pd'])); + // } + + } + + $id = $this->SMC_Credit_PD_Model->saveRecords($records,SMC_CREDIT_PD_DOCS); + if($id) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $id; + $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 saveSMCCreditPD_post() + { + $records = $this->post('records'); + $is_entry_done = null; + $id = null; + //print_r($records);die(); + + + // log_message('ERROR','####SALESPD SAVE CALLED'); + + $section_names = array('1' => 'General Section','2' => 'Fund Requirement','3' => 'stakeholders','4' => 'Brief of business','5' => 'Financial','6' => 'Property Details','7' => 'Final Remraks','8' => 'Officer Details','9' => 'Photography'); + + $count = $this->SMC_Credit_PD_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $records['lender_id'],'product_id' => $records['product_id']),SMC_CREDIT_PD); + + $lender_short_name = $this->SMC_Credit_PD_Model->selectCustomRecords(array('short_name'),array('entity_id' => $records['lender_id']),ENTITY); + + $product_short_name = $this->SMC_Credit_PD_Model->selectCustomRecords(array('abbr'),array('product_id' => $records['product_id']),PRODUCTS); + if($records['smc_credit_pd'] == '' || $records['smc_credit_pd'] == 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 SALESPD'); + $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['smc_credit_pd_sno'] = $salepd_serial_no; + //print_r($records);die(); + $id = $this->SMC_Credit_PD_Model->saveRecords($records,SMC_CREDIT_PD); + } + else + { + //echo $product_short_name[0]['abbr']; + if(isset($records['status']) && $records['status'] == 'COMPLETED') + { + // log_message('ERROR','####COMPLETE SALESPD'.$records['smc_credit_pd']); + // $drafted_sections = $this->SMC_Credit_PD_Model->selectCustomRecords(array('section_id'),array('status' => 0,'smc_credit_pd' => $records['smc_credit_pd'],'isactive' => 1),SMC_CREDIT_PD_SECTION_DATA); + + // $completed_sections = $this->SMC_Credit_PD_Model->selectCustomRecords(array('section_id'),array('status' => 1,'smc_credit_pd' => $records['smc_credit_pd'],'isactive' => 1),SMC_CREDIT_PD_SECTION_DATA); + // //print_r($completed_sections); + + // if($records['sales_pd_type'] == 1) + // { + // $img_satellite_check = $this->SMC_Credit_PD_Model->selectCustomRecords(array('count(*) as count'),array('img_name' => 'satellite','smc_credit_pd' => $records['smc_credit_pd'],'isactive' => 1),SALEPD_DOCS); + // } + // else if($records['sales_pd_type'] == 2) + // { + // log_message('ERROR','###TELE SALES PD satellite check overrided'); + // $img_satellite_check[0]['count'] = array();//for sales tele pd avoid satellite img check + // } + + // $img_selfile_check = $this->SMC_Credit_PD_Model->selectCustomRecords(array('count(*) as count'),array('img_name' => 'selfie_with_person_met','smc_credit_pd' => $records['smc_credit_pd'],'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'] ]); + // } + // } + + // unset($dup_of_section_names[9]);//unset photograph always + // if($product_short_name[0]['abbr'] == "WCTL"){ unset($dup_of_section_names[6]);} + // //print_r($dup_of_section_names);die(); + // 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' => 9,'sectin_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->SMC_Credit_PD_Model->updateRecords($records,SMC_CREDIT_PD,array('smc_credit_pd' => $records['smc_credit_pd'])); + + //$this->prepareSalesPDReport($records['smc_credit_pd'],false); + // sleep(10); + // log_message('ERROR','####SALESPD AFTER 10 PREPARED REPORT'.$records['smc_credit_pd']); + //echo 'afetr 10'; + //trigger mail function + //PDALERTS::sendSalesPDMail($this,$records['smc_credit_pd']); + //} + + } + else + { + log_message('ERROR','####UPDATE SALESPD'.$records['smc_credit_pd']); + $id = $this->SMC_Credit_PD_Model->updateRecords($records,SMC_CREDIT_PD,array('smc_credit_pd' => $records['smc_credit_pd'])); + + } + + } + + 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 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']; + $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 getSalesPDSectionData_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; + } + + + + } + + + 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() + { + //PDALERTS::sendSalesPDMail($this,32);die(); + satellite_image::getSatelliteImage(32,2);//die(); + // $url = "https://maps.googleapis.com/maps/api/staticmap?center=12.9788141,80.1871334&zoom=14&markers=color:red|12.9788141,80.1871334&size=800x300&maptype=roadmap&key=AIzaSyA3lYDYxwtn5vLSl45SOKbtK7G6cEyXGr0"; + // file_put_contents('test.jpg', file_get_contents($url)); + } + + public function salesPDMisReport_post() + { + //$lender_id = $this->uri->segment(2); + $officer_name = $this->post('officer_name'); + $from_date = $this->post('from_date'); + $to_date = $this->post('to_date'); + + + $columns = array('SMC_CREDIT_PD.smc_credit_pd','SMC_CREDIT_PD.sales_pd_sno','SMC_CREDIT_PD.applicant_name','concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as officer_name','SMC_CREDIT_PD.applicant_id','SMC_CREDIT_PD.lender_id','SMC_CREDIT_PD.product_id','SMC_CREDIT_PD.is_pdf','SMC_CREDIT_PD.is_edited','ENTITY.short_name','PRODUCT.abbr','SMC_CREDIT_PD.createdon','SMC_CREDIT_PD.status','SMC_CREDIT_PD.mail_status','SMC_CREDIT_PD.sales_pd_type','IF(SMC_CREDIT_PD.sales_pd_type = 1 ,"physical pd","tele pd") as sales_pd_type_name'); + $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'), + array('table' => USERPROFILE. ' as USERPROFILE', + 'condition' =>'SMC_CREDIT_PD.createdby = USERPROFILE.userid', + 'jointype' => 'LEFT') + ); + + $where_condition_array = array(); + if($officer_name) + { + //$where_condition_array[] = array('SMC_CREDIT_PD.officer_name like' => '%'.$officer_name.'%'); + $where_condition_array['SMC_CREDIT_PD.officer_name like'] = '%'.$officer_name.'%'; + } + if($from_date) + { + + $where_condition_array['date(SMC_CREDIT_PD.createdon) >='] = $from_date; + } + if($to_date) + { + + $where_condition_array['date(SMC_CREDIT_PD.createdon) <='] = $to_date; + } + + $order_by = 'SMC_CREDIT_PD.smc_credit_pd'; + $SMC_CREDIT_PD = $this->SMC_Credit_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array,$order_by,'DESC'); + //print_r($this->db->last_query()); + if(count($SMC_CREDIT_PD)) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $SMC_CREDIT_PD; + $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 filterSalesPDList_post() { + $records = $this->post('records'); + $pd_status= $records['pd_status']; + $pd_from_date = $records['pd_from_date']; + $pd_to_date = $records['pd_to_date']; + $pd_products = $records['pd_products']; + $pd_lender = $records['pd_lender']; + $pd_applicant_name = strtolower($records['pd_applicant_name']); + $pd_officer_name = isset($records['pd_officer']) ? $records['pd_officer'] : null ; + $sales_pd_officer_id = isset($records['sales_pd_officer_id']) ? $records['sales_pd_officer_id'] : null ; + $result_data=$this->SMC_Credit_PD_Model->getSalesPDListwithFilters($pd_status,$pd_from_date,$pd_to_date,$pd_products,$pd_lender,$pd_applicant_name,$pd_officer_name,$sales_pd_officer_id); + // print_r ($result_data); + if(count($result_data)){ + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $result_data; + $this->response($data,REST_Controller::HTTP_OK); + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'No Records Found'; + $this->response($data,REST_Controller::HTTP_OK); + } +} + + + public function generateSatelliteImg_post() + { + + $input_data = $this->post(); + + $id = $this->SMC_Credit_PD_Model->updateRecords($input_data,SMC_CREDIT_PD,array('smc_credit_pd' => $input_data['smc_credit_pd'])); + satellite_image::getSatelliteImage($input_data['smc_credit_pd'],2); + + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $id; + $this->response($data,REST_Controller::HTTP_OK); + + + } + + + public function getSalesPDImgDataCusLink_post() + { + $rand_string = $this->post('rand_string'); + + $sales_pd_master_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('rand_string' => $rand_string),SMC_CREDIT_PD); + + $sales_pd_img_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('doc_id', 'fk_smc_credit_pd','img','img_name','isactive'),array('fk_smc_credit_pd' => $sales_pd_master_data[0]['smc_credit_pd'],'isactive' => 1,'img_name!=' => 'satellite'),SALEPD_DOCS); + + //print_r($sales_pd_img_data);die(); + //sales tele pd img structure array + $imgs = array('selfie_with_person_met' => array('is_multiple' => 0,'img_name' => 'Selfie of the person contacted'),'name_board_seen' => array('is_multiple' => 1,'img_name' => 'Business Name Board'),'stock_image' => array('is_multiple' => 1,'img_name' => 'Stock Images'),'workplace_interior_image' => array('is_multiple' => 1,'img_name' => 'Work Place Interior')); + + $img_data = array(); + if(count($sales_pd_img_data)) + { + + foreach ($imgs as $key => $value) + { + //echo "FISRT LOOP****$key"; + foreach ($sales_pd_img_data as $sales_pd_img_data_key => $sales_pd_img_data_value) + { + //echo "SEC LOOP****"; + if($key == $sales_pd_img_data_value['img_name']) + { + if($value['is_multiple']) + { + if(!array_key_exists($key,$img_data)) + { + $img_data[$key] = array('img_key' => $key,'img_name' => $value['img_name'],'img_data' => [array('img_url' => $sales_pd_img_data_value['img'] ? $sales_pd_img_data_value['img'] : '')],'is_multiple' => 1,'section_heading' => $value['img_name']); + } + else + { + $img_data[$key]['img_data'][] = array('img_url' => $sales_pd_img_data_value['img'] ? $sales_pd_img_data_value['img'] : ''); + } + + } + else + { + $img_data[$key] = array('img_key' => $key,'img_name' => $value['img_name'],'img_url' => $sales_pd_img_data_value['img'] ? $sales_pd_img_data_value['img'] : '','is_multiple' => 0,'section_heading' => $value['img_name']);//$sales_pd_img_data_value['img'] + } + + unset($sales_pd_img_data[$sales_pd_img_data_key]); + //break; + } + // else + // { + + // if(!$value['is_multiple']) + // { + + // $img_data[$key] = array('img_key' => $key,'img_name' => $value['img_name'],'img_url' => $value['is_multiple'] == 0 ? '' : array(),'is_multiple' => $value['is_multiple'],'section_heading' => $value['img_name']); + // } + // else + // { + // if(!array_key_exists($key,$img_data)) + // { + // $img_data[$key] = array('img_key' => $key,'img_name' => $value['img_name'],'img_data' => [array('img_url' => $sales_pd_img_data_value['img'] ? 'Y' : 'N')],'is_multiple' => 1,'section_heading' => $value['img_name']); + // } + // else + // { + // $img_data[$key]['img_data'][] = array('img_url' => $sales_pd_img_data_value['img'] ? 'yes' : 'No'); + // } + // } + + // } + } + + //IF current img key is not exist in existing img arry + + if(!array_key_exists($key,$img_data)) + { + + if(!$value['is_multiple']) + { + $img_data[$key] = array('img_key' => $key,'img_name' => $value['img_name'],'img_url' => '','is_multiple' => $value['is_multiple'],'section_heading' => $value['img_name']); + } + else + { + $img_data[$key] = array('img_key' => $key,'img_name' => $value['img_name'],'img_data' => array(),'is_multiple' => $value['is_multiple'],'section_heading' => $value['img_name']); + } + } + } + $img_data = array_values($img_data); + + } + else + { + + foreach ($imgs as $key => $value) + { + if($value['is_multiple']) + { + $img_data[] = array('img_key' => $key,'img_name' => $value['img_name'],'img_data' => array(),'is_multiple' => 1,'section_heading' => $value['img_name']); + + } + else + { + $img_data[] = array('img_key' => $key,'img_name' => $value['img_name'],'img_url' => '','is_multiple' => 0,'section_heading' => $value['img_name']); + } + } + } + + //print_r($img_data); + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = array('smc_credit_pd' => $sales_pd_master_data[0]['smc_credit_pd'],'img_data' => $img_data,'is_cus_link_disabled' => $sales_pd_master_data[0]['is_cus_link_disabled']); + $this->response($data,REST_Controller::HTTP_OK); + } + + + function sendSalesCusLinkViaSMS_post() + { + //$mobile_no = $this->post('mobile_no'); + $random_string = $this->post('random_string'); + $smc_credit_pd = $this->post('smc_credit_pd'); + + // + $response = false; + + //select mobile no from general form + $gen_form = $this->SMC_Credit_PD_Model->selectCustomRecords(array(),array('isactive' => 1,'smc_credit_pd' => $smc_credit_pd,'section_id' => 1,'status' => 1),SMC_CREDIT_PD_SECTION_DATA); + + //print_r($gen_form);die(); + if(is_array($gen_form) && isset($gen_form[0]['smc_credit_pd']) && $gen_form[0]['smc_credit_pd'] == $smc_credit_pd) + { + + //separate mobile no + print_r( json_decode($gen_form[0]['section_data'],true)); + + $msg = "Dear Applicant, Please click the link to upload the photographs. " . SALESPD_CUSTOMER_IMG_URL .$random_string; + echo $msg;die(); + //SALESPD_CUSTOMER_IMG_URL + $res = SMS_GUPSHUP::sendSMS($msg,$mobile_no,array('pd_id' => $smc_credit_pd,'status' => 'SALES PD SMS','msg' => 'Cus Link snd sms from SALES PD controlller'),true); + //print_r($res); + $res = explode('|', $res); + + if(is_array($res) && count($res)) + { + + if(trim($res[0]) == "success") + { + $response = true; + } + } + if($response) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['msg'] = 'SMS Sent Successfully'; + $this->response($data,REST_Controller::HTTP_OK); + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NOT_FOUND; + $data['msg'] = 'SMS Sent Falied. Try Later!'; + $this->response($data,REST_Controller::HTTP_OK); + } + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NOT_FOUND; + $data['msg'] = 'Mobile No Not Found!'; + $this->response($data,REST_Controller::HTTP_OK); + } + + } +} + + \ No newline at end of file diff --git a/api/application/controllers/Sales_PD_Controller.php b/api/application/controllers/Sales_PD_Controller.php index c68e160e..3af915a5 100644 --- a/api/application/controllers/Sales_PD_Controller.php +++ b/api/application/controllers/Sales_PD_Controller.php @@ -33,8 +33,9 @@ class Sales_PD_Controller extends REST_Controller { $lender_id = $records['lender_id']; $product = $records['product_id']; $sales_pd_type = $records['sales_pd_type']; - - $template = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('lender_id' => $lender_id,'product_id' => $product,'sales_pd_type' => $sales_pd_type,'isactive' => 1),SALESPDTEMPLATE); + $pd_type = 1; + if(isset($records['pd_type'])){ $pd_type = $records['pd_type'];} + $template = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('lender_id' => $lender_id,'product_id' => $product,'pd_type' => $pd_type,'sales_pd_type' => $sales_pd_type,'isactive' => 1),SALESPDTEMPLATE); if(is_array($template) && count($template)) { $data['dataStatus'] = true; diff --git a/api/application/models/SMC_Credit_PD_Model.php b/api/application/models/SMC_Credit_PD_Model.php new file mode 100644 index 00000000..bf7e91af --- /dev/null +++ b/api/application/models/SMC_Credit_PD_Model.php @@ -0,0 +1,57 @@ +db->SELECT(' SALES_PD_DATA.sales_pd_sno, SALES_PD_DATA.sales_pd_id, 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.product_id,SALES_PD_DATA.is_pdf,SALES_PD_DATA.is_edited,ENTITY.short_name,PRODUCTS.abbr,SALES_PD_DATA.createdon, + DATE_FORMAT(SALES_PD_DATA.createdon, "%Y-%m-%d") as pd_createdon, SALES_PD_DATA.status,SALES_PD_DATA.sales_pd_type,SALES_PD_DATA.rand_string'); + $this->db->from(SALES_PD_DATA.' as SALES_PD_DATA'); + $this->db->join(ENTITY.' as ENTITY','ENTITY.entity_id = SALES_PD_DATA.lender_id','INNER'); + $this->db->join(PRODUCTS.' as PRODUCTS', 'PRODUCTS.product_id = SALES_PD_DATA.product_id','INNER'); + $this->db->join(USERPROFILE.' as USERPROFILE', 'USERPROFILE.userid = SALES_PD_DATA.createdby','INNER'); + if(!empty($pd_status)){ + $this->db->where_in('SALES_PD_DATA.status',$pd_status); + } + if(($pd_from_date != "" || $pd_from_date != null) && ($pd_to_date != "" || $pd_to_date != null)) { + $this->db->where('SALES_PD_DATA.createdon BETWEEN '. "'$pd_from_date'". ' AND '. "'$pd_to_date'" ); + } + else if($pd_from_date != "" && $pd_from_date != null) { + $this->db->where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d')",$pd_from_date); + } + else if($pd_to_date != "" && $pd_to_date != null) { + $this->db->where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d')",$pd_to_date); + } + if(!empty($pd_products)){ + $this->db->where_in('SALES_PD_DATA.product_id',$pd_products); + } + if(!empty($pd_lender)) { + $this->db->where_in('SALES_PD_DATA.lender_id',$pd_lender); + } + if(!empty($pd_applicant_name)) { + $this->db->like('SALES_PD_DATA.applicant_name',$pd_applicant_name); + } + if(!empty($pd_officer_name)) { + $this->db->like('SALES_PD_DATA.officer_name',$pd_officer_name); + } + + if(!empty($sales_pd_officer_id)) { + $this->db->WHERE('SALES_PD_DATA.createdby',$sales_pd_officer_id); + } + $this->db->WHERE('SALES_PD_DATA.isactive',1); + $this->db->order_by('SALES_PD_DATA.sales_pd_id','desc'); + $this->db->limit(1000,0); + $result = $this->db->get()->result_array(); + // if(ENVIRONMENT == 'development'){echo 'LAST QUERY '. $this->db->last_query();} + return $result; + } + + + +} \ No newline at end of file