@extends('template.app')

@section('meta') @endsection
@section('title') Yet To Delivery Report @endsection

@section('styles')
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
    <link href="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/css/select2.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.datatables.net/1.13.7/css/jquery.dataTables.min.css">
    <style>
        .table-responsive {
            overflow-x: auto;
            max-width: 100%;
        }
        
        .dataTables_scrollHeadInner,
        .dataTables_scrollBody table {
            width: 100% !important;
        }
        
        .dataTables_scrollHead {
            overflow: hidden;
        }
        .dataTables_scrollBody {
            max-height: 400px; 
            overflow-y: auto;
        }
        
        
        #data-table {
            width: 100% !important;
            border-collapse: collapse;
        }
        
        #data-table thead th {
            white-space: nowrap;
        }
       
        #data-table_wrapper {
            width: 100%;
            overflow-x: auto;
        }
        
        td, th {
            border: 1px solid #dddddd;
            text-align: left;
            padding: 8px;
        }
        
        tr:nth-child(even) {
            background-color: #313762;
        }
        .daterangepicker {
            background-color: #fff !important;
            color: #000 !important;
            border: 1px solid #ccc;
            z-index: 9999;
        }
        
        .daterangepicker .calendar-table,
        .daterangepicker td,
        .daterangepicker th {
            background-color: #fff !important;
            color: #000 !important;
        }
        
        .daterangepicker td.active,
        .daterangepicker td.active:hover {
            background-color: #007bff !important;
            color: #fff !important;
        }
        
        .daterangepicker .drp-buttons .btn {
            background-color: #007bff;
            color: #fff;
        }
        
        .daterangepicker .drp-buttons .btn:hover {
            background-color: #0056b3;
        }
        
        .width_150 {
            width: 150px;
        }
        .width_200 {
            width: 200px;
        }
        .width_250 {
            width: 250px;
        }
        .width_300 {
            width: 300px;
        }
        
        tr:nth-child(even) {
         background-color: rgba(0,0,0,0.24) !important;
    }
            
    </style>
@endsection

@section('content')
<div class="page-breadcrumb">
    <div class="row">
        <div class="col-7 align-self-center">
            <h4 class="page-title text-truncate text-dark font-weight-medium mb-1">Yet To Delivery Report</h4>
            <div class="d-flex align-items-center">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb m-0 p-0">
                        <li class="breadcrumb-item"><a href="{{ route('dashboard') }}" class="text-muted">Dashboard</a></li>
                        <li class="breadcrumb-item"><a href="{{ route('allReport') }}" class="text-muted">Mis Report</a></li>
                        <li class="breadcrumb-item text-muted active" aria-current="page">Yet To Delivery Report</li>
                    </ol>
                </nav>
            </div>
        </div>
        <div class="col-5 align-self-center">
            <div class="customize-input float-right">
                <button class="btn waves-effect waves-light btn-rounded btn-outline-primary pull-right" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
                    Export
                </button>
            </div>
        </div>
        <div class="col-sm-8"></div>
        <div class="col-sm-4">
            <div class="col-md-12 align-self-center collapse" id="collapseExample">
                <div class="customize-input float-right">
                    <form action="{{ route('YettodeliveryReportExport') }}" method="get">
                        @csrf
                        <div class="row">
                            <div class="form-group col-md-6">
                                <select name="slug" class="form-control" required>
                                    <option value="">Select Status</option>
                                    <option value="all">All</option>
                                </select>
                            </div>
                            <div class="form-group col-md-6">
                                <button class="btn btn-primary" type="submit">Submit</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="container-fluid">
  <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body table-responsive" style="text-align: center;">
                    <table class="table table-bordered data-table tables" id="data-table"> 
                        <thead>
                            <tr>
                                <th>No</th>
                                <th>Customer Name</th>
                                <th>Branch</th>
                                <th>KEC</th>
                                <th>Model</th>
                                <th>Varient</th>
                                <th>VIN Number</th>
                                <th>Engine Number</th>
                                <th>On Road Price</th>
                                <th>Less: Discount</th>
                                <th>Received Amount</th>
                                <th>Due Amount</th>
                                <th>Invoice No</th>
                                <th>Invoice Date</th>
                                <th>Invoice Status</th>
                                <th>Insurance Status</th>
                                <th>RTO Status</th>
                                <th>Municipal Tax Status</th>
                            </tr>
                            <tr class="filterrow">
                                <th></th>
                                <!-- Customer Name -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_300">
                                        <div class="form-group is-empty">
                                            <input type="text" name="customer_name" value="{{ request()->get('customer_name', '') }}" class="form-control text-capitalize custom_color" id="customer_name" autocomplete="off" autofocus tabindex="1">
                                        </div>
                                    </div>
                                </th>
                                
                                <!-- Branch -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_300">
                                        <div class="form-group is-empty">
                                            <input type="text" name="branch" value="{{ request()->get('branch', '') }}" class="form-control text-capitalize custom_color" id="branch" autocomplete="off" autofocus tabindex="2">
                                        </div>
                                    </div>
                                </th>
                                
                                <!-- KEC -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_300">
                                        <div class="form-group is-empty">
                                            <input type="text" name="sales_person_name" value="{{ request()->get('sales_person_name', '') }}" class="form-control text-capitalize custom_color" id="sales_person_name" autocomplete="off" autofocus tabindex="3">
                                        </div>
                                    </div>
                                </th>
                                
                                <!-- Model -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_300">
                                        <div class="form-group is-empty">
                                            <input type="text" name="model" value="{{ request()->get('model', '') }}" class="form-control text-capitalize custom_color" id="model" autocomplete="off" autofocus tabindex="4">
                                        </div>
                                    </div>
                                </th>
                                
                                <!-- Varient -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_300">
                                        <div class="form-group is-empty">
                                            <input type="text" name="car_varient_name" value="{{ request()->get('car_varient_name', '') }}" class="form-control text-capitalize custom_color" id="car_varient_name" autocomplete="off" autofocus tabindex="5">
                                        </div>
                                    </div>
                                </th>
                                
                                <!-- VIN Number -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_200">
                                        <div class="form-group is-empty">
                                            <input type="text" name="vin_number" value="{{ request()->get('vin_number', '') }}" class="form-control text-capitalize custom_color" id="vin_number" autocomplete="off" autofocus tabindex="6">
                                        </div>
                                    </div>
                                </th>
                                
                                <!-- Engine Number -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_200">
                                        <div class="form-group is-empty">
                                            <input type="text" name="engine_number" value="{{ request()->get('engine_number', '') }}" class="form-control text-capitalize custom_color" id="engine_number" autocomplete="off" autofocus tabindex="7">
                                        </div>
                                    </div>
                                </th>
                                
                                <!-- On Road Price -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_150">
                                        <div class="form-group is-empty">
                                            <input type="text" name="on_road_price" value="{{ request()->get('on_road_price', '') }}" class="form-control text-capitalize custom_color" id="on_road_price" autocomplete="off" autofocus tabindex="8">
                                        </div>
                                    </div>
                                </th>
                                
                                <!-- Less: Discount Price -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_150">
                                        <div class="form-group is-empty">
                                            <input type="text" name="total_discount" value="{{ request()->get('total_discount', '') }}" class="form-control text-capitalize custom_color" id="total_discount" autocomplete="off" autofocus tabindex="9">
                                        </div>
                                    </div>
                                </th>
                                
                                <!-- Received Amount -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_150">
                                        <div class="form-group is-empty">
                                            <input type="text" name="total_received_amount" value="{{ request()->get('total_received_amount', '') }}" class="form-control text-capitalize custom_color" id="total_received_amount" autocomplete="off" autofocus tabindex="10">
                                        </div>
                                    </div>
                                </th>
                                <!-- Due Amount -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_150">
                                        <div class="form-group is-empty">
                                            <input type="text" name="due_amount" value="{{ request()->get('due_amount', '') }}" class="form-control text-capitalize custom_color" id="due_amount" autocomplete="off" autofocus tabindex="11">
                                        </div>
                                    </div>
                                </th>
                                
                                <!-- Invoice No -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_150">
                                        <div class="form-group is-empty">
                                            <input type="text" name="invoice_no" value="{{ request()->get('invoice_no', '') }}" class="form-control text-capitalize custom_color" id="invoice_no" autocomplete="off" autofocus tabindex="12">
                                        </div>
                                    </div>
                                </th>
                                
                                <!-- Invoice Date -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_150">
                                        <div class="form-group is-empty">
                                            <input type="text" name="invoice_date" value="{{ request()->get('invoice_date', '') }}" class="form-control text-capitalize custom_color" id="invoice_date" autocomplete="off" autofocus tabindex="13">
                                        </div>
                                    </div>
                                </th>
                                
                                <!-- Invoice Status -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_150">
                                        <div class="form-group is-empty">
                                            <input type="text" name="invoice_status" value="{{ request()->get('invoice_status', '') }}" class="form-control text-capitalize custom_color" id="invoice_status" autocomplete="off" autofocus tabindex="14">
                                        </div>
                                    </div>
                                </th>
                                
                                <!-- Insurance Status -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_150">
                                        <div class="form-group is-empty">
                                            <input type="text" name="insurance_status" value="{{ request()->get('insurance_status', '') }}" class="form-control text-capitalize custom_color" id="insurance_status" autocomplete="off" autofocus tabindex="15">
                                        </div>
                                    </div>
                                </th>
                                
                                <!-- RTO Status -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_150">
                                        <div class="form-group is-empty">
                                            <input type="text" name="rto_status" value="{{ request()->get('rto_status', '') }}" class="form-control text-capitalize custom_color" id="rto_status" autocomplete="off" autofocus tabindex="16">
                                        </div>
                                    </div>
                                </th>
                                
                                <!-- Municipal Tax Status -->
                                <th>
                                    <div class="search-box-container datatable-form-filter width_150">
                                        <div class="form-group is-empty">
                                            <input type="text" name="municipal_status" value="{{ request()->get('municipal_status', '') }}" class="form-control text-capitalize custom_color" id="municipal_status" autocomplete="off" autofocus tabindex="16">
                                        </div>
                                    </div>
                                </th>

                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
@endsection

@section('scripts')
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.datatables.net/1.13.7/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.13.7/js/dataTables.bootstrap5.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
    <script src="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/select2.min.js"></script>
    <script src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
    <script src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
    
    
    <script type="text/javascript">
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
    </script>
    
    <script type="text/javascript">
        $(document).ready(function() {
            $('#booking_date').daterangepicker({
                autoUpdateInput: false,
                locale: {
                    format: 'DD-MM-YYYY',
                    cancelLabel: 'Clear'
                }
            });
        
            $('#booking_date').on('apply.daterangepicker', function(ev, picker) {
                $(this).val(picker.startDate.format('DD-MM-YYYY') + ' to ' + picker.endDate.format('DD-MM-YYYY'));
                $('#data-table').DataTable().draw();
            });
        
            $('#booking_date').on('cancel.daterangepicker', function(ev, picker) {
                $(this).val('');
                $('#data-table').DataTable().draw();
            });
    
            $('.js-example-basic-single').select2();
    
            var tableColumns = [
                { data: 'id', name: 'id' },
                { data: 'customer_name', name: 'customer_name' },
                { data: 'branch', name: 'branches' },
                { data: 'sales_person_name', name: 'sales_person_name' },
                { data: 'model', name: 'model' },
                { data: 'car_varient_name', name: 'car_varient_name' },
                { data: 'vin_number', name: 'vin_number' },
                { data: 'engine_number', name: 'engine_number' },
                { data: 'on_road_price', name: 'on_road_price' },
                { data: 'total_discount', name: 'total_discount' },
                { data: 'total_received_amount', name: 'total_received_amount', searchable: false },
                { data: 'due_amount', name: 'due_amount', searchable: false },
                { data: 'invoice_no', name: 'invoice_no' },
                { data: 'invoice_date', name: 'invoice_date' },
                { data: 'invoice_status', name: 'invoice_status' },
                { data: 'insurance_status', name: 'insurance_status' },
                { data: 'rto_status', name: 'rto_status' },
                { data: 'municipal_status', name: 'municipal_status' },
            ];
    
            (function(window, $) {
                window.LaravelDataTables = window.LaravelDataTables || {};
                window.LaravelDataTables["dataTableBuilder"] = $("#data-table").DataTable({
                    processing: true,
                    serverSide: true,
                    language: {
                        "info": "_START_ - _END_ of _TOTAL_",
                        "lengthMenu": "_MENU_ ",
                        "infoFiltered": ""
                    },
                    scrollX: true,
                    scrollY: '750px',
                    scrollCollapse: true,
                    paging: true,
                    fixedHeader: false,
                    searching: false,
                    autoWidth: false,
                    bSortCellsTop : true,
                    ajax: {
                        url: '{!! route("yettodeliveryReportfetch") !!}',
                        method: "POST",
                        data: function (d) {
                            d.customer_name = $('#customer_name').val();
                            d.branch = $('#branch').val();
                            d.sales_person_name = $('#sales_person_name').val();
                            d.model = $('#model').val();
                            d.car_varient_name = $('#car_varient_name').val();
                            d.vin_number = $('#vin_number').val();
                            d.engine_number = $('#engine_number').val();
                            d.on_road_price = $('#on_road_price').val();
                            d.total_discount = $('#total_discount').val();
                            d.total_received_amount = $('#total_received_amount').val();
                            d.remaining_amount = $('#remaining_amount').val();
                            d.due_amount = $('#due_amount').val();
                            d.invoice_no = $('#invoice_no').val();
                            d.invoice_date = $('#invoice_date').val();
                            d.invoice_status = $('#invoice_status').val();
                            d.insurance_status = $('#insurance_status').val();
                            d.rto_status = $('#rto_status').val();
                            d.municipal_status = $('#municipal_status').val();
                        },
                        error : function(d) {}
                    },
                    columns: tableColumns,
                    lengthMenu: [
                        [25, 50,100, -1 ],['25', '50','100', 'Show all' ]
                    ],
                    order: [ [0,'DESC'] ],
                    responsive: true,
                    colReorder:{
                        enable: false,
                    },
                    dom: '<"top"f>rt<"bottom"ipl><"clear">',
                    fnInitComplete: function(settings, json) {
                        jQuery('table.table input:checkbox').map(function() {
                            if(jQuery(this).prop("checked") != true){
                                var column = table.column( jQuery(this).attr('data-column') );
                                column.visible(false);
                            }
                        });
                    },
                    pageLength: 25,
                });
            })(window, jQuery);
    
            $("#min").flatpickr({ onSelect: function () { window.LaravelDataTables["dataTableBuilder"].draw(); }, changeMonth: true, changeYear: true });
    
            $(document).on("change", "#min", function () {
                window.LaravelDataTables["dataTableBuilder"].draw();
            });
    
    
    
        jQuery('.datatable-form-filter input').on('keyup', function (e) {
            if(jQuery(this).val().length >= 3 || e.keyCode == 13 || !jQuery(this).val()) {
                window.LaravelDataTables["dataTableBuilder"].draw();
                e.preventDefault();
            }
        });
    
        jQuery('.datatable-form-filter select').on('change', function (e) {
            window.LaravelDataTables["dataTableBuilder"].draw();
            e.preventDefault();
        });
    
        jQuery('input:checkbox[name="name_sort_asc"],input:checkbox[name="name_sort_desc"]').on('click', function (e) {
            window.LaravelDataTables["dataTableBuilder"].draw();
            e.preventDefault();
        });
    }); 
    </script>
@endsection