<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    @include('layout.header')

    <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>

</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> {{__('vaccination.list_title')}}</h4>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <form method="get" action="{{url('vaccination/search')}}">
                                            <div class="row">
                                                <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
                                                    <div class="input-group">
                                                        <input type="text" class="form-control" value="{{isset($_GET['kword']) ? $_GET['kword'] : ''}}" name="kword" id="kword" placeholder="{{__('sample.search_placeholder')}}">
                                                        <div class="input-group-append">
                                                            <button class="btn btn-sm btn-inverse-secondary px-3" type="submit"><i class="fa fa-search"></i> {{__('general.btn_search')}} </button>
                                                            @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['add_vaccination']))
                                                            <a class="btn btn-info waves-effect px-3 ml-2" href="{{route('vaccination.create')}}"><i class="typcn typcn-plus"></i> {{__('general.btn_add_new')}} </a>
                                                            @endif
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </form> <hr class="my-3 d-none">
                                        <div class="col-sm-12 p-0 mb-1 mt-3">
                                            <div class="table-responsive">
                                                <table class="table table-bordered table-hover table-striped" id="department_dt">
                                                    <thead>
                                                    <tr class="bg-gradient-light">
                                                        <th class="py-2 text-center" width="50px">{{__('sample.table_no')}}</th>
                                                        <th class="py-2 text-center" width="100px">{{__('sample.table_action')}}</th>
                                                        <th class="py-2 text-center" width="50px">{{__('invoice.table_invoice_code')}}</th>
                                                        <th class="py-2" width="200px">{{__('sample.table_patient_name')}}</th>
                                                        <th class="py-2" width="200px">{{__('patient.form_age')}}</th>
                                                        <th class="py-2" width="200px">{{__('patient.table_sex')}}</th>
                                                        <th class="py-2" width="200px">{{__('patient.table_phon')}}</th>
                                                        <th class="py-2 text-center" width="120px">{{__('vaccination.date')}}</th>
                                                        <th class="py-2 text-center" width="300px">{{__('vaccination.next_visit')}}</th>
                                                        <th class="py-2 text-center" width="90px">{{__('invoice.table_net_cost')}}</th>
                                                        <th class="py-2 text-center" width="90px">{{__('invoice.cash_paid')}}</th>
                                                        <th class="py-2 text-center" width="90px">{{__('invoice.bank_paid')}}</th>
                                                        <th class="py-2 text-center" width="90px">{{__('invoice.table_owe')}}</th>
                                                        <!--<th class="py-2 text-center" width="90px">{{__('sample.table_status')}}</th>-->
                                                    </tr>
                                                    </thead>
                                                    <tbody>
                                                    @foreach($vaccinations as $k=>$vaccination)
                                                        <tr>
                                                            <td class="py-1 text-center">{{($k+1) + (($_GET['page'] ?? 1) * 20) - 20}}</td>
                                                            <td class="py-1 text-center">
                                                                <div class="btn-group" role="group" aria-label="Basic example" >
                                                                    @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['print_vaccination_invoice']))
                                                                        <a href="{{url('vaccination/edit/'.$vaccination->id.'?print')}}" class="btn btn-sm btn-info mr-2" title="{{__('Print Vaccination Invoice')}}">
                                                                            <i class="mdi mdi-printer"></i>
                                                                        </a>

{{--                                                                        <a href="javascript:void(0)" data-toggle="modal" data-target="#print_preview_modal" data-backdrop="static" class="btn btn-sm btn-primary mr-2" title="{{__('Print Vaccination History')}}">--}}
{{--                                                                            <i class="mdi mdi-printer-settings"></i>--}}
{{--                                                                        </a>--}}

                                                                    @endif
                                                                    @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['edit_vaccination']))
                                                                        <a href="{{route('vaccination.edit', $vaccination->id)}}" class="btn btn-sm btn-inverse-primary mr-2" title="{{__('test_sample.form_edit_tittle')}}"><i class="typcn typcn-edit"></i></a>
                                                                    @endif
                                                                    @if($vaccination->record_status_id==0)
                                                                            <button type="button" class="btn btn-sm btn-inverse-primary " title="Restore"  onclick="restore_data({{$vaccination->id}})"><i class="typcn typcn-plus"></i></button>
                                                                    @else
                                                                        @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['delete_vaccination']))
                                                                            <button type="button" class="btn btn-sm btn-inverse-danger " title="{{__('general.btn_delete')}}" onclick="delete_data({{$vaccination->id}})"><i class="mdi mdi-close-circle"></i></button>
                                                                        @endif
                                                                    @endif
                                                                </div>
                                                            </td>
                                                            <td class="py-1">{{$vaccination->invoice_code}}</td>
                                                            <td class="py-1">{{@$vaccination->patient->name_en}}</td>
                                                            <td class="py-1">{{@\App\Helpers\Helpers::getAge($vaccination->patient->dob, date('Y-m-d'))}}</td>
                                                            <td class="py-1">{{@$vaccination->patient->gender == 1 ? 'M' : 'F'}}</td>
                                                            <td class="py-1">{{@$vaccination->patient->phone_number}}</td>
                                                            <td class="py-1 text-center">{{date('d-m-Y',strtotime($vaccination->vaccination_date))}}</td>
                                                            <td class="py-1 text-center">{{date('d-m-Y',strtotime($vaccination->next_visit_date))}}</td>
                                                            <td class="py-1 text-right">{{$vaccination->gross_total}}</td>
                                                            <td class="py-1 text-right">{{$vaccination->deposit}}</td>
                                                            <td class="py-1 text-right">{{$vaccination->bank_deposit}}</td>
                                                            <td class="py-1 text-right">{{$vaccination->balance}}</td>
                                                            <!--<td class="py-1 text-center">-->
                                                            <!--    <i class="mdi {{$vaccination->record_status_id == 1 ? 'mdi-check-circle text-primary' : 'mdi-checkbox-blank-circle-outline'}}"></i>-->
                                                            <!--</td>-->

                                                        </tr>
                                                    @endforeach
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>

                                        <div class="float-right mt-3">
                                            {!! $vaccinations->links('pagination.custom') !!}
                                        </div>

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>



            @include('layout.footer')


        </div>
    </div>


    @include('modal.vaccination_print')

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


<script>


    var patient_base_url = "{{url('patient')}}";
    var vaccination_base_url = "{{url('vaccination')}}";

    let modal_add_title = "{{__('Add Vaccination')}}";
    let modal_edit_title = "{{__('Edit Vaccination')}}";


    $('#vaccination-detail-add').click(function () {
        addVaccinationRow();
    })

    function addVaccinationRow(medicine_id = 0, step=1, next_visit = ''){
        var id = 'vac-val-' + (Math.floor(Math.random() * (1000 - 100)) + 100) + (Math.floor(Math.random() * (99)) + 1)
        var medicine = '<select class="form-control select2 rounded-0" style="width: 100%" name="medicine_id" id="medicine-id'+id+'">' +
            '<option></option>' +
            '@foreach($medicineItems as $medicineItem)' +
            '<option value="{{$medicineItem->id}}">{{$medicineItem->medicine->name_en}}</option>' +
            '@endforeach' +
            '</select>';
        if($('#vaccination-detail tbody tr').length) {
            var $lastRow = $("[id$=vaccination-detail] tr:not('.ui-widget-header'):last"); //grab row before the last row
            var $newRow = $lastRow.clone().prop({id: id}); //clone it
            $newRow.find('td:last').addClass('py-0 text-center').html('<button type="button" class="btn btn-sm btn-inverse-danger " onclick="removeVaccinationRow(\'' + id + '\')"><i class="mdi mdi-close-circle"></i></button>');
            $newRow.find('td:nth(0)').html(medicine)
            $newRow.find('input[name="step"]').val(step); //clear out textbox values
            $newRow.find('input[name="next_visit"]').val(next_visit); //clear out textbox values
            $lastRow.after($newRow); //add in the new row at the end
            $newRow.find('.select2').select2({placeholder: choose_option, allowClear: true});
        }
        else{
            var tr = document.createElement('TR');
            tr.setAttribute('id', id);
            tr.insertCell(0).innerHTML = medicine
            tr.insertCell(1).innerHTML = '<input type="number" value="'+step+'" name="step" id="step" class="form-control">';
            tr.insertCell(2).innerHTML = '<input type="date" value="'+next_visit+'" class="form-control" name="next_visit" id="next-visit">';
            tr.insertCell(3).innerHTML = '<button type="button" class="btn btn-sm btn-inverse-danger " onclick="removeVaccinationRow(\'' + id + '\')"><i class="mdi mdi-close-circle"></i></button>';
            tr.cells[0].classList.add('p-2');
            tr.cells[1].classList.add('p-2');
            tr.cells[2].classList.add('p-2');
            tr.cells[3].classList.add('p-2','text-center');
            $('#vaccination-detail tbody').append(tr);
            $('.select2').select2({placeholder: choose_option, allowClear: true});
        }

        $('#medicine-id'+id).val(medicine_id).trigger('change');

    }

    function removeVaccinationRow(id){
        $('#vaccination-detail tr#'+id).remove();
    }

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


</body>

</html>

