diff --git a/api/application/controllers/Request_DataDump_Controller.php b/api/application/controllers/Request_DataDump_Controller.php index e2abc8e0..5c24617a 100755 --- a/api/application/controllers/Request_DataDump_Controller.php +++ b/api/application/controllers/Request_DataDump_Controller.php @@ -33,12 +33,14 @@ class Request_DataDump_Controller extends REST_Controller { parent::__construct(); $this->load->model('Data_Dump_Model','Data_Dump_Model'); $this->load->library('pdfgenerator'); + $this->load->library('zip'); + // $this->load->helper('download'); // $this->load->library('AWS_S3'); } ### XL-Data-Dump master Details Filter # PD-TYPE,PRODUCT,CUSTOMER-SEGMENT AND PD-SNO. - public function getMasterForDataDump_get(){ + public function getMasterForDataDumpold_get(){ log_message('ERROR','## XL-datadump Master Details inside Fns - '.date('Y-m-d H:i:s A')); $result = $this->Data_Dump_Model->filtermasterfordatadumprequest(); if(count($result) > 0) @@ -55,6 +57,39 @@ class Request_DataDump_Controller extends REST_Controller { $this->response($data,REST_Controller::HTTP_OK); }//getMasterForDataDump closed here. + public function getMasterForDataDump_post(){ + log_message('ERROR','## XL-datadump Master Details inside Fns - '.date('Y-m-d H:i:s A')); + $records = $this->post(); + $result = $this->Data_Dump_Model->filtermasterfordatadumprequest(); + if(count($result) > 0) + { log_message('ERROR',"## XL-datadump Master Details : ".json_encode($result)); + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $result; + $data['message'] = "Totalpd-count Except Truncate cases"; + if(!empty($records)){ + $pd_type = isset($records['pd_type'])?$records['pd_type']:null; + $pd_from_date = isset($records['pd_from_date'])?$records['pd_from_date']: null; + $pd_to_date = isset($records['pd_to_date'])?$records['pd_to_date']: null; + $pd_city = isset($records['pd_city'])?$records['pd_city']: null; + $pd_products = isset($records['pd_products'])?$records['pd_products']: null; + $pd_lender = isset($records['pd_lender'])?$records['pd_lender']: null; + $pd_customer_segment = isset($records['pd_customer_segment'])?$records['pd_customer_segment']: null; + $pd_status = COMPLETED; + $result_data = $this->Data_Dump_Model->PDList($pd_type, $pd_status, $pd_from_date, $pd_to_date, $pd_city, $pd_products, $pd_lender,$pd_customer_segment); + $data['records']['pdid'] = $result_data; + $data['records']['totalpd'] = count($result_data); + $data['message'] = "Totalpd-count Should be completed Cases only"; + } + }else{ log_message('ERROR',"## XL-datadump Master Details Error "); + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['message'] = "Fails"; + unset($data['records']); + } + $this->response($data,REST_Controller::HTTP_OK); + }//getMasterForDataDump closed here. + ### Request the Details For XL-Data-Dump. public function getRequestForDataDump_post(){ // echo XLPATH;die(); @@ -66,7 +101,28 @@ class Request_DataDump_Controller extends REST_Controller { $requested_details = $this->Data_Dump_Model->getRequestForDataDump($postarr); log_message('ERROR','## Request For XL-datadump Requested-data count - '.count($requested_details)); if (!empty($requested_details)){ - requestdatadump::Fns4($requested_details); + // requestdatadump::Fns4($requested_details); + // requestdatadump::Fns5($requested_details); + // header('Content-Type: text/csv; charset=utf-8'); + // header('Content-Disposition: attachment; filename=PDExport1.csv'); + + // // create a file pointer connected to the output stream + // $output = fopen('php://output', 'w'); + + // // output the column headings + // fputcsv($output, array("City", "Product", "Process", "Price", "Vendor Price", "Brand")); + // fputcsv($output, array("Bangalore", "Product", "Process", "Price", "Vendor Price", "Brand")); + + + $files = array("PDExportXL.xls","PDExportXL2.xls","PDExportXL2.xls"); + foreach($files as $f) + { + $this->zip->read_file(XLPATH.'/tmp/'.$f); + } + $this->zip->archive(XLPATH.'/tmp/'.time().'.zip'); + // force_download($this->zip->archive(XLPATH.'/tmp/'.time().'.zip')); + // force_download($this->zip->archive('S1.zip')); + // $this->zip->download(XLPATH.'/tmp/'.time().'.zip'); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['message'] = "Success"; diff --git a/api/application/helpers/requestdatadump_helper.php b/api/application/helpers/requestdatadump_helper.php index 4f7b48ee..9f6d5f2b 100644 --- a/api/application/helpers/requestdatadump_helper.php +++ b/api/application/helpers/requestdatadump_helper.php @@ -72,6 +72,35 @@ class requestdatadump $writer = $CI->myspreadsheet->getXlsx($spreadsheet); $writer->save(XLPATH.'/tmp/PDExportXL_f.xls'); } + public static function createzip(){ + + // Load zip library + $CI =&get_instance(); + $CI->load->library('zip'); + $files = array("PDExportXL.xls","PDExportXL2.xls","PDExportXL2.xls"); + foreach ($files as $row) + { + $fileName = XLPATH."/tmp/".$row; + $CI->zip->read_file($fileName); + } + + $filename = XLPATH."/tmp/backup.zip"; + $CI->zip->download($filename); + } +// public static function createzip2(){ + +// // Load zip library +// $CI =&get_instance(); +// $CI->load->library('zip'); +// $files = array("PDExportXL.xls","PDExportXL2.xls","PDExportXL2.xls"); +// // Write the zip file to a folder on your server. Name it "my_backup.zip" +// $CI->zip->archive(XLPATH."/tmp/); + +// // Download the file to your desktop. Name it "my_backup.zip" +// $filename = XLPATH."/tmp/backup.zip"; +// $CI->zip->download($filename); +// } + public static function Fns4($requested_details) { @@ -248,6 +277,181 @@ class requestdatadump $filename = "PDExportXL_".date('Y-m-d H:i:s A').".xls"; $writer->save(XLPATH.'/tmp/'.$filename); }// fns2 ends here + public static function Fns5($requested_details) + { + log_message('ERROR','####RequestDataDump Helper FNS2'); + log_message('ERROR','####Creating Test Excel'); + $CI =&get_instance(); + $CI->load->library('myspreadsheet'); + SELF::$current_spreadsheet = $CI->myspreadsheet->getMySpreadSheet(); + $formid_arr = array(); + for($i=0;$i < count($requested_details);$i++){ + $processedJson = json_decode($requested_details[$i]['processed_json'],TRUE); + $formid = $processedJson['formid']; + // echo " ".$formid." "; + if (!in_array($formid, $formid_arr)){ + array_push($formid_arr,(int)$formid); + } + } + sort($formid_arr); + SELF::formHeadlines($formid_arr); + $writer = $CI->myspreadsheet->getXlsx(SELF::$current_spreadsheet); + $filename = "PDExportXL_".date('Y-m-d H:i:s A').".xls"; + $writer->save(XLPATH.'/tmp/'.$filename); + // $numbers = array(4, 6, 2, 22, 11);sort($numbers); + // print_r($numbers); + // print_r($formid_arr);die(); + + for($i=0;$i < count($requested_details);$i++){ + $processedJson = json_decode($requested_details[$i]['processed_json'],TRUE); + // print_r($processedJson);die(); + // echo "Don't Worry Be happy because i have JSON"; + $formid = $processedJson['formid']; + switch($formid) + { + // case 1: ## '1', 'Supplier Details' + // $details = SELF::gatheringSupplierForm($processedJson); + // // $sheet->setTitle('Supplier Details'); + // $sheet->setActiveSheetIndex(0)->setCellValue('A1','Supplier Details'); + // $sheet->getActiveSheet()->setTitle('Supplier Details'); + + // break; + // case 2: ## '2', 'Client Details' + // $details = SELF::gatheringClientForm($processedJson); + // $sheet->createSheet(); + // $sheet->setActiveSheetIndex(1)->setCellValue('A1', 'Client Details !'); + // $sheet->getActiveSheet()->setTitle('Client Details'); + + // break; + // case 3: ## '3', 'Personal Details' + // $details = SELF::gatheringPersonalForm($processedJson); + // $sheet->createSheet(); + // $sheet->setActiveSheetIndex(2)->setCellValue('A1', 'Personal Details !'); + // $sheet->getActiveSheet()->setTitle('Personal Details'); + // break; + // case 4: ## '4', 'Other Assets' + // $details = SELF::gatheringOtherAssetForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Other Assets'); + + // break; + // case 5: ## '5', 'Address Details' + // $details = SELF::gatheringAddressForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Address Details'); + + // break; + // case 6: ## '6', 'Family Details' + // $details = SELF::gatheringOtherFamilyDetailsForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Family Details'); + + // break; + // case 7: ## '7', 'Banking Details' + // $details = SELF::gatheringBankingInfoForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Banking Details'); + + // break; + // case 8: ## '8', 'Existing Loan Obligations' + // $details = SELF::gatheringExistingLoanDetailsForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Existing Loan Obligations'); + + // break; + // case 9: ## '9', 'Other Income Details' + // $details = SELF::gatheringOtherIncomeDetailsForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Other Income Details'); + + // break; + // case 10: ## '10', 'Loan Details' + // $details = SELF::gatheringLoanDetailsForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Loan Details'); + + // break; + // case 11: ## '11', 'Stock Details' + // $details = SELF::gatheringStockDetailsForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Stock Details'); + + // break; + // case 12: ## '12', 'Employment Information' + // $details = SELF::gatheringEmploymetForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Employment Information'); + + // break; + // case 13: ## '13', 'Business Information' + // $details = SELF::gatheringBusinessForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Business Information'); + + // break; + // case 14: ## '14', 'Financial Information' + // $details = SELF::gatheringFinancialInfoForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Financial Information'); + + // break; + // case 15: ## '15', 'Lender Representative' + // $details = SELF::gatheringLenderRepresentativeForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Lender Representative'); + + // break; + // case 16: ## '16', 'Assessed Income' + // $details = SELF::gatheringAssessedIncomeForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Assessed Income'); + + // break; + // case 17: ## '17', 'Rental Verification' + // $details = SELF::gatheringRentalIncomeForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Rental Verification'); + + // break; + // case 18: ## '18', 'General Information' + // $details = SELF::gatheringGeneralInfoForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('General Information'); + + // break; + // case 19: ## '19', 'Neighbourhood / Reference Check' + // $details = SELF::gatheringNeighbourForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Neighbourhood and Ref Check'); + + // break; + // case 20: ## '20', 'Final Remarks Form' + // $details = SELF::gatheringFinalRemarksForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Final Remarks Form'); + + // break; + // case 21: ## '21', 'Business Banking' + // $details = SELF::gatheringBusinessBankingFormForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Business Banking'); + + // break; + // case 22: ## '22', 'Business Assets' + // $details = SELF::gatheringBusinessAssetsForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Business Assets'); + + // break; + // case 23: ## '23', 'Future Plan and Business Environment' + // $details = SELF::gatheringFuturePlanandBusinessEnvironmentForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Future Plan'); + + // break; + // case 24: ## '24', 'Credit Manager Queries' + // $details = SELF::gatheringCreditManagerQueriesForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Credit Manager Queries'); + + // break; + // case 25: ## '25', 'Vendor PD Form' + // $details = SELF::gatheringVendorPDForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Vendor PD Form'); + + // break; + // case 26: ## '26', 'Photograph' + // $details = SELF::gatheringPhotographForm($processedJson); + // SELF::$current_spreadsheet->setActiveSheetIndex($formid)->setTitle('Photograph'); + + // break; + // default: ## + // echo "Final - No Form ID";break; + }// Switch ends here + }// for loop ends here + $writer = $CI->myspreadsheet->getXlsx(SELF::$current_spreadsheet); + $filename = "PDExportXL_".date('Y-m-d H:i:s A').".xls"; + $writer->save(XLPATH.'/tmp/'.$filename); + }// fns5 ends here public static function formHeadlines($formid_arr){ $i=0; $arr = sort($formid_arr); @@ -536,6 +740,8 @@ class requestdatadump return $sheet; } + + ## '1', 'Supplier Details' static function gatheringSupplierForm($processedJson){ diff --git a/api/application/models/Data_Dump_Model.php b/api/application/models/Data_Dump_Model.php index 3fa96e75..c6371f02 100755 --- a/api/application/models/Data_Dump_Model.php +++ b/api/application/models/Data_Dump_Model.php @@ -74,8 +74,8 @@ class Data_Dump_Model extends SPARQ_Model { function getRequestForDataDump($arr){ $pdid = isset($arr['pd_id'])?$arr['pd_id']:[]; - $fromd = $arr['from_date']; - $tod= $arr['to_date']; + $fromd = isset($arr['from_date'])?$arr['from_date']:null; + $tod= isset($arr['to_date'])?$arr['to_date']:null; $type = isset($arr['pd_type_id'])?$arr['pd_type_id']:null; $prod = isset($arr['product_id'])?$arr['product_id']:null; $cseg = isset($arr['customer_segment_id'])?$arr['customer_segment_id']:null; @@ -107,7 +107,7 @@ class Data_Dump_Model extends SPARQ_Model { } $this->db->WHERE('PDFORMDETAILSJSON.isactive',1); $this->db->order_by('PDFORMDETAILSJSON.pd_form_detail_json_id','desc'); - $this->db->limit(5); + // $this->db->limit(5); $result = $this->db->get()->result_array(); // echo count($result);print_r($result);print_r($this->db->last_query());die(); return $result; @@ -117,7 +117,10 @@ class Data_Dump_Model extends SPARQ_Model { $result['pdtype'] = $this->db->select('PDTYPE.pd_type_id,PDTYPE.type_name')->from(PDTYPE.' as PDTYPE')->WHERE('PDTYPE.isactive',1)->GET()->result_array(); $result['product'] = $this->db->select('PRODUCTS.product_id,PRODUCTS.name,PRODUCTS.abbr')->from(PRODUCTS.' as PRODUCTS')->WHERE('PRODUCTS.isactive',1)->GET()->result_array(); $result['customersegment'] = $this->db->select('CUSTOMERSEGMENT.customer_segment_id,CUSTOMERSEGMENT.name,CUSTOMERSEGMENT.abbr')->from(CUSTOMERSEGMENT.' as CUSTOMERSEGMENT')->WHERE('CUSTOMERSEGMENT.isactive',1)->GET()->result_array(); - $result['pdid'] = $this->db->select('PDTRIGGER.pd_sno,PDTRIGGER.pd_id')->from(PDTRIGGER.' as PDTRIGGER')->WHERE('PDTRIGGER.pd_status !=',"TRUNCATED")->GET()->result_array(); + $result['city'] = $this->db->select('CITY.city_id, CITY.name')->from(CITY.' as CITY')->WHERE('CITY.isactive',1)->GET()->result_array(); + $result['pdid'] = $this->db->select('PDTRIGGER.pd_sno,PDTRIGGER.pd_id,PDTRIGGER.pd_status')->from(PDTRIGGER.' as PDTRIGGER')->WHERE('PDTRIGGER.pd_status !=',"TRUNCATED")->GET()->result_array(); + $result['totalpd'] = count($result['pdid']); + $result['overallpdcount'] = count($result['pdid']); return $result; } @@ -168,4 +171,67 @@ class Data_Dump_Model extends SPARQ_Model { } // public function GsheetData($GSdata){ // } + + public function PDList($pd_type,$pd_status,$pd_from_date,$pd_to_date,$pd_city,$pd_products,$pd_lender,$pd_customer_segment) + { + + // PDTRIGGER.pd_specific_clarification, DATE_FORMAT(PDTRIGGER.createdon,"%d/%m/%Y %h:%i:%s %p") as createdon, PDTRIGGER.fk_createdby, PDTRIGGER.fk_updatedby,PDTRIGGER.fk_pd_allocation_type, PDTRIGGER.fk_pd_allocated_to,PDTRIGGER.executive_id,PDTRIGGER.central_pd_officer_id,PDTRIGGER.fk_pd_template_id, PDTRIGGER.fk_customer_segment,CUSTOMERSEGMENT.name as customer_segment_name,CUSTOMERSEGMENT.abbr as customer_segment_abbr, PDTRIGGER.pd_officier_final_judgement, PDTRIGGER.pd_agency_id, PDTRIGGER.loan_amount,PDTRIGGER.addressline1,PDTRIGGER.addressline2,PDTRIGGER.addressline3,PDTRIGGER.fk_city,CITY.name as city_name,PDTRIGGER.fk_state,STATE.name as state_name,PINCODE.pincode,PDTRIGGER.pincode as pincode_id,PDTRIGGER.lender_credit_person,PDTRIGGER.pd_contact_person,PDTRIGGER.pd_contact_mobileno,DATE_FORMAT(PDTRIGGER.scheduled_on,"%d/%m/%Y %h:%i %p") as scheduled_on,DATE_FORMAT(PDTRIGGER.completed_on,"%d/%m/%Y %h:%i:%s %p") as completed_on,PDTRIGGER.remarks,PDTRIGGER.bounce_reason,PDTRIGGER.bounce_reason_others,PDTRIGGER.is_original_report_created,PDTRIGGER.pd_report_latest_version,PDTRIGGER.pd_branch_id,PDTRIGGER.qc_feedback,PDTRIGGER.qc_rating,PDTRIGGER.qc_remarks,PDTRIGGER.lender_rating,PDTRIGGER.lender_feedback,PDTRIGGER.pd_contact_landline,PDTRIGGER.other_pincode,PDTRIGGER.is_otp_done,PDTRIGGER.otp_reject_other_reason,PDTRIGGER.encrypted_url,PDTRIGGER.is_child,PDTRIGGER.parent_pd_id,PDTRIGGER.fk_primary_address_id,PDTRIGGER.fk_address_id,PDTRIGGER.start_location,PDTRIGGER.random_string + $this->db->SELECT('PDTRIGGER.pd_id, PDTRIGGER.pd_sno,PDTRIGGER.pd_status'); + $this->db->FROM(PDTRIGGER.' as PDTRIGGER'); + $this->db->JOIN(ENTITY.' as ENTITY','PDTRIGGER.fk_lender_id = ENTITY.entity_id ','LEFT'); + $this->db->JOIN(ENTITY.' as SUBENTITY','PDTRIGGER.sub_entity_id = SUBENTITY.entity_id ','LEFT'); + $this->db->JOIN(PRODUCTS.' as PRODUCTS','PDTRIGGER.fk_product_id = PRODUCTS.product_id','LEFT'); + $this->db->JOIN(SUBPRODUCTS.' as SUBPRODUCTS','PDTRIGGER.fk_subproduct_id = SUBPRODUCTS.subproduct_id','LEFT'); + $this->db->JOIN(PDTYPE.' as PDTYPE','PDTRIGGER.fk_pd_type = PDTYPE.pd_type_id','LEFT'); + $this->db->JOIN(CUSTOMERSEGMENT.' as CUSTOMERSEGMENT','PDTRIGGER.fk_customer_segment = CUSTOMERSEGMENT.customer_segment_id','LEFT'); + $this->db->JOIN(ENTITY.' as AGENCY','PDTRIGGER.pd_agency_id = AGENCY.entity_id','LEFT'); + $this->db->JOIN(STATE.' as STATE','PDTRIGGER.fk_state = STATE.state_id ','LEFT'); + $this->db->JOIN(CITY.' as CITY','PDTRIGGER.fk_city = CITY.city_id','LEFT'); + $this->db->JOIN(PINCODE.' as PINCODE','PDTRIGGER.pincode = PINCODE.pincode_id','LEFT'); + $this->db->WHERE('PDTRIGGER.pd_status =',COMPLETED); + + + if(!empty($pd_type)) + { + $this->db->WHERE_IN('PDTRIGGER.fk_pd_type',$pd_type); + } + // if(!empty($pd_status)){ + // $this->db->WHERE_IN('PDTRIGGER.pd_status',$pd_status); + // } + if(($pd_from_date != "" || $pd_from_date != null) && ($pd_to_date != "" || $pd_to_date != null)) + { + $this->db->where('PDTRIGGER.completed_on BETWEEN ' ."'$pd_from_date'". ' AND ' ."'$pd_to_date'"); + + } + + if(!empty($pd_city)) + { + $this->db->WHERE_IN('PDTRIGGER.fk_city',$pd_city); + } + + if(!empty($pd_products)) + { + $this->db->WHERE_IN('PDTRIGGER.fk_product_id',$pd_products); + } + + if(!empty($pd_lender)) + { + $this->db->WHERE_IN('PDTRIGGER.fk_lender_id',$pd_lender); + } + else + { + $this->db->WHERE('PDTRIGGER.fk_lender_id != ',(ENVIRONMENT == 'production' ? 7 : 35)); + } + if(!empty($pd_customer_segment)) + { + $this->db->WHERE('PDTRIGGER.fk_customer_segment',$pd_customer_segment); + } + + $this->db->ORDER_BY('PDTRIGGER.pd_id','DESC'); + + + $result_array = $this->db->GET()->result_array(); + // print_r($this->db->last_query());die(); + return $result_array; + } } \ No newline at end of file