BUSINESS GROUP FORMS

This commit is contained in:
velz 2019-01-03 20:04:48 +05:30
parent 3818acd222
commit 3d1c3827cf

View File

@ -2036,9 +2036,18 @@ class PD_Controller extends REST_Controller {
$pdid = $records['pdid'];
$formid = $records['formid'];
$createdby = $records['fk_createdby'];
$company_id = null;
if(isset($records['company_id']))
{
$company_id = $records['company_id'];
}
$fields = array('isactive' => 0);
$where_condition_array = array('fk_form_id'=>$formid,'fk_pd_id'=>$pdid);
if($company_id != null)
{
$where_condition_array = array('fk_form_id'=>$formid,'fk_pd_id'=>$pdid,'company_id' => $company_id);
}
$id = $this->PD_Model->updateRecords($fields,PDFORMDETAILSJSON,$where_condition_array);
//Save Any New Applicants Details From General Form
@ -2049,9 +2058,10 @@ class PD_Controller extends REST_Controller {
unset($records['pdid']);
unset($records['formid']);
unset($records['fk_createdby']);
unset($records['company_id']);
$records = json_encode($records);
$temp_array = array('fk_form_id'=>$formid,'fk_pd_id'=>$pdid,'fk_createdby'=>$createdby,'json'=>$records);
$temp_array = array('fk_form_id'=>$formid,'company_id' => $company_id,'fk_pd_id'=>$pdid,'fk_createdby'=>$createdby,'json'=>$records);
$id = $this->PD_Model->saveRecords($temp_array,PDFORMDETAILSJSON);
if($id != "" || $id != null)
{
@ -2075,9 +2085,18 @@ class PD_Controller extends REST_Controller {
{
$pd_id = $this->post('pd_id');
$pd_form_id = $this->post('pd_form_id');
$company_id = null;
if(isset($records['company_id']))
{
$company_id = $records['company_id'];
}
$fields = array('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'=>$formid,'fk_pd_id'=>$pdid,'company_id' => $company_id);
}
$rec = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDFORMDETAILSJSON);
// print_r($rec);die();
if(count($rec))
@ -2667,8 +2686,12 @@ class PD_Controller extends REST_Controller {
$household_expenses = array();
$household_expenses_flag = 0;
$other_business_income = array();
$other_business_income_flag = 0;
$overall_purchase_total = 0;
$overall_business_total = 0;
$overall_business_expenses_total = 0;
$overall_other_business_income_total = 0;
$overall_household_total = 0;
$net_profit = 0;
$final_sales_avg_value = 0;
@ -2681,6 +2704,7 @@ class PD_Controller extends REST_Controller {
$sales_by_item_monthwise = $result_array['sales_items_by_monthwise'];
$purchases = $result_array['purchase_details'];
$business_expenses = $result_array['business_expenses'];
$other_business_income = $result_array['othre_business_income'];
$household_expenses = $result_array['house_hold_expenses'];
$gross_profit_calculation_type = $result_array['gross_profit_calculation_type'];
$othre_business_income = $result_array['othre_business_income'];
@ -2690,6 +2714,7 @@ class PD_Controller extends REST_Controller {
if(count($purchases)){$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;}
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))
@ -2744,11 +2769,16 @@ class PD_Controller extends REST_Controller {
}
//print_r($sales_monthwise);
//print_r($total_sales_monthwise);
foreach($other_business_income as $other_business_key => $other_business)
{
$overall_other_business_income_total = $overall_other_business_income_total + $other_business['annual_income_value'];
}
foreach($business_expenses as $business_key => $business_expense)
{
$overall_business_total = $overall_business_total + $business_expense['annual_expenses_value'];
$overall_business_expenses_total = $overall_business_expenses_total + $business_expense['annual_expenses_value'];
}
foreach($household_expenses as $household_key => $household_expense)
@ -2806,10 +2836,17 @@ class PD_Controller extends REST_Controller {
if($gross_profit_calculation_type[0]['mode'] == 1)
{
$estimation_of_gross_profit = $final_sales_avg_value - $overall_purchase_total;
$net_profit = $estimation_of_gross_profit - $overall_business_total;
$net_profit = $estimation_of_gross_profit - $overall_business_expenses_total;
if($other_business_income_flag != 0)
{
$net_profit = $net_profit + $overall_other_business_income_total;
}
}
else
{
if($gross_profit_calculation_type[0]['margin'] == 1)
{
if($sales_declared_by_customer_flag != 0)
@ -2831,8 +2868,12 @@ class PD_Controller extends REST_Controller {
}
}
$net_profit = $estimation_of_gross_profit - $overall_business_total;
$overall_purchase_total = $net_profit + $overall_business_total;
$net_profit = $estimation_of_gross_profit - $overall_business_expenses_total;
$overall_purchase_total = $net_profit + $overall_business_expenses_total;
if($other_business_income_flag != 0)
{
$overall_purchase_total = $overall_purchase_total + $overall_other_business_income_total;
}
}
else
{
@ -2857,25 +2898,33 @@ class PD_Controller extends REST_Controller {
}
$overall_purchase_total = $final_sales_avg_value - ($overall_business_total+$net_profit);
$overall_purchase_total = $final_sales_avg_value - ($overall_business_expenses_total+$net_profit);
if($other_business_income_flag != 0)
{
$overall_purchase_total = $overall_purchase_total + $overall_other_business_income_total;
}
}
}
}
/**************************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;
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;
}
else
{
$calculated_data['gross_profit'] =( $net_profit + $overall_business_total);
$calculated_data['gross_profit'] =( $net_profit + $overall_business_expenses_total);
$calculated_data['other_business_income'] = $overall_other_business_income_total;
}
}
$calculated_data['expense']['business_expense'] = $overall_business_total;
$calculated_data['expense']['business_expense'] = $overall_business_expenses_total;
$calculated_data['expense']['net_profit'] = $net_profit;
$calculated_data['net_margin'] = $net_profit / $final_sales_avg_value;