<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    @include('layout.header')
    <link href="{{url(env("APP_URL").'storage/assets/libs/bootstrap-datepicker/css/bootstrap-datepicker.min.css')}}" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="{{url(env("APP_URL").'storage/assets/libs/lightgallery/lightgallery.css')}}" >
    <link rel="stylesheet" href="{{url(env("APP_URL").'storage/assets/libs/printjs/printjs.css')}}" >
    <script src="{{url(env("APP_URL").'storage/assets/libs/printjs/printjs.min.js')}}"></script>
    <style>
        #report_tb tr td{
            padding: 10px !important;
        }
    </style>
</head>
<body>


<div class="container-scroller">
@include('layout.navbar')
<!-- partial -->
    @include('layout.breadscrum')
    <div class="container-fluid page-body-wrapper">

    @include('layout.sidebar')

    <!-- partial -->
        <div class="main-panel">
            <div class="content-wrapper">
                <div class="row">
                    <div class="col-md-12 grid-margin stretch-card">
                        <div class="card">
                            <div class="card-body">
                                <h4 class="card-title"><i class="mdi mdi-dots-vertical menu-icon"></i> {{__('sidebar.financial_report')}}</h4>
{{--                                <small><code>*</code> is generated based on the invoice</small>--}}

                                <div class="row">

                                    <div class="col-sm-12">
                                        <div class="col-sm-12 py-2 inv-search">
                                            <form method="get" action="{{url('report/financial-report')}}">
                                                <div class="row">
                                                    <div class="col-sm-12 col-md-3 col-lg-3">
                                                        <div class="form-group mb-1">
                                                            <label for="start-invoice-date">{{__('report.doctor_date_range_filter')}}</label>
                                                            <div class="input-group">
                                                            <input name="start_date" value="{{isset($_GET['start_date']) ? date('Y-m-d',strtotime($_GET['start_date'])) : ''}}" onfocus="(this.type='date')" onblur="(this.type='text')" placeholder="{{__('general.type_date_placeholder')}}" class="form-control rounded-right-0">
                                                            <input name="end_date" value="{{isset($_GET['end_date']) ? date('Y-m-d',strtotime($_GET['end_date'])) : ''}}" onfocus="(this.type='date')" onblur="(this.type='text')" placeholder="{{__('general.type_date_placeholder')}}" class="form-control  rounded-left-0">
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-sm-12 col-md-3 col-lg-2">
                                                        <div class="form-group mb-1">
                                                            <label for="lab-name-en">{{__('report.doctor_sample_source_filter')}}</label>
                                                            <select class="form-control" name="sample_source">
                                                                <option></option>
                                                                <option {{ isset($_GET['sample_source']) && $_GET['sample_source'] == -1 ? 'selected':''}} value="-1">{{__('Vaccination ')}}</option>
                                                                <option {{ isset($_GET['sample_source']) && $_GET['sample_source'] == -2 ? 'selected':''}} value="-2">{{__('Dialy Report')}}</option>
                                                                @foreach($sampleSources as $sampleSource)
                                                                    <option {{$sampleSource->id==@$_GET['sample_source'] ? 'selected':''}} value="{{$sampleSource->id}}">{{$sampleSource->name_en}}</option>
                                                                @endforeach
                                                            </select>
                                                        </div>
                                                    </div>
                                                    <div class="col-sm-12 col-md-3 col-lg-2">
                                                        <div class="form-group mb-1">
                                                            <label for="lab-name-en">{{__('report.doctor_physician_filter')}}</label>
                                                            <select class="form-control select2" name="physician">
                                                                <option></option>
                                                                <option {{'All'==@$_GET['physician'] ? 'selected':''}} value="All">All</option>
                                                                @foreach($physicians as $physician)
                                                                    <option {{$physician->id==@$_GET['physician'] ? 'selected':''}} value="{{$physician->id}}">{{$physician->name_en}}</option>
                                                                @endforeach
                                                            </select>
                                                        </div>
                                                    </div>
                                                    <div class="col-sm-12 col-md-7 col-lg-5 p-0 m-0">
                                                        <div class="form-group">
                                                             <label for="lab-name-en">&nbsp;</label>
                                                            <div class="input-group p-0 m-0">
                                                                <div class="input-group-append p-0 m-0">
                                                                    <button class="btn btn-inverse-secondary rounded-25" title="Search" type="submit"><i class="fa fa-search"></i> {{__('report.btn_view')}}</button>
                                                                    <a href="{{url('report/financial-report')}}" class="btn rounded-25 btn-inverse-warning ml-1 mx-3 " title="Clear Search Filter"><i class="mdi mdi-filter-remove-outline"></i>{{__('general.btn_clear')}}</a>
                                                                    <button type="button" class="btn btn-xs btn-light rounded-25 dropdown-toggle" data-toggle="dropdown" aria-expanded="true">{{__('report.btn_action')}}</button>
                                                                    <div class="dropdown-menu" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(0px, 44px, 0px);" x-placement="bottom-start">
                                                                        <button type="button" data-toggle="modal" data-target="#print_preview_modal" data-backdrop="static" class="dropdown-item font-14">{{__('report.btn_action_print')}}</button>
                                                                        <button type="submit" value="true" name="export" class="dropdown-item font-14">{{__('report.btn_action_export')}}</button>
                                                                    </div>
                                                                </div>
                                                            </div>

                                                        </div>
                                                    </div>


                                                </div>
                                            </form> <hr class="my-3 d-none">
                                        </div>
                                        <br>
                                        <div class="col-sm-12 p-0 mb-1 mt-3">
                                            <div class="table-responsive">
                                                <table class="table table-bordered" id="report_tb">

                                                    <thead>
                                                    <tr class="bg-light">
                                                        <td style="padding-left: 10px; text-align:center;">Invoice Date</td>
                                                        <td style="padding-left: 10px; text-align:center;">Sample No</td>
														<td style="padding-left: 10px;">Patient Name</td>
														<td style="padding-left: 10px; text-align:center;">Physician</td>
                                                        <td  style="padding-right: 10px;">Exchange Rate</td>
                                                        <td style="padding-right: 10px;">Total</td>
                                                        <td  style="padding-right: 10px;">Discount</td>
                                                        <td  style="padding-right: 10px;">Net Amount</td>
                                                        <td  style="padding-right: 10px;">Cash Pay</td>
                                                        <td  style="padding-right: 10px;">Bank Pay</td>
                                                        <td  style="padding-right: 10px;">Owe</td>
                                                    </tr>

                                                    </thead>
                                                    <tbody>
                                                        @php
                                                            $i=1;
                                                            $totalPrice = 0;
                                                            $totalPriceRiel = 0;
                                                            $total = 0;
                                                            $totalRiel = 0;
                                                            $total_discount = 0;
                                                            $total_discountRiel = 0;
                                                            $total_paid = 0;
                                                             $total_paidRiel = 0;
                                                            $total_bank_paid = 0;
                                                            $total_bank_paidRiel = 0;
                                                            $total_owe = 0;
                                                            $total_oweRiel = 0;

                                                        @endphp
                                                        @foreach($financialReport as $row)
                                                            <tr>
                                                                 <td style="text-align:center;">{{$row['date']}}</td>
																 <td style="padding-left: 5px">{{$row['sample_number']}}</td>
                                                                 <td style="padding-left: 5px">{{$row['patient']}}</td>
																 <td style="padding-left: 5px">{{$row['physician']}}</td>
                                                                 <td style="padding-right: 5px; text-align: right">{{@$row['exchange_rate']}}</td>
                                                                 <td style="padding-right: 5px; text-align: right">{{$row['total_amount']}}</td>
                                                                 <td style="padding-right: 5px; text-align: right">{{$row['total_discount']}}</td>
                                                                 <td style="padding-right: 5px; text-align: right">{{$row['total_net_amount']}}</td>
                                                                 <td style="padding-right: 5px; text-align: right">{{$row['total_paid']}}</td>
                                                                 <td style="padding-right: 5px; text-align: right">{{$row['total_bank_paid']}}</td>
                                                                 <td style="padding-right: 5px; text-align: right">{{$row['total_owe']}}</td>

                                                            </tr>
                                                            @php
                                                                $totalPrice+=$row['total_net_amount'];
                                                                $totalPriceRiel+=($row['total_net_amount'] * @$row['exchange_rate']);
                                                                $total += $row['total_amount'];
                                                                $totalRiel += ($row['total_amount'] * @$row['exchange_rate']);
                                                                $total_discount += $row['total_discount'];
                                                                $total_discountRiel += ($row['total_discount'] * @$row['exchange_rate']);
                                                                $total_paid += $row['total_paid'];
                                                                $total_paidRiel += ($row['total_paid'] * @$row['exchange_rate']);
                                                                $total_bank_paid+=$row['total_bank_paid'];
                                                                $total_bank_paidRiel+=($row['total_bank_paid'] * @$row['exchange_rate']);
                                                                $total_owe += $row['total_owe'];
                                                                $total_oweRiel += ($row['total_owe'] * @$row['exchange_rate']);
                                                            @endphp
                                                        @endforeach

                                                        <tr><td colspan="11" style="padding-left:20px"></td></tr>

                                                        <tr>
                                                            <td style="text-align: right; font-weight: bold" class="border-0" colspan="5">{{__('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(($totalRiel))}}</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_discountRiel))}}</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(($totalPriceRiel))}}</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_paidRiel))}}</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_paidRiel))}}</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_oweRiel))}}</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="5">{{$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((($totalRiel * ($labSettings->is_hide_comission_percentage/100))))}}</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_discountRiel * ($labSettings->is_hide_comission_percentage/100))))}}</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((($totalPriceRiel * ($labSettings->is_hide_comission_percentage/100))))}}</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_paidRiel * ($labSettings->is_hide_comission_percentage/100))))}}</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_paidRiel * ($labSettings->is_hide_comission_percentage/100))))}}</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_oweRiel * ($labSettings->is_hide_comission_percentage/100))))}}</td>
                                                        </tr>


                                                        <tr>
                                                            <td style="text-align: right; font-weight: bold" class="border-0" colspan="5">{{$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((($totalRiel * ($ownBenefitRate/100))))}}</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_discountRiel * ($ownBenefitRate/100))))}}</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((($totalPriceRiel * ($ownBenefitRate/100))))}}</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_paidRiel * ($ownBenefitRate/100))))}}</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_paidRiel * ($ownBenefitRate/100))))}}</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_oweRiel * ($ownBenefitRate/100))))}}</td>
                                                        </tr>
                                                        @endif
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            @include('modal.financial_report_print')

            @include('layout.footer')
        </div>
    </div>
</div>
@include('layout.common_script')

<script src="{{url(env("APP_URL").'storage/assets/libs/bootstrap-datepicker/js/bootstrap-datepicker.min.js')}}"></script>
<script>


    var patient_base_url = "{{url('patient')}}";
    var get_refs_base_url = "{{url('refs')}}";
    var base_url = "{{url('invoice')}}";
    let invoice_id = 0;

    $(".datepicker").datepicker({
        format:'dd-mm-yyyy',
        autoclose: true
    });

    $(".monthpicker").datepicker({
        format:'mm-yyyy',
        autoclose: true
    });

    $(".yearpicker").datepicker({
        format:'yyyy',
        autoclose: true
    });

</script>
{{--<script src="{{url(env("APP_URL").'storage/assets/js/admin/invoice.js')}}"></script>--}}

</body>

</html>

