AI SECOND CHANGES
This commit is contained in:
parent
e0565c20fb
commit
3720d6a2d0
@ -3254,7 +3254,7 @@ class PD_Controller extends REST_Controller {
|
||||
{
|
||||
if(($child['sales_date'] != null || $child['sales_date'] != ""))
|
||||
{
|
||||
$child['fk_sci_id'] = $record['sci_id'];
|
||||
$child['fk_sci_id'] = $id;
|
||||
$child_id = $this->PD_Model->saveRecords($child,SALESITEMMONTHWISECHILD);
|
||||
}
|
||||
}
|
||||
@ -3452,16 +3452,17 @@ class PD_Controller extends REST_Controller {
|
||||
$id = "";
|
||||
|
||||
//Remove other than DB fields
|
||||
if(array_key_exists('margin_final_value', $record)
|
||||
if(array_key_exists('margin_final_value',$record))
|
||||
{
|
||||
$record['margin_value'] = $record['margin_final_value']; unset($record['margin_final_value']);
|
||||
$record['margin_value'] = $record['margin_final_value'];
|
||||
unset($record['margin_final_value']);
|
||||
}
|
||||
array_key_exists('sales_qty', $record) ? unset($record['sales_qty']) : '';
|
||||
array_key_exists('fk_uom_id', $record) ? unset($record['fk_uom_id']) : '';
|
||||
array_key_exists('rate_per_unit', $record) ? unset($record['rate_per_unit']) : '';
|
||||
array_key_exists('fk_frequency_id', $record) ? unset($record['fk_frequency_id']) : '';
|
||||
array_key_exists('annual_sale_value', $record) ? unset($record['annual_sale_value']) : '';
|
||||
array_key_exists('margin_per_uom', $record) ? unset($record['margin_per_uom']) : '';
|
||||
// array_key_exists('sales_qty', $record) ? unset($record['sales_qty']) : '';
|
||||
// array_key_exists('fk_uom_id', $record) ? unset($record['fk_uom_id']) : '';
|
||||
// array_key_exists('rate_per_unit', $record) ? unset($record['rate_per_unit']) : '';
|
||||
// array_key_exists('fk_frequency_id', $record) ? unset($record['fk_frequency_id']) : '';
|
||||
// array_key_exists('annual_sale_value', $record) ? unset($record['annual_sale_value']) : '';
|
||||
// array_key_exists('margin_per_uom', $record) ? unset($record['margin_per_uom']) : '';
|
||||
|
||||
// CURD Operations
|
||||
if($record['sim_id'] != null || $record['sim_id'] != "" )
|
||||
@ -3500,7 +3501,7 @@ class PD_Controller extends REST_Controller {
|
||||
|
||||
foreach($child_data as $ckey => $child)
|
||||
{
|
||||
if((($child['sales_date'] != null || $child['sales_date'] != ""))
|
||||
if((($child['sales_date'] != null || $child['sales_date'] != "")))
|
||||
{
|
||||
//echo 'true';
|
||||
$child['fk_sim_id'] = $id;
|
||||
@ -3816,7 +3817,7 @@ class PD_Controller extends REST_Controller {
|
||||
//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'];
|
||||
//$sales_by_item_monthwise = $result_array['sales_items_by_monthwise'];
|
||||
$purchases = $result_array['purchase_details'];
|
||||
$purchase_declared_by_customer = $result_array['purchase_declared_by_customer'];
|
||||
//$purchase_billwise = $result_array['purchase_billwise'];
|
||||
@ -3868,7 +3869,7 @@ class PD_Controller extends REST_Controller {
|
||||
foreach($purchases as $purchase_key => $purchase)
|
||||
{
|
||||
|
||||
$overall_purchase_total += $purchase['sales_type'] != 3 ? $purchase['annual_purchase_value'] : ($purchase['annual_purchase_value'] * (12/ count($purchase['items'])) );
|
||||
$overall_purchase_total += $purchase['purchase_type'] != 3 ? $purchase['annual_purchase_value'] : ($purchase['annual_purchase_value'] * (12/ count($purchase['items'])) );
|
||||
}
|
||||
// }
|
||||
// else if($gross_profit_calculation_type[0]['mode'] == 1 && $gross_profit_calculation_type[0]['purchase_type'] == 2)////purchase bill wise
|
||||
@ -3891,8 +3892,12 @@ class PD_Controller extends REST_Controller {
|
||||
$temp_netprofit = 0;
|
||||
$temp_grossprofit = 0;
|
||||
$temp_netmargin = 0;
|
||||
$month_total = 0;
|
||||
$i = 0;
|
||||
foreach($sales_calculated_by_itemwise as $itemwise_key => $item)
|
||||
{
|
||||
|
||||
//print_r($item);die();
|
||||
if($item['sales_type'] != 3)
|
||||
{
|
||||
$total_sales_itemwise = $total_sales_itemwise + $item['annual_sale_value'];
|
||||
@ -3901,17 +3906,16 @@ class PD_Controller extends REST_Controller {
|
||||
else
|
||||
{
|
||||
//*****************************
|
||||
foreach($sales_by_item_monthwise as $monthwise_key => $sales_by_item_month)
|
||||
{
|
||||
// foreach($sales_by_item_monthwise as $monthwise_key => $sales_by_item_month)
|
||||
// {
|
||||
//print_r($sales_by_item_month['items']);
|
||||
//echo isset($sales_by_item_month['items']);die();
|
||||
$month_total = 0;
|
||||
$i = 0;
|
||||
$temp_netprofit = $temp_netprofit + $sales_by_item_month['margin_value'];
|
||||
if(isset($sales_by_item_month['items']))
|
||||
|
||||
$temp_netprofit = $temp_netprofit + $item['margin_final_value'];
|
||||
if(isset($item['items']))
|
||||
{
|
||||
//echo 'insdie if';
|
||||
foreach($sales_by_item_month['items'] as $month_key => $month)
|
||||
foreach($item['items'] as $month_key => $month)
|
||||
{
|
||||
$temp = 0;
|
||||
|
||||
@ -3925,8 +3929,8 @@ class PD_Controller extends REST_Controller {
|
||||
}
|
||||
|
||||
//die();
|
||||
$sales_monthwise[] = array('total' => $month_total,'no_of_months' => $i,'sales_type' => $sales_by_item_month['sales_type']);
|
||||
}
|
||||
$sales_monthwise[] = array('total' => $month_total,'no_of_months' => $i,'sales_type' => $item['sales_type']);
|
||||
//}
|
||||
|
||||
|
||||
//print_r($sales_monthwise);die();
|
||||
@ -3968,10 +3972,10 @@ class PD_Controller extends REST_Controller {
|
||||
$temp_grossprofit = $temp_netprofit;// + $overall_business_expenses_total;
|
||||
$temp_netprofit = $temp_grossprofit - $overall_business_expenses_total;
|
||||
$temp_purchases = ($total_sales_itemwise + $total_sales_monthwise) - $temp_grossprofit;
|
||||
$temp_netmargin = ($temp_netprofit/( $total_sales_itemwise + $total_sales_monthwise) * 100;
|
||||
$temp_netmargin = ($temp_netprofit/( $total_sales_itemwise + $total_sales_monthwise) * 100);
|
||||
}
|
||||
|
||||
$overall_summary_report['sales_calculated_by_itemwise']['sales_revenue'] = round($total_sales_itemwise);
|
||||
$overall_summary_report['sales_calculated_by_itemwise']['sales_revenue'] = round($total_sales_itemwise + $total_sales_monthwise);
|
||||
($gross_profit_calculation_type[0]['mode'] == 1) ? $overall_summary_report['sales_calculated_by_itemwise']['purchases'] = round($temp_purchases,2) : $overall_summary_report['sales_calculated_by_itemwise']['cost_of_goods_sold'] = round($temp_purchases);
|
||||
$overall_summary_report['sales_calculated_by_itemwise']['grossprofit'] = round($temp_grossprofit);
|
||||
$overall_summary_report['sales_calculated_by_itemwise']['business_expenses'] = round($overall_business_expenses_total);
|
||||
|
||||
@ -1469,7 +1469,7 @@ class PD_Model extends SPARQ_Model {
|
||||
$fields = array('pdc_id','purchase_declared_by_customer','comments');
|
||||
$where_condition_array = array('fk_pd_id'=>$pdid,'isactive'=>1);
|
||||
$where_condition_array['company_id'] = $company_id ? $company_id : null;
|
||||
$purchase_declared_by_customer = $this->selectCustomRecords($fields,$where_condition_array,SALESDECLAREDBYCUSTOMER);
|
||||
$purchase_declared_by_customer = $this->selectCustomRecords($fields,$where_condition_array,PURCHASEDECLAREDBYCUSTOMER);
|
||||
|
||||
//get Gross Profit calculatio Mode details
|
||||
$fields = array('calc_type_id','mode','margin','purchase_type');
|
||||
@ -1486,25 +1486,24 @@ class PD_Model extends SPARQ_Model {
|
||||
//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'=>FREQUENCY.' as FREQUENCY','condition'=>'SALESCALCULATEDBYITEMWISE.fk_frequency_id = FREQUENCY.frequency_id','jointype'=>'LEFT'),
|
||||
array('table'=>UOM.' as UOM','condition'=>'SALESCALCULATEDBYITEMWISE.fk_uom_id = UOM.uom_id','jointype'=>'LEFT'));
|
||||
$sales_calculated_by_itemwise = $this->getJoinRecords($fields,$table,$joins,$where_condition_array);
|
||||
|
||||
//print_r($sales_calculated_by_itemwise);
|
||||
if(count($sales_calculated_by_itemwise))
|
||||
{
|
||||
foreach($sales_calculated_by_itemwise as $key => $item)
|
||||
{
|
||||
if($item['sales_type'] == 3)
|
||||
{
|
||||
//echo 'THREE';
|
||||
$this->db->SELECT('month(sales_date) as month,year(sales_date) as year');
|
||||
$this->db->FROM(SALESITEMMONTHWISECHILD.' as SALESITEMMONTHWISECHILD');
|
||||
$this->db->WHERE('SALESITEMMONTHWISECHILD.fk_sim_id',$item['sim_id']);
|
||||
$this->db->WHERE('SALESITEMMONTHWISECHILD.fk_sci_id',$item['sci_id']);
|
||||
$this->db->WHERE('SALESITEMMONTHWISECHILD.isactive',1);
|
||||
$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))
|
||||
{
|
||||
$sales_items_by_months = array();
|
||||
@ -1513,7 +1512,7 @@ class PD_Model extends SPARQ_Model {
|
||||
|
||||
$this->db->SELECT('simc_id,sales_date,sales_value,fk_frequency_id,frequency_value,FREQUENCY.name as frequency_name,FREQUENCY.mutiple_factor');
|
||||
$this->db->FROM(SALESITEMMONTHWISECHILD.' as SALESITEMMONTHWISECHILD');
|
||||
$this->db->WHERE('SALESITEMMONTHWISECHILD.fk_sim_id',$item['sim_id']);
|
||||
$this->db->WHERE('SALESITEMMONTHWISECHILD.fk_sci_id',$item['sci_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']);
|
||||
@ -1537,6 +1536,9 @@ class PD_Model extends SPARQ_Model {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// print_r($sales_calculated_by_itemwise);
|
||||
// die();
|
||||
|
||||
//print_r($this->db->last_query());
|
||||
|
||||
@ -1622,7 +1624,7 @@ class PD_Model extends SPARQ_Model {
|
||||
{
|
||||
$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.fk_purchase_id',$billwise['purchase_id']);
|
||||
$this->db->WHERE('PDPURCHASEBILLWISECHILD.isactive',1);
|
||||
$this->db->GROUP_BY('month(PDPURCHASEBILLWISECHILD.purchase_date)');
|
||||
$purchase_billwise_child_group = $this->db->GET()->result_array();
|
||||
@ -1636,7 +1638,7 @@ class PD_Model extends SPARQ_Model {
|
||||
|
||||
$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('PDPURCHASEBILLWISECHILD.fk_purchase_id',$billwise['purchase_id']);
|
||||
|
||||
$this->db->WHERE('month(PDPURCHASEBILLWISECHILD.purchase_date)',$child['month']);
|
||||
$this->db->WHERE('PDPURCHASEBILLWISECHILD.isactive',1);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user