From e96e6060cac3aa6f3079b05a4196ab567fb104dd Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 5 Feb 2019 17:56:10 +0530 Subject: [PATCH] AI CHANGED --- api/application/config/database.php | 2 +- api/application/controllers/PD_Controller.php | 33 +- .../helpers/getprocessedjson_helper.php | 345 ++++++++++++++++-- .../models/Common_Masters_Model.php | 16 +- 4 files changed, 354 insertions(+), 42 deletions(-) diff --git a/api/application/config/database.php b/api/application/config/database.php index 99da2c96..6ab0f361 100644 --- a/api/application/config/database.php +++ b/api/application/config/database.php @@ -70,7 +70,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); | The $query_builder variables lets you determine whether or not to load | the query builder class. */ -$active_group = 'test'; +$active_group = 'dev'; $query_builder = TRUE; $db['dev'] = array( diff --git a/api/application/controllers/PD_Controller.php b/api/application/controllers/PD_Controller.php index 6f7fdd86..11cf87ef 100644 --- a/api/application/controllers/PD_Controller.php +++ b/api/application/controllers/PD_Controller.php @@ -2164,9 +2164,9 @@ class PD_Controller extends REST_Controller { // break; // case 2: - // $processed_json = $records; + // $processed_json = GETPROCESSEDJSON::convertClientForm($records,$formid); // break; - // case 4: + // case 4: $processed_json = GETPROCESSEDJSON::convertOtherAssetForm($records,$formid); // $processed_json = $records; // break; // case 5: @@ -2227,9 +2227,9 @@ class PD_Controller extends REST_Controller { // //default: // //echo "Something Wrong! Form ID did not match, Contact System Administrator"; - //} + // } - //die(); + // die(); /*****End of Form Specific funcitons to convert RAW JSON Data to Processed JSON DATA*******/ unset($records['pdid']); @@ -2406,8 +2406,14 @@ class PD_Controller extends REST_Controller { //print_r($result_array);die(); $result_array['final_data'] = array(); $fine = $this->calculateAssessedIncome($pd_id); + //print_r($fine);die(); if($fine != null) { + $fine['sales_revenue_details'] = $result_array['sales_calculated_by_itemwise']; + $fine['other_business_income_details'] = $result_array['othre_business_income']; + $fine['purchase_details'] = $result_array['purchase_details']; + $fine['business_expense_details'] = $result_array['business_expenses']; + $fine['house_hold_expense_details'] = $result_array['house_hold_expenses']; $result_array['final_data'][] = $fine; } @@ -2500,7 +2506,7 @@ class PD_Controller extends REST_Controller { $count = 0; foreach($records as $rec_key => $record) { - if($recordrecordrecordrecord['sci_id'] != null || $record['sci_id'] != "") + if($record['sci_id'] != null || $record['sci_id'] != "") { $where_condition_array = array('sci_id'=>$record['sci_id']); $id = $this->PD_Model->updateRecords($record,SALESCALCULATEDBYITEMWISE,$where_condition_array); @@ -2941,7 +2947,7 @@ class PD_Controller extends REST_Controller { if(count($other_business_income)){$other_business_income_flag = 1;} - if(($household_expenses_flag == 1 && $business_expenses_flag == 1) && ($sales_declared_by_customer_flag == 1 || $sales_calculated_by_itemwise_flag == 1 || $sales_by_item_monthwise_flag == 1)) + if(($business_expenses_flag == 1) && ($sales_declared_by_customer_flag == 1 || $sales_calculated_by_itemwise_flag == 1 || $sales_by_item_monthwise_flag == 1)) { $total_sales_itemwise = 0; $sales_monthwise = array(); @@ -3132,24 +3138,24 @@ class PD_Controller extends REST_Controller { } } /**************************Gross Profit calculation end***************/ - $calculated_data['income']['sales_revenue'] = $final_sales_avg_value; - $calculated_data['income']['other_business_income'] = $overall_other_business_income_total; - $calculated_data['expense']['purchase'] = $overall_purchase_total; + $calculated_data['sales_revenue'] = $final_sales_avg_value; + $calculated_data['other_business_income'] = $overall_other_business_income_total; + $calculated_data['purchase'] = $overall_purchase_total; if(isset($gross_profit_calculation_type[0])) { if($gross_profit_calculation_type[0]['mode'] == 1 || $gross_profit_calculation_type[0]['margin'] == 1) { $calculated_data['gross_profit'] = $estimation_of_gross_profit; - $calculated_data['other_business_income'] = $overall_other_business_income_total; + //$calculated_data['other_business_income'] = $overall_other_business_income_total; } else { $calculated_data['gross_profit'] =( $net_profit + $overall_business_expenses_total); - $calculated_data['other_business_income'] = $overall_other_business_income_total; + //$calculated_data['other_business_income'] = $overall_other_business_income_total; } } - $calculated_data['expense']['business_expense'] = $overall_business_expenses_total; - $calculated_data['expense']['net_profit'] = $net_profit; + $calculated_data['business_expense'] = $overall_business_expenses_total; + $calculated_data['net_profit'] = $net_profit; $calculated_data['net_margin'] = $net_profit / $final_sales_avg_value; @@ -4572,6 +4578,7 @@ class PD_Controller extends REST_Controller { $pdid = $this->post('pd_id'); //echo $pdid; //Get Details From General Full + $final_names = array(); $fields = array('json'); $where_condition_array = array('isactive' => 1,'fk_form_id' =>18,'fk_pd_id' => $pdid); $general_data = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDFORMDETAILSJSON); diff --git a/api/application/helpers/getprocessedjson_helper.php b/api/application/helpers/getprocessedjson_helper.php index 23ca4755..29c67f9f 100644 --- a/api/application/helpers/getprocessedjson_helper.php +++ b/api/application/helpers/getprocessedjson_helper.php @@ -848,7 +848,7 @@ class GETPROCESSEDJSON /*****************########## START GENERAL FORM DETAILS ##########**************/ public static function convertGeneralDetailsForm($raw_json,$formid) { - echo "called"; + //echo "called"; $CI =& get_instance(); $master_tables_field_names = $CI->config->item('master_tables_field_names'); $master_tables_pkid = $CI->config->item('master_tables_pkid'); @@ -860,44 +860,339 @@ class GETPROCESSEDJSON $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(); - echo "****************"; + //print_r($master_keys);die(); + //echo "****************"; if(!empty($raw_json) && !empty($master_keys)) { if(array_key_exists('individuals',$raw_json)) { + //echo "exists"; foreach($raw_json['individuals'] as $individuals_key => $individual) { - 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['family_details']); - - $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']; - + foreach($individual as $key => $value) + { + if($value != "" || $value != null) + { + + foreach($master_keys as $master_key => $master_value) + { + if(!strcmp($key,$master_value['key']) && $master_value['ismaster'] == 1) + { + //echo $key.'---'.$master_value['key']; + + $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']);echo "*****"; + $key = $key . '_master'; + $raw_json['individuals'][$individuals_key][$key] = $result_data[0]['name']; + + } + } } - } - } + } + } + } + + if(array_key_exists('companies',$raw_json)) + { + //echo "exists"; + foreach($raw_json['companies'] as $company_key => $company) + { + foreach($company as $key => $value) + { + if($value != "" || $value != null) + { + + foreach($master_keys as $master_key => $master_value) + { + if(!strcmp($key,$master_value['key']) && $master_value['ismaster'] == 1) + { + //echo $key.'---'.$master_value['key']; + + $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']);echo "*****"; + $key = $key . '_master'; + $raw_json['companies'][$company_key][$key] = $result_data[0]['name']; + + } + } + } + } + } + } + + } + + if(array_key_exists('persons_with_relationships',$raw_json)) + { + //echo "exists"; + foreach($raw_json['persons_with_relationships'] as $persons_with_relationship_key => $persons_with_relationship) + { + foreach($persons_with_relationship as $key => $value) + { + if($value != "" || $value != null) + { + + foreach($master_keys as $master_key => $master_value) + { + if(!strcmp($key,$master_value['key']) && $master_value['ismaster'] == 1) + { + //echo $key.'---'.$master_value['key']; + + $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']);echo "*****"; + $key = $key . '_master'; + $raw_json['persons_with_relationships'][$persons_with_relationship_key][$key] = $result_data[0]['name']; + + } + } + } + } + } + } + + } + + + if(array_key_exists('company_with_relationships',$raw_json)) + { + foreach($raw_json['company_with_relationships'] as $company_with_relationship_key => $company_with_relationship) + { + if($company_with_relationship['applicant_name'] != "" || $company_with_relationship['applicant_name'] != null) + { + $CI->db->SELECT( $master_tables_field_names['PDAPPLICANTSDETAILS'] ); + $CI->db->FROM(PDAPPLICANTSDETAILS); + //$CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['PDAPPLICANTSDETAILS'] ,$company_with_relationship['applicant_name']); + $name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + //print_r($name); + if(count($name)) + { + $raw_json['company_with_relationships'][$company_with_relationship_key]['applicant_name_master'] = $name[0][$master_tables_field_names['PDAPPLICANTSDETAILS']]; + } + + + + } + + if($company_with_relationship['company_relationship'] != "" || $company_with_relationship['company_relationship '] != null) + { + $CI->db->SELECT( $master_tables_field_names['COMPANYRELATIONSHIPS'] ); + $CI->db->FROM(COMPANYRELATIONSHIPS); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['COMPANYRELATIONSHIPS'] ,$company_with_relationship['company_relationship']); + $name= $CI->db->GET()->result_array(); + //print_r($CI->db->last_query()); + if(count($name)) + { + $raw_json['company_with_relationships'][$company_with_relationship_key]['company_relationship_master'] = $name[0][$master_tables_field_names['COMPANYRELATIONSHIPS']]; + } + + } + + if($company_with_relationship['relation_to_company'] != "" || $company_with_relationship['relation_to_company'] != null) + { + foreach($raw_json['companies'] as $company) + { + if($company['company_order_id'] == $company_with_relationship['relation_to_company']) + { + $raw_json['company_with_relationships'][$company_with_relationship_key]['company_name'] = $company['company_name']; + } + } } } } - die(); + + } + + + } + return $raw_json; + //print_r($raw_json); } /*****************########## 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) + { + $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)) + { + $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['PROPERTIES'] ); + $CI->db->FROM(PROPERTIES); + $CI->db->WHERE('isactive',1); + $CI->db->WHERE( $master_tables_pkid['PROPERTIES'] ,$business_assets_detail['business_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['business_assets_details'][$business_assets_detail_key]['business_details'][0]['property_type_master'] = $assest_mode_name[0][$master_tables_field_names['PROPERTIES']]; + } + } + } + } + } + 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); + + // 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($CI->db->last_query()); + 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']]; + } + } + + + 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) + { + + } + /*****************########## END OF CLIENT FORM DETAILS ##########**************/ } diff --git a/api/application/models/Common_Masters_Model.php b/api/application/models/Common_Masters_Model.php index 96024a58..3e8f2a0a 100644 --- a/api/application/models/Common_Masters_Model.php +++ b/api/application/models/Common_Masters_Model.php @@ -18,14 +18,24 @@ class Common_Masters_Model extends SPARQ_Model { public function selectCustomMasterRecords($table_constant) { + $master_tables_field_names = $this->config->item('master_tables_field_names'); $master_tables_pkid = $this->config->item('master_tables_pkid'); - - $order = $master_tables_field_names[$table_constant]; + if($table_constant == 'PDLOCATIONAPPROACH') + { + $order = $master_tables_pkid[$table_constant]; $master_data = $this->db->SELECT('*')->FROM(constant($table_constant))->ORDER_BY('is_others')->ORDER_BY($order)->GET()->result_array(); + return $master_data; + } + else + { + $order = $master_tables_field_names[$table_constant]; + $master_data = $this->db->SELECT('*')->FROM(constant($table_constant))->ORDER_BY('is_others')->ORDER_BY($order)->GET()->result_array(); + return $master_data; + } // print_r($this->db->last_query()); // die(); - return $master_data; + } /**