@extends('layouts.app')
@section('content')
<!-- The Modal -->
<div class="modal fade" id="marhunModal">
    <div class="modal-dialog modal-xl modal-dialog-centered">
        <div class="modal-content">

          <!-- Modal Header -->
            <div class="modal-header">
                <h4 class="modal-title"></h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

          <!-- Modal body -->
            <div class="modal-body">
                <h4>Marhun</h4>
                <table id="biasa" class="table table-striped table-bordered text-center" style="width:100%">
                    <thead class="thead-dark">
                        <tr>
                            <th>Bil</th>
                            <th>Jenis Marhun</th>
                            <th>Berat Bersih</th>
                            <th>Karat</th>
                            <th>Nilai Marhun</th>
                            <th>Nota</th>
                            <th>Berat Permata</th>
                        </tr>
                    </thead>
                    <tbody id="tablemarhun">
                    </tbody>
                </table>
                <div class="row form-group">
                    <div class="col-md-12 text-center">
                        <form target="_blank" action="{{ route('printsag') }}" id="print_submit" method="post">
                            @csrf
                            <input hidden value="gadaiansemasa" name="jenisprint">
                            <input type="text" hidden name="norujukan_modal" id="norujukan_modal">
                            <input type="text" hidden name="pinjaman_modal" id="pinjaman_modal">
                            <input type="submit" class="btn btn-primary" id="cetak_sag" value="Cetak SAG">
                        </form>
                    </div>
                </div>
          </div>

          <!-- Modal footer -->
          <div class="modal-footer">
              <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
          </div>

      </div>
  </div>
</div>

<div class="modal fade" id="belum_serah_modal">
    <div class="modal-dialog modal-xl modal-dialog-centered">
        <div class="modal-content">

          <!-- Modal Header -->
            <div class="modal-header">
                <h4 class="modal-title"></h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

          <!-- Modal body -->
            <div class="modal-body">
                <h4>Marhun</h4>
                <table id="biasa" class="table table-striped table-bordered text-center" style="width:100%">
                    <thead class="thead-dark">
                        <tr>
                            <th>Bil</th>
                            <th>Jenis Marhun</th>
                            <th>Berat Bersih</th>
                            <th>Karat</th>
                            <th>Nilai Marhun</th>
                            <th>Nota</th>
                            <th>Berat Permata</th>
                        </tr>
                    </thead>
                    <tbody id="belum_serah">
                    </tbody>
                </table>
                <div class="row form-group">
                    <div class="col-md-12 text-center">
                        <form target="_blank" action="{{ route('printsag') }}" id="print_submit_belum_serah" method="post">
                            @csrf
                            <input type="text" hidden name="norujukan_modal" id="norujukan_modal1">
                            <input type="text" hidden name="pinjaman_modal" id="pinjaman_modal1">
                            <input type="button" class="btn btn-primary" id="cetak_sag_belum_serah" value="Cetak SAG">
                        </form>
                    </div>
                </div>
          </div>

          <!-- Modal footer -->
          <div class="modal-footer">
              <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
          </div>

      </div>
  </div>
</div>

<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-12">
            <div class="card">

                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb pb-3">
                      <li class="breadcrumb-item"><a href="#">Home</a></li>
                    <li class="breadcrumb-item active" aria-current="page">Pembiayaan</li>
                    </ol>
                  </nav>

                <input type="hidden" name="kodcaw" id="kodcaw" value="{{$cawangan_info['kodcaw']}}">
                <div class="card-body text-center">
                    <ul class="nav nav-tabs" id="myTab" role="tablist">
                        <li class="nav-item">
                            <a class="nav-link active" id="gadaian-semasa-tab" data-toggle="tab" href="#gadaian-semasa" role="tab" aria-controls="gadaian-semasa" aria-selected="true"> Semasa</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" id="gadaian-belum-serah-tab" data-toggle="tab" href="#gadaian-belum-serah" role="tab" aria-controls="gadaian-belum-serah" aria-selected="false"> Belum Serah</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" id="rekod-gadaian-tab" data-toggle="tab" href="#rekod-gadaian" role="tab" aria-controls="rekod-gadaian" aria-selected="false">Rekod </a>
                        </li>
                    </ul>
                    <div class="tab-content" id="myTabContent">
                        <div class="tab-pane fade show active" id="gadaian-semasa" role="tabpanel" aria-labelledby="gadaian-semasa-tab">
                            <table class='table table-striped table-hover' id='table-gadaian-semasa'>
                                <thead class="thead-dark">
                                    <tr>
                                        <th>Bil</th>
                                        <th>Nama</th>
                                        <th>No KP</th>
                                        <th>No Rujukan</th>
                                        <th>Pembiayaan (RM)</th>
                                        <th>Nilai Marhun (RM)</th>
                                        <th>Berat (g)</th>
                                        <th>Surat Wakil</th>

                                    </tr>
                                </thead>
                                <tbody>
                                    @php $count=1; @endphp
                                    @if (is_array($gadaian_semasa) || is_object($gadaian_semasa))
                                        @foreach($gadaian_semasa as $index=>$gadaian)
                                            <tr>
                                                <td>{{ $count }}</td>
                                                <td style="white-space: nowrap">
                                                    @php
                                                        $customer_info = Http::withOptions(['verify' => config('app.api_verify')])->get($api_url . '/api/customers/'. $gadaian['nokp'])->json();
                                                        echo ($customer_info['nama']);
                                                    @endphp
                                                </td>
                                                <td>{{ $gadaian['nokp'] }}</td>
                                                <td style="white-space: nowrap">
                                                    @php
                                                        $marhun = Http::withOptions(['verify' => config('app.api_verify')])->get($api_url . '/api/marhun/' . $gadaian['norujukan'] )->json();
                                                    @endphp
                                                    <a href="#" data-toggle="modal" data-marhun="{{ json_encode($marhun) }}" data-pinjaman="{{$gadaian['pinjaman']}}" data-norujukan="{{$gadaian['norujukan']}}" data-hargajualan="{{$gadaian['hargajualan']}}" data-kodcaw="{{ $gadaian['kodcaw'] }}" data-target="#marhunModal"> {{$gadaian['norujukan']}}</a>
                                                </td>
                                                <td>{{ number_format($gadaian['pinjaman'],2) }}</td>
                                                <td>{{ number_format($gadaian['nilaimarhun'],2) }}</td>
                                                <td>{{ number_format($gadaian['berat'],2) }}</td>
                                                <td><a href="{{ route('penilai.print.suratwakil',$gadaian['norujukan']) }}" target='_blank' class="float-center btn btn-info mr-2"><i class='fas fa-print'></i></a></td>
                                            </tr>
                                            @php $count++; @endphp
                                        @endforeach
                                    @endif
                                </tbody>
                            </table>
                        </div>
                        <div class="tab-pane fade" id="gadaian-belum-serah" role="tabpanel" aria-labelledby="gadaian-belum-serah-tab">
                            {{-- <div class="float-right mb-3">
                                <button class="btn btn-primary mt-4 pull-left" onclick="checkallfunc()" disabled>Check All</button>
                                <button class="btn btn-primary mt-4 pull-left" onclick="uncheckallfunc()" disabled>Uncheck All</button>
                                <input type="checkbox" id="selectallcheck" onclick="checkallfunction()"/>
                            </div> --}}
                            <table class='table table-striped table-hover' id='table-gadaian-belum-serah'>
                                <thead class="thead-dark">
                                    <tr>
                                        <th>Bil <input type="checkbox" id="selectallcheck" onclick="checkallfunction()"/></th>
                                        <th>Nama</th>
                                        <th>No KP</th>
                                        <th>No Rujukan</th>
                                        <th>Pembiayaan (RM)</th>
                                        <th>Nilai Marhun (RM)</th>
                                        <th>Berat (g)</th>
                                        <th>Surat Wakil</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @php $count=1; @endphp
                                    @if (is_array($gadaian_belumserah) || is_object($gadaian_belumserah))
                                        @foreach($gadaian_belumserah as $index=>$gadaian)
                                            <tr>
                                                @php
                                                    $customer_info = Http::withOptions(['verify' => config('app.api_verify')])->get($api_url . '/api/customers/'. $gadaian['nokp'])->json();
                                                @endphp
                                                <td><input type="checkbox" id="checkgadai" name="checkgadai" autocomplete="off" data-nokp="{{ $gadaian['nokp'] }}" data-nama="{{ $customer_info['nama'] }}" data-norujukan="{{$gadaian['norujukan']}}" data-kodcaw="{{ $gadaian['kodcaw'] }}" data-marhun="{{$gadaian['nilaimarhun']}}"></input></td>
                                                <td>{{ $customer_info['nama'] }}</td>
                                                <td>{{ $gadaian['nokp'] }}</td>
                                                <td>
                                                    @php
                                                        $marhun = Http::withOptions(['verify' => config('app.api_verify')])->get($api_url . '/api/marhun/' . $gadaian['norujukan'] )->json();
                                                    @endphp
                                                    <a href="#" data-toggle="modal" data-marhun="{{ json_encode($marhun) }}" data-pinjaman="{{$gadaian['pinjaman']}}" data-norujukan="{{$gadaian['norujukan']}}" data-hargajualan="{{$gadaian['hargajualan']}}" data-kodcaw="{{ $gadaian['kodcaw'] }}" data-target="#belum_serah_modal"> {{$gadaian['norujukan']}}</a>
                                                </td>
                                                <td>{{ number_format($gadaian['pinjaman'],2) }}</td>
                                                <td>{{ number_format($gadaian['nilaimarhun'],2) }}</td>
                                                <td>{{ number_format($gadaian['berat'],2) }}</td>
                                                <td><a href="{{ route('penilai.print.suratwakil',$gadaian['norujukan']) }}" target='_blank' class="float-center btn btn-info mr-2"><i class='fas fa-print'></i></a></td>


                                            </tr>
                                            @php $count++; @endphp
                                        @endforeach
                                    @endif
                                </tbody>
                            </table>
                            <div class='row mt-md-3'>
                                <div class='col-md-12 d-flex justify-content-end form-group'>
                                    Jumlah Nilai Marhun Dipilih
                                    <div class='col-md-3'>
                                        <input type="text" name="marhunpilih" id="marhunpilih" readonly class='form-control'>
                                    </div>
                                    <form action="{{ route('marhun.serah') }}" method="post">
                                        @csrf
                                        <input type="text" name="norujukanpilih" id="norujukanpilih" hidden>
                                        <button type="submit" id="btn-serah" class='btn btn-primary' disabled>Serah Marhun</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                        <div class="tab-pane fade" id="rekod-gadaian" role="tabpanel" aria-labelledby="rekod-gadaian-tab">
                            <div class="row">
                                <div class="col-12">
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-2">Tarikh</div>
                                <div class="col-3"><input class="form-control" autocomplete="off" type="text" placeholder="Tarikh" onchange="fetchRekodGadaian()" name="tarikh_rekod" id="tarikh_rekod"></div>
                            </div>
                            <div class="row">
                                <div class="col-12">
                                    <table class='table table-striped table-hover' id='table-rekod-gadaian'>
                                        <thead class="thead-dark">
                                            <tr>
                                                <th>Bil</th>
                                                <th>Nama</th>
                                                <th>No KP</th>
                                                <th>No Rujukan</th>
                                                <th>Pembiayaan (RM)</th>
                                                <th>Nilai Marhun (RM)</th>
                                                <th>Berat (g)</th>
                                            </tr>
                                        </thead>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var api_url = "<?php echo $api_url ?>";
    var cawangan = "{{ Auth::user()->cawangan }}";
    var teller = "{{ Auth::user()->name }}";

    var total_marhun_pilih = 0;


    // function timedRefresh(timeoutPeriod) {
    //     setTimeout("console.log('refresh');fetchGadaianEverytime();",timeoutPeriod);
    //     fetchGadaianEverytime();
    //     console.log('refresh');
    // }

    // window.onload = timedRefresh(3000);
    //Pusher

    var pusher = new Pusher("{{ env('PUSHER_APP_KEY') }}", {
        cluster: 'ap1',
        encrypted: true
    });

    var channel = pusher.subscribe('gadai-notify');
    channel.bind('trigger-gadai', function(data) {

        if(cawangan == data.cawangan)
        {
            fetchGadaianEverytime();
        }

    });

    var table_gadaian_semasa = $('#table-gadaian-semasa').DataTable({
        "ordering": true
    });
    var table_gadaian_belum_serah = $('#table-gadaian-belum-serah').DataTable({
        "order": [],
        // "ordering": true,
        "columnDefs": [ { orderable: false, targets: [0] }]
    });

    var table_rekod_gadaian = $('#table-rekod-gadaian').DataTable({
        "ordering": true
    });

    $('#tarikh_rekod').datepicker({
        format: 'dd/mm/yyyy',
        endDate: new Date()
    });

    const formatter = new Intl.NumberFormat('en-US', {
        minimumFractionDigits: 2
    });

    $('#cetak_sag').on('click',function(){
        location.reload();
    });

    function checkallfunction(){
        let totalmarhun = 0;
        let checked = $('#selectallcheck').prop("checked");
        let marhunpilih = $('#marhunpilih').val();
        let norujukanpilih = $('#norujukanpilih').val();

        if(!table_gadaian_belum_serah.data().any())
        {
            $('#selectallcheck').prop('checked', false);
            return false;
        }

        if(checked) {
            // Iterate each checkbox
            $(':checkbox').each(function() {

                if($(this).attr("name") == 'checkgadai')
                {
                    let norujukan = $(this).data("norujukan");

                    if(norujukanpilih.indexOf(norujukan) === -1)
                    {
                        norujukanpilih += norujukan + ",";

                        console.log(norujukanpilih);

                        let marhun = Number($(this).data("marhun"));
                        totalmarhun += marhun;
                        // this.checked = true;
                        $(this).prop('checked', true);
                    }
                }
            });

            $('#norujukanpilih').val(norujukanpilih);
            total_marhun_pilih = totalmarhun;
            $("#btn-serah").prop('disabled', false);
            $('#marhunpilih').val(formatter.format(totalmarhun.toFixed(2)));
        } else {
            $(':checkbox').each(function() {
                if($(this).attr("name") == 'checkgadai')
                {
                    let norujukan = $(this).data("norujukan");

                    let sag;
                    sag = norujukan + ",";

                    norujukanpilih = norujukanpilih.replace(sag, "");

                    $(this).prop('checked', false);
                }
            });

            $('#norujukanpilih').val(norujukanpilih);
            $('#marhunpilih').val(0);
            total_marhun_pilih = 0;
            $("#btn-serah").prop('disabled', true);
        }
    }


    function fetchRekodGadaian(){
        var tarikh_rekod = $('#tarikh_rekod').val();
        if(tarikh_rekod == ''){
            var current = new Date();
            var current_date = current.getDate();
            var current_month = current.getMonth()+1;
            var current_year = current.getFullYear();
            var tarikh = current_year + '-' +current_month+'-'+current_date;
        }else{
            var split_date = tarikh_rekod.split('/');
            var tarikh = split_date[2] + '-' + split_date[1] + '-' + split_date[0];
        }
        table_rekod_gadaian.clear().draw();
        $.ajax({
            method:'get',
            url: api_url + '/api/gadai/list/rekod/old',
            data:{
                'kodcaw': "{{ $cawangan_info['kodcaw'] }}",
                'tarikh': tarikh
            },
            success:function(data){
                var count = 0;
                $.each(data,function(index,rekodgadaian){
                    $.ajax({
                        url: api_url + '/api/customers/' + rekodgadaian['nokp'],
                        method:'get',
                        success:function(rekodcustomer){
                            count++;
                            table_rekod_gadaian.row.add([
                                count,
                                rekodcustomer['nama'],
                                rekodgadaian['nokp'],
                                rekodgadaian['norujukan'],
                                rekodgadaian['pinjaman'],
                                rekodgadaian['nilaimarhun'],
                                rekodgadaian['berat']
                            ]).draw();
                        }
                    });
                });
            }
        });
    }

    function fetchGadaianEverytime(){

        table_gadaian_semasa.clear().draw();

        $.ajax({
            method:'get',
            url: api_url + '/api/gadaiansemasa/' + cawangan,
            success:function(data){
                var count = 0;
                $.each(data,function(index,gadaiansemasa){
                    $.ajax({
                        url: api_url + '/api/customers/' + gadaiansemasa['nokp'],
                        method:'get',
                        success:function(rekodcustomer){

                            $.ajax({
                                url: api_url + '/api/marhun/' + gadaiansemasa['norujukan'],
                                method:'get',
                                success:function(rekodmarhun){

                                    var urlroute = '{{ route("penilai.print.suratwakil", ":id") }}';
                                    urlroute = urlroute.replace(':id', gadaiansemasa["norujukan"]);

                                    count++;
                                    table_gadaian_semasa.row.add([
                                        count,
                                        rekodcustomer['nama'],
                                        gadaiansemasa['nokp'],
                                        '<a href="#" data-toggle="modal" data-marhun=' + JSON.stringify(rekodmarhun) + '  data-pinjaman=' + gadaiansemasa['pinjaman'] + ' data-norujukan=' + gadaiansemasa['norujukan'] + ' data-hargajualan=' + gadaiansemasa['hargajualan'] + ' data-kodcaw=' + gadaiansemasa['kodcaw'] + ' data-target="#marhunModal"> ' + gadaiansemasa['norujukan'] + '</a>',
                                        formatter.format(gadaiansemasa['pinjaman']),
                                        formatter.format(gadaiansemasa['nilaimarhun']),
                                        formatter.format(gadaiansemasa['berat']),
                                        "<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();
                                }
                            });
                        }
                    });
                });
            }
        });
    }
    //modal
    $('#marhunModal').on('show.bs.modal', function(event) {
        var button = $(event.relatedTarget); // button yg trigger
        var arraymarhun = button.data('marhun');
        var norujukan = button.data('norujukan');
        var kodcaw = button.data('kodcaw');
        var hargajualan = button.data('hargajualan');
        var pinjaman = button.data('pinjaman');
        // $('#pembelian_komuditi').attr('href','http://bsas-arrahn.test/pembelian/komuditi?norujukan='+norujukan);

        $('#norujukan_modal').val(norujukan);
        $('#pinjaman_modal').val(pinjaman);
        $('#tablemarhun').empty();
        var bil_count = 0;
        $.each(arraymarhun,function(index,marhun){
            $.each(marhun, function(index2,marhun_detail){

                var marhun_name;
                $.ajax({
                    method:'GET',
                    url: api_url + '/api/jemas/nama_marhun',
                    dataType: 'json',
                    data:{
                        marhun:marhun_detail['marhun']
                    },
                    success:function(marhun_ajax){
                        bil_count++;
                        var valBatuPermata = marhun_detail['berat_batu_permata'] != null ? marhun_detail['berat_batu_permata'] : '';
                        var valTagPermata = marhun_detail['tag_permata'] == 1 ? '(PMT) ' : '';
                        var notaDanTag = valTagPermata + marhun_detail['nota'];
                        $("#tablemarhun").append("<tr><td>" + bil_count + "</td><td>" + marhun_ajax['descpt'] +"</td><td>" + marhun_detail['berat'] +"</td><td>" + marhun_detail['karat'] +"</td><td>RM " + marhun_detail['n_marhun'].toLocaleString(undefined,{minimumFractionDigits:2}) +"</td><td>"+ notaDanTag + "</td><td>" + valBatuPermata +"</td></tr>");
                    }
                });
            });
        });

    });

    $('#belum_serah_modal').on('show.bs.modal', function(event) {
        var button = $(event.relatedTarget); // button yg trigger
        var arraymarhun = button.data('marhun');
        var norujukan = button.data('norujukan');
        var kodcaw = button.data('kodcaw');
        var hargajualan = button.data('hargajualan');
        var pinjaman = button.data('pinjaman');

        $('#norujukan_modal1').val(norujukan);
        $('#pinjaman_modal1').val(pinjaman);

        $('#belum_serah').empty();
        var bil_count = 0;
        $.each(arraymarhun,function(index,marhun){
            $.each(marhun, function(index2,marhun_detail){
                var marhun_name;
                $.ajax({
                    method:'GET',
                    url: api_url + '/api/jemas/nama_marhun',
                    dataType: 'json',
                    data:{
                        marhun:marhun_detail['marhun']
                    },
                    success:function(marhun_ajax){
                        bil_count++;
                        var valBatuPermata = marhun_detail['berat_batu_permata'] != null ? marhun_detail['berat_batu_permata'] : '';
                        var valTagPermata = marhun_detail['tag_permata'] == 1 ? '(PMT) ' : '';
                        var notaDanTag = valTagPermata + marhun_detail['nota'];
                        $("#belum_serah").append("<tr><td>" + bil_count + "</td><td>" + marhun_ajax['descpt'] +"</td><td>" + marhun_detail['berat'] +"</td><td>" + marhun_detail['karat'] +"</td><td>RM " + marhun_detail['n_marhun'].toLocaleString(undefined,{minimumFractionDigits:2}) +"</td><td>"+ notaDanTag + "</td><td>" + valBatuPermata +"</td></tr>");
                    }
                });
            });
        });
    });

    $(document).on('click', '#checkgadai', function(e) {
        if ($(this).is(':checked')) {
            var norujukan = $(this).data("norujukan");
            var kodcaw = $(this).data("kodcaw");
            var marhun = $(this).data("marhun");

            total_marhun_pilih += Number(marhun);

            $('#marhunpilih').val(formatter.format(total_marhun_pilih.toFixed(2)));

            $("#btn-serah").prop('disabled', false);

            var norujukanpilih = $('#norujukanpilih').val();

            norujukanpilih += norujukan + ",";

            $('#norujukanpilih').val(norujukanpilih);

            if($('input[name=checkgadai]:checked').length == $('input[name=checkgadai]').length) {
               $('#selectallcheck').prop("checked",true);
            }

        }else {
            var norujukan = $(this).data("norujukan");
            var kodcaw = $(this).data("kodcaw");
            var marhun = $(this).data("marhun");

            total_marhun_pilih -= Number(marhun);


            $('#marhunpilih').val(total_marhun_pilih.toFixed(2));

            var norujukanpilih = $('#norujukanpilih').val();

            var sag;
            sag = norujukan + ",";

            norujukanpilih = norujukanpilih.replace(sag, "");

            $('#norujukanpilih').val(norujukanpilih);

            if($('input[name=checkgadai]:unchecked').length == $('input[name=checkgadai]').length) {
               $('#selectallcheck').prop("checked",false);
            }
        }
        var legchecked = $('input[id^=checkgadai]:checked').length;
        if(legchecked == 0){
            $("#btn-serah").prop('disabled', true);
        }
    });

    $(document).on('click', '#cetak_sag_belum_serah', function(e) {

        let norujukan = $('#norujukan_modal1').val();
        let mohon = "Print SAG";

        const swalWithBootstrapButtons = Swal.mixin({
            customClass: {
                confirmButton: 'btn btn-success ml-1',
                cancelButton: 'btn btn-danger'
            },
            buttonsStyling: false
        });

        swalWithBootstrapButtons.fire({
            title: 'Dapatkan Pengesahan Khazanah',
            text: "Cetak SAG Semula!",
            icon: 'info',
            showCancelButton: true,
            confirmButtonText: 'Hantar',
            cancelButtonText: 'Batal',
            reverseButtons: true
        }).then((result) => {
            if(result.isConfirmed) {
                Swal.fire({
                    title: 'Tunggu Pengesahan Daripada Khazanah.',
                    icon: 'info',
                    width: 600,
                    padding: '6em',
                    background: '#fffff',
                    showCancelButton: false,
                    showConfirmButton: false,
                    allowOutsideClick: false,
                    allowEscapeKey: false,
                    allowEnterKey: false
                })


                $.ajax({
                    method:'post',
                    url: '{{ route("teller.createkelulusan") }}',
                    data: {
                        "_token" : "{{ csrf_token() }}",
                        "norujukan" : norujukan,
                        "mohon" : mohon
                    },
                    success:function(data){

                    },error: function(xhr, status, error) {
                        var err = eval("(" + xhr.responseText + ")");
                        alert(xhr.responseText);
                        console.log(err);
                    }
                });


                var channel = pusher.subscribe('notice-ubahhapus');
                channel.bind('my-ubahhapus', function(data) {
                    if(norujukan == data.norujukan && teller == data.teller && data.kelulusan == 'lulus')
                    {
                        Swal.fire({
                        icon: 'success',
                        title: 'Telah Disahkan'
                        }).then(function(){
                            $("#print_submit_belum_serah").submit();
                        });
                    }else{
                        Swal.fire({
                        icon: 'error',
                        title: 'Tidak Berjaya',
                        text: data.komen
                        });
                    }

                });

            }else if (result.dismiss === Swal.DismissReason.cancel) {
                swalWithBootstrapButtons.fire(
                    'Batal',
                    'Tidak Berjaya Mendapatkan Kelulusan Khazanah',
                    'error'
                )
            }

        });
    });

</script>
@endsection
