@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center" style="margin-top:60px;">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header bg-secondary text-center"><span style="font-weight:500;">{{ __('Paparan Utama') }}</span></div>

                <div class="card-body text-center">
                    <a class="btn btn-info btn-lg" href="#" onclick="pelangganclick()">PELANGGAN</a>
                    <a class="btn btn-info btn-lg" href="{{ url('/harga_emas') }}">HARGA EMAS</a>
                    <a class="btn btn-info btn-lg" href="{{ url('/aliran_tunai') }}">ALIRAN TUNAI</a>
                    {{-- <a class="btn btn-info btn-lg" href="#">TETAPAN</a> --}}
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var api_url = "<?php echo $api_url ?>";
    let teller = "{{ Auth::user()->name }}";
    let kodcaw = "{{ Auth::user()->cawangan }}";

    function pelangganclick()
    {
        // $getTunai2=Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url').'/api/GetCurrentTunai/'.$auth_user['cawangan'],['kodlaluan' => $kodlaluan])->json();

        $.ajax({
            method:'get',
            url: api_url + '/api/GetCurrentTunai/' + kodcaw,
            data: {
                "kodlaluan" : teller
            },
            success:function(data){



                if(jQuery.isEmptyObject(data))
                {
                    Swal.fire({
                    icon: 'error',
                    title: 'Amaran!',
                    text: 'Anda perlulah menetapkan aliran tunai terlebih dahulu sebelum memasuki pelanggan!',
                    });

                }
                else
                {
                    window.location.replace("{{ url('/pelanggan') }}");
                }
            },
            error: function(xhr, status, error) {
                var err = eval("(" + xhr.responseText + ")");
                alert(xhr.responseText);
            }
        });
    }
</script>
@endsection
