diff --git a/api/application/config/constants.php b/api/application/config/constants.php index e24185f2..3ef5e6f3 100644 --- a/api/application/config/constants.php +++ b/api/application/config/constants.php @@ -133,6 +133,7 @@ defined('ARCHIVED') OR define('ARCHIVED','ARCHIVED'); defined('CANCELLED') OR define('CANCELLED','CANCELLED'); defined('DRAFT') OR define('DRAFT','DRAFT'); defined('RESCHEDULED') OR define('RESCHEDULED','RESCHEDULED'); +defined('ADD_ON_PENDING') OR define('ADD_ON_PENDING','ADD_ON_PENDING'); /*******************End Of Constants PD status**************************/ @@ -540,6 +541,12 @@ defined('PDCOMPANYID') OR define('PDCOMPANYID','pd_company_id'); defined('SCRIPTS') OR define('SCRIPTS','m_scripts'); defined('SCRIPTSID') OR define('SCRIPTSID','script_id'); +defined('PDPURCHASEBILLWISE') OR define('PDPURCHASEBILLWISE','t_pd_purchase_billwise'); +defined('PDPURCHASEBILLWISEID') OR define('PDPURCHASEBILLWISEID','pbw_id'); + +defined('PDPURCHASEBILLWISECHILD') OR define('PDPURCHASEBILLWISECHILD','t_pd_purchase_billwise_child'); +defined('PDPURCHASEBILLWISECHILDID') OR define('PDPURCHASEBILLWISECHILDID','pbwc_id'); + diff --git a/api/application/config/customconfig_one.php b/api/application/config/customconfig_one.php index e91cdf0a..ced548a0 100644 --- a/api/application/config/customconfig_one.php +++ b/api/application/config/customconfig_one.php @@ -58,4 +58,6 @@ $config['sms_gupshup_url'] = 'http://enterprise.smsgupshup.com/GatewayAPI/rest?m $config['master_tables_field_names'] = array('INDUSTRYCLASSIFICATION' => 'name','UOM' => 'name','OCCUPATIONMEMBERS' => 'name','EDUQUALIFICATION' => 'qualification_name', 'TYPEOFACTIVITY' => 'name','RELATIONSHIPS' => 'name','FREQUENCY' => 'name', 'CUSTOMERBEHAVIOUR' => 'description', 'CUSTOMERSEGMENT' => 'name','DESIGNATION' => 'short_name', 'EARNINGMEMBERSSTATUS' => 'earning_member_status','EDUQUALIFICATION' => 'qualification_name','ADDRESSTYPE' => 'address_type','LOCALITY' => 'locality_name','ASSETTYPE' => 'name','PROPERTIES' => 'name','INVESTMENTTYPE' => 'name','INSURANCETYPE' => 'name','PERSONSMET' => 'person_met_name','RESIDENCEOWNERSHIP' => 'name','PAYMENTMODE' => 'name','ACCOUNTTYPE' => 'name','SOURCEOFOTHERINCOME' => 'name','MORTAGEPROPERTYTYPE' => 'name','ENDUSEOFLOAN' => 'enduse_of_loan','SOURCEOFBALANCETRANSFER' => 'name', 'STATUSOFCONSTRUCTION' => 'name','BTLENDERLIST'=>'lender_name','MORTAGEPROPERTIES'=>'property_name','EXISTINGLOANTYPES'=>'loan_type_name','PDAPPLICANTSDETAILS'=>'applicant_name','RELATIONWITHBUSINESS'=>'relation_with_business_name','BUSINESSENTITYTYPE'=>'business_entity_type_name','COMPANYRELATIONSHIPS'=>'name','STATE'=>'name','CITY'=>'name','COUNTRY'=>'country_name','BOUNCEMASTER'=>'bounce_reason_name','BUSINESSEXPENSES'=>'expense_item','BUSINESSINCOME'=>'business_income_item','COMMENTSONLOCALITY'=>'rating','COMPANY'=>'company_id','LOCALITY'=>'locality_name','NONINDIVIDUALENTITIES'=>'non_individual_entity_name','PDFORMS'=>'pd_form_name','PDLOCATIONAPPROACH'=>'description','PDTYPE'=>'type_name','PDNOTIFICATION'=>'pd_status','QUESTIONCATEGORY'=>'category_name','ROLES'=>'role_name','SUBPRODUCTS'=>'name','TITLES'=>'name','PINCODE'=>'pincode','PRODUCTS'=>'name','ENTITYTYPE'=>'name','PDTEAM'=>'team_name','ENTITY'=>'short_name','PDSTATUS'=>'pd_status_name','LISTOFMASTERS'=>'master_name','OTPREJECTION'=>'rejection_reason','ENDUSEOFTOPUP'=>'end_use_of_topup','VEHICLETYPE'=>'vehicle_type_name','PDOFFICERRECOMMENDATIONS'=>'pdofficer_recommendation','REGIONS'=>'name','PRICINGINFO'=>'pricing_info_id'); $config['master_tables_pkid'] = array('INDUSTRYCLASSIFICATION' => 'industry_classification_id','UOM' => 'uom_id','OCCUPATIONMEMBERS' => 'occupation_non_earning_member_id','EDUQUALIFICATION' => 'qualification_name', 'TYPEOFACTIVITY' => 'type_of_activity_id','RELATIONSHIPS' => 'relationship_id','FREQUENCY' => 'frequency_id', 'CUSTOMERBEHAVIOUR' => 'customer_behaviour_id', 'CUSTOMERSEGMENT' => 'customer_segment_id','DESIGNATION' => 'designation_id', 'EARNINGMEMBERSSTATUS' => 'earning_member_status_id','EDUQUALIFICATION' => 'qualification_id','ADDRESSTYPE' => 'address_type_id','LOCALITY' => 'locality_id','ASSETTYPE' => 'id','PROPERTIES' => 'id','INVESTMENTTYPE' => 'id','INSURANCETYPE' => 'id','PERSONSMET' => 'person_met_id','RESIDENCEOWNERSHIP' => 'id','PAYMENTMODE' => 'id','ACCOUNTTYPE' => 'id','SOURCEOFOTHERINCOME' => 'id','MORTAGEPROPERTYTYPE' => 'id','ENDUSEOFLOAN' => 'enduse_of_loan_id','SOURCEOFBALANCETRANSFER' => 'id', 'STATUSOFCONSTRUCTION' => 'id','MORTAGEPROPERTIES' => 'mortage_property_id','BTLENDERLIST'=>'bt_lender_list_id','EXISTINGLOANTYPES'=>'existing_loan_type_id','PDAPPLICANTSDETAILS'=>'pd_co_applicant_id','RELATIONWITHBUSINESS'=>'relation_with_business_id','BUSINESSENTITYTYPE'=>'business_entity_type_id','COMPANYRELATIONSHIPS'=>'company_relationship_id','STATE'=>'state_id','CITY'=>'city_id','COUNTRY'=>'country_id','BOUNCEMASTER'=>'bounce_id','BUSINESSEXPENSES'=>'expense_item_id','BUSINESSINCOME'=>'business_income_id','COMMENTSONLOCALITY'=>'comments_on_locality_id','COMPANY'=>'name','LOCALITY'=>'locality_id','NONINDIVIDUALENTITIES'=>'non_individual_entity_id','PDFORMS'=>'form_id','PDLOCATIONAPPROACH'=>'pd_location_approach_id','PDTYPE'=>'pd_type_id','PDNOTIFICATION'=>'pdnotification_id','QUESTIONCATEGORY'=>'question_category_id','ROLES'=>'role_id','SUBPRODUCTS'=>'subproduct_id','TITLES'=>'title_id','PINCODE'=>'pincode_id','PRODUCTS'=>'product_id','ENTITYTYPE'=>'entity_type_id','PDTEAM'=>'pdteam_id','ENTITY'=>'entity_id','PDSTATUS'=>'pd_status_id','LISTOFMASTERS'=>'master_id','OTPREJECTION'=>'otp_rejection_id','ENDUSEOFTOPUP'=>'end_use_of_topup_id','VEHICLETYPE'=>'vehicle_type_id','PDOFFICERRECOMMENDATIONS'=>'pdofficer_recommendation_id','REGIONS'=>'region_id','PRICINGINFO'=>'pricing_info_id'); + +$config['parent_forms'] = array(0,18,10,7,4,6,8,9,20,5);// 0 added for dummy ?> \ No newline at end of file diff --git a/api/application/config/routes.php b/api/application/config/routes.php index be5d6bc4..a47cf8af 100644 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -172,6 +172,7 @@ $route['saveAssessedIncomePurchaseDetails'] = 'PD_Controller/saveAssessedIncomeP $route['saveAssessedIncomeBusinessExpenses'] = 'PD_Controller/saveAssessedIncomeBusinessExpenses'; $route['saveAssessedIncomeHouseholdExpenses'] = 'PD_Controller/saveAssessedIncomeHouseholdExpenses'; $route['saveAssessedIncomeMonthwiseItems'] = 'PD_Controller/saveAssessedIncomeMonthwiseItems'; +$route['saveAssessedIncomePurchaseBillwise'] = 'PD_Controller/saveAssessedIncomePurchaseBillwise'; $route['calculateAssessedIncome'] = 'PD_Controller/calculateAssessedIncome'; $route['saveAssessedIncomeCalculateMode'] = 'PD_Controller/saveAssessedIncomeCalculateMode'; $route['saveOtherBusinessIncome'] = 'PD_Controller/saveOtherBusinessIncome'; diff --git a/api/application/controllers/PD_Controller.php b/api/application/controllers/PD_Controller.php index 3d084ec3..579b9544 100644 --- a/api/application/controllers/PD_Controller.php +++ b/api/application/controllers/PD_Controller.php @@ -490,7 +490,7 @@ class PD_Controller extends REST_Controller { if(!empty($pd_document_from_mobile)) { - $this->saveBase64Images($pd_id,null,$pd_document_from_mobile); + $this->saveBase64Images($pd_id,null,null,$pd_document_from_mobile); // foreach($pd_document_from_mobile as $iter => $doc) // { // $temp_base64_string = $doc['image']; @@ -635,11 +635,12 @@ class PD_Controller extends REST_Controller { public function updatePDMaster_post() { $pd_details = $this->post('records'); - + if(isset($pd_details['pd_id']) && $pd_details['pd_id'] != "") { - + $exist_pd_details = $this->PD_Model->getPDMasterDetails($pd_details['pd_id']); + //print_r($exist_pd_details); if(isset($pd_details['pd_status']) && $pd_details['pd_status'] == INITIATED) { @@ -721,22 +722,40 @@ class PD_Controller extends REST_Controller { } } - //Update Address table,if primary address choosed - $primary_address_id = isset($pd_details['fk_primary_address_id'])?$pd_details['fk_primary_address_id']:null; - $pd_details['fk_address_id'] = $primary_address_id; + + $primary_address_id = null; + //echo "primary_address_id--".$primary_address_id; + if( $exist_pd_details[0]['fk_primary_address_id'] == null && $exist_pd_details[0]['is_child'] == 0)//Master PD only + { + $primary_address_id = isset($pd_details['fk_primary_address_id'])?$pd_details['fk_primary_address_id']:null; + $pd_details['fk_address_id'] = $primary_address_id; + } + + // if( $exist_pd_details[0]['parent_pd_id'] == null) + // { + // $pd_details['parent_pd_id'] = isset($pd_details['parent_pd_id']) ? $pd_details['parent_pd_id'] : null; + // } + if( $exist_pd_details[0]['is_child'] == 0 && $exist_pd_details[0]['parent_pd_id'] == null) + { + $pd_details['parent_pd_id'] = $pd_details['pd_id']; + } + + $where_condition_array = array('pd_id' => $pd_details['pd_id']); $pd_id_modified = $this->PD_Model->updateRecords($pd_details,PDTRIGGER,$where_condition_array); - + //Update Address table,if primary address choosed if($primary_address_id != null) { $where_condition_array = array('pd_address_id' => $primary_address_id); $temp_data = array('is_primary' => 1,'assigned_pd' => $pd_details['pd_id']); + $id = $this->PD_Model->updateRecords($temp_data,PDADDRESS,$where_condition_array); } + if($pd_id_modified != null || $pd_id_modified != '' && $count != 0) { PDALERTS::pdnotification($pd_details['pd_id']); @@ -767,6 +786,7 @@ class PD_Controller extends REST_Controller { if(count($parent_pd_details)) { $newpd['fk_lender_id'] = $parent_pd_details[0]['fk_lender_id']; + $newpd['pd_date_of_initiation'] = $parent_pd_details[0]['pd_date_of_initiation']; $newpd['fk_entity_billing_id'] = $parent_pd_details[0]['fk_entity_billing_id']; $newpd['lender_applicant_id'] = $parent_pd_details[0]['lender_applicant_id']; $newpd['fk_product_id'] = $parent_pd_details[0]['fk_product_id']; @@ -780,24 +800,34 @@ class PD_Controller extends REST_Controller { $newpd['fk_customer_segment'] = $pd_details['fk_customer_segment']; $newpd['fk_address_id'] = $pd_details['fk_address_id']; $newpd['parent_pd_id'] = $pd_details['parent_pd_id']; - $newpd['fk_pd_allocated_to'] = $pd_details['fk_pd_allocated_to'] ? $pd_details['fk_pd_allocated_to'] : null; - $newpd['scheduled_on'] = $pd_details['scheduled_on'] ? $pd_details['scheduled_on'] : null; + //$newpd['fk_pd_allocated_to'] = $pd_details['fk_pd_allocated_to'] ? $pd_details['fk_pd_allocated_to'] : null; + //$newpd['scheduled_on'] = $pd_details['scheduled_on'] ? $pd_details['scheduled_on'] : null; $newpd['fk_pd_template_id'] = $this->assignPDTempalate(array('lender' => $newpd['fk_lender_id'],'product' => $newpd['fk_product_id'],'customer_segment' => $newpd['fk_customer_segment'])); - if($newpd['fk_pd_template_id'] != "" || $newpd['fk_pd_template_id'] != null) - { - $logger = MYLOG::logFunction(); - $logger->info("TEMPLATE ASSIGN FUNCTIONALTIY".$newpd['fk_pd_template_id']." CHOOSED",array('ENV'=>ENVIRONMENT,'PDID' => 'Addtional PD','Pre-Status' => null,'Current_status' => $newpd['pd_status'])); - - $dataToBot = array('ENV'=>ENVIRONMENT,'Task Name'=>'PD Template Assign','Template ID'=>$newpd['fk_pd_template_id'] ,'PDID'=> 'Addtional PD','Method' => 'UpdatePDMaster - Addtional PD Creation','Pre-Status' => null,'Current_status' => $newpd['pd_status']); - MYHTTPCLIENT::sendPOST($dataToBot); - } $pd_id = $this->PD_Model->saveRecords($newpd,PDTRIGGER); if($pd_id != "" || $pd_id != null) { + //Save Assigned Address Details to newly created Addtional PD in address table - HOLD TEMP (NOT DONE) + // for this have to change getPDAddress model funcitons + // $current_address = $this->PD_Model->getPDAddress(null,$newpd['fk_address_id']); + // if(count($current_address)) + // { + // $temp_address = $current_address[0]; + // $tem_address['pd_address_id'] = null; + + // $id = $this->PD_Model->saveRecords($tem_address,PDADDRESS); + // } + + $logger = MYLOG::logFunction(); + $logger->info("TEMPLATE ASSIGN FUNCTIONALTIY CALLED AND TEMPLATED ID - ".$newpd['fk_pd_template_id']." CHOOSED",array('ENV'=>ENVIRONMENT,'Parent-PDID' => $newpd['parent_pd_id'],'Addresss ID'=>$newpd['fk_address_id'] ,'PDID' => $pd_id,'PD Type' => "Addtional PD",'Current_status' => $newpd['pd_status'])); + + $dataToBot = array('ENV'=>ENVIRONMENT,'Task Name'=>'PD Template Assign','Template ID'=>$newpd['fk_pd_template_id'] ,'PDID' => $pd_id,'PD Type' => "Addtional PD",'Method' => 'UpdatePDMaster - Addtional PD Creation','Pre-Status' => null,'Current_status' => $newpd['pd_status']); + MYHTTPCLIENT::sendPOST($dataToBot); + + //update Assiged PD to Address Table $where_condition_array = array('pd_address_id' => $newpd['fk_address_id']); $temp_data = array('assigned_pd' => $pd_id); @@ -807,7 +837,7 @@ class PD_Controller extends REST_Controller { //PDALERTS::pdnotification($newpd['pd_id']); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; - $data['records'] = pd_id; + $data['records'] = $pd_id; $data['msg'] = "Addtional PD Created!"; $this->response($data,REST_Controller::HTTP_OK); } @@ -842,40 +872,47 @@ class PD_Controller extends REST_Controller { } - //While PD Completion stage, send lenth of PD address so get complete or addonpd + //While PD Completion stage, send lenth of PD address public function getPDCompleteDetails_post() { + + //print_r($this->db->select('*')->from('PD_MIS')->GET()->result_array()); + //echo $this->assignPDTempalate(array()); + //die(); $records = $this->post('records'); $pdid = $records['pd_id']; $pd_master_detials = $this->PD_Model->getPDMasterDetails($pdid); if($pd_master_detials[0]['is_child'] == 0)//primary PD { - $address_count = $this->db->SELECT('count(*) as count')->FROM(PDADDRESS)->GET()->result_array(); + $address_count = $this->db->SELECT('count(*) as count')->FROM(PDADDRESS)->WHERE('fk_pd_id',$pdid)->GET()->result_array(); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; - $data['records'] = array('address_count'=>$address_count); + $data['records'] = array('address_count'=>(int)$address_count[0]['count']); $this->response($data,REST_Controller::HTTP_OK); } else// Addtional PD { + $address_count = $this->db->SELECT('count(*) as count')->FROM(PDADDRESS.' as PDADDRESS')->WHERE('PDADDRESS.fk_pd_id',$pd_master_detials[0]['parent_pd_id'])->WHERE('assigned_pd is null')->GET()->result_array(); + //print_r($this->db->last_query()); + //If this one is addtional PD $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; - $data['records'] = array('address_count'=>0); + $data['records'] = array('address_count' => (int)$address_count[0]['count']); $this->response($data,REST_Controller::HTTP_OK); } } public function assignPDTempalate($data) - { - // Template Re assign Functionality - - $res_array = array(); + { + $logger = MYLOG::logFunction(); + $logger->info("TEMPLATE ASSIGN FUNCTIONALTIY CALLED",array('ENV'=>ENVIRONMENT,'DATA' => $data)); + //print_r($data); if(!is_array($data)) { $fields = array('fk_lender_id','fk_product_id','fk_customer_segment','pd_status'); - $where_condition_array = array('pd_id'=>$data); + $where_condition_array = array('pd_id' => $data); $res_array = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDTRIGGER); } @@ -889,6 +926,7 @@ class PD_Controller extends REST_Controller { } else { + //print_r('else'); $where_condition_array = array('fk_lender_id'=>$data['lender'] ,'fk_product_id'=> $data['product'],'fk_customer_segment'=> $data['customer_segment'],'isactive' => 1); } @@ -904,30 +942,33 @@ class PD_Controller extends REST_Controller { } else // CHOOSE GENERIC TEMPLATE// { - // echo "CHOOSE GENERIC "; - if($res_array[0]['fk_customer_segment'] == 1 || $res_array[0]['fk_customer_segment'] == 2) + //echo "CHOOSE GENERIC "; + $customer_segment = isset($res_array[0]['fk_customer_segment']) ? $res_array[0]['fk_customer_segment'] : $data['customer_segment']; + + + if($customer_segment == 1 || $customer_segment == 2) { //SAL - (CASH/CHQ) $templateid = 1; } - else if($res_array[0]['fk_customer_segment'] == 3 || $res_array[0]['fk_customer_segment'] == 5) + else if($customer_segment == 3 || $customer_segment == 5) { //* SENP/SEP - (DI) $templateid = 2; } - else if($res_array[0]['fk_customer_segment'] == 4 || $res_array[0]['fk_customer_segment'] == 6) + else if($customer_segment == 4 || $customer_segment == 6) { //* SENP/SEP - (AI) $templateid = 3; } - else if($res_array[0]['fk_customer_segment'] == 8) + else if($customer_segment == 8) { //* SENP/SEP - (RI) $templateid = 4; } } - return $templateid; + return $templateid; @@ -1765,6 +1806,7 @@ class PD_Controller extends REST_Controller { { $pd_id = ""; $client = ""; + if($this->get('pd_id')) { $pd_id = $this->get('pd_id'); } if($this->get('client')) { $client = $this->get('client'); } if($pd_id != "" || $pd_id != null) @@ -2079,6 +2121,7 @@ class PD_Controller extends REST_Controller { public function savePDFormDetailsJSON_post() { + $records = $this->post('records'); $pdid = $records['pdid']; $formid = $records['formid']; @@ -2088,17 +2131,17 @@ class PD_Controller extends REST_Controller { //print_r($records);die(); $parent_pdid = $records['parent_pdid'];; $parent_form_index = null; - $parent_forms = array(0,10,7,4,6,8,9,20);// 0 added for dummy + $parent_forms = $this->config->item('parent_forms'); - if($pd_id != $parent_pdid) + if($pdid != $parent_pdid) { $parent_form_index = array_search($formid,$parent_forms); - $pdid = $parent_form_index != null ? $parent_pd_id : $pdid; + $pdid = $parent_form_index != null ? $parent_pdid : $pdid; $records['pdid'] = $pdid; } - - + // print_r($records); + // die(); if(isset($records['company_id'])) { $company_id = $records['company_id']; @@ -2233,6 +2276,8 @@ class PD_Controller extends REST_Controller { $temp_array = array('fk_form_id'=>$formid,'company_id' => $company_id,'fk_pd_id'=>$pdid,'fk_createdby'=>$createdby,'json'=>$records,'processed_json' => $processed_json); + //print_r($temp_array); + // die(); $id = $this->PD_Model->saveRecords($temp_array,PDFORMDETAILSJSON); if($id != "" || $id != null) { @@ -2256,25 +2301,27 @@ class PD_Controller extends REST_Controller { { $pd_id = $this->post('pd_id'); $pd_form_id = $this->post('pd_form_id'); - $parent_pd_id = $this->post('parent_pd_id');// ? $this->post('parent_pd_id') : null; + $parent_pd_id = $this->post('parent_pdid');// ? $this->post('parent_pd_id') : null; $company_id = $this->post('company_id') ? $this->post('company_id') : null; $parent_form_index = null; - $parent_forms = array(0,18,10,7,4,6,8,9,20);// 0 added for dummy + $parent_forms = $this->config->item('parent_forms'); if($pd_id != $parent_pd_id) { + $parent_form_index = array_search($pd_form_id,$parent_forms); $pd_id = $parent_form_index != null ? $parent_pd_id : $pd_id; } $fields = array('json','processed_json'); $where_condition_array = array('isactive' => 1,'fk_form_id'=>$pd_form_id,'fk_pd_id'=>$pd_id); + if($company_id != null) { $where_condition_array = array('fk_form_id'=>$pd_form_id,'fk_pd_id'=>$pd_id,'company_id' => $company_id,'isactive' => 1); } $rec = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDFORMDETAILSJSON); - //print_r($this->db->last_query());die(); + if(count($rec)) { $data['dataStatus'] = true; @@ -2542,16 +2589,19 @@ class PD_Controller extends REST_Controller { { $pd_id = $this->post('pd_id'); $pd_form_id = $this->post('pd_form_id'); - $result_array = $this->PD_Model->getAssessedIncome($pd_id); - //print_r($result_array);die(); + $company_id = $this->post('company_id') ? $this->post('company_id') : null; + + $result_array = $this->PD_Model->getAssessedIncome($pd_id,$company_id); + $result_array['final_data'] = array(); - $fine = $this->calculateAssessedIncome($pd_id); + $fine = $this->calculateAssessedIncome($pd_id,$company_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['purchase_billwise'] = $result_array['purchase_billwise']; $fine['business_expense_details'] = $result_array['business_expenses']; $fine['house_hold_expense_details'] = $result_array['house_hold_expenses']; $result_array['final_data'][] = $fine; @@ -2849,6 +2899,75 @@ class PD_Controller extends REST_Controller { } } + //Save Purcahse Items billwise + public function saveAssessedIncomePurchaseBillwise_post()//SALESITEMMONTHWISECHILD + { + $records = $this->post('records'); + $count = 0; + foreach($records as $key => $record) + { + + $child_data = array(); + if(array_key_exists('child',$record)) + { + $child_data = $record['child']; + unset($record['child']); + } + $id = ""; + if($record['pbw_id'] != null || $record['pbw_id'] != "") + { + $where_condition_array = array('pbw_id'=>$record['pbw_id']); + $id = $this->PD_Model->updateRecords($record,PDPURCHASEBILLWISE,$where_condition_array); + if($id != "" || $id != null) + { + $count++; + foreach($child_data as $ckey => $child) + { + if($child['pbwc_id'] != "" || $child['pbwc_id'] != null) + { + $where_condition_array = array('pbwc_id'=>$child['pbwc_id']); + $child_id = $this->PD_Model->updateRecords($child,PDPURCHASEBILLWISECHILD,$where_condition_array); + } + else + { + $child['fk_pbw_id'] = $record['pbw_id']; + $child_id = $this->PD_Model->saveRecords($child,PDPURCHASEBILLWISECHILD); + } + } + } + + } + else + { + $id = $this->PD_Model->saveRecords($record,PDPURCHASEBILLWISE); + if($id != "" || $id != null) + { + $count++; + foreach($child_data as $ckey => $child) + { + $child['fk_pbw_id'] = $id; + $child_id = $this->PD_Model->saveRecords($child,PDPURCHASEBILLWISECHILD); + } + } + } + } + + if($count == count($records)) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $id; + $this->response($data,REST_Controller::HTTP_OK); + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; + $data['msg'] = 'Something went wrong! Try Later'; + $this->response($data,REST_Controller::HTTP_OK); + } + } + /********************************************************************************************* *********************************************************************************************/ @@ -3031,7 +3150,7 @@ class PD_Controller extends REST_Controller { /********************************************************************************************* *********************************************************************************************/ - public function calculateAssessedIncome($pd_id) + public function calculateAssessedIncome($pd_id,$company_id) { @@ -3070,12 +3189,13 @@ class PD_Controller extends REST_Controller { $final_sales_avg_value = 0; //Get all Master Details - $result_array = $this->PD_Model->getAssessedIncome($pd_id); + $result_array = $this->PD_Model->getAssessedIncome($pd_id,$company_id); //print_r($result_array); $sales_declared_by_customer = $result_array['sales_declared_by_customer']; $sales_calculated_by_itemwise = $result_array['sales_calculated_by_itemwise']; $sales_by_item_monthwise = $result_array['sales_items_by_monthwise']; $purchases = $result_array['purchase_details']; + $purchase_billwise = $result_array['purchase_billwise']; $business_expenses = $result_array['business_expenses']; $other_business_income = $result_array['othre_business_income']; $household_expenses = $result_array['house_hold_expenses']; @@ -3084,7 +3204,7 @@ class PD_Controller extends REST_Controller { if(count($sales_declared_by_customer)){$sales_declared_by_customer_flag = 1;} if(count($sales_calculated_by_itemwise)){$sales_calculated_by_itemwise_flag = 1;} if(count($sales_by_item_monthwise)){$sales_by_item_monthwise_flag = 1;} - if(count($purchases)){$purchases_flag = 1;} + if(count($purchases) || count($purchase_billwise)){$purchases_flag = 1;} if(count($business_expenses)){$business_expenses_flag = 1;} if(count($household_expenses)){$household_expenses_flag = 1;} if(count($other_business_income)){$other_business_income_flag = 1;} @@ -3117,9 +3237,21 @@ class PD_Controller extends REST_Controller { if($purchases_flag != 0) { - foreach($purchases as $purchase_key => $purchase) + + if($gross_profit_calculation_type[0]['purchase_type'] == 1) { - $overall_purchase_total = $overall_purchase_total + $purchase['annual_purchase_value']; + foreach($purchase_billwise as $purchase_billwise_key => $bill) + { + $overall_purchase_total = $overall_purchase_total + $bill['annual_purchase_value']; + } + + } + else + { + foreach($purchases as $purchase_key => $purchase) + { + $overall_purchase_total = $overall_purchase_total + $purchase['annual_purchase_value']; + } } } @@ -5111,7 +5243,8 @@ class PD_Controller extends REST_Controller { { $records = $this->post('records'); - $res = $this->saveBase64Images($records['pd_id'],$records['formid'],$records['images']); + $company_id = $records['company_id'] ? $records['company_id'] : null; + $res = $this->saveBase64Images($records['pd_id'],$records['formid'],$company_id,$records['images']); if(count($res)) { @@ -5152,7 +5285,7 @@ class PD_Controller extends REST_Controller { } - public function saveBase64Images($pd_id,$form_id = null,$data) + public function saveBase64Images($pd_id,$form_id = null,$company_id,$data) { $count = 0; @@ -5196,6 +5329,7 @@ class PD_Controller extends REST_Controller { if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { $record_data = array('fk_pd_id' => $pd_id,'pd_document_title'=>$title,'pd_document_name'=>$tempdocname,'fk_form_id'=>$form_id); + $record_data['company_id'] = $company_id ? $company_id : null; $id = $this->PD_Model->saveRecords($record_data,PDDOCUMENTS); if($id != null || $id != "") { $count++;} } diff --git a/api/application/docs/temp_base64_image.png b/api/application/docs/temp_base64_image.png index 56ba1ad4..abf3bd76 100755 Binary files a/api/application/docs/temp_base64_image.png and b/api/application/docs/temp_base64_image.png differ diff --git a/api/application/models/PD_Model.php b/api/application/models/PD_Model.php index a81a0d17..db459d16 100644 --- a/api/application/models/PD_Model.php +++ b/api/application/models/PD_Model.php @@ -287,16 +287,31 @@ class PD_Model extends SPARQ_Model { - public function getPDAddress($pdid) + public function getPDAddress($temp_pdid) { + $pdid = $temp_pdid; + $pd_master_detials = $this->getPDMasterDetails($pdid); + $assigned_pd = null; + + if($pd_master_detials[0]['is_child'] == 1) + { + $assigned_pd = $pdid; + $pdid = $pd_master_detials[0]['parent_pd_id']; + + } $this->db->SELECT('PDADDRESS.pd_address_id,PDADDRESS.fk_pd_id,PDADDRESS.assigned_pd, PDADDRESS.addressline1, PDADDRESS.fk_city, PDADDRESS.fk_state,PDADDRESS.pincode as pincode_id,PINCODE.pincode,PDADDRESS.other_pincode,PDADDRESS.isactive,PDADDRESS.createdon,PDADDRESS.updatedon,PDADDRESS.is_visited,CITY.name as city_name,STATE.name as state_name,PDADDRESS.is_primary'); $this->db->FROM(PDADDRESS.' as PDADDRESS'); $this->db->JOIN(STATE.' as STATE','PDADDRESS.fk_state = STATE.state_id','LEFT'); $this->db->JOIN(CITY.' as CITY','PDADDRESS.fk_city = CITY.city_id','LEFT'); $this->db->JOIN(PINCODE.' as PINCODE','PDADDRESS.pincode = PINCODE.pincode_id','LEFT'); $this->db->WHERE('PDADDRESS.fk_pd_id ',$pdid); + if($assigned_pd != null) + { + $this->db->WHERE('PDADDRESS.assigned_pd ',$assigned_pd); + } $this->db->ORDER_BY('PDADDRESS.pd_address_id'); $result_child_array = $this->db->GET()->result_array(); + //print_r($this->db->last_query()); if(count($result_child_array) != 0) { @@ -807,9 +822,10 @@ class PD_Model extends SPARQ_Model { $template_id = ""; - $categories = ""; - $overall_answered_count = 0; - $overall_question_count = 0; + + // $categories = ""; + // $overall_answered_count = 0; + // $overall_question_count = 0; //Get PD Master Details including Template id @param $pd_id $pd_master_detials = $this->getPDMasterDetails($pdid); $pd_applicants_detials = $this->getApplicantsDetails($pdid); @@ -818,100 +834,100 @@ class PD_Model extends SPARQ_Model { $template_id = $pd_master_detials[0]['fk_pd_template_id']; } - if($template_id != "" || $template_id != null) - { + //if($template_id != "" || $template_id != null) + // { - //Get Category, QUestions and Answers @param $template_id - $this->db->SELECT('QUESTIONCATEGORY.category_name,TEMPLATECATEGORYWEIGHTAGE.template_category_weightage_id, TEMPLATECATEGORYWEIGHTAGE.fk_question_category_id, TEMPLATECATEGORYWEIGHTAGE.fk_template_id, TEMPLATECATEGORYWEIGHTAGE.weightage, DATE_FORMAT(TEMPLATECATEGORYWEIGHTAGE.createdon,"%d/%m/%Y") as createdon, TEMPLATECATEGORYWEIGHTAGE.fk_createdby, DATE_FORMAT(TEMPLATECATEGORYWEIGHTAGE.updatedon, "%d/%m/%Y") as updatedon, TEMPLATECATEGORYWEIGHTAGE.isactive, TEMPLATECATEGORYWEIGHTAGE.fk_updatedby'); - $this->db->FROM(TEMPLATECATEGORYWEIGHTAGE .' as TEMPLATECATEGORYWEIGHTAGE'); - $this->db->JOIN(QUESTIONCATEGORY.' as QUESTIONCATEGORY','TEMPLATECATEGORYWEIGHTAGE.fk_question_category_id = QUESTIONCATEGORY.question_category_id'); - // $this->db->JOIN(USERPROFILE.' as USERPROFILE','TEMPLATECATEGORYWEIGHTAGE.fk_createdby = USERPROFILE.userid','LEFT'); - // $this->db->JOIN(USERPROFILE.' as USERPROFILE1','TEMPLATECATEGORYWEIGHTAGE.fk_updatedby = USERPROFILE1.userid','LEFT'); - $this->db->WHERE('TEMPLATECATEGORYWEIGHTAGE.fk_template_id',$template_id); - $categories = $this->db->GET()->result_array(); - //print_r( $categories); - if(count($categories)) - { + // //Get Category, QUestions and Answers @param $template_id + // // $this->db->SELECT('QUESTIONCATEGORY.category_name,TEMPLATECATEGORYWEIGHTAGE.template_category_weightage_id, TEMPLATECATEGORYWEIGHTAGE.fk_question_category_id, TEMPLATECATEGORYWEIGHTAGE.fk_template_id, TEMPLATECATEGORYWEIGHTAGE.weightage, DATE_FORMAT(TEMPLATECATEGORYWEIGHTAGE.createdon,"%d/%m/%Y") as createdon, TEMPLATECATEGORYWEIGHTAGE.fk_createdby, DATE_FORMAT(TEMPLATECATEGORYWEIGHTAGE.updatedon, "%d/%m/%Y") as updatedon, TEMPLATECATEGORYWEIGHTAGE.isactive, TEMPLATECATEGORYWEIGHTAGE.fk_updatedby'); + // // $this->db->FROM(TEMPLATECATEGORYWEIGHTAGE .' as TEMPLATECATEGORYWEIGHTAGE'); + // // $this->db->JOIN(QUESTIONCATEGORY.' as QUESTIONCATEGORY','TEMPLATECATEGORYWEIGHTAGE.fk_question_category_id = QUESTIONCATEGORY.question_category_id'); + // // // $this->db->JOIN(USERPROFILE.' as USERPROFILE','TEMPLATECATEGORYWEIGHTAGE.fk_createdby = USERPROFILE.userid','LEFT'); + // // // $this->db->JOIN(USERPROFILE.' as USERPROFILE1','TEMPLATECATEGORYWEIGHTAGE.fk_updatedby = USERPROFILE1.userid','LEFT'); + // // $this->db->WHERE('TEMPLATECATEGORYWEIGHTAGE.fk_template_id',$template_id); + // // $categories = $this->db->GET()->result_array(); + // //print_r( $categories); + // if(count($categories)) + // { - foreach($categories as $category_key => $category) - { + // foreach($categories as $category_key => $category) + // { - $this->db->SELECT('QUESTIONS.question_id,QUESTIONS.question,TEMPLATEQUESTION.template_question_id, TEMPLATEQUESTION.fk_template_id, TEMPLATEQUESTION.fk_question_id, TEMPLATEQUESTION.question_weightage, TEMPLATEQUESTION.question_answerable_by,TEMPLATEQUESTION.fk_template_question_category_id, TEMPLATEQUESTION.isactive,QUESTIONS.fk_question_answertype,QUESTIONANSWERTYPE.answer_type_name,PDDETAIL.pd_detail_id'); - //$this->db->FROM(TEMPLATEQUESTION.' as TEMPLATEQUESTION'); - $this->db->FROM(TEMPLATEQUESTION.' as TEMPLATEQUESTION'); - $this->db->JOIN(QUESTIONS.' as QUESTIONS','TEMPLATEQUESTION.fk_question_id = QUESTIONS.question_id'); - $this->db->JOIN(QUESTIONANSWERTYPE.' as QUESTIONANSWERTYPE','QUESTIONS.fk_question_answertype = QUESTIONANSWERTYPE.question_answer_type_id'); - $this->db->JOIN(PDDETAIL.' as PDDETAIL',"QUESTIONS.question_id = PDDETAIL.fk_question_id AND PDDETAIL.fk_pd_id = $pdid",'LEFT'); - // $this->db->JOIN(USERPROFILE.' as USERPROFILE','TEMPLATEQUESTION.fk_createdby = USERPROFILE.userid','LEFT'); - // $this->db->JOIN(USERPROFILE.' as USERPROFILE1','TEMPLATEQUESTION.fk_updatedby = USERPROFILE1.userid','LEFT'); - $this->db->WHERE('TEMPLATEQUESTION.fk_template_question_category_id',$category['fk_question_category_id']); - $this->db->WHERE('TEMPLATEQUESTION.fk_template_id', $template_id); - $this->db->ORDER_BY('QUESTIONS.question_id'); - //$this->db->WHERE('TEMPLATEQUESTION.fk_template_id',$template_id); + // $this->db->SELECT('QUESTIONS.question_id,QUESTIONS.question,TEMPLATEQUESTION.template_question_id, TEMPLATEQUESTION.fk_template_id, TEMPLATEQUESTION.fk_question_id, TEMPLATEQUESTION.question_weightage, TEMPLATEQUESTION.question_answerable_by,TEMPLATEQUESTION.fk_template_question_category_id, TEMPLATEQUESTION.isactive,QUESTIONS.fk_question_answertype,QUESTIONANSWERTYPE.answer_type_name,PDDETAIL.pd_detail_id'); + // //$this->db->FROM(TEMPLATEQUESTION.' as TEMPLATEQUESTION'); + // $this->db->FROM(TEMPLATEQUESTION.' as TEMPLATEQUESTION'); + // $this->db->JOIN(QUESTIONS.' as QUESTIONS','TEMPLATEQUESTION.fk_question_id = QUESTIONS.question_id'); + // $this->db->JOIN(QUESTIONANSWERTYPE.' as QUESTIONANSWERTYPE','QUESTIONS.fk_question_answertype = QUESTIONANSWERTYPE.question_answer_type_id'); + // $this->db->JOIN(PDDETAIL.' as PDDETAIL',"QUESTIONS.question_id = PDDETAIL.fk_question_id AND PDDETAIL.fk_pd_id = $pdid",'LEFT'); + // // $this->db->JOIN(USERPROFILE.' as USERPROFILE','TEMPLATEQUESTION.fk_createdby = USERPROFILE.userid','LEFT'); + // // $this->db->JOIN(USERPROFILE.' as USERPROFILE1','TEMPLATEQUESTION.fk_updatedby = USERPROFILE1.userid','LEFT'); + // $this->db->WHERE('TEMPLATEQUESTION.fk_template_question_category_id',$category['fk_question_category_id']); + // $this->db->WHERE('TEMPLATEQUESTION.fk_template_id', $template_id); + // $this->db->ORDER_BY('QUESTIONS.question_id'); + // //$this->db->WHERE('TEMPLATEQUESTION.fk_template_id',$template_id); - $questions = $this->db->GET()->result_array(); - $answerd_count = 0; - $pd_docs = array(); - foreach($questions as $t_key => $question) - { + // $questions = $this->db->GET()->result_array(); + // $answerd_count = 0; + // $pd_docs = array(); + // foreach($questions as $t_key => $question) + // { - if($question['pd_detail_id'] != "" || $question['pd_detail_id'] != null){ - $answerd_count++; + // if($question['pd_detail_id'] != "" || $question['pd_detail_id'] != null){ + // $answerd_count++; - // Get Alredy stored Images - $fields = array('pd_document_title', 'pd_document_name'); - $where_condition_array = array('fk_pd_id'=>$pdid,'fk_pd_detail_id'=> $question['pd_detail_id']); + // // Get Alredy stored Images + // $fields = array('pd_document_title', 'pd_document_name'); + // $where_condition_array = array('fk_pd_id'=>$pdid,'fk_pd_detail_id'=> $question['pd_detail_id']); - $pd_docs = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDDOCUMENTS); - // print_r($pd_docs);die(); - if(count($pd_docs)) - { - $bucket_name = LENDER_BUCKET_NAME_PREFIX.$pd_master_detials[0]['fk_lender_id']; - foreach($pd_docs as $doc_key => $doc) - { - if($doc['pd_document_name'] != "" || $doc['pd_document_name'] != null) - { - $profilepics3path = 'pd'.$pd_master_detials[0]['pd_id'].'/'.$doc['pd_document_name']; - $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$profilepics3path,'+30 minutes'); - $pd_docs[$doc_key]['pd_document_name'] = $singed_uri; - } - } + // $pd_docs = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDDOCUMENTS); + // // print_r($pd_docs);die(); + // if(count($pd_docs)) + // { + // $bucket_name = LENDER_BUCKET_NAME_PREFIX.$pd_master_detials[0]['fk_lender_id']; + // foreach($pd_docs as $doc_key => $doc) + // { + // if($doc['pd_document_name'] != "" || $doc['pd_document_name'] != null) + // { + // $profilepics3path = 'pd'.$pd_master_detials[0]['pd_id'].'/'.$doc['pd_document_name']; + // $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$profilepics3path,'+30 minutes'); + // $pd_docs[$doc_key]['pd_document_name'] = $singed_uri; + // } + // } - } - $questions[$t_key]['images'] = $pd_docs; - } + // } + // $questions[$t_key]['images'] = $pd_docs; + // } - } + // } - //print_r($questions);die(); - $categories[$category_key]['questions_count'] = count($questions); - $categories[$category_key]['answerd_count'] = $answerd_count; - $overall_answered_count += count($questions); - $overall_question_count += $answerd_count; + // //print_r($questions);die(); + // $categories[$category_key]['questions_count'] = count($questions); + // $categories[$category_key]['answerd_count'] = $answerd_count; + // $overall_answered_count += count($questions); + // $overall_question_count += $answerd_count; - if(count($questions)) - { - //image S3 url attach is pending - foreach($questions as $answer_key => $question) - { + // if(count($questions)) + // { + // //image S3 url attach is pending + // foreach($questions as $answer_key => $question) + // { - $this->db->SELECT('QUESTIONANSWERS.question_answer_id,QUESTIONANSWERS.answer,PDANSWER.pd_answer,TEMPLATEANSWERWEIGHTAGE.template_answer_weightage_id, TEMPLATEANSWERWEIGHTAGE.fk_template_question_id, TEMPLATEANSWERWEIGHTAGE.fk_question_answer_id, TEMPLATEANSWERWEIGHTAGE.template_answer_weightage,PDANSWER.isactive,PDANSWER.pd_detail_answer_id,PDANSWER.fk_pd_detail_id'); - $this->db->FROM(TEMPLATEANSWERWEIGHTAGE.' as TEMPLATEANSWERWEIGHTAGE'); - $this->db->JOIN(QUESTIONANSWERS.' as QUESTIONANSWERS','TEMPLATEANSWERWEIGHTAGE.fk_question_answer_id = QUESTIONANSWERS.question_answer_id','LEFT'); - $this->db->JOIN(PDANSWER." as PDANSWER","QUESTIONANSWERS.question_answer_id = PDANSWER.pd_answer_id AND TEMPLATEANSWERWEIGHTAGE.fk_question_answer_id = PDANSWER.pd_answer_id AND PDANSWER.isactive = 1 AND PDANSWER.fk_pd_id = $pdid",'LEFT'); - // $this->db->WHERE('QUESTIONANSWERS.fk_question_id',$question['question_id']); - $this->db->WHERE('TEMPLATEANSWERWEIGHTAGE.fk_template_question_id',$question['template_question_id']); - // $this->db->WHERE('PDDETAIL.fk_pd_id',$pdid); - $this->db->ORDER_BY('QUESTIONANSWERS.question_answer_id'); - $answers = $this->db->GET()->result_array(); - $questions[$answer_key]['answers'] = $answers; - } - } - $categories[$category_key]['questions'] = $questions; - } + // $this->db->SELECT('QUESTIONANSWERS.question_answer_id,QUESTIONANSWERS.answer,PDANSWER.pd_answer,TEMPLATEANSWERWEIGHTAGE.template_answer_weightage_id, TEMPLATEANSWERWEIGHTAGE.fk_template_question_id, TEMPLATEANSWERWEIGHTAGE.fk_question_answer_id, TEMPLATEANSWERWEIGHTAGE.template_answer_weightage,PDANSWER.isactive,PDANSWER.pd_detail_answer_id,PDANSWER.fk_pd_detail_id'); + // $this->db->FROM(TEMPLATEANSWERWEIGHTAGE.' as TEMPLATEANSWERWEIGHTAGE'); + // $this->db->JOIN(QUESTIONANSWERS.' as QUESTIONANSWERS','TEMPLATEANSWERWEIGHTAGE.fk_question_answer_id = QUESTIONANSWERS.question_answer_id','LEFT'); + // $this->db->JOIN(PDANSWER." as PDANSWER","QUESTIONANSWERS.question_answer_id = PDANSWER.pd_answer_id AND TEMPLATEANSWERWEIGHTAGE.fk_question_answer_id = PDANSWER.pd_answer_id AND PDANSWER.isactive = 1 AND PDANSWER.fk_pd_id = $pdid",'LEFT'); + // // $this->db->WHERE('QUESTIONANSWERS.fk_question_id',$question['question_id']); + // $this->db->WHERE('TEMPLATEANSWERWEIGHTAGE.fk_template_question_id',$question['template_question_id']); + // // $this->db->WHERE('PDDETAIL.fk_pd_id',$pdid); + // $this->db->ORDER_BY('QUESTIONANSWERS.question_answer_id'); + // $answers = $this->db->GET()->result_array(); + // $questions[$answer_key]['answers'] = $answers; + // } + // } + // $categories[$category_key]['questions'] = $questions; + // } - } - } + // } + // } //Get Forms details @@ -926,59 +942,127 @@ class PD_Model extends SPARQ_Model { $level_one_total = 0; $level_two_status = 0; $level_two_total = 0; - foreach($template_forms as $template_key => $value) + + if($pd_master_detials[0]['is_child'] == 0) + { + + //echo "parent"; + foreach($template_forms as $template_key => $value) + { + $this->db->SELECT('count(*) as count'); + $this->db->FROM(PDFORMDETAILSJSON.' as PDFORMDETAILSJSON'); + $this->db->WHERE('PDFORMDETAILSJSON.fk_pd_id',$pdid); + $this->db->WHERE('PDFORMDETAILSJSON.fk_form_id',$value['form_id']); + $this->db->WHERE('PDFORMDETAILSJSON.isactive',1); + $template_forms_count = 0; + $template_forms_count = $this->db->GET()->result_array(); + //print_r($template_forms_count);die(); + if(count($template_forms_count) && $template_forms_count[0]['count'] != 0) + { + $template_forms[$template_key]['isAnswered'] = true; + if($value['pd_form_level_order'] == 1){$level_one_status++; $level_one_total++;} + else if($value['pd_form_level_order'] == 2){$level_two_status++; $level_two_total++;} + } + else + { + $template_forms[$template_key]['isAnswered'] = false; + if($value['pd_form_level_order'] == 1){ $level_one_total++;} + else if($value['pd_form_level_order'] == 2){$level_two_total++;} + } + + if($value['pd_form_level_order'] == 1) + { + $template_forms[$template_key]['isAnswerable'] = true; + } + else if($value['pd_form_level_order'] == 2) + { + if($level_one_status != $level_one_total) + { + $template_forms[$template_key]['isAnswerable'] = false; + } + else + { + $template_forms[$template_key]['isAnswerable'] = true; + } + } + else if($value['pd_form_level_order'] == 3) + { + if($level_two_status != $level_two_total) + { + $template_forms[$template_key]['isAnswerable'] = false; + } + else + { + $template_forms[$template_key]['isAnswerable'] = true; + } + } + } + + } + else // FOr addtional PD { - $this->db->SELECT('count(*) as count'); - $this->db->FROM(PDFORMDETAILSJSON.' as PDFORMDETAILSJSON'); - $this->db->WHERE('PDFORMDETAILSJSON.fk_pd_id',$pdid); - $this->db->WHERE('PDFORMDETAILSJSON.fk_form_id',$value['form_id']); - $this->db->WHERE('PDFORMDETAILSJSON.isactive',1); - $template_forms_count = 0; - $template_forms_count = $this->db->GET()->result_array(); - //print_r($template_forms_count);die(); - if(count($template_forms_count) && $template_forms_count[0]['count'] != 0) + + $parent_forms = $this->config->item('parent_forms'); + foreach($template_forms as $template_key => $value) { - $template_forms[$template_key]['isAnswered'] = true; - if($value['pd_form_level_order'] == 1){$level_one_status++; $level_one_total++;} - else if($value['pd_form_level_order'] == 2){$level_two_status++; $level_two_total++;} - } - else - { - $template_forms[$template_key]['isAnswered'] = false; - if($value['pd_form_level_order'] == 1){ $level_one_total++;} - else if($value['pd_form_level_order'] == 2){$level_two_total++;} - } - - if($value['pd_form_level_order'] == 1) + $this->db->SELECT('count(*) as count'); + $this->db->FROM(PDFORMDETAILSJSON.' as PDFORMDETAILSJSON'); + $this->db->WHERE('PDFORMDETAILSJSON.fk_pd_id',$pdid); + $this->db->WHERE('PDFORMDETAILSJSON.fk_form_id',$value['form_id']); + $this->db->WHERE('PDFORMDETAILSJSON.isactive',1); + $template_forms_count = 0; + $template_forms_count = $this->db->GET()->result_array(); + //print_r($template_forms_count);die(); + if(count($template_forms_count) && $template_forms_count[0]['count'] != 0) { - $template_forms[$template_key]['isAnswerable'] = true; + $template_forms[$template_key]['isAnswered'] = true; + if($value['pd_form_level_order'] == 1){ + $level_one_status++; + $level_one_total++;} + else if($value['pd_form_level_order'] == 2){$level_two_status++; $level_two_total++;} } - else if($value['pd_form_level_order'] == 2) + else { - if($level_one_status != $level_one_total) - { - $template_forms[$template_key]['isAnswerable'] = false; - } - else + $template_forms[$template_key]['isAnswered'] = false; + if( array_search($value['form_id'],$parent_forms) ) + { + $template_forms[$template_key]['isAnswered'] = true; + } + if($value['pd_form_level_order'] == 1){ $level_one_total++;} + else if($value['pd_form_level_order'] == 2){$level_two_total++;} + } + + if($value['pd_form_level_order'] == 1) { $template_forms[$template_key]['isAnswerable'] = true; } - } - else if($value['pd_form_level_order'] == 3) - { - if($level_two_status != $level_two_total) + else if($value['pd_form_level_order'] == 2) { - $template_forms[$template_key]['isAnswerable'] = false; + if($level_one_status != $level_one_total) + { + $template_forms[$template_key]['isAnswerable'] = false; + } + else + { + $template_forms[$template_key]['isAnswerable'] = true; + } } - else + else if($value['pd_form_level_order'] == 3) { - $template_forms[$template_key]['isAnswerable'] = true; + if($level_two_status != $level_two_total) + { + $template_forms[$template_key]['isAnswerable'] = false; + } + else + { + $template_forms[$template_key]['isAnswerable'] = true; + } } - } + } } - + //FOr smart PD Purpose Filter PD forms if($pd_master_detials[0]['fk_pd_type'] == 2 && $client == 1) { @@ -997,8 +1081,8 @@ class PD_Model extends SPARQ_Model { - $result_data['question_answers'] = $categories; - $result_data['counts'] = array('overall_answered_count'=>$overall_answered_count,'overall_question_count'=>$overall_question_count); + $result_data['question_answers'] = array();; + $result_data['counts'] = array(); if(count($pd_master_detials)) { $result_data['pdmaster_details'] = $pd_master_detials[0]; @@ -1273,24 +1357,30 @@ class PD_Model extends SPARQ_Model { } - public function getAssessedIncome($pdid) + public function getAssessedIncome($pdid,$company_id = null) { /********************************* Assessd Income Sections *****************************************/ $assessed_income = array(); - + //echo "getAssessedIncome" ; //get sales_declared_by_customer details $fields = array('sdc_id','sales_declared_by_customer','margin_per','margin_value','comments'); - $where_condition_array = array('fk_pd_id'=>$pdid,'isactive'=>1); + $where_condition_array = array('fk_pd_id'=>$pdid,'isactive'=>1); + $where_condition_array['company_id'] = $company_id ? $company_id : null; $sales_declared_by_customer = $this->selectCustomRecords($fields,$where_condition_array,SALESDECLAREDBYCUSTOMER); //get Gross Profit calculatio Mode details - $fields = array('calc_type_id','mode','margin'); + $fields = array('calc_type_id','mode','margin','purchase_type'); $where_condition_array = array('fk_pd_id'=>$pdid); $gross_profit_calculation_type = $this->selectCustomRecords($fields,$where_condition_array,PDASSESSEDINCOMEESTIMATIONOFGROSSPROFITTYPE); + //print_r($gross_profit_calculation_type);die(); + //get sales_calculated_by_itemwise details $fields = array('sci_id','sales_item','sales_qty','UOM.name as uom_name','fk_uom_id','FREQUENCY.name as frequency_name','rate_per_unit','fk_frequency_id','annual_sale_value','margin_final_value','margin_per','margin_per_uom','uom_other','comments','sales_type','other_sales_item'); $table = SALESCALCULATEDBYITEMWISE.' as SALESCALCULATEDBYITEMWISE'; $where_condition_array = array('fk_pd_id'=>$pdid,'SALESCALCULATEDBYITEMWISE.isactive'=>1); + $where_condition_array['company_id'] = $company_id ? $company_id : null; + //echo "where_condition_array"; + //print_r($where_condition_array );die(); $joins = array( array('table'=>FREQUENCY.' as FREQUENCY','condition'=>'SALESCALCULATEDBYITEMWISE.fk_frequency_id = FREQUENCY.frequency_id','jointype'=>'INNER JOIN'), array('table'=>UOM.' as UOM','condition'=>'SALESCALCULATEDBYITEMWISE.fk_uom_id = UOM.uom_id','jointype'=>'LEFT')); @@ -1305,7 +1395,12 @@ class PD_Model extends SPARQ_Model { $this->db->FROM(SALESITEMMONTHWISE.' as SALESITEMMONTHWISE'); $this->db->WHERE('SALESITEMMONTHWISE.fk_pd_id',$pdid); $this->db->WHERE('SALESITEMMONTHWISE.isactive',1); + if($company_id != null) + { + $this->db->WHERE('SALESITEMMONTHWISE.company_id',$company_id); + } $sales_items_by_monthwise = $this->db->GET()->result_array(); + //print_r($sales_items_by_monthwise); if(count($sales_items_by_monthwise)) { foreach($sales_items_by_monthwise as $key => $item) @@ -1317,6 +1412,7 @@ class PD_Model extends SPARQ_Model { $this->db->GROUP_BY('month(SALESITEMMONTHWISECHILD.sales_date)'); $sales_items_by_month = $this->db->GET()->result_array(); //print_r($this->db->last_query()); + //print_r($sales_items_by_month); if(count($sales_items_by_month)) { @@ -1329,9 +1425,11 @@ class PD_Model extends SPARQ_Model { $this->db->WHERE('SALESITEMMONTHWISECHILD.fk_sim_id',$item['sim_id']); $this->db->JOIN(FREQUENCY.' as FREQUENCY','SALESITEMMONTHWISECHILD.fk_frequency_id = FREQUENCY.frequency_id','LEFT'); $this->db->WHERE('month(SALESITEMMONTHWISECHILD.sales_date)',$month['month']); + //$this->db->WHERE('year(SALESITEMMONTHWISECHILD.sales_date)',$month['year']); $this->db->WHERE('SALESITEMMONTHWISECHILD.isactive',1); //$this->db->GROUP_BY('month(SALESITEMMONTHWISECHILD.sales_date)'); $sales_items_by_month_child = $this->db->GET()->result_array(); + //print_r($sales_items_by_month_child); if(count($sales_items_by_month_child)) { foreach($sales_items_by_month_child as $t_key => $child_item) @@ -1353,20 +1451,84 @@ class PD_Model extends SPARQ_Model { - //Get purchase_details - $fields = array('purchase_id','purchase_item','purchase_qty','UOM.name as uom_name','fk_uom_id','FREQUENCY.name as frequency_name','rate_per_unit','fk_frequency_id','annual_purchase_value','uom_other','comments','purchase_type'); + //*************Get purchase_details + + + $fields = array('purchase_id','purchase_item','purchase_qty','UOM.name as uom_name','fk_uom_id','FREQUENCY.name as frequency_name','rate_per_unit','fk_frequency_id','annual_purchase_value','uom_other','comments','purchase_type','other_purchase_item'); $table = PDPURCHASEDETAILS.' as PDPURCHASEDETAILS'; $where_condition_array = array('fk_pd_id'=>$pdid,'PDPURCHASEDETAILS.isactive'=>1); + $where_condition_array['company_id'] = $company_id ? $company_id : null; $joins = array( - array('table'=>FREQUENCY.' as FREQUENCY','condition'=>'PDPURCHASEDETAILS.fk_frequency_id = FREQUENCY.frequency_id','jointype'=>'INNER JOIN'), - array('table'=>UOM.' as UOM','condition'=>'PDPURCHASEDETAILS.fk_uom_id = UOM.uom_id','jointype'=>'INNER JOIN')); + array('table'=>FREQUENCY.' as FREQUENCY','condition'=>'PDPURCHASEDETAILS.fk_frequency_id = FREQUENCY.frequency_id','jointype'=>'LEFT'), + array('table'=>UOM.' as UOM','condition'=>'PDPURCHASEDETAILS.fk_uom_id = UOM.uom_id','jointype'=>'LEFT')); $purchase_details = $this->getJoinRecords($fields,$table,$joins,$where_condition_array); + // print_r(); + //get purchase bill details + + $purchase_billwise_parent = array(); + + $this->db->SELECT('pbw_id,purchase_item,annual_purchase_value,comments,other_purchase_item'); + $this->db->FROM(PDPURCHASEBILLWISE.' as PDPURCHASEBILLWISE'); + $this->db->WHERE('PDPURCHASEBILLWISE.fk_pd_id',$pdid); + $this->db->WHERE('PDPURCHASEBILLWISE.isactive',1); + if($company_id != null) + { + $this->db->WHERE('PDPURCHASEBILLWISE.company_id',$company_id); + } + $purchase_billwise_parent = $this->db->GET()->result_array(); + //print_r($purchase_billwise_parent); + if(count($purchase_billwise_parent)) + { + foreach($purchase_billwise_parent as $purchase_billwise_parent_key => $billwise) + { + $this->db->SELECT('month(purchase_date) as month,year(purchase_date) as year'); + $this->db->FROM(PDPURCHASEBILLWISECHILD.' as PDPURCHASEBILLWISECHILD'); + $this->db->WHERE('PDPURCHASEBILLWISECHILD.fk_pbw_id',$billwise['pbw_id']); + $this->db->WHERE('PDPURCHASEBILLWISECHILD.isactive',1); + $this->db->GROUP_BY('month(PDPURCHASEBILLWISECHILD.purchase_date)'); + $purchase_billwise_child_group = $this->db->GET()->result_array(); + //print_r($purchase_billwise_child_group); + + if(count($purchase_billwise_child_group)) + { + $purchase_billwise_data = array(); + foreach($purchase_billwise_child_group as $billwise_child_key => $child) + { + + $this->db->SELECT('pbwc_id,purchase_date,purchase_value,'); + $this->db->FROM(PDPURCHASEBILLWISECHILD.' as PDPURCHASEBILLWISECHILD'); + $this->db->WHERE('PDPURCHASEBILLWISECHILD.fk_pbw_id',$billwise['pbw_id']); + + $this->db->WHERE('month(PDPURCHASEBILLWISECHILD.purchase_date)',$child['month']); + $this->db->WHERE('PDPURCHASEBILLWISECHILD.isactive',1); + //$this->db->GROUP_BY('month(SALESITEMMONTHWISECHILD.sales_date)'); + $purchase_billwise_child = $this->db->GET()->result_array(); + if(count($purchase_billwise_child)) + { + foreach($purchase_billwise_child as $t_key => $child_item) + { + $purchase_billwise_child[$t_key]['row_index'] = $t_key + 1; + } + } + $purchase_billwise_data[$billwise_child_key][date("M-Y", strtotime($child['year'].'-'.$child['month']))] = $purchase_billwise_child; + } + $purchase_billwise_parent[$purchase_billwise_parent_key]['items'] = $purchase_billwise_data; + } + + //print_r($sales_items_by_months); + } + + } + //echo "*****************************************"; + //print_r($purchase_billwise_parent);die(); + //Get business_expenses $fields = array('pd_expense_id','PDBUSINESSEXPENSES.expense_item_id','BUSINESSEXPENSES.expense_item','FREQUENCY.name as frequency_name','fk_frequency_id','expense_value','annual_expenses_value','comments'); $table = PDBUSINESSEXPENSES.' as PDBUSINESSEXPENSES'; $where_condition_array = array('fk_pd_id'=>$pdid,'PDBUSINESSEXPENSES.isactive'=>1); + $where_condition_array['company_id'] = $company_id ? $company_id : null; $joins = array( array('table'=>FREQUENCY.' as FREQUENCY','condition'=>'PDBUSINESSEXPENSES.fk_frequency_id = FREQUENCY.frequency_id','jointype'=>'INNER JOIN'), array('table'=>BUSINESSEXPENSES.' as BUSINESSEXPENSES','condition'=>'PDBUSINESSEXPENSES.expense_item_id = BUSINESSEXPENSES.expense_item_id','jointype'=>'INNER JOIN')); @@ -1378,6 +1540,7 @@ class PD_Model extends SPARQ_Model { $fields = array('household_expense_id','expense_item','FREQUENCY.name as frequency_name','fk_frequency_id','expense_value','annual_expense_value','comments'); $table = PDHOUSEHOLDEXPENSES.' as PDHOUSEHOLDEXPENSES'; $where_condition_array = array('fk_pd_id'=>$pdid,'PDHOUSEHOLDEXPENSES.isactive'=>1); + $where_condition_array['company_id'] = $company_id ? $company_id : null; $joins = array( array('table'=>FREQUENCY.' as FREQUENCY','condition'=>'PDHOUSEHOLDEXPENSES.fk_frequency_id = FREQUENCY.frequency_id','jointype'=>'INNER JOIN')); $house_hold_expenses = $this->getJoinRecords($fields,$table,$joins,$where_condition_array); @@ -1387,6 +1550,7 @@ class PD_Model extends SPARQ_Model { $fields = array('PDBUSINESSINCOME.pd_business_income_id', 'PDBUSINESSINCOME.fk_pd_id', 'PDBUSINESSINCOME.business_income_id', 'PDBUSINESSINCOME.income_value', 'PDBUSINESSINCOME.fk_frequency_id', 'PDBUSINESSINCOME.annual_income_value','PDBUSINESSINCOME.fk_createdby','PDBUSINESSINCOME.other_income_item','PDBUSINESSINCOME.other_frequncy_item','FREQUENCY.name as frequency_name','BUSINESSINCOME.business_income_item','comments'); $table = PDBUSINESSINCOME.' as PDBUSINESSINCOME'; $where_condition_array = array('fk_pd_id'=>$pdid,'PDBUSINESSINCOME.isactive'=>1); + $where_condition_array['company_id'] = $company_id ? $company_id : null; $joins = array( array('table'=>FREQUENCY.' as FREQUENCY','condition'=>'PDBUSINESSINCOME.fk_frequency_id = FREQUENCY.frequency_id','jointype'=>'INNER JOIN'), array('table'=>BUSINESSINCOME.' as BUSINESSINCOME','condition'=>'PDBUSINESSINCOME.business_income_id = BUSINESSINCOME.business_income_id','jointype'=>'INNER JOIN')); @@ -1394,7 +1558,7 @@ class PD_Model extends SPARQ_Model { /*********************************End of Assessd Income Sections *****************************************/ - $assessed_income= array('sales_declared_by_customer'=>$sales_declared_by_customer,'sales_calculated_by_itemwise'=>$sales_calculated_by_itemwise,'sales_items_by_monthwise'=>$sales_items_by_monthwise,'purchase_details'=>$purchase_details,'business_expenses'=>$business_expenses,'house_hold_expenses'=>$house_hold_expenses,'gross_profit_calculation_type' => $gross_profit_calculation_type,'othre_business_income' => $other_business_income); + $assessed_income= array('sales_declared_by_customer'=>$sales_declared_by_customer,'sales_calculated_by_itemwise'=>$sales_calculated_by_itemwise,'sales_items_by_monthwise'=>$sales_items_by_monthwise,'purchase_details'=>$purchase_details,'purchase_billwise' => $purchase_billwise_parent,'business_expenses'=>$business_expenses,'house_hold_expenses'=>$house_hold_expenses,'gross_profit_calculation_type' => $gross_profit_calculation_type,'othre_business_income' => $other_business_income); return $assessed_income; } diff --git a/api/index.php b/api/index.php index 55eefb8f..c9e55e88 100644 --- a/api/index.php +++ b/api/index.php @@ -57,6 +57,7 @@ define('ENVIRONMENT','development'); date_default_timezone_set('Asia/Kolkata'); + /* *---------------------------------------------------------------