'<!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>
</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> {{__('Inventory Report')}}</h4>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="col-sm-12 bg-gradient-light border-1 border-solid border-gray p-4 inv-search">
                                            <form method="get" action="{{url('inventory/report/view')}}">
                                                <div class="row">
                                                    <div class="col-sm-12 col-md-3 col-lg-3">
                                                        <div class="form-group mb-1">
                                                            <label for="lab-name-en">{{__('Report Type')}}</label>
                                                            <select class="form-control" id="report_type_filter" name="report_type">
                                                                <option></option>
                                                                <option {{(isset($_GET['report_type']) && $_GET['report_type']==1 ? 'selected' : '')}} value="1">Inventory On hand</option>
                                                                <option {{(isset($_GET['report_type']) && $_GET['report_type']==2 ? 'selected' : '')}} value="2">Expire Report</option>
{{--                                                                <option {{(isset($_GET['report_type']) && $_GET['report_type']==3 ? 'selected' : '')}} value="2">Need Restock</option>--}}
                                                            </select>
                                                        </div>
                                                    </div>

                                                    <div id="report_date_range" class="col-sm-12 col-md-5 col-lg-4 {{(isset($_GET['report_type']) && $_GET['report_type']!=1 ? 'd-block' : 'd-none')}}">
                                                        <div class="form-group mb-1">
                                                            <label for="start-invoice-date">{{__('Report Date')}}</label>
                                                            <div class="input-group">
                                                                <input name="start_date" value="{{isset($_GET['start_date']) && !empty($_GET['start_date']) ? date('Y-m-d',strtotime($_GET['start_date'])) : date('Y-m-01')}}" onfocus="(this.type='date')" onblur="(this.type='text')" placeholder="{{__('general.type_date_placeholder')}}" class="form-control">
                                                                <input name="end_date" value="{{isset($_GET['end_date']) && !empty($_GET['end_date']) ?  date('Y-m-d',strtotime($_GET['end_date'])) : date('Y-m-d')}}" onfocus="(this.type='date')" onblur="(this.type='text')" placeholder="{{__('general.type_date_placeholder')}}" class="form-control">
                                                            </div>
                                                        </div>
                                                    </div>

                                                    <div class="col-sm-12 col-md-7 col-lg-5">
                                                        <div class="form-group mb-1">
                                                            <label for="lab-name-en">&nbsp;</label>
                                                            <div class="input-group">
                                                                <div class="input-group-append">
                                                                    <button class="btn btn-sm btn-info ml-4 px-3" title="Search" type="submit"><i class="fa fa-search"></i>{{__('report.btn_view')}}</button>
                                                                    <a href="{{url('report/doctor-report')}}" class="btn btn-inverse-warning px-3 ml-4" title="Clear Search Filter"><i class="mdi mdi-filter-remove-outline"></i>{{__('general.btn_clear')}}</a>
                                                                    <button type="button" class="btn btn-white rounded-0 dropdown-toggle ml-4" 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>
                                        @if(!empty($report_data['report_data']) && $report_data['report_id']==1)
                                        <p>{{$report_data['report_name']}}</p>
                                        <div class="col-sm-12 p-0 mb-1 mt-1">
                                            <div class="table-responsive--">
                                                <table class="table table-bordered" id="department_dt">
                                                    <thead>
                                                        <tr class="bg-light">
                                                            <th class="p-1">Item Group</th>
                                                            <th class="p-1">Item Name</th>
                                                            <th class="p-1">On hand</th>
                                                            <th class="p-1">Last Stock In</th>
                                                            <th class="p-1">Last Stock Out</th>
                                                        </tr>
                                                    </thead>

                                                    <tbody>
                                                        @foreach($report_data['report_data'] as $v)
                                                            <tr>
                                                                <td class="p-1">{{$v->item_group}}</td>
                                                                <td class="p-1">{{$v->item_name}}</td>
                                                                <td class="p-1 text-right">{{floatval($v->available_quantity)}}</td>
                                                                <td class="p-1 text-center">{{!empty($v->stock_in_date) ? date('d-m-Y',strtotime($v->stock_in_date)) : ''}}</td>
                                                                <td class="p-1 text-center">{{!empty($v->stock_out_date) ? date('d-m-Y',strtotime($v->stock_out_date)) : ''}}</td>
                                                            </tr>
                                                        @endforeach
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                        @endif

                                        @if(!empty($report_data['report_data']) && $report_data['report_id']==2)
                                            <p>{{$report_data['report_name']}}</p>
                                            <div class="col-sm-12 p-0 mb-1 mt-1">
                                                <div class="table-responsive--">
                                                    <table class="table table-bordered" id="department_dt">
                                                        <thead>
                                                        <tr class="bg-light">
                                                            <th class="p-1">Item Group</th>
                                                            <th class="p-1">Item Name</th>
                                                            <th class="p-1">Stock In</th>
                                                            <th class="p-1">Stock In Date</th>
                                                            <th class="p-1">Expire Date</th>
                                                            <th class="p-1"># Month</th>
                                                        </tr>
                                                        </thead>

                                                        <tbody>
                                                        @foreach($report_data['report_data'] as $v)
                                                            <tr>
                                                                <td class="p-1">{{$v->item_group}}</td>
                                                                <td class="p-1">{{$v->item_name}}</td>
                                                                <td class="p-1 text-right">{{$v->stock_in}}</td>
                                                                <td class="p-1 text-center">{{!empty($v->stock_in_date) ? date('d-m-Y',strtotime($v->stock_in_date)) : ''}}</td>
                                                                <td class="p-1 text-center">{{!empty($v->expiry_date) ? date('d-m-Y',strtotime($v->expiry_date)) : ''}}</td>
                                                                <td class="p-1 text-right">{{$v->months}}</td>
                                                            </tr>
                                                        @endforeach
                                                        </tbody>
                                                    </table>
                                                </div>
                                            </div>
                                        @endif

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

            @if(isset($_GET['report_type']))
            @include('modal.inventory_onhand_print')
            @endif

            @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
    });

    $('#report_type_filter').change(function(){
        let reportTypeId = $(this).val();
        if(reportTypeId==1){
            //$('#report_date_range').css('display','none');
            $('#report_date_range').removeClass("d-block");
            $('#report_date_range').addClass('d-none');
        }
        else{
            $('#report_date_range').removeClass("d-none");
            $('#report_date_range').addClass('d-block');
        }
    })

</script>

</body>

</html>

