@extends('template.app')



@section('meta') @endsection

@section('title') Make Deal 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">Make Deal 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">Make Deal 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-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>Date</th>

                                <th>Customer Name</th>

                                <th>Location</th>

                                <th>VIN Number</th>

                                <th>Team Leader</th>

                                <th>KEC Name</th>

                                <!--<th>Ex. Showroom Amount</th>-->

                                <th>GST Tax Amount</th>

                                <th>Cess Tax Amount</th>

                                <th>TCS Tax Amount</th>

                                <th>Municipal Tax Amount</th>

                                <th>RTO Amount</th>

                            </tr>

                            <tr class="filterrow">

                                <th></th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_150">

                                        <div class="form-group is-empty">

                                            <input type="text" name="booking_date" value="{{ request()->get('booking_date', '') }}" class="form-control text-capitalize" autocomplete="off" tabindex="1" id="booking_date" placeholder="DD-MM-YYYY to DD-MM-YYYY">

                                        </div>

                                    </div>

                                </th>

                                <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="3">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_250">

                                        <div class="form-group is-empty">

                                            <input type="text" name="branch_name" value="{{ request()->get('branch_name', '') }}" class="form-control text-capitalize custom_color" id="branch_name" autocomplete="off" autofocus tabindex="2">

                                        </div>

                                    </div>

                                </th>

                                <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="10">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_150">

                                        <div class="form-group is-empty">

                                            <input type="text" name="team_name" value="{{ request()->get('team_name', '') }}" class="form-control text-capitalize" id="team_name" autocomplete="off" tabindex="1">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_200">

                                        <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="6">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_200">

                                        <div class="form-group is-empty">

                                            <input type="text" name="gst_tax_deal" value="{{ request()->get('gst_tax_deal', '') }}" class="form-control text-capitalize custom_color" id="gst_tax_deal" autocomplete="off" autofocus tabindex="6">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_200">

                                        <div class="form-group is-empty">

                                            <input type="text" name="cess_tax_deal" value="{{ request()->get('cess_tax_deal', '') }}" class="form-control text-capitalize custom_color" id="cess_tax_deal" autocomplete="off" autofocus tabindex="6">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_200">

                                        <div class="form-group is-empty">

                                            <input type="text" name="tcs_tax_deal" value="{{ request()->get('tcs_tax_deal', '') }}" class="form-control text-capitalize custom_color" id="tcs_tax_deal" autocomplete="off" autofocus tabindex="6">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_200">

                                        <div class="form-group is-empty">

                                            <input type="text" name="municipal_tax_deal" value="{{ request()->get('municipal_tax_deal', '') }}" class="form-control text-capitalize custom_color" id="municipal_tax_deal" autocomplete="off" autofocus tabindex="6">

                                        </div>

                                    </div>

                                </th>

                                <th>

                                    <div class="search-box-container datatable-form-filter width_200">

                                        <div class="form-group is-empty">

                                            <input type="text" name="rto_deal" value="{{ request()->get('rto_deal', '') }}" class="form-control text-capitalize custom_color" id="rto_deal" autocomplete="off" autofocus tabindex="6">

                                        </div>

                                    </div>

                                </th>

                            </tr>

                        </thead>

                        <tfoot>

                            <tr>

                                <th></th>

                                <th></th>

                                <th></th>

                                <th></th>

                                <th></th>

                                <th></th>

                                <th class="text-right">Total :</th>

                                <th></th>

                                <th></th>

                                <th></th>

                                <th></th>

                                <th></th>

                            </tr>

                        </tfoot>

                    </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() {

        

        let rowCount = $("table tbody tr").length;

        if (rowCount < 3) {

            $(".table").css("height", "600px");

        }



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



        var tableColumns = [

            { data: 'id', name: 'No', orderable: false, searchable: false },

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

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

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

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

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

            { data: 'kec_name', name: 'kec_name'},

            { data: 'gst_tax_deal', name: 'gst_tax_deal'},

            { data: 'cess_tax_deal', name: 'cess_tax_deal' },

            { data: 'tcs_tax_deal', name: 'tcs_tax_deal' },

            { data: 'municipal_tax_deal', name: 'municipal_tax_deal' },

            { data: 'rto_deal', name: 'rto_deal' },

        ];

        

        (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("MakeDealReportFetch") !!}',

                    method: "POST",

                    data: function (d) {

                        d.booking_date = $('#booking_date').val(); 

                        d.customer_name = $('#customer_name').val(); 

                        d.branch_name = $('#branch_name').val();

                        d.team_name = $('#team_name').val(); 

                        d.sales_person_name = $('#sales_person_name').val();

                        d.gst_tax_deal = $('#gst_tax_deal').val();

                        d.cess_tax_deal = $('#cess_tax_deal').val();

                        d.tcs_tax_deal = $('#tcs_tax_deal').val();

                        d.municipal_tax_deal = $('#municipal_tax_deal').val();

                        d.rto_deal = $('#rto_deal').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,

                

                footerCallback: function (row, data, start, end, display) {

                    var api = this.api();

                    

                    var intVal = function (i) {

                        return typeof i === 'string' ?

                            i.replace(/[$,]/g, '') * 1 :

                            typeof i === 'number' ? i : 0;

                    };

                    

                    var totalgst_tax_deal = api.column(7, { page: 'current' }).data().reduce((a, b) => intVal(a) + intVal(b), 0);

                    var totalcess_tax_deal = api.column(8, { page: 'current' }).data().reduce((a, b) => intVal(a) + intVal(b), 0);

                    var totaltcs_tax_deal = api.column(9, { page: 'current' }).data().reduce((a, b) => intVal(a) + intVal(b), 0);

                    var totalmunicipal_tax_deal = api.column(10, { page: 'current' }).data().reduce((a, b) => intVal(a) + intVal(b), 0);

                    var totalrto_deal = api.column(11, { page: 'current' }).data().reduce((a, b) => intVal(a) + intVal(b), 0);

    

                    

                    $(api.column(7).footer()).html(totalgst_tax_deal.toLocaleString());

                    $(api.column(8).footer()).html(totalcess_tax_deal.toLocaleString());

                    $(api.column(9).footer()).html(totaltcs_tax_deal.toLocaleString());

                    $(api.column(10).footer()).html(totalmunicipal_tax_deal.toLocaleString());

                    $(api.column(11).footer()).html(totalrto_deal.toLocaleString());

                },

            });

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