@php use Illuminate\Support\Facades\DB; $distypes = []; $grnd_dttl_count_sum = 0; $grnd_act_count_sum = 0; $grnd_net_sale_sum = 0; @endphp
Product Sales Report
Period From: {{date('M-Y',strtotime($start_date))}} Period To: {{date('M-Y',strtotime($end_date))}}
@foreach($disttypes as $row) @endforeach @foreach($disttypes as $row) @endforeach @foreach($areas as $key=>$area) @php $ttl_count_sum = 0; $act_count_sum = 0; $net_sale_sum = 0; @endphp @foreach($disttypes as $disttype) @php $ttl_count = DB::table('distributor_details')->where('distributor_type_id',$disttype->id)->where('distributor_area_id',$area->id)->count(); $ttl = DB::table('orders_dist') ->join('order_contents_dist', 'order_contents_dist.order_id', '=', 'orders_dist.id') ->selectRaw("SUM(parent_qty_sold) as total_qty_sold, COUNT(DISTINCT(orders_dist.distributor_id)) as act_dist_count") ->whereRaw("orders_dist.distributor_type_id = '{$disttype->id}' AND orders_dist.booking_area= '{$area->id}' AND DATE(orders_dist.completed_at) >= '{$start_date}' AND DATE(orders_dist.completed_at) <= '{$end_date}' AND lower(orders_dist.status) = 'completed' ") ->first(); $act_count = $ttl->act_dist_count; $net_sale = $ttl->total_qty_sold; @$distypes[$disttype->id]['ttl_count'] += $ttl_count; @$distypes[$disttype->id]['act_count'] += $act_count; @$distypes[$disttype->id]['net_sale'] += $net_sale; $ttl_count_sum += $ttl_count; $act_count_sum += $act_count; $net_sale_sum += $net_sale; $grnd_dttl_count_sum += $ttl_count; $grnd_act_count_sum += $act_count; $grnd_net_sale_sum += $net_sale; @endphp @endforeach @endforeach @foreach($disttypes as $disttype) @endforeach
SN Zone Region{{@$row->distributor_type_name}}Overall
TTL.Count ACT.Count Net SalesTTL.Count ACT.Count Net Sales
{{ @$key+1 }} {{ @$area->area_name }} {{ @$area->region_name }} {{spencerRound(@(int)$ttl_count)}} {{spencerRound(@(int)$act_count)}} {{spencerRound(@(int)$net_sale)}} {{spencerRound(@(int)$ttl_count_sum)}} {{spencerRound(@(int)$act_count_sum)}} {{spencerRound(@(int)$net_sale_sum)}}
Total{{spencerRound(@(int)@$distypes[$disttype->id]['ttl_count'])}} {{spencerRound(@(int)@$distypes[$disttype->id]['act_count'])}} {{spencerRound(@(int)@$distypes[$disttype->id]['net_sale'])}} {{spencerRound(@(int)$grnd_dttl_count_sum)}} {{spencerRound(@(int)$grnd_act_count_sum)}} {{spencerRound(@(int)$grnd_net_sale_sum)}}