@extends('layouts.admin')

@if($new)
@section('title'){{__('adminforms.orders.plural_new')}} @endsection
@section('header'){{__('adminforms.orders.plural_new')}} @endsection
@else
@section('title'){{__('adminforms.orders.plural')}} @endsection
@section('header'){{__('adminforms.orders.plural')}} @endsection
@endif
@section('header_desc') @endsection
@section('breadcumbs') @endsection

@section('content')
    <!-- Main content -->
    <section class="content">

        <div class="row">
            <div class="col-xs-12">
                @if (session('result'))
                    <div class="alert alert-success alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <i class="icon fa fa-check"></i> <strong>Info: </strong> &nbsp;  &nbsp;
                        {{ session('result') }}
                    </div>
                @endif
                @if (session('error'))
                    <div class="alert alert-danger alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <i class="icon fa fa-exclamation-triangle"></i> <strong>Info: </strong> &nbsp;  &nbsp;
                        {{ session('error') }}
                    </div>
                @endif
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <div class="box">

                <!-- /.box-header -->
                    
                    <div class="box-body">
                        <table id="data-table" class="table table-hover">
                            <thead>
                            <tr>
                                <th>{{ucfirst(__('adminforms.orders.ord_id'))}}</th>
                                <th>{{ucfirst(__('adminforms.orders.created_at'))}}</th>
                                <th>{{ucfirst(__('adminforms.orders.items_num'))}}</th>
                                <th>{{ucfirst(__('adminforms.orders.ord_total'))}}</th>
                                <th>{{ucfirst(__('adminforms.orders.buyer'))}}</th>
                                <th>{{ucfirst(__('adminforms.orders.ord_adress'))}}</th>
                                <th>{{ucfirst(__('adminforms.orders.ord_phone'))}}</th>
                                <th>{{ucfirst(__('adminforms.orders.ord_email'))}}</th>
                                <th style="text-align: right;">{{ucfirst(__('adminforms.orders.inv_id'))}}</th>
                            </tr>
                            </thead>
                            <tbody>
                            @inject('invoice','\App\Invoice');
                            @foreach($orders as $order)
                                
                                <tr>
                                    <td>{{$order->ord_id}}</td>
                                    <td>{{sr_date($order->created_at)}}</td>
                                    <td>{{$order->items->count()}}</td>
                                    <td>{{number_format($order->ord_total, 2, ',', '.')}}</td>
                                    <td>{{$order->ord_lname}} {{$order->ord_fname}}</td>
                                    <td>{{$order->ord_adress}}</td>
                                    <td>{{$order->ord_phone}}</td>
                                    <td>{{$order->ord_email}}</td>
                                    <td style="text-align: right;">

                                        @if(!is_null($order->inv_id))
                                            @can('view', $invoice)
                                            <a class="btn btn-outline-success btn-xsm" href="{{ route('admin.invoice.show', ['invoice' => $order->inv_id]) }}">
                                                <i class="fa fa-eye"></i> {{__('adminforms.common.show_invoice_btn')}}
                                            </a>
                                            @else
                                                &nbsp;
                                            @endcan
                                        @else

                                            @can('create', $invoice)
                                                <a class="btn btn-outline-success btn-xsm" href="{{ route('admin.invoice.create', ['order' => $order->ord_id]) }}">
                                                    <i class="fa fa-calculator"></i> {{__('adminforms.common.make_invoice_btn')}}
                                                </a>
                                            @else
                                                &nbsp;
                                            @endcan

                                        @endif
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->

    </section>
@endsection


@push('css')
<link rel="stylesheet" href="{{asset('assets/components/datatables.net-bs/css/dataTables.bootstrap.min.css')}}">
@endpush

@push('primscripts')
<script src="{{asset('assets/components/datatables.net/js/jquery.dataTables.min.js')}}"></script>
<script src="{{asset('assets/components/datatables.net-bs/js/dataTables.bootstrap.js')}}"></script>
@endpush
@push('scripts')
<script>
    $(function () {
        $('#data-table').DataTable({
            'paging'      : true,
            'lengthChange': false,
            'searching'   : true,
            'ordering'    : true,
            'info'        : true,
            'autoWidth'   : false,
            "bStateSave"  : true,
            "language": {
                "sProcessing":   "{{__('adminforms.data_tables.sProcessing')}}",
                "sLengthMenu":   "{{__('adminforms.data_tables.sLengthMenu')}}",
                "sZeroRecords":  "{{__('adminforms.data_tables.sZeroRecords')}}",
                "sInfo":         "{{__('adminforms.data_tables.sInfo')}}",
                "sInfoEmpty":    "{{__('adminforms.data_tables.sInfoEmpty')}}",
                "sInfoFiltered": "{{__('adminforms.data_tables.sInfoFiltered')}}",
                "sInfoPostFix":  "{{__('adminforms.data_tables.sInfoPostFix')}}",
                "sSearch":       "{{__('adminforms.data_tables.sSearch')}}",
                "sUrl":          "{{__('adminforms.data_tables.sUrl')}}",
                "oPaginate": {
                    "sFirst":    "{{__('adminforms.data_tables.sFirst')}}",
                    "sPrevious": "{{__('adminforms.data_tables.sPrevious')}}",
                    "sNext":     "{{__('adminforms.data_tables.sNext')}}",
                    "sLast":     "{{__('adminforms.data_tables.sLast')}}",
                }
            }
        })
    })
</script>
@endpush