FROM: SNT
PH: +91 9043736796
|
TO: {{ $invoice->name }}
PH: {{ $invoice->phone_no }}
|
| S.NO |
ITEM |
BALE NO'S |
NO. OF BALES |
PCS/BALE |
NO.OF PCS |
UNIT PRICE |
AMOUNT |
@php
$total = 0;
$Noofpics = 0;
$allBaleNos = [];
// Step 1: Build map of all bale numbers → list of their corresponding item indexes
foreach ($obeinvoice_list as $index => $item) {
$bales = json_decode($item->bale_no);
foreach ($bales as $bale) {
$bale = trim($bale);
$allBaleNos[$bale][] = $index;
}
}
// Step 2: Track which index is already marked as "first" for a duplicate bale
$markedFirstIndexes = [];
foreach ($obeinvoice_list as $index => $item) {
$bales = json_decode($item->bale_no);
foreach ($bales as $bale) {
$bale = trim($bale);
$occurrences = $allBaleNos[$bale];
$counts = count($occurrences);
if ($counts > 1) {
$firstIndex = $occurrences[0];
// If this is the first item with this duplicate bale_no
if ($index == $firstIndex && !in_array($index, $markedFirstIndexes)) {
$obeinvoice_list[$index]->duplicate_count = $counts;
$markedFirstIndexes[] = $index;
} elseif ($index != $firstIndex) {
$obeinvoice_list[$index]->duplicate_count = 0;
}
// Break because we only care about one bale_no per item
break;
}
}
}
@endphp
@foreach ($obeinvoice_list as $data)
@php
$baleNo = is_array(json_decode($data->bale_no)) ? implode(', ', json_decode($data->bale_no)) : $data->bale_no;
$total += $data->amount;
$Noofpics += $data->pic_of_bale;
@endphp
| {{ $loop->iteration }} |
{{ $data->product_name }} |
@if((isset($data->duplicate_count) && $data->duplicate_count!=0) || !isset($data->duplicate_count))
{{ $baleNo }}
|
@endif
@if((isset($data->duplicate_count) && $data->duplicate_count!=0) || !isset($data->duplicate_count))
{{$data->no_of_bale}} |
@endif
{{ $data->pic_bale }} |
{{ $data->pic_of_bale }} |
₦{{ number_format($data->unit_price, 0, '.', ',') }} |
₦{{ number_format($data->amount, 0, '.', ',') }} |
@endforeach
| TOTAL |
{{ $invoice->bale_count }} |
|
{{ number_format($Noofpics, 0, '.', ',') }} |
|
₦{{ number_format($total, 0, '.', ',') }} |