@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">{{ __('Laporan Aging Bulanan') }}</div>

                <div class="card-body text-center">
                    <div class="row form-group">
                        <div class="col-md-2">
                        </div>
                        <div class="col-md-10">
                        </div>
                    </div>

                    
                    <div class="row">
                        <div class="col-md-5">
                            <form action="{{ route('agingbulan.cetaklaporan') }}" target="_blank" method="post">
                                @csrf
                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text" id="basic-addon1"  >Tarikh</span>
                                    </div>
                                    <input type="text" class="form-control" placeholder="Pilih Tarikh" aria-label="Tarikh" id="datetimepicker1" name="datetimepicker1"    autocomplete="off"  aria-describedby="basic-addon1">
                                     <input type="hidden"  id="num1" name="num1" value=1>
                                     <input type="hidden"  id="num2" name="num2" value=2>
                                     <input type="hidden"  id="num3" name="num3" value=3>
                                     <input type="hidden"  id="num4" name="num4" value=4>
                                     <input type="hidden"  id="num5" name="num5" value=5>

                                     <input type="hidden"  id="num6" name="num6" value=6>
                                     <input type="hidden"  id="num7" name="num7" value=7>
                                     <input type="hidden"  id="num8" name="num8" value=8>
                                     <input type="hidden"  id="num9" name="num9" value=9>
                                     <input type="hidden"  id="num10" name="num10" value=10>
                                     <input type="hidden"  id="num11" name="num11" value=11>
                                     <input type="hidden"  id="num12" name="num12" value=12>
                                     <input type="hidden"  id="num13" name="num13" value=12>


                                    <input type="submit" class="btn btn-primary ml-md-5" id="submit_button" name="submit_button" value="Cetak">
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-12">
                            <table class="" id="myTable">
                                <thead>
                                    <tr>
                                        <th>Bil</th>
                                        <th>Bil Pembiayaan</th>
                                        <th>Jumlah Pinjaman (RM)</th>
                                        <th>Peratusan %</th>
                                    
                             
                                    </tr>
                                </thead>
                            </table>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-12 text-right">
                            Bilangan Surat : <span id="bilangan_surat">3</span>
                            Jumlah Pembiayaan : <span id="jumlah_pinjaman">RM 3,000.00</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var api_url = "<?php echo $api_url ?>";
    var kodcaw = "<?php echo $cawangan_info['kodcaw'] ?>";

    var tablecustomers = $('#myTable').DataTable({
        "ordering": false
    });
    $(document).ready( function () {
        $('#datetimepicker1').datepicker({
            format: 'dd-mm-yyyy'
        });
        var current = new Date();
        var current_date = current.getDate();
        var current_month = current.getMonth()+1;
        var current_year = current.getFullYear();
        var today_date = current_year + '-' +current_month+'-'+current_date;
        $.ajax({
            method:'get',
            url: api_url + '/api/marhun/laporan/'+kodcaw+'/' + today_date,
            success: function(customers){
                customertable(customers);
            },error: function(XMLHttpRequest, textStatus, errorThrown) {
                console.log(textStatus);
            }
        });
    });

    $('#datetimepicker1').change(function(){
        var input_date = this.value;
        var split_date = input_date.split('-');
        var today_date = split_date[2] + '-' +split_date[1]+'-'+split_date[0];
        $.ajax({
            method:'get',
            url: api_url + '/api/marhun/laporan/'+kodcaw+'/' + today_date,
            success: function(customers){
                customertable(customers);
            }
        });
    });
    
    function customertable(data){
        var counter = 1;
        tablecustomers.clear().draw();
        $.each(data,function(index,customers){
            
            tablecustomers.row.add([
                counter,
                customers['norujukan'],
                customers['nokp'],
                customers['nama'],
                customers['marhun'],
                customers['nota'],
                customers['berat'],
                customers['karat'],
                customers['harga'],
                customers['n_marhun'],
            ]).draw();
     
        });
        
    }
</script>
@endsection

