Я застрял в очень сложной проблеме, у меня есть магазины, группы и таблица заказов. Я хочу показать все заказы всех магазинов, которые имеют тот же идентификатор группы, который я пробовал, но я получаю индивидуальную группу магазинов, пожалуйста, проверьте на скриншоте вы поймете мою проблему
Для сгруппированных магазинов, я думаю, следует показать и группу, и магазин
заранее спасибо
// show the last 7 days report
public function getSalesStores()
{
$weekStart = Carbon::parse('last Sunday')->subdays(7);
$weekEnd = $weekStart->copy()->adddays(7);
$allusers = User::getAllUsers();
$allgroups = storeGroup::getAllGroups();
$allstores = Storeinfo::select('id', 'store_name', 'site_percent', 'fee_type', 'store_group_id')
->whereHas('userorders', function ($query) use ($weekStart, $weekEnd) {
$query->whereBetween('order_date', [$weekStart, $weekEnd]);
})
->with(['userorders' => function ($query) use ($weekStart, $weekEnd) {
$query
->whereBetween('order_date', [$weekStart, $weekEnd])
->whereNotIn('confirmed', ['c', 'a', 'r'])
->groupBy('userorders.order_number');
}])
->orderBy('storeinfos.store_name')
->get();
$groupedStores = $allstores->where('store_group_id', '!=', null);
return view('managedashboard.cservicedashboard.sales_orders_bystore.archive', compact('allusers', 'allstores','allgroups','groupedStores'));
}
Blade:
<table class="table table-striped table-bordered table-hover" id="postTable">
<p class="tabletitle">Sales Report</p>
<thead>
<tr>
<th class="textcenter">Store</th>
<th class="textcenter">Total</th>
<th class="textcenter">our fee</th>
<th class="textcenter">Pay to store</th>
<th class="textcenter">Order number</th>
<th class="textcenter">Date</th>
<th class="textcenter">Store Name</th>
<th class="textcenter">Customer Name</th>
</tr>
</thead>
<tbody>
@foreach($groupedStores as $key => $store)
@php
$class = $key % 2 === 0 ? 'even' : 'odd';
$fee=0;
@endphp
<tr class="{{$class}}">
<td class="storename" rowspan="{{ $store->userorders->count() + 1 }}">
@foreach($allgroups as $allgroup)
@if(($store->store_group_id)==$allgroup->id)
{{$allgroup->name}}
@endif
@endforeach
</td>
</tr>
@foreach($store->userorders as $userorder)
<tr>
<td class="textcenter">
{{number_format($userorder->totalpayment, 2, '.', ',')}}
</td>
<td class="textcenter">
@if($store->fee_type=='total')
{{number_format(($userorder->totalpayment * ($store->site_percent / 100)), 2, '.', ',')}}
@else
{{number_format(($userorder->order_subtotal * ($store->site_percent / 100)), 2, '.', ',')}}
@endif
@php
if($store->fee_type=='total') {
$fee = $fee + number_format(($userorder->totalpayment * ($store->site_percent/100)), 2, '.', ',');
}
else {
$fee = $fee + number_format(($userorder->order_subtotal *
($store->site_percent/100)), 2, '.', ',');
}
@endphp
</td>
<td class="textcenter">
<!-- Pay to Store -->
@if($store->fee_type=='total')
{{number_format(($userorder->totalpayment - ($userorder->totalpayment * ($store->site_percent/100))), 2, '.', ',')}}
@else
{{number_format(($userorder->totalpayment -
($userorder->order_subtotal * ($store->site_percent/100))), 2, '.', ',')}}
@endif
</td>
<td class="textcenter">
{{$userorder->order_number}}
</td>
<td class="textcenter">
{{date('D d M, Y', strtotime($userorder->order_date))}}
</td>
<!-- Store Name -->
<td class="textcenter">
@foreach($allusers as $alluser)
@if(($userorder->user_id)==$alluser->id)
{{$alluser->fname}}
@endif
@endforeach
</td>
<!-- Customer Name -->
<td class="textcenter">
@foreach($allusers as $alluser)
@if(($userorder->user_id)==$alluser->id)
{{$alluser->fname}}
@endif
@endforeach
</td>
</tr>
@endforeach <!-- end orders loop -->
<tr>
<td class="totalstyle">TOTAL</td>
<td class="totalstyle">
{{number_format($store->userorders->sum('totalpayment'), 2, '.', ',')}}
</td>
<td class="totalstyle">
{{$fee}}
</td>
<td class="totalstyle">
{{number_format($store->userorders->sum('totalpayment')-($fee), 2, '.', ',')}}
</td>
</tr>
@endforeach <!-- end main store loop -->