 @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 Expense 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 Expense List</h3>
                     </div>
                 </div>
             </div>
         </div>
     </div>
     <form action="{{url('/realty/report-accouting-expense-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')) !!}
                 </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')) !!}
                 </div>
                 <div class="col-xs-12 col-sm-6 col-md-6">
                     <strong>accType</strong> {!! Form::select('journal_acccode', $account_chats, null, ['class' => 'form-control select2 journal_acccode']) !!}
                 </div>
                 <div class="col-xs-12 col-sm-6 col-md-6">
                     <strong>Pay For</strong> {!! Form::select('pay_for', $projects, null, ['class' => 'form-control select2 pay_for']) !!}
                 </div>
                 <div class="col-xs-12 col-sm-6 col-md-6">
                     <strong>Supplier</strong> {!! Form::select('supp_id', $supplier, null, ['class' => 'form-control select2 supp_id']) !!}
                 </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('Accounting-Report-Income-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_expense_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>Pay For</th>
                         <th>Supplier</th>
                         <th>Reference</th>
                         <th>Invoice</th>
                         <th>User By</th>
                         <th>Description</th>
                         <th>Amount</th>
                     </tr>
                 </thead>
                 <tbody class="tbody">

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

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

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

                 _token: '{{ csrf_token() }}',
                 start_date: start_date,
                 end_date: end_date,
                 journal_acccode: journal_acccode,
                 pay_for: pay_for,
                 supp_id: supp_id,
             },
             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.expense_code + "</td>" +
                         "<td>" + val.expense_title + "</td>" +
                         "<td>" + val.expense_for + "</td>" +
                         "<td>" + val.supplier_name + "</td>" +
                         "<td>" + val.reference_by + "</td>" +
                         "<td>" + val.expense_invoice + "</td>" +
                         "<td>" + val.user_by + "</td>" +
                         "<td>" + val.expense_des + "</td>" +
                         "<td>$" + parseFloat(val.expense_amount).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,') + "</td>" +
                         "</tr>";
                     total_expense += parseFloat(val.expense_amount);
                 });

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

             },

         });
     }
 </script>
 @endsection