 @extends('adminlte::page') @section('content')
<?php Fun::lang()?>
    <div class="title-page">
        <div class="page-bar">
            <ul class="page-breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
              <li><a href="#">Report Accounting</a></li>
              <li><a href="#">Report Withdrawal List</a></li>
            </ul>
        </div>
    </div>
    <div class="page">
        <div class="top-content">
            <div class="row">
                <div class="col-sm-12 col-xs-12">
                    <div class="title-add">
                        <div class="pull-left">
                            <h3>Report Withdrawal List</h3>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <form action="{{url('/realty/report-accouting-withdrawal-print')}}" method="POST">
            @csrf
            <div class="form-search">
                <div class="row">
                    <div class="col-xs-12 col-sm-6 col-md-6">
                        <strong>Start Date</strong> {!! Form::text('start_date', null, array('placeholder' => 'Start Date','class' => 'form-control date_picker start_date','autocomplete' => 'off','required')) !!}
                    </div>
                    <div class="col-xs-12 col-sm-6 col-md-6">
                        <strong>End Date</strong> {!! Form::text('end_date', null, array('placeholder' => 'End Date','class' => 'form-control date_picker end_date','autocomplete' => 'off','required')) !!}
                    </div>

                    <div class="col-xs-12 col-sm-12 col-md-12 text-right">
                        <button type="button" class="button_primary btn-sm search" onclick="searching()"><span class="fa fa-search"> Search</span></button>&nbsp
                        @can('Withdrawal-Print')
                ​​​​​​​​​​​​​​​​            <button type="submit" class="button_primary btn-sm search"><span class="fa fa-print"> Print</span></button>
                        @endcan
                    </div>
                </div>
            </div>
        {!! Form::close() !!}
        <div class="box-body table-responsive">
            <table id="datatable_accounting_withdrawal_report" class="table table-striped table-bordered table-hover nowrap">
                <thead>
                    <tr>
                        <th>No</th>
                        <th>Date</th>
                        <th>Code</th>
                        <th>Title</th>
                        <th>Description</th>
                        <th>Reference</th>
                        <th>User By</th>
                        <th>Amount</th>
                    </tr>
                </thead>
                <tbody class="tbody">

                </tbody>
                <tfoot class="tfoot">
                    <tr>
                        <td colspan="7" class="text-right">Total :</td>
                        <td></td>
                    </tr>
                </tfoot>
            </table>
        </div>
    </div>
    @endsection @section('js')

    <script type="text/javascript" src="{{asset('assets/controller/report-withdraw-administrator.js')}}"></script>
    <script type="text/javascript">
        function searching() {

            var start_date = $('.start_date').val();
            var end_date = $('.end_date').val();
            var table = '';
            var i = 0;
            var total_withraw = 0;
            $('.tbody').empty();
            $('.tfoot').empty();
            $.ajax({
                method: 'POST',
                dataType: 'json',
                url: '/realty/report-accounting-withdrawal',
                async: false,
                data: {

                    _token: '{{ csrf_token() }}',
                    start_date: start_date,
                    end_date: end_date,
                },
                success: function(response) {
                    $.each(response, function(index, val) {
                        str = val.do_date;
                        st2 = str.split("-");

                        yr = st2[0];
                        mo = st2[1];
                        dy = st2[2];
                        var new_date = dy+'-'+mo+'-'+yr;
                        i++;
                        table += "<tr class='remove'>" +
                            "<td>" + i + "</td>" +
                            "<td>" + new_date + "</td>" +
                            "<td>" + val.withdraw_code + "</td>" +
                            "<td>" + val.withdraw_title + "</td>" +
                            "<td>" + val.withdraw_des + "</td>" +
                            "<td>" + val.withdraw_invoice + "</td>" +
                            "<td>" + val.user_by + "</td>" +
                            "<td>$" + parseFloat(val.withdraw_amount).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,') + "</td>" +
                            "</tr>";

                        total_withraw += parseFloat(val.withdraw_amount);
                    });

                    $('.dataTables_filter').hide();
                    $('.dataTables_info').hide();
                    $('.pagination').hide();
                    $('.dataTables_length').hide();
                    var tfoot = `<tr>
                            <td colspan="7" class="text-right">Total : </td>
                            <td>$${parseFloat(total_withraw).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')}</td>
                          </tr>`;
                    $('.tbody').append(table);
                    $('.tfoot').append(tfoot);

                },

            });
        }
    </script>
    @endsection