@php // Define the maximum number of lines per page $maxLines = 14; $allDetails = $salesOrder->details; $pages = []; $currentPageItems = []; $currentLines = 0; $currentPageSubtotal = 0; foreach ($allDetails as $detail) { $maxLength = 55; $itemName = $detail->items->item_name; $linesNeeded = count(explode("\n", wordwrap($itemName, $maxLength, "\n", false))); if (($currentLines + $linesNeeded) > $maxLines) { $pages[] = [ 'items' => $currentPageItems, 'subtotal' => $currentPageSubtotal ]; $currentPageItems = []; $currentLines = 0; $currentPageSubtotal = 0; } $currentPageItems[] = $detail; $currentLines += $linesNeeded; $currentPageSubtotal += ($detail->qty*$detail->price)-($detail->qty*$detail->price*$detail->disc_percent/100); } if (!empty($currentPageItems)) { $pages[] = [ 'items' => $currentPageItems, 'subtotal' => $currentPageSubtotal ]; } $name=''; $name=$salesOrder->logo==true?'UD.OLIVIA':'SERBAJAYA'; $totalPages = count($pages); @endphp @foreach($pages as $pageNumber => $page)


  {{ str_pad($name, 35) }} {{$salesOrder->customers->customer_name ?? 'N/A'}}
  {{ str_pad('SURABAYA', 45) }} {{$salesOrder->customers->address ?? 'N/A'}}
  {{ str_pad('', 45) }} {{$salesOrder->customers->city ?? 'N/A'}}
  {{ str_pad('', 45) }} TGL PERMINTAAN : {{ \Carbon\Carbon::parse($salesOrder->document_date)->format('d-m-Y') }}

  PERMINTAAN PENJUALAN                          {{ substr($salesOrder->sales_order_number,7) }}
 —————————————————————————————————————————————————————————————————————————————————————————————————
 |NO |                        NAMA BARANG                    | QTY| UNIT|    HARGA |     SUBTOTAL|
 —————————————————————————————————————————————————————————————————————————————————————————————————
@php
     $count = 0;
     $startingIndex = 0;
     for ($i = 0; $i < $pageNumber; $i++) {
         $startingIndex += count($pages[$i]['items']);
     }
@endphp
@foreach($page['items'] as $index => $detail)
@php
     $maxLength = 55;
     $itemName = $detail->items->item_name;
     $lines = explode("\n", wordwrap($itemName, $maxLength, "\n", false));
@endphp
@foreach($lines as $lineIndex => $line)
@if($lineIndex == 0)
 |{{ str_pad($startingIndex + $loop->parent->iteration, 3) }}|{{ str_pad($line, 55) }}|{{ str_pad(number_format($detail->qty, 0, ',', '.'), 4, ' ', STR_PAD_LEFT) }}|{{ str_pad($detail->unit, 5, ' ', STR_PAD_LEFT) }}|{{ str_pad(number_format($detail->price, 0, ',', '.'), 10, ' ', STR_PAD_LEFT) }}|{{ str_pad(number_format(($detail->qty*$detail->price), 0, ',', '.'), 13, ' ', STR_PAD_LEFT) }}|
@else
 |{{ str_pad('', 3) }}|{{ str_pad($line, 55) }}|{{ str_pad('', 4) }}|{{ str_pad('', 5) }}|{{ str_pad('', 10) }}|{{ str_pad('', 13) }}|
@endif
@php
     $count++;
@endphp
@endforeach
@endforeach
@for($i = 0; $i < ($maxLines - $count); $i++)
 |{{ str_pad('', 3) }}|{{ str_pad('', 55) }}|{{ str_pad('', 4) }}|{{ str_pad('', 5) }}|{{ str_pad('', 10) }}|{{ str_pad('', 13) }}|
@endfor
 —————————————————————————————————————————————————————————————————————————————————————————————————
 |                                                                |SUBTOTAL         {{ str_pad(number_format($page['subtotal'], 0, ',', '.'), 13, ' ', STR_PAD_LEFT) }}|
 —————————————————————————————————————————————————————————————————————————————————————————————————
  {{ str_pad('', 45) }}                   |TOTAL            {{ str_pad(number_format($salesOrder->subtotal, 0, ',', '.'), 13, ' ', STR_PAD_LEFT) }}|
@if($salesOrder->disc_nominal>0||$salesOrder->disc_percent==0)
  {{ str_pad('', 45) }}                   |DISCOUNT         {{ str_pad(number_format($salesOrder->disc_nominal, 0, ',', '.'), 13, ' ', STR_PAD_LEFT) }}|
@endif
@if($salesOrder->disc_percent>0)
  {{ str_pad('', 45) }}                   |DISCOUNT {{str_pad(('('.number_format($salesOrder->disc_percent,1).' %)'), 7, ' ', STR_PAD_LEFT)}} {{ str_pad(number_format(($salesOrder->subtotal*$salesOrder->disc_percent/100), 0, ',', '.'), 13, ' ', STR_PAD_LEFT) }}|
@endif
  {{ str_pad('', 45) }}                   |GRAND TOTAL      {{ str_pad(number_format($salesOrder->total, 0, ',', '.'), 13, ' ', STR_PAD_LEFT) }}|
                                                                  ————————————————————————————————
                                                                                {{ ($pageNumber + 1) }} of {{ $totalPages }}
        
@endforeach Kembali