<?php 
  include '_header.php';
  include '_nav.php';
  include '_sidebar.php'; 
?>
<?php  
  if ( $levelLogin === "kasir" && $levelLogin === "kurir" ) {
    echo "
      <script>
        document.location.href = 'bo';
      </script>
    ";
  }  
?>
<?php  

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

  // $hilangbarang_kode_count_id = base64_encode($_POST['hilangbarang_id']);
  // $hilangbarang_option_sn  = $_POST['hilangbarang_option_sn'];

  // if ( $hilangbarang_option_sn > 0 ) {
  //   $url = "hilangbarang-sn?no=".$hilangbarang_kode_count_id;
  // } else {
  //   $url = "hilangbarang";
  // }

  // cek apakah data berhasil di tambahkan atau tidak
  if( tambahhilangbarang($_POST) > 0 ) {
    echo "
      <script>
        document.location.href = 'hilangbarang';
      </script>
    ";
  } else {
    echo "
      <script>
        alert('data gagal ditambahkan');
      </script>
    ";
  }
  
}
?>
  
  <?php 
      $hilangbarang = mysqli_query($conn,"select * from hilangbarang where hilangbarang_cabang = ".$sessionCabang." ");
      $jmlhilangbarang = mysqli_num_rows($hilangbarang); 

      if ( $jmlhilangbarang < 1 ) {
          $hilangbarangCount = 1;
      } else {
          $hilangbarangCount = query("SELECT * FROM hilangbarang ORDER BY hilangbarang_id DESC LIMIT 1")[0];
          $hilangbarangCount = $hilangbarangCount['hilangbarang_kode_count'];
          $hilangbarangCount += 1;
          
      }
  ?>

  <!-- 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>Tambah Data Hilang Barang</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 Hilang Barang</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">Data Hilang Barang</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">
                      <div class="form-group">
                          <label for="hilangbarang_kode">Barcode / Kode Hilang Barang</label>
                          <input type="text" name="hilangbarang_kode" class="form-control" id="hilangbarang_kode" placeholder="Contoh: 878868889080" required autofocus="">
                          <small style="color: red">
                            <b>
                              Barcode / Kode Hilang Barang Sifatnya Sekali Input & Pastikan Tidak Terjadi Kesalahan
                            </b>
                          </small>
                      </div>
                    </div>
                    <div class="col-md-6 col-lg-6"></div>
                    <div class="col-md-6 col-lg-6">
                      <input type="hidden" name="hilangbarang_cabang" value="<?= $sessionCabang; ?>">
                      <input type="hidden" name="hilangbarang_kode_count" value="<?= $hilangbarangCount; ?>">
                        <div class="form-group">
                            <label for="hilangbarang_nama">Nama Hilang Barang</label>
                            <input type="text" name="hilangbarang_nama" class="form-control" id="hilangbarang_nama" placeholder="Input Nama hilangbarang" required>
                        </div>
                        <div class="form-group">
                            <label for="hilangbarang_deskripsi">Deskripsi</label>
                            <textarea name="hilangbarang_deskripsi" id="hilangbarang_deskripsi" class="form-control" rows="5" required="required" placeholder="Deskripsi Lengkap"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="hilangbarang_harga">Harga Jual</label>
                            <input type="number" name="hilangbarang_harga" class="form-control" id="hilangbarang_harga" placeholder="Input Harga hilangbarang" onkeypress="return hanyaAngka(event)" >
                        </div>
                        <div class="form-group ">
                            <label for="kategori_id" class="">Kategori</label>
                            <div class="">
                              <?php $data = query("SELECT * FROM kategori WHERE kategori_cabang = $sessionCabang ORDER BY kategori_id DESC"); ?>
                              <select name="kategori_id" required="" class="form-control select2bs4">
                                  <option value="">--Pilih Kategori--</option>
                                  <?php foreach ( $data as $row ) : ?>
                                    <?php if ( $row['kategori_status'] === '1' ) { ?>
                                      <option value="<?= $row['kategori_id']; ?>">
                                        <?= $row['kategori_nama']; ?> 
                                      </option>
                                    <?php } ?>
                                  <?php endforeach; ?>
                              </select>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6 col-lg-6">

                        <div class="form-group ">
                              <label for="satuan_id">Satuan</label>
                              <div class="">
                                <?php $data2 = query("SELECT * FROM satuan WHERE satuan_cabang = $sessionCabang ORDER BY satuan_id DESC"); ?>
                                  <select name="satuan_id" required="" class="form-control ">
                                    <option value="">-- Satuan --</option>
                                    <?php foreach ( $data2 as $row ) : ?>
                                      <?php if ( $row['satuan_status'] === '1' ) { ?>
                                        <option value="<?= $row['satuan_id']; ?>">
                                          <?= $row['satuan_nama']; ?>
                                        </option>
                                      <?php } ?>
                                    <?php endforeach; ?>
                                  </select>
                              </div>
                        </div>

                        <div class="form-group ">
                            <label for="hilangbarang_option_sn">Non-SN or SN</label>
                            <div class="">
                                <select name="hilangbarang_option_sn" required="" id="hilangbarang_option_sn" class="form-control stock-pilihan">
                                    <option value="">-- Pilih --</option>
                                        <option value="0">Non-SN</option>
                                        <option value="1">SN</option>
                                  </select>
                              </div>
                              <small style="color: red">
                                  <b>
                                      SN (Serial Number) Hanya dikhususkan Untuk Produk yang memiliki No. SN Seperti Handphone & Laptop 
                                  </b>
                              </small>
                        </div>
                      
                        <div class="form-group">
                          <label for="hilangbarang_stock">Stock</label>
                          <input type="number" name="hilangbarang_stock" class="form-control" id="hilangbarang_stock" placeholder="Input Jumlah Stock" value="0" required>
                        </div>

                        <div class="form-group ">
                            <label for="hilangbarang_status">Status</label>
                            <div class="">
                                <select name="hilangbarang_status" required="" id="hilangbarang_status" class="form-control stock-pilihan">
                                    <option value="">-- Pilih --</option>
                                        <option value="1">Dijual</option>
                                        <option value="2">Khusus Servis</option>
                                        <option value="3">Dijual & Untuk Sevis</option>
                                        <option value="0">Tidak Dijual</option>
                                  </select>
                              </div>
                        </div>
                    </div>
                  </div>
                </div>
                <!-- /.card-body -->

                <div class="card-footer text-right">
                  <button type="submit" name="submit" class="btn btn-primary">Submit</button>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>
    </section>


  </div>


<?php include '_footer.php'; ?>
<script>
    function hanyaAngka(evt) {
      var charCode = (evt.which) ? evt.which : event.keyCode
       if (charCode > 31 && (charCode < 48 || charCode > 57))
 
        return false;
      return true;
    }
</script>

