@extends('template.app')

@section('meta')
@endsection

@section('title')
Cash Receipt
@endsection

@section('styles')
<style>
     .highlight {
        background-color: #ffff99; /* Change to desired highlight color */
    }
    #data-table.dataTable tbody td {
        padding: 0px !important;
        height: 20px !important;
        line-height: 35px !important;
        font-size: 15px !important;
        text-align: center;
    }
    .form-group .custom_color {
        background-color: lightgrey !important;
    }
</style>
@endsection

@section('content')
<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>
    #data-table td {
        white-space: nowrap;
        padding: 0.5rem !important;
        font-size: 15px;
    }

    .select2-container .select2-selection--single
    {
     
      height: 30px;
    }
    .mt-2
    {
        font-size: 15px;
        margin-left: 15px;
    }
    
    .custom-select {
        width: 200px !important;
    }
    
    .custom-form-spacing {
      margin-bottom: -19px;
    }
    
    
    /*.width_150 {*/
    /*    width: 150px;*/
    /*}*/
    /*.width_200 {*/
    /*    width: 200px;*/
    /*}*/
    /*.width_250 {*/
    /*    width: 250px;*/
    /*}*/
    /*.width_300 {*/
    /*    width: 300px;*/
    /*}*/
    /*.table {*/
    /*    min-height: 600px;*/
    /*}*/
</style>
<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</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('cash_receipt') }}" class="text-muted">Cash Receipt</a></li>
                        <li class="breadcrumb-item text-muted active" aria-current="page">List</li>
                    </ol>
                </nav>
            </div>
        </div>
        <div class="col-5 align-self-center">
            <div class="customize-input float-right">

            </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>Receipt Type</th>
                                <th>Receipt Number</th>
                                <th>Location</th>
                                <th>Customer Name (Bill To)</th>
                                <th>GST No. (Bill To)</th>
                                <th>Customer Name (Ship To)</th>
                                <th>Team Leader </th>
                                <th>KEC Name </th>
                                <th>Model</th>
                                <th>Variant</th>
                                <th> Exterior Color</th>
                                <th>VIN Number</th>
                                <th>On Road Price (A)</th>
                                <th>Booking Amount (B(+))</th>
                                <th>DP Amount Received (C(+))</th>
                                <th>Finance Amount</th> 
                                <th>Net Disbusment Amount (D(+))</th>
                                <th>Exchange Amount (E(+))</th>
                                <th>Total received amount (B+C+D+E = F)</th>
                                <th>Total Discount (G(-))</th>
                                <th>Total Amount Receivable (A-G = H)</th>
                                <th>Due Amount  (H-F=J)</th>
                                <th>Invoice No</th>
                                <th>Invoice Date</th>
                                <th>No of receipt </th>
                                <th>No of rejected receipt </th>
                                <th>Status</th>
                                <th>Action</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="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">
                                        <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="2">
                                        </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="3">
                                        </div>
                                    </div>
                                </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="4">
                                        </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="3">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="gst" value="{{ request()->get('gst', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="5">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="ship_to_customer_name" value="{{ request()->get('ship_to_customer_name', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="3">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="team_name" value="{{ request()->get('team_name', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="6">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <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" autocomplete="off" autofocus tabindex="7">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="product" value="{{ request()->get('product', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="8">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <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" autocomplete="off" autofocus tabindex="9">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="exterior_color" value="{{ request()->get('exterior_color', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="10">
                                        </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="11">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <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" autocomplete="off" autofocus tabindex="12">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="booking_amount" value="{{ request()->get('booking_amount', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="13">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="dp_amount" value="{{ request()->get('dp_amount', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="14">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="loan_amount" value="{{ request()->get('loan_amount', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="15">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="net_disbusment" value="{{ request()->get('net_disbusment', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="16">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="total_exchange_amount" value="{{ request()->get('total_exchange_amount', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="17">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="final_total" value="{{ request()->get('final_total', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="18">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="finance_discount" value="{{ request()->get('finance_discount', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="19">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="net_total" value="{{ request()->get('net_total', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="20">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="due_amount" value="{{ request()->get('due_amount', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="21">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="invoice_no" value="{{ request()->get('invoice_no', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="22">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="invoice_date" value="{{ request()->get('invoice_date', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="22">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="no_of_receipt" value="{{ request()->get('no_of_receipt', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="23">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                        <div class="form-group is-empty">
                                            <input type="text" name="no_of_receipt_rejected" value="{{ request()->get('no_of_receipt_rejected', '') }}" class="form-control text-capitalize custom_color" autocomplete="off" autofocus tabindex="24">
                                        </div>
                                    </div>
                                </th>
                                <th>
                                    <div class="search-box-container datatable-form-filter">
                                    <div class="form-group">
                                    <select name="status" class="form-control text-capitalize custom_color" tabindex="15">
                                        <option value="">-- Select Status --</option>
                                        <option value="accepted" {{ request()->get('status') == 'accepted' ? 'selected' : '' }}>Accepted</option>
                                        <option value="rejected" {{ request()->get('status') == 'rejected' ? 'selected' : '' }}>Rejected</option>
                                        <option value="pending" {{ request()->get('status') == 'pending' ? 'selected' : '' }}>Pending</option>
                                        <option value="cancel" {{ request()->get('status') == 'cancel' ? 'selected' : '' }}>Cancel</option>
                                    </select>
                                    </div>
                                    </div>
                                </th>
                                <th></th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>

        <!-- Modal -->
        <div class="modal fade" id="DescModal" role="dialog">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h3 class="modal-title">Reject Reason</h3>
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

                    </div>
                    <form action="">
                        <div class="modal-body">
                            
                                <input type="hidden" name="id" id="id" value="">
                                <input type="hidden" name="status" id="status" value="">
                                <label for="">Enter Your Reason</label>
                                <textarea placeholder="Please Enter Your Reason" class="form-control" name="reason" id="reason" cols="30" rows="10"></textarea>
                            

                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default " onclick="status_reject(this);" >Submit</button>
                            <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
                        </div>
                    </form>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
        <!-- Modal -->
    </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() {
            $('#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();
        });
        
            var tableColumns = [
                {data: 'id', name: 'id',class:'text-center id',title: 'No.', orderable: false, width:100,default: true},
                {data: 'booking_date', name: 'booking_date',class:'text-center booking_date',title: 'Date', orderable: false,default: true},
                {data: 'receipt_type', name: 'receipt_type',class:'text-center receipt_type',title: 'Receipt Type', orderable: true,default: true},
                {data: 'receipt_no', name: 'receipt_no',class:'text-center receipt_no',title: 'Receipt No', orderable: true,default: true},
                {data: 'branch_name', name: 'branch_name',class:'text-center branch_name',title: 'Location', orderable: true,default: true},
                {data: 'customer_name', name: 'customer_name',class:'text-center customer_name',title: 'Customer Name (Bill To)', orderable: true,default: true},
                {data: 'gst', name: 'gst',class:'text-center gst',title: 'GST No. (Bill To)', orderable: true,default: true},
                {data: 'ship_to_customer_name', name: 'ship_to_customer_name',class:'text-center ship_to_customer_name',title: 'Customer Name (Ship To)', orderable: true,default: true},
                {data: 'team_name', name: 'team_name',class:'text-center team_name',title: 'Team Leader', orderable: true,default: true},
                {data: 'sales_person_name', name: 'sales_person_name',class:'text-center sales_person_name',title: 'KEC Name', orderable: true,default: true},
                {data: 'product', name: 'product',class:'text-center product',title: 'Model', orderable: true,default: true},
                {data: 'car_varient_name', name: 'car_varient_name',class:'text-center car_varient_name',title: 'Variant', orderable: true,default: true},
                {data: 'exterior_color', name: 'exterior_color',class:'text-center exterior_color',title: 'Exterior Color', orderable: true,default: true},
                {data: 'vin_number', name: 'vin_number',class:'text-center vin_number',title: 'VIN No.', orderable: true,default: true},
                {data: 'on_road_price', name: 'on_road_price',class:'text-center on_road_price',title: 'On Road Price (A)', orderable: false,default: true},
                {data: 'booking_amount', name: 'booking_amount',class:'text-center booking_amount',title: 'Booking Amount (B(+))', orderable: false,default: true},
                {data: 'dp_amount', name: 'dp_amount',class:'text-center dp_amount',title: 'DP Amount Received (C(+))', orderable: false,default: true},
                {data: 'loan_amount', name: 'loan_amount',class:'text-center loan_amount',title: 'Finance Amount', orderable: false,default: true},
                {data: 'net_disbusment', name: 'net_disbusment',class:'text-center net_disbusment',title: 'Net Disbusment Amount (D(+))', orderable: false,default: true},
                {data: 'total_exchange_amount', name: 'total_exchange_amount',class:'text-center total_exchange_amount',title: 'Exchange Amount (E(+))', orderable: false,default: true},
                {data: 'final_total', name: 'final_total',class:'text-center final_total',title: 'Total received amount (B+C+D+E = F)', orderable: false,default: true},
                {data: 'finance_discount', name: 'finance_discount',class:'text-center finance_discount',title: 'Total Discount (G(-))', orderable: false,default: true},
                {data: 'net_total', name: 'net_total',class:'text-center net_total',title: 'Total Amount Receivable (A-G = H)', orderable: false,default: true},
                {data: 'due_amount', name: 'due_amount',class:'text-center due_amount',title: 'Due Amount  (H-F=J)', orderable: false,default: true},
                {data: 'invoice_no', name: 'invoice_no',class:'text-center invoice_no',title: 'Invoice No.', orderable: false,default: true},
                {data: 'invoice_date', name: 'invoice_date',class:'text-center invoice_date',title: 'Invoice Date', orderable: false,default: true},
                {data: 'no_of_receipt', name: 'no_of_receipt',class:'text-center no_of_receipt',title: 'No. Of Receipt', orderable: true,default: true},
                {data: 'no_of_receipt_rejected', name: 'no_of_receipt_rejected',class:'text-center no_of_receipt_rejected',title: 'No. Of Rejected Receipt', orderable: true,default: true},
                {data: 'status', name: 'status',class:'text-center status',title: 'Status', orderable: true,default: true},
                {data: 'action',name: 'action',class:'text-center action',title: 'Action',orderable: false,searchable: true},
            ];
            
            (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": ""
                    },
                    scrollCollapse: true,
                    paging: true,
                    searching: false,
                    scrollY: "450px",
                    scrollX: "true",
                    bSortCellsTop : true,
                    ajax: {
                        url: '{!! route("cash_receipt") !!}',
                        data: function (d) {
                            d.booking_date = jQuery(".datatable-form-filter input[name='booking_date']").val();
                            d.receipt_type = jQuery(".datatable-form-filter input[name='receipt_type']").val();
                            d.receipt_no = jQuery(".datatable-form-filter input[name='receipt_no']").val();
                            d.branch_name = jQuery(".datatable-form-filter input[name='branch_name']").val();
                            d.customer_name = jQuery(".datatable-form-filter input[name='customer_name']").val();
                            d.gst = jQuery(".datatable-form-filter input[name='gst']").val();
                            d.ship_to_customer_name = jQuery(".datatable-form-filter input[name='ship_to_customer_name']").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.product = jQuery(".datatable-form-filter input[name='product']").val();
                            d.car_varient_name = jQuery(".datatable-form-filter input[name='car_varient_name']").val();
                            d.exterior_color = jQuery(".datatable-form-filter input[name='exterior_color']").val();
                            d.vin_number = jQuery(".datatable-form-filter input[name='vin_number']").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.final_total = jQuery(".datatable-form-filter input[name='final_total']").val();
                            d.finance_discount = jQuery(".datatable-form-filter input[name='finance_discount']").val();
                            d.net_total = jQuery(".datatable-form-filter input[name='net_total']").val();
                            d.due_amount = jQuery(".datatable-form-filter input[name='due_amount']").val();
                            d.invoice_no = jQuery(".datatable-form-filter input[name='invoice_no']").val();
                            d.invoice_date = jQuery(".datatable-form-filter input[name='invoice_date']").val();
                            d.no_of_receipt = jQuery(".datatable-form-filter input[name='no_of_receipt']").val();
                            d.no_of_receipt_rejected = jQuery(".datatable-form-filter input[name='no_of_receipt_rejected']").val();
                            d.status = jQuery(".datatable-form-filter select[name='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();
            });
    
            window.change_status = function(object) {
                var id = $(object).data("id");
                var status = $(object).data("status");
                
                if (confirm('Are you sure?')) {
                    $.ajax({
                        "url": "{!! route('cash_receipt.change.status') !!}",
                        "dataType": "json",
                        "type": "POST",
                        "data": {
                            id: id,
                            status: status,
                            _token: "{{ csrf_token() }}"
                        },
                        success: function(response) {
                            if (response.code == 200) {
                                datatable.ajax.reload();
                                toastr.success('Status changed successfully', 'Success');
                                location.reload();
                            } else {
                                toastr.error('Failed to change status', 'Error');
                            }
                        }
                    });
                }
            }
            
            window.change_status_reject = function(object) {
                var id = $(object).data("id");
                var status = $(object).data("status");
                $('#DescModal').modal("show");
                $('#id').val(id);
                $('#status').val(status);
            } 
            
            window.status_reject = function() {
                var id = $('#id').val();
                var status = $('#status').val();
                var reason = $('#reason').val();
                $('#DescModal').modal("hide");
                $('#id').val('');
                $('#status').val('');
                $.ajax({
                    "url": "{!! route('cash_receipt.change.status') !!}",
                    "dataType": "json",
                    "type": "POST",
                    "data": {
                        id: id,
                        status: status,
                        reason: reason,
                        _token: "{{ csrf_token() }}"
                    },
                    success: function(response) {
                        if (response.code == 200) {
                            datatable.ajax.reload();
                            toastr.success('Status changed successfully', 'Success');
                            location.reload();
                        } else {
                            toastr.error('Failed to change status', 'Error');
                        }
                    }
                });
            }
            
            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>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
@endsection