FlyHI Master api Splitted : ps

This commit is contained in:
VE10-Sanjeev 2022-06-15 19:11:30 +05:30
parent d8caf49718
commit 8da58136c5
2 changed files with 127 additions and 12 deletions

View File

@ -381,5 +381,10 @@ $route['getFlyhiPD'] = 'Flyhi_Controller/getFlyhiPD';
$route['loadFlyhiPDTemplate'] = 'Flyhi_Controller/loadFlyhiPDTemplate';
$route['(downloadFlyhiPDReport/:any)'] = 'Flyhi_Controller/getFlyhiPDReport';
$route['getMasterForFlyhiPD'] = 'Flyhi_Controller/getMasterForFlyhiPD';
$route['getFlyhiSalesPersonList'] = 'Flyhi_Controller/lenderSalesPersonForFlyhiPD';
$route['getFlyhiCreditPersonList'] = 'Flyhi_Controller/lenderCreditPersonForFlyhiPD';
$route['getFlyhiBranchList'] = 'Flyhi_Controller/branchMasterForFlyhiPD';
$route['getFlyhiProductList'] = 'Flyhi_Controller/productMasterForFlyhiPD';
$route['getFlyhiLenderList'] = 'Flyhi_Controller/lenderMasterForFlyhiPD';

View File

@ -10,7 +10,6 @@ class Flyhi_Controller extends REST_Controller {
{
parent::__construct();
$this->load->model('Flyhi_Model','Flyhi_Model');
$this->load->model('Sales_PD_Model','Sales_PD_Model');
$this->load->library('AWS_S3');
$this->load->library('pdfgenerator');
$this->load->helper('satellite_image');
@ -66,6 +65,114 @@ class Flyhi_Controller extends REST_Controller {
$this->response($data,REST_Controller::HTTP_OK);
}
public function lenderMasterForFlyhiPD_get(){
$FHFSL_lender = (ENVIRONMENT == 'production' ? 19 : 49);
$default_lender = $FHFSL_lender;
$lender_fields = array('entity_id','full_name','short_name');
$lender_where_condition_array = array('isactive' => 1,'entity_id' => $FHFSL_lender);
$result_data = $this->Flyhi_Model->selectCustomRecords($lender_fields,$lender_where_condition_array,ENTITY,array(),'','full_name');
$result_data = count($result_data)>0 ? $result_data : 'Lender was not found';
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $result_data;
$this->response($data,REST_Controller::HTTP_OK);
}
public function productMasterForFlyhiPD_get(){
$FHFSL_product = (ENVIRONMENT == 'production' ? 27 : 26);
$default_product = $FHFSL_product;
$product = $this->Flyhi_Model->selectCustomRecords(array('product_id','name as product_name','abbr as product_abbr','prod_catagory'),array('product_id' => $FHFSL_product),PRODUCTS);
$product = count($product)>0 ? $product : 'product was not found';
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $product;
$this->response($data,REST_Controller::HTTP_OK);
}
public function branchMasterForFlyhiPD_get(){
$FHFSL_lender = (ENVIRONMENT == 'production' ? 19 : 49);
$branches = array();
$lender_fields = array('entity_id','full_name','short_name');
$lender_where_condition_array = array('isactive' => 1,'entity_id' => $FHFSL_lender);
$result_data = $this->Flyhi_Model->selectCustomRecords($lender_fields,$lender_where_condition_array,ENTITY,array(),'','full_name');
if(count($result_data))
{
foreach($result_data as $key => $value)
{
$branch_fields = array('entity_lender_branch_id', 'branch_name');
$branch_where_condition_array = array('fk_entity_id' => $value['entity_id'],'isactive'=>1);
$result_data[$key]['branches'] = $this->Flyhi_Model->selectCustomRecords($branch_fields,$branch_where_condition_array,ENTITYLENDERBRANCH);
$branches = $this->Flyhi_Model->selectCustomRecords($branch_fields,$branch_where_condition_array,ENTITYLENDERBRANCH);
}
}
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = count($branches)>0?$branches:"Branches Not Found";
$this->response($data,REST_Controller::HTTP_OK);
}
public function lenderCreditPersonForFlyhiPD_get(){
$FHFSL_lender = (ENVIRONMENT == 'production' ? 19 : 49);
$FHFSL_product = (ENVIRONMENT == 'production' ? 27 : 26);
$columns = array('USERPROFILE.userid','concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as user_name','USERPROFILE.fk_entity_id','USERPROFILE.fk_city','USERPROFILEROLES.user_role','USERPROFILE.fk_entity_type_id','ROLES.role_name','if( POSITION("credit" IN ROLES.role_name),"CREDIT","SALES") as role_type');
$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';
$where_condition_array['USERPROFILE.fk_entity_id'] = $FHFSL_lender;
$key_date="ROLES.role_name LIKE '%credit%'";
$condition_value=null;
$where_condition_array[$key_date] = $condition_value;
$or_where = array();
$lender_contact_persons = $this->Flyhi_Model->getJoinRecords($columns,$table,$joins,$where_condition_array,$order_by,'DESC','',$or_where);
$lender_contact_persons = count($lender_contact_persons)>0 ? $lender_contact_persons : 'Credit Person Lender Profile was not found?. Create Credit Person Lender profile';
// isset($records['pd_branch_id']) ? $records['pd_branch_id'] : null
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $lender_contact_persons;
$this->response($data,REST_Controller::HTTP_OK);
}
public function lenderSalesPersonForFlyhiPD_get(){
$FHFSL_lender = (ENVIRONMENT == 'production' ? 19 : 49);
$FHFSL_product = (ENVIRONMENT == 'production' ? 27 : 26);
$columns = array('USERPROFILE.userid','concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as user_name','USERPROFILE.fk_entity_id','USERPROFILE.fk_city','USERPROFILEROLES.user_role','USERPROFILE.fk_entity_type_id','ROLES.role_name','if( POSITION("credit" IN ROLES.role_name),"CREDIT","SALES") as role_type');
$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';
$or_where = array();
$where_condition_array['USERPROFILE.fk_entity_id'] = $FHFSL_lender;
$key_date="ROLES.role_name LIKE '%sale%'";
$condition_value=null;
$where_condition_array[$key_date] = $condition_value;
$lender_contact_persons = $this->Flyhi_Model->getJoinRecords($columns,$table,$joins,$where_condition_array,$order_by,'DESC','',$or_where);
$lender_contact_persons = count($lender_contact_persons)>0 ? $lender_contact_persons : 'Sales Person Lender Profile was not found?. Create Sales Person Lender profile';
// isset($records['pd_branch_id']) ? $records['pd_branch_id'] : null
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $lender_contact_persons;
$this->response($data,REST_Controller::HTTP_OK);
}
public function listFlyhiPD_get(){
$user_id = $this->uri->segment(1);
@ -152,7 +259,7 @@ class Flyhi_Controller extends REST_Controller {
$lender_sales_person = null;
$lender_credit_person = null;
$product_id = null;
// $product_short_name = $this->Sales_PD_Model->selectCustomRecords(array('abbr'),array('product_id' => $records['product_id']),PRODUCTS);
// $product_short_name = $this->Flyhi_Model->selectCustomRecords(array('abbr'),array('product_id' => $records['product_id']),PRODUCTS);
log_message('ERROR','####FLYHI-PD SAVE CALLED');
@ -254,10 +361,10 @@ class Flyhi_Controller extends REST_Controller {
$FLYHI_PD['product_id'] = $product_id ? $product_id : (ENVIRONMENT == 'production' ? 27 : 26);
$flyhi_pd_id = $this->Flyhi_Model->saveRecords($FLYHI_PD,SALES_PD_DATA);
$section_data = json_encode($records);
$this->Sales_PD_Model->updateRecords(array('isactive' => 0),SALESPD_SECTION_DATA,array('sales_pd_id' =>$flyhi_pd_id,'section_id' => 1 ));
$this->Flyhi_Model->updateRecords(array('isactive' => 0),SALESPD_SECTION_DATA,array('sales_pd_id' =>$flyhi_pd_id,'section_id' => 1 ));
$status = $records['is_complete'];
$fields = array('sales_pd_id' => $flyhi_pd_id, 'section_id' => 1, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby);
$is_entry_done = $this->Sales_PD_Model->saveRecords($fields,SALESPD_SECTION_DATA);
$is_entry_done = $this->Flyhi_Model->saveRecords($fields,SALESPD_SECTION_DATA);
}
else
@ -279,7 +386,7 @@ class Flyhi_Controller extends REST_Controller {
log_message('ERROR','####UPDATE FLYHIPD'.$records['sales_pd_id']);
// $gen_form = json_decode($form[0]['section_data'],true);
$flyhi_pd_id = $records['sales_pd_id'];
$flyhi_pd_id = (int)$records['sales_pd_id'];
if($records['questions']){
foreach ($records['questions'] as $g_key => $g_value)
@ -358,10 +465,12 @@ class Flyhi_Controller extends REST_Controller {
$FLYHI_PD['pd_branch_id'] = $pd_branch_id;
$FLYHI_PD['lender_id'] = $lender_id;
$FLYHI_PD['product_id'] = $product_id ? $product_id : (ENVIRONMENT == 'production' ? 27 : 26);
$flyhi_pd_id = $this->Flyhi_Model->updateRecords($FLYHI_PD,SALES_PD_DATA,array('sales_pd_id' => $flyhi_pd_id));
$status = $records['is_complete'];
$section_data = json_encode($records);
$this->Flyhi_Model->updateRecords($FLYHI_PD,SALES_PD_DATA,array('sales_pd_id' => $flyhi_pd_id));
$this->Flyhi_Model->updateRecords(array('isactive' => 0),SALESPD_SECTION_DATA,array('sales_pd_id' =>$flyhi_pd_id,'section_id' => 1));
$fields = array('sales_pd_id' => $flyhi_pd_id, 'section_id' => 1, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby);
$is_entry_done = $this->Sales_PD_Model->saveRecords($fields,SALESPD_SECTION_DATA);
$is_entry_done = $this->Flyhi_Model->saveRecords($fields,SALESPD_SECTION_DATA);
} // else 179
} // else 167
if($flyhi_pd_id)
@ -415,7 +524,7 @@ class Flyhi_Controller extends REST_Controller {
$pd_type = 2;
if(isset($records['pd_type'])){ $pd_type = $records['pd_type'];}
$template = $this->Flyhi_Model->selectCustomRecords(array('*'),array('lender_id' => $lender_id,'pd_type' => $pd_type,'sales_pd_type' => $sales_pd_type,'isactive' => 1),SALESPDTEMPLATE);
// $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);
// $template = $this->Flyhi_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;
@ -459,7 +568,7 @@ class Flyhi_Controller extends REST_Controller {
$where_condition_array = array('SALES_PD_DATA.sales_pd_id' => $pd_id);
// $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);
$sales_pd_data = $this->Flyhi_Model->getJoinRecords($columns,$table,$joins,$where_condition_array);
$pd_type = "";
if($sales_pd_data[0]['sales_pd_type'] == 3){$pd_type = "Office FI PD-"; }else if($sales_pd_data[0]['sales_pd_type'] == 4){$pd_type = "Residence FI PD-";}
@ -473,7 +582,7 @@ class Flyhi_Controller extends REST_Controller {
$pdf_name .= '-'.$pd_type.$sales_pd_data[0]['abbr'];
$pdf_name .= '-'.(date('dmY',strtotime($sales_pd_data[0]['completed_date'])));
$key = 'sales_pd/'.$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' => $pd_id));
//$this->Flyhi_Model->updateRecords(array('pd_report_filename' => 'PD_Report-'.$pdf_name),SALES_PD_DATA,array('sales_pd_id' => $pd_id));
if(!file_exists($this->external_path.'/sales_pd/'.$pd_id))
{
@ -483,7 +592,7 @@ class Flyhi_Controller extends REST_Controller {
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' => $pd_id,'isactive' => 1),SALESPD_SECTION_DATA,array(),'','section_id','ASC');
$all_section_data = $this->Flyhi_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $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;
@ -502,6 +611,7 @@ class Flyhi_Controller extends REST_Controller {
//$view_name = $sales_pd_data[0]['short_name'].'_'.$sales_pd_data[0]['abbr'];
$view_name = $sales_pd_data[0]['short_name'];
$html_content = $this->load->view('sale_pd_templates/'.$view_name,$view_data,true);
echo $html_content;die();
$pdf_doc = $this->pdfgenerator->generate($html_content, $filename='version', $stream=false, $paper = 'A4', $orientation = "portrait");
//End of PDF Gen using DOM PDF
$output_file = $this->external_path ."/sales_pd/" .$pd_id. "/temp.pdf";
@ -515,7 +625,7 @@ class Flyhi_Controller extends REST_Controller {
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' => $pd_id));
$this->Flyhi_Model->updateRecords(array('is_pdf' => 1, 'is_edited' => 0),SALES_PD_DATA,array('sales_pd_id' => $pd_id));
if($api)
{
$_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes');