@if($voucherType=='PATHOLOGY_LAB_BILLING' || $voucherType=='PATHOLOGY' || $voucherType=='IPD_ADMISSION' || $voucherType=='SALES')
<div class="row border-bottom-1 text-uppercase mx-0 font-12 report-body" style="border-top: 1px solid #565656;border-bottom: 1px solid #565656;">
    <div class="col-4"><b>Invoice No :
            {!! $sale_invoice->main_invoice_no ?? '' !!}</b>
    </div>
    <div class="col-4 text-center"><b>Date :
            {!! $sale_invoice->invoice_date ? formatedDate($sale_invoice->invoice_date) : '' !!}</b>
    </div>
    <div class="col-4 text-center">
        <b style="margin-left: -22px !important;">Batch No. : {!! $sale_invoice->invoice_batch_no ?? '' !!}</b>
    </div>
</div>
@elseif($voucherType=='CONTRA' || $voucherType=='JOURNAL')
<div class="row border-bottom-1 text-uppercase mx-0 font-12 mt-2" style="border-top: 1px solid #565656;border-bottom: 1px solid #565656;">
    <div class="col-4"><b>Voucher No : {!! $sale_invoice->voucher_no ?? '' !!}</b>
    </div>
    <div class="col-4 text-center"><b>
            Date : {!! ($sale_invoice->transaction_date ? formatedDate($sale_invoice->transaction_date) : '') !!}</b>
    </div>
    <div class="col-4 text-center">
        <b style="margin-left: -22px !important;">Reff No. : {!! $sale_invoice->reference !!}</b>
    </div>
</div>
@elseif($voucherType=='OPD_BOOKING')
<div class="row border-bottom-0 text-uppercase font-12 mt-2 report-body" style="border-top: 1px solid #565656;border-bottom: 1px solid #565656;">
    <div class="col-4 font-12" style="text-align: left;"><b>Invoice No : {!! $sale_invoice->booking_no ?? '' !!}</b></div>
    <div class="col-4 text-center font-12"><b>Date : {!! $sale_invoice->booking_date_time ? formatedDate($sale_invoice->booking_date_time) : '' !!}</b></div>
    <div class="col-4 text-right font-12" style="text-align: right;"> <b>Serial No. : {!! $sale_invoice->appointment_serial_no ?? '' !!}</b>
    </div>
</div>
<div class="row border-bottom-0 text-uppercase font-12 report-body" style="border-top: 1px solid #565656;border-bottom: 1px solid #565656;">
    <div class="col-4 font-12" style="text-align: left;">
        <b>Appointment Date : {!! ($sale_invoice->appointment_date_time ? formatedDate($sale_invoice->appointment_date_time) : '') !!}</b>

    </div>
    <div class="col-4 text-center font-12"><b style="margin-left: -10px;">Time : {!! ($sale_invoice->appointment_date_time ? date('h:i A',strtotime($sale_invoice->appointment_date_time)) : '') !!}</b></div>
    <div class="col-4 text-left font-12" style="text-align: right;"><b>Ref. : {!! 'Walk In' !!}</b></div>
</div>
@endif
@if($voucherType=='PATHOLOGY_LAB_BILLING' || $voucherType=='PATHOLOGY' || $voucherType=='IPD_ADMISSION' || $voucherType=='SALES' || $voucherType=='OPD_BOOKING')
@php
$patient = $sale_invoice->getPatient;
$patientContact = $patient->account_contact ?? null;
$patientTitle = $patient->account_title??null;
$patientAddress = $patient->first_account_address ?? null;
$dateOfBirth = $patientContact->date_of_birth ?? '';
$age = $dateOfBirth != '' ? age($dateOfBirth) : 0;
$generatorPNG = new Picqer\Barcode\BarcodeGeneratorPNG();

if($voucherType=='OPD_BOOKING')
{
    $ref_doctor = $sale_invoice->getDoctorAccount ? ucfirst(@$sale_invoice->getDoctorAccount->name) : 'Self';
    $doctorTitle = $sale_invoice->getDoctorAccount->account_title??null;
    $doctorQualification = $sale_invoice->getDoctorAccount->account_contact??null;
    $generatorPNG = new Picqer\Barcode\BarcodeGeneratorPNG();
    $mainInvoiceNo = $sale_invoice->booking_no ?? $sale_invoice->main_invoice_no;
    $collectionAgent = $sale_invoice->getCollectionAgent? ucfirst(@$sale_invoice->getCollectionAgent->name):'';
    $collectionAgentTitle = $sale_invoice->getCollectionAgent->account_title??null;

    $referralLab = $sale_invoice->getRefferalLab?ucfirst(@$sale_invoice->getRefferalLab->name):'';
    $referralLabTitle = $sale_invoice->getRefferalLab->account_title??null;
}
else
{
    $ref_doctor = $sale_invoice->getDoctor ? ucfirst(@$sale_invoice->getDoctor->name) : 'Self';
    $doctorTitle = $sale_invoice->getDoctor->account_title??null;
    $doctorQualification = $sale_invoice->getDoctor->account_contact??null;

    $collectionAgent = $sale_invoice->getCollectionAgent? ucfirst(@$sale_invoice->getCollectionAgent->name):'';
    $collectionAgentTitle = $sale_invoice->getCollectionAgent->account_title??null;

    $referralLab = $sale_invoice->getRefferalLab?ucfirst(@$sale_invoice->getRefferalLab->name):'';
    $referralLabTitle = $sale_invoice->getRefferalLab->account_title??null;
    $mainInvoiceNo = $sale_invoice->voucher_type_invoice_no ?? '';
}
$barcodeData = base64_encode($generatorPNG->getBarcode($mainInvoiceNo, $generatorPNG::TYPE_CODE_128));
@endphp
<div class="row report-body">
    <div class="col-12 ">
        <table class="table table-borderless table-sm mb-1" id="account_to">
            <tbody>
                <tr>
                    <td>
                        <div class="row mx-0 " style="padding-top: 4px; padding-bottom: 4px;border-bottom: 1px solid #565656;">
                            <div class="col-5 border-right border-dark">
                                <table class="table table-borderless mb-1 w-100 table-line-height1-2">
                                    <tbody>
                                        <tr class="fw-bold">
                                            <td style="width:20%">Name</td>
                                            <td>:</td>
                                            <td colspan="3" style="padding-left: 2px;{!! $cap_names == 'yes' ? 'text-transform: uppercase;' : ''; !!}">
                                                {!! $patientTitle?$patientTitle->name:'' !!} {{ $patient->name }}
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>{!! $patient->unique_register_no?'ABHA':'UH' !!} ID</td>
                                            <td>:</td>
                                            <td colspan="3" style="padding-left: 2px">
                                                <b>{{ $patient->unique_register_no?$patient->unique_register_no:$patient->code }}</b>
                                            </td>
                                        </tr>
                                        @if ($patientContact)
                                        <tr>
                                            <td>Gender/Age</td>
                                            <td>:</td>
                                            <td style="padding-left: 2px">{{ $patientContact->gender->name ?? '' }}{{ $age > 0 ? ', '.$age.' Years' : '' }}
                                            </td>
                                        </tr>
                                        @endif
                                        @foreach (accountLicenses($patient->id) as $value)
                                        <tr>
                                            <td>{!! $value->name !!}</td>
                                            <td>:</td>
                                            <td style="padding-left: 2px">{!! $value->license_number !!}</td>
                                        </tr>
                                        @endforeach
                                        <tr>
                                            <td>Address</td>
                                            <td>:</td>
                                            <td style="padding-left: 2px">
                                                {{-- @php
                                                $address = generate_comma_separated_string(['address'=>$patientAddress->address_line1,
                                                'city'=>$patientAddress->city->name,
                                                'state'=>$patientAddress->state->name,
                                                'country'=>$patientAddress->country->name]);
                                                @endphp --}}

                                                {!! $patientAddress->city->name??'' !!}
                                            </td>
                                        </tr>
                                        <tr class="font-weight-bold">
                                            <td>Phone No</td>
                                            <td>:</td>
                                            <td colspan="3" style="padding-left: 2px"> {!! $patientContact->phone_no ?? '' !!}
                                                @if ($patientContact->whatsapp_no)
                                                WhatsApp : {!! $patientContact->whatsapp_no !!}
                                                @endif
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                            <div class="col-4 line-height1-2">
                                @if($voucherType!='SALES')
                                <table class="table table-borderless mb-1 w-100 table-line-height1-2" style="margin-left: -3.9px;">
                                    <tbody>
                                        <tr class="fw-bold">
                                            <td width="35%">Ref. Doctor</td>
                                            <td>:</td>
                                            <td colspan="3" style="padding-left: 2px"> {!! $doctorTitle->name??'' !!} {{ $ref_doctor }}</td>
                                        </tr>
                                        {{-- @if($doctorQualification)
                                        <tr>
                                            <td width="35%">Dr. Qualification</td>
                                            <td>:</td>
                                            <td colspan="3" style="padding-left: 2px"> {!! $doctorQualification->qualifications??'' !!}</td>
                                        </tr>
                                        @endif --}}
                                        {{-- @if($collectionAgent)
                                        <tr class="font-weight-bold">
                                            <td>Collection Agent</td>
                                            <td>:</td>
                                            <td colspan="3" style="padding-left: 2px">{!! $collectionAgentTitle->name??'' !!} {{ $collectionAgent }} </td>
                                        </tr>
                                        @endif --}}
                                        @if($referralLab)
                                        <tr class="font-weight-bold">
                                            <td>Ref. Partner</td>
                                            <td>:</td>
                                            <td colspan="3" style="padding-left: 2px">
                                                {!! $referralLabTitle->name??'' !!} {{ $referralLab }}
                                            </td>
                                        </tr>
                                        @endif
                                        <tr >
                                            <td width="35%">Registered At</td>
                                            <td>:</td>
                                            <td colspan="3" class="registered_at" style="padding-left: 2px"></td>
                                        </tr>
                                        <tr >
                                            <td width="35%">Collected At</td>
                                            <td>:</td>
                                            <td colspan="3" class="collected_at" style="padding-left: 2px"></td>
                                        </tr>
                                    </tbody>
                                </table>
                                @endif
                            </div>
                            <div class="col-3 border-right border-dark my-auto line-height1-2">
                                <div class="text-end">
                                    <div class="text-center">
                                        {{--@if($voucherType=='IPD_ADMISSION')
                                        {!! DNS1D::getBarcodeHTML($sale_invoice->voucher_type_invoice_no, 'C93') !!}
                                        @else --}}
                                        <img class="barcodeStyle" src="data:image/png;base64,{{ $barcodeData }}">
                                        {{--@endif --}}
                                    </div>
                                    <div class="text-center">
                                        <span class="font-14"><b>{!! $mainInvoiceNo !!}</b></span>
                                    </div>
                                </div>
                            </div>
                            {{-- <div class="col-1 border-right border-dark my-auto line-height1-2" style="text-align: left">
                                <span class="" style="width: 10px">{!! DNS2D::getBarcodeSVG($mainInvoiceNo, 'QRCODE') !!}</span>
                            </div> --}}
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
@endif
{{-- <div class="row mb-1">
    <div class="col-12 text-center">
        <span class="text-bold my-auto font-14">{!! $voucher_type->voucher_title ?? '' !!}
        </span>
    </div>
</div> --}}
