@extends('layouts.app')

@section('content')


<div class="container">

<div class="row justify-content-center">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">{{ __('Serahan Wang Peti Besi') }}</div>

                <div class="card-body text-center">
                  
                <form id="form-pendahuluan" action="{{ route('khazanah.KemaskiniSerahan') }}" method="post">
@csrf
 <div class="row mb-2">
  <div class="col-2">Tarikh</div>
  <div class="col-3"><input type="text" class="form-control"  id="tarikh" readonly  name="tarikh" value="{{ $currdate=date('Y-m-d')}}"    /></div>
  <div class="col-2">Teller ID </div>
  <div class="col-3"><input type="text" class="form-control" name="teller" id="teller" value="{{ $array_reqteller['kodlaluan'] }}" readonly/></div>
</div>

<input type="hidden" id="no" name="no" value="{{ $array_reqteller['no'] }}"/>

 <div class="row">
  <div class="col-2">Amaun (RM)</div>
  <div class="col-3"><input type="text" class="form-control" data-amaun="{{ $array_reqteller['serahan'] }}" value="{{ $array_reqteller['serahan'] }}" readonly name="amt" id="amt"/></div>
  <div class="col-2"> Nota</div>
  <div class="col-3"><input type="text" class="form-control" readonly name="nota" id="nota" /> </div>
</div>
<br>
<div class="row">
  <div class="col-2"></div>
  <div class="col-3"> </div>
  <div class="col-2"> </div>
  <div class="col-6">
    <button type="button"  data-toggle="modal" data-target="#marhunModal" class="btn btn-info">Panduan Format Bundle</button>
    <input type="button" id="terima_transaksi" onclick="triggersubmit();" class="btn btn-success" value="Lulus"/>
    <a onclick="triggerbatal();" class="btn btn-danger">Batal</a>
  </div>
</div>
<br>

<ul class="nav nav-tabs" id="myTab" role="tablist">
  {{-- <li class="nav-item">
    <a class="nav-link" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Bundle</a>
  </li> --}}
  <li class="nav-item">
    <a class="nav-link active" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Keping</a>
  </li>
</ul>

<div class="tab-content" id="myTabContent">
  <div class="tab-pane fade" id="home" role="tabpanel" aria-labelledby="home-tab">

    <h4>Wang Bundle Dari Peti Besi</h4>
    <table class="table table-bordered"> 
          <tr>
                <th></th>
                <th>Peti Besi</th>
                <th>Teller</th>
                <th>Total</th>
                <th></th>
                <th>Peti Besi</th>
                <th>Teller</th>
                <th>Total (RM)</th>
          </tr>
          <tr>
            <td>RM1</td>
            <td><input type="text" name="rekodb1" class="form-control" id="rekodb1" value="{{ $denominasi['0']['bd1'] }}" readonly/></td> 
            <td><input type="text" name="ambilanb1" class="form-control" id="bundle1" value="{{ $array_reqteller['bd1'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
            <td><input type="text" name="totalb1" class="form-control" id="totalb1" value="{{ $denominasi['0']['b1'] }}" readonly/> </td>
            <td> RM20</td>
            <td><input type="text" name="rekodb20" class="form-control" id="rekodb20" value="{{ $denominasi['0']['bd20'] }}" readonly/> </td>
            <td><input type="text" name="ambilanb20" class="form-control" id="bundle20" value="{{ $array_reqteller['bd20'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
            <td><input type="text" name="totalb20" class="form-control" id="totalb20" value="{{ $denominasi['0']['b20'] }}" readonly/> </td>
        </tr>
        <tr>
            <td>RM5</td>
            <td><input type="text" name="rekodb5" class="form-control" id="rekodb5" value="{{ $denominasi['0']['bd5'] }}" readonly/> </td>
            <td><input type="text" name="ambilanb5" class="form-control" id="bundle5" value="{{ $array_reqteller['bd5'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
            <td><input type="text" name="totalb5" class="form-control" id="totalb5" value="{{ $denominasi['0']['b5'] }}" readonly/> </td>
            <td>RM50</td> 
            <td><input type="text" name="rekodb50" class="form-control" id="rekodb50" value="{{ $denominasi['0']['bd50'] }}" readonly/> </td>
            <td><input type="text" name="ambilanb50" class="form-control" id="bundle50" value="{{ $array_reqteller['bd50'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
            <td><input type="text" name="totalb50" class="form-control" id="totalb50" value="{{ $denominasi['0']['b50'] }} " readonly/> </td>
        </tr>
        <tr>
            <td>RM10</td>
            <td><input type="text" name="rekodb10" class="form-control" id="rekodb10" value=" {{ $denominasi['0']['bd10'] }}" readonly/> </td>
            <td><input type="text" name="ambilanb10" class="form-control" id="bundle10" value="{{ $array_reqteller['bd10'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
            <td><input type="text" name="totalb10" class="form-control" id="totalb10" value=" {{ $denominasi['0']['b10'] }}" readonly/> </td>
            <td>RM100 </td> <td>
            <input type="text" name="rekodb100" class="form-control" id="rekodb100" value="{{ $denominasi['0']['bd100'] }}" readonly/> </td>
            <td><input type="text" name="ambilanb100" class="form-control" id="bundle100" value="{{ $array_reqteller['bd100'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
            <td><input type="text" name="totalb100" class="form-control" id="totalb100" value=" {{ $denominasi['0']['b100'] }}" readonly/> </td>
        </tr>
          </table>
          <br>
    
          <table class="table table-bordered">
          <tr>
            <th colspan="6">  Total Wang Tunai Bundle (RM)   </th>
            <th> <input type="text" class="form-control" name="totalbundle" id="totalbundle" value="{{ $denominasi['0']['jumlahbundle'] }}" readonly/> </th>
    
          </tr>
    
          </table>
          <br>


  </div>
  <div class="tab-pane fade show active" id="profile" role="tabpanel" aria-labelledby="profile-tab">

    <h4>Wang Keping Dari Peti Besi</h4>
    <table class="table table-bordered"> 
      <tr>
            <th></th>
            <th>Peti Besi</th>
            <th>Teller</th>
            <th>Total</th>
            <th></th>
            <th>Peti Besi</th>
            <th>Teller</th>
            <th>Total (RM)</th>
      </tr>
      <tr>
        
        <td>RM0.01</td>
        <td><input type="text" name="rekodsen1" class="form-control" value="{{ $denominasi['0']['txtsen1'] }}" readonly/></td> 
        <td><input type="text" name="ambilansen1" class="form-control" id="sen1" value="{{ $array_reqteller['txtsen1'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
        <td><input type="text" name="totalsen1" class="form-control" value="{{ number_format($denominasi['0']['k01'],2) }}" readonly/> </td>
        <td>RM1</td>
        <td><input type="text" name="rekodring1" class="form-control" value="{{ $denominasi['0']['txtring1'] }}" readonly/></td> 
        <td><input type="text" name="ambilanring1" class="form-control" id="ringgit1" value="{{ $array_reqteller['txtring1'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
        <td><input type="text" name="totalring1" class="form-control" value="{{ number_format($denominasi['0']['k1'],2) }}" readonly/> </td>
    </tr>
    <tr>
        <td>RM0.05</td>
        <td><input type="text" name="rekodsen5" class="form-control" value=" {{ $denominasi['0']['txtsen5'] }}" readonly/> </td>
        <td><input type="text" name="ambilansen5" class="form-control" id="sen5" value="{{ $array_reqteller['txtsen5'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
        <td><input type="text" name="totalsen5" class="form-control" value=" {{ number_format($denominasi['0']['k05'],2) }}" readonly/> </td>
        <td>RM5</td>
        <td><input type="text" name="rekodring5" class="form-control" value=" {{ $denominasi['0']['txtring5'] }}" readonly/> </td>
        <td><input type="text" name="ambilanring5" class="form-control" id="ringgit5" value="{{ $array_reqteller['txtring5'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
        <td><input type="text" name="totalring5" class="form-control" value=" {{ number_format($denominasi['0']['k5'],2) }}" readonly/> </td>
    </tr>
    <tr>
        <td>RM0.10</td>
        <td><input type="text" name="rekodsen10" class="form-control"  value=" {{ $denominasi['0']['txtsen10'] }}" readonly/> </td>
        <td><input type="text" name="ambilansen10" class="form-control" id="sen10" value="{{ $array_reqteller['txtsen10'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
        <td><input type="text" name="totalsen10" class="form-control"  value=" {{ number_format($denominasi['0']['k010'],2) }}" readonly/> </td>
        <td>RM10</td>
        <td><input type="text" name="rekodring10" class="form-control"  value=" {{ $denominasi['0']['txtring10'] }}" readonly/> </td>
        <td><input type="text" name="ambilanring10" class="form-control" id="ringgit10" value="{{ $array_reqteller['txtring10'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
        <td><input type="text" name="totalring10" class="form-control"  value=" {{ number_format($denominasi['0']['k10'],2) }}" readonly/> </td>
    </tr>
    <tr>
      <td>RM0.20</td>
      <td><input type="text" name="rekodsen20" class="form-control"  value=" {{ $denominasi['0']['txtsen20'] }}" readonly/> </td>
      <td><input type="text" name="ambilansen20" class="form-control" id="sen20" value="{{ $array_reqteller['txtsen20'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
      <td><input type="text" name="totalsen20" class="form-control"  value=" {{ number_format($denominasi['0']['k020'],2) }}" readonly/> </td>
      <td> RM20</td>
      <td><input type="text" name="rekodring20" class="form-control"  value=" {{ $denominasi['0']['txtring20'] }}" readonly/> </td>
      <td><input type="text" name="ambilanring20" class="form-control" id="ringgit20" value="{{ $array_reqteller['txtring20'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
      <td><input type="text" name="totalring20" class="form-control"  value=" {{ number_format($denominasi['0']['k20'],2) }}" readonly/> </td>
  </tr>
  <tr>
    <td>RM0.50</td>
    <td><input type="text" name="rekodsen50" class="form-control"  value=" {{ $denominasi['0']['txtsen50'] }}" readonly/> </td>
    <td><input type="text" name="ambilansen50" class="form-control" id="sen50" value="{{ $array_reqteller['txtsen50'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
    <td><input type="text" name="totalsen50" class="form-control"  value=" {{ number_format($denominasi['0']['k050'],2) }}" readonly/> </td>
    <td>RM50</td> 
    <td><input type="text" name="rekodring50" class="form-control"  value=" {{ $denominasi['0']['txtring50'] }}" readonly/> </td>
    <td><input type="text" name="ambilanring50" class="form-control" id="ringgit50" value="{{ $array_reqteller['txtring50'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
    <td><input type="text" name="totalring50" class="form-control"  value=" {{ number_format($denominasi['0']['k50'],2) }}" readonly/> </td>
</tr>
<tr>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td>RM100 </td> 
  <td><input type="text" name="rekodring100" class="form-control" value=" {{ $denominasi['0']['txtring100'] }}" readonly/> </td>
  <td><input type="text" name="ambilanring100" class="form-control" id="ringgit100" data-jenis="serahan"value="{{ $array_reqteller['txtring100'] }}" readonly onkeyup="totalkeyserahan(this)"/> </td>
  <td><input type="text" name="totalring100" class="form-control" value=" {{ number_format($denominasi['0']['k100'],2) }}"  readonly/> </td>
</tr>
      </table>
      <br>

      <table class="table table-bordered">
      <tr>
        <th colspan="6">  Total Wang Tunai Keping (RM)   </th>
        <th> <input type="text" class="form-control"   value=" {{ number_format($denominasi['0']['jumlahkeping'],2) }}" readonly/> </th>

      </tr>

      </table>
      <br>

  </div>
</div>

        <table class="table table-bordered">
          <tr>
            <th>  Total Keseluruhan (RM)   </th>
            <th> <input type="text" class="form-control"   value=" {{ number_format($denominasi['0']['txtjumlah'],2) }}" readonly/> </th>
          </tr>
          <tr>
            <th>  Baki Akhir Sistem (RM)   </th>
            <th> <input type="text" class="form-control" value="@php $bakiakhirsistem = $denominasi['0']['txtjumlah'] - $denominasi['0']['lebihan']; echo number_format($bakiakhirsistem,2); @endphp" readonly/> </th>
        </tr>
        <tr>
            <th>  Lebihan/Kekurangan (RM)   </th>
            <th> <input type="text" class="form-control"   value=" {{ number_format($denominasi['0']['lebihan'],2) }}" readonly/> </th>
          </tr>
    
          </table>

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





<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>Guide Format Bundle:</h4>
                <div class="row">
                    
                    <div class="col-6">
                        
                        <h4>Wang Kertas</h4> 
                        <table id="kertas" class="table table-striped table-bordered text-center" style="width:100%">
                            <thead>
                                <tr>
                                   <td> RM 1 </td><td> 100 </td>
                                   <td> RM 20</td><td> 1000 </td>
                                </tr>
                                <tr>
                                    <td> RM 5 </td><td> 500 </td>
                                    <td> RM 50</td><td> 5000 </td>
                                </tr>

                                <tr>
                                    <td> RM 10 </td><td> 1000 </td>
                                    <td> RM 100</td><td> 5000 </td>
                                </tr>
                            </thead>
                        </table>
                    
                        
                    </div>

                    <div class="col-6">
                        
                        <h4>Wang Syilling</h4> 
                        <table id="syilling" class="table table-striped table-bordered text-center" style="width:100%">
                            <thead>
                                <tr>
                                   <td> RM 0.10 </td><td> 10 </td>
                                   <td> RM 0.50 </td><td> 10 </td>
                                </tr>
                                <tr>
                                    <td> RM 0.20 </td><td> 10 </td>
                                    <td></td><td></td>
                                </tr>
                            </thead>
                        </table>
                    
                        
                    </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>

<script>

  let api = "{{ config('api.url') }}";

  $(document).ready(function() {

    let teller = $('#teller').val();
    let kodcaw = "{{ Auth::user()->cawangan }}";
    let notasebenar = '';
        
    $.ajax({
      method: 'get',
      url: api + '/api/getAddTunaiLatest/' + kodcaw,
      async:false,
      data: { 
              'jenisnota' : 'serahan',
              'kodlaluan' : teller
            },
      success:function(data){

        if(data.nota == null)
        {
          notasebenar = "S1";
          $('#nota').val(notasebenar);
        }
        else{
          let nota = data.nota.substring(1);

          notasebenar = "S" + (Number(nota)+1);
          $('#nota').val(notasebenar);
        }
      }

    });


  });


  function triggersubmit()
  {
    Swal.fire({
      title: 'Memuatkan...',
      allowEscapeKey : false,
      allowOutsideClick: false,
      didOpen: function () {
          Swal.showLoading();
      }
    });
    $("#terima_transaksi").prop('disabled', true);
    $('#form-pendahuluan').trigger('submit');
  }

  
  function triggerbatal()
  {
    let nom = $('#no').val();
    let teller = $('#teller').val();
    let kodcaw = "{{ Auth::user()->cawangan }}";

    $.ajax({
      method: 'get',
      url: "{{ route('request.pembatalan') }}",
      data:{
          'kodcaw' : kodcaw,
          'no' : nom,
          'kodlaluan' : teller
      },
      beforeSend: function(){
        Swal.fire({
          title: 'Memuatkan...',
          allowEscapeKey : false,
          allowOutsideClick: false,
          didOpen: function () {
              Swal.showLoading();
          }
        });
      },
      success:function(data){
        window.location.href = "{{ route('khazanah.serahan') }}";
      }
    });
  }

</script>

<script type="text/javascript" src="{{ asset('js/main.js') }}"></script>
@endsection
