@extends('admin.template.master')
@section('content')
<form action="{{ route('report.purchases') }}" method="POST">
    <div class="row">
        <div class="col-sm-6">
            @csrf
            <div class="row">
                <div class="form-group col-md-4">
                    <label>{{__('messages.start_date')}}</label>
                    <input type="text" class="form-control datepickr" name="sdate"
                        value="{{ $sdate }}">
                </div>
                <div class="form-group col-md-4 ">
                    <label>{{__('messages.end_date')}}</label>
                    <input type="text" class="form-control datepickr" name="edate"
                        value="{{ $edate }}">
                </div>
                <div class="col-md-4">
                    <button class="btn btn-primary mt-20" type="submit"> {{__('messages.submit')}}</button>
                </div>
            </div>
        </div>
    </div>
</form>
<div class="row">
    <div class="col-12">
        <hr><br>
    </div>
</div>
<div class="row">
    <div class="col-md-12">
        <table class="table MyTable">
            <thead>
                <tr>
                    <th class="text-center"> # </th>
                    <th class="text-center"> {{__('messages.date/time')}} </th>
                    <th class="text-center"> {{__('messages.invoice')}} </th>
                    <th> {{__('messages.total')}} </th>
                </tr>
            </thead>
            <tbody>
                @php
                    $total = 0;
                @endphp
                @foreach ($purchases as $pur)
                    <tr>
                        <td class="text-center">{{ $loop->iteration }}</td>
                        <td class="text-center">{{ $pur->dated }}</td>
                        <td class="text-center"><a href="#" id="{{ $pur->invoice }}" data-toggle="modal" data-target="#pinvoice-details">{{ $pur->invoice }}</a></td>
                        <td>{{ $pur->sub_total }}</td>
                    </tr>
                    @php
                        $total += $pur->sub_total;
                    @endphp
                @endforeach

            </tbody>
            <tfoot>
                <tr>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th>{{formatAmount($total)}}</th>
                </tr>
            </tfoot>
        </table>
    </div>
</div>

<div id="pinvoice-details" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="modal-close" data-dismiss="modal">
                    <i class="font-icon-close-2"></i>
                </button>
                <h4 class="modal-title">{{__('messages.invoice')}} : <span id="invoice_number"></span></h4>
            </div>
            <div class="modal-body" id="sinvoice-mbody">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">{{__('messages.close')}}</button>
            </div>
        </div>
    </div>
</div>
@endsection
@section('customjs')
<script src="{{ asset('custom_js/reports.js') }}"></script>
@endsection
