<div id="print_div">
    <div class="pathology-bill">
<div class="row">
<div class="col-2" style="width: 20%">
    <p>Date : {!! formatedDate(date('Y-m-d')) !!}</p>
</div>
<div class="col-7" style="text-align: center;">
    <p style="color:#0b5ed7;font-size:18px;margin-bottom: -4px !important"><b>{!! $company->name ?? '' !!}</b></p>
    <p style="font-size: 14px;"><b>Lab Billing STATEMENT</b></p>
    <p style="padding-bottom: 5px;font-size: 11px;"><b><span style="color: #698aff;">Billing</span> List</b>
    <b>From <span style="color:#698aff;" id="">{{$fromDate?formatedDate($fromDate):formatedDate(date('Y-m-d H:i:s'))}}</span> TO <span style="color:#698aff;" id="">{{$toDate?formatedDate($toDate):formatedDate(date('Y-m-d H:i:s')) }}</span>
            </b></p>
</div>
<div class="col-2" style="text-align: right; width:20%">
    <p>Time : {!! formatedTime(date('H:i:s')) !!}</p>
</div>
</div>

<div>
    <table class="table table-borderless report-container">
        <tbody class="report-content">
            <tr>
                <td class="report-content-cell">
                    <div class="row">
                        <div class="col-12">

                            <table class="table table-bordered-print w-100 table-only-header-full-width mb-1" id="quotation_products">
                                <thead>
                                    <tr class="text-uppercase">
                                        <th class="thbutton">Sl No</th>
                                        <th style="text-align: left;">Invoice No</th>
                                        <th style="text-align: left;">Batch No</th>
                                        <th style="text-align: left;">Patient</th>
                                        <th style="text-align: left;">Doctor</th>
                                        <th style="text-align: left;">Referral Lab</th>
                                        <th style="text-align: left;">Bill To</th>
                                        <!-- <th style="text-align: left;">Special Case</th> -->
                                        <!-- <th style="text-align: left;">Type</th> -->
                                        <th style="text-align: right;">Total</th>
                                        <th style="text-align: right;">Received</th>
                                        <th style="text-align: right;">Due</th>
                                        <th style="text-align: left;">Col. Status</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @php $i=1;@endphp

                                    @php
                                        $total_billing_amount = $total_received = $total_due_amount = 0;
                                    @endphp
                                    @if(count($sale_invoice)>0)
                                    @foreach($sale_invoice as $key=> $list)

                                        @php
                                            $total_received_amount = getTotalReceiptAmount($list->ac_receipt_details_ids);

                                            $due = ($list->get_sale_invoice_details_sum_total_amount - $total_received_amount) ?? 0;
                                            if (!empty($collection_status)) {
                                                if ($collection_status == 'due' && $due < 1) {
                                                    continue;
                                                }
                                                if ($collection_status == 'collected' && $due > 0) {
                                                    continue;
                                                }
                                            }
                                        @endphp
                                    <tr>
                                        <td class="text-center">{{$i}}</td>
                                        <td style="text-align: left;">@php $invoice_date = \Illuminate\Support\Carbon::parse($list->invoice_date); @endphp
                                            {{$list->main_invoice_no}}
                                            <br>
                                            {{$invoice_date->format('d-m-Y') ?? ''}}<br>
                                            {{$invoice_date->format('h:i A') ?? '' }}
                                        </td>
                                        <td style="text-align: left;">
                                            {{$list->invoice_batch_no ?? '' }}
                                        </td>
                                        <td style="text-align: left;">
                                            {{$list->account_title ?? ''}}
                                            {{$list->account_name ?? ''}}<br>
                                            {{$list->gender ?? ''}}{{ isset($list->date_of_birth) && isset($list->gender) ? ', ' : '' }} {{ isset($list->date_of_birth) ? age($list->date_of_birth) . ' Years' : '' }}
                                            <br>
                                            {{ isset($list->phone_no) ?'Ph:'. $list->phone_no:''}}
                                        </td>
                                        <td style="text-align: left;">
                                            {{$list->doctor_title ?? 'Self'}}
                                            {{$list->doctor ?? ''}}<br>
                                            Created by: {{$list->operator ?? ''}}
                                        </td>
                                        <td style="text-align: left;">
                                            {{$list->refferal_organization ?? ''}}
                                        </td>
                                        <td style="text-align: left;">
                                            {{$list->bill_to_title ?? ''}}
                                            {{$list->bill_to_account ?? ''}}
                                        </td>
                                        {{-- <td style="text-align: left;">
                                            {{$list->special_case ?? 'N/A'}}
                                        </td> --}}
                                        <td style="text-align: right;">{{ convertDecimelPoint($list->get_sale_invoice_details_sum_total_amount) ?? ''}}</td>
                                        <td style="text-align: right;">{{ convertDecimelPoint($total_received_amount) ?? ''}}</td>
                                        <td style="text-align: right;">{{ convertDecimelPoint($due) ?? ''}}</td>
                                        <td style="text-align: left;">
                                        @if($due > 0)
                                            Due
                                        @else
                                            Collected
                                        @endif
                                        </td>
                                        @php
                                            $total_billing_amount += $list->get_sale_invoice_details_sum_total_amount;
                                            $total_received += $total_received_amount;
                                            $total_due_amount += $due;
                                        @endphp
                                    </tr>
                                    @php $i++; @endphp
                                    @endforeach
                                        <tr>
                                            <td colspan="7" style="text-align: left;">Total</td>
                                            <td style="text-align: right;">{!! $total_billing_amount !!}</td>
                                            <td style="text-align: right;">{!! $total_received !!}</td>
                                            <td style="text-align: right;">{!! $total_due_amount !!}</td>
                                            <td style="text-align: right;"></td>
                                        </tr>
                                    @else
                                        <tr>
                                            <td colspan="12" class="text-center">No Data Found</td>
                                        </tr>
                                    @endif
                                </tbody>
                            </table>
                        </div>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</div>
</div>
</div>
@if(count($sale_invoice)>0)
<div class="row">
<div class="col-md-6" style="text-align: right;">
    <button id="btn_print" type="button" class="btn btn-primary btn-lg"><i class="bi bi-printer text-white"></i> Print Statement </button>
</div>

<div class="col-md-6" style="text-align: left;">
    <a href="javascript:;" class="btn btn-outline-primary export-statement"><i class="bi bi-download"></i> Export</a>
</div>
</div>
@endif
