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'); $this->load->helper('camunda'); $this->external_path = $this->config->item('external_data_path'); } public function getMasterForFlyhiPD_get(){ $FHFSL_lender = (ENVIRONMENT == 'production' ? 19 : 49); $FHFSL_product = (ENVIRONMENT == 'production' ? 27 : 26); $default_product = $FHFSL_product; $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'); if(count($result_data)) { foreach($result_data as $key => $value) { $fields = array('*'); $where_condition_array = array('isactive' => 1,'fk_entity_id' => $value['entity_id']); $result_data[$key]['billing_address'] = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,ENTITYBILLING); $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); } } $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?. Create Product in Lender profile'; $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(); $lender_contact_persons = $this->Flyhi_Model->getJoinRecords($columns,$table,$joins,array('USERPROFILE.fk_entity_id' => $FHFSL_lender),$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'] = array('lender'=> $result_data,'products' =>$product,'lender_contact_persons'=>$lender_contact_persons,'default_lender' =>$FHFSL_lender,'default_product' =>$FHFSL_product); $this->response($data,REST_Controller::HTTP_OK); } public function listFlyhiPD_get(){ $user_id = $this->uri->segment(1); $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.is_pdf','SALES_PD_DATA.is_edited','ENTITY.full_name','ENTITY.short_name','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', 'SALES_PD_DATA.lender_sales_person','concat(LENDERSALESPERSON.first_name," ",LENDERSALESPERSON.last_name) as lender_sales_person_name','LENDERSALESPERSON.mobile_no as lender_sales_contact_mobileno','LENDERSALESPERSON.email as lender_sales_person_email', 'SALES_PD_DATA.lender_credit_person','concat(LENDERCREDITPERSON.first_name," ",LENDERCREDITPERSON.last_name) as lender_credit_person_name','LENDERCREDITPERSON.mobile_no as lender_credit_person_contact_mobileno','LENDERCREDITPERSON.email as lender_credit_person_email', 'SALES_PD_DATA.pd_branch_id','ENTITYLENDERBRANCH.branch_name','SALES_PD_DATA.loan_amount', '(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' => CITY. ' as CITY', 'condition' =>'SALES_PD_DATA.city_id = CITY.city_id', 'jointype' => 'LEFT'), array('table' => USERPROFILE. ' as USERPROFILE', 'condition' =>'SALES_PD_DATA.createdby = USERPROFILE.userid', 'jointype' => 'LEFT'), array('table' => USERPROFILE. ' as LENDERSALESPERSON', 'condition' =>'SALES_PD_DATA.lender_sales_person = LENDERSALESPERSON.userid', 'jointype' => 'LEFT'), array('table' => USERPROFILE. ' as LENDERCREDITPERSON', 'condition' =>'SALES_PD_DATA.lender_credit_person = LENDERCREDITPERSON.userid', 'jointype' => 'LEFT'), array('table' => ENTITYLENDERBRANCH. ' as ENTITYLENDERBRANCH', 'condition' =>'SALES_PD_DATA.pd_branch_id = ENTITYLENDERBRANCH.entity_lender_branch_id', 'jointype' => 'LEFT') ); $or_where = array(); $where_condition_array['SALES_PD_DATA.isactive'] = 1; // 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; // ----END OF FILTERING THE LAST 10 DAYS RECORDS--- $FHFSL_lender = (ENVIRONMENT == 'production' ? 19 : 49); if($user_id && is_numeric($user_id)) { $where_condition_array['SALES_PD_DATA.createdby'] = $user_id; } $where_condition_array['SALES_PD_DATA.sales_pd_type in (3,4)'] = null; $order_by = 'SALES_PD_DATA.sales_pd_id'; $Flyhi_pd_data = $this->Flyhi_Model->getJoinRecords($columns,$table,$joins,$where_condition_array,$order_by,'DESC','',$or_where); //print_r($this->db->last_query());die(); if(count($Flyhi_pd_data)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $Flyhi_pd_data; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'FlyHI PD Data Not Found! Try Later'; $this->response($data,REST_Controller::HTTP_OK); } } public function saveFlyhiPD_post() { $records = $this->post('records'); $is_entry_done = null; $flyhi_pd_id = null; $section_data = json_encode($records); $fk_createdby = isset($records['fk_createdby']) ? $records['fk_createdby'] : ""; $applicant_id = null; $applicant_name = null; $city = null; $lender_id = null; $loan_amount = null; $pd_branch_id = null; $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); log_message('ERROR','####FLYHI-PD SAVE CALLED'); // $section_names = array('1' => 'General Section','2' => 'Photography'); $section_names = array('1' => 'General Section'); 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 FLYHIPD'); if($records['questions']) { foreach ($records['questions'] as $g_key => $g_value) { if(isset($g_value['question_key']) && $g_value['question_key'] === 'loan_application_id') { $applicant_id = $g_value['answer_value'] ? $g_value['answer_value'] : 'Not Provided'; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_name') { $lender_id = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'loan_amount') { $loan_amount = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'branch') { $pd_branch_id = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_sales_person') { $lender_sales_person = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_credit_person') { $lender_credit_person = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'product_name') { $product_id = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'verification_type') { if(isset($g_value['onchange_properties'])) { foreach ($g_value['onchange_properties'] as $h_key => $h_value) { foreach ($h_value['form_controls'] as $i_key => $i_value) { foreach ($i_value['questions'] as $j_key => $j_value) { if($g_value['answer_value'] == 'Residence verification' && $j_value['question_key'] == 'residence_city'){ $city = $j_value['answer_value']; $sales_pd_type = 4; } if($g_value['answer_value'] == 'Office verification' && $j_value['question_key'] == 'officer_city'){ $city = $j_value['answer_value']; $sales_pd_type = 3; } if($g_value['answer_value'] == 'Office verification' && $j_value['question_key'] == 'employer_business_name') { $applicant_name = $j_value['answer_value']; } } } } } } } } $count = $this->Flyhi_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $lender_id,'isactive' => 1),SALES_PD_DATA); $lender_short_name = $this->Flyhi_Model->selectCustomRecords(array('short_name'),array('entity_id' => $lender_id),ENTITY); $flyhipd_serial_no = $lender_short_name[0]['short_name'].'-'.(++$count[0]['count']); $FLYHI_PD['applicant_name'] = $applicant_name; $FLYHI_PD['applicant_id'] = $applicant_id; $FLYHI_PD['city_id']=$city; $FLYHI_PD['sales_pd_sno'] = $flyhipd_serial_no; $FLYHI_PD['loan_amount'] = $loan_amount; $FLYHI_PD['lender_sales_person'] = $lender_sales_person ; $FLYHI_PD['lender_credit_person'] = $lender_credit_person ; $FLYHI_PD['pd_branch_id'] = $pd_branch_id; $FLYHI_PD['lender_id'] = $lender_id; $FLYHI_PD['createdby'] = $fk_createdby; $FLYHI_PD['rand_string'] = $randomString; $FLYHI_PD['sales_pd_type'] = $sales_pd_type; $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 )); $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); } else { if(isset($records['status']) && $records['status'] == 'COMPLETED') { log_message('ERROR','####COMPLETE FLYHI-PD'.$records['sales_pd_id']); $records['status'] = 'COMPLETED'; $records['is_cus_link_disabled'] = 1; $records['completed_date'] = date('Y-m-d H:i:s'); $flyhi_pd_id = $this->Flyhi_Model->updateRecords($records,SALES_PD_DATA,array('sales_pd_id' => $records['sales_pd_id'])); $completed_sections = $this->Flyhi_Model->selectCustomRecords(array('section_id'),array('status' => 1,'sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALESPD_SECTION_DATA); $this->prepareFlyhiPDReport($records['sales_pd_id'],false); sleep(10); log_message('ERROR','####FLYHI-PD AFTER 10 PREPARED REPORT'.$records['sales_pd_id']); } else { 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']; if($records['questions']){ foreach ($records['questions'] as $g_key => $g_value) { if(isset($g_value['question_key']) && $g_value['question_key'] === 'loan_application_id') { $applicant_id = $g_value['answer_value'] ? $g_value['answer_value'] : 'Not Provided'; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_name') { $lender_id = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'loan_amount') { $loan_amount = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'branch') { $pd_branch_id = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_sales_person') { $lender_sales_person = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_credit_person') { $lender_credit_person = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'product_name') { $product_id = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'verification_type') { if(isset($g_value['onchange_properties'])) { foreach ($g_value['onchange_properties'] as $h_key => $h_value) { foreach ($h_value['form_controls'] as $i_key => $i_value) { foreach ($i_value['questions'] as $j_key => $j_value) { if($g_value['answer_value'] == 'Residence verification' && $j_value['question_key'] == 'residence_city'){ $city = $j_value['answer_value']; $sales_pd_type = 4; } if($g_value['answer_value'] == 'Office verification' && $j_value['question_key'] == 'officer_city'){ $city = $j_value['answer_value']; $sales_pd_type = 3; } if($g_value['answer_value'] == 'Office verification' && $j_value['question_key'] == 'employer_business_name') { $applicant_name = $j_value['answer_value']; } } } } } } } } $FLYHI_PD['applicant_name'] = int($applicant_name); $FLYHI_PD['applicant_id'] = int($applicant_id); $FLYHI_PD['city_id']=int($city); $FLYHI_PD['loan_amount'] = int($loan_amount); $FLYHI_PD['lender_sales_person'] = int($lender_sales_person) ; $FLYHI_PD['lender_credit_person'] = int($lender_credit_person) ; $FLYHI_PD['pd_branch_id'] = int($pd_branch_id); $FLYHI_PD['lender_id'] = int($lender_id); $FLYHI_PD['product_id'] = int($product_id); $flyhi_pd_id = $this->Flyhi_Model->updateRecords($FLYHI_PD,SALES_PD_DATA,array('sales_pd_id' => $flyhi_pd_id)); $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); } // else 179 } // else 167 if($flyhi_pd_id) { $data['dataStatus'] = true; $data['records'] = $flyhi_pd_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 getFlyhiPD_get() { $Flyhi_pdid = $this->get('pd_id'); $section_data = array(); if(isset($Flyhi_pdid) || $Flyhi_pdid != "" || $Flyhi_pdid != null) { $section_data = $this->Flyhi_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $Flyhi_pdid,'isactive' => 1,'section_id' => 1),SALESPD_SECTION_DATA); } 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 loadFlyhiPDTemplate_post() { $records = $this->post('records'); $lender_id = $records['lender_id']; // $product = $records['product_id']; $sales_pd_type = $records['sales_pd_type'] ? $records['sales_pd_type'] : null; $product = $records['product_id']; $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); 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 getFlyhiPDReport_get() { $pd_id = $this->uri->segment(2); $this->prepareFlyhiPDReport($pd_id); } function prepareFlyhiPDReport($pd_id,$api = true) { log_message('ERROR','####PREPARE Flyhi PD REPORT CALLED'.$pd_id); $columns = array('SALES_PD_DATA.*','ENTITY.short_name','PRODUCT.name','PRODUCT.abbr','USERPROFILE.smc_emp_code'); // $columns = array('SALES_PD_DATA.*','ENTITY.short_name','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' => $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); $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-";} 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; $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)); if(!file_exists($this->external_path.'/sales_pd/'.$pd_id)) { mkdir($this->external_path.'/sales_pd/'.$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' => $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; $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']); foreach ($all_section_data as $sec_key => $section) { // print_r($section['section_id']);die(); // log_message('ERROR','####PREPARE SALESPD REPORT CALLED'.$pd_id); $view_data['section'.$section['section_id'] ] = $this->processSalesPDJSON($section);//die(); $section_fields['section'.$section['section_id'] ] = $this->processSalesPDJSON($section); } $view_data['geo_location'] = $sales_pd_data[0]['geo_location']; // die(); //$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); $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"; $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/'.$pd_id.'/temp.pdf'); log_message('ERROR','####FLYHIPD REPORT UPLOAD TO S3'.$pd_id); $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' => $pd_id)); if($api) { $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); $headers = @get_headers($_uri); if($headers && strpos( $headers[0], '200')) { // $singed_uri = $_uri; $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $_uri; }else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'Report URI Not Found'; } $this->response($data,REST_Controller::HTTP_OK); } } } else { if($api) { ## NEW KEY BECAUSE TITLE-RENAME $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); $headers = @get_headers($_uri); if($headers && strpos( $headers[0], '200')) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $_uri; }else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'Report URI Not Found'; } $this->response($data,REST_Controller::HTTP_OK); } } } } function processSalesPDJSON($section_array) { if($section_array['section_id']) { $questions = json_decode($section_array['section_data'],true); return $this->processSalesPDQuestions($questions['questions'],$section_array['section_id']); } } 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'] == 'residence_state' || $question['question_key'] == 'residence_city' || $question['question_key'] == 'residence_pincode' || $question['question_key'] == 'business_state'|| $question['question_key'] == 'business_city'|| $question['question_key'] == 'business_pincode' || $question['question_key'] == 'permanent_state' || $question['question_key'] == 'permanent_city' || $question['question_key'] == 'permanent_pincode' || $question['question_key'] == 'officer_state' || $question['question_key'] == 'officer_city' || $question['question_key'] == 'officer_pincode') // $question['question_key'] == 'employer_business_state' || $question['question_key'] == 'employer_business_address_city' || $question['question_key'] == 'employer_business_pincode' || // $question['question_key'] == 'educational_institute_state' || $question['question_key'] == 'educational_institute_address_city' || $question['question_key'] == 'educational_institute_pincode' // ) { //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; } } }// Class Ends