This commit is contained in:
velz 2019-02-28 19:25:22 +05:30
parent e77020f161
commit a47daf3938

View File

@ -3116,7 +3116,7 @@ class PD_Controller extends REST_Controller {
{
$calculated_data = array();
$overall_summary_report = array();
$sales_declared_by_customer = array();
$sales_declared_by_customer_flag = 0;
@ -3176,50 +3176,6 @@ class PD_Controller extends REST_Controller {
$total_sales_monthwise = 0;
$total_sales_declared_by_customer = 0;
if($sales_calculated_by_itemwise_flag == 1)
{
foreach($sales_calculated_by_itemwise as $itemwise_key => $item)
{
$total_sales_itemwise = $total_sales_itemwise + $item['annual_sale_value'];
}
}
if($sales_by_item_monthwise_flag == 1)
{
foreach($sales_by_item_monthwise as $monthwise_key => $sales_by_item_month)
{
$month_total = 0;
$i = 0;
foreach($sales_by_item_month['items'] as $month_key => $month)
{
$temp = 0;
$i++;
foreach($month as $key => $m)
{
$temp = $temp + $m['sales_value'];
}
$month_total = $month_total + $temp;
}
$sales_monthwise[] = array('total' => $month_total,'no_of_months' => $i);
}
foreach($sales_monthwise as $sale)
{
$annual_multuplier = 12 / $sale['no_of_months'];
$total_sales_monthwise = $total_sales_monthwise + ($sale['total'] * $annual_multuplier);
}
//print_r($total_sales_monthwise);
}
if($sales_declared_by_customer_flag == 1)
{
$total_sales_declared_by_customer = $sales_declared_by_customer[0]['sales_declared_by_customer'];
}
//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'];
@ -3246,147 +3202,160 @@ class PD_Controller extends REST_Controller {
}
//case 1 - (b:ref doc) If the difference between the lowest and highest of the 3 revenue (sales) figures arrived at above in step 1, is > 50% of lowest, then the revenue considered would be 125% of the lowest revenue
$temp_array = array();
if($sales_declared_by_customer_flag != 0){ $temp_array = array_merge($temp_array,array($total_sales_declared_by_customer));}
if($sales_calculated_by_itemwise_flag != 0){ $temp_array = array_merge($temp_array,array($total_sales_itemwise));}
if($sales_by_item_monthwise_flag != 0){ $temp_array = array_merge($temp_array,array($total_sales_monthwise));}
$height_value = max($temp_array);
$lowest_vaule = min($temp_array);
if($lowest_vaule != 0 && count($temp_array) > 1)
if($sales_calculated_by_itemwise_flag == 1)
{
$diff = $height_value - $lowest_vaule;
if($diff > ($lowest_vaule * 0.5))
$temp_purchases = 0;
$temp_netprofit = 0;
$temp_grossprofit = 0;
$temp_netmargin = 0;
foreach($sales_calculated_by_itemwise as $itemwise_key => $item)
{
$final_sales_avg_value = $lowest_vaule * 1.25;
$total_sales_itemwise = $total_sales_itemwise + $item['annual_sale_value'];
$temp_netprofit = $temp_netprofit + $item['margin_final_value'];
}
}
else //case 2 - (a) ref doc - Normally Average of the above 3 sales estimates is considered. There may be situations where sales information is available only from a or b or c or any
{
$average = array_sum($temp_array)/count($temp_array);
$final_sales_avg_value = $average;
}
//echo "\n\n".$final_sales_avg_value;
/**************End of Purchase Calculations************************/
/**************************Gross Profit calculation start***************/
//print_r($gross_profit_calculation_type);
$estimation_of_gross_profit = 0;
if(isset($gross_profit_calculation_type[0]))
{
if($gross_profit_calculation_type[0]['mode'] == 1)
//calculatin part
if($purchases_flag != 0)
{
$estimation_of_gross_profit = $final_sales_avg_value - $overall_purchase_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;
}
$temp_purchases = $overall_purchase_total;
$temp_grossprofit = $temp_purchases - $total_sales_itemwise;
$temp_netprofit = $overall_business_expenses_total - $temp_grossprofit;
$temp_netmargin = $total_sales_itemwise/$temp_netprofit;
}
else
{
if($gross_profit_calculation_type[0]['margin'] == 1)
{
if($sales_declared_by_customer_flag != 0)
{
$estimation_of_gross_profit = $sales_declared_by_customer[0]['margin_value'];
}
else if($sales_calculated_by_itemwise_flag != 0)
{
foreach($sales_calculated_by_itemwise as $sci_key => $sci)
{
$estimation_of_gross_profit = $estimation_of_gross_profit+$sci['margin_final_value'];
}
}
else if($sales_by_item_monthwise_flag != 0)
{
foreach($sales_by_item_monthwise as $sim_key => $sim)
{
$estimation_of_gross_profit = $estimation_of_gross_profit+$sim['margin_value'];
}
}
$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
{
if($sales_declared_by_customer_flag != 0)
{
$net_profit = $sales_declared_by_customer[0]['margin_value'];
}
else if($sales_calculated_by_itemwise_flag != 0)
{
foreach($sales_calculated_by_itemwise as $sci_key => $sci)
{
$net_profit = $net_profit+$sci['margin_final_value'];
}
}
else if($sales_by_item_monthwise_flag != 0)
{
foreach($sales_by_item_monthwise as $sim_key => $sim)
{
$net_profit = $net_profit+ $sim['margin_value'];
}
}
$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;
}
}
$temp_grossprofit = $temp_netprofit - $overall_business_expenses_total;
$temp_purchases = $temp_grossprofit - $total_sales_itemwise;
$temp_netmargin = $total_sales_itemwise/$temp_netprofit;
}
}
/**************************Gross Profit calculation end***************/
$calculated_data['sales_revenue'] = $final_sales_avg_value;
$calculated_data['other_business_income'] = $overall_other_business_income_total;
$calculated_data['purchase'] = $overall_purchase_total;
$calculated_data['household_expenses'] = $overall_household_total;
if(isset($gross_profit_calculation_type[0]))
{
if($gross_profit_calculation_type[0]['mode'] == 1 || $gross_profit_calculation_type[0]['margin'] == 1)
$overall_summary_report['sales_calculated_by_itemwise']['sales_revenue'] = $total_sales_itemwise;
$overall_summary_report['sales_calculated_by_itemwise']['purchases'] = $temp_purchases;
$overall_summary_report['sales_calculated_by_itemwise']['grossprofit'] = $temp_grossprofit;
$overall_summary_report['sales_calculated_by_itemwise']['business_expenses'] = $overall_business_expenses_total;
$overall_summary_report['sales_calculated_by_itemwise']['netprofit'] = $temp_netprofit;
$overall_summary_report['sales_calculated_by_itemwise']['house_hold_expenses'] = $overall_household_total;
$overall_summary_report['sales_calculated_by_itemwise']['disposable_income'] = $overall_other_business_income_total;
$overall_summary_report['sales_calculated_by_itemwise']['netmargin'] = $temp_netmargin;
}
if($sales_by_item_monthwise_flag == 1)
{
$temp_purchases = 0;
$temp_netprofit = 0;
$temp_grossprofit = 0;
$temp_netmargin = 0;
foreach($sales_by_item_monthwise as $monthwise_key => $sales_by_item_month)
{
$calculated_data['gross_profit'] = $estimation_of_gross_profit;
//$calculated_data['other_business_income'] = $overall_other_business_income_total;
$month_total = 0;
$i = 0;
$temp_netprofit = $temp_netprofit + $sales_by_item_month['margin_value'];
foreach($sales_by_item_month['items'] as $month_key => $month)
{
$temp = 0;
$i++;
foreach($month as $key => $m)
{
$temp = $temp + $m['sales_value'];
}
$month_total = $month_total + $temp;
}
$sales_monthwise[] = array('total' => $month_total,'no_of_months' => $i);
}
foreach($sales_monthwise as $sale)
{
$annual_multuplier = 12 / $sale['no_of_months'];
$total_sales_monthwise = $total_sales_monthwise + ($sale['total'] * $annual_multuplier);
}
//calculation part
//calculatin part
if($purchases_flag != 0)
{
$temp_purchases = $overall_purchase_total;
$temp_grossprofit = $temp_purchases - $total_sales_monthwise;
$temp_netprofit = $overall_business_expenses_total - $temp_grossprofit;
$temp_netmargin = $total_sales_monthwise/$temp_netprofit;
}
else
{
$calculated_data['gross_profit'] =( $net_profit + $overall_business_expenses_total);
//$calculated_data['other_business_income'] = $overall_other_business_income_total;
$temp_grossprofit = $temp_netprofit - $overall_business_expenses_total;
$temp_purchases = $temp_grossprofit - $total_sales_monthwise;
$temp_netmargin = $total_sales_monthwise/$temp_netprofit;
}
}
$calculated_data['business_expense'] = $overall_business_expenses_total;
$calculated_data['net_profit'] = $net_profit;
$calculated_data['net_margin'] = $net_profit / $final_sales_avg_value;
$overall_summary_report['sales_calculated_by_monthwise']['sales_revenue'] = $total_sales_monthwise;
$overall_summary_report['sales_calculated_by_monthwise']['purchases'] = $temp_purchases;
$overall_summary_report['sales_calculated_by_monthwise']['grossprofit'] = $temp_grossprofit;
$overall_summary_report['sales_calculated_by_monthwise']['business_expenses'] = $overall_business_expenses_total;
$overall_summary_report['sales_calculated_by_monthwise']['netprofit'] = $temp_netprofit;
$overall_summary_report['sales_calculated_by_monthwise']['house_hold_expenses'] = $overall_household_total;
$overall_summary_report['sales_calculated_by_monthwise']['disposable_income'] = $overall_other_business_income_total;
$overall_summary_report['sales_calculated_by_monthwise']['netmargin'] = $temp_netmargin;
}
if($sales_declared_by_customer_flag == 1)
{
$temp_purchases = 0;
$temp_netprofit = 0;
$temp_grossprofit = 0;
$temp_netmargin = 0;
$total_sales_declared_by_customer = $sales_declared_by_customer[0]['sales_declared_by_customer'];
$temp_netprofit = $sales_declared_by_customer[0]['margin_value'];
if($purchases_flag != 0)
{
$temp_purchases = $overall_purchase_total;
$temp_grossprofit = $temp_purchases - $total_sales_declared_by_customer;
$temp_netprofit = $overall_business_expenses_total - $temp_grossprofit;
$temp_netmargin = $total_sales_declared_by_customer/$temp_netprofit;
}
else
{
$temp_grossprofit = $temp_netprofit - $overall_business_expenses_total;
$temp_purchases = $temp_grossprofit - $total_sales_declared_by_customer;
$temp_netmargin = $total_sales_declared_by_customer/$temp_netprofit;
}
$overall_summary_report['sales_declared_by_customer']['sales_revenue'] = $total_sales_declared_by_customer;
$overall_summary_report['sales_declared_by_customer']['purchases'] = $temp_purchases;
$overall_summary_report['sales_declared_by_customer']['grossprofit'] = $temp_grossprofit;
$overall_summary_report['sales_declared_by_customer']['business_expenses'] = $overall_business_expenses_total;
$overall_summary_report['sales_declared_by_customer']['netprofit'] = $temp_netprofit;
$overall_summary_report['sales_declared_by_customer']['house_hold_expenses'] = $overall_household_total;
$overall_summary_report['sales_declared_by_customer']['disposable_income'] = $overall_other_business_income_total;
$overall_summary_report['sales_declared_by_customer']['netmargin'] = $temp_netmargin;
}
$temp_sales_array = array();
// $data['dataStatus'] = true;
// $data['status'] = REST_Controller::HTTP_OK;
// $data['records'] = $calculated_data;
// $this->response($data,REST_Controller::HTTP_OK);
return $calculated_data;
if(isset($overall_summary_report['sales_declared_by_customer']['sales_revenue'])){ $temp_sales_array = array_merge($temp_sales_array,array($overall_summary_report['sales_declared_by_customer']['sales_revenue'])); }
if(isset($overall_summary_report['sales_calculated_by_monthwise']['sales_revenue'])){ $temp_sales_array = array_merge($temp_sales_array,array($overall_summary_report['sales_calculated_by_monthwise']['sales_revenue'])); }
if(isset($overall_summary_report['sales_calculated_by_itemwise']['sales_revenue'])){ $temp_sales_array = array_merge($temp_sales_array,array($overall_summary_report['sales_calculated_by_itemwise']['sales_revenue'])); }
$temp_netmargin_array = array();
if(isset($overall_summary_report['sales_declared_by_customer']['netmargin'])){ $temp_netmargin_array = array_merge($temp_netmargin_array,array($overall_summary_report['sales_declared_by_customer']['netmargin'])); }
if(isset($overall_summary_report['sales_calculated_by_monthwise']['netmargin'])){ $temp_netmargin_array = array_merge($temp_netmargin_array,array($overall_summary_report['sales_calculated_by_monthwise']['netmargin'])); }
if(isset($overall_summary_report['sales_calculated_by_itemwise']['netmargin'])){ $temp_netmargin_array = array_merge($temp_netmargin_array,array($overall_summary_report['sales_calculated_by_itemwise']['netmargin'])); }
$overall_summary_report['consolidated_report']['consolidated_sales_revenue'] = (array_sum($temp_sales_array) / count($temp_sales_array));
$overall_summary_report['consolidated_report']['consolidated_nermagin'] = (array_sum($temp_netmargin_array) / count($temp_netmargin_array));
$overall_summary_report['consolidated_report']['consolidated_nerprofit'] = ($overall_summary_report['consolidated_report']['consolidated_sales_revenue'] / $overall_summary_report['consolidated_report']['consolidated_nermagin'] );
return $overall_summary_report;
}
else
{