PD REPORTS EDITED

This commit is contained in:
velz 2018-12-11 18:04:24 +05:30
parent b164ae8e49
commit 577934d182
5 changed files with 179 additions and 56 deletions

View File

@ -87,7 +87,7 @@ defined('EXIT__AUTO_MAX') OR define('EXIT__AUTO_MAX', 125); // highest auto
// define login route name for token verification
//defined('ROUTE_LOGIN') OR define('ROUTE_LOGIN', '(listLessPDDetails/:any)'); // no errors
//defined('ROUTE_LOGIN') OR define('ROUTE_LOGIN', '(listAllTemplates/:any)'); // no errors
defined('ROUTE_LOGIN') OR define('ROUTE_LOGIN', 'saveNewVersionOfPDReport'); // no errors
defined('ROUTE_LOGIN') OR define('ROUTE_LOGIN', 'getFinalPDReportQuestions'); // no errors
/*********************AWS resources Constants*************************************************/
defined('PROFILE_PICTURE_BUCKET_NAME') OR define('PROFILE_PICTURE_BUCKET_NAME','sineedgedevprofilepic');
@ -442,6 +442,9 @@ defined('COMPANYRELATIONSHIPSID') OR define('COMPANYRELATIONSHIPSID','company_re
defined('RELATIONWITHBUSINESS') OR define('RELATIONWITHBUSINESS','m_relation_with_business');
defined('RELATIONWITHBUSINESSID') OR define('RELATIONWITHBUSINESSID','relation_with_business_id');
defined('PDREPORTSVERSIONBLOB') OR define('PDREPORTSVERSIONBLOB','t_pd_reports_version_blob');
defined('PDREPORTSVERSIONBLOBID') OR define('PDREPORTSVERSIONBLOBID','pd_report_version_blob_id');

View File

@ -168,6 +168,7 @@ $route['savePDAdditionalRequiremets'] = 'PD_Controller/savePDAdditionalRequireme
$route['generatePDReport'] = 'PD_Controller/generatePDReport';
$route['getLatestPDReportBlob'] = 'PD_Controller/getLatestPDReportBlob';
$route['saveNewVersionOfPDReport'] = 'PD_Controller/saveNewVersionOfPDReport';
$route['getListOfPDReportVersions'] = 'PD_Controller/getListOfPDReportVersions';
//PD Form Related
$route['getPDFormDetails'] = 'PD_Controller/getPDFormDetails';

View File

@ -51,6 +51,8 @@ class Entity_Management_Controller extends REST_Controller {
{
$records = "";
$entity_id = "";
$bucket_status = "";
$cors_status = "";
if($this->post('records')){ $records = $this->post('records'); }
@ -67,7 +69,11 @@ class Entity_Management_Controller extends REST_Controller {
//echo "LENDER TYPE";
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$entity_id;
$bucket_status = $this->aws_s3->createNewBucket($bucket_name);
//print_r($bucket_status);
if($bucket_status['Location'])
{
$cors_status = $this->aws_s3->setCors($bucket_name)
}
}
}
@ -77,6 +83,8 @@ class Entity_Management_Controller extends REST_Controller {
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['record'] = $entity_id;
$data['bucket_info'] = $bucket_status;
$data['cors_info'] = $cors_status;
$this->response($data,REST_Controller::HTTP_OK);
}
else

View File

@ -2047,7 +2047,8 @@ class PD_Controller extends REST_Controller {
}
/*********************************************************************************************
*********************************************************************************************/
public function saveAssessedIncomeMonthwiseItems_post()//SALESITEMMONTHWISECHILD
{
$records = $this->post('records');
@ -2116,6 +2117,9 @@ class PD_Controller extends REST_Controller {
}
}
/*********************************************************************************************
*********************************************************************************************/
public function getFinalPDReportQuestions_post()
{
$pd_id = $this->post('pd_id');
@ -2204,6 +2208,9 @@ class PD_Controller extends REST_Controller {
}
/*********************************************************************************************
*********************************************************************************************/
public function transformKeyPairToQuestionAnswers($pd_form_raw_data,$form_id)
{
//field name array holds - field name of each masters table
@ -2254,6 +2261,9 @@ class PD_Controller extends REST_Controller {
}
/*********************************************************************************************
*********************************************************************************************/
public function saveAssessedIncomeCalculateMode_post()
{
$records = $this->post('records');
@ -2289,6 +2299,9 @@ class PD_Controller extends REST_Controller {
}
/*********************************************************************************************
*********************************************************************************************/
public function calculateAssessedIncome($pd_id)
{
@ -2544,14 +2557,18 @@ class PD_Controller extends REST_Controller {
}
/*********************************************************************************************
*********************************************************************************************/
public function getLatestPDReportBlob_post()
{
$records = $this->post('records');
$pdid = $records['pd_id'];
$version_id = $records['version_id'];
$fields = array('pd_report_latest_version_blob');
$where_condition_array = array('pd_id'=>$pdid);
$result_array = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDTRIGGER);
$fields = array('content');
$where_condition_array = array('fk_pd_id'=>$pdid,'version_no'=>$version_id);
$result_array = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDREPORTSVERSIONBLOB);
if(count($result_array))
{
$data['dataStatus'] = true;
@ -2570,6 +2587,8 @@ class PD_Controller extends REST_Controller {
}
/*********************************************************************************************
*********************************************************************************************/
public function generatePDReport_post()
{
$records = $this->post('records');
@ -2581,9 +2600,10 @@ class PD_Controller extends REST_Controller {
//getSingleObjectInaBucketAsSignedURI($bucket_name,$folder_name,$time = '+5 minutes')
//CHeck if already pd original version created
if($pd_master_details[0]['is_original_report_created'] == "" || $pd_master_details[0]['is_original_report_created'] == null)
{
// //CHeck if already pd original version created
// if($pd_master_details[0]['is_original_report_created'] == "" || $pd_master_details[0]['is_original_report_created'] == null)
// {
//Get PD Report Functions
$fields = array('report_template_id', 'fk_template_id','content');
$where_condition_array = array('fk_template_id'=>$pd_master_details[0]['fk_pd_template_id'],'isactive'=>1);
@ -2631,7 +2651,7 @@ class PD_Controller extends REST_Controller {
if(file_put_contents($output_file2, $pdf_doc))
{
$bucketname = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['fk_lender_id'];
$key = 'pd'.$pdid.'/'.'pd_report_original_version.pdf';
$key = 'pd'.$pdid.'/pd_reports/pd_report_original_version.pdf';
$sourcefile = $output_file2;
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile);
@ -2644,12 +2664,16 @@ class PD_Controller extends REST_Controller {
$temp_array = array('is_original_report_created'=>1,'pd_report_latest_version_blob'=>$result_array[0]['content']);
$id = $this->PD_Model->updateRecords($temp_array,PDTRIGGER,$where_condition_array);
$uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,$time = '3600 seconds');
//call all reports functionality and send it.
$urls = $this->getALLPDReportsSingedURLs($bucket_name,$key);
if($id != null || $id != "" )
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = array('pd_report_uri' => $uri);
$data['records'] = $urls;
$this->response($data,REST_Controller::HTTP_OK);
}
else
@ -2662,39 +2686,42 @@ class PD_Controller extends REST_Controller {
}
}
}
else
{
//get latest or same original version of pd_report_original_version
$flag = 0;
if($pd_master_details[0]['pd_report_latest_version'] != null || $pd_master_details[0]['pd_report_latest_version'] != "")
{
$flag = 1;
}
// }
// else
// {
// //get latest or same original version of pd_report_original_version
// $flag = 0;
// if($pd_master_details[0]['pd_report_latest_version'] != null || $pd_master_details[0]['pd_report_latest_version'] != "")
// {
// $flag = 1;
// }
$bucketname = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['fk_lender_id'];
//$bucketname = LENDER_BUCKET_NAME_PREFIX.'8';
$key = 'pd'.$pdid.'/'.'pd_report_original_version.pdf';
//$key = 'pd'.'4'.'/'.'11.pdf';
if($flag == 1)
{
$key = 'pd'.$pdid.'/'.'version'.$pd_master_details[0]['pd_report_latest_version'].'.pdf';
}
//echo $key;
$uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,$time = '3600 seconds');
if($uri != "" || $uri != null)
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = array('pd_report_uri' => $uri);
$this->response($data,REST_Controller::HTTP_OK);
}
// $bucketname = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['fk_lender_id'];
// //$bucketname = LENDER_BUCKET_NAME_PREFIX.'8';
// $key = 'pd'.$pdid.'/'.'pd_report_original_version.pdf';
// //$key = 'pd'.'4'.'/'.'11.pdf';
// if($flag == 1)
// {
// $key = 'pd'.$pdid.'/'.'version'.$pd_master_details[0]['pd_report_latest_version'].'.pdf';
// }
// //echo $key;
// $uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,$time = '3600 seconds');
// if($uri != "" || $uri != null)
// {
// $data['dataStatus'] = true;
// $data['status'] = REST_Controller::HTTP_OK;
// $data['records'] = array('pd_report_uri' => $uri);
// $this->response($data,REST_Controller::HTTP_OK);
// }
}
// }
}
/*********************************************************************************************
*********************************************************************************************/
public function saveNewVersionOfPDReport_post()
{
@ -2702,16 +2729,23 @@ class PD_Controller extends REST_Controller {
$records = $this->post('records');
$pdid = $records['pd_id'];
$blob = $records['content'];
$fk_updatedby = $records['fk_updatedby'];
$fk_createdby = $records['fk_createdby'];
//Get PD Master Details
$pd_master_details = $this->PD_Model->getPDMasterDetails($pdid);
//print_r($pd_master_details);
//store BLOB in pd trigger Table
//update BLOB in pd trigger Table
$latest_version = $pd_master_details[0]['pd_report_latest_version'] + 1;
$where_condition_array = array('pd_id' => $pdid);
$temp_array = array('pd_report_latest_version' => $latest_version,'pd_report_latest_version_blob' => $blob);
$id = $this->PD_Model->updateRecords($temp_array,PDTRIGGER,$where_condition_array);
//store BLOB in t_pd_reports_version_blob Table
//$latest_version = $pd_master_details[0]['pd_report_latest_version'] + 1;
//$where_condition_array = array('pd_id' => $pdid);
$temp_array_one = array('fk_pd_id'=>$pdid,'version_no' => $latest_version,'content' => $blob,'fk_createdby'=>$fk_createdby,'fk_updatedby'=>$fk_updatedby);
$id = $this->PD_Model->saveRecords($temp_array_one,PDREPORTSVERSIONBLOB);
//convert BLOB as html then pdf then store it s3.
$output_file = APPPATH."/docs/temp.html";
@ -2729,7 +2763,7 @@ class PD_Controller extends REST_Controller {
if(file_put_contents($output_file2, $pdf_doc))
{
$bucketname = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['fk_lender_id'];
$key = 'pd'.$pdid.'/'.'version'.$latest_version.'.pdf';
$key = 'pd'.$pdid.'/pd_reports/'.'version'.$latest_version.'.pdf';
$sourcefile = $output_file2;
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile);
@ -2738,12 +2772,12 @@ class PD_Controller extends REST_Controller {
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
{
$uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,$time = '3600 seconds');
$urls = $this->getALLPDReportsSingedURLs($bucketname,$key);
if($id != null || $id != "" )
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = array('pd_report_uri' => $uri);
$data['records'] = $urls;
$this->response($data,REST_Controller::HTTP_OK);
}
else
@ -2760,7 +2794,84 @@ class PD_Controller extends REST_Controller {
}
}
/*********************************************************************************************
*********************************************************************************************/
public function getListOfPDReportVersions_post()
{
$records = $this->post('records');
$pdid = $records['pd_id'];
//Get PD Master Details
$pd_master_details = $this->PD_Model->getPDMasterDetails($pdid);
$lender_id = $pd_master_details[0]['fk_lender_id'];
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$lender_id;
$key = 'pd'.$pdid.'pd_reports';
//$key = 'pd'.$pdid;
$urls = $this->getALLPDReportsSingedURLs($bucket_name,$key);
if(count($urls))
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $urls;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = 'PD Report Not Generated/Report Not Available!';
$this->response($data,REST_Controller::HTTP_OK);
}
}
/*********************************************************************************************
*********************************************************************************************/
public function getALLPDReportsSingedURLs($bucket_name,$key)
{
$all_objects = $this->aws_s3->getAllObjectsInaBucket($bucket_name,$key);
$uri = array();
foreach($all_objects as $obj)
{
//print_r($obj);
$uri[]['doc_name'] = $obj['Key'];
}
//print_r($uri);
if(count($uri))
{
foreach($uri as $uri_key => $url)
{
$uri[$uri_key]['doc_uri'] = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$url['doc_name'],$time = '3600 seconds');
$uri[$uri_key]['doc_name'] = $uri[$uri_key]['doc_name'];
if($uri_key == (count($uri)-1))
{
$uri[$uri_key]['is_latest'] = 1;
}else
{
$uri[$uri_key]['is_latest'] = 0;
}
}
}
return $uri;
}
/*********************************************************************************************
*********************************************************************************************/
}

View File

@ -21,8 +21,8 @@ class AWS_S3
//echo "listAllBuckets";
$this->S3 = S3Client::factory($this->s3_properties);
// echo "Called";
//$this->setCors();
// echo "Called";
// $this->createNewBucket();
}
@ -49,9 +49,9 @@ class AWS_S3
return $result;
} catch (AwsException $e) {
// output error message if fails
// echo $e->getMessage();
// echo "\n";
//output error message if fails
return $e->getMessage();
//echo "\n";
}
}
@ -144,11 +144,11 @@ class AWS_S3
return $result;
}
public function setCors()
public function setCors($BUCKETNAME)
{
$result = $this->S3->putBucketCors([
'Bucket' => 'lender8',
'Bucket' => $BUCKETNAME,
'CORSConfiguration' => [
'CORSRules' => [
[
@ -185,16 +185,16 @@ class AWS_S3
]);
print_r($result);
return $result;
}
public function getCORES()
public function getCORES($BUCKETNAME)
{
$result = $this->S3->getBucketCors([
'Bucket' => 'lender8']);
print_r($result);
'Bucket' => $BUCKETNAME]);
//////print_r($result);
}
}