<div class="modal fade" id="print_preview_modal" style="padding-top: 40px; background: rgba(0, 0, 0, 0.54); overflow: auto; padding-left: 17px;">
    <div class="print-preview-header">
        <div class="presult-pagination d-none">
            <input type="text" class="page-number" value="1" onfocus="this.select()"> /
            <span class="page-count">1</span>
        </div>
        <ul>
            <li style="display: inline-block;" class="print">
                @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['print_result']))
                    <a href="javascript:void(0)" onclick="printJS('presult-1-dt', 'html')" id="doPrinting"><i class="fa fa-print"></i>&nbsp;<b>{{__('sample.btn_print')}}</b></a>
                @endif
            </li>
        </ul>
        <span class="close-preview" data-dismiss="modal" title="Close"><i class="fa fa-times"></i></span>
    </div>
    <div class="modal-dialog modal-xxl A4-portrait"><div class="psample-result active" id="presult-1-dt">

            <title>Result</title>
            <meta name="viewport" content="width=device-width, initial-scale=.5, maximum-scale=12.0, minimum-scale=.25, user-scalable=yes">
            {{--<link rel="stylesheet" href="{{url(env("APP_URL").'storage/assets/libs/lightgallery/preview_result.css')}}">--}}
            <style>


                @font-face {
                    font-family: 'KhmerOS_muollight';

                    src: url('{{url(env("APP_URL").'storage/assets/fonts/KhmerOS_muollight.ttf')}}');
                }

                .KhmerOS {
                    font-family: 'SourceSerifPro-Regular', 'KhmerOS', 'serif';
                }
                .KhmerMoulLight {
                    font-family: 'SourceSerifPro-Regular', 'KhmerOS_muollight', 'serif';
                }
                .tacteng {
                    font-family: Tacteng !important;
                }
                .sourceserifpro-bold {
                    font-family: 'SourceSerifPro-Bold', 'serif';
                }
                /*body {
                    background: rgb(204, 204, 204);
                }*/
                page[size="A4"] {
                    background: white;
                    width: 29.7cm;
                    display: block;
                    margin: 10px auto;
                    margin-left: 0.5cm !important;
                    box-shadow: 0 0 0.5cm rgba(0,0,0,0.5);
                    padding: 1cm;
                    font-family: 'SourceSerifPro-Regular', 'Noto Sans Khmer', 'serif';
                    font-size: 13pt;
                    line-height: 23px;
                    page-break-after: always;
                }

                page[size="A4"], th, td {
                    -webkit-box-sizing: border-box;
                    -moz-box-sizing: border-box;
                    box-sizing: border-box;
                }

                page[size="A4"] table {
                    border-spacing: 2px !important;
                    border-collapse: separate !important;
                }

                table th, table td {
                    text-align: left;
                }
                table td {
                    font-weight: normal;
                }

                table.patient-info, table.department-sample-info  {
                    border: 1px solid #7a7a7a;
                    line-height: 18px;
                    padding: 3px;
                }
                table.patient-info td, table.patient-info th {
                    vertical-align: top;
                }
                table.department-sample-info {
                    background-color: #ebebeb;
                }

                table.test-result {
                    font-family: 'SourceSerifPro-Regular', 'serif';
                }
                table.test-result tr th {
                    border-bottom: 1px solid black;
                }
                table.test-result tr th:not(:last-child), table.test-result tr td:not(:last-child) {
                    padding-right: .2cm;
                }
                table.test-result tr:first-child + tr td {
                    padding-top: 5px;
                }

                p.value-pair {
                    position: relative;
                    width: 100%;
                    margin: 0;
                }

                p.value-pair:before {
                    content: '';
                    display: block;
                    position: absolute;
                    width: 100%;
                    bottom: .25rem;
                    height: 0;
                    line-height: 0;
                    border-bottom: 2px dotted #858585;
                }

                p.value-pair .name {
                    background: white;
                    z-index: 1;
                    position: relative;
                    padding-right: 5px;
                }

                p.value-pair .value {
                    background: white;
                    z-index: 1;
                    right: 0;
                    position: absolute;
                    padding-left: 5px;
                    font-weight: bold;
                }

                .text-center {
                    text-align: center;
                }
                .text-no-wrap {
                    white-space: nowrap;
                }

                @page {
                    margin: 1cm 1cm 0;
                }

                @media print {
                    @page {
                        margin-top: 0.1cm;
                        margin-left: 0.5cm !important;
                    }
                    
                    @page :second {
                       margin-top: 2cm;
                    }

                    body,
                    page[size="A4"] {
                        margin-left: 0.1cm !important;
                        padding-right: 1cm !important;
                        box-shadow: none;
                        background-color: transparent;
                    }

                    #print_preview_modal_detail .table-inv th, .table-inv td {
                        border: 1px solid black;
                        border-collapse: collapse;
                    }

                    .bg-light{
                        background: #e8e8e8 !important;
                    }

                    .border-0{
                        border:none !important;
                    }

                }

                #print_preview_modal_detail .table-inv th, .table-inv td {
                    border: 1px solid black;
                    border-collapse: collapse;
                }

                .bg-light{
                    background: #e8e8e8 !important;
                }

                .border-0{
                    border:none !important;
                }
                
                #print_preview_modal .modal-dialog.A4-portrait {
                    width: 29.7cm !important;
                }

            </style>


            <page size="A4">
            
                
                <table border="0" width="100%">
                    <thead>
                    <tr>
                        <th style="width:100%" class="text-center">
                            @if(!empty($samplePhysician->logo))
                                <img width="100%" class="rounded-0" src="{{ url(env("APP_URL").'storage/images/physician/'.$samplePhysician->logo) }}"  />
                            @else
                                <table width="100%">
                                    <tr>
                                        <td style="width:120px; vertical-align: top;" class="text-center">
                                            <img src="{{url(env("APP_URL").'storage/images/avatars/labs/'.$labSettings->logo)}}" alt="Logo" style="width: 120px;">
                                        </td>
                                        <td class="text-center">
                                            <p style="line-height: 13px !important; font-size: 15pt; font-weight: bold; color: #0000ff;" class="KhmerMoulLight py-1">{{$labSettings->name_kh}}</p>
                                            <p style="line-height: 13px !important; font-size: 13.5pt; font-weight: bold; color: #0000ff;" class="text-uppercase py-1">{{$labSettings->name_en}}</p>
											<p style="line-height: 10px !important;">{{ app()->getLocale()=='kh' ? $labSettings->address_kh : $labSettings->address_en}} </p>
											<p style="line-height: 10px !important;">{{$labSettings->phone_number}} {{$labSettings->email}}</p>
 
                                        </td>
                                        <td style="width:120px" >&nbsp;</td>
                                    </tr>
                                </table>
                            @endif
                        </th>
                    </tr>
                    <tr>
                        <td class="text-top text-center">
                            <div class="" style="font-size: 13pt; font-weight: 600;text-decoration: underline;">{{__('Laboratory Financial Report')}}</div>
                        </td>
                    </tr>

                </table>

                @if(!empty($financialReport))
                @if(date('d/m/Y',strtotime($_GET['start_date']))==date('d/m/Y',strtotime($_GET['end_date'])))
                <p style="text-align: center">{{__('Date:') . date('d-M-Y',strtotime($_GET['start_date']))}}</p>
                @else
                <p style="text-align: center">{{__('From Date:') . date('d-M-Y',strtotime($_GET['start_date'])) . ' To Date: '.date('d-M-Y',strtotime($_GET['end_date']))}}</p>
                @endif
                @endif
                
                <table class="table-inv" width="100%" border="0" style="border-collapse: collapse !important; font-size: 9pt">
                    <thead>
                    <tr class="bg-light">
                        <td width="30px" style="padding-left: 1px; text-align:center;">No.</td>
                        <td width="50px" style="padding-left: 1px; text-align:center;">Invoice Date</td>
                        <td width="80px" style="padding-left: 1px; text-align:center;">Sample No</td>
                        <td width="100px" style="padding-left: 1px; text-align:center;">Patient Name</td>
                        <td width="100px" style="padding-left: 1px; text-align:center;">Physician</td>
                        <td style="padding-left: 5px; text-align:center;">Test Name</td>
                        <td width="70px" style="padding-right: 1px; text-align:center;">Total</td>
                        <td width="70px" style="padding-right: 1px; text-align:center;">Discount</td>
                        <td width="70px" style="padding-right: 1px; text-align:center;">Net Amount</td>
                        <td width="70px" style="padding-right: 1px; text-align:center;">Cash Pay</td>
                        <td width="70px" style="padding-right: 1px; text-align:center;">Bank Pay</td>
                        <td width="70px" style="padding-right: 1px; text-align:center;">Owe</td>
                    </tr>
                    
                    </thead>
                    <tbody>
                        @php
                            $i=1;
                            $totalPrice = 0;
                            $total = 0;
                            $total_discount = 0;
                            $total_paid = 0;
                            $total_bank_paid = 0;
                            $total_owe = 0;
                        @endphp
                        @foreach($financialReport as $row)
                            <tr>
                                <td style="text-align:center;">{{$i}}</td>
                                 <td style="text-align:center;">{{date('d/m/y',strtotime($row['date']))}}</td>
                                 <td style="padding-left: 1px">{{$row['sample_number']}}</td>
                                  <td style="padding-left: 1px">{{$row['patient']}}</td>
                                  <td style="padding-left: 1px">{{$row['physician']}}</td>
                                  <td style="padding-left: 1px">{{$row['test_name']}}</td>
                                 <td style="padding-right: 1px; text-align: right">{{$row['total_amount']}}</td>
                                 <td style="padding-right: 1px; text-align: right">{{$row['total_discount']}}</td>
                                 <td style="padding-right: 1px; text-align: right">{{$row['total_net_amount']}}</td>
                                 <td style="padding-right: 1px; text-align: right">{{$row['total_paid']}}</td>
                                 <td style="padding-right: 1px; text-align: right">{{$row['total_bank_paid']}}</td>
                                 <td style="padding-right: 1px; text-align: right">{{$row['total_owe']}}</td>
                            </tr>
                            @php
                                $totalPrice+=$row['total_net_amount'];
                                $total += $row['total_amount'];
                                $total_discount += $row['total_discount'];
                                $total_paid += $row['total_paid'];
                                $total_bank_paid += $row['total_bank_paid'];
                                $total_owe += $row['total_owe'];
                                $i++;
                            @endphp
                        @endforeach
                        
                        <tr><td colspan="12" style="padding-left:20px">Exchange Rate : 1 USD = {{$labSettings->exchange_rate}}</td></tr>

                        <tr>
                            <td style="text-align: right; font-weight: bold" class="border-0" colspan="6">{{__('TOTAL')}}&nbsp;&nbsp;</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($total),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format(($total * $labSettings->exchange_rate))}}</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($total_discount),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format(($total_discount * $labSettings->exchange_rate))}}</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($totalPrice),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format(($totalPrice * $labSettings->exchange_rate))}}</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($total_paid),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format(($total_paid * $labSettings->exchange_rate))}}</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($total_bank_paid),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format(($total_bank_paid * $labSettings->exchange_rate))}}</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($total_owe),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format(($total_owe * $labSettings->exchange_rate))}}</td>
              
                        </tr>
                        @if($labSettings->is_hide_comission_percentage>0)
                        @php
                            $ownBenefitRate = ((100 - $labSettings->is_hide_comission_percentage));
                        @endphp

                        <tr>
                            <td style="text-align: right; font-weight: bold" class="border-0" colspan="6">{{$labSettings->is_hide_comission_percentage}}% {{__('Percent')}}&nbsp;&nbsp;</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($total * ($labSettings->is_hide_comission_percentage/100)),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format((($total * ($labSettings->is_hide_comission_percentage/100)) * $labSettings->exchange_rate))}}</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($total_discount * ($labSettings->is_hide_comission_percentage/100)),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format((($total_discount * ($labSettings->is_hide_comission_percentage/100)) * $labSettings->exchange_rate))}}</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($totalPrice * ($labSettings->is_hide_comission_percentage/100)),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format((($totalPrice * ($labSettings->is_hide_comission_percentage/100)) * $labSettings->exchange_rate))}}</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($total_paid * ($labSettings->is_hide_comission_percentage/100)),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format((($total_paid * ($labSettings->is_hide_comission_percentage/100)) * $labSettings->exchange_rate))}}</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($total_bank_paid * ($labSettings->is_hide_comission_percentage/100)),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format((($total_bank_paid * 0.4) * $labSettings->exchange_rate))}}</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($total_owe * ($labSettings->is_hide_comission_percentage/100)),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format((($total_owe * ($labSettings->is_hide_comission_percentage/100)) * $labSettings->exchange_rate))}}</td>
                        </tr>

                        
                        <tr>
                            <td style="text-align: right; font-weight: bold" class="border-0" colspan="6">{{$ownBenefitRate}}% {{__('Percent')}}&nbsp;&nbsp;</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($total * ($ownBenefitRate/100)),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format((($total * ($ownBenefitRate/100)) * $labSettings->exchange_rate))}}</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($total_discount * ($ownBenefitRate/100)),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format((($total_discount * ($ownBenefitRate/100)) * $labSettings->exchange_rate))}}</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($totalPrice * ($ownBenefitRate/100)),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format((($totalPrice * ($ownBenefitRate/100)) * $labSettings->exchange_rate))}}</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($total_paid * ($ownBenefitRate/100)),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format((($total_paid * ($ownBenefitRate/100)) * $labSettings->exchange_rate))}}</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($total_bank_paid * ($ownBenefitRate/100)),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format((($total_bank_paid * ($ownBenefitRate/100)) * $labSettings->exchange_rate))}}</td>
                            <td style="text-align: right;" class="bg-light"><b style="float: left">&nbsp;$ </b> {{number_format(($total_owe * ($ownBenefitRate/100)),2)}}<br><b style="float: left">&nbsp;៛ </b> {{number_format((($total_owe * ($ownBenefitRate/100)) * $labSettings->exchange_rate))}}</td>
                        </tr>
                        @endif
                    </tbody>
                </table>

           {{--        @endforeach --}}

                <table id="footer_" width="100%" border="0" style="margin-top:20px !important;">
                    <tbody>
                    <tr style="height:40px !important;">&nbsp;<br><td colspan="3"></td></tr>
                    <tr>
                        <td class="text-center text-no-wrap" style="width: 7cm"></td>
                        <td style="width: 7cm"></td>
                        <td class="text-center text-no-wrap" style="width: 7cm">
                            {{__('Reported By')}} </td>
                    </tr>
                    <tr class="result-footer-signature">
                        <td class="text-center text-no-wrap" valign="bottom">

                        </td>
                        <td class="text-center text-no-wrap"></td>
                        <td class="text-center text-no-wrap">........................ <br>
                        {{date('d-M-Y H:i')}}<br>
                            <!--@if(!empty(Auth::user()->signature))-->
                            <!--    <img id="signature-preview" style="width: 120px !important;" src="{{url(env("APP_URL").'storage/images/signature/'.Auth::user()->signature)}}">-->
                            <!--@else-->
                            <!--    <br>-->
                            <!--@endif-->
                            <!--<p style="text-transform: capitalize;">{{$labSettings->technician_label}}</p>-->
                        </td>
                    </tr>
                    </tbody></table>
            </page>
        </div></div>

    <button class="previous d-none"><i class="fa fa-chevron-left"></i></button>
    <button class="next d-none"><i class="fa fa-chevron-right"></i></button>
</div>
