<?php 
  include '_header.php';
  include '_nav.php';
  include '_sidebar.php'; 
?>
<?php  
  if ( $levelLogin === "driver") {
    echo "
      <script>
        document.location.href = 'bo';
      </script>
    ";
  }
    
?>
<?php  
// ambil data di URL
$id = abs((int)base64_decode($_GET['id']));


// query data mahasiswa berdasarkan id
$cashdrawer = query("SELECT * FROM cashdrawer WHERE cashdrawer_id = $id ")[0];

// cek apakah tombol submit sudah ditekan atau belum
if( isset($_POST["submit"]) ){
  // var_dump($_POST);

  // cek apakah data berhasil di tambahkan atau tidak
  if( editcashdrawer($_POST) > 0 ) {
    echo "
      <script>
        document.location.href = 'cashdrawer-data';
      </script>
    ";
  } elseif( editcashdrawer($_POST) == null ) {
    echo "
      <script>
        alert('Anda Belum melakukan perubahan data !!');
      </script>
    ";
  } else {
    echo "
      <script>
        alert('data gagal ditambahkan');
      </script>
    ";
  }
  
}
?>


  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Edit Data Cashdrawer</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="bo">Home</a></li>
              <li class="breadcrumb-item active">Data Cashdrawer</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <!-- left column -->
          <div class="col-md-12">
            <!-- general form elements -->
            <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Cashdrawer</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <form role="form" action="" method="post">
                <div class="card-body">
                  <div class="row">
                    <div class="col-md-6 col-lg-6">
                        <input type="hidden" name="cashdrawer_id" value="<?= $cashdrawer['cashdrawer_id']; ?>">
                        <input type="hidden" name="cashdrawer_user_edit" value="<?= $_SESSION['user_id']; ?>">
                        <div class="form-group">
                          <label for="cashdrawer_date">Tanggal Transaksi</label>
                          <input type="teks" name="cashdrawer_date" class="form-control" id="cashdrawer_date" value="<?= tanggal_indo($cashdrawer['cashdrawer_date']); ?>" readonly>
                        </div>
                        <div class="form-group">
                          <label for="cashdrawer_create">User Create</label>
                          <?php  
                            $cashdrawer_create = $cashdrawer['cashdrawer_create'];
                            $userId = mysqli_query($conn, "SELECT user_nama FROM user WHERE user_id = $cashdrawer_create ");
                            $userId = mysqli_fetch_array($userId);
                            $userId = $userId['user_nama'];
                          ?>
                          <input type="text" name="cashdrawer_create" class="form-control" id="cashdrawer_create" placeholder="Input cashdrawer" value="<?= $userId; ?>" readonly>
                        </div>
                        <div class="form-group">
                          <label for="cashdrawer_name">cashdrawer</label>
                          <input type="text" name="cashdrawer_name" class="form-control" id="cashdrawer_name" placeholder="Input cashdrawer" value="<?= $cashdrawer['cashdrawer_name']; ?>" readonly>
                        </div>
                        <div class="form-group">
                          <label for="cashdrawer_penerima">Penerima</label>
                          <input type="text" name="cashdrawer_penerima" class="form-control" id="cashdrawer_penerima" placeholder="Input Penerima" value="<?= $cashdrawer['cashdrawer_penerima']; ?>" readonly>
                        </div>
                        
                    </div>

                    <div class="col-md-6 col-lg-6">
                      <div class="form-group">
                          <label for="cashdrawer_desc">Keterangan</label>
                          <textarea name="cashdrawer_desc" id="cashdrawer_desc" class="form-control" rows="3" readonly="readonly"><?= $cashdrawer['cashdrawer_desc']; ?></textarea>
                        </div>
                        <div class="form-group">
                          <label for="cashdrawer_total_dibayar">Total Dibayar</label>
                          <input type="number" name="cashdrawer_total_dibayar" class="form-control" id="cashdrawer_total_dibayar" value="<?= $cashdrawer['cashdrawer_total_dibayar']; ?>"  readonly>
                        </div>

                        <div class="form-group">
                          <label for="cashdrawer_metode">Metode Pembayaran</label>
                          <?php 
                              $cashdrawer_metode = $cashdrawer['cashdrawer_metode']; 

                          ?>
                          <?php if ( $cashdrawer_metode == 1 ) : ?>
                            <?php $textMetode = "Transfer"; ?>

                          <?php elseif ( $cashdrawer_metode == 2 ) : ?>
                            <?php $textMetode = "Debit"; ?>

                          <?php elseif ( $cashdrawer_metode == 3 ) : ?>
                            <?php $textMetode = "QRIS"; ?>

                          <?php else : ?>
                            <?php $textMetode = "Cash"; ?>
                          <?php endif; ?>
                         </select>
                       <input type="text" name="cashdrawer_penerima" class="form-control" id="cashdrawer_penerima" placeholder="Input Penerima" value="<?= $textMetode; ?>" readonly>
                    </div>
                  </div>
                </div>
                <div class="row no-print">
                  <div class="col-12">
                    <a href="#!" class="btn btn-success float-right" onclick="self.close()" style="margin-right: 5px;"> Kembali</a>
                  </div>
                </div>
                <!-- /.card-body -->
              </form>
            </div>
          </div>
        </div>
      </div>
    </section>


  </div>


<?php include '_footer.php'; ?>