@extends('template.app')



@section('meta') @endsection

@section('title') Booking Retail 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 {

        font-family: Arial, sans-serif;

        border-collapse: collapse;

        width: 100%;

    }



    td, th {

        border: 1px solid #dddddd;

        text-align: left;

        padding: 8px;

    }



    /*tr:nth-child(even) {*/

    /*    background-color: #313762;*/

    /*}*/



    div.dataTables_wrapper div.dataTables_filter label {

        font-weight: normal;

        white-space: nowrap;

        margin-left: auto;

        margin-right: auto;

    }



    .table-responsive {

        overflow-x: auto;

        max-width: 100%;

    }

    /* Commented by Kerav */

    /*.card-body {

        overflow-x: auto;

        max-width: 100%;

        margin-right: 40px;

        margin-left: 40px;

    }



    .card-header {

        margin-right: 40px;

        margin-left: 40px;

    }


    .card.mt-4, .card {

        margin: 20px 40px;

    }*/

    /* Commented by Kerav */



    .dataTables_wrapper {

        width: 100%;

        max-width: 100%;

        overflow-x: auto;

    }

</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">Booking Retail 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">Booking Retail 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('CancelReasonReportExport') }}" 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" id="datatable" style="text-align: center;">

                    <table class="table table-bordered data-table tables" id="data-table" cellspacing="0" width="100%">

                        <thead>

                            <tr>

                                <!--<th>No</th>-->

                                <th>Car Name</th>

                                <th>Variant</th>

                                <th>Branch</th>

                                <th>Ex Showroom Price</th>

                                <th>Purchase Price</th>

                                <th>Kin Margin</th>

                                <th>Fuel Type</th>

                                <th>VIN Number</th>

                                <th>Inventory Type</th>

                                <th>Status</th>

                                <th>Aging Days</th>

                                <th>Booking Date</th>

                                <th>Customer Name</th>

                                <th>Gst No</th>

                                <th>Team Leader</th>

                                <th>KEC Name</th>

                                <th>Exterior</th>

                                <th>On Road Price (A)</th>

                                <th>Booking Amount (B(+))</th>

                                <th>DP Amount Received (C(+))</th>

                                <th>Finance Amount</th>

                                <th>Net Disbursement Amount (D(+))</th>

                                <th>Exchange Amount (E(+))</th>

                                <th>Total Received Amount (B+C+D+E = F)</th>

                                <th>Discount (G(-))</th>

                                <th>Net Amount Received (F-G=H)</th>

                                <th>Due Amount (A-H=I)</th>

                                <th>OBF Status</th>

                            </tr>

                            <tr class="filterrow">

                                <th><input type="text" name="car_name" value="{{ request()->get('car_name', '') }}" class="form-control" id="car_name"></th>

                                <th><input type="text" name="variant" value="{{ request()->get('variant', '') }}" class="form-control" id="variant"></th>

                                <th><input type="text" name="branch_name" value="{{ request()->get('branch_name', '') }}" class="form-control" id="branch_name"></th>

                                <th><input type="text" name="ex_showroom_price" value="{{ request()->get('ex_showroom_price', '') }}" class="form-control" id="ex_showroom_price"></th>

                                <th><input type="text" name="purchase_price" value="{{ request()->get('purchase_price', '') }}" class="form-control" id="purchase_price"></th>

                                <th><input type="text" name="kin_margin" value="{{ request()->get('kin_margin', '') }}" class="form-control" id="kin_margin"></th>

                                <th><input type="text" name="fuel_type" value="{{ request()->get('fuel_type', '') }}" class="form-control" id="fuel_type"></th>

                                <th><input type="text" name="vin_number" value="{{ request()->get('vin_number', '') }}" class="form-control" id="vin_number"></th>

                                <th><input type="text" name="inventory_type" value="{{ request()->get('inventory_type', '') }}" class="form-control" id="inventory_type"></th>

                                <th><input type="text" name="inventory_status" value="{{ request()->get('inventory_status', '') }}" class="form-control" id="inventory_status"></th>

                                <th><input type="text" name="aging_days" value="{{ request()->get('aging_days', '') }}" class="form-control" id="aging_days"></th>

                                <th><input type="text" name="booking_date" value="{{ request()->get('booking_date', '') }}" class="form-control" id="booking_date"></th>

                                <th><input type="text" name="customer_name" value="{{ request()->get('customer_name', '') }}" class="form-control" id="customer_name"></th>

                                <th><input type="text" name="gst" value="{{ request()->get('gst', '') }}" class="form-control" id="gst"></th>

                                <th><input type="text" name="team_name" value="{{ request()->get('team_name', '') }}" class="form-control" id="team_name"></th>

                                <th><input type="text" name="sales_person_name" value="{{ request()->get('sales_person_name', '') }}" class="form-control" id="sales_person_name"></th>

                                <th><input type="text" name="exterior_color" value="{{ request()->get('exterior_color', '') }}" class="form-control" id="exterior_color"></th>

                                <th><input type="text" name="on_road_price" value="{{ request()->get('on_road_price', '') }}" class="form-control" id="on_road_price"></th>

                                <th><input type="text" name="booking_amount" value="{{ request()->get('booking_amount', '') }}" class="form-control" id="booking_amount"></th>

                                <th><input type="text" name="dp_amount" value="{{ request()->get('dp_amount', '') }}" class="form-control" id="dp_amount"></th>

                                <th><input type="text" name="loan_amount" value="{{ request()->get('loan_amount', '') }}" class="form-control" id="loan_amount"></th>

                                <th><input type="text" name="net_disbusment" value="{{ request()->get('net_disbusment', '') }}" class="form-control" id="net_disbusment"></th>

                                <th><input type="text" name="total_exchange_amount" value="{{ request()->get('total_exchange_amount', '') }}" class="form-control" id="total_exchange_amount"></th>

                                <th><input type="text" name="total_received_amount" value="{{ request()->get('total_received_amount', '') }}" class="form-control" id="total_received_amount"></th>

                                <th><input type="text" name="finance_discount" value="{{ request()->get('finance_discount', '') }}" class="form-control" id="finance_discount"></th>

                                <th><input type="text" name="net_amount_received" value="{{ request()->get('net_amount_received', '') }}" class="form-control" id="net_amount_received"></th>

                                <th><input type="text" name="due_amount" value="{{ request()->get('due_amount', '') }}" class="form-control" id="due_amount"></th>

                                <th><input type="text" name="status" value="{{ request()->get('status', '') }}" class="form-control" id="status"></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.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>

<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>

<script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.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.datatables.net/1.13.7/js/jquery.dataTables.min.js"></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() {



        $('.js-example-basic-single').select2();



        var tableColumns = [

            { data: 'car_name', name: 'car_name' },

            { data: 'variant', name: 'variant' },

            { data: 'branch_name', name: 'branch_name' },

            { data: 'ex_showroom_price', name: 'ex_showroom_price' },

            { data: 'purchase_price', name: 'purchase_price' },

            { data: 'kin_margin', name: 'kin_margin',

                render: function(data, type, row) {

                    return Math.round(data);

                }

            },

            { data: 'fuel_type', name: 'fuel_type' },

            { data: 'vin_number', name: 'vin_number' },

            { data: 'inventory_type', name: 'inventory_type' },

            { data: 'inventory_status', name: 'inventory_status' },

            { data: 'aging_days', name: 'aging_days' },

            // OBF Info

            { data: 'booking_date', name: 'booking_date' },

            { data: 'customer_name', name: 'customer_name' },

            { data: 'gst', name: 'gst' },

            { data: 'team_name', name: 'team_name' },

            { data: 'sales_person_name', name: 'sales_person_name' },

            { data: 'exterior_color', name: 'exterior_color' },

            { data: 'on_road_price', name: 'on_road_price' },

            { data: 'booking_amount', name: 'booking_amount' },

            { data: 'dp_amount', name: 'dp_amount' },

            { data: 'loan_amount', name: 'loan_amount' },

            { data: 'net_disbusment', name: 'net_disbusment' },

            { data: 'total_exchange_amount', name: 'total_exchange_amount' },

            {

                data: null,

                name: 'total_received_amount',

                render: function (data) {

                    let total = parseFloat(data.booking_amount || 0)

                            + parseFloat(data.dp_amount || 0)

                            + parseFloat(data.net_disbusment || 0)

                            + parseFloat(data.total_exchange_amount || 0);

                    return total.toFixed(2);

                }

            },

            { data: 'finance_discount', name: 'finance_discount' },

            {

                data: null,

                name: 'net_amount_received',

                render: function (data) {

                    let total = parseFloat(data.booking_amount || 0)

                            + parseFloat(data.dp_amount || 0)

                            + parseFloat(data.net_disbusment || 0)

                            + parseFloat(data.total_exchange_amount || 0);

                    let discount = parseFloat(data.finance_discount || 0);

                    return (total - discount).toFixed(2);

                }

            },

            { data: 'due_amount', name: 'due_amount' },

            { data: 'status', name: '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": ""

                },

                // scrollY: '400px',

                scrollCollapse: true,

                paging: true,

                searching: false,



                bSortCellsTop : true,

                ajax: {

                    url: '{!! route("BookingRetailReportFetch") !!}',

                    method: "POST",

                    data: function (d) {

                        d.car_name = jQuery(".datatable-form-filter input[name='car_name']").val();

                        d.variant = jQuery(".datatable-form-filter input[name='variant']").val();

                        d.branch_name = jQuery(".datatable-form-filter input[name='branch_name']").val();

                        d.ex_showroom_price = jQuery(".datatable-form-filter input[name='ex_showroom_price']").val();

                        d.purchase_price = jQuery(".datatable-form-filter input[name='purchase_price']").val();

                        d.kin_margin = jQuery(".datatable-form-filter input[name='kin_margin']").val();

                        d.fuel_type = jQuery(".datatable-form-filter input[name='fuel_type']").val();

                        d.vin_number = jQuery(".datatable-form-filter input[name='vin_number']").val();

                        d.inventory_type = jQuery(".datatable-form-filter input[name='inventory_type']").val();

                        d.inventory_status = jQuery(".datatable-form-filter input[name='inventory_status']").val();

                        d.aging_days = jQuery(".datatable-form-filter input[name='aging_days']").val();

                        d.booking_date = jQuery(".datatable-form-filter input[name='booking_date']").val();

                        d.customer_name = jQuery(".datatable-form-filter input[name='customer_name']").val();

                        d.gst = jQuery(".datatable-form-filter input[name='gst']").val();

                        d.team_name = jQuery(".datatable-form-filter input[name='team_name']").val();

                        d.sales_person_name = jQuery(".datatable-form-filter input[name='sales_person_name']").val();

                        d.exterior_color = jQuery(".datatable-form-filter input[name='exterior_color']").val();

                        d.on_road_price = jQuery(".datatable-form-filter input[name='on_road_price']").val();

                        d.booking_amount = jQuery(".datatable-form-filter input[name='booking_amount']").val();

                        d.dp_amount = jQuery(".datatable-form-filter input[name='dp_amount']").val();

                        d.loan_amount = jQuery(".datatable-form-filter input[name='loan_amount']").val();

                        d.net_disbusment = jQuery(".datatable-form-filter input[name='net_disbusment']").val();

                        d.total_exchange_amount = jQuery(".datatable-form-filter input[name='total_exchange_amount']").val();

                        d.total_received_amount = jQuery(".datatable-form-filter input[name='total_received_amount']").val();

                        d.finance_discount = jQuery(".datatable-form-filter input[name='finance_discount']").val();

                        d.net_amount_received = jQuery(".datatable-form-filter input[name='net_amount_received']").val();

                        d.due_amount = jQuery(".datatable-form-filter input[name='due_amount']").val();

                        d.status = jQuery(".datatable-form-filter input[name='status']").val();

                    },

                    error : function(d) {}

                },

                columns: tableColumns,

                lengthMenu: [

                    [25, 50,100, -1 ],['25', '50','100', 'Show all' ]

                ],

                order: [ [0,'ASC'] ],

                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,

                drawCallback: function(settings) {

                    var rowCount = $('#data-table tbody tr').length;

            

                    if (rowCount < 3) {

                        $('#data-table').css('height', '600px');

                    } else {

                        $('#data-table').css('height', 'auto');

                    }

                }

            });

        })(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