<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    @include('layout.header')
    <style>
        .center {
            height:100%;
            display:flex;
            align-items:center;
            justify-content:center;

        }
        .form-input {
            width:50%;
            padding:0px 0px 0px 0;
        }
        .form-input img {
            width:100%;
            display:none;
            margin-bottom:10px;
        }
        .form-input input {
            display:none;
        }

        .form-input label {
            height:25px;
            background:#cdcdcd26;
            color:#c9c9c9;
            cursor:pointer;
            width: 75px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
<div class="row" id="x" style="display: none;">
    <div class="col-12">
      <span class="d-flex align-items-center purchase-popup">
        <i class="typcn typcn-delete-outline" id="bannerClose"></i>
      </span>
    </div>
</div>
<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.medicine')}}</h4>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <form method="get" action="{{url('/inventory/medicine/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="{{__('Medical item name')}}">
                                                        <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_medicine']))
                                                                <button class="btn btn-info waves-effect px-3 ml-2" type="button" data-action="new" data-toggle="modal" data-target="#modal-medicine-item" data-backdrop="static"><i class="typcn typcn-plus"></i> {{__('general.btn_add_new')}}</button>
                                                            @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" width="50px">{{__('physician.table_no')}}</th>
                                                        <th class="py-2 text-center" width="100px">{{__('physician.table_action')}}</th>
                                                        <th class="py-2">{{__('Code')}}</th>
                                                        <th class="py-2">{{__('Medical Item')}}</th>
                                                        <th class="py-2">{{__('Medical Item Group')}}</th>
                                                        <th class="py-2">{{__('Unit Price')}}</th>
                                                        <th class="py-2">{{__('Sale Price')}}</th>
{{--                                                        <th class="py-2" width="100px">{{__('Is Vaccination')}}</th>--}}
                                                        <th class="py-2 text-center" width="100px">{{__('physician.table_status')}}</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody>
                                                    @foreach($medicineItems as $k=>$medicineItem)
                                                        <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, ['update_medicine']))
                                                                        <button type="button" class="btn btn-sm btn-inverse-primary mr-2" title="{{__('general.btn_edit')}}" data-action="edit" data-uid="{{$medicineItem->id}}" data-toggle="modal" data-target="#modal-medicine-item" data-backdrop="static">
                                                                            <i class="typcn typcn-edit"></i>
                                                                        </button>
                                                                    @endif
                                                                    @if($medicineItem->record_status_id==0)
                                                                        <button type="button" class="btn btn-sm btn-inverse-primary " title="Restore"  onclick="restore_data({{$medicineItem->id}})"><i class="typcn typcn-plus"></i></button>
                                                                    @else
                                                                        @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['delete_medicine']))
                                                                            <button type="button" class="btn btn-sm btn-inverse-danger " title="{{__('general.btn_delete')}}" onclick="delete_data({{$medicineItem->id}})"><i class="mdi mdi-close-circle"></i></button>
                                                                        @endif
                                                                    @endif
                                                                </div>
                                                            </td>
                                                            <td class="py-1">{{$medicineItem->code}}</td>
                                                            <td class="py-1">{{$medicineItem->medicine->name}}</td>
                                                            <td class="py-1">{{@$medicineItem->medicineGroup->name_en}}</td>
                                                            <td class="py-1">{{$medicineItem->unit_price}}</td>
                                                            <td class="py-1">{{$medicineItem->sale_price}}</td>
{{--                                                            <td class="py-1 text-center"><i class="mdi {{$medicineItem->is_vaccination == 1 ? 'mdi-check-circle text-primary' : 'mdi-checkbox-blank-circle-outline_'}}"></i></td>--}}
                                                            <td class="py-1 text-center">
                                                                <i class="mdi {{$medicineItem->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">
                                            {!! $medicineItems->links('pagination.custom') !!}
                                        </div>

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

                </div>
            </div>

            <!-- Modal Laboratory -->
            <div class="modal fade modal-primary" id="modal-medicine-item">
                <div class="modal-dialog modal-xl">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h6 class="modal-title new">{{__('New Supplier')}}</h6>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" class="mdi mdi-close"></span></button>
                        </div>
                        <div class="modal-body">
                            <form method="POST" action="#" id="form-physician" enctype="multipart/form-data" onkeydown="return event.key != 'Enter';">
                                @csrf
                                <input type="hidden" class="form-control" name="uid" id="data-id" value="0" />
                                <div class="form-vertical">

                                    <div class="row">
                                        <div class="col-sm-12 col-md-6">
                                            <div class="form-group">
                                                <label for="lab-name-en">{{__('Medical Item')}} <span class="text-danger">*</span></label>
                                                <div class="input-group" id="testItem">
                                                    <div class="form-group" style="flex: 1 !important;">
                                                        <select class="form-control rounded-0 select2" name="medicine_id" id="medicine-id" style=" width: 100% !important;">
                                                            <option></option>
                                                            @foreach($medicines as $medicine)
                                                                <option value="{{$medicine->id}}">{{$medicine->name}}</option>
                                                            @endforeach
                                                        </select>
                                                    </div>
                                                    <div class="input-group-append">
                                                        @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['update_medicine']))
                                                        <button class="btn btn-sm btn-inverse-warning px-3" type="button" onclick="editMedicine()"><i class="mdi mdi-table-edit"></i>&nbsp;</button>
                                                        @endif
                                                        @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['add_medicine']))
                                                        <button class="btn btn-sm rounded-0 btn-inverse-info px-3" type="button" onclick="addNewMedicine('medicine-id')"><i class="typcn typcn-plus"></i>&nbsp;</button>
                                                        @endif
                                                    </div>
                                                </div>
                                                <br>
                                            </div>
                                        </div>

                                        <div class="col-sm-12 col-md-6">
                                            <div class="form-group mb-1">
                                                <label for="lab-name-en">{{__('test_sample.code')}}</label>
                                                <input type="text" class="form-control rounded-0" name="medicine_code" id="medicine-code" placeholder="{{__('test_sample.code')}}">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <div class="col-sm-12 col-md-6">
                                            <div class="form-group mb-1">
                                                <label for="lab-name-en">{{__('Medical Item Group')}} <span class="text-danger">*</span></label>
                                                <select class="form-control rounded-0 select2" name="medicine_group_id" id="medicine-group-id" style=" width: 100% !important;">
                                                    <option></option>
                                                    @foreach($medicineGroups as $medicineGroup)
                                                        <option value="{{$medicineGroup->id}}">{{$medicineGroup->name_en}}</option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-sm-12 col-md-6">
                                            <div class="form-group mb-1">
                                                <label for="lab-name-en">{{__('Description')}}</label>
                                                <input type="text" class="form-control rounded-0" name="dosage" id="dosage" placeholder="{{__('Description or dosage in case item is medicine')}}">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="row">

                                        <div class="col-sm-12 col-md-6">
                                            <div class="form-group mb-1">
                                                <label for="lab-name-en">{{__('Unit Price')}}</label>
                                                <input type="number" class="form-control rounded-0" name="unit_price" id="unit-price" placeholder="{{__('Unit Price')}}">
                                            </div>
                                        </div>

                                        <div class="col-sm-12 col-md-6">
                                            <div class="form-group mb-1">
                                                <label for="lab-name-en">{{__('Sale Price')}}</label>
                                                <input type="number" class="form-control rounded-0" name="sale_price" id="sale-price" placeholder="{{__('Sale Price')}}">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <div class="col-sm-12">
                                            <div class="form-check form-check-flat form-check-primary mb-1 mt-1">
                                                <div class="form-check form-check-primary">
                                                    <label class="form-check-label">
                                                        <input type="checkbox" data-id="1" class="checkbox" value="1" name="is_vaccination" id="is-vaccination"> {{__('Is Vaccination')}}
                                                    </label>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-info" id="btnSave"><i class="fa fa-floppy-o"></i>&nbsp;&nbsp;<span class="save">{{__('lang.save')}}</span><span class="update" style="display: none">{{__('lang.update')}}</span></button>
                            <button type="button" class="btn btn-light" data-dismiss='modal'>{{__('lang.cancel')}}</button>
                        </div>
                    </div>
                </div>
            </div>

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

<script>

    var save_url = "{{url('inventory/medicine/save')}}";
    var update_url = "{{url('inventory/medicine/update')}}";
    var delete_url = "{{url('inventory/medicine/delete')}}";
    var restore_url = "{{url('inventory/medicine/restore')}}";

    var get_url = "{{url('inventory/medicine/get')}}";

    var medicine_base_url = "{{url('inventory/ref-medicine')}}";

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

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

<script>
    function editMedicine(){
        let selectedOption = $('#medicine-id option:selected');
        let selectedText = selectedOption.text();
        let selectedVal = selectedOption.val();
        if(selectedVal>0){
            editMedicineName(selectedVal, selectedText, 'medicine-id')
        }
    }
</script>

</body>

</html>

