@extends('layouts.app')



@section('content')
@include('modal.historytebus')
@include('modal.wakil')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-12 col-lg-12">

            <nav aria-label="breadcrumb">
                <ol class="breadcrumb pb-3">
                  <li class="breadcrumb-item"><a href="{{ route('home') }}">Home</a></li>
                  <li class="breadcrumb-item"><a href="{{ url('/khazanah/indexwakil') }}">ID Pelanggan</a></li>
                  <li class="breadcrumb-item active" aria-current="page">Senarai Surat Pelanggan</li>
                </ol>
            </nav>

            <div class="form-group row col-md-12">
                <div class="col-md-6">
                    <div class="form-group row">
                        <div class="col-md-4">
                            <b>Nama</b>
                        </div>
                        <div class="col-md-8">
                            <input type="text" class="form-control" name="name" id="name" readonly value="{{ $customer_info['nama'] }}">
                        </div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group row">
                        <div class="col-md-4">
                            <b>No Kad Pengenalan</b>
                        </div>
                        <div class="col-md-8">
                            @php
                                if($customer_info['kpbaru'] != null){
                                    $noic = $customer_info['kpbaru'];
                                }else{
                                    $noic = $customer_info['kplama'];
                                }
                            @endphp
                            <input type="text" class="form-control" name="noic" id="noic" readonly value="{{ $noic }}">
                        </div>
                    </div>
                </div>
                <div class="col-md-6">

                    <div class="form-group row">
                        <div class="col-md-4">
                            <b>No Telefon</b>
                        </div>
                        <div class="col-md-8">
                            <input type="text" class="form-control" name="cust_telefon" id="cust_telefon" readonly value="{{ $customer_info['telefon'] ? $customer_info['telefon'] : '' }}">
                        </div>
                    </div>                   

                </div>

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


                   <div class="form-group row">
                        <div class="col-md-4">
                            <b>Alamat </b>
                        </div>
                        <div class="col-md-8">
                            <input type="text" class="form-control" name="alamat" id="alamat" readonly value="{{$customer_info['alamat1'] }}">
                        </div>
                    </div>    

                </div>

            </div>
                    
                    <div class="card">
                        <div class="card-body">

                            <div class="tab-content" id="listsagpelanggan">
                                
                                <div id="listsag" role="tabpanel" aria-labelledby="listsag-tab">
                                    <table id="xtawarruq" class="table table-striped table-hover">
                                        <thead class="thead-dark">
                                        
                                            <tr>
                                                <th>Bil</th>
                                                <th>No Rujukan</th>
                                                <th>Tarikh Pembiayaan</th>
                                                <th>Tempoh</th>
                                                <th>Surat Wakil</th>
                                        </thead>
                                    </table>
                                </div>
                            </div>
                            
                        </div>
                    </div>
        </div>
    </div>
</div>



<script>
    var api_arrahnbid = "<?php echo config('app.api_arrahnbid') ?>";
    var api_url = "<?php echo $api_url ?>";
    var kodcaw = "{{ $cawangan_info['kodcaw'] }}";
    var tagarrahnbid = "{{ $cawangan_info['tagarrahnbid'] }}";
    
   
    var tablegadai = $('#myTable').DataTable({
        "scrollX": false,
        order: [[1,'desc']]
    });

    var xtawarruq = $('#xtawarruq').DataTable({
        "scrollX": false
    });
    
    const formatter = new Intl.NumberFormat('en-US', {
        minimumFractionDigits: 2
    });   


    function gadaiTable(data,jenistebus){

        var counter = 1;
        tablegadai.clear().draw();
        xtawarruq.clear().draw();
        $.each(data,function(index,gadai_detail){

            // console.log(gadai_detail);

            // console.log(route_norujukan);
            $.ajax({
                method:'get',
                url:api_url + '/api/upahtawarruq/'+ gadai_detail['kodcaw'] +'/' + gadai_detail['norujukan'],
                

                success:function(sag){

                        var urlroute = '{{ route("khazanah.print.suratwakil", ":id") }}';
                        urlroute = urlroute.replace(':id', gadai_detail["norujukan"]);
                        
                            let table_norujukan = gadai_detail["norujukan"];
                            xtawarruq.row.add([
                                counter,
                                gadai_detail['norujukan'],
                                gadai_detail['t_gadai'],
                                gadai_detail['tempoh'],                                 
                                "<a class='btn m-1 btn-info' data-toggle='tooltip' data-placement='top' target='_blank' href="+ urlroute +"><i class='fas fa-print'></i></a>",

                            ]).draw();    
                    
                    counter = counter + 1;
                }
            });
        });
    }

    $(document).ready( function () {
        
        var noic = $("#noic").val();

        $.ajax({
            method:"GET",
            url: api_url + "/api/customers/"+noic+"/gadai/belum_tebus/"+kodcaw,
            success: function(data){
                $('#myTable').parents('div.dataTables_wrapper').first().show();
                gadaiTable(data,"belum_tebus");
            }
        });

      

       
    });   
    
    
</script>
@endsection
