@extends('layouts.app')

@section('content')

@include('modal.pendahuluanserahan')
@include('modal.denominasimodalpendahuluanserahan')


<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="{{ route('home') }}">Home</a></li>
                          <li class="breadcrumb-item active" aria-current="page">Pendahuluan Serahan</li>
                        </ol>
                      </nav>

                <div class="card-body">

                    <div class="mt-3 mx-auto">
                               
                        <table class='table table-hover table-striped table-bordered' id='table-pendahuluanserahan' style="width: 100%;">
                            <thead class="thead-dark">
                                <tr>
                                    <th>Tarikh</th>
                                    <th>Description</th>
                                    <th>Pendahuluan (RM)</th>
                                    <th>Serahan (RM)</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($listgldetail as $gldetail)
                                  <tr>
                                  <td>{{ $gldetail['tarikh'] }}</td>
                                  <td>{{ $gldetail['descpt'] }}</td>
                                  <td>{{ ($gldetail['pendahuluan'] == 0 && ($gldetail['ktacct'] == '7000/102' || $gldetail['ktacct'] == '7000/106')) ? number_format($gldetail['amaun'],2) : number_format($gldetail['pendahuluan'],2) }}</td>
                                  <td>{{ ($gldetail['serahan'] == 0 && ($gldetail['dtacct'] == '1000/026' || $gldetail['dtacct'] == '1000/020' || $gldetail['dtacct'] == '1000/090')) ? number_format($gldetail['amaun'],2) : number_format($gldetail['serahan'],2) }}</td>
                                  </tr>
                                @endforeach
                            </tbody>
                        </table>

                    </div>


                    <button class="btn btn-primary mt-4" data-toggle="modal" data-target="#pendahuluanserahanModal">Daftar</button>

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

<script src="{{ asset('js/main.js') }}"></script>

    <script>

        var tablependahuluanserahan = $('#table-pendahuluanserahan').DataTable({
            "scrollX": true,
            "order": [[ 0, "desc" ]]
        });

        let api = "{{ config('api.url') }}";
        let kodcaw = "{{ Auth::user()->cawangan }}";
        let teller = "{{ Auth::user()->name }}";


        $(document).ready(function(){
        
            let date = new Date();
            let year = date.getFullYear();
            let month = 1 + date.getMonth();
            let day = date.getDate();

            let tarikh = day + '/' + month + '/' + year;
            $('#tarikh').val(tarikh);

        });

        $("input[name='radwang']").click(function() {
            let jenis = $('#radiopendahuluanserahan:checked').val();

            if(jenis == 'pendahuluan')
            {
                $('#keterangan').val('Pendahuluan Daripada HQ');
                $('#dtacct').val('1000/010');
                $('#ktacct').val('7000/102');
                $('input[name="denominasi"]').attr('style','display: none');
                $('.denominasi').attr('style','display: none');
                

            }else if(jenis == 'serahan')
            {
                $('#keterangan').val('Serahan Kepada HQ');
                $('#dtacct').val('1000/010');
                $('#ktacct').val('1000/020');
                $('input[name="denominasi"]').attr('style','display: block');
                $('.denominasi').attr('style','display: block');

            }
            else
            {
                $('#keterangan').val('Tiada Maklumat');
                $('#dtacct').val(0);
                $('#ktacct').val(0);
            }

        });

        function validateformat(evt)
        {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
                return false;

            return true;
        }

        $('#pendahuluanserahanModal').on('shown.bs.modal', function (e) {

            $('#bundle1').val('');
            $('#totalb1').val(0.00);
            $('#bundle5').val('');
            $('#totalb5').val(0.00);
            $('#bundle10').val('');
            $('#totalb10').val(0.00);
            $('#bundle20').val('');
            $('#totalb20').val(0.00);
            $('#bundle50').val('');
            $('#totalb50').val(0.00);
            $('#bundle100').val('');
            $('#totalb100').val(0.00);
            $('#amaunkiraan').val('');
            $('#dtacct').val('');
            $('#ktacct').val('');
            $('#keterangan').val('');
            $('#amaun').val('');
            $('input[name="radwang"]').prop('checked', false);
        
        });

        function functerima()
        {
            let amaun = $('#amaun').val();
            let keterangan = $('#keterangan').val();
            let jenis = $('#radiopendahuluanserahan:checked').val();
            let dtacct = $('#dtacct').val();
            let ktacct = $('#ktacct').val();

            $('#amaundiminta').val(amaun);

            $('#denominasiHQModal').modal('show');
            $('#pendahuluanserahanModal').modal('hide');
        }

        function funcbatal()
        {
            $('#denominasiHQModal').modal('hide');
            $('#pendahuluanserahanModal').modal('show');

            $('#bundle1').val('');
            $('#totalb1').val(0.00);
            $('#bundle5').val('');
            $('#totalb5').val(0.00);
            $('#bundle10').val('');
            $('#totalb10').val(0.00);
            $('#bundle20').val('');
            $('#totalb20').val(0.00);
            $('#bundle50').val('');
            $('#totalb50').val(0.00);
            $('#bundle100').val('');
            $('#totalb100').val(0.00);
            $('#amaunkiraan').val('');
        }

        function terimapost()
        {
            let amaun = $('#amaundiminta').val();
            let keterangan = $('#keterangan').val();
            let jenis = $('#radiopendahuluanserahan:checked').val();
            let dtacct = $('#dtacct').val();
            let ktacct = $('#ktacct').val();

            //denominasi bundle
            let bundle1 = $('#bundle1').val();let bundle5 = $('#bundle5').val();let bundle10 = $('#bundle10').val();
            let bundle20 = $('#bundle20').val();let bundle50 = $('#bundle50').val();let bundle100 = $('#bundle100').val();

            //denominasi keping
            let sen1 = $('#sen1').val();let sen5 = $('#sen5').val();let sen10 = $('#sen10').val();let sen20 = $('#sen20').val();let sen50 = $('#sen50').val();
            let ringgit1 = $('#ringgit1').val();let ringgit5 = $('#ringgit5').val();let ringgit10 = $('#ringgit10').val();let ringgit20 = $('#ringgit20').val();let ringgit50 = $('#ringgit50').val();
            let ringgit100 = $('#ringgit100').val();

            $.ajax({
                method: 'post',
                url: '{{ route("khazanah.pendahuluanserahanHQ") }}',
                data: {
                    "_token": "{{ csrf_token() }}",
                    'amaun' : amaun,
                    'jenisgldetail' : jenis,
                    'keterangan' : keterangan,
                    'kodcaw' : kodcaw,
                    'teller' : teller,
                    'dtacct' : dtacct,
                    'ktacct' : ktacct,
                    'ambilansen1' : sen1,
                    'ambilansen5' : sen5,
                    'ambilansen10' : sen10,
                    'ambilansen20' : sen20,
                    'ambilansen50' : sen50,
                    'ambilanring1' : ringgit1,
                    'ambilanring5' : ringgit5,
                    'ambilanring10' : ringgit10,
                    'ambilanring20' : ringgit20,
                    'ambilanring50' : ringgit50,
                    'ambilanring100' : ringgit100
                    // 'bundle1' : bundle1,
                    // 'bundle5' : bundle5,
                    // 'bundle10' : bundle10,
                    // 'bundle20' : bundle20,
                    // 'bundle50' : bundle50,
                    // 'bundle100' : bundle100
                },
                success:function(data){
                    if(data == 'LULUS'){

                        Swal.fire({
                            icon: 'success',
                            title: 'Transaksi Berjaya'
                        }).then(function(){

                            $('#denominasiHQModal').modal('hide');
                            $('#pendahuluanserahanModal').modal('hide');

                        });

                    }else if(data == 'GAGAL'){
                        Swal.fire({
                            icon: 'error',
                            title: 'Transaksi Gagal'
                        }).then(function(){

                            $('#denominasiHQModal').modal('hide');
                            $('#pendahuluanserahanModal').modal('hide');
                           
                        });
                    }
                }
            });
        }

    </script>
@endsection
