@if(!empty($invoice->ID))
INVOICE NUMBER: {{$invoice->INVOICE_NO}}
INVOICE DATE: {{empty($date_to) ? date('Y-m-d',strtotime("+3 hours")) : date("Y-m-d",strtotime($date_to))}}
INVOICING FROM: {{date("Y-m-d",strtotime($date_from))}}
INVOICING TO: {{date("Y-m-d",strtotime($date_to))}}

@if($invoice->STATUS == 0 || is_null($invoice->STATUS)) Draft Invoice @else {{$global_symbol['tax'] ?? 'TAX'}} Invoice @endif

@if($qr_image) @endif
@endif

Vendor Information

NAME: {{$profile->C_INV_NAME}}
BUILDING NO: {{$profile->C_BUILDING_NO}}
STREET: {{$profile->C_STREET}}
DISTRICT: {{$profile->C_DISTRICT}}
CITY: {{$profile->C_CITY}}
COUNTRY: {{$profile->C_COUNTRY}}
POSTAL CODE: {{$profile->C_POST_CODE}}
VAT NO: {{$profile->VAT_NO}}

Client Information

NAME: {{$insurance->LEGAL_NAME}}
BUILDING NO: {{$insurance->BUILDING_NO}}
STREET: {{$insurance->STREET}}
DISTRICT: {{$insurance->DISTRICT}}
CITY: {{$insurance->CITY}}
COUNTRY: {{$insurance->COUNTRY}}
POSTAL CODE: {{$insurance->POST_CODE}}
VAT NO: {{$insurance->VAT_NUMBER}}
@if(!empty($invoice->eNDUSER->CLIENT_LOGO))
@endif

This invoice is considered final and valid unless it is returned to us within a week from the date of receipt.

Invoice No. Invoice From Invoice To Days Qty
@if(!empty($invoice->ID)) {{$invoice->INVOICE_NO}} @endif {{date("Y-m-d",strtotime($date_from))}} {{date("Y-m-d",strtotime($date_to))}} {{date_diff(date_create($date_from),date_create($date_to))->format("%a")}} {{count($orders)}}
SubTotal {{round(($net_total - $total_tax),2)}} @if(isset($global_symbol['is_html']) && $global_symbol['is_html'] && isset($global_symbol['currency'])) {!! $global_symbol['currency'] !!} @else {{ $global_symbol['currency'] ?? 'SAR' }} @endif
Total Discount {{round($invoice->DISCOUNT_TOTAL/100,2)}} @if(isset($global_symbol['is_html']) && $global_symbol['is_html'] && isset($global_symbol['currency'])) {!! $global_symbol['currency'] !!} @else {{ $global_symbol['currency'] ?? 'SAR' }} @endif
Total {{$global_symbol['tax'] ?? 'TAX'}} {{$total_tax}} @if(isset($global_symbol['is_html']) && $global_symbol['is_html'] && isset($global_symbol['currency'])) {!! $global_symbol['currency'] !!} @else {{ $global_symbol['currency'] ?? 'SAR' }} @endif
Net Total {{$net_total}} @if(isset($global_symbol['is_html']) && $global_symbol['is_html'] && isset($global_symbol['currency'])) {!! $global_symbol['currency'] !!} @else {{ $global_symbol['currency'] ?? 'SAR' }} @endif
Paid Total {{$paid_total}} @if(isset($global_symbol['is_html']) && $global_symbol['is_html'] && isset($global_symbol['currency'])) {!! $global_symbol['currency'] !!} @else {{ $global_symbol['currency'] ?? 'SAR' }} @endif
Remaining Total {{$net_total - $paid_total}} @if(isset($global_symbol['is_html']) && $global_symbol['is_html'] && isset($global_symbol['currency'])) {!! $global_symbol['currency'] !!} @else {{ $global_symbol['currency'] ?? 'SAR' }} @endif
@php $baseRowHeight = 46; $additionalHeightPer29Chars = 21; $charLimit = 29; $patientRowHeight = 49; $maxPageHeight = 1200; $dynamicChunks = []; $currentChunk = []; $currentChunkHeight = 0; $lastPatientName = null; foreach ($orders as $order) { $isNewPatient = ($lastPatientName != $order['NAME']); $orderName = $order['lABCATEGORYPACKAGE']['NAME_EN']; $orderNameLength = strlen($orderName); $additionalHeight = 0; if ($orderNameLength > $charLimit) { $additionalSets = ceil(($orderNameLength - $charLimit) / $charLimit); $additionalHeight = $additionalSets * $additionalHeightPer29Chars; } $rowHeight = $baseRowHeight + $additionalHeight; if ($isNewPatient) { $lastPatientName = $order['NAME']; $rowHeight += $patientRowHeight; } if ($currentChunkHeight + $rowHeight > $maxPageHeight) { $dynamicChunks[] = $currentChunk; $currentChunk = []; $currentChunkHeight = $isNewPatient ? $patientRowHeight : 0; } $currentChunk[] = $order; $currentChunkHeight += $rowHeight; } if (!empty($currentChunk)) { $dynamicChunks[] = $currentChunk; } @endphp @php $summary = []; @endphp @foreach($dynamicChunks as $key => $chunk)

Details

@php $c = 1; @endphp @foreach($chunk as $order) @if(empty($order['PRICE'])) @continue @endif @if(isset($summary[$order['lABCATEGORYPACKAGE']['ID']])) @php $summary[$order['lABCATEGORYPACKAGE']['ID']]['qty'] +=1; $summary[$order['lABCATEGORYPACKAGE']['ID']]['tax'] +=round($order['INSURANCE_CREDIT_AMOUNT'] - ($order['INSURANCE_CREDIT_AMOUNT'] / (1+$order['TAX'])),2); $summary[$order['lABCATEGORYPACKAGE']['ID']]['total'] +=$order['INSURANCE_CREDIT_AMOUNT']; $summary[$order['lABCATEGORYPACKAGE']['ID']]['paid'] +=($order['AMOUNT'] / 100 - $order['PRICE']); @endphp @else @php $summary[$order['lABCATEGORYPACKAGE']['ID']]['name'] =$order['lABCATEGORYPACKAGE']['NAME_EN']; $summary[$order['lABCATEGORYPACKAGE']['ID']]['qty'] =1; $summary[$order['lABCATEGORYPACKAGE']['ID']]['unit_price'] =round(($order['INSURANCE_CREDIT_AMOUNT'] / (1+$order['TAX'])),2); $summary[$order['lABCATEGORYPACKAGE']['ID']]['tax'] =round($order['INSURANCE_CREDIT_AMOUNT'] - ($order['INSURANCE_CREDIT_AMOUNT'] / (1+$order['TAX'])),2); $summary[$order['lABCATEGORYPACKAGE']['ID']]['total'] =$order['INSURANCE_CREDIT_AMOUNT']; $summary[$order['lABCATEGORYPACKAGE']['ID']]['paid'] =($order['AMOUNT'] / 100 - $order['PRICE']); @endphp @endif @php $c++; @endphp @endforeach @if($key == count($dynamicChunks) - 1) @endif
Policy Number Reservation ID Patient Name ID No MRN Date Reservations Test ID Test Name Paid by Patient Patient {{$global_symbol['tax'] ?? 'TAX'}} Insurance Credit Insurance {{$global_symbol['tax'] ?? 'TAX'}} Total Paid
{{$order['eNDUSERLABORDER']['POLICY_NUMBER']}} {{$order['eNDUSERLABORDER']['ID']}} {{$order['NAME']}} {{$order['IDENTIFICATION']}} {{$order['MRN']}} {{$order['eNDUSERLABORDER']['CREATE_DATE']}} {{$order['lABCATEGORYPACKAGE']['ID']}}{{$order['lABCATEGORYPACKAGE']['NAME_EN']}} {{round(($order['PRICE'] / ($order['TAX']+1)),2)}} {{round($order['PRICE'] - ($order['PRICE'] / ($order['TAX']+1)),2)}} {{round(($order['INSURANCE_CREDIT_AMOUNT'] / ($order['TAX']+1)),2)}} {{round($order['INSURANCE_CREDIT_AMOUNT'] - ($order['INSURANCE_CREDIT_AMOUNT'] / ($order['TAX']+1)),2)}} {{$order['INSURANCE_CREDIT_AMOUNT']}} {{($order['AMOUNT'] / 100 - $order['PRICE'])}}
Total {{round($net_total_patient - $total_tax_patient, 2)}} {{$total_tax_patient}} {{round($net_total - $total_tax, 2)}} {{$total_tax}} {{$net_total}} {{$paid_total}}
@endforeach
@if(!empty($summary)) @php $summary_total = 0; @endphp

Summary

@foreach($summary as $testSummery) @php $summary_total += ($testSummery['total']); @endphp @endforeach
Test Name Quantity Insurance Credit Insurance {{$global_symbol['tax'] ?? 'TAX'}} Total Paid
{{$testSummery['name']}} {{$testSummery['qty']}} {{$testSummery['unit_price']}}{{$testSummery['tax']}} {{$testSummery['total']}} {{$testSummery['paid']}}
Total {{array_sum(array_column($summary, 'qty'))}} {{array_sum(array_column($summary, 'unit_price'))}} {{array_sum(array_column($summary, 'tax'))}} {{$summary_total}} {{array_sum(array_column($summary, 'paid'))}}
@endif