874 lines
29 KiB
PHP
874 lines
29 KiB
PHP
<?php
|
|
/**
|
|
|
|
* User: velz
|
|
* This Controller deals with User Management CRUD Operations
|
|
*/
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
|
|
require_once APPPATH . '/libraries/REST_Controller.php';
|
|
|
|
|
|
class Sales_PD_Controller extends REST_Controller {
|
|
|
|
function __construct()
|
|
{
|
|
// Construct the parent class
|
|
parent::__construct();
|
|
$this->load->model('Sales_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'];
|
|
|
|
$template = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('lender_id' => $lender_id,'product_id' => $product,'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['sales_pd_id'])
|
|
// {
|
|
// //generate sales pd serial no
|
|
|
|
// $count = $this->Sales_PD_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $records['lender_id'],'product_id' => $records['product_id']),SALES_PD_DATA);
|
|
|
|
// $lender_short_name = $this->Sales_PD_Model->selectCustomRecords(array('short_name'),array('entity_id' => $records['lender_id']),ENTITY);
|
|
|
|
// $product_short_name = $this->Sales_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->Sales_PD_Model->saveRecords($records,SALES_PD_DATA);
|
|
// satellite_image::getSatelliteImage($id,2);
|
|
// }
|
|
// else
|
|
// {
|
|
// $id = $this->Sales_PD_Model->updateRecords($records,SALES_PD_DATA,array('sales_pd_id' => $records['sales_pd_id']));
|
|
// }
|
|
|
|
// 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($sales_pd_id,$api = true)
|
|
{
|
|
$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_data = $this->Sales_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array);
|
|
//print_r($sales_pd_data);//die();
|
|
|
|
if($sales_pd_data)
|
|
{
|
|
ini_set('max_execution_time', 0);
|
|
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$sales_pd_data[0]['lender_id'];
|
|
$pdf_name = strtolower(trim($sales_pd_data[0]['applicant_name']));
|
|
$pdf_name .= '-'.$sales_pd_data[0]['abbr'];
|
|
$pdf_name .= '-'.(date('dmY',strtotime($sales_pd_data[0]['completed_date'])));
|
|
//$pdf_name = str_replace(' ', '_', $pdf_name);
|
|
|
|
|
|
$key = 'sales_pd/'.$sales_pd_id.'/'.$pdf_name.'.pdf';
|
|
|
|
if(!file_exists($this->external_path.'/sales_pd/'.$sales_pd_id))
|
|
{
|
|
mkdir($this->external_path.'/sales_pd/'.$sales_pd_id,0761);
|
|
}
|
|
|
|
if(!$sales_pd_data[0]['is_pdf'] || $sales_pd_data[0]['is_edited'])
|
|
{
|
|
|
|
|
|
//$json_data = (json_decode($sales_pd_data[0]['pd_json'],true));
|
|
//satellite_image::getSatelliteImage($sales_pd_id,2);
|
|
$all_section_data = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $sales_pd_id,'isactive' => 1),SALESPD_SECTION_DATA);
|
|
// print_r($this->db->last_query());die();
|
|
$view_data['master'] = $sales_pd_data;
|
|
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->Sales_PD_Model->selectCustomRecords(array('*'),array('fk_sales_pd_id' => $sales_pd_id,'img_name !=' => 'satellite','isactive' => 1),SALEPD_DOCS);
|
|
$view_data['satellite_image'] = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('fk_sales_pd_id' => $sales_pd_id,'img_name' => 'satellite','isactive' => 1),SALEPD_DOCS);
|
|
$view_data['product_id'] = $sales_pd_data[0]['product_id'];
|
|
$view_data['geo_location'] = $sales_pd_data[0]['geo_location'];
|
|
//print_r($this->db->last_query());die();
|
|
//$view_name = $sales_pd_data[0]['short_name'].'_'.$sales_pd_data[0]['abbr'];
|
|
$view_name = $sales_pd_data[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/" . $sales_pd_id . "/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/'.$sales_pd_id.'/temp.pdf');
|
|
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
|
|
|
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
|
|
{
|
|
|
|
$this->Sales_PD_Model->updateRecords(array('is_pdf' => 1, 'is_edited' => 0),SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id));
|
|
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()
|
|
{
|
|
$sales_pd_id = $this->uri->segment(2);
|
|
$this->prepareSalesPDReport($sales_pd_id);
|
|
|
|
|
|
}
|
|
|
|
public function listSalesPD_get()
|
|
{
|
|
$lender_id = $this->uri->segment(2);
|
|
$user_id = $this->uri->segment(3);
|
|
$columns = array('SALES_PD_DATA.sales_pd_id','SALES_PD_DATA.sales_pd_sno','SALES_PD_DATA.applicant_name','concat(USERPROFILE.first_name," ",USERPROFILE.first_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','PRODUCT.abbr','SALES_PD_DATA.createdon','SALES_PD_DATA.status');
|
|
$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'),
|
|
array('table' => USERPROFILE. ' as USERPROFILE',
|
|
'condition' =>'SALES_PD_DATA.createdby = USERPROFILE.userid',
|
|
'jointype' => 'LEFT')
|
|
);
|
|
|
|
$where_condition_array = array();
|
|
if(is_numeric($lender_id))
|
|
{
|
|
$where_condition_array = array('SALES_PD_DATA.lender_id' => $lender_id);
|
|
}
|
|
if($user_id && is_numeric($user_id))
|
|
{
|
|
$where_condition_array = array('SALES_PD_DATA.createdby' => $user_id);
|
|
}
|
|
$order_by = 'SALES_PD_DATA.sales_pd_id';
|
|
$sales_pd_data = $this->Sales_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array,$order_by,'DESC');
|
|
if(count($sales_pd_data))
|
|
{
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $sales_pd_data;
|
|
$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 saveSalesPDImage_post()
|
|
{
|
|
$records = $this->post('records');
|
|
|
|
if($records['img_name'] == 'selfie_with_person_met')
|
|
{
|
|
//$location = $records['location'];
|
|
$update_fields = array('geo_location' => $records['location']);
|
|
$this->Sales_PD_Model->updateRecords($update_fields,SALES_PD_DATA,array('sales_pd_id' => $records['fk_sales_pd_id']));
|
|
|
|
//disable previous selfie img
|
|
$update_fields2 = array('isactive' => 0);
|
|
$this->Sales_PD_Model->updateRecords($update_fields2,SALEPD_DOCS,array('img_name' => 'selfie_with_person_met'));
|
|
}
|
|
|
|
$id = $this->Sales_PD_Model->saveRecords($records,SALEPD_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 saveSalesPD_post()
|
|
{
|
|
$records = $this->post('records');
|
|
$is_entry_done = null;
|
|
$id = null;
|
|
//print_r($records);die();
|
|
if($records['sales_pd_id'] == '' || $records['sales_pd_id'] == null)
|
|
{
|
|
|
|
$count = $this->Sales_PD_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $records['lender_id'],'product_id' => $records['product_id']),SALES_PD_DATA);
|
|
|
|
$lender_short_name = $this->Sales_PD_Model->selectCustomRecords(array('short_name'),array('entity_id' => $records['lender_id']),ENTITY);
|
|
|
|
$product_short_name = $this->Sales_PD_Model->selectCustomRecords(array('abbr'),array('product_id' => $records['product_id']),PRODUCTS);
|
|
|
|
$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->Sales_PD_Model->saveRecords($records,SALES_PD_DATA);
|
|
}
|
|
else
|
|
{
|
|
|
|
if(isset($records['status']) && $records['status'] == 'COMPLETED')
|
|
{
|
|
$drafted_sections = $this->Sales_PD_Model->selectCustomRecords(array('section_id'),array('status' => 0,'sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALESPD_SECTION_DATA);
|
|
//print_r($drafted_sections);
|
|
if(count($drafted_sections))
|
|
{
|
|
|
|
//merge section name
|
|
$section_names = array('General Section','Fund Requirement','stakeholders','Brief of business','Financial','Property Details','Officer Details','Final Remraks','Photography');
|
|
|
|
$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
|
|
{
|
|
$records['status'] = 'COMPLETED';
|
|
$records['completed_date'] = date('Y-m-d h:i:s');
|
|
$id = $this->Sales_PD_Model->updateRecords($records,SALES_PD_DATA,array('sales_pd_id' => $records['sales_pd_id']));
|
|
satellite_image::getSatelliteImage($records['sales_pd_id'],2);
|
|
$this->prepareSalesPDReport($records['sales_pd_id'],false);
|
|
//trigger mail function
|
|
PDALERTS::sendSalesPDMail($this,$records['sales_pd_id']);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$id = $this->Sales_PD_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;
|
|
$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 saveSalesPDsection_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->Sales_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 = '';
|
|
$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'] == 'main_loan_applicant')
|
|
{
|
|
$applicant_name = $g_value['answer_value'];
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
$update_fields = array('applicant_name' => $applicant_name,'applicant_id' => $applicant_id);
|
|
$this->Sales_PD_Model->updateRecords($update_fields,SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id));
|
|
|
|
|
|
break;
|
|
|
|
case 2: //Fund Requirement
|
|
break;
|
|
|
|
case 3: //stakeholders
|
|
break;
|
|
|
|
case 4: //brief of business
|
|
|
|
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->Sales_PD_Model->updateRecords($update_fields,SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id));
|
|
break;
|
|
|
|
case 9: //photosection
|
|
break;
|
|
|
|
default:
|
|
}
|
|
|
|
//make inactive previous records
|
|
$this->Sales_PD_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->Sales_PD_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);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public function getSalesPDSectionData_post()
|
|
{
|
|
$records = $this->post('records');
|
|
$section_data = array();
|
|
|
|
if($records['section_id'] != 9)
|
|
{
|
|
$section_data = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $records['sales_pd_id'],'isactive' => 1,'section_id' => $records['section_id']),SALESPD_SECTION_DATA);
|
|
//print_r( json_decode($section_data[0]['section_data'],true));
|
|
}
|
|
else
|
|
{
|
|
$image_order = array('selfie_with_person_met','approach_to_pd_location','name_board_seen','stock_image','workplace_interior_image');
|
|
$images = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('fk_sales_pd_id' => $records['sales_pd_id'],'img_name !=' => 'satellite','isactive' => 1),SALEPD_DOCS);
|
|
//print_r($images);die();
|
|
|
|
$photo_names = array('selfie_with_person_met' => 'Selfie with person met','approach_to_pd_location' => 'Approach to pd location','name_board_seen' => 'Name board seen', 'stock_image' => 'Stock image','workplace_interior_image' => 'Workplace interior image');
|
|
|
|
|
|
$questions = array();
|
|
$questions_group = array();
|
|
|
|
foreach ($photo_names as $photo_key => $photo_value)
|
|
{
|
|
if(count($images))
|
|
{
|
|
// foreach ($images as $key => $value)
|
|
// {
|
|
|
|
//check current photo is exist in images array
|
|
//print_r($photo_key);
|
|
$is_exist = false;
|
|
$exist_data = array();
|
|
|
|
//$question = [];
|
|
foreach ($images as $key => $value)
|
|
{
|
|
if($photo_key == $value['img_name'])
|
|
{
|
|
$is_exist = true;
|
|
$exist_data[] = array('img_name' => $value['img_name'],'img' => $value['img']);
|
|
// unset($images[$key]);
|
|
// break;
|
|
}
|
|
}
|
|
// echo $is_exist;
|
|
// echo '<br>';
|
|
if($is_exist)
|
|
{
|
|
// echo "YESPART";
|
|
// echo '<br>';
|
|
foreach ($exist_data as $exist_data_key => $exist_data_value)
|
|
{
|
|
|
|
|
|
$question['is_repeatable'] = "";
|
|
$question['group_title'] = null;
|
|
$question['answer_value'] = $exist_data_value['img'];
|
|
//$question['answer_value'] = "IMG";
|
|
$question['question'] = $photo_names [ $exist_data_value['img_name'] ];
|
|
$question['question_key'] = $exist_data_value['img_name'];
|
|
$question['type'] = 6;
|
|
$question['validations'] = [];
|
|
$question['raw_validations'] = [];
|
|
$question['api_properties'] = null;
|
|
$question['answers'] = null;
|
|
$question['onchange_properties'] = null;
|
|
if($exist_data_value['img_name'] == 'selfie_with_person_met')
|
|
{
|
|
$questions[] = $question;
|
|
}
|
|
else
|
|
{
|
|
$questions[ $photo_names [ $exist_data_value['img_name'] ] ] ['is_repeatable'] = 1;
|
|
$questions[ $photo_names [ $exist_data_value['img_name'] ] ] ['group_title'] = $photo_names [ $exist_data_value['img_name'] ];
|
|
$questions[ $photo_names [ $exist_data_value['img_name'] ] ] ['group_type'] = 6;
|
|
$questions[ $photo_names [ $exist_data_value['img_name'] ] ] ['questions_group'][0]['questions'][] = $question;
|
|
}
|
|
}
|
|
$exist_data = array();
|
|
|
|
}
|
|
else
|
|
{
|
|
// echo "NOPART";
|
|
// echo '<br>';
|
|
// print_r($questions);
|
|
$question['is_repeatable'] = "";
|
|
$question['group_title'] = null;
|
|
$question['answer_value'] = '';
|
|
//$question['answer_value'] = "IMG";
|
|
$question['question'] = $photo_value;
|
|
$question['question_key'] =$photo_key;
|
|
$question['type'] = 6;
|
|
$question['validations'] = [];
|
|
$question['raw_validations'] = [];
|
|
$question['api_properties'] = null;
|
|
$question['answers'] = null;
|
|
$question['onchange_properties'] = null;
|
|
if($photo_key == 'selfie_with_person_met')
|
|
{
|
|
//echo 'SELFIE';
|
|
$questions[] = $question;
|
|
}
|
|
else
|
|
{
|
|
$questions[ $photo_names [ $value['img_name'] ] ] ['is_repeatable'] = 1;
|
|
$questions[ $photo_names [ $value['img_name'] ] ] ['group_title'] = $photo_value;
|
|
$questions[ $photo_names [ $value['img_name'] ] ] ['group_type'] = 6;
|
|
$questions[ $photo_names [ $value['img_name'] ] ] ['questions_group'][0]['questions'][] = $question;
|
|
}
|
|
//break;
|
|
// print_r($questions);
|
|
// die();
|
|
}
|
|
|
|
//}
|
|
}
|
|
else
|
|
{
|
|
$question['is_repeatable'] = "";
|
|
$question['group_title'] = null;
|
|
$question['answer_value'] = '';
|
|
//$question['answer_value'] = "IMG";
|
|
$question['question'] = $photo_value;
|
|
$question['question_key'] =$photo_key;
|
|
$question['type'] = 6;
|
|
$question['validations'] = [];
|
|
$question['raw_validations'] = [];
|
|
$question['api_properties'] = null;
|
|
$question['answers'] = null;
|
|
$question['onchange_properties'] = null;
|
|
if($photo_key == 'selfie_with_person_met')
|
|
{
|
|
$questions[] = [];
|
|
}
|
|
else
|
|
{
|
|
$questions[ $photo_key ] ['is_repeatable'] = 1;
|
|
$questions[ $photo_key ] ['group_title'] = $photo_value;
|
|
$questions[ $photo_key ] ['group_type'] = 6;
|
|
$questions[ $photo_key ] ['questions_group'][0]['questions'][] = [];
|
|
}
|
|
}
|
|
}
|
|
|
|
$temp['questions'] = array_values($questions);
|
|
//print_r($questions);die();
|
|
|
|
$temp['section_id'] = 9;
|
|
$temp['section_name'] = 'Photography';
|
|
$temp['onsubmit'] = '';
|
|
$temp['sales_pd_id'] = $records['sales_pd_id'];
|
|
|
|
//print_r($temp);die();
|
|
$temp2['section_data'] = json_encode($temp);
|
|
|
|
$temp2['id'] = null;
|
|
$temp2['sales_pd_id'] = $records['sales_pd_id'];
|
|
$temp2['section_id'] = $records['section_id'];
|
|
$temp2['status'] = '1';
|
|
$section_data[] = $temp2;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|