From 02712ed2c9a5b3872b3c4751b03d124e6d3cfeda Mon Sep 17 00:00:00 2001 From: sanjeev Date: Wed, 23 Feb 2022 13:52:37 +0530 Subject: [PATCH 1/3] pd_report string added : ps --- .../controllers/SMC_Credit_PD_Controller.php | 32 ++++++++---- .../controllers/Sales_PD_Controller.php | 50 +++++++++++++------ 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/api/application/controllers/SMC_Credit_PD_Controller.php b/api/application/controllers/SMC_Credit_PD_Controller.php index 3c192e5b..4ebbd444 100644 --- a/api/application/controllers/SMC_Credit_PD_Controller.php +++ b/api/application/controllers/SMC_Credit_PD_Controller.php @@ -168,20 +168,27 @@ class SMC_Credit_PD_Controller extends REST_Controller { $where_condition_array = array('SMC_CREDIT_PD.smc_credit_pd' => $smc_credit_pd); $SMC_CREDIT_PD = $this->SMC_Credit_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array); - //print_r($SMC_CREDIT_PD);die(); if($SMC_CREDIT_PD) { ini_set('max_execution_time', 0); $bucket_name = LENDER_BUCKET_NAME_PREFIX.$SMC_CREDIT_PD[0]['lender_id']; - $pdf_name = strtolower(trim($SMC_CREDIT_PD[0]['applicant_name'])); - $pdf_name .= '-'.$SMC_CREDIT_PD[0]['abbr']; - $pdf_name .= '-'.(date('dmY',strtotime($SMC_CREDIT_PD[0]['completed_date']))); - $this->PD_Model->updateRecords(array('pd_report_filename' => $pdf_name),SMC_CREDIT_PD,array('SMC_CREDIT_PD.smc_credit_pd' => $smc_credit_pd)); + + // 1st Type Key name. (name,abbr and date). + $type1_pdf_name = strtolower(trim($SMC_CREDIT_PD[0]['applicant_name'])); + $type1_pdf_name .= '-'.$SMC_CREDIT_PD[0]['abbr']; + $type1_pdf_name .= '-'.(date('dmY',strtotime($SMC_CREDIT_PD[0]['completed_date']))); + + // 2nd Type Key name. (name,type,abbr and date). + $type2_pdf_name = strtolower(trim($SMC_CREDIT_PD[0]['applicant_name'])); + $type2_pdf_name .= '-'.$SMC_CREDIT_PD[0]['abbr']; + $type2_pdf_name .= 'PD_Report-'.(date('dmY',strtotime($SMC_CREDIT_PD[0]['completed_date']))); + + // $this->PD_Model->updateRecords(array('pd_report_filename' => $pdf_name),SMC_CREDIT_PD,array('smc_credit_pd' => $smc_credit_pd)); //$pdf_name = str_replace(' ', '_', $pdf_name); - - $key = 'sales_pd/'.$smc_credit_pd.'/'.$pdf_name.'.pdf'; + $type1_key = 'sales_pd/'.$smc_credit_pd.'/'.$type1_pdf_name.'.pdf'; + $type2_key = 'sales_pd/'.$smc_credit_pd.'/'.$type2_pdf_name.'.pdf'; if(!file_exists($this->external_path.'/sales_pd/'.$smc_credit_pd)) { @@ -217,7 +224,7 @@ class SMC_Credit_PD_Controller extends REST_Controller { $bytes = file_put_contents($output_file, $pdf_doc); // echo $bytes; // die(); - $bucket_data = array('bucket_name'=>$bucket_name,'key'=>$key,'sourcefile'=>$this->external_path.'/sales_pd/'.$smc_credit_pd.'/temp.pdf'); + $bucket_data = array('bucket_name'=>$bucket_name,'key'=>$type2_key,'sourcefile'=>$this->external_path.'/sales_pd/'.$smc_credit_pd.'/temp.pdf'); log_message('ERROR','####SALES PD REPORT UPLOAD TO S3'.$smc_credit_pd); $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); @@ -227,7 +234,14 @@ class SMC_Credit_PD_Controller extends REST_Controller { $this->SMC_Credit_PD_Model->updateRecords(array('is_pdf' => 1, 'is_edited' => 0),SMC_CREDIT_PD,array('smc_credit_pd' => $smc_credit_pd)); if($api) { - $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); + // $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); + $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type1_key,'30 minutes'); + $headers = @get_headers($_uri); + if($headers && strpos( $headers[0], '200')) { + $singed_uri = $_uri; + }else { + $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type2_key,'30 minutes'); + } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $singed_uri; diff --git a/api/application/controllers/Sales_PD_Controller.php b/api/application/controllers/Sales_PD_Controller.php index b1c28459..810ac1cf 100644 --- a/api/application/controllers/Sales_PD_Controller.php +++ b/api/application/controllers/Sales_PD_Controller.php @@ -180,17 +180,27 @@ class Sales_PD_Controller extends REST_Controller { { ini_set('max_execution_time', 0); $bucket_name = LENDER_BUCKET_NAME_PREFIX.$sales_pd_data[0]['lender_id']; - $pdf_name = strtolower(trim($sales_pd_data[0]['applicant_name'])); - $pdf_name .= '-'.$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'; - - $key = 'sales_pd/'.$sales_pd_id.'/'.$pdf_name.'.pdf'; + // 1st Type Key name. (name,abbr and date). + $type1_pdf_name = strtolower(trim($sales_pd_data[0]['applicant_name'])); + $type1_pdf_name .= '-'.$sales_pd_data[0]['abbr']; + $type1_pdf_name .= '-'.(date('dmY',strtotime($sales_pd_data[0]['completed_date']))); + // 2nd Type Key name. (name,type,abbr and date). + $type2_pdf_name = strtolower(trim($sales_pd_data[0]['applicant_name'])); + $type2_pdf_name .= '-'.$pd_type.$sales_pd_data[0]['abbr']; + $type2_pdf_name .= '-'.(date('dmY',strtotime($sales_pd_data[0]['completed_date']))); + + // 3rd Type Key name. (string,name,type,abbr and date). + $type2_pdf_name = strtolower(trim($sales_pd_data[0]['applicant_name'])); + $type2_pdf_name .= '-'.$pd_type.$sales_pd_data[0]['abbr']; + $type2_pdf_name .= 'PD_Report-'.(date('dmY',strtotime($sales_pd_data[0]['completed_date']))); + + //$this->Sales_PD_Model->updateRecords(array('pd_report_filename' => 'PD_Report-'.$pdf_name),SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id)); + + $type1_key = 'sales_pd/'.$sales_pd_id.'/'.$type1_pdf_name.'.pdf'; + $type2_key = 'sales_pd/'.$sales_pd_id.'/'.$type2_pdf_name.'.pdf'; + $type3_key = 'sales_pd/'.$sales_pd_id.'/'.$type3_pdf_name.'.pdf'; + if(!file_exists($this->external_path.'/sales_pd/'.$sales_pd_id)) { mkdir($this->external_path.'/sales_pd/'.$sales_pd_id,0777); @@ -223,7 +233,7 @@ class Sales_PD_Controller extends REST_Controller { $bytes = file_put_contents($output_file, $pdf_doc); //echo $bytes; //die(); - $bucket_data = array('bucket_name'=>$bucket_name,'key'=>$key,'sourcefile'=>$this->external_path.'/sales_pd/'.$sales_pd_id.'/temp.pdf'); + $bucket_data = array('bucket_name'=>$bucket_name,'key'=>$type3_key,'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); @@ -232,13 +242,17 @@ class Sales_PD_Controller extends REST_Controller { $this->Sales_PD_Model->updateRecords(array('is_pdf' => 1, 'is_edited' => 0),SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id)); if($api) - { - $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); + { + $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type3_key,'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'); + if($headers && strpos( $headers[0], '200')) { + $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type2_key,'30 minutes'); + }else { + $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type1_key,'30 minutes'); + } } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; @@ -252,12 +266,16 @@ class Sales_PD_Controller extends REST_Controller { if($api) { ## NEW KEY BECAUSE TITLE-RENAME - $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); + $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type3_key,'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'); + if($headers && strpos( $headers[0], '200')) { + $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type2_key,'30 minutes'); + }else { + $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type3_key,'30 minutes'); + } } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; From babe069c3900e78cb733bbd9971a0fc85768aafb Mon Sep 17 00:00:00 2001 From: sanjeev Date: Wed, 23 Feb 2022 22:09:13 +0530 Subject: [PATCH 2/3] report prfic added : ps --- api/application/controllers/PD_Controller.php | 27 ++++++++++++++++--- .../controllers/SMC_Credit_PD_Controller.php | 17 +++++++++--- .../controllers/Sales_PD_Controller.php | 24 ++++------------- 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/api/application/controllers/PD_Controller.php b/api/application/controllers/PD_Controller.php index 21be7471..fa69033e 100644 --- a/api/application/controllers/PD_Controller.php +++ b/api/application/controllers/PD_Controller.php @@ -4938,7 +4938,11 @@ public function getPDFormDetailsJSON_post() $bucketname = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['fk_lender_id']; $main_applicant_name = $pd_master_details[0]['main_applicant']; - $key = 'pd'.$pdid.'/pd_reports/'.$main_applicant_name.'.pdf'; + $pdf_name = 'PD_REPORTS_'.$main_applicant_name; + + // $key = 'pd'.$pdid.'/pd_reports/'.$main_applicant_name.'.pdf'; + $type1_key = 'pd'.$pdid.'/pd_reports/'.$main_applicant_name.'.pdf'; + $type2_key = 'pd'.$pdid.'/pd_reports/'.$pdf_name.'.pdf'; @@ -4995,7 +4999,7 @@ public function getPDFormDetailsJSON_post() { $sourcefile = $output_file2; - $bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile); + $bucket_data = array('bucket_name'=>$bucketname,'key'=>$type2_key,'sourcefile'=>$sourcefile); $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); //print_r($s3result); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) @@ -5009,7 +5013,15 @@ public function getPDFormDetailsJSON_post() - $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+30 minutes'); + // $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+30 minutes'); + $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type2_key,'30 minutes'); + $headers = @get_headers($_uri); + if($headers && strpos( $headers[0], '200')) { + $singed_uri = $_uri; + }else { + $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type1_key,'30 minutes'); + } + if($id != null || $id != "" ) { @@ -5039,7 +5051,14 @@ public function getPDFormDetailsJSON_post() else //If Qc not edited pull PDF uri from S3 { - $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+30 minutes'); + // $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+30 minutes'); + $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type2_key,'+30 minutes'); + $headers = @get_headers($_uri); + if($headers && strpos( $headers[0], '200')) { + $singed_uri = $_uri; + }else { + $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type1_key,'+30 minutes'); + } if($singed_uri != null || $singed_uri != "" ) { diff --git a/api/application/controllers/SMC_Credit_PD_Controller.php b/api/application/controllers/SMC_Credit_PD_Controller.php index 4ebbd444..29f5aa30 100644 --- a/api/application/controllers/SMC_Credit_PD_Controller.php +++ b/api/application/controllers/SMC_Credit_PD_Controller.php @@ -1644,22 +1644,31 @@ public function filterSalesPDList_post() { } // echo $html_content;exit(); - $pdf_name = $view_data['pd_master_details'][0]['main_applicant']; + $type1_pdf_name = $view_data['pd_master_details'][0]['main_applicant']; + $type2_pdf_name = "PD_Report_".$view_data['pd_master_details'][0]['main_applicant']; $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 ."/pd_reports/" . $records['pd_id'] . "/temp.pdf"; $bytes = file_put_contents($output_file, $pdf_doc); //echo $bytes;die(); $bucket_name = LENDER_BUCKET_NAME_PREFIX.(ENVIRONMENT == 'production' ? 7 : 35); - $key = 'pd'.$records['pd_id'].'/pd_reports/'.$pdf_name.'.pdf'; - $bucket_data = array('bucket_name'=>$bucket_name,'key'=>$key,'sourcefile'=>$output_file); + $type1_key = 'pd'.$records['pd_id'].'/pd_reports/'.$type1_pdf_name.'.pdf'; + $type2_key = 'pd'.$records['pd_id'].'/pd_reports/'.$type2_pdf_name.'.pdf'; + $bucket_data = array('bucket_name'=>$bucket_name,'key'=>$type2_key,'sourcefile'=>$output_file); $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { // $this->Sales_PD_Model->updateRecords(array('is_pdf' => 1, 'is_edited' => 0),SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id)); - $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); + // $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); + $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type2_key,'30 minutes'); + $headers = @get_headers($_uri); + if($headers && strpos( $headers[0], '200')) { + $singed_uri = $_uri; + }else { + $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type1_key,'30 minutes'); + } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $singed_uri; diff --git a/api/application/controllers/Sales_PD_Controller.php b/api/application/controllers/Sales_PD_Controller.php index 810ac1cf..36e65fe3 100644 --- a/api/application/controllers/Sales_PD_Controller.php +++ b/api/application/controllers/Sales_PD_Controller.php @@ -190,16 +190,10 @@ class Sales_PD_Controller extends REST_Controller { $type2_pdf_name .= '-'.$pd_type.$sales_pd_data[0]['abbr']; $type2_pdf_name .= '-'.(date('dmY',strtotime($sales_pd_data[0]['completed_date']))); - // 3rd Type Key name. (string,name,type,abbr and date). - $type2_pdf_name = strtolower(trim($sales_pd_data[0]['applicant_name'])); - $type2_pdf_name .= '-'.$pd_type.$sales_pd_data[0]['abbr']; - $type2_pdf_name .= 'PD_Report-'.(date('dmY',strtotime($sales_pd_data[0]['completed_date']))); - //$this->Sales_PD_Model->updateRecords(array('pd_report_filename' => 'PD_Report-'.$pdf_name),SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id)); $type1_key = 'sales_pd/'.$sales_pd_id.'/'.$type1_pdf_name.'.pdf'; $type2_key = 'sales_pd/'.$sales_pd_id.'/'.$type2_pdf_name.'.pdf'; - $type3_key = 'sales_pd/'.$sales_pd_id.'/'.$type3_pdf_name.'.pdf'; if(!file_exists($this->external_path.'/sales_pd/'.$sales_pd_id)) { @@ -233,7 +227,7 @@ class Sales_PD_Controller extends REST_Controller { $bytes = file_put_contents($output_file, $pdf_doc); //echo $bytes; //die(); - $bucket_data = array('bucket_name'=>$bucket_name,'key'=>$type3_key,'sourcefile'=>$this->external_path.'/sales_pd/'.$sales_pd_id.'/temp.pdf'); + $bucket_data = array('bucket_name'=>$bucket_name,'key'=>$type2_key,'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); @@ -243,16 +237,12 @@ class Sales_PD_Controller extends REST_Controller { $this->Sales_PD_Model->updateRecords(array('is_pdf' => 1, 'is_edited' => 0),SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id)); if($api) { - $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type3_key,'30 minutes'); + $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type2_key,'30 minutes'); $headers = @get_headers($_uri); if($headers && strpos( $headers[0], '200')) { $singed_uri = $_uri; }else { - if($headers && strpos( $headers[0], '200')) { - $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type2_key,'30 minutes'); - }else { - $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type1_key,'30 minutes'); - } + $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type1_key,'30 minutes'); } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; @@ -266,16 +256,12 @@ class Sales_PD_Controller extends REST_Controller { if($api) { ## NEW KEY BECAUSE TITLE-RENAME - $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type3_key,'30 minutes'); + $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type2_key,'30 minutes'); $headers = @get_headers($_uri); if($headers && strpos( $headers[0], '200')) { $singed_uri = $_uri; }else { - if($headers && strpos( $headers[0], '200')) { - $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type2_key,'30 minutes'); - }else { - $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type3_key,'30 minutes'); - } + $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$type1_key,'30 minutes'); } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; From a2a363d0c7d9fd2c1813046fcf0877cf159bfab5 Mon Sep 17 00:00:00 2001 From: sanjeev Date: Thu, 24 Feb 2022 16:26:31 +0530 Subject: [PATCH 3/3] Dynamic template : ps --- .../Template_Management_Controller.php | 30 ++++++++----------- .../models/Template_Management_Model.php | 2 +- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/api/application/controllers/Template_Management_Controller.php b/api/application/controllers/Template_Management_Controller.php index 41b752c5..85da4a29 100644 --- a/api/application/controllers/Template_Management_Controller.php +++ b/api/application/controllers/Template_Management_Controller.php @@ -1088,25 +1088,21 @@ class Template_Management_Controller extends REST_Controller { $fields = array('id'); $status = strtoupper(str_replace(' ', '',$records['form_status'])); $where_condition_array = array('map_id'=>$map_id,"form_id"=>$form_id,"isactive"=>1); - $json_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_JSON_V2); - if(count($json_table)>0 && $status == "COMPLETED"){ - $this->db->where('id',$json_table[0]['id']); + $json_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_JSON_V2); + foreach ($json_table as $value) $id_array[] = $value['id']; + if(count($json_table)>0 && $status == "COMPLETED"){ + $this->db->where_in('id',$id_array); $this->db->set('isactive',0); $this->db->update(TEMPLATE_JSON_V2); - }else if(count($json_table)>0 && ($status == "DRAFT" || $status == "APPROVED" )){ - $json = json_encode($records['json'],true); - $this->db->where('id',$json_table[0]['id']); - $this->db->where('map_id',$map_id); - $this->db->where('form_id',$form_id); - $this->db->where('is_form_status',$status); - $this->db->set('json',$json); - $this->db->update(TEMPLATE_JSON_V2); - $json_pk_id = $json_table[0]['id']; - }else{ - $json = json_encode($records['json'],true); - $fields = array('form_id' => $form_id,'json' => $json,'map_id'=>$map_id,'is_form_status'=>$status); - $json_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_JSON_V2); - } + }else if(count($json_table)>0 && ($status == "DRAFT" || $status == "APPROVED")){ + $this->db->where('is_form_status',"COMPLETED"); + $this->db->where_in('id',$id_array); + $this->db->set('isactive',0); + $this->db->update(TEMPLATE_JSON_V2); + } + $json = json_encode($records['json'],true); + $fields = array('form_id' => $form_id,'json' => $json,'map_id'=>$map_id,'is_form_status'=>$status); + $json_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_JSON_V2); if($json_pk_id) { $data['dataStatus'] = true; diff --git a/api/application/models/Template_Management_Model.php b/api/application/models/Template_Management_Model.php index 9de859a5..147b75b0 100644 --- a/api/application/models/Template_Management_Model.php +++ b/api/application/models/Template_Management_Model.php @@ -314,7 +314,7 @@ class Template_Management_Model extends SPARQ_Model { } public function getTemplateFormsV2($value){ - $this->db->SELECT('TEMPLATE_JSON_V2.form_id,PDFORMS.pd_form_name as form_name,TEMPLATE_JSON_V2.json,TEMPLATE_JSON_V2.is_form_disabled,PDFORMS.is_business_form,TEMPLATE_JSON_V2.is_group_form,PDFORMS.pd_form_order'); + $this->db->SELECT('TEMPLATE_JSON_V2.form_id,PDFORMS.pd_form_name as form_name,TEMPLATE_JSON_V2.json,TEMPLATE_JSON_V2.is_form_disabled,PDFORMS.is_business_form,TEMPLATE_JSON_V2.is_group_form,PDFORMS.pd_form_order,TEMPLATE_JSON_V2.is_form_status'); $this->db->FROM(TEMPLATE_JSON_V2.' as TEMPLATE_JSON_V2'); $this->db->JOIN(PDFORMS.' as PDFORMS','TEMPLATE_JSON_V2.form_id = PDFORMS.pd_form_id','LEFT'); $this->db->WHERE('TEMPLATE_JSON_V2.isactive',1);