2307 lines
103 KiB
PHP
2307 lines
103 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';
|
|
include_once APPPATH.'/vendor/autoload.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->helper('camunda');
|
|
$this->load->library('phpmailer_library');
|
|
$this->load->helper('cet_salespd');
|
|
$this->load->helper('smcfinance');
|
|
|
|
|
|
}
|
|
|
|
public function loadSalesPDTemplate_post()
|
|
{
|
|
$records = $this->post('records');
|
|
$lender_id = $records['lender_id'];
|
|
$product = $records['product_id'];
|
|
$sales_pd_type = $records['sales_pd_type'];
|
|
$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;
|
|
$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)
|
|
{
|
|
$this->load->library('Googlecloud');
|
|
log_message('ERROR','####PREPARE SALESPD REPORT CALLED'.$sales_pd_id);
|
|
$columns = array('SALES_PD_DATA.*','ENTITY.short_name','PRODUCT.abbr','USERPROFILE.smc_emp_code');
|
|
$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('SALES_PD_DATA.sales_pd_id' => $sales_pd_id);
|
|
$sales_pd_data = $this->Sales_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array);
|
|
$pd_type = "";
|
|
if($sales_pd_data[0]['sales_pd_type'] == 1){$pd_type = "Physical PD-"; }else if($sales_pd_data[0]['sales_pd_type'] == 2){$pd_type = "Tele PD-";}
|
|
|
|
if($sales_pd_data)
|
|
{
|
|
ini_set('max_execution_time', 0);
|
|
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$sales_pd_data[0]['lender_id'];
|
|
// 1st Type Key name. (name,abbr and date).
|
|
$pdf_name = strtolower(trim($sales_pd_data[0]['applicant_name']));
|
|
$pdf_name .= '-'.$pd_type.$sales_pd_data[0]['abbr'];
|
|
$pdf_name .= '-'.(date('dmY',strtotime($sales_pd_data[0]['completed_date'])));
|
|
//$pdf_name = str_replace(' ', '_', $pdf_name);
|
|
$old_pdf_name = strtolower(trim($sales_pd_data[0]['applicant_name']));
|
|
$old_pdf_name .= '-'.$sales_pd_data[0]['abbr'];
|
|
$old_pdf_name .= '-'.(date('dmY',strtotime($sales_pd_data[0]['completed_date'])));
|
|
$old_key = 'sales_pd/'.$sales_pd_id.'/'.$old_pdf_name.'.pdf';
|
|
$bucketkey = 'sales_pd/'.$sales_pd_id.'/'.$pdf_name.'.pdf';
|
|
//$this->Sales_PD_Model->updateRecords(array('pd_report_filename' => 'PD_Report-'.$pdf_name),SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id));
|
|
|
|
if(!file_exists($this->external_path.'/sales_pd/'.$sales_pd_id))
|
|
{
|
|
mkdir($this->external_path.'/sales_pd/'.$sales_pd_id,0777);
|
|
}
|
|
|
|
if(!$sales_pd_data[0]['is_pdf'] || $sales_pd_data[0]['is_edited'])
|
|
{
|
|
|
|
$all_section_data = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $sales_pd_id,'isactive' => 1),SALESPD_SECTION_DATA,array(),'','section_id','ASC');
|
|
// print_r(json_decode($all_section_data[0]['section_data'],true));die();
|
|
$view_data['master'] = $sales_pd_data;
|
|
foreach ($all_section_data as $sec_key => $section)
|
|
{
|
|
// print_r($section['section_id']);die();
|
|
$view_data['section'.$section['section_id'] ] = $this->processSalesPDJSON($section);//die();
|
|
}
|
|
// print_r($view_data['section3']);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);
|
|
if($view_data['section9']){
|
|
// $gcpBucketName = GCP_BUCKET_NAME;
|
|
foreach ($view_data['section9'] as $key => $value){
|
|
if($value['img_name'] != '' ){
|
|
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$sales_pd_data[0]['lender_id'];
|
|
$img_rand_name = $value['rand_name'] != null ? $value['rand_name'] : $value['img_name'].".png" ;
|
|
$bucket_key = "sales_pd/".$sales_pd_data[0]['sales_pd_id']."/images/".$img_rand_name;
|
|
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name, $bucket_key,'30 minutes');
|
|
$img_url = $value['img'] ? $value['img'] : ($singed_uri ? $singed_uri : "");
|
|
$view_data['section9'][$key]['img'] = $img_url;
|
|
// $objectName = "pd".$sales_pd_id."/images/".$value['img_name'].".png";
|
|
// $img_gcp_url = $this->googlecloud->getSingleObjectInaBucketAsSignedURI($gcpBucketName,$objectName);
|
|
// $view_data['section9'][$key]['img'] = $img_gcp_url ? $img_gcp_url : "";
|
|
// echo "img". $img_gcp_url;
|
|
}
|
|
}
|
|
}
|
|
|
|
$satellite_image = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('fk_sales_pd_id' => $sales_pd_id,'img_name' => 'satellite','isactive' => 1),SALEPD_DOCS);
|
|
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$sales_pd_data[0]['lender_id'];
|
|
$bucket_key = "sales_pd/".$sales_pd_data[0]['sales_pd_id']."/images/satellite.png";
|
|
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name, $bucket_key,'30 minutes');
|
|
$img_url = $value['img'] ? 'data:image/gif;base64,'.$satellite_image[0]['img'] : ($singed_uri ? $singed_uri : "");
|
|
$view_data['satellite_image'] = $img_url;
|
|
// $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'];if( $sales_pd_data[0]['abbr'] == 'MEQ'){ $view_name = $sales_pd_data[0]['abbr']; }
|
|
$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'=>$bucketkey,'sourcefile'=>$this->external_path.'/sales_pd/'.$sales_pd_id.'/temp.pdf');
|
|
log_message('ERROR','####SALES PD REPORT UPLOAD TO S3'.$sales_pd_id);
|
|
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
|
/*** GCP Report Upload here */
|
|
$gcpBucketName = GCP_BUCKET_NAME;
|
|
$gcpObjectName = "pd".$sales_pd_id."/".$sales_pd_id.".pdf";
|
|
$source=$output_file;
|
|
$gcpResult = $this->googlecloud->uploadFileToGCPBucket($gcpBucketName,$gcpObjectName,$source);
|
|
$report_gcp_url = '';
|
|
if($gcpResult == true){
|
|
$report_gcp_url = $this->googlecloud->getSingleObjectInaBucketAsSignedURI($gcpBucketName,$gcpObjectName);
|
|
}
|
|
|
|
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));
|
|
sleep(10);
|
|
$result = $this->dataSynchronization($sales_pd_id,0);
|
|
$data['CETresponse'] = $result;
|
|
log_message('ERROR', '#### Automation CET Data Push Sales PD ('.$sales_pd_id.') status : '.$result->status);
|
|
if(isset($result->status) && $result->status == 200){
|
|
log_message('ERROR', '#### Sales PD ('.$sales_pd_id.') status : '.$result->status." Data Transfered");
|
|
$update_fields2 = array('is_the_data_transfer_cet' => 1);
|
|
$this->Sales_PD_Model->updateRecords($update_fields2,SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id));
|
|
}else{
|
|
log_message('ERROR', '#### Sales PD ('.$sales_pd_id.") Data Not Transfered");
|
|
}
|
|
if($api)
|
|
{
|
|
$_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$bucketkey,'30 minutes');
|
|
$headers = @get_headers($_uri);
|
|
if($headers && strpos( $headers[0], '200')) {
|
|
$singed_uri = $_uri;
|
|
}else {
|
|
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$old_key,'30 minutes');
|
|
}
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $singed_uri;
|
|
$data['gcpUrl'] = $report_gcp_url;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if($api)
|
|
{
|
|
## NEW KEY BECAUSE TITLE-RENAME
|
|
$_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$bucketkey,'30 minutes');
|
|
$headers = @get_headers($_uri);
|
|
if($headers && strpos( $headers[0], '200')) {
|
|
$singed_uri = $_uri;
|
|
}else {
|
|
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$old_key,'30 minutes');
|
|
}
|
|
$gcpBucketName = GCP_BUCKET_NAME;
|
|
$gcpObjectName = "pd".$sales_pd_id."/".$sales_pd_id.".pdf";
|
|
$report_gcp_url = $this->googlecloud->getSingleObjectInaBucketAsSignedURI($gcpBucketName,$gcpObjectName);
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $singed_uri;
|
|
$data['gcpUrl'] = $report_gcp_url;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function uploadSalesPDDataToCETApp_get()
|
|
{
|
|
$sales_pd_id = $this->uri->segment(2);
|
|
if($sales_pd_id){
|
|
log_message('ERROR', '#### upload Sales PDData To CETApp Function Called');
|
|
$columns = array('SALES_PD_DATA.sales_pd_id');
|
|
$table = SALES_PD_DATA . ' as SALES_PD_DATA';
|
|
$where_arr = array('SALES_PD_DATA.is_the_data_transfer_cet'=>1,'SALES_PD_DATA.status' => COMPLETED,'SALES_PD_DATA.sales_pd_id'=>$sales_pd_id);
|
|
$details = $this->Sales_PD_Model->selectCustomRecords($columns, $where_arr, $table);
|
|
if(!empty($details)){
|
|
$response = $this->dataSynchronization($sales_pd_id,0);
|
|
$data['CETresponse'] = $response;
|
|
if(isset($response->status) && ($response->status == 200)){
|
|
log_message('ERROR', '#### Sales PD ('.$sales_pd_id.') status '.$response->status." Data Transfered");
|
|
$update_fields2 = array('is_the_data_transfer_cet' => 1);
|
|
$this->Sales_PD_Model->updateRecords($update_fields2,SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id));
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['msg'] = 'Data Shared Successfully';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}else{
|
|
log_message('ERROR', '#### Sales PD ('.$sales_pd_id.") Data Not Transfered");
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'Something went wrong! Try Later';
|
|
$this->response($data, REST_Controller::HTTP_OK);
|
|
}
|
|
}else{
|
|
log_message('ERROR', $sales_pd_id.' Data already uploaded');
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'Data already uploaded! Try Later';
|
|
$this->response($data, REST_Controller::HTTP_OK);
|
|
}
|
|
}else{
|
|
$msg = 'Can`t Upload. ID Not Founded ! Try Later';
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = $msg;
|
|
log_message('ERROR', $msg);
|
|
$this->response($data, REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
}
|
|
public function transferSalesPDToCETApp_get()
|
|
{
|
|
$from_date = $this->get('from_date');
|
|
$to_date = $this->get('to_date');
|
|
if(($from_date != "" || $from_date != null) && ($to_date != "" || $to_date != null)){
|
|
$newDate1 = date("Y-m-d", strtotime($from_date));
|
|
$newDate2 = date("Y-m-d", strtotime($to_date));
|
|
$msg = " SMC-Credit PDData Transfer To CETApp Date Given Format => " . $from_date ." to ".$to_date;
|
|
// $where = 'DATE(PDTRIGGER.completed_on) BETWEEN ' ."'$newDate1'". ' AND ' ."'$newDate2'";
|
|
$columns = array('SALES_PD_DATA.sales_pd_id','SALES_PD_DATA.status', 'SALES_PD_DATA.completed_date');
|
|
$table = SALES_PD_DATA . ' as SALES_PD_DATA';
|
|
$where = 'DATE(SALES_PD_DATA.completed_date)
|
|
BETWEEN ' ."'$newDate1'". ' AND ' ."'$newDate2'";
|
|
$where_arr = array('SALES_PD_DATA.is_the_data_transfer_cet'=>0,'SALES_PD_DATA.status' => COMPLETED, $where => null);
|
|
// $where_arr = array('SALES_PD_DATA.status' => COMPLETED, $where => null);
|
|
$details = $this->Sales_PD_Model->selectCustomRecords($columns, $where_arr, $table);
|
|
// log_message('ERROR', $msg." Changed ".$newDate1." to ".$newDate2." Total Records => " . count($details));
|
|
log_message('ERROR', $msg." Total Records => " . count($details));
|
|
if(!empty($details)){
|
|
$flag = 0;$ids=array();
|
|
for ($i = 0; $i < count($details); $i++) {
|
|
log_message('ERROR', "inx = $i ".$details[$i]['sales_pd_id']);
|
|
$sales_pd_id = $details[$i]['sales_pd_id'];
|
|
// echo $sales_pd_id;
|
|
$result = $this->dataSynchronization($sales_pd_id,0);
|
|
$data['CETresponse'][$sales_pd_id] = $result;
|
|
sleep(2);
|
|
if(isset($result->status) && $result->status == 200){
|
|
$flag = $flag+1;
|
|
//update here.
|
|
log_message('ERROR', '#### Sales PD ('.$sales_pd_id.') status '.$result->status." Data Transfered");
|
|
$update_fields2 = array('is_the_data_transfer_cet' => 1);
|
|
$this->Sales_PD_Model->updateRecords($update_fields2,SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id));
|
|
array_push($ids, $sales_pd_id);
|
|
}else{
|
|
log_message('ERROR', '#### Sales PD ('.$sales_pd_id.") Data Not Transfered");
|
|
}
|
|
// $flag = ($result == true) ? $flag+1 : $flag;
|
|
}
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['msg'] = implode(', ', $ids).' ( '.$flag.' ) Data Shared Successfully';
|
|
$this->response($data, REST_Controller::HTTP_OK);
|
|
}else{
|
|
$msg = 'There is no data for Given Date ! Try Later';
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = $msg;
|
|
log_message('ERROR', $msg);
|
|
$this->response($data, REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
else {
|
|
$msg = 'Can`t Upload Date Not Founded ! Try Later';
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = $msg;
|
|
log_message('ERROR', $msg);
|
|
$this->response($data, REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
function dataSynchronization($sales_pd_id,$dummy_flag)
|
|
{
|
|
if(!empty($sales_pd_id)){
|
|
$columns = array('SALES_PD_DATA.*','ENTITY.short_name','PRODUCT.abbr','USERPROFILE.smc_emp_code');
|
|
$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('SALES_PD_DATA.sales_pd_id' => $sales_pd_id);
|
|
$sales_pd_data = $this->Sales_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array);
|
|
// log_message('ERROR', '#### Sales PD ('.$sales_pd_id.') There are ' . count($sales_pd_data).' Forms ');
|
|
log_message('ERROR', '#### Sales PD ('.$sales_pd_id.')');
|
|
if(count($sales_pd_data)>0)
|
|
{
|
|
$all_section_data = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $sales_pd_id,'isactive' => 1),SALESPD_SECTION_DATA,array(),'','section_id','ASC');
|
|
|
|
$common_fields = array('pdid'=>$sales_pd_data[0]['sales_pd_id'],
|
|
'product'=>$sales_pd_data[0]['abbr'],
|
|
'caseno'=>$sales_pd_data[0]['sales_pd_sno'],
|
|
'sales_pd_type'=>$sales_pd_data[0]['sales_pd_type'],
|
|
'completed_date'=>$sales_pd_data[0]['completed_date'],
|
|
'employee_id'=>$sales_pd_data[0]['smc_emp_code']);
|
|
|
|
foreach ($all_section_data as $sec_key => $section)
|
|
{
|
|
if($section['section_id'] != 9){
|
|
$section_fields['section'.$section['section_id'] ] = $this->processSalesPDJSON($section); }
|
|
}
|
|
|
|
|
|
|
|
// cet_salespd::pushwithcetsalespdapi($common_fields,$section_fields,1);
|
|
$CETAPP_salesPD_data = $section_fields;
|
|
$officer_name = isset($CETAPP_salesPD_data['section8']['name_of_sales_team_member']) ? $CETAPP_salesPD_data['section8']['name_of_sales_team_member'] : '';
|
|
if(!empty($officer_name)){
|
|
$officer_details = $this->Sales_PD_Model->selectCustomRecords(array('userid as officer_id', 'email','mobile_no','concat(first_name," ",last_name) as officer_full_name'),array('first_name' => $officer_name),USERPROFILE);
|
|
if(!empty($officer_details)){
|
|
foreach($officer_details as $key=>$value) {
|
|
$CETAPP_salesPD_data['section8'] = array_merge($section_fields['section8'],$value);
|
|
$CETAPP_salesPD_data['section8']['employee_id'] = isset($sales_pd_data[0]['smc_emp_code']) ? $sales_pd_data[0]['smc_emp_code'] : '';
|
|
}
|
|
}
|
|
}
|
|
if($dummy_flag == 0){
|
|
$photograph_data = $this->Sales_PD_Model->selectCustomRecords(array('img_name','IF(img_name="satellite","satellite.png",rand_name) AS img'),array('fk_sales_pd_id' => $sales_pd_id,'isactive' => 1),SALEPD_DOCS);
|
|
log_message('ERROR', '#### Automation DataPush - SalesPD ('.$sales_pd_id.') There are ' . count($photograph_data).' Images');
|
|
if(!empty($photograph_data)) $CETAPP_salesPD_data['section9'] = $photograph_data;
|
|
}
|
|
|
|
// print_r($common_fields);die();
|
|
$result = cet_salespd::pushwithcetsalespdapi($common_fields,$CETAPP_salesPD_data,1);
|
|
if(isset($result->status) && $result->status == 200){
|
|
if($dummy_flag == 1){
|
|
$photograph_data = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('fk_sales_pd_id' => $sales_pd_id,'img_name !=' => 'satellite','isactive' => 1),SALEPD_DOCS);
|
|
$satellite_image = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('fk_sales_pd_id' => $sales_pd_id,'img_name' => 'satellite','isactive' => 1),SALEPD_DOCS);
|
|
log_message('ERROR', '#### Sales PD ('.$sales_pd_id.') There are ' . count($photograph_data).' Images');
|
|
$totalimages = count($satellite_image)+count($photograph_data);
|
|
if(count($photograph_data)>0){
|
|
$j=0;
|
|
for ($i = 0; $i < count($photograph_data); $i++){
|
|
$img_fields = $common_fields;
|
|
$img_fields['img_name'] = $photograph_data[$i]['img_name'];
|
|
$img_split = explode( ',', $photograph_data[$i]['img']);
|
|
$img_fields['img'] = $img_split[1];
|
|
// $img_fields[0]['img'] = $photograph_data[$i]['img'];
|
|
$img_result = cet_salespd::pushwithcetphotographapi($img_fields,$i);
|
|
if(isset($img_result->status) && ($img_result->status == 200)){$j++;}else{ log_message('ERROR', '#### Sales PD ('.$sales_pd_id.') ' . $photograph_data[$i]['img_name'].' Images Not Transfer Check it'); }
|
|
}
|
|
}
|
|
|
|
if(!empty($satellite_image)){
|
|
log_message('ERROR', '#### Sales PD ('.$sales_pd_id.') satellite Available');
|
|
$stt_fields = $common_fields;
|
|
$stt_fields['img_name'] = $satellite_image[0]['img_name'];
|
|
$stt_fields['img'] = $satellite_image[0]['img'];
|
|
$stt_result = cet_salespd::pushwithcetphotographapi($stt_fields,0);
|
|
if(isset($stt_result->status) && ($stt_result->status == 200)){$j++;}else{ log_message('ERROR', '#### Sales PD ('.$sales_pd_id.') ' . $satellite_image[0]['img_name'].' Images Not Transfer Check it'); }
|
|
}
|
|
$result->imageStatus = $j.'/'.$totalimages;
|
|
}
|
|
return $result;
|
|
}else{
|
|
log_message('ERROR',"### CET APP SALES PDID (".$sales_pd_id.") PullSalesPDData response :".json_encode($result));
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'Sales pd details Not Pushed ! Try Later';
|
|
}
|
|
}
|
|
else
|
|
{
|
|
log_message('ERROR','#### There is No Data Found relevant Sales PDID ');
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'There is No Data Found relevant Sales PDID ! Try Later';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
}else{
|
|
log_message('ERROR','#### Can`t able Found the Sales PDID ');
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'Can`t able Found the Sales PDID ! Try Later';
|
|
$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()
|
|
{
|
|
//echo "sales ctrl";die();
|
|
$lender_id = $this->uri->segment(2);
|
|
$user_id = $this->uri->segment(3);
|
|
$role = $this->uri->segment(4);
|
|
$redirect_email = base64_decode($this->uri->segment(5)); # becoz email can't able to send in url. so encoded
|
|
// echo base64_decode($redirect_email);
|
|
|
|
$columns = array('SALES_PD_DATA.sales_pd_id','SALES_PD_DATA.sales_pd_sno','SALES_PD_DATA.applicant_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.status','SALES_PD_DATA.sales_pd_type','SALES_PD_DATA.rand_string','SALES_PD_DATA.isactive','SALES_PD_DATA.city_id','CITY.name as city_name',
|
|
'(CASE WHEN SALES_PD_DATA.status = "STARTED" THEN SALES_PD_DATA.createdon WHEN SALES_PD_DATA.status = "COMPLETED" THEN SALES_PD_DATA.completed_date ELSE NULL END) AS createdon'
|
|
// ,"DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d') as modify","DATE_ADD(CURDATE(),INTERVAL '-10' DAY) as currd",
|
|
// "(CURDATE()) as daye10"
|
|
);
|
|
if($user_id && is_numeric($user_id)){array_push($columns, 'concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as officer_name');}
|
|
else if($user_id && is_string($user_id)){array_push($columns, 'SALES_PD_DATA.redirect_email as officer_name');}
|
|
$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' => CITY. ' as CITY',
|
|
'condition' =>'SALES_PD_DATA.city_id = CITY.city_id',
|
|
'jointype' => 'LEFT'),
|
|
);
|
|
if($user_id && is_numeric($user_id)){
|
|
$user_join = array('table' => USERPROFILE. ' as USERPROFILE',
|
|
'condition' =>'SALES_PD_DATA.createdby = USERPROFILE.userid',
|
|
'jointype' => 'LEFT');
|
|
array_push($joins, $user_join);
|
|
}
|
|
|
|
$or_where = array();
|
|
$where_condition_array['SALES_PD_DATA.isactive'] = 1;
|
|
if(is_numeric($lender_id))
|
|
{
|
|
$where_condition_array['SALES_PD_DATA.lender_id'] = $lender_id;
|
|
}
|
|
$where_condition_array['SALES_PD_DATA.status !='] = 'ARCHIVED';
|
|
// FILTERING THE LAST 10 DAYS RECORDS
|
|
|
|
$key_date='SALES_PD_DATA.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---
|
|
$MWISELender = (ENVIRONMENT == 'production' ? 7 : 35);
|
|
if($role && is_numeric($role) && $role == 11 && $MWISELender == $lender_id){
|
|
// $where_condition_array['SALES_PD_DATA.product_id'] = (ENVIRONMENT == 'production' ? 23 : 22);
|
|
}else{
|
|
if($role && is_numeric($role) && $role == 15) //if role area sales head the pull all meq cases
|
|
{
|
|
$where_condition_array['SALES_PD_DATA.product_id'] = (ENVIRONMENT == 'production' ? 23 : 22);
|
|
$or_where['SALES_PD_DATA.createdby'] = $user_id;
|
|
}
|
|
else if($user_id && is_numeric($user_id))
|
|
{
|
|
$where_condition_array['SALES_PD_DATA.createdby'] = $user_id;
|
|
}
|
|
else if($user_id && is_string($user_id)){
|
|
# here $user_id is numeric means createdby else redirect_email.becoz sales auto-login
|
|
$where_condition_array['SALES_PD_DATA.redirect_email'] = base64_decode($user_id);
|
|
}
|
|
|
|
if(!empty($redirect_email)){
|
|
$or_where['SALES_PD_DATA.redirect_email'] = $redirect_email;
|
|
}
|
|
|
|
}
|
|
$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','',$or_where);
|
|
// print_r($sales_pd_data);
|
|
// print_r($this->db->last_query());die();
|
|
|
|
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' || $question['question_key'] == 'constitution' || $question['question_key'] == 'about_locality' || $question['question_key'] == 'equipment_list' || $question['question_key'] == 'vendor_list' || $question['question_key'] == 'person_met_designation')
|
|
{
|
|
//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'].',';
|
|
|
|
}
|
|
// echo 'FIRST';print_r($temp_array[ $question['question_key'] ]);
|
|
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);
|
|
}
|
|
//echo 'SECOND'; print_r($temp_array[ $question['question_key'] ]);
|
|
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);echo '***';
|
|
if(!is_array($id))
|
|
{
|
|
foreach($array as $value)
|
|
{
|
|
if($id == $value['answer_id'])
|
|
{
|
|
return ($value['answer']);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$final_string = '';
|
|
|
|
foreach($id as $value)
|
|
{
|
|
//echo $value.'****'.strcasecmp($value,'Others').'#';
|
|
foreach($array as $mas_value)
|
|
{
|
|
if( !strcasecmp($value,$mas_value['answer_id']) && (!substr_count($mas_value['answer'],'Others')) )
|
|
{
|
|
$final_string .= $mas_value['answer'] . ',';
|
|
}
|
|
}
|
|
}
|
|
// print_r($final_string);//die();
|
|
return $final_string;
|
|
}
|
|
|
|
}
|
|
|
|
public function saveSalesPDImage_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->Sales_PD_Model->updateRecords($update_fields,SALES_PD_DATA,array('sales_pd_id' => $records['fk_sales_pd_id']));
|
|
|
|
|
|
//satellite_image::getSatelliteImage($records['fk_sales_pd_id'],2);
|
|
|
|
//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','fk_sales_pd_id' => $records['fk_sales_pd_id']));
|
|
if($is_customer_app)
|
|
{
|
|
$this->Sales_PD_Model->updateRecords(array('isactive' => 0),SALESPD_SECTION_DATA,array('section_id' => 9,'sales_pd_id' => $records['fk_sales_pd_id']));
|
|
log_message('ERROR', '### SATELLITE IMAGE STORED IN S3 DONE - ');
|
|
}
|
|
|
|
}
|
|
if(!empty($records['img_id']) && $records['img_name'] != 'selfie_with_person_met'){
|
|
$update_fields2 = array('isactive' => 0);
|
|
$this->Flyhi_Model->updateRecords($update_fields2,SALEPD_DOCS,array('doc_id'=>$records['img_id']));
|
|
}
|
|
unset($records['img_id']);
|
|
$sales_pd_id = $records['fk_sales_pd_id'];
|
|
$image_inserted = 0;
|
|
$source=$records['img'];
|
|
//Google Library - GCP
|
|
$this->load->library('Googlecloud');
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < 6; $i++)
|
|
{
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
}
|
|
$rand_name = $records['img_name'] == 'satellite' ? $records['img_name'].".png" : $records['img_name']."_".$randomString.".png";
|
|
$gcpBucketName = GCP_BUCKET_NAME;
|
|
$objectName = "pd".$sales_pd_id."/images/".$rand_name;
|
|
$result = $this->googlecloud->uploadFileToGCPBucket($gcpBucketName,$objectName,$source);
|
|
if($result == true){
|
|
$image_inserted++;
|
|
log_message('ERROR', '### Sales-PD ('.$sales_pd_id.') '.$records['img_name'].' Image Stored In GCP');
|
|
}else{ log_message('ERROR', '### Sales-PD ('.$sales_pd_id.') '.$records['img_name'].' Image Not Stored In GCP'); }
|
|
//Amazon Library - S3
|
|
$columns = array('SALES_PD_DATA.lender_id');
|
|
$table = SALES_PD_DATA.' as SALES_PD_DATA';
|
|
$where_condition_array = array('SALES_PD_DATA.sales_pd_id' => $sales_pd_id);
|
|
$sales_pd_data = $this->Sales_PD_Model->selectCustomRecords($columns,$where_condition_array,$table);
|
|
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$sales_pd_data[0]['lender_id'];
|
|
$bucket_key = "sales_pd/".$sales_pd_id."/images/".$rand_name;
|
|
$bucket_data = array('bucket_name' => $bucket_name, 'key' => $bucket_key, 'sourcefile' => $source);
|
|
$s3result = $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
|
if (is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) {
|
|
$image_inserted++;
|
|
log_message('ERROR', '### Sales-PD ('.$sales_pd_id.') '.$records['img_name'].' Image Stored In S3');
|
|
}else{ log_message('ERROR', '### Sales-PD ('.$sales_pd_id.') '.$records['img_name'].' Image Not Stored In S3'); }
|
|
if($image_inserted>=1){
|
|
unset($records['img']);
|
|
$records['rand_name'] = $rand_name;
|
|
$id = $this->Sales_PD_Model->saveRecords($records,SALEPD_DOCS);
|
|
log_message('ERROR', '### Sales-PD ('.$sales_pd_id.') Image Saved in DB - id : '.$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);
|
|
}
|
|
}
|
|
|
|
public function saveSalesPD_post()
|
|
{
|
|
$records = $this->post('records');
|
|
$is_entry_done = null;
|
|
$id = null;
|
|
// print_r($records);//die();
|
|
log_message('ERROR','####SALESPD SAVE CALLED');
|
|
$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);
|
|
|
|
$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');
|
|
if($product_short_name[0]['abbr'] == 'MEQ')
|
|
{
|
|
$section_names = array('1' => 'General Section','2' => 'Fund Requirement','3' => 'stakeholders','4' => 'Institution Details','5' => 'Product Information','6' => 'Financial Information','7' => 'Final Remraks','8' => 'Officer Details','9' => 'Photography');
|
|
}
|
|
|
|
$count = $this->Sales_PD_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $records['lender_id'],'product_id' => $records['product_id'],'isactive' => 1),SALES_PD_DATA);
|
|
|
|
|
|
// die();
|
|
if($records['sales_pd_id'] == '' || $records['sales_pd_id'] == null)
|
|
{
|
|
|
|
|
|
/************ASSIGN Random URL******************/
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < 16; $i++)
|
|
{
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
}
|
|
$records['rand_string'] = $randomString;
|
|
log_message('ERROR','####INSERT NEW 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['sales_pd_sno'] = $salepd_serial_no;
|
|
// print_r($records);die();
|
|
$id = $this->Sales_PD_Model->saveRecords($records,SALES_PD_DATA);
|
|
|
|
//start camunda process
|
|
//CAMUNDA::startSalesPDInstance($id);
|
|
}
|
|
else
|
|
{
|
|
//echo $product_short_name[0]['abbr'];
|
|
if(isset($records['status']) && $records['status'] == 'COMPLETED')
|
|
{
|
|
log_message('ERROR','####COMPLETE SALESPD'.$records['sales_pd_id']);
|
|
$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);
|
|
|
|
$completed_sections = $this->Sales_PD_Model->selectCustomRecords(array('section_id'),array('status' => 1,'sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALESPD_SECTION_DATA);
|
|
// print_r($completed_sections);die();
|
|
|
|
if($records['sales_pd_type'] == 1)
|
|
{
|
|
$img_satellite_check = $this->Sales_PD_Model->selectCustomRecords(array('count(*) as count'),array('img_name' => 'satellite','fk_sales_pd_id' => $records['sales_pd_id'],'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->Sales_PD_Model->selectCustomRecords(array('count(*) as count'),array('img_name' => 'selfie_with_person_met','fk_sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALEPD_DOCS);
|
|
|
|
|
|
|
|
$dup_of_section_names = $section_names;
|
|
// print_r($dup_of_section_names);
|
|
foreach ($completed_sections as $completed_section_key => $completed_section_value)
|
|
{
|
|
if($dup_of_section_names [ $completed_section_value['section_id'] ] )
|
|
{
|
|
unset($dup_of_section_names [ $completed_section_value['section_id'] ]);
|
|
}
|
|
}
|
|
|
|
// print_r($dup_of_section_names);
|
|
unset($dup_of_section_names[9]);//unset photograph always
|
|
if($product_short_name[0]['abbr'] == "WCTL"){ unset($dup_of_section_names[6]);}
|
|
if($product_short_name[0]['abbr'] == "MEQ")
|
|
{
|
|
$gen = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('status' => 1,'sales_pd_id' => $records['sales_pd_id'],'isactive' => 1,'section_id' => 1),SALESPD_SECTION_DATA);
|
|
if(count($gen))
|
|
{
|
|
$gen = json_decode($gen[0]['section_data'],true);
|
|
//echo $gen['questions'][2]['answer_value'];
|
|
if($gen['questions'][2]['answer_value'] == 9 || $gen['questions'][2]['answer_value'] == 10)
|
|
{
|
|
unset($dup_of_section_names[3]);// remove stake holders if MEQ Gen sectio have constitiion as socity or trust
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
// 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->Sales_PD_Model->updateRecords($records,SALES_PD_DATA,array('sales_pd_id' => $records['sales_pd_id']));
|
|
$columns = array('SALES_PD_DATA.sales_pd_sno','SALES_PD_DATA.applicant_id');
|
|
$table = SALES_PD_DATA.' as SALES_PD_DATA';
|
|
$where_condition_array = array('SALES_PD_DATA.sales_pd_id' => $records['sales_pd_id']);
|
|
$sales_pd_data = $this->Sales_PD_Model->selectCustomRecords($columns,$where_condition_array,$table);
|
|
$sales_pd_sno = $sales_pd_data[0]['sales_pd_sno'];
|
|
$applicant_id = $sales_pd_data[0]['applicant_id'];
|
|
$smcauthtoken = smcfinance::SmcFinanceAuthUrl();
|
|
if($smcauthtoken != null){
|
|
smcfinance::SmcFinanceApiUrl($applicant_id,$records['sales_pd_id'],$sales_pd_sno,2,$smcauthtoken);
|
|
}else{
|
|
log_message('ERROR','## SMC Finance Auth Token Not Founded, '.$smcauthtoken);
|
|
}
|
|
|
|
//CAMUNDA::completeSalesPDTask($records['sales_pd_id']);
|
|
|
|
$this->prepareSalesPDReport($records['sales_pd_id'],false);
|
|
sleep(10);
|
|
log_message('ERROR','####SALESPD AFTER 10 PREPARED REPORT'.$records['sales_pd_id']);
|
|
//echo 'afetr 10';
|
|
//trigger mail function
|
|
$city = '';
|
|
$form = $this->Sales_PD_Model->selectCustomRecords(array(),array('isactive' => 1,'sales_pd_id' => $records['sales_pd_id'],'section_id' => 1,'status' => 1),SALESPD_SECTION_DATA);
|
|
$gen_form = json_decode($form[0]['section_data'],true);
|
|
if(!empty($gen_form)){
|
|
foreach ($gen_form['questions'] as $g_key => $g_value)
|
|
{
|
|
// if($g_value['question_key'] == 'state')
|
|
// {
|
|
// $ids_to_send_mail['state'] = $g_value['answer_value'];
|
|
// }
|
|
if($g_value['question_key'] == 'city')
|
|
{
|
|
$city = $g_value['answer_value'];
|
|
}
|
|
}
|
|
}//gen_form closed here.
|
|
PDALERTS::sendSalesPDMail($this,$records['sales_pd_id'],$city);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
log_message('ERROR','####UPDATE SALESPD'.$records['sales_pd_id']);
|
|
$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;
|
|
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 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 = null;
|
|
$applicant_name = '';
|
|
$city = '';
|
|
if($records['questions'])
|
|
{
|
|
foreach ($records['questions'] as $g_key => $g_value)
|
|
{
|
|
if($g_value['question_key'] == 'application_id')
|
|
{
|
|
$applicant_id = $g_value['answer_value'] ? $g_value['answer_value'] : 'Not Provided';
|
|
}
|
|
|
|
if($g_value['question_key'] == 'company_name')
|
|
{
|
|
$applicant_name = $g_value['answer_value'];
|
|
}
|
|
|
|
if($g_value['question_key'] == 'city')
|
|
{
|
|
$city = $g_value['answer_value'];
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
$update_fields = array('applicant_name' => $applicant_name,'city_id'=>$city);
|
|
if($applicant_id != 'Not Provided' && $applicant_id != null){ $update_fields['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
|
|
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->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
|
|
$check=$this->Sales_PD_Model->selectCustomRecords(array('*'),array('sales_pd_id' =>$sales_pd_id,'section_id' => $section_id,'isactive' => 1 ),SALESPD_SECTION_DATA);
|
|
if(count($check)>0){
|
|
$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();
|
|
$columns = array('SALES_PD_DATA.lender_id','SALES_PD_DATA.t_process_instance_id');
|
|
$table = SALES_PD_DATA.' as SALES_PD_DATA';
|
|
$where_condition_array = array('SALES_PD_DATA.sales_pd_id' => $records['sales_pd_id']);
|
|
$sales_pd_data = $this->Sales_PD_Model->selectCustomRecords($columns,$where_condition_array,$table);
|
|
|
|
// print_r($sales_pd_data);die;
|
|
if(!is_numeric($records['section_id'])){ // Sales PD Section ListPage.
|
|
$fields=array('id','sales_pd_id','section_id','status','createdby','createdon');
|
|
if($records['section_id'] == 'data'){ $fields[] = 'section_data'; }
|
|
$section_data=$this->Sales_PD_Model->selectCustomRecords($fields,array('sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALESPD_SECTION_DATA);
|
|
if($sales_pd_data[0]['t_process_instance_id'] == '1'){
|
|
$section_data= $this->autologinSalesPDVaildation($section_data,$records['sales_pd_id']);
|
|
}
|
|
}
|
|
else{// Get-Single Section Json Data From DB.
|
|
$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);
|
|
if($records['section_id'] == 9 && count($section_data))
|
|
{
|
|
$all_sales_pd_images = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('fk_sales_pd_id' => $records['sales_pd_id'],'img_name !=' => 'satellite','isactive' => 1),SALEPD_DOCS);
|
|
|
|
$photo_questions = (json_decode(($section_data[0]['section_data']),true));
|
|
$array1 = array_map(function($element){
|
|
return $element['img_name'];
|
|
}, $all_sales_pd_images);
|
|
$array2 = (array_count_values($array1));
|
|
$array3 = array();
|
|
foreach ($photo_questions['questions'] as $key => $value)
|
|
{
|
|
$array3[$value['question_key']] = (isset($value['questions_group']) && $value['is_repeatable']) ? count($value['questions_group']) : ($value['answer_value'] ? 1 : 0 );
|
|
}
|
|
$result = array();
|
|
foreach ($array2 as $key => $value) {
|
|
$var = $array2[$key] - $array3[$key];
|
|
$result[$key] = ($var < 0 ? 0 : $var);
|
|
}
|
|
|
|
foreach ($photo_questions['questions'] as $key => $value)
|
|
{
|
|
if(isset($value['answer_value']) && $value['answer_value'] && !$value['is_repeatable'])
|
|
{
|
|
$selfie = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('fk_sales_pd_id' => $records['sales_pd_id'],'img_name' => 'selfie_with_person_met','isactive' => 1),SALEPD_DOCS);
|
|
if(count($selfie))
|
|
{
|
|
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$sales_pd_data[0]['lender_id'];
|
|
$img_rand_name = $selfie[0]['rand_name'] != null ? $selfie[0]['rand_name'] : $selfie[0]['img_name'].".png" ;
|
|
$bucket_key = "sales_pd/".$records['sales_pd_id']."/images/".$img_rand_name;
|
|
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name, $bucket_key, '30 minutes');
|
|
$photo_questions['questions'][$key]['answer_value'] = $singed_uri;
|
|
// $photo_questions['questions'][$key]['answer_value'] = $selfie[0]['img'];
|
|
$photo_questions['questions'][$key]['image_location'] = $selfie[0]['location'];
|
|
$photo_questions['questions'][$key]['image_id'] = $selfie[0]['doc_id'];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach ($value['questions_group'] as $v_key => $individual_value)
|
|
{
|
|
if (array_key_exists($individual_value['questions'][0]['question_key'],$result)){
|
|
for($i=1;$i<=$result[$individual_value['questions'][0]['question_key']];$i++){
|
|
$photo_questions['questions'][$key]['questions_group'][$v_key+($i)] = $photo_questions['questions'][$key]['questions_group'][0];
|
|
}
|
|
}
|
|
if(isset($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'])
|
|
{
|
|
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$sales_pd_data[0]['lender_id'];
|
|
$img_rand_name = $img_value['rand_name'] != null ? $img_value['rand_name'] : $img_value['img_name'].".png" ;
|
|
$bucket_key = "sales_pd/".$records['sales_pd_id']."/images/".$img_rand_name;
|
|
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name, $bucket_key,'30 minutes');
|
|
$photo_questions['questions'][$key]['questions_group'][$v_key]['questions'][0]['answer_value'] = $singed_uri;
|
|
// $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]['image_location'] = $img_value['location'];
|
|
$photo_questions['questions'][$key]['questions_group'][$v_key]['questions'][0]['image_id'] = $img_value['doc_id'];
|
|
unset($all_sales_pd_images[$img_key]);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$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 autologinSalesPDVaildation($section_data,$spdid){
|
|
$general_count = $this->Sales_PD_Model->selectCustomRecords(array('count(*) as g_count'),array('sales_pd_id' => $spdid,'section_id' => 1),SALESPD_SECTION_DATA);
|
|
$fund_count = $this->Sales_PD_Model->selectCustomRecords(array('count(*) as f_count'),array('sales_pd_id' => $spdid,'section_id' => 2),SALESPD_SECTION_DATA);
|
|
$newarray = array();
|
|
for($x=0;$x<count($section_data);$x++){
|
|
$newarray[$x] = $section_data[$x];
|
|
if($section_data[$x]['section_id'] == '1' && $general_count[0]['g_count'] == '1'){
|
|
$newarray[$x]['status'] = 0;
|
|
}
|
|
else if($section_data[$x]['section_id'] == '2' && $fund_count[0]['f_count'] == '1'){
|
|
$newarray[$x]['status'] = 0;
|
|
}
|
|
}
|
|
return $newarray;
|
|
}
|
|
|
|
public function testAPISalesPD_post()
|
|
{
|
|
$id = $this->post('id');
|
|
log_message('ERROR','####testAPISalesPD CALLED'.$id);
|
|
PDALERTS::sendSalesPDMail($this,$id,869);die();
|
|
// PDALERTS::sendSalesPDMail($this,32);die();
|
|
// satellite_image::getSatelliteImage(2897,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('SALES_PD_DATA.sales_pd_id','SALES_PD_DATA.sales_pd_sno','SALES_PD_DATA.applicant_name','concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as officer_name','SALES_PD_DATA.applicant_id','SALES_PD_DATA.lender_id','SALES_PD_DATA.product_id','SALES_PD_DATA.is_pdf','SALES_PD_DATA.is_edited','ENTITY.short_name','PRODUCT.abbr','SALES_PD_DATA.status','SALES_PD_DATA.mail_status','SALES_PD_DATA.sales_pd_type','IF(SALES_PD_DATA.sales_pd_type = 1 ,"physical pd","tele pd") as sales_pd_type_name,
|
|
DATE_FORMAT(SALES_PD_DATA.createdon, "%Y-%m-%d") as pd_createdon,DATE_FORMAT(SALES_PD_DATA.completed_date, "%Y-%m-%d") as pd_completedon,USERPROFILE.smc_emp_code,
|
|
(CASE WHEN SALES_PD_DATA.status = "STARTED" THEN SALES_PD_DATA.createdon WHEN SALES_PD_DATA.status = "COMPLETED" THEN SALES_PD_DATA.completed_date ELSE NULL END) AS createdon');
|
|
|
|
$table = SALES_PD_DATA.' as SALES_PD_DATA';
|
|
$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($officer_name)
|
|
{
|
|
//$where_condition_array[] = array('SALES_PD_DATA.officer_name like' => '%'.$officer_name.'%');
|
|
$where_condition_array['SALES_PD_DATA.officer_name like'] = '%'.$officer_name.'%';
|
|
}
|
|
if($from_date)
|
|
{
|
|
$where_condition_array['date(SALES_PD_DATA.createdon) >='] = $from_date;
|
|
$or_where_condition_array['date(SALES_PD_DATA.completed_date) >='] = $from_date;
|
|
}
|
|
if($to_date)
|
|
{
|
|
$where_condition_array['date(SALES_PD_DATA.createdon) <='] = $to_date;
|
|
$or_where_condition_array['date(SALES_PD_DATA.completed_date) <='] = $to_date;
|
|
}
|
|
|
|
$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',"",$or_where_condition_array);
|
|
// print_r($this->db->last_query());echo count($sales_pd_data);die();
|
|
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'] = 'No Data Found';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
|
|
}
|
|
public function filterSalesPDList_post() {
|
|
$records = $this->post('records');
|
|
// print_r($records);die();
|
|
$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 ;
|
|
$sales_pd_type = isset($records['sales_pd_type']) ? $records['sales_pd_type'] : null ;
|
|
$result_data=$this->Sales_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,$sales_pd_type);
|
|
// print_r (count($result_data));die();
|
|
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();
|
|
log_message('ERROR','####Satellite IMG CALLED sales pd = '.$input_data['sales_pd_id']);
|
|
$id = $this->Sales_PD_Model->updateRecords($input_data,SALES_PD_DATA,array('sales_pd_id' => $input_data['sales_pd_id']));
|
|
satellite_image::getSatelliteImage($input_data['sales_pd_id'],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->Sales_PD_Model->selectCustomRecords(array('*'),array('rand_string' => $rand_string),SALES_PD_DATA);
|
|
$product_short_name = $this->Sales_PD_Model->selectCustomRecords(array('abbr'),array('product_id' => $sales_pd_master_data[0]['product_id']),PRODUCTS);
|
|
$is_flyhi_pd = ($sales_pd_master_data[0]['sales_pd_type'] == "3" || $sales_pd_master_data[0]['sales_pd_type'] == "4") ? 1 : 0 ;
|
|
$sales_pd_img_data = $this->Sales_PD_Model->selectCustomRecords(array('doc_id', 'fk_sales_pd_id','img','img_name','location','isactive','rand_name'),array('fk_sales_pd_id' => $sales_pd_master_data[0]['sales_pd_id'],'isactive' => 1,'img_name!=' => 'satellite'),SALEPD_DOCS);
|
|
|
|
// print_r($sales_pd_img_data);
|
|
// print_r($product_short_name);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'));
|
|
if($product_short_name[0]['abbr'] == 'MEQ')
|
|
{
|
|
$imgs = array('selfie_with_person_met' => array('is_multiple' => 0,'img_name' => 'Selfie of the person contacted'),'hospital_building' => array('is_multiple' => 1,'img_name' => 'Institute Building photo'),'name_board_seen' => array('is_multiple' => 1,'img_name' => 'Name Board'),'institute_interior' => array('is_multiple' => 1,'img_name' => 'Institute interior potographs'));
|
|
}
|
|
|
|
$img_data = array();
|
|
// $this->load->library('Googlecloud');
|
|
// $gcpBucketName = GCP_BUCKET_NAME;
|
|
// $objectName = "pd".$sales_pd_master_data[0]['sales_pd_id']."/images/";
|
|
// print_r($sales_pd_img_data);die();
|
|
if(count($sales_pd_img_data))
|
|
{
|
|
|
|
// print_r($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))
|
|
{
|
|
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$sales_pd_master_data[0]['lender_id'];
|
|
$img_rand_name = $sales_pd_img_data_value['rand_name'] != null ? $sales_pd_img_data_value['rand_name'] : $sales_pd_img_data_value['img_name'].".png" ;
|
|
$bucket_key = "sales_pd/".$sales_pd_master_data[0]['sales_pd_id']."/images/".$img_rand_name;
|
|
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name, $bucket_key,'30 minutes');
|
|
$img_url = $sales_pd_img_data_value['img'] ? $sales_pd_img_data_value['img'] : ($singed_uri ? $singed_uri : "");
|
|
$img_data[$key] = array('img_key' => $key,'img_name' => $value['img_name'],'img_data' => [array('img_url' => $img_url,'img_id'=>($sales_pd_img_data_value['doc_id']) ? $sales_pd_img_data_value['doc_id'] : '','location'=>($sales_pd_img_data_value['location']) ? $sales_pd_img_data_value['location'] : '')],'is_multiple' => 1,'section_heading' => $value['img_name']);
|
|
// $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'] : '','img_id'=>($sales_pd_img_data_value['doc_id']) ? $sales_pd_img_data_value['doc_id'] : '','location'=>($sales_pd_img_data_value['location']) ? $sales_pd_img_data_value['location'] : '')],'is_multiple' => 1,'section_heading' => $value['img_name']);
|
|
}
|
|
else
|
|
{
|
|
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$sales_pd_master_data[0]['lender_id'];
|
|
$img_rand_name = $sales_pd_img_data_value['rand_name'] != null ? $sales_pd_img_data_value['rand_name'] : $sales_pd_img_data_value['img_name'].".png" ;
|
|
$bucket_key = "sales_pd/".$sales_pd_master_data[0]['sales_pd_id']."/images/".$img_rand_name;
|
|
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name, $bucket_key,'30 minutes');
|
|
$img_url = $sales_pd_img_data_value['img'] ? $sales_pd_img_data_value['img'] : ($singed_uri ? $singed_uri : "");
|
|
$img_data[$key]['img_data'][] = array('img_url' => $img_url,'img_id'=>($sales_pd_img_data_value['doc_id']) ? $sales_pd_img_data_value['doc_id'] : '','location'=>($sales_pd_img_data_value['location']) ? $sales_pd_img_data_value['location'] : '');
|
|
// $img_gcp_url = $this->googlecloud->getSingleObjectInaBucketAsSignedURI($gcpBucketName,$objectName.$value['img_name'].".png");
|
|
// $img_url = $sales_pd_img_data_value['img'] ? $sales_pd_img_data_value['img'] : ($img_gcp_url ? $img_gcp_url : "");
|
|
// $img_data[$key]['img_data'][] = array('img_url' => $img_url,'img_id'=>($sales_pd_img_data_value['doc_id']) ? $sales_pd_img_data_value['doc_id'] : '','location'=>($sales_pd_img_data_value['location']) ? $sales_pd_img_data_value['location'] : '');
|
|
// $img_data[$key]['img_data'][] = array('img_url' => $sales_pd_img_data_value['img'] ? $sales_pd_img_data_value['img'] : '','img_id'=>($sales_pd_img_data_value['doc_id']) ? $sales_pd_img_data_value['doc_id'] : '','location'=>($sales_pd_img_data_value['location']) ? $sales_pd_img_data_value['location'] : '');
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$sales_pd_master_data[0]['lender_id'];
|
|
$img_rand_name = $sales_pd_img_data_value['rand_name'] != null ? $sales_pd_img_data_value['rand_name'] : $sales_pd_img_data_value['img_name'].".png" ;
|
|
$bucket_key = "sales_pd/".$sales_pd_master_data[0]['sales_pd_id']."/images/".$img_rand_name;
|
|
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name, $bucket_key,'30 minutes');
|
|
$img_url = $sales_pd_img_data_value['img'] ? $sales_pd_img_data_value['img'] : ($singed_uri ? $singed_uri : "");
|
|
$img_data[$key] = array('img_key' => $key,'img_name' => $value['img_name'],'img_url' => $img_url,'is_multiple' => 0,'section_heading' => $value['img_name'],'img_id'=>($sales_pd_img_data_value['doc_id']) ? $sales_pd_img_data_value['doc_id'] : '','location'=>($sales_pd_img_data_value['location']) ? $sales_pd_img_data_value['location'] : '');//$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'],'img_id'=>$value['doc_id']);
|
|
|
|
}
|
|
else
|
|
{
|
|
$img_data[] = array('img_key' => $key,'img_name' => $value['img_name'],'img_url' => '','is_multiple' => 0,'section_heading' => $value['img_name'],'img_id'=>$value['doc_id']);
|
|
}
|
|
}
|
|
}
|
|
|
|
//print_r($img_data);
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = array('sales_pd_id' => $sales_pd_master_data[0]['sales_pd_id'],'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');
|
|
$sales_pd_id = $this->post('sales_pd_id');
|
|
|
|
//
|
|
$response = false;
|
|
|
|
//select mobile no from general form
|
|
$gen_form = $this->Sales_PD_Model->selectCustomRecords(array(),array('isactive' => 1,'sales_pd_id' => $sales_pd_id,'section_id' => 1,'status' => 1),SALESPD_SECTION_DATA);
|
|
|
|
//print_r($gen_form);die();
|
|
if(is_array($gen_form) && isset($gen_form[0]['sales_pd_id']) && $gen_form[0]['sales_pd_id'] == $sales_pd_id)
|
|
{
|
|
|
|
//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' => $sales_pd_id,'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);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public function camundaTest_post()
|
|
{
|
|
echo 'hi';
|
|
|
|
// CAMUNDA::completeSalesPDTask(1);
|
|
//CAMUNDA::startSalesPDInstance(1);
|
|
}
|
|
//api for Manually statellite Image Generation.
|
|
public function regenerateSatelliteImg_post()
|
|
{
|
|
|
|
$input_data = $this->post();
|
|
if(!isset($input_data['geo_location'])){
|
|
// fk_sales_pd_id, img, img_name, createdon, isactive, location
|
|
$where = array('img_name' => "selfie_with_person_met",'fk_sales_pd_id'=>$input_data['sales_pd_id'],'isactive'=>1);
|
|
$check_docs = $this->Sales_PD_Model->selectCustomRecords(array('location'),$where,SALEPD_DOCS);
|
|
if(count($check_docs) && $check_docs[0]['location'] != ""){
|
|
$input_data['geo_location'] = $check_docs[0]['location'];
|
|
}else{
|
|
log_message('ERROR','####Manually Called - Satellite IMG Not Generated Bcoz Selfie Image not Available sales pd = '.$input_data['sales_pd_id']);
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'Selfie with Person Met Images and Location Not Available. please Try Again';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
log_message('ERROR','####Manually Called - Satellite IMG sales pd = '.$input_data['sales_pd_id']);
|
|
$id = $this->Sales_PD_Model->updateRecords($input_data,SALES_PD_DATA,array('sales_pd_id' => $input_data['sales_pd_id']));
|
|
satellite_image::getSatelliteImage($input_data['sales_pd_id'],2);
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['records'] = $id;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
|
|
}
|
|
//api for Manually Report Generation.
|
|
public function regenerateSaleReport_get(){
|
|
$sales_pd_id = $this->get('sales_pd_id');
|
|
if(!empty($sales_pd_id)){
|
|
$this->Sales_PD_Model->updateRecords(array('is_pdf' => 0),SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id));
|
|
log_message('ERROR','####Manually Called - Report Generated sales pd = '.$sales_pd_id);
|
|
$this->prepareSalesPDReport($sales_pd_id);}
|
|
else{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
|
|
$data['msg'] = 'Sales PDID Not Found !';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
|
|
//api for Manually Resend Report With Mail.
|
|
public function resendSaleReportMail_get(){
|
|
$sales_pd_id = $this->get('sales_pd_id');
|
|
if(!empty($sales_pd_id)){
|
|
$city = '';
|
|
$form = $this->Sales_PD_Model->selectCustomRecords(array(),array('isactive' => 1,'sales_pd_id' => $sales_pd_id,'section_id' => 1,'status' => 1),SALESPD_SECTION_DATA);
|
|
$gen_form = json_decode($form[0]['section_data'],true);
|
|
if(!empty($gen_form)){
|
|
foreach ($gen_form['questions'] as $g_key => $g_value)
|
|
{
|
|
if($g_value['question_key'] == 'city')
|
|
{
|
|
$city = $g_value['answer_value'];
|
|
}
|
|
}
|
|
}//gen_form closed here.
|
|
PDALERTS::sendSalesPDMail($this,$sales_pd_id,$city);
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['msg'] = ' Sented Successfully!';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
|
|
$data['msg'] = 'Sales PDID Not Found !';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
}
|
|
public function getSalesPDReportforCETApp_get(){
|
|
log_message('ERROR','## SalesPDReportforCETApp Fns Entered');
|
|
$get = $this->get('sales_pd_id');
|
|
if(!empty($get)){
|
|
$this->prepareSalesPDReport($get);
|
|
log_message('ERROR',"Sales Report Generated for CET App");
|
|
}else{
|
|
log_message('ERROR','Sales Report Not Available for CET App');
|
|
$statusMsg = 'Report Not Available.';
|
|
}
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['msg'] = $statusMsg;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
// public function salespd_cetapp_sectionapi_get(){
|
|
// $get = $this->get('sales_pd_id');
|
|
// $this->prepareSalesPDReport($get);
|
|
|
|
// }
|
|
// public function salespd_cetapp_imageapi_get(){
|
|
|
|
// }
|
|
|
|
//test purpose
|
|
public function testSaleSection_get(){
|
|
$data = $this->Sales_PD_Model->testSaleSection(527);
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
|
|
public function checksalesPD_post()
|
|
{
|
|
$records = $this->post('records');
|
|
$section_data = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $records['id'],'isactive' => 1,'section_id' => $records['sec']),SALESPD_SECTION_DATA);
|
|
print_r(json_decode($section_data[0]['section_data'],true));
|
|
// $template = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('lender_id' => 35,'product_id' => 8,'pd_type' => 1,'sales_pd_type' => 1,'isactive' => 1),SALESPDTEMPLATE);
|
|
// print_r(json_decode($template[0]['template'],true));
|
|
}
|
|
|
|
|
|
/****** ******
|
|
* API : cetNewSalesPd
|
|
* Method : get
|
|
* Sample-Param : newSalesPd?type=1&prod=LFMP&apcntname=Shreekrishnan&apcntid=293&uid=mwisesales1@sine.com
|
|
* TO Trigger New Sales PD and Inserting the applicant on general Form also.
|
|
****** ******/
|
|
public function cetNewSalesPd_get(){
|
|
//for demo purpose only
|
|
$saltkey = $this->get('saltkey');
|
|
// if(password_verify("Smc@123$", '$2y$10$n4dEVCXJ2Oho9KJUnhss/.LAXTyXN60dz332ZRPNp4VpY8J.Ue7ly')){
|
|
// echo '## a) true toMakeCetNewSalesPd Fns Going to Call';
|
|
// }
|
|
// else{
|
|
// echo '## b) false';
|
|
// }
|
|
// die();
|
|
// $hash = password_hash("Smc@123$", PASSWORD_DEFAULT);
|
|
// echo $hash;
|
|
// $2y$10$H4vSrWl15syQHO.tsT0DdOF7pYSTKZBT85sOFCJerttTdObBRsB36
|
|
// die();
|
|
// postman header
|
|
//$saltkey = '';
|
|
// foreach (getallheaders() as $name => $value) {
|
|
// if($name == 'Token'){ $saltkey = $value; }
|
|
// }
|
|
|
|
// $hash = password_hash("Smc@123$", PASSWORD_DEFAULT);
|
|
// Print the generated hash
|
|
// echo "Generated hash: ".$hash;die;
|
|
// MwiseSales@yahoo.com#sine1234
|
|
// $2y$10$n4dEVCXJ2Oho9KJUnhss/.LAXTyXN60dz332ZRPNp4VpY8J.Ue7ly
|
|
|
|
// .. if($saltkey != ''){
|
|
// .. log_message('ERROR','## A) saltkey Found : '.$saltkey);
|
|
// .. if(password_verify("Smc@123$", $saltkey)){
|
|
// .. log_message('ERROR','## B) toMakeCetNewSalesPd Fns Going to Call');
|
|
$this->toMakeCetNewSalesPd($this->get());
|
|
// .. }else{
|
|
// .. log_message('ERROR','## B) Invaild saltkey/Token ');
|
|
// .. $response['status']=false;
|
|
// .. $response['error']="Access denied ! Invaild Salt key";
|
|
// .. $this->response($response,REST_Controller::HTTP_UNAUTHORIZED);
|
|
// .. exit;
|
|
// .. }
|
|
// .. }
|
|
// .. else{
|
|
// .. log_message('ERROR','## A) saltkey Not Found : '.$saltkey);
|
|
// .. $response['status']=false;
|
|
// .. $response['error']="Access denied ! Salt key Not Found!";
|
|
// .. $this->response($response,REST_Controller::HTTP_UNAUTHORIZED);
|
|
// .. exit;
|
|
// .. }
|
|
}
|
|
|
|
public function toMakeCetNewSalesPd($array)
|
|
{
|
|
|
|
// print_r($array['type']);die;
|
|
// header("Location: https://demo.pdgenie.com/salespdpwa/#/sales-pd-list/list-pd");
|
|
log_message('ERROR', '## C) Inside toMakeCetNewSalesPd Fns');
|
|
$sales_pd_type = $array['type'];
|
|
$productname = $array['product'];
|
|
$applicantname = $array['applicantname'];
|
|
$applicantid = $array['applicantid'];
|
|
$usersemailid = $array['userid'];
|
|
$loanamount = $array['loanamount'];
|
|
$createdby = null;
|
|
$salepdid = null;
|
|
$current_date = date("d/m/Y H:i:s");
|
|
|
|
// $reponse_arr = json_decode(,true);
|
|
// print_r(APPPATH."controller/newSalesPD.json");die();
|
|
$lenderid = (ENVIRONMENT == 'production' ? 7 : 35);
|
|
|
|
if ((!empty($sales_pd_type)) && (!empty($productname)) && (!empty($applicantname)) && (!empty($applicantid)) && (!empty($usersemailid)) && (!empty($loanamount))) {
|
|
|
|
|
|
/************lender id,shortname******************/
|
|
// .. for dynamic serial number creation don't delete it.
|
|
// .. $lender_short_name = $this->Sales_PD_Model->selectCustomRecords(array('short_name'), array('entity_id' => $lenderid), ENTITY);
|
|
|
|
/************product id,name,abbr******************/
|
|
// .. for dynamic serial number creation don't delete it.
|
|
// .. if ($productname) {
|
|
// .. $product_short_name = preg_replace('/[^A-Za-z0-9\-]/', '', strtoupper($productname));
|
|
// .. $product_where_condition = array('isactive' => 1);
|
|
// .. if ($usersemailid) {
|
|
// .. $product_where_condition['abbr like'] = '%' . $product_short_name . '%';
|
|
// .. }
|
|
|
|
// .. $product_id = $this->Sales_PD_Model->selectCustomRecords(array('product_id'), $product_where_condition, PRODUCTS);
|
|
// .. $product_id = $product_id[0]['product_id'];
|
|
// .. }
|
|
|
|
/************user id******************/
|
|
$columns = array('USERPROFILE.userid', 'ROLES.role_id', 'USERPROFILEROLES.user_role', 'ROLES.role_name');
|
|
$table = USERPROFILE . ' as USERPROFILE';
|
|
$joins = array(
|
|
array(
|
|
'table' => USERPROFILEROLES . ' as USERPROFILEROLES',
|
|
'condition' => 'USERPROFILEROLES.fk_userid = USERPROFILE.userid and USERPROFILEROLES.isactive =1',
|
|
'jointype' => 'INNER'
|
|
),
|
|
array(
|
|
'table' => ROLES . ' as ROLES',
|
|
'condition' => 'ROLES.role_id = USERPROFILEROLES.user_role',
|
|
'jointype' => 'INNER'
|
|
)
|
|
);
|
|
$order_by = 'USERPROFILE.userid';
|
|
if ($usersemailid) {
|
|
$user_where_condition['email like'] = '%' . $usersemailid . '%';
|
|
}
|
|
$user_details = $this->Sales_PD_Model->getJoinRecords($columns, $table, $joins, $user_where_condition, $order_by, 'DESC', '');
|
|
$user_id = !empty($user_details) ? $user_details[0]['userid'] : null ;
|
|
$role_id = !empty($user_details) ? $user_details[0]['role_id'] : 19 ;
|
|
$createdby = $user_id;
|
|
if($applicantid != null && (!empty($applicantid))){
|
|
$where_condition = array("applicant_id"=>$applicantid);
|
|
$is_exist_applicant_id = $this->Sales_PD_Model->selectCustomRecords(array('sales_pd_sno','sales_pd_id'),$where_condition,SALES_PD_DATA);
|
|
}
|
|
if(!empty($is_exist_applicant_id)){
|
|
$is_exist_sales_pd_sno = $is_exist_applicant_id[0]['sales_pd_sno'];
|
|
log_message('ERROR','## InVaild : Applicant_id Already Exist with ``'.$is_exist_sales_pd_sno.'`` PD');
|
|
$salepdid = $is_exist_applicant_id[0]['sales_pd_id'];
|
|
}
|
|
else{
|
|
log_message('ERROR','## Vaild : Applicant_id = '.$applicantid);
|
|
/************random URL******************/
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < 16; $i++) {
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
}
|
|
|
|
/************Random URL******************/
|
|
$product_id = "";
|
|
if(strtoupper($productname) == "LFMP"){
|
|
$product_id = 8;
|
|
}else if(strtoupper($productname) == "WCTL"){
|
|
$product_id = 9;
|
|
}
|
|
|
|
$count = $this->Sales_PD_Model->selectCustomRecords(array('count(*) as count'), array('lender_id' => $lenderid, 'product_id' => $product_id, 'isactive' => 1), SALES_PD_DATA);
|
|
|
|
// .. dynamic number serial number creation don't delete it.
|
|
// .. $salepd_serial_no = count($lender_short_name) ? $lender_short_name[0]['short_name'] : 'UNKNOWN';
|
|
// .. $salepd_serial_no .= $product_id ? '-' . $product_short_name : '-UNKNOWN';
|
|
// .. $salepd_serial_no .= '-' . (++$count[0]['count']);
|
|
|
|
// .. static
|
|
$salepd_serial_no = "MWISE-".strtoupper($productname).'-' . (++$count[0]['count']);
|
|
|
|
log_message('ERROR', '## 1) random string : ' . $randomString . ' serial No : ' . $salepd_serial_no);
|
|
/*************Inserting Here ******************/
|
|
$records = array("sales_pd_sno" => $salepd_serial_no, "rand_string" => $randomString, "lender_id" => $lenderid, "product_id" => $product_id, "sales_pd_type" => $sales_pd_type, "applicant_id" => $applicantid, "applicant_name" => $applicantname, "isactive" => 1,"t_process_instance_id"=>1);
|
|
if($user_id != null){ $records["createdby"] = $createdby; }
|
|
else{ $records["redirect_email"] = $usersemailid; $user_id = base64_encode($usersemailid);}
|
|
|
|
$id = $this->Sales_PD_Model->saveRecords($records, SALES_PD_DATA);
|
|
$salepdid = $id;
|
|
// $id = 775; // 772,773,777,778
|
|
log_message('ERROR', '## 2) available sales pdid : ' . $id);
|
|
if (!empty($id)) {
|
|
$msg = "Inserted, Sales PD : " . $salepd_serial_no . "/" . $id;
|
|
$template = $this->Sales_PD_Model->selectCustomRecords(array('*'), array('lender_id' => $lenderid, 'product_id' => $product_id, 'pd_type' => 1, 'sales_pd_type' => $sales_pd_type, 'isactive' => 1), SALESPDTEMPLATE);
|
|
log_message('ERROR', "## 3) sales_pd_template_id : " . $template[0]["sales_pd_template_id"] . " name : " . $template[0]["name"] . " lender_id : " . $template[0]["lender_id"] . " product_id : " . $template[0]["product_id"] . " pd_type : " . $template[0]["pd_type"] . " sales_pd_type : " . $template[0]["sales_pd_type"]);
|
|
log_message('ERROR', '## 4) ' . $msg);
|
|
$template = json_decode($template[0]['template'], true);
|
|
$section_data = array();
|
|
foreach ($template['sections'] as $key => $value) {
|
|
$section_id = $template['sections'][$key]['section_id'];
|
|
$section_name = $template['sections'][$key]['section_name'];
|
|
switch ($section_id) {
|
|
case 1:
|
|
if ($value['questions']) {
|
|
foreach ($value['questions'] as $form_key => $form_value) {
|
|
$fieldtype = isset($form_value['type']) ? $form_value['type'] : "";
|
|
// echo $fieldtype;
|
|
if ($form_value['question_key'] == 'application_id') {
|
|
$value['questions'][$form_key]['answer_value'] = $applicantid;
|
|
} else if ($form_value['question_key'] == 'main_loan_applicant') {
|
|
$value['questions'][$form_key]['answer_value'] = $applicantname;
|
|
}else if ($form_value['question_key'] === 'state') {
|
|
$value['questions'][$form_key]['answer_value'] = 0;
|
|
$value['questions'][$form_key]['answers'] = $this->Sales_PD_Model->selectCustomRecords(array('state_id as answer_id', 'name as answer'), array('isactive' => 1), STATE);
|
|
} else if ($form_value['question_key'] === 'person_met_designation') {
|
|
$value['questions'][$form_key]['answer_value'] = 0;
|
|
$value['questions'][$form_key]['answers'] = $this->Sales_PD_Model->selectCustomRecords(array('company_relationship_id as answer_id', 'name as answer'), array('isactive' => 1), COMPANYRELATIONSHIPS);
|
|
} else if (!empty($form_value['question_key'])) {
|
|
$value['questions'][$form_key]['answer_value'] = ($fieldtype == 8 || $fieldtype == 4 || $fieldtype == 3 || $fieldtype == 2) ? 0 : null;
|
|
}
|
|
}
|
|
$general = array("section_id" => $section_id, "section_name" => $section_name, "onsubmit" => null, "questions" => $value['questions'], "order_id" => 1, "is_complete" => 1, "fk_createdby" => $createdby, "sales_pd_id" => $id);
|
|
array_push($section_data, $general);
|
|
}
|
|
break;
|
|
case 2:
|
|
if ($value['questions'] && $loanamount) {
|
|
foreach ($value['questions'] as $form_key => $form_value) {
|
|
$fieldtype = isset($form_value['type']) ? $form_value['type'] : "";
|
|
if ($form_value['question_key'] == 'loan_amount_applied') {
|
|
$value['questions'][$form_key]['answer_value'] = $loanamount;
|
|
} else if (!empty($form_value['question_key'])) {
|
|
$value['questions'][$form_key]['answer_value'] = ($fieldtype == 8 || $fieldtype == 4 || $fieldtype == 3 || $fieldtype == 2) ? 0 : null;
|
|
}
|
|
}
|
|
$fund = array("section_id" => $section_id, "section_name" => $section_name, "onsubmit" => null, "questions" => $value['questions'], "order_id" => 1, "is_complete" => 1, "fk_createdby" => $createdby, "sales_pd_id" => $id);
|
|
array_push($section_data, $fund);
|
|
}
|
|
break;
|
|
default:
|
|
"No Sections";
|
|
}
|
|
}
|
|
if (!empty($section_data)) {
|
|
foreach ($section_data as $key => $data_value) {
|
|
$check = $this->Sales_PD_Model->selectCustomRecords(array('*'), array('sales_pd_id' => $id, 'section_id' => $data_value['section_id'], 'isactive' => 1), SALESPD_SECTION_DATA);
|
|
if (count($check) > 0) {
|
|
$this->Sales_PD_Model->updateRecords(array('isactive' => 0), SALESPD_SECTION_DATA, array('sales_pd_id' => $id, 'section_id' => $data_value['section_id']));
|
|
}
|
|
//insert new record
|
|
$section_data_arr = json_encode($data_value);
|
|
$fields = array('sales_pd_id' => $id, 'section_id' => $data_value['section_id'], 'status' => 1, 'section_data' => $section_data_arr, 'createdby' => $createdby);
|
|
$reponse = $this->Sales_PD_Model->saveRecords($fields, SALESPD_SECTION_DATA);
|
|
// $reponse = 1;
|
|
$msg = $msg . " ( " . $data_value['section_name'] . " ID : " . $reponse . " )";
|
|
log_message('ERROR', '## 5) Confirmation : ' . $msg);
|
|
}
|
|
}
|
|
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['msg'] = "Sales PD : " . $salepd_serial_no;
|
|
} else {
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
|
|
$data['msg'] = 'Data Not Found,Try again';
|
|
}
|
|
log_message('ERROR', '## 6) Finally, ' . $data['msg']);
|
|
date_default_timezone_set("Asia/Kolkata");
|
|
|
|
// .. $smcauthtoken = smcfinance::SmcFinanceAuthUrl();
|
|
// .. if ($smcauthtoken != null) {
|
|
// .. log_message('ERROR', '## 7) I Got SMC Finance Auth Token');
|
|
// .. smcfinance::SmcFinanceApiUrl($applicantid, $salepdid, $salepd_serial_no, 1, $smcauthtoken);
|
|
// .. } else {
|
|
// .. log_message('ERROR', '## 7) SMC Finance Auth Token Not Founded, ' . $smcauthtoken);
|
|
// .. }
|
|
}
|
|
} else {
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
|
|
$data['msg'] = 'Param (or) Value Not Missing,Please Check again';
|
|
}
|
|
|
|
|
|
if (ENVIRONMENT == 'production') {
|
|
$auth_user_id = "MwiseSales@yahoo.com";
|
|
$auth_password = "sine1234";
|
|
$token = base64_encode($auth_user_id . "#" . $auth_password . "#" . $user_id . "#" . $role_id . "#" . $current_date . "#" . $usersemailid . "#" . $salepdid);
|
|
// echo $token;
|
|
// log_message('ERROR','## 7) Finally, '.$data['msg']);
|
|
$redirect_uri = "https://pdgenie.com/sales/#/auto?token=" . $token; // For Production
|
|
} else {
|
|
$auth_user_id = "MwiseSales@yahoo.com";
|
|
$auth_password = "sine1234";
|
|
$token = base64_encode($auth_user_id . "#" . $auth_password . "#" . $user_id . "#" . $role_id . "#" . $current_date . "#" . $usersemailid . "#" . $salepdid);
|
|
// echo $token;
|
|
// $token = base64_encode('mwisesales1@sine.com#test1234'."#".$user_id."#".$role_id);
|
|
// $redirect_uri = "http://localhost:4200/#/auto?token=".$token; // For Localhost
|
|
$redirect_uri = "https://demo.pdgenie.com/salespdpwa/#/auto?token=" . $token; // For Testing
|
|
}
|
|
log_message('ERROR', '## 8) Redirect B4 '.$auth_user_id."#".$auth_password."#".$user_id."#".$role_id."#".$current_date."#".$usersemailid."#".$salepdid);
|
|
// MwiseSales@yahoo.com#sine1234#293#19#06/07/2023 16:02:57#mwisesales1@sine.com#904
|
|
// https://demo.pdgenie.com/salespdpwa/#/auto?token=TXdpc2VTYWxlc0B5YWhvby5jb20jc2luZTEyMzQjMjkzIzE5IzA2LzA3LzIwMjMgMTY6MDI6NTcjbXdpc2VzYWxlczFAc2luZS5jb20jOTA0
|
|
log_message('ERROR', '## 9) Redirect Aftr `' . $redirect_uri . '`');
|
|
//echo $redirect_uri;die();
|
|
header("Location: " . $redirect_uri);
|
|
// $this->response($data,REST_Controller::HTTP_OK);
|
|
//if($data['dataStatus']){ header("Location: https://sidharthindustries.com/SIA/"); }
|
|
}
|
|
|
|
function uploadSalesImages_get(){
|
|
$sales_pd_id = $this->get('sales_pd_id');
|
|
// 2961
|
|
$photograph_data = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('fk_sales_pd_id' => $sales_pd_id,'isactive' => 1),SALEPD_DOCS);
|
|
if(count($photograph_data)>0){
|
|
for ($i = 0; $i < count($photograph_data); $i++){
|
|
$img_fields = $common_fields;
|
|
$img_fields['img_name'] = $photograph_data[$i]['img_name'];
|
|
$img_split = explode( ',', $photograph_data[$i]['img']);
|
|
$img_fields['img'] = $img_split[1];
|
|
// $img_fields[0]['img'] = $photograph_data[$i]['img'];
|
|
$img_result = cet_salespd::pushwithcetphotographapi($img_fields,$i);
|
|
}
|
|
}
|
|
}
|
|
|
|
function transferSalesPDImgToCETApp_post(){
|
|
$records = $this->post('records');
|
|
log_message('ERROR',"### CET APP SALES PD-IMG, PDID are :".implode(', ', $records));
|
|
if(!empty($records))
|
|
{
|
|
$j = 0;$section_fields=array();
|
|
foreach ($records as $key => $value)
|
|
{
|
|
$sales_pd_id = $value;
|
|
if(!empty($sales_pd_id)){
|
|
$columns = array('SALES_PD_DATA.*','ENTITY.short_name','PRODUCT.abbr','USERPROFILE.smc_emp_code');
|
|
$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('SALES_PD_DATA.sales_pd_id' => $sales_pd_id);
|
|
$sales_pd_data = $this->Sales_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array);
|
|
|
|
if(count($sales_pd_data)>0)
|
|
{
|
|
$section_fields = array('pdid'=>$sales_pd_data[0]['sales_pd_id'],
|
|
'product'=>$sales_pd_data[0]['abbr'],
|
|
'caseno'=>$sales_pd_data[0]['sales_pd_sno'],
|
|
'sales_pd_type'=>$sales_pd_data[0]['sales_pd_type'],
|
|
'completed_date'=>$sales_pd_data[0]['completed_date']
|
|
);
|
|
|
|
// $photograph_data = $this->Sales_PD_Model->selectCustomRecords(array('img_name','case when img IS NOT NULL then CONCAT(img_name, ".png") when rand_name IS NULL then CONCAT(img_name, ".png") else rand_name end AS img'),array('fk_sales_pd_id' => $sales_pd_id,'isactive' => 1),SALEPD_DOCS);
|
|
$photograph_data = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('fk_sales_pd_id' => $sales_pd_id,'isactive' => 1),SALEPD_DOCS);
|
|
log_message('ERROR', '#### Sales PD ('.$sales_pd_id.') - Total Images'.count($photograph_data));
|
|
if(!empty($photograph_data)){
|
|
$this->load->library('Googlecloud');
|
|
$k=0;
|
|
foreach ($photograph_data as $key => $value){
|
|
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < 6; $i++)
|
|
{
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
}
|
|
$rand_name = $value['img_name'] == 'satellite' ? "satellite.png" : $value['img_name']."_".$randomString.".png";
|
|
$section_fields['data']['section9'][$k]['img_name'] = $value['img_name'];
|
|
$section_fields['data']['section9'][$k]['img'] = $rand_name;
|
|
$photograph_data[$k]['rand_name'] = $rand_name;$k++;
|
|
}
|
|
$CET_response = cet_salespd::repushwithcetphotographapi($section_fields);
|
|
$CET_api_response[$sales_pd_id] = $CET_response;
|
|
$CET_api_response[$sales_pd_id]->totalImages = count($photograph_data);
|
|
$a = array();
|
|
if(isset($CET_response->status) && $CET_response->status == 200){
|
|
foreach ($photograph_data as $key => $value){
|
|
$rand_name = $value['rand_name'];
|
|
$source=$value['img_name'] == 'satellite' ? 'data:image/png;base64,'.$value['img'] : $value['img'];
|
|
//Google Library - GCP
|
|
$gcpBucketName = GCP_BUCKET_NAME;
|
|
$objectName = "pd".$sales_pd_id."/images/".$rand_name;
|
|
$gcp_result = $this->googlecloud->uploadFileToGCPBucket($gcpBucketName,$objectName,$source);
|
|
if($gcp_result == true){
|
|
log_message('ERROR', '### Sales-PD ('.$sales_pd_id.') '.$value['img_name'].' Image Stored In GCP');
|
|
}else{ log_message('ERROR', '### Sales-PD ('.$sales_pd_id.') '.$records['img_name'].' Image Not Stored In GCP'); }
|
|
|
|
// Amazon Library - S3
|
|
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$sales_pd_data[0]['lender_id'];
|
|
$bucket_key = "sales_pd/".$sales_pd_id."/images/".$rand_name;
|
|
$bucket_data = array('bucket_name' => $bucket_name, 'key' => $bucket_key, 'sourcefile' => $source);
|
|
|
|
$s3result = $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
|
if (is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) {
|
|
log_message('ERROR', '### Sales-PD ('.$sales_pd_id.') '.$value['img_name'].' Image Stored In S3');
|
|
}else{ log_message('ERROR', '### Sales-PD ('.$sales_pd_id.') '.$records['img_name'].' Image Not Stored In S3'); }
|
|
|
|
if($gcp_result == true && is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200 && $value['img_name'] != 'satellite'){
|
|
$update_fields2 = array('rand_name' => $rand_name);
|
|
$this->Sales_PD_Model->updateRecords($update_fields2,SALEPD_DOCS,array('doc_id'=>$value['doc_id']));
|
|
}
|
|
array_push($a,$value['img']);
|
|
$CET_api_response[$sales_pd_id]->images = $a;
|
|
}
|
|
log_message('ERROR', '#### Sales PD ('.$sales_pd_id.') - CET response - '.json_encode($CET_response,true));
|
|
}
|
|
else{
|
|
log_message('ERROR', '#### Sales PD ('.$sales_pd_id.') - CET response - '.json_encode($CET_response,true));
|
|
}
|
|
|
|
}else{
|
|
log_message('ERROR', '#### Sales PD ('.$sales_pd_id.') - No Images');
|
|
}
|
|
}
|
|
else
|
|
{
|
|
log_message('ERROR', '#### Sales PD ('.$sales_pd_id.') - No Data In ParentTable');
|
|
}
|
|
}else{
|
|
log_message('ERROR', '#### Sales PDID Not Founded');
|
|
}
|
|
}
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['reInsertImageDataApiResponse'] = $CET_api_response;
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
else
|
|
{
|
|
log_message('ERROR', '#### Sales PDID Array Empty');
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
|
|
$data['msg'] = 'No Data Found';
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
}
|
|
|
|
public function archivedSalesPD_get(){
|
|
$sales_pd_id = $this->get('sales_pd_id');
|
|
$days = 60;
|
|
$day_limit = date("d/m/Y", strtotime("-".$days." days"));
|
|
$select = array('*');
|
|
// $condit = array('isactive' => 1,'status' => 'COMPLETED','(DATE_FORMAT(completed_date, "%d/%m/%Y")) <=' => $day_limit);
|
|
$condit = array('isactive' => 1,'status' => 'COMPLETED');
|
|
// $condit = array('isactive' => 1,'status' => 'ARCHIVED'); //vel changed in live.
|
|
$condit['DATE_FORMAT(completed_date, "%Y-%m-%d") <= DATE_SUB(CURDATE(), INTERVAL 60 DAY)'] =null;
|
|
if(!empty($sales_pd_id)) $condit['sales_pd_id'] = $sales_pd_id;
|
|
$value = $this->Sales_PD_Model->selectCustomRecords($select, $condit, SALES_PD_DATA);
|
|
// print_r($this->db->last_query());die();
|
|
// echo count($value);
|
|
if(!empty($value)){
|
|
$flag = 0;$ids=array();$flag2=0;$completed_ids=array();
|
|
foreach( $value as $k => $v)
|
|
{
|
|
if($v['is_the_data_transfer_cet'] == 1){
|
|
// echo "... ... ".$v['sales_pd_id'];
|
|
$updt_arr['status'] = ARCHIVED;
|
|
$updt_where = array('sales_pd_id' => $v['sales_pd_id'], 'status' => COMPLETED);
|
|
$result = $this->Sales_PD_Model->updateRecords($updt_arr, SALES_PD_DATA, $updt_where);
|
|
if($result) $flag = $flag+1;
|
|
log_message('ERROR', '#### Sales PDID '.$v['sales_pd_id']." - ".$v['sales_pd_sno'].' in ARCHIVED status ');
|
|
$this->archivedSalesPDDeletion($v['sales_pd_id'],$v['lender_id'],$day_limit);
|
|
array_push($ids, $v['sales_pd_id']." - ".$v['sales_pd_sno']);
|
|
}else{
|
|
array_push($completed_ids, $v['sales_pd_id']." - ".$v['sales_pd_sno']);
|
|
log_message('ERROR', '#### Sales PDID '.$v['sales_pd_id'].'-'.$v['sales_pd_sno'].' is in Completed status because Data not transfer to CET');
|
|
$flag2++;
|
|
}
|
|
}
|
|
log_message('ERROR', '#### '.$flag. '/'.count($value).' (archived pd/total pd) below this date '.$day_limit);
|
|
$data['dataStatus'] = true;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['message'] = $flag. '/'.count($value).' sales PD in ARCHIVED status ('.implode(', ', $ids).' ). Remaining '.$flag2.' ('.implode(', ', $completed_ids).' ) data are in Completed status because Data not transfer to CET. ';
|
|
}else{
|
|
$data['dataStatus'] = false;
|
|
$data['status'] = REST_Controller::HTTP_OK;
|
|
$data['message'] = 'NO Sales PD Data Less than or equal to '.$day_limit;
|
|
log_message('ERROR', '#### NO Sales PD Data Less than or equal to '.$day_limit );
|
|
}
|
|
$this->response($data,REST_Controller::HTTP_OK);
|
|
}
|
|
function archivedSalesPDDeletion($sales_pd_id,$pdLenId,$day_limit){
|
|
log_message('ERROR', '#### Old Sales PD Data Deletion Doc,JSON'.$sales_pd_id);
|
|
|
|
$json_cond_arr = array('sales_pd_id'=>$sales_pd_id);
|
|
$json_dtls = $this->Sales_PD_Model->selectCustomRecords(array('*'), $json_cond_arr, SALESPD_SECTION_DATA);
|
|
if(!empty($json_dtls)){
|
|
$json_result = $this->Sales_PD_Model->delete_data(array('column'=>'sales_pd_id','value'=>$sales_pd_id,'table'=>SALESPD_SECTION_DATA));
|
|
log_message('ERROR', '#### Sales PD Data '.count($json_dtls).' JSON Deleted for this '.$sales_pd_id.' result '.$json_result);
|
|
}else log_message('ERROR', '#### Sales PD Data '.count($json_dtls).' JSON Deleted for this '.$sales_pd_id);
|
|
|
|
$docs_cond_arr = array('fk_sales_pd_id'=>$sales_pd_id);
|
|
$docs_dtls = $this->Sales_PD_Model->selectCustomRecords(array('*'), $docs_cond_arr, SALEPD_DOCS);
|
|
if(!empty($docs_dtls)){
|
|
$docs_result = $this->Sales_PD_Model->delete_data(array('column'=>'fk_sales_pd_id','value'=>$sales_pd_id,'table'=>SALEPD_DOCS));
|
|
log_message('ERROR', '#### Sales PD '.count($docs_dtls).' Docs Entires Deleted for this '.$sales_pd_id.' result '.$docs_result);
|
|
$destination_path = $this->external_path . "/sales_pd/".$sales_pd_id;
|
|
if(is_dir($destination_path)){
|
|
$files = glob($destination_path.'/*');
|
|
log_message('ERROR', '#### Sales PD '.count($files).' Local Files Deleted for this '.$sales_pd_id);
|
|
rmdir($destination_path);
|
|
$this->deleteS3Images($pdLenId,$sales_pd_id);
|
|
} else log_message('ERROR', '#### There is No Sales PD Local Files for this '.$sales_pd_id);
|
|
}else log_message('ERROR', '#### Sales PD '.count($docs_dtls).' Docs Entries Deleted for this '.$sales_pd_id);
|
|
|
|
}
|
|
public function deleteS3Images($pdLenId,$sales_pd_id){
|
|
$bucketName = LENDER_BUCKET_NAME_PREFIX . $pdLenId;
|
|
$key = 'sales_pd/'.$sales_pd_id;
|
|
$allFiles = $this->aws_s3->getAllObjectsInaBucket($bucketName, $key);
|
|
log_message('ERROR', '#### Sales PD '.count(array($allFiles)).' S3 Files Deleted For this '.$sales_pd_id);
|
|
$this->aws_s3->deleteMatchingObjects($bucketName, $key);
|
|
}
|
|
}
|
|
|
|
|