@nickywan123 It's impossible what do you want. change your logic that you will have 5 orders in one table, and show all items for each order.
how to group multiple orders as a single entity?
I am using snappy pdf to output a list of items bought by a user on a table in pdf. I want each table to limit only 5 items to display and the subsequent next 5 items will be on the next page with a new table and so on.
I thought of using chunk() to achieve this but my relationship model causes some issues. I have a purchase that can have many orders. Each order can have many items. So if I bought from:
Seller A: Item 1 Item 2
Seller B: Item 3
Seller C: Item 4 Item 5 Item 6
This means I will have 3 orders with 6 items. Though I want to display Item 1-5 in my first table but the chunk() loops each orders as separate, so items in seller A will be in first table and items in seller B will be in second table and so on (with a limit of 5).
My blade code:
<div class="row ">
<div class="col-xs-12 pl-1 pr-1">
<div style="border: 1px solid #000; width: 100%; height: 625px;">
@foreach($purchase->orders as $order)
@foreach($order->items->chunk(5) as $page)
<table style="width: 100%;">
<tr style="text-align: center; font-weight: 600;">
<td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 5%;">
<div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
No.
</td>
<td style="position:relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 12%;">
<div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
Product Code
</td>
<td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 53%;">
<div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
Description
</td>
<td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 6%">
<div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
Quantity
</td>
<td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 12%;">
<div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
Unit Price (RM)
</td>
<td style="font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; width: 12%;">Amount (RM)</td>
</tr>
<?php
$iterationNo = 0;
?>
{{---Iterate each page--}}
@foreach ($page as $item)
<tr style="font-size: 10pt;">
<td style="padding: 16px; text-align: center; vertical-align: top;">
<?php
$iterationNo = $iterationNo + 1;
?>
{{ $iterationNo }}
</td>
<td style="padding: 16px; vertical-align: top;">
{{ $item->product->parentProduct->product_code }}
</td>
<td style="padding: 6px; vertical-align: top;">
<table>
<tr style="font-size: 10pt;">
<td style="padding: 4px; vertical-align: top;">
<img src="{{ asset('storage/' . $item->product->parentProduct->images[0]->path . '/' . $item->product->parentProduct->images[0]->filename) }}" alt="{{ $item->product->parentProduct->name }}" style="width: 105px; height: 90px; border-radius: 10px;">
</td>
<td style="padding: 14px; vertical-align: top;">
<p style="margin-bottom: 10px;">
{{ $item->quantity }} x {{ $item->product->parentProduct->name }}
</p>
<p style="margin: 0;">
@if(array_key_exists('product_color_name', $item->product_information))
Color: {{ $item->product_information['product_color_name'] }}
@endif
@if(array_key_exists('product_size', $item->product_information))
Color Temperature: {{ $item->product_information['product_size'] }}
@endif
@if(array_key_exists('product_temperature', $item->product_information))
Color Temperature: {{ $item->product_information['product_temperature'] }}
@endif
</p>
</td>
</tr>
</table>
</td>
<td style="padding: 16px; text-align: center; vertical-align: top;">
{{ $item->quantity }}
</td>
<td style="padding: 16px; text-align: center; vertical-align: top;">
{{ $item->product->getDecimalPrice() }}
</td>
<td style="padding: 16px; text-align: center; vertical-align: top;">
{{ number_format(($item->subtotal_price / 100), 2) }}
</td>
</tr>
@endforeach
</table>
@endforeach
@endforeach
</div>
</div>
How do I chunk items as one instead of orders?
Please or to participate in this conversation.