@extends('template.app')



@section('meta') @endsection

@section('title') Cash Receipt 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">Cash Receipt 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">Cash Receipt 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('cashreceiptExport') }}" 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="row">

                    <div class="col-md-4">

                        <label>Branch:</label>

                        <select name="branch_name" class="form-control" id="branch_name">

                            <option value="">Select Branch</option>

                            @foreach($branch_nm as $key => $val)

                                <option value="{{$val->id}}">{{$val->name}}</option>

                            @endforeach    

                        </select>

                    </div>

                    <div class="col-md-4">

                        <label>Customer Name:</label>

                        <select name="customer_name" class="form-control" id="customer_name">

                            <option value="">Select Customer</option>

                            @foreach($cust_nm as $key => $val)

                                <option value="{{$val->id}}">{{$val->customer_name}}</option>

                            @endforeach    

                        </select>

                    </div>

                    <div class="col-md-4">

                        <label>Receipt Type:</label>

                        <select name="receipt_type" class="form-control" id="receipt_type">

                            <option value="">Select Receipt Type</option>

                            @foreach($receipt_type as $key => $val)

                                <option value="{{$val->receipt_type}}">{{ucwords(str_replace('_',' ',$val->receipt_type))}}</option>

                            @endforeach    

                        </select>

                    </div>

                </div>

                <div class="row">

                    <div class="col-md-4">

                        <label>Payment Type:</label>

                        <select name="payment_type" class="form-control" id="payment_type">

                            <option value="">Select Receipt Type</option>

                            @foreach($payment_type as $key => $val)

                                <option value="{{$val->payment_type}}">{{ucwords(str_replace('_',' ',$val->payment_type))}}</option>

                            @endforeach    

                        </select>

                    </div>

                    <div class="col-md-4">

                        <label>Start Date:</label>

                        <input type="date" id="start_date" class="form-control form-control-sm" placeholder="Start Date">

                    </div>

                    <div class="col-md-4">

                        <label>End Date:</label>

                        <input type="date" id="end_date" class="form-control form-control-sm" placeholder="End Date">

                    </div>

                </div>

                <div class="row">

                    <div class="col-md-4 mt-4">

                        <button id="submit-btn" class="btn waves-effect waves-light btn-rounded btn-outline-primary">Filter</button>

                    </div>

                </div>

            </div> 

        </div>

        <div class="col-12 mt-4">

            <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>Location</th>

                                    <th>KEC Name</th>

                                    <th>Customer Name</th>

                                    <th>Customer Mobile No.</th>

                                    <th>Receipt Date</th>

                                    <th>Receipt No.</th>

                                    <th>Receipt Amount</th>

                                    <th>Receipt Type</th>

                                    <th>Payment Method</th> 

                                    <th>Bank Account No.</th>

                                    <th>Hyp.</th>

                                    <th>Transaction No.</th>

                                    <th>Model</th>

                                    <th>Variant</th>

                                    <th>VIN Number</th>

                                    <th>Color</th>

                                    <th>Status</th>

                                    <th>Receipt Remark</th>

                                </tr>

                                <tr class="filterrow">

                                <th></th>

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                <th>

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

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

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

                                        </div>

                                    </div>

                                </th>

                                <th>

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

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

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

                                        </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>

                                    <th></th>

                                    <th></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: 'id',class:'text-center id',title: 'No.', orderable: false, width:100,default: true},

            {data: 'branch_name', name: 'branch_name',class:'text-center branch_name',title: 'Location', orderable: true,default: true},

            {data: 'kec_name', name: 'kec_name',class:'text-center kec_name',title: 'KEC Name', orderable: true,default: true},

            {data: 'customer_name', name: 'customer_name',class:'text-center customer_name',title: 'Customer Name', orderable: true,default: true},

            {data: 'contact_number', name: 'contact_number',class:'text-center contact_number',title: 'Customer Mobile No.', orderable: true,default: true},

            {data: 'receipt_date', name: 'receipt_date',class:'text-center receipt_date',title: 'Receipt Date', orderable: true,default: true},

            {data: 'receipt_no', name: 'receipt_no',class:'text-center receipt_no',title: 'Receipt No.', orderable: true,default: true},

            {data: 'receipt_amount', name: 'receipt_amount',class:'text-center receipt_amount',title: 'Receipt Amount', orderable: true,default: true},

            {data: 'receipt_type', name: 'receipt_type',class:'text-center receipt_type',title: 'Receipt Type', orderable: true,default: true},

            {data: 'payment_type', name: 'payment_type',class:'text-center payment_type',title: 'Payment Type', orderable: true,default: true},

            {data: 'bank_account_no', name: 'bank_account_no',class:'text-center bank_account_no',title: 'Bank Account No.', orderable: true,default: true},

            {data: 'hyp', name: 'hyp',class:'text-center hyp',title: 'Hyp.', orderable: false,default: true},

            {data: 'transaction_no', name: 'transaction_no',class:'text-center transaction_no',title: 'Transaction No.', orderable: false,default: true},

            {data: 'model_name', name: 'model_name',class:'text-center model_name',title: 'Model', orderable: false,default: true},

            {data: 'varient_name', name: 'varient_name',class:'text-center varient_name',title: 'Varient', orderable: false,default: true},

            {data: 'vin_number', name: 'vin_number',class:'text-center vin_number',title: 'VIN No.', orderable: false,default: true},

            {data: 'combined_color', name: 'combined_color',class:'text-center combined_color',title: 'Color', orderable: false,default: true},

            {data: 'status', name: 'status',class:'text-center status',title: 'Status', orderable: false,default: true},

            {data: 'cash_remark', name: 'cash_remark',

                render: function(data, type, row) {

                    if (!data) return '';

                    let shortText = data.length > 5 ? data.substring(0, 5) + '...' : data;

                    return `<span title="${data}" data-toggle="tooltip">${shortText}</span>`;

                }

            },

        ];



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

                    method: "GET",

                    data: function (d) {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            



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

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

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

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

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

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

                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 totalReceiptAmount = api.column(7, { page: 'current' }).data().reduce(function (a, b) {

                        return intVal(a) + intVal(b);

                    }, 0);

        

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

                },

        

                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);



        $('#submit-btn').on('click', function() {

            window.LaravelDataTables["dataTableBuilder"].draw(false); 

        });

        

        $("#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