From f2d7f61feced63a60110f2f9f89be8bfc919ef4a Mon Sep 17 00:00:00 2001 From: Velz2020 Date: Mon, 1 Feb 2021 00:31:11 +0530 Subject: [PATCH] WATER MARK --- .../config/api_user_auth_config.php | 2 +- api/application/config/hooks.php | 7 + api/application/config/routes.php | 1 + api/application/controllers/PD_Controller.php | 31 +- .../controllers/SMC_Credit_PD_Controller.php | 3 +- .../helpers/photo_pdf_converter_helper.php | 4 +- .../helpers/photo_zip_creator_helper.php | 4 +- api/application/helpers/watermark_helper.php | 1933 +++++++++++++++++ api/application/hooks/waterMarkHook.php | 20 + api/application/models/PD_Model.php | 11 +- .../views/smc_creditpd_reports/MWISE.php | 36 +- 11 files changed, 2028 insertions(+), 24 deletions(-) create mode 100644 api/application/helpers/watermark_helper.php create mode 100644 api/application/hooks/waterMarkHook.php diff --git a/api/application/config/api_user_auth_config.php b/api/application/config/api_user_auth_config.php index 0c06cfac..56188f73 100644 --- a/api/application/config/api_user_auth_config.php +++ b/api/application/config/api_user_auth_config.php @@ -36,7 +36,7 @@ $config['api_user_auth_info'] = array( //'updatePDMaster' => array(1,2,3,10,11,12,13,1,15,16,17,18,19,20), 'updatePDDocs' => array(1,2,3,10,11,12,13,1,15,16,17,18,19,20), 'updatePDApplicants' => array(1,2,3,10,11,12,13,1,15,16,17,18,19,20), -'allocatePD' => array(2,3,4,5,10,21,22,25,26), +'allocatePD' => array(2,3,4,5,10,21,22,25,26,20), 'schdulePD' => array(2,3,4,5,21,10,22,21), 'generatePDReport' => array(3,6,7,10), 'savePDPhotos' => array(3,4,5,6,7,10,21,22), diff --git a/api/application/config/hooks.php b/api/application/config/hooks.php index cdebd58a..e0c7c8b8 100644 --- a/api/application/config/hooks.php +++ b/api/application/config/hooks.php @@ -24,3 +24,10 @@ $hook['pre_controller'][] = array( 'filename' => 'ExceptionHook.php', 'filepath' => 'hooks' ); + +$hook['post_system'][] = array( + 'class' => 'waterMarkHook', + 'function' => 'initializeWaterMarkProcess', + 'filename' => 'waterMarkHook.php', + 'filepath' => 'hooks' + ); diff --git a/api/application/config/routes.php b/api/application/config/routes.php index dab459e3..4d44af8c 100644 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -238,6 +238,7 @@ $route['saveApplicantImgFromVendorForm'] = 'PD_Controller/saveApplicantImgFromVe $route['loadCreditPDTemplate'] = 'PD_Controller/loadCreditPDTemplate'; $route['saveRoomInfo'] = 'PD_Controller/saveRoomInfo'; $route['updateTwlioVideoStatus'] = 'PD_Controller/updateTwlioVideoStatus'; +$route['checkAfterResponse'] = 'PD_Controller/checkAfterResponse'; // $route['getPDFormDetailsJSON'] = 'PD_Controller/getPDFormDetailsJSON'; $route['smartyTestFunction'] = 'PD_Controller/smartyTestFunction'; diff --git a/api/application/controllers/PD_Controller.php b/api/application/controllers/PD_Controller.php index 8cdb40f5..4da6f4c4 100644 --- a/api/application/controllers/PD_Controller.php +++ b/api/application/controllers/PD_Controller.php @@ -5085,8 +5085,9 @@ public function getPDFormDetailsJSON_post() $records = $this->post('records'); $pdid = $records['pd_id']; $random_string = $records['random_string']; + $regenerate = isset($records['regenerate']) ? $records['regenerate'] : 0; $this->load->helper('photo_zip_creator'); - $res_data = (new photo_zip_creator)->covertImgs2ZIP($pdid,$random_string); + $res_data = (new photo_zip_creator)->covertImgs2ZIP($pdid,$random_string,array(),$regenerate); $response_data['dataStatus'] = true; $response_data['status'] = REST_Controller::HTTP_OK; @@ -5105,7 +5106,9 @@ public function getPDFormDetailsJSON_post() $pdid = $records['pd_id']; $random_string = $records['random_string']; - $res_data = (new photo_pdf_converter)->covertImgs2PDF($pdid,$random_string); + $regenerate = isset($records['regenerate']) ? $records['regenerate'] : 0; + + $res_data = (new photo_pdf_converter)->covertImgs2PDF($pdid,$random_string,array(),$regenerate); $response_data['dataStatus'] = true; @@ -7359,7 +7362,7 @@ public function getCompaniesListsFromGeneralFormRawJSON_post() $data['records'] = $res['count']; $data['uri'] = $res['records']; $data['msg'] = $res['msg']; - $this->response($data,REST_Controller::HTTP_OK); + $this->response($data,REST_Controller::HTTP_OK,true); } else { @@ -7406,6 +7409,10 @@ public function getCompaniesListsFromGeneralFormRawJSON_post() EXTERNAL_DIR_CHECK::checkExternalDirectory($pd_id); foreach($data as $iter => $doc) { + //make location for water mark helper function + $this->location_for_watermark = $doc['link']; + + $temp_base64_string = $doc['image']; $title = $doc['Name']; $is_show_report = isset($doc['is_show_report']) ? $doc['is_show_report'] : null; @@ -7418,7 +7425,7 @@ public function getCompaniesListsFromGeneralFormRawJSON_post() $co_applicant_id = isset($doc['co_applicant_id']) ? $doc['co_applicant_id'] : null; $img_type = isset($doc['img_type']) ? $doc['img_type'] : null; $output_file = $this->external_path."/pd_reports/". $pd_id ."/temp_base64_image.jpeg"; - + $this->temp_path_for_watermark = $output_file; //Generate Random File Name $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; @@ -7476,6 +7483,9 @@ public function getCompaniesListsFromGeneralFormRawJSON_post() $sourcefile = $tempdoc; $bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile); + + //this line make this bucket data values in obj level so can access in helpers and hook files + $this->bucket_data_for_watermark = $bucket_data; $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) @@ -7486,6 +7496,8 @@ public function getCompaniesListsFromGeneralFormRawJSON_post() $id = $this->PD_Model->saveRecords($record_data,PDDOCUMENTS); if($id != null || $id != "") { $count++; $pks[] = $id;} $uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,$time = '+1 week'); + + $this->img_url_for_watermark = $uri; //print_r($uri); } @@ -10975,6 +10987,17 @@ public function getCompaniesListsFromGeneralFormRawJSON_post() $this->response($data,REST_Controller::HTTP_OK); } } + + + public function checkAfterResponse_post() + { + $this->myvariable = 10; + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NOT_FOUND; + $data['msg'] = 'No Data File Found!'; + $this->response($data,REST_Controller::HTTP_OK,true); + // echo 'Hi'; + } diff --git a/api/application/controllers/SMC_Credit_PD_Controller.php b/api/application/controllers/SMC_Credit_PD_Controller.php index a89106df..cc32e0fd 100644 --- a/api/application/controllers/SMC_Credit_PD_Controller.php +++ b/api/application/controllers/SMC_Credit_PD_Controller.php @@ -1481,7 +1481,8 @@ public function filterSalesPDList_post() { //score card part $score_card_questions = $this->seperateScorecardQuestions($view_data); $view_data['pd_score'] = SMCPDSCORE::genericDIPDScoreCalculate($score_card_questions,$view_data['pd_master_details']); - $final_score = $view_data['pd_score']['score_summary']['overall_score']['final_score']; + $final_score = round($view_data['pd_score']['score_summary']['overall_score']['final_score'],1); + // echo $final_score;die(); //GET phantom script from DB $phantom_script = $this->PD_Model->selectCustomRecords(array('*'),array('script_name' => PHANTOMJSSCRIPT_LOCATION),SCRIPTS); diff --git a/api/application/helpers/photo_pdf_converter_helper.php b/api/application/helpers/photo_pdf_converter_helper.php index b7e869e5..ebf5cd9f 100644 --- a/api/application/helpers/photo_pdf_converter_helper.php +++ b/api/application/helpers/photo_pdf_converter_helper.php @@ -8,7 +8,7 @@ class photo_pdf_converter //$CI =&get_instance(); } - public function covertImgs2PDF($pdid,$random_string,$pd_master_details = array()) + public function covertImgs2PDF($pdid,$random_string,$pd_master_details = array(),$regenerate = 0) { //echo 'this is from daiu'; $CI =&get_instance(); @@ -33,7 +33,7 @@ class photo_pdf_converter $key = 'pd'.$pdid.'/'.$main_applicant_name.'_'.$pdid.'_'.'pd_images.pdf'; //$singed_uri = $CI->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+30 minutes'); - if($pd_master_details[0]['is_img_pdf_created']) + if($pd_master_details[0]['is_img_pdf_created'] && ($regenerate == 0)) { return $singed_uri = $CI->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+7 days'); diff --git a/api/application/helpers/photo_zip_creator_helper.php b/api/application/helpers/photo_zip_creator_helper.php index 94e4747c..37dcaf61 100644 --- a/api/application/helpers/photo_zip_creator_helper.php +++ b/api/application/helpers/photo_zip_creator_helper.php @@ -8,7 +8,7 @@ class photo_zip_creator //$CI =&get_instance(); } - public function covertImgs2ZIP($pdid,$random_string,$pd_master_details = array()) + public function covertImgs2ZIP($pdid,$random_string,$pd_master_details = array(),$regenerate = 0) { //echo 'this is from daiu'; $CI =&get_instance(); @@ -33,7 +33,7 @@ class photo_zip_creator $key = 'pd'.$pdid.'/'.$main_applicant_name.'_'.$pdid.'_'.'pd_images.zip'; //$singed_uri = $CI->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+30 minutes'); - if($pd_master_details[0]['is_zip_created']) + if($pd_master_details[0]['is_zip_created'] && ($regenerate == 0)) { return $singed_uri = $CI->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+30 minutes'); diff --git a/api/application/helpers/watermark_helper.php b/api/application/helpers/watermark_helper.php new file mode 100644 index 00000000..2521f893 --- /dev/null +++ b/api/application/helpers/watermark_helper.php @@ -0,0 +1,1933 @@ +img_url_for_watermark; + $output_file = $CI->temp_path_for_watermark; + $bucket_data = $CI->bucket_data_for_watermark; + $location_watermarktext = "Location: " . $CI->location_for_watermark; + + // ################### start img water marking with text + + + $imagetobewatermark = imagecreatefromstring(file_get_contents($sourceFilePath)); + // $location_watermarktext="Location: ".$doc['link']; + // $location_watermarktext="Location: 9876543210"; + $font = APPPATH."docs/roboto.ttf"; //metion font and it's location + $fontsize="8"; + $x = imagesx($imagetobewatermark); + $y = imagesy($imagetobewatermark); + + $water_mark_text_color = imagecolorallocate($imagetobewatermark, 225, 0, 0); + imagettftext($imagetobewatermark, $fontsize, 0, 70, ($y - 15), $water_mark_text_color, $font, $location_watermarktext); + + imagettftext($imagetobewatermark, $fontsize, 0, 70, ($y - 5), $water_mark_text_color, $font, 'Date: '.date('Y-m-d h:i:s a')); + imagepng($imagetobewatermark,$output_file,9);//save as png file in ouputfile location + // //################# end img water marking with text + + + //###########image water marking with logo + $pd_logo = imagecreatefromstring(file_get_contents(APPPATH.'docs/icon.png')); + $curret_file = imagecreatefromstring(file_get_contents($output_file)); + $sx = imagesx($curret_file); + $sy = imagesy($curret_file); + // imagecopyresized ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h ) : bool + imagecopyresampled ( $curret_file , $pd_logo ,5, ($sy - 54) , 0 , 0 , 50 , 50 , 50 , 54 ); + + imagepng($curret_file,$output_file,9);// save png image in specified location + // //###########end of image water marking with logo + sleep(1); + //uploading watremarked file into s3 bucket + $s3resul = $CI->aws_s3->uploadFileToS3Bucket($bucket_data); + } + + + + + + /*****************########## BANKING INFO DETAILS FORM ##########**************/ + public static function convertBankingInfoDetailsForm($raw_json,$formid) + { + $CI =& get_instance(); + $master_tables_field_names = $CI->config->item('master_tables_field_names'); + $master_tables_pkid = $CI->config->item('master_tables_pkid'); + + //print_r($raw_json); + + // GET KEYS FROM MASTER TABLE FOR SUPPLIER FORM + $fields = array('question', 'key', 'ismaster', 'master_name'); + $where_condition_array = array('fk_form_id' => $formid,'isactive' => 1); + $master_keys = $CI->PD_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONKEYMAPPING); + + //print_r($master_keys); + if(!empty($raw_json) && !empty($master_keys)) + { + foreach($raw_json['banking_details'] as $bank_key => $bank_info) + { + + foreach($bank_info as $key => $value) + { + if($value != "" || $value != null) + { + //compare with master_keys array + foreach($master_keys as $master_key => $master_value) + { + if(!strcmp($key,$master_value['key']) && $master_value['ismaster'] == 1) + { + //print_r($key);echo "\n\n"; + //GET MASASTER DATA + + $table = constant($master_value['master_name']); + + $temp_fields = array($master_tables_field_names[$master_value['master_name']].' as name'); + + $where_condition_array = array($master_tables_pkid[$master_value['master_name']] => $value); + if($key == 'applicant_name') + { + $where_condition_array = array($master_tables_pkid[$master_value['master_name']] => $value['id']); + } + $result_data = $CI->PD_Model->selectCustomRecords($temp_fields,$where_condition_array,$table); + if(count($result_data)) + { + //print_r($result_data[0]['name']); + $key = $key . '_master'; + $raw_json['banking_details'][$bank_key][$key] = $result_data[0]['name']; + + } + } + } + } + } + + + // print_r($loan); + } + } + + return ($raw_json); + } + /*****************########## END BANKING INFO DETAILS FORM ##########**************/ + + + + /*****************########## LOAN DETAILS FORM ##########**************/ + public static function convertLoanDetailsForm($raw_json,$formid) + { + $CI =& get_instance(); + $master_tables_field_names = $CI->config->item('master_tables_field_names'); + $master_tables_pkid = $CI->config->item('master_tables_pkid'); + + //print_r($raw_json);die(); + + // GET KEYS FROM MASTER TABLE FOR SUPPLIER FORM + $fields = array('question', 'key', 'ismaster', 'master_name'); + $where_condition_array = array('fk_form_id' => $formid,'isactive' => 1); + $master_keys = $CI->PD_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONKEYMAPPING); + + //print_r($master_keys); + if(!empty($raw_json) && !empty($master_keys)) + { + $end_use_master = array(); + foreach($raw_json['end_use_group'] as $end_use_key => $end_use) + { + + + $CI->db->SELECT( $master_tables_field_names['ENDUSEOFLOAN'] ); + $CI->db->FROM(ENDUSEOFLOAN); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['ENDUSEOFLOAN'] ,$end_use['end_use']); + $enduse= $CI->db->GET()->result_array(); + if(count($enduse)) + { + $end_use_master = array_merge($end_use_master,array($enduse[0][$master_tables_field_names['ENDUSEOFLOAN']])); + } + } + $raw_json['end_use_master'] = $end_use_master; + + if(array_key_exists('end_use_topup',$raw_json)) + { + $CI->db->SELECT( $master_tables_field_names['ENDUSEOFTOPUP'] ); + $CI->db->FROM(ENDUSEOFTOPUP); + $CI->db->WHERE('is_active',1); + $CI->db->WHERE( $master_tables_pkid['ENDUSEOFTOPUP'] ,$raw_json['end_use_topup']); + $end_use_topup = $CI->db->GET()->result_array(); + if(count($end_use_topup)) + { + $raw_json['end_use_topup_master'] = $end_use_topup[0][ $master_tables_field_names['ENDUSEOFTOPUP'] ]; + } + } + + if(array_key_exists('construction_status',$raw_json)) + { + $CI->db->SELECT( $master_tables_field_names['STATUSOFCONSTRUCTION'] ); + $CI->db->FROM(STATUSOFCONSTRUCTION); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['STATUSOFCONSTRUCTION'] ,$raw_json['construction_status']); + $status_of_construction = $CI->db->GET()->result_array(); + if(count($status_of_construction)) + { + $raw_json['construction_status_master'] = $status_of_construction[0][ $master_tables_field_names['STATUSOFCONSTRUCTION'] ]; + } + } + + + if(array_key_exists('lender',$raw_json)) + { + $CI->db->SELECT( $master_tables_field_names['BTLENDERLIST'] ); + $CI->db->FROM(BTLENDERLIST); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['BTLENDERLIST'] ,$raw_json['lender']); + $btlender = $CI->db->GET()->result_array(); + if(count($btlender)) + { + $raw_json['lender_master'] = $btlender[0][ $master_tables_field_names['BTLENDERLIST'] ]; + } + } + + if(array_key_exists('property_type',$raw_json)) + { + $CI->db->SELECT( $master_tables_field_names['MORTAGEPROPERTIES'] ); + $CI->db->FROM(MORTAGEPROPERTIES); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['MORTAGEPROPERTIES'],$raw_json['property_type']); + $mortage_property_type = $CI->db->GET()->result_array(); + if(count($mortage_property_type)) + { + $raw_json['property_type_master'] = $mortage_property_type[0][ $master_tables_field_names['MORTAGEPROPERTIES'] ]; + } + } + + + if(array_key_exists('source_group',$raw_json)) + { + + if($raw_json['source_group'] != "" || $raw_json['source_group'] != null) + { + $source_of_own_contribution_master = array(); + foreach($raw_json['source_group'] as $source_group_key => $source_group) + { + + + $CI->db->SELECT( $master_tables_field_names['SOURCEOFBALANCETRANSFER'] ); + $CI->db->FROM(SOURCEOFBALANCETRANSFER); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['SOURCEOFBALANCETRANSFER'] ,$source_group['sources']); + $source_of_own_contribution= $CI->db->GET()->result_array(); + if(count($source_of_own_contribution)) + { + $source_of_own_contribution_master = array_merge($source_of_own_contribution_master,array($source_of_own_contribution[0][$master_tables_field_names['SOURCEOFBALANCETRANSFER']])); + } + } + $raw_json['source_of_own_contribution_master'] = $source_of_own_contribution_master; + } + + } + + $owners_list_master = array(); + + if($raw_json['owner_name_group'] != null) + { + foreach($raw_json['owner_name_group'] as $owner_name_group_key => $owner_name_group) + { + + //print_r($owner_name_group);die(); + $CI->db->SELECT( $master_tables_field_names['PDAPPLICANTSDETAILS'] ); + $CI->db->FROM(PDAPPLICANTSDETAILS); + //$CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['PDAPPLICANTSDETAILS'] ,$owner_name_group['owner_name']['id']); + $owners_list= $CI->db->GET()->result_array(); + //print_r($owners_list); + if(count($owners_list)) + { + $owners_list_master = array_merge($owners_list_master,array($owners_list[0][$master_tables_field_names['PDAPPLICANTSDETAILS']])); + } + } + } + + if(array_key_exists('state',$raw_json)) + { + //print_r($address); + $CI->db->SELECT( $master_tables_field_names['STATE'] ); + $CI->db->FROM(STATE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['STATE'] ,$raw_json['state']); + $adress_type_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($adress_type_name)) + { + $raw_json['state_master'] = $adress_type_name[0][$master_tables_field_names['STATE']]; + } + } + + if(array_key_exists('city',$raw_json)) + { + //print_r($address); + $CI->db->SELECT( $master_tables_field_names['CITY'] ); + $CI->db->FROM(CITY); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['CITY'] ,$raw_json['city']); + $city= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($city)) + { + $raw_json['city_master'] = $city[0][$master_tables_field_names['CITY']]; + } + } + + if(array_key_exists('pincode',$raw_json)) + { + //print_r($address); + $CI->db->SELECT( $master_tables_field_names['PINCODE'] ); + $CI->db->FROM(PINCODE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['PINCODE'] ,$raw_json['pincode']); + $pincode= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($pincode)) + { + $raw_json['pincode_master'] = $pincode[0][$master_tables_field_names['PINCODE']]; + } + } + + + + + $raw_json['owners_list_master'] = $owners_list_master; + } + + return $raw_json; + } + /*****************########## END LOAN DETAILS FORM ##########**************/ + + + /*****************########## OTHER INCOME DETAILS FORM ##########**************/ + public static function convertOtherIncomeDetailsForm($raw_json,$formid) + { + $CI =& get_instance(); + $master_tables_field_names = $CI->config->item('master_tables_field_names'); + $master_tables_pkid = $CI->config->item('master_tables_pkid'); + + //print_r($raw_json); + + // GET KEYS FROM MASTER TABLE FOR SUPPLIER FORM + $fields = array('question', 'key', 'ismaster', 'master_name'); + $where_condition_array = array('fk_form_id' => $formid,'isactive' => 1); + $master_keys = $CI->PD_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONKEYMAPPING); + + //print_r($master_keys); + if(!empty($raw_json) && !empty($master_keys)) + { + if(!strcmp(strtolower($raw_json['other_income']),'yes')) + { + foreach($raw_json['income_details'] as $income_details_key => $income_details) + { + + foreach($income_details as $key => $value) + { + if($value != "" || $value != null) + { + //compare with master_keys array + foreach($master_keys as $master_key => $master_value) + { + if(!strcmp($key,$master_value['key']) && $master_value['ismaster'] == 1) + { + //print_r($key);echo "\n\n"; + //GET MASASTER DATA + + $table = constant($master_value['master_name']); + + $temp_fields = array($master_tables_field_names[$master_value['master_name']].' as name'); + + $where_condition_array = array($master_tables_pkid[$master_value['master_name']] => $value); + + $result_data = $CI->PD_Model->selectCustomRecords($temp_fields,$where_condition_array,$table); + if(count($result_data)) + { + //print_r($result_data[0]['name']); + $key = $key . '_master'; + $raw_json['income_details'][$income_details_key][$key] = $result_data[0]['name']; + + } + } + } + } + } + + + // print_r($loan); + } + } + } + + return $raw_json; + } + /*****************########## END OTHER INCOME DETAILS FORM ##########**************/ + + + /*****************########## STOCK DETAILS FORM ##########**************/ + public static function convertStockDetailsForm($raw_json,$formid) + { + $CI =& get_instance(); + $master_tables_field_names = $CI->config->item('master_tables_field_names'); + $master_tables_pkid = $CI->config->item('master_tables_pkid'); + + //print_r($raw_json); + + // GET KEYS FROM MASTER TABLE FOR SUPPLIER FORM + $fields = array('question', 'key', 'ismaster', 'master_name'); + $where_condition_array = array('fk_form_id' => $formid,'isactive' => 1); + $master_keys = $CI->PD_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONKEYMAPPING); + + //print_r($master_keys); + if(!empty($raw_json) && !empty($master_keys)) + { + if(array_key_exists('manufacturing_details',$raw_json)) + { + foreach($raw_json['manufacturing_details'] as $main_key =>$manufacturing_details) + { + if($manufacturing_details != "" || $manufacturing_details != null){ + foreach($manufacturing_details as $second_key => $details) + { + if(is_array($details)) + { + foreach($details as $key => $value) + { + $uom_name = null; + $uom_name = isset($value['raw_uom']) ? 'raw_uom':(isset($value['goods_uom']) ? 'goods_uom' : null); + $uom_value = isset($value['raw_uom']) ? $value['raw_uom']:(isset($value['goods_uom']) ? $value['goods_uom'] : null); + + $CI->db->SELECT( $master_tables_field_names['UOM'] ); + $CI->db->FROM(UOM); + $CI->db->WHERE( $master_tables_pkid['UOM'],$uom_value); + $uom= $CI->db->GET()->result_array(); + + if(count($uom)) + { + $uom_master = $uom[0][ $master_tables_field_names['UOM'] ]; + $raw_json['manufacturing_details'][$main_key][$second_key][$key]['uom_master'] = $uom_master; + } + } + } + } + } + } + } + //************* + if(array_key_exists('retail_details',$raw_json)) + { + foreach($raw_json['retail_details'] as $main_key =>$retail_details) + { + if($retail_details != "" || $retail_details != null){ + foreach($retail_details as $second_key => $details) + { + if(is_array($details)) + { + foreach($details as $key => $value) + { + $CI->db->SELECT( $master_tables_field_names['UOM'] ); + $CI->db->FROM(UOM); + $CI->db->WHERE( $master_tables_pkid['UOM'],$value['traded_goods_uom']); + $uom= $CI->db->GET()->result_array(); + + if(count($uom)) + { + $uom_master = $uom[0][ $master_tables_field_names['UOM'] ]; + $raw_json['retail_details'][$main_key][$second_key][$key]['uom_master'] = $uom_master; + } + } + } + } + } + } + } + + //************* + if(array_key_exists('trade_details',$raw_json)) + { + foreach($raw_json['trade_details'] as $main_key =>$trade_details) + { + if($retail_details != "" || $retail_details != null){ + foreach($trade_details as $second_key => $details) + { + if(is_array($details)) + { + foreach($details as $key => $value) + { + $CI->db->SELECT( $master_tables_field_names['UOM'] ); + $CI->db->FROM(UOM); + $CI->db->WHERE( $master_tables_pkid['UOM'],$value['traded_goods_uom']); + $uom= $CI->db->GET()->result_array(); + + if(count($uom)) + { + $uom_master = $uom[0][ $master_tables_field_names['UOM'] ]; + $raw_json['trade_details'][$main_key][$second_key][$key]['uom_master'] = $uom_master; + } + } + } + } + } + } + } + + //************* + if(array_key_exists('servicing_details',$raw_json)) + { + foreach($raw_json['servicing_details'] as $main_key =>$servicing_details) + { + if($servicing_details != "" || $servicing_details != null){ + foreach($servicing_details as $second_key => $details) + { + if(is_array($details)) + { + foreach($details as $key => $value) + { + $CI->db->SELECT( $master_tables_field_names['UOM'] ); + $CI->db->FROM(UOM); + $CI->db->WHERE( $master_tables_pkid['UOM'],$value['service_provider_uom']); + $uom= $CI->db->GET()->result_array(); + + if(count($uom)) + { + $uom_master = $uom[0][ $master_tables_field_names['UOM'] ]; + $raw_json['servicing_details'][$main_key][$second_key][$key]['uom_master'] = $uom_master; + } + } + } + } + } + } + } + } + + + return $raw_json; + + } + /*****************########## END STOCK DETAILS FORM ##########**************/ + + + /*****************########## NEIGHBOURHOOD DETAILS FORM ##########**************/ + public static function convertNeighbourDetailsForm($raw_json,$formid) + { + + $CI =& get_instance(); + $master_tables_field_names = $CI->config->item('master_tables_field_names'); + $master_tables_pkid = $CI->config->item('master_tables_pkid'); + + //print_r($raw_json); + + // GET KEYS FROM MASTER TABLE FOR SUPPLIER FORM + $fields = array('question', 'key', 'ismaster', 'master_name'); + $where_condition_array = array('fk_form_id' => $formid,'isactive' => 1); + $master_keys = $CI->PD_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONKEYMAPPING); + + //print_r($master_keys); + if(!empty($raw_json) && !empty($master_keys)) + { + + if(array_key_exists('referencecheck_list',$raw_json)) + { + foreach($raw_json['referencecheck_list'] as $referencecheck_list_key => $referencecheck_list) + { + + foreach($referencecheck_list as $key => $value) + { + if($value != "" || $value != null) + { + //compare with master_keys array + foreach($master_keys as $master_key => $master_value) + { + if(!strcmp($key,$master_value['key']) && $master_value['ismaster'] == 1) + { + //print_r($key);echo "\n\n"; + //GET MASASTER DATA + + $table = constant($master_value['master_name']); + + $temp_fields = array($master_tables_field_names[$master_value['master_name']].' as name'); + + $where_condition_array = array($master_tables_pkid[$master_value['master_name']] => $value); + + $result_data = $CI->PD_Model->selectCustomRecords($temp_fields,$where_condition_array,$table); + if(count($result_data)) + { + //print_r($result_data[0]['name']); + $key = $key . '_master'; + $raw_json['referencecheck_list'][$referencecheck_list_key][$key] = $result_data[0]['name']; + + } + } + } + } + } + + + // print_r($loan); + } + } + } + + return $raw_json; + } + /*****************########## END NEIGHBOURHOOD DETAILS FORM ##########**************/ + + + + /*****************########## OTHER FAMILY DETAILS FORM ##########**************/ + public static function convertOtherFamilyDetailsForm($raw_json,$formid) + { + + $CI =& get_instance(); + $master_tables_field_names = $CI->config->item('master_tables_field_names'); + $master_tables_pkid = $CI->config->item('master_tables_pkid'); + + //print_r($raw_json); + + // GET KEYS FROM MASTER TABLE FOR SUPPLIER FORM + $fields = array('question', 'key', 'ismaster', 'master_name'); + $where_condition_array = array('fk_form_id' => $formid,'isactive' => 1); + $master_keys = $CI->PD_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONKEYMAPPING); + + //print_r($master_keys);die(); + if(!empty($raw_json) && !empty($master_keys)) + { + + if(array_key_exists('family_details',$raw_json)) + { + foreach($raw_json['family_details'] as $family_details_key => $family_details) + { + //print_r($selected_person); + + + if(array_key_exists('selected_person',$family_details)) + { + $CI->db->SELECT( 'PDAPPLICANTSDETAILS.applicant_name,TITLES.name' ); + $CI->db->FROM(PDAPPLICANTSDETAILS.' as PDAPPLICANTSDETAILS'); + $CI->db->JOIN(TITLES.' as TITLES','PDAPPLICANTSDETAILS.applicant_title_name = TITLES.title_id','LEFT'); + $CI->db->WHERE( $master_tables_pkid['PDAPPLICANTSDETAILS'] ,$family_details['selected_person']); + $owner= $CI->db->GET()->result_array(); + // print_r($CI->db->last_query());die(); + // print_r($owner); + if(count($owner)) + { + $selected_person_master = $owner[0][$master_tables_field_names['PDAPPLICANTSDETAILS']]; + $selected_person_title_master = $owner[0]['name']; + $raw_json['family_details'][$family_details_key]['selected_person_master'] = $selected_person_master; + $raw_json['family_details'][$family_details_key]['selected_person_title_master'] = $selected_person_title_master; + + } + } + + if(array_key_exists('residence_city',$family_details)) + { + $CI->db->SELECT( $master_tables_field_names['CITY'] ); + $CI->db->FROM(CITY); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['CITY'] ,$family_details['residence_city']); + $city= $CI->db->GET()->result_array(); + if(count($city)) + { + $city_master = $city[0][$master_tables_field_names['CITY']]; + $raw_json['family_details'][$family_details_key]['residence_city_master'] = $city_master; + + } + } + + if(array_key_exists('residence_state',$family_details)) + { + $CI->db->SELECT( $master_tables_field_names['STATE'] ); + $CI->db->FROM(STATE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['STATE'] ,$family_details['residence_state']); + $state= $CI->db->GET()->result_array(); + if(count($state)) + { + $state_master = $state[0][$master_tables_field_names['STATE']]; + $raw_json['family_details'][$family_details_key]['residence_state_master'] = $state_master; + + } + } + + if(array_key_exists('residence_pin',$family_details)) + { + $CI->db->SELECT( $master_tables_field_names['PINCODE'] ); + $CI->db->FROM(PINCODE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['PINCODE'] ,$family_details['residence_pin']); + $pincode= $CI->db->GET()->result_array(); + if(count($pincode)) + { + $pincodee_master = $pincode[0][$master_tables_field_names['PINCODE']]; + $raw_json['family_details'][$family_details_key]['residence_pincode_master'] = $pincodee_master; + + } + } + + + if(array_key_exists('residence_ownership',$family_details)) + { + $CI->db->SELECT( $master_tables_field_names['RESIDENCEOWNERSHIP'] ); + $CI->db->FROM(RESIDENCEOWNERSHIP); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['RESIDENCEOWNERSHIP'] ,$family_details['residence_ownership']); + $residence_owner= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($residence_owner)) + { + $residence_ownership_master = $residence_owner[0][$master_tables_field_names['RESIDENCEOWNERSHIP']]; + $raw_json['family_details'][$family_details_key]['residence_ownership_master'] = $residence_ownership_master; + + } + } + + + if(array_key_exists('family_members_details',$family_details)) + { + foreach($family_details['family_members_details'] as $family_members_details_key => $family_members_details) + { + + //print_r($family_members_details); + foreach($family_members_details as $key => $value) + { + + if($value != "" || $value != null) + { + //compare with master_keys array + foreach($master_keys as $master_key => $master_value) + { + if(!strcmp($key,$master_value['key']) && $master_value['ismaster'] == 1) + { + //print_r($key);echo "\n\n"; + //GET MASASTER DATA + + $table = constant($master_value['master_name']); + + $temp_fields = array($master_tables_field_names[$master_value['master_name']].' as name'); + + $where_condition_array = array($master_tables_pkid[$master_value['master_name']] => $value); + + $result_data = $CI->PD_Model->selectCustomRecords($temp_fields,$where_condition_array,$table); + if(count($result_data)) + { + //print_r($result_data[0]['name']); + $key = $key . '_master'; + $raw_json['family_details'][$family_details_key]['family_members_details'][$family_members_details_key][$key] = $result_data[0]['name']; + + } + } + } + } + } + } + + } + + + // print_r($loan); + } + } + } + + return ($raw_json); + } + /*****************########## END OTHER FAMILY DETAILS FORM ##########**************/ + + + /*****************########## BUSINESS FORM DETAILS ##########**************/ + public static function convertBusinessDetailsForm($raw_json,$master,$company_data) + { + + //print_r($raw_json); + //die(); + + if(!empty($raw_json)) + { + + //get single items + $single_business_items = array(); + + $single_business_items['pd_id'] = $master[0]['pd_id']; + $single_business_items['lender_sno'] = $master[0]['pd_sno']; + $single_business_items['company_name'] = SELF::getCompanyName($raw_json['company_id'],$company_data); + $single_business_items['seasonality'] = $raw_json['seasonality']; + $single_business_items['employees_total'] = $raw_json['employees_total']; + $single_business_items['employees_permanent'] = $raw_json['employees_permanent']; + $single_business_items['employees_temporary'] = $raw_json['employees_temporary']; + $single_business_items['employees_appx_salary'] = $raw_json['employees_appx_salary']; + $single_business_items['name_board_sighted'] = $raw_json['was_the_company_name_board_sighted']; + $single_business_items['employees_pdofficer'] = $raw_json['officer_total']; + $single_business_items['shop_eat_act_cert'] = $raw_json['shop_eat_act_cert']; + $single_business_items['gst_Regn_cert'] = $raw_json['gst_Regn_cert']; + $single_business_items['pf_regn'] = $raw_json['pf_regn']; + $single_business_items['esic_regn'] = $raw_json['esic_regn']; + $single_business_items['shop_eat_act_cert'] = $raw_json['shop_eat_act_cert']; + $single_business_items['export_import_cert'] = isset($raw_json['export_import_cert']) ? $raw_json['export_import_cert'] : null; + $single_business_items['factory_cert'] = isset($raw_json['factory_cert']) ? $raw_json['factory_cert'] : null; + $single_business_items['business_remarks'] = $raw_json['business_remarks']; + $single_business_items['export_sale_of_total_sales'] = $raw_json['export_sale_of_total_sales']; + //print_r($single_business_items); + + if(array_key_exists('partners',$raw_json)) + { + $partners_details = array(); + foreach($raw_json['partners'] as $partner_key => $partner) + { + if($partner['partner_name'] != "" || $partner['partner_name'] != null) + { + $temp['company_name'] = SELF::getCompanyName($raw_json['company_id'],$company_data); + $temp['partner_name'] = $partner['partner_name_master']; + $temp['total_business_experiance'] = $partner['total_business_experiance']; + $temp['current_business_experiance_year'] = $partner['current_business_experiance_year']; + $temp['current_business_experiance_month'] = $partner['current_business_experiance_month']; + $temp['started_business'] = $partner['started_business']; + $temp['shareholding'] = $partner['shareholding']; + $temp['pd_id'] = $master[0]['pd_id']; + $temp['lender_sno'] = $master[0]['pd_sno']; + array_push($partners_details,$temp); + } + } + //print_r($partners_details); + } + + if(array_key_exists('select_business_activity_type',$raw_json)) + { + $type_of_activity_details = array(); + foreach($raw_json['select_business_activity_type'] as $activity_key => $activity) + { + + $activity_temp['type_of_activity'] = $activity['name']; + //$activity_temp['type_of_activity_id'] = $activity['type_of_activity_id']; + $activity_temp['pd_id'] = $master[0]['pd_id']; + $activity_temp['lender_sno'] = $master[0]['pd_sno']; + $activity_temp['company_name'] = SELF::getCompanyName($raw_json['company_id'],$company_data); + array_push($type_of_activity_details,$activity_temp); + + } + //print_r($type_of_activity_details); + } + + $business_relatinship_data = array(); + if(array_key_exists('persons_with_relationships',$raw_json)) + { + foreach($raw_json['persons_with_relationships'] as $persons_with_relationship_key => $persons_with_relationship) + { + + $business_relatinship_temp = array(); + $business_relatinship_temp['pd_id'] = $master[0]['pd_id']; + $business_relatinship_temp['lender_sno'] = $master[0]['pd_sno']; + $business_relatinship_temp['company_name'] = SELF::getCompanyName($raw_json['company_id'],$company_data); + $business_relatinship_temp['family_member_name'] = $persons_with_relationship['family_member_salutation_master'].' '.$persons_with_relationship['family_member_name']; + $business_relatinship_temp['family_relation'] = $persons_with_relationship['other_family_relationship_id_master']; + $business_relatinship_temp['business_relation'] = substr_replace($persons_with_relationship['relationship_with_company_id_master'], '',-2) ; + $business_relatinship_temp['relation_to'] = $persons_with_relationship['relation_to_id_master']; + $business_relatinship_temp['started_business'] = $persons_with_relationship['started_business']; + array_push($business_relatinship_data,$business_relatinship_temp); + + + } + } + //print_r($business_relatinship_data); + //die(); + $products = array(); + if(array_key_exists('manufacturing_activity_details',$raw_json) && count($raw_json['manufacturing_activity_details'])) + { + + array_push($products,SELF::getProducts($raw_json['manufacturing_activity_details'],'Manufacturing',$raw_json['company_id'],$company_data,$master)); + } + + if(array_key_exists('retail_trading_activity_details',$raw_json) && count($raw_json['retail_trading_activity_details'])) + { + + array_push($products,SELF::getProducts($raw_json['retail_trading_activity_details'],'Retail Trading',$raw_json['company_id'],$company_data,$master)); + } + if(array_key_exists('wholesale_trading_activity_details',$raw_json) && count($raw_json['wholesale_trading_activity_details'])) + { + + array_push($products,SELF::getProducts($raw_json['wholesale_trading_activity_details'],'Wholesale Trading',$raw_json['company_id'],$company_data,$master)); + } + if(array_key_exists('service_provider_activity_details',$raw_json) && count($raw_json['service_provider_activity_details'])) + { + + array_push($products,SELF::getProducts($raw_json['service_provider_activity_details'],'Service Provider',$raw_json['company_id'],$company_data,$master)); + } + + + + + + + + } + + return array('products' => $products,'business_relatinship_data' => $business_relatinship_data,'type_of_activity_details' => $type_of_activity_details,'partners_details' => $partners_details,'single_business_items' => $single_business_items); + } + /*****************########## END BUSINESS FORM DETAILS ##########**************/ + + static function getCompanyName($company_id,$company_data) + { + foreach ($company_data as $key => $value) + { + if($value['company_id'] == $company_id) + { + return $value['company_name']; + break; + } + } + } + + static function getProducts($data,$type_of_activity,$company_id,$company_data,$master) + { + $result_array = array(); + foreach ($data as $key => $value) + { + $temp = array(); + $temp['pd_id'] = $master[0]['pd_id']; + $temp['lender_sno'] = $master[0]['pd_sno']; + $temp['company_name'] = SELF::getCompanyName($company_id,$company_data); + $temp['type_of_activity'] = $type_of_activity; + $temp['product'] = $value['main_products']; + $temp['area_of_sale'] = $value['area_of_sale']; + $temp['description'] = $value['description']; + $temp['pan_india'] = isset($value['pan_india_options']) ? $value['pan_india_options'] : null; + if(($value['area_of_sale'] == 'Within India' || $value['area_of_sale'] == 'Both') && $value['pan_india_options'] == 'Yes') + { + $max_state_name = ""; + foreach ($value['max_sale_state_name'][0]['state_name'] as $ms_key => $ms_value) + { + $max_state_name .= $ms_value.' ,'; + } + $max_state_name = substr_replace($max_state_name,'', -1); + $temp['max_sales_states'] = $max_state_name; + } + + else if(($value['area_of_sale'] == 'Within India' || $value['area_of_sale'] == 'Both') && $value['pan_india_options'] == 'No') + { + + $city_name = ""; + $state_name = ""; + + foreach ($value['india_where_sale_done'] as $is_key => $is_value) + { + $state_name .= $is_value['state_name'].' ,'; + foreach ($is_value['city_name'] as $c_key => $c_value) + { + $city_name .= $c_value.' ,'; + } + + } + $state_name = substr_replace($state_name,'', -1); + $temp['states'] = $state_name; + $temp['cities'] = $city_name; + + $max_state_name = ""; + //print_r($value['max_sale_state_name']); + foreach ($value['max_sale_state_name'][0]['state_name'] as $ms_key => $ms_value) + { + $max_state_name .= $ms_value.' ,'; + } + $max_state_name = substr_replace($max_state_name,'', -1); + $temp['max_sales_states'] = $max_state_name; + + $max_city_name = ""; + //print_r($value['max_sale_state_name']); + foreach ($value['max_sale_state_name'][0]['city_name'] as $mc_key => $mc_value) + { + $max_city_name .= $mc_value.' ,'; + } + $max_city_name = substr_replace($max_city_name,'', -1); + $temp['max_sales_cites'] = $max_city_name; + } + + if($value['area_of_sale'] == 'Export' || $value['area_of_sale'] == 'Both') + { + //echo "SAJHBASDJ"; + $course_name = ""; + foreach ($value['countries_where_export_done'] as $ec_key => $ec_value) + { + //echo + $course_name .= '['.$ec_value['country_name'].','.$ec_value['approx_sale'].'%]'.','; + } + $course_name = substr_replace($course_name,'', -1); + $temp['export_countries'] = $course_name; + } + array_push($result_array,$temp); + } + return $result_array; + + } + + /*****************########## START GENERAL FORM DETAILS ##########**************/ + public static function convertGeneralDetailsForm($json,$master) + { + //echo "called"; + //$CI =& get_instance(); + + $individuals_data = array(); + $relationship_data = array(); + $company_data = array(); + if(array_key_exists('individuals',$json)) + { + //echo "exists"; + foreach($json['individuals'] as $individuals_key => $individual) + { + $temp = array(); + $temp['applicant_name'] = $individual['applicant_name']; + $temp['is_applicant'] = $individual['is_applicant']; + $temp['is_person_met'] = $individual['is_person_met']; + $temp['age'] = $individual['age']; + $temp['qualification'] = $individual['qualification_master']; + $temp['course_name'] = $individual['course_name']; + $temp['entity_type'] = null; + $temp['yrs_month'] = null; + $temp['pd_id'] = $master[0]['pd_id']; + $temp['lender_sno'] = $master[0]['pd_sno']; + $individuals_data[] = $temp; + + + } + } + if(array_key_exists('companies',$json)) + { + //echo "exists"; + foreach($json['companies'] as $company_key => $company) + { + $temp = array(); + $temp['applicant_name'] = $company['company_name']; + $temp['is_applicant'] = $company['is_company_applicant']; + $temp['entity_type'] = $company['business_entity_type_master']; + $temp['yrs_month'] = $company['business_years'].' '.$company['business_month']; + $temp['pd_id'] = $master[0]['pd_id']; + $temp['lender_sno'] = $master[0]['pd_sno']; + + $company_data[] = array('company_name' => $temp['applicant_name'],'company_id' => $company['company_order_id']); + $individuals_data[] = $temp; + } + } + if(array_key_exists('persons_with_relationships',$json)) + { + //echo "exists"; + foreach($json['persons_with_relationships'] as $relation_key => $relation) + { + if($relation['relationship'] != 0) + { + $temp = array(); + $temp['applicant_name'] = $relation['applicant_name']; + $temp['relationship'] = $relation['relationship_master']; + $temp['relation_to'] = isset($relation['relation_to_master']) ? $relation['relation_to_master'] : null; + $temp['pd_id'] = $master[0]['pd_id']; + $temp['lender_sno'] = $master[0]['pd_sno']; + $relationship_data[] = $temp; + } + } + } + if(array_key_exists('company_with_relationships',$json)) + { + //echo "exists"; + foreach($json['company_with_relationships'] as $relation_key => $relation) + { + + $temp = array(); + $temp['applicant_name'] = $relation['applicant_name_master']; + $temp['relationship'] = $relation['company_relationship_master']; + $temp['relation_to'] = $relation['company_name']; + $temp['pd_id'] = $master[0]['pd_id']; + $temp['lender_sno'] = $master[0]['pd_sno']; + $relationship_data[] = $temp; + + } + } + return array('individuals_data' => $individuals_data,'relationship_data' => $relationship_data,'company_data' => $company_data); + + + + } + /*****************########## END GENERAL FORM DETAILS ##########**************/ + + + + /*****************########## BUSINESS ASSETS FORM DETAILS ##########**************/ + public static function convertBusinessAssetsForm($raw_json,$formid) + { + ///echo "BA called"; + $CI =& get_instance(); + $master_tables_field_names = $CI->config->item('master_tables_field_names'); + $master_tables_pkid = $CI->config->item('master_tables_pkid'); + + //print_r($raw_json); + + // GET KEYS FROM MASTER TABLE FOR SUPPLIER FORM + $fields = array('question', 'key', 'ismaster', 'master_name'); + $where_condition_array = array('fk_form_id' => $formid,'isactive' => 1); + $master_keys = $CI->PD_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONKEYMAPPING); + + if(array_key_exists('business_assets_details',$raw_json)) + { + foreach($raw_json['business_assets_details'] as $business_assets_detail_key => $business_assets_detail) + { + if($business_assets_detail['business_assets_mode'] != "" || $business_assets_detail['business_assets_mode'] != null) + { + //echo $business_assets_detail['business_assets_mode']; + $CI->db->SELECT( $master_tables_field_names['ASSETTYPE'] ); + $CI->db->FROM(ASSETTYPE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['ASSETTYPE'] ,$business_assets_detail['business_assets_mode']); + $assest_mode_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($assest_mode_name)) + { + //print_r($assest_mode_name); + $raw_json['business_assets_details'][$business_assets_detail_key]['business_assets_mode_master'] = $assest_mode_name[0][$master_tables_field_names['ASSETTYPE']]; + } + + if($business_assets_detail['business_assets_mode'] == 2) + { + + + $CI->db->SELECT( $master_tables_field_names['ADDRESSTYPE'] ); + $CI->db->FROM(ADDRESSTYPE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['ADDRESSTYPE'] ,$business_assets_detail['business_details'][0]['property_type']); + $assest_mode_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + //print_r($assest_mode_name); + if(count($assest_mode_name)) + { + $raw_json['business_assets_details'][$business_assets_detail_key]['business_details'][0]['property_type_master'] = $assest_mode_name[0][$master_tables_field_names['ADDRESSTYPE']]; + } + // if($business_assets_detail['business_details'][0]['property_type']) + // { + // $CI->db->SELECT( $master_tables_field_names['ASSETTYPE'] ); + // $CI->db->FROM(ASSETTYPE); + // $CI->db->WHERE('isactive',1); + // $CI->db->WHERE( $master_tables_pkid['ASSETTYPE'] ,$business_assets_detail['business_details'][0]['property_type']); + // $assest_type= $CI->db->GET()->result_array(); + // //print_r($CI->db->last_query()); + // if(count($assest_type)) + // { + // $raw_json['business_assets_details'][$business_assets_detail_key]['business_details'][0]['business_details']['property_type_master'] = $assest_type[0][$master_tables_field_names['ASSETTYPE']]; + // } + // } + + } + + if($business_assets_detail['business_assets_mode'] == 3) + { + + + $CI->db->SELECT( $master_tables_field_names['VEHICLETYPE'] ); + $CI->db->FROM(VEHICLETYPE); + $CI->db->WHERE('is_active',1); + $CI->db->WHERE( $master_tables_pkid['VEHICLETYPE'] ,$business_assets_detail['business_details'][0]['vehicle_type']); + $assest_mode_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($assest_mode_name)) + { + $raw_json['business_assets_details'][$business_assets_detail_key]['business_details'][0]['vehicle_type_master'] = $assest_mode_name[0][$master_tables_field_names['VEHICLETYPE']]; + } + } + } + } + } + return ($raw_json); + + } + /*****************########## END OF BUSINESS ASSETS FORM DETAILS ##########**************/ + + + + + /*****************########## Other ASSETS FORM DETAILS ##########**************/ + public static function convertOtherAssetForm($raw_json,$formid) + { + //echo "OA CALLED"; + $CI =& get_instance(); + $master_tables_field_names = $CI->config->item('master_tables_field_names'); + $master_tables_pkid = $CI->config->item('master_tables_pkid'); + + //print_r($raw_json);die(); + + // GET KEYS FROM MASTER TABLE FOR SUPPLIER FORM + $fields = array('question', 'key', 'ismaster', 'master_name'); + $where_condition_array = array('fk_form_id' => $formid,'isactive' => 1); + $master_keys = $CI->PD_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONKEYMAPPING); + + if(array_key_exists('assets_details',$raw_json)) + { + foreach($raw_json['assets_details'] as $assets_detail_key => $assets_detail) + { + if($assets_detail['assets_mode'] != "" || $assets_detail['assets_mode'] != null) + { + $CI->db->SELECT( $master_tables_field_names['ASSETTYPE'] ); + $CI->db->FROM(ASSETTYPE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['ASSETTYPE'] ,$assets_detail['assets_mode']); + $assest_mode_name= $CI->db->GET()->result_array(); + // print_r($assest_mode_name); + // print_r($CI->db->last_query());die(); + if(count($assest_mode_name)) + { + $raw_json['assets_details'][$assets_detail_key]['assets_mode_master'] = $assest_mode_name[0][$master_tables_field_names['ASSETTYPE']]; + } + + if($assets_detail['assets_mode'] == 2) + { + + + $CI->db->SELECT( $master_tables_field_names['PROPERTIES'] ); + $CI->db->FROM(PROPERTIES); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['PROPERTIES'] ,$assets_detail['details'][0]['property_type']); + $assest_mode_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($assest_mode_name)) + { + $raw_json['assets_details'][$assets_detail_key]['details'][0]['property_type_master'] = $assest_mode_name[0][$master_tables_field_names['PROPERTIES']]; + } + //UOM + $CI->db->SELECT( $master_tables_field_names['UOM'] ); + $CI->db->FROM(UOM); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['UOM'] ,$assets_detail['details'][0]['uom_of_the_property']); + $uom_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($uom_name)) + { + $raw_json['assets_details'][$assets_detail_key]['details'][0]['uom_master'] = $uom_name[0][$master_tables_field_names['UOM']]; + } + + + } + + if($assets_detail['assets_mode'] == 3) + { + + + $CI->db->SELECT( $master_tables_field_names['VEHICLETYPE'] ); + $CI->db->FROM(VEHICLETYPE); + $CI->db->WHERE('is_active',1); + $CI->db->WHERE( $master_tables_pkid['VEHICLETYPE'] ,$assets_detail['details'][0]['vehicle_type']); + $assest_mode_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($assest_mode_name)) + { + $raw_json['assets_details'][$assets_detail_key]['details'][0]['vehicle_type_master'] = $assest_mode_name[0][$master_tables_field_names['VEHICLETYPE']]; + } + } + + + if($assets_detail['assets_mode'] == 7) + { + + + $CI->db->SELECT( $master_tables_field_names['INVESTMENTTYPE'] ); + $CI->db->FROM(INVESTMENTTYPE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['INVESTMENTTYPE'] ,$assets_detail['details'][0]['investments_type']); + $assest_mode_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($assest_mode_name)) + { + $raw_json['assets_details'][$assets_detail_key]['details'][0]['investments_type_master'] = $assest_mode_name[0][$master_tables_field_names['INVESTMENTTYPE']]; + } + } + + if($assets_detail['assets_mode'] == 6) + { + + + $CI->db->SELECT( $master_tables_field_names['FREQUENCY'] ); + $CI->db->FROM(FREQUENCY); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['FREQUENCY'] ,$assets_detail['details'][0]['frequency_mode']); + $assest_mode_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($assest_mode_name)) + { + $raw_json['assets_details'][$assets_detail_key]['details'][0]['frequency_mode_master'] = $assest_mode_name[0][$master_tables_field_names['FREQUENCY']]; + } + } + } + } + } + + return $raw_json; + + } + /*****************########## END OF BUSINESS ASSETS FORM DETAILS ##########**************/ + + + /*****************########## CLIENT FORM DETAILS ##########********************/ + + public static function convertClientForm($raw_json,$formid) + { + + + $CI =& get_instance(); + $master_tables_field_names = $CI->config->item('master_tables_field_names'); + $master_tables_pkid = $CI->config->item('master_tables_pkid'); + + //print_r($raw_json); + + // GET KEYS FROM MASTER TABLE FOR SUPPLIER FORM + $fields = array('question', 'key', 'ismaster', 'master_name'); + $where_condition_array = array('fk_form_id' => $formid,'isactive' => 1); + $master_keys = $CI->PD_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONKEYMAPPING); + + //print_r($master_keys); + if(!empty($raw_json) && !empty($master_keys)) + { + + // Handling manufacturing_details subarry + if(array_key_exists('manufacturing_details',$raw_json)) + { + if(array_key_exists('main_raw_materials',$raw_json['manufacturing_details'][0])) + { + foreach($raw_json['manufacturing_details'][0]['main_raw_materials'] as $manufacturing_details_key => $manufacturing_details) + { + foreach($manufacturing_details as $key => $value) + { + if($value != "" || $value != null) + { + //compare with master_keys array + foreach($master_keys as $master_key => $master_value) + { + if(!strcmp($key,$master_value['key']) && $master_value['ismaster'] == 1) + { + //GET MASASTER DATA + + $table = constant($master_value['master_name']); + + $temp_fields = array($master_tables_field_names[$master_value['master_name']].' as name'); + + $where_condition_array = array($master_tables_pkid[$master_value['master_name']] => $value); + + $result_data = $CI->PD_Model->selectCustomRecords($temp_fields,$where_condition_array,$table); + if(count($result_data)) + { + //print_r($result_data[0]['name']); + $key = $key . '_master'; + $raw_json['manufacturing_details'][0]['main_raw_materials'][$manufacturing_details_key][$key] = $result_data[0]['name']; + + } + } + } + } + } + + + } + } + } + + + + // Handling trading_details subarry + if(array_key_exists('trade_details',$raw_json)) + { + if(array_key_exists('trading_products',$raw_json['trade_details'][0])) + { + foreach($raw_json['trade_details'][0]['trading_products'] as $trade_details_key => $manufacturing_details) + { + foreach($manufacturing_details as $key => $value) + { + if($value != "" || $value != null) + { + //compare with master_keys array + foreach($master_keys as $master_key => $master_value) + { + if(!strcmp($key,$master_value['key']) && $master_value['ismaster'] == 1) + { + //GET MASASTER DATA + + $table = constant($master_value['master_name']); + + $temp_fields = array($master_tables_field_names[$master_value['master_name']].' as name'); + + $where_condition_array = array($master_tables_pkid[$master_value['master_name']] => $value); + + $result_data = $CI->PD_Model->selectCustomRecords($temp_fields,$where_condition_array,$table); + if(count($result_data)) + { + //print_r($result_data[0]['name']); + $key = $key . '_master'; + $raw_json['trade_details'][0]['trading_products'][$trade_details_key][$key] = $result_data[0]['name']; + + } + } + } + } + } + + + } + } + } + + + + // Handling Service_details_ subarry + + + if(array_key_exists('service_provider_details',$raw_json)) + { + + if(array_key_exists('service_products',$raw_json['service_provider_details'][0])) + { + foreach($raw_json['service_provider_details'][0]['service_products'] as $service_provider_details_key => $manufacturing_details) + { + foreach($manufacturing_details as $key => $value) + { + if($value != "" || $value != null) + { + //compare with master_keys array + foreach($master_keys as $master_key => $master_value) + { + if(!strcmp($key,$master_value['key']) && $master_value['ismaster'] == 1) + { + //GET MASASTER DATA + + $table = constant($master_value['master_name']); + + $temp_fields = array($master_tables_field_names[$master_value['master_name']].' as name'); + + $where_condition_array = array($master_tables_pkid[$master_value['master_name']] => $value); + + $result_data = $CI->PD_Model->selectCustomRecords($temp_fields,$where_condition_array,$table); + if(count($result_data)) + { + //print_r($result_data[0]['name']); + $key = $key . '_master'; + $raw_json['service_provider_details'][0]['service_products'][$service_provider_details_key][$key] = $result_data[0]['name']; + + } + } + } + } + } + + + } + } + } + + + } + + return $raw_json; + } + /*****************########## END OF CLIENT FORM DETAILS ##########**************/ + + + + + /*****************########## ADDRESS FORM DETAILS ##########********************/ + + public static function convertAddressForm($raw_json,$formid) + { + //echo "ADDRESS FORM CALLED"; + $CI =& get_instance(); + $master_tables_field_names = $CI->config->item('master_tables_field_names'); + $master_tables_pkid = $CI->config->item('master_tables_pkid'); + + $fields = array('question', 'key', 'ismaster', 'master_name'); + $where_condition_array = array('fk_form_id' => $formid,'isactive' => 1); + $master_keys = $CI->PD_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONKEYMAPPING); + + + //print_r($raw_json); + foreach($raw_json['addresses'] as $raw_json_key => $address) + { + + + + if(array_key_exists('address_type',$address)) + { + $CI->db->SELECT( $master_tables_field_names['ADDRESSTYPE'] ); + $CI->db->FROM(ADDRESSTYPE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['ADDRESSTYPE'] ,$address['address_type']); + $adress_type_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($adress_type_name)) + { + $raw_json['addresses'][$raw_json_key]['address_type_master'] = $adress_type_name[0][$master_tables_field_names['ADDRESSTYPE']]; + } + } + + + if(array_key_exists('locality',$address)) + { + $CI->db->SELECT( $master_tables_field_names['LOCALITY'] ); + $CI->db->FROM(LOCALITY); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['LOCALITY'] ,$address['locality']); + $locality_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($locality_name)) + { + $raw_json['addresses'][$raw_json_key]['locality_master'] = $locality_name[0][$master_tables_field_names['LOCALITY']]; + } + } + + + if(array_key_exists('pd_location',$address)) + { + $CI->db->SELECT( $master_tables_field_names['PDLOCATIONAPPROACH'] ); + $CI->db->FROM(PDLOCATIONAPPROACH); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['PDLOCATIONAPPROACH'] ,$address['pd_location']); + $pd_location_approach= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($pd_location_approach)) + { + $raw_json['addresses'][$raw_json_key]['pd_location_master'] = $pd_location_approach[0][$master_tables_field_names['PDLOCATIONAPPROACH']]; + } + } + + + if(array_key_exists('comment_locality',$address)) + { + $CI->db->SELECT( $master_tables_field_names['COMMENTSONLOCALITY'] ); + $CI->db->FROM(COMMENTSONLOCALITY); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['COMMENTSONLOCALITY'] ,$address['comment_locality']); + $comments_on_locality= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($comments_on_locality)) + { + $raw_json['addresses'][$raw_json_key]['comment_locality_master'] = $comments_on_locality[0][$master_tables_field_names['COMMENTSONLOCALITY']]; + } + } + + if(array_key_exists('additional_address_units',$address)) + { + + foreach($address['additional_address_units'] as $additional_address_unit_key => $additional_address_unit) + { + $CI->db->SELECT( $master_tables_field_names['ADDRESSTYPE'] ); + $CI->db->FROM(ADDRESSTYPE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['ADDRESSTYPE'] ,$additional_address_unit['premises_type']); + $premises_type= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($premises_type)) + { + $raw_json['addresses'][$raw_json_key]['additional_address_units'][$additional_address_unit_key]['premises_type_master'] = $premises_type[0][$master_tables_field_names['ADDRESSTYPE']]; + } + } + } + + + if(array_key_exists('state',$address)) + { + //print_r($address); + $CI->db->SELECT( $master_tables_field_names['STATE'] ); + $CI->db->FROM(STATE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['STATE'] ,$address['state']); + $adress_type_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($adress_type_name)) + { + $raw_json['addresses'][$raw_json_key]['state_master'] = $adress_type_name[0][$master_tables_field_names['STATE']]; + } + } + + if(array_key_exists('city',$address)) + { + //print_r($address); + $CI->db->SELECT( $master_tables_field_names['CITY'] ); + $CI->db->FROM(CITY); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['CITY'] ,$address['city']); + $city= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($city)) + { + $raw_json['addresses'][$raw_json_key]['city_master'] = $city[0][$master_tables_field_names['CITY']]; + } + } + + if(array_key_exists('pincode',$address)) + { + //print_r($address); + $CI->db->SELECT( $master_tables_field_names['PINCODE'] ); + $CI->db->FROM(PINCODE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['PINCODE'] ,$address['pincode']); + $pincode= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($pincode)) + { + $raw_json['addresses'][$raw_json_key]['pincode_master'] = $pincode[0][$master_tables_field_names['PINCODE']]; + } + } + + if(array_key_exists('uom',$address)) + { + //print_r($address); + $CI->db->SELECT( $master_tables_field_names['UOM'] ); + $CI->db->FROM(UOM); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['UOM'] ,$address['uom']); + $uom= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($uom)) + { + $raw_json['addresses'][$raw_json_key]['uom_master'] = $uom[0][$master_tables_field_names['UOM']]; + } + } + + } + + if(isset($raw_json['is_pd_done_on_initiated_address']) && ($raw_json['is_pd_done_on_initiated_address'] == "") ) + { + foreach($raw_json['alternative_addresses'] as $raw_json_key => $address) + { + // GET KEYS FROM MASTER TABLE FOR SUPPLIER FORM + // $fields = array('question', 'key', 'ismaster', 'master_name'); + // $where_condition_array = array('fk_form_id' => $formid,'isactive' => 1); + // $master_keys = $CI->PD_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONKEYMAPPING); + + if(array_key_exists('address_type',$address)) + { + $CI->db->SELECT( $master_tables_field_names['ADDRESSTYPE'] ); + $CI->db->FROM(ADDRESSTYPE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['ADDRESSTYPE'] ,$address['address_type']); + $adress_type_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($adress_type_name)) + { + $raw_json['alternative_addresses'][$raw_json_key]['address_type_master'] = $adress_type_name[0][$master_tables_field_names['ADDRESSTYPE']]; + } + } + + + if(array_key_exists('locality',$address)) + { + $CI->db->SELECT( $master_tables_field_names['LOCALITY'] ); + $CI->db->FROM(LOCALITY); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['LOCALITY'] ,$address['locality']); + $locality_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($locality_name)) + { + $raw_json['alternative_addresses'][$raw_json_key]['locality_master'] = $locality_name[0][$master_tables_field_names['LOCALITY']]; + } + } + + + if(array_key_exists('pd_location',$address)) + { + $CI->db->SELECT( $master_tables_field_names['PDLOCATIONAPPROACH'] ); + $CI->db->FROM(PDLOCATIONAPPROACH); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['PDLOCATIONAPPROACH'] ,$address['pd_location']); + $pd_location_approach= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($pd_location_approach)) + { + $raw_json['alternative_addresses'][$raw_json_key]['pd_location_master'] = $pd_location_approach[0][$master_tables_field_names['PDLOCATIONAPPROACH']]; + } + } + + + if(array_key_exists('comment_locality',$address)) + { + $CI->db->SELECT( $master_tables_field_names['COMMENTSONLOCALITY'] ); + $CI->db->FROM(COMMENTSONLOCALITY); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['COMMENTSONLOCALITY'] ,$address['comment_locality']); + $comments_on_locality= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($comments_on_locality)) + { + $raw_json['alternative_addresses'][$raw_json_key]['comment_locality_master'] = $comments_on_locality[0][$master_tables_field_names['COMMENTSONLOCALITY']]; + } + } + + if(array_key_exists('additional_address_units',$address)) + { + + foreach($address['additional_address_units'] as $additional_address_unit_key => $additional_address_unit) + { + $CI->db->SELECT( $master_tables_field_names['ADDRESSTYPE'] ); + $CI->db->FROM(ADDRESSTYPE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['ADDRESSTYPE'] ,$additional_address_unit['premises_type']); + $premises_type= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($premises_type)) + { + $raw_json['alternative_addresses'][$raw_json_key]['additional_address_units'][$additional_address_unit_key]['premises_type_master'] = $premises_type[0][$master_tables_field_names['ADDRESSTYPE']]; + } + } + } + + + if(array_key_exists('alternative_state',$address)) + { + //print_r($address); + $CI->db->SELECT( $master_tables_field_names['STATE'] ); + $CI->db->FROM(STATE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['STATE'] ,$address['alternative_state']); + $adress_type_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($adress_type_name)) + { + $raw_json['alternative_addresses'][$raw_json_key]['state_master'] = $adress_type_name[0][$master_tables_field_names['STATE']]; + } + } + + if(array_key_exists('alternative_city',$address)) + { + //print_r($address); + $CI->db->SELECT( $master_tables_field_names['CITY'] ); + $CI->db->FROM(CITY); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['CITY'] ,$address['alternative_city']); + $city= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($city)) + { + $raw_json['alternative_addresses'][$raw_json_key]['city_master'] = $city[0][$master_tables_field_names['CITY']]; + } + } + + if(array_key_exists('alternative_pincode',$address)) + { + //print_r($address); + $CI->db->SELECT( $master_tables_field_names['PINCODE'] ); + $CI->db->FROM(PINCODE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['PINCODE'] ,$address['alternative_pincode']); + $pincode= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($pincode)) + { + $raw_json['alternative_addresses'][$raw_json_key]['pincode_master'] = $pincode[0][$master_tables_field_names['PINCODE']]; + } + } + + if(array_key_exists('uom',$address)) + { + //print_r($address); + $CI->db->SELECT( $master_tables_field_names['UOM'] ); + $CI->db->FROM(UOM); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['UOM'] ,$address['uom']); + $uom= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($uom)) + { + $raw_json['alternative_addresses'][$raw_json_key]['uom_master'] = $uom[0][$master_tables_field_names['UOM']]; + } + } + + } + } + + return ($raw_json); + + } + /*****************########## END OF ADDRESS FORM DETAILS ##########**************/ + + + + /*****************########## FINAL REMARKS FORM DETAILS ##########**************/ + public static function convertFinalRemarksForm($raw_json,$formid) + { + + //echo "FEPJ called"; + $CI =& get_instance(); + $master_tables_field_names = $CI->config->item('master_tables_field_names'); + $master_tables_pkid = $CI->config->item('master_tables_pkid'); + + //print_r($raw_json); + + // GET KEYS FROM MASTER TABLE FOR FINAL FORM + $fields = array('question', 'key', 'ismaster', 'master_name'); + $where_condition_array = array('fk_form_id' => $formid,'isactive' => 1); + $master_keys = $CI->PD_Model->selectCustomRecords($fields,$where_condition_array,QUESTIONKEYMAPPING); + + + if(array_key_exists('final_custormer_remark_type',$raw_json)) + { + $CI->db->SELECT( $master_tables_field_names['CUSTOMERBEHAVIOUR'] ); + $CI->db->FROM(CUSTOMERBEHAVIOUR); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['CUSTOMERBEHAVIOUR'] ,$raw_json['final_custormer_remark_type']); + $customer_behaviour= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($customer_behaviour)) + { + $raw_json['final_custormer_remark_type_master'] = $customer_behaviour[0][$master_tables_field_names['CUSTOMERBEHAVIOUR']]; + } + } + + if(array_key_exists('pd_officers_recommendation',$raw_json)) + { + $CI->db->SELECT( $master_tables_field_names['PDOFFICERRECOMMENDATIONS'] ); + $CI->db->FROM(PDOFFICERRECOMMENDATIONS); + $CI->db->WHERE('is_active',1); + $CI->db->WHERE($master_tables_pkid['PDOFFICERRECOMMENDATIONS'] ,$raw_json['pd_officers_recommendation']); + $pdofficer_recommendations= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($pdofficer_recommendations)) + { + $raw_json['pd_officers_recommendation_master'] = $pdofficer_recommendations[0][$master_tables_field_names['PDOFFICERRECOMMENDATIONS']]; + } + } + + return $raw_json; + } + /*****************########## END OF FINAL REMARKS FORM DETAILS ##########**************/ + + + /************************########### RENTAL INCOME #################****************************/ + public static function convertRentalIncomeDetailsForm($raw_json,$formid) + { + + $CI =& get_instance(); + $master_tables_field_names = $CI->config->item('master_tables_field_names'); + $master_tables_pkid = $CI->config->item('master_tables_pkid'); + + if(array_key_exists('state',$raw_json)) + { + //print_r($address); + $CI->db->SELECT( $master_tables_field_names['STATE'] ); + $CI->db->FROM(STATE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['STATE'] ,$raw_json['state']); + $adress_type_name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($adress_type_name)) + { + $raw_json['state_master'] = $adress_type_name[0][$master_tables_field_names['STATE']]; + } + } + + if(array_key_exists('city',$raw_json)) + { + //print_r($address); + $CI->db->SELECT( $master_tables_field_names['CITY'] ); + $CI->db->FROM(CITY); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['CITY'] ,$raw_json['city']); + $city= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($city)) + { + $raw_json['city_master'] = $city[0][$master_tables_field_names['CITY']]; + } + } + + if(array_key_exists('pincode',$raw_json)) + { + //print_r($address); + $CI->db->SELECT( $master_tables_field_names['PINCODE'] ); + $CI->db->FROM(PINCODE); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE($master_tables_pkid['PINCODE'] ,$raw_json['pincode']); + $pincode= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($pincode)) + { + $raw_json['pincode_master'] = $pincode[0][$master_tables_field_names['PINCODE']]; + } + } + return ($raw_json); + } + /************************########### END OF RENTAL INCOME #################****************************/ + + + + /************************###########CREDIT MANAGER QUERIES FORM #################****************************/ + + public static function convertCreditManagerQueriesForm($records,$formid) + { + $CI =& get_instance(); + $additional_requirements = $CI->PD_Model->getPDAdditionalRequirements($records['pdid']); + $docs_to_collected = $CI->PD_Model->getDocsToBeCollected($records['pdid']); + //print_r($records); + // print_r($docs_to_collected); + if(isset($records['addtional_requirements'][0]) && count($records['addtional_requirements'][0]) ) + { + foreach ($records['addtional_requirements'][0] as $add_key => $add_value) + { + foreach ($additional_requirements as $key => $value) + { + if($add_key == $value['add_req_id']) + { + + $records['additional_requirements_processed'][] = array('question' => $value['add_requirement'],'answer' => $add_value); + break; + } + } + + } + } + unset($records['addtional_requirements']); + + if(isset($records['docs_to_be_sighted']) && count($records['docs_to_be_sighted']) ) + { + foreach ($records['docs_to_be_sighted'] as $doc_key => $doc_value) + { + foreach ($docs_to_collected as $key => $value) + { + if(key($doc_value) == $value['pd_doc_to_be_collect_id']) + { + // $temp['pk'] = key($doc_value); + // $temp['key_index'] = $doc_key; + $temp['doc_name'] = $value['doc_name']; + $temp['ans'] = $doc_value[ key($doc_value) ]; + $temp['img'] = array_key_exists('img',$doc_value) ? $doc_value['img']: null; + if(array_key_exists('img',$doc_value) && $doc_value['is_new'] == 1) + { + $return_data = $CI->saveBase64Images($records['pdid'],$records['formid'],$company_id = null,$rental_count_id = null,array(array('image' => $doc_value['img'],'Name' => $value['doc_name'],'link' => $records['link']))); + if(count($return_data) && isset($return_data['pks']) ) + { + $records['docs_to_be_sighted'][$doc_key]['img'] = $return_data['pks'][0]; + $temp['img'] = $return_data['pks'][0]; + $records['docs_to_be_sighted'][$doc_key]['is_new'] = 0; + } + } + + //$temp['is_new'] = array_key_exists('is_new',$doc_value) ? $doc_value['is_new']: 0; + $temp['reason'] = array_key_exists('reason',$doc_value) ? $doc_value['reason']: null; + $records['docs_to_be_sighted_processed'][] = $temp; + + + break; + } + } + + } + } + //unset($records['docs_to_be_sighted']); + // print_r($records); + // die(); + return $records; + } + /************************########### END OF CREDIT MANAGER QUERIES FORM #################****************************/ + + +} + + + +?> \ No newline at end of file diff --git a/api/application/hooks/waterMarkHook.php b/api/application/hooks/waterMarkHook.php new file mode 100644 index 00000000..39c47863 --- /dev/null +++ b/api/application/hooks/waterMarkHook.php @@ -0,0 +1,20 @@ +router->class == 'PD_Controller' && ($CI->router->method == 'checkAfterResponse' || $CI->router->method == 'savePDPhotos')) + { + $CI->load->helper('watermark'); + // $sourceFilePath = 'C:\Users\Venba\Pictures\1canvas.png'; + watermark::makeWatermark(); + + } + + + } +} \ No newline at end of file diff --git a/api/application/models/PD_Model.php b/api/application/models/PD_Model.php index 9fb7ff83..172d5a9b 100644 --- a/api/application/models/PD_Model.php +++ b/api/application/models/PD_Model.php @@ -1185,7 +1185,8 @@ class PD_Model extends SPARQ_Model { $pd_master_detials = $this->getPDMasterDetails($pdid,$random_string); $pd_additional_requirements = $this->getPDAdditionalRequirements($pdid); $docs_to_be_collected = $this->getDocsToBeCollected($pdid); - + $over_all_photocount = $this->PD_Model->selectCustomRecords(array('*'),array('fk_pd_id' => $pdid,'isactive' => 1),PDDOCUMENTS); + //echo count($docs_to_be_collected);die(); $pd_applicants_detials = $this->getApplicantsDetails($pdid); @@ -1208,7 +1209,7 @@ class PD_Model extends SPARQ_Model { } $this->db->ORDER_BY('PDFORMS.pd_form_order'); $template_forms = $this->db->GET()->result_array(); - //print_r($this->db->last_query());die(); + // print_r($template_forms);die(); $level_one_status = 0; $level_one_total = 0; $level_two_status = 0; @@ -1241,7 +1242,11 @@ class PD_Model extends SPARQ_Model { if($value['pd_form_level_order'] == 1){ $level_one_total++;} else if($value['pd_form_level_order'] == 2){$level_two_total++;} } - + //make photo section always answerable true + if($value['form_id'] == 26) + { + $template_forms[$template_key]['isAnswered'] = true; + } if($value['pd_form_level_order'] == 1) { $template_forms[$template_key]['isAnswerable'] = true; diff --git a/api/application/views/smc_creditpd_reports/MWISE.php b/api/application/views/smc_creditpd_reports/MWISE.php index 2572d543..093c1ffb 100644 --- a/api/application/views/smc_creditpd_reports/MWISE.php +++ b/api/application/views/smc_creditpd_reports/MWISE.php @@ -798,7 +798,7 @@ $business_pd_visited_remark = (isset($pd_section_data[8]['business_pd_visited_re echo '

Business Assets Remarks - '.$pd_section_data[8]['common_remarks'].'
'; }?> - +
@@ -856,7 +856,7 @@ $business_pd_visited_remark = (isset($pd_section_data[8]['business_pd_visited_re { if(is_numeric($fy_key)) { - echo ''; + echo ''; } } ?> @@ -871,7 +871,7 @@ $business_pd_visited_remark = (isset($pd_section_data[8]['business_pd_visited_re if(is_numeric($fy_key)) { // echo ''; - echo ''; + echo ''; } } ?> @@ -966,7 +966,7 @@ $business_pd_visited_remark = (isset($pd_section_data[8]['business_pd_visited_re { if(is_numeric($fy_key)) { - echo ''; + echo ''; } } ?> @@ -979,7 +979,7 @@ $business_pd_visited_remark = (isset($pd_section_data[8]['business_pd_visited_re { if(is_numeric($fy_key)) { - echo ''; + echo ''; } } ?> @@ -992,7 +992,7 @@ $business_pd_visited_remark = (isset($pd_section_data[8]['business_pd_visited_re { if(is_numeric($fy_key)) { - echo ''; + echo ''; } } ?> @@ -1007,7 +1007,7 @@ $business_pd_visited_remark = (isset($pd_section_data[8]['business_pd_visited_re
'.$rupee_symbol.' '. MYUTIL::customIndianNumberFormat($fy_value['net_profit']).''.($fy_value['net_profit'] != '' ? $rupee_symbol.' '. MYUTIL::customIndianNumberFormat($fy_value['net_profit']) : '-').''.round((($fy_value['net_profit'] / $fy_value['sales_revenue'] ) * 100 ),2).'%'.($fy_value['net_profit_sales_percent']).''.($fy_value['net_profit_sales_percent'] != '' ? $fy_value['net_profit_sales_percent'] : '-').''.number_format($fy_value['debtor_days_cet'],2,'.','') .''.($fy_value['debtor_days_cet'] != '' ? number_format($fy_value['debtor_days_cet'],2,'.','') : '-') .''.number_format($fy_value['creditor_days_cet'],2,'.','') .''.($fy_value['creditor_days_cet'] != '' ? number_format($fy_value['creditor_days_cet'],2,'.','') : '-') .''.number_format($fy_value['inventory_days_cet'],2,'.','') .''.( $fy_value['inventory_days_cet'] != '' ? number_format($fy_value['inventory_days_cet'],2,'.','') : '-') .'
'?> - '?> + '?> '?> @@ -1035,8 +1035,8 @@ $business_pd_visited_remark = (isset($pd_section_data[8]['business_pd_visited_re
Sales / Revenue ('.$rupee_symbol.') '.$rupee_symbol.' '. MYUTIL::customIndianNumberFormat($pd_section_data[10]['sales_amount']) .'
Net Profit or (Net Loss) to Sales % '. $pd_section_data[10]['net_profit_to_sales_percent'] .'
Net Profit or (Net Loss) to Sales % '. ( $pd_section_data[10]['net_profit_to_sales_percent'] != ''? $pd_section_data[10]['net_profit_to_sales_percent'] : '-').'
Net Profit / (Net Loss) ('.$rupee_symbol.') '.$rupee_symbol.' '.MYUTIL::customIndianNumberFormat($pd_section_data[10]['net_profit_rs']) .'
- -
+ +
Supplier Details
@@ -1170,11 +1170,13 @@ Business run by the applicant + + @@ -1208,9 +1210,14 @@ Business run by the applicant'; // } } - + } + else//if no count + { + echo ''; + } ?>
Business Banking & Personal Banking
Sr. No. Account Holder's Name'.( ucfirst($pd_section_data[13]['estimated_uom']) ) .'
Banking Details Not Available
+
@@ -1246,6 +1253,7 @@ Business run by the applicantExisting Loan Obligations < /table>--> +
@@ -1253,6 +1261,7 @@ Business run by the applicant + @@ -1274,6 +1283,11 @@ Business run by the applicant'; } + } + else// if no count + { + echo ''; + } if($pd_section_data[15]['common_remarks']) { echo ''; @@ -1286,7 +1300,7 @@ Business run by the applicant
Existing Loan Obligations
Sr. No. Loan
Type
'. ($key15 + 1) .''. $value15['loan_type'] .''.$rupee_symbol.MYUTIL::customIndianNumberFormat($value15['loan_amount']).''.$value15['lender_name'].''.$value15['loan_taken_by'].''.$rupee_symbol.' '.MYUTIL::customIndianNumberFormat($value15['instalment_amount']).''.$value15['instalment_frequency'].''.($value15['original_tenure_months'] != '' ? $value15['original_tenure_months'] : 'NA').''.($value15['current_tenure_months'] != '' ? $value15['current_tenure_months'] : 'NA').''.($value15['elapsed_tenure_months'] != '' ? $value15['elapsed_tenure_months'] : 'NA') .'
Existing Loan Obligations Not Available
Remarks '. $pd_section_data[15]['common_remarks'] .'
- +