<?php foreach($kontak as $kontak) :   endforeach; ?>
<?php foreach($admin_login as $user) :   endforeach; ?> 
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark"> 
            		 <?php echo $title1; ?>
            </h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">Home</a></li>
              <li class="breadcrumb-item active"><?php echo $title1; ?></li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->
	    
          
    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
      	  <div class="card">
              <div class="card-header">
              	<form action="<?php echo base_url('barang/code_simpan_fastmoving'); ?>" method="post">
              	<table border="1">
              		<tr>
              			<td>
              							<div class="input-group input-group-sm">
                              <input type="text" class="form-control" id="kode2" placeholder="Kode" required="" readonly=""  >
                              <span class="input-group-append">
                                <button type="button" class="btn btn-success btn-flat" data-toggle="modal" data-target="#modalbarang">Klik Cari</button>
                              </span>
                            </div>
                    </td>
                    <td>
                    	 <input type="hidden" class="form-control-sm" placeholder="ID Barang"  style="width: 250px;"   name="id_barang" id="id_barang2">
                    </td>
                    <td >
                            <input type="text" class="form-control-sm" placeholder="Nama Barang"  style="width: 250px;"   name="nama_barang" id="nama_barang2" readonly="" >
                             <input type="hidden" class="form-control-sm"    name="id_kantor" value="<?php echo $id_kantor; ?>">
                          </td>
                          <td >
                            <input type="text" class="form-control-sm" placeholder="Harga Jual"  style="width: 250px;"   name="harga_jual_ecer"  id="harga_jual_ecer2" readonly="" >
                          </td>
                         
                          <td >
                            <input type="submit" class="form-control-sm btn-success" style="width: 140px;"  value="Tambah" name="simpan">
                          </td>
              		</tr>
              	</table>
                </form>  
                        

              </div>
              <!-- /.card-header -->
              <div class="card-body">
              	<table id="example1" class="table table-bordered table-striped">
              		<thead>
              			<tr>
              				<th>No</th>
              				<th>Barcode </th>
                      <th>Nama Barang</th>
                      <th>Stok</th>
                      <th> H. Beli Satuan</th>
                      <th> H. Beli Dos</th>
                      <th> H. Jual Ecer</th>
                      <th> H. Jual Dos</th>
                      <th> H. Grosir Lv1</th>
                      <th> H. Grosir Lv2</th>
                      <th> H. Grosir Lv3</th>
                      <th> H. Grosir Lv4</th>
                      <th> Aksi</th> 
              			 
              				
              			</tr>
              		</thead>
                  
              		<tbody>
              			<?php $no=1; foreach($barang as $rows) : ?> 
              			<tr>
              				<td><?php echo $no; ?></td>
              				<td><?php echo $rows->barcode_ecer; ?></td>
              				<td><?php echo $rows->nama_barang; ?></td>
              				<td><?php echo $rows->stok_aplikasi; ?></td>
              				
              				<td><?php echo $rows->harga_beli_ecer; ?></td>
              				<td><?php echo $rows->harga_beli_dos; ?></td>
              				<td><?php echo $rows->harga_jual_ecer; ?></td>
              				<td><?php echo $rows->harga_jual_dos; ?></td>
              				<td><?php echo $rows->harga_grosir_lv1; ?></td>
              				<td><?php echo $rows->harga_grosir_lv2; ?></td>
              				<td><?php echo $rows->harga_grosir_lv3; ?></td>
              				<td><?php echo $rows->harga_grosir_lv4; ?></td>
              				<td><a href="<?php echo base_url('barang/code_hapus_fastmoving/');?><?php echo $rows->id_fastmoving; ?>">Hapus</a></td>
              			</tr>
              			<?php $no++; endforeach; ?>

              		</tbody>

              	</table>
              </div>
            
            </div>
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  	<!-- Modal Tambah Data -->
  	<form class="form-horizontal" action="<?php echo base_url('barang/code_tambah'); ?>" method="POST" enctype="multipart/form-data" />  
  		<div class="modal fade" id="modal-default">
  			<div class="modal-dialog">
  				<div class="modal-content">
  					<div class="modal-header">
  						<h4 class="modal-title">Tambah Data</h4>
  						<button type="button" class="close" data-dismiss="modal" aria-label="Close">
  							<span aria-hidden="true">&times;</span>
  						</button>
  					</div>
  					<div class="modal-body">
  						<div class="form-group">
  							<label for="exampleInputEmail1">Kode Barcode Ecer</label>
  							<input type="text" class="form-control" id="" name="barcode_ecer" placeholder="Isikan Kode Barcode" required="">
  							<input type="hidden" name="id_admin" value="<?php echo $id_admin_login; ?>">
  						</div>
  						<div class="form-group">
  							<label for="exampleInputEmail1">Kode Barcode Pack/Dos</label>
  							<input type="text" class="form-control" id="" name="barcode_dos" placeholder="Isikan Barcode Barang dalam 1Dos/Pack/Liter dll" required="">
  						</div>
  						<div class="form-group">
  							<label for="exampleInputEmail1">Nama Barang  </label>
  							<input type="text" class="form-control" id="" name="nama_barang" placeholder="Exm: Baterai ABC AAA  " required="">
  							<small>Tambahkan Merk + Ukuran ada Barang</small>
  						</div>
  						<div class="form-group">
  							<label for="exampleInputPassword1">Pilih Satuan Beli</label>
  							<select class="form-control" id="exampleInputPassword1" name="id_satuan_beli">
  								<?php foreach($satuan as $satuan1) : ?>
  									<option value=" <?php echo $satuan1->id_satuan; ?>"> <?php echo $satuan1->nama_satuan; ?></option>
  								<?php endforeach; ?> 

  							</select>  
  						</div>

  						<div class="form-group">
  							<label for="exampleInputEmail1">Isi Satuan Beli</label>
  							<input type="text" class="form-control" id="" name="isi" placeholder="Jumlah dalam satuan beli" required="">
  						</div>
  						<div class="form-group">
  							<label for="exampleInputEmail1">Harga Beli Ecer/Dos</label>
  							<input type="text" class="form-control" id="" name="harga_beli_dos" placeholder="Harga Beli" required="">
  						</div>

  						<div class="form-group">
  							<label for="exampleInputPassword1">Pilih Satuan Jual</label>
  							<select class="form-control" id="exampleInputPassword1" name="id_satuan_jual">
  								<?php foreach($satuan as $satuan2) : ?>
  									<option value=" <?php echo $satuan2->id_satuan; ?>"> <?php echo $satuan2->nama_satuan; ?></option>
  								<?php endforeach; ?> 

  							</select>  
  						</div>
  						<div class="form-group">
  							<label for="exampleInputEmail1">Harga Jual Ecer</label>
  							<input type="text" class="form-control" id="" name="harga_jual_ecer" placeholder="Harga Jual Ecer" required="">
  						</div>
  						<div class="form-group">
  							<label for="exampleInputEmail1">Harga Jual Dos</label>
  							<input type="text" class="form-control" id="" name="harga_jual_dos" placeholder="Harga Jual Dos" required="">
  						</div>
  						<div class="form-group">
  							<label for="exampleInputPassword1">Harga Grosir</label>
  							<input type="text" class="form-control" id="exampleInputPassword1" name="harga_grosir" placeholder="Harga Jual Grosir" required="">
  						</div>
  						<div class="form-group">
  							<label for="exampleInputPassword1">Min Grosir</label>
  							<input type="text" class="form-control" id="exampleInputPassword1" name="min_grosir" placeholder="Harga Grosir" required="">
  						</div>
  						 
  						<div class="form-group">
  							<label for="exampleInputPassword1">Pilih Katagori</label>
  							<select class="form-control" id="exampleInputPassword1" name="id_katagori">
  								<?php foreach($katagori as $katagori1) : ?>
  									<option value=" <?php echo $katagori1->id_katagori; ?>"> <?php echo $katagori1->nama_katagori; ?></option>
  								<?php endforeach; ?> 

  							</select>  
  						</div>
  						<div class="form-group">
  							<label for="exampleInputPassword1">Pilih Rak</label>
  							<select class="form-control" id="exampleInputPassword1" name="id_rak">
  								<?php foreach($rak as $rak1) : ?>
  									<option value=" <?php echo $rak1->id_rak; ?>"> <?php echo $rak1->nama_rak; ?></option>
  								<?php endforeach; ?> 

  							</select>  
  						</div>
              <div class="form-group">
                <label for="exampleInputPassword1">Pilih Selfing</label>
                <select class="form-control" id="exampleInputPassword1" name="id_selfing">
                  <?php foreach($selfing as $selfing1) : ?>
                    <option value=" <?php echo $selfing1->id_selfing; ?>"> <?php echo $selfing1->nama_selfing; ?></option>
                  <?php endforeach; ?> 

                </select>  
              </div>
  						 
  						 
  						<div class="form-group">
  							<label for="exampleInputFile">File Foto</label>
  							<div class="input-group">

  								<input type="file" name="foto">


  							</div>
  						</div>
  					</div>
  						<div class="modal-footer justify-content-between">
  							<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  							<button type="submit" class="btn btn-primary">Simpan</button>
  						</div>
  					</div>
  					<!-- /.modal-content -->
  				</div>
  				<!-- /.modal-dialog -->
  		</div>
  	</form>


<div class="modal fade" id="modalbarang">
  <div class="modal-dialog modal-xl">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Cari Data Barang</h4>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
 
         

           <div class="form-group">

            <div class="input-group ">
               <input type="text" name="search_text" id="search_text"    placeholder="Masukkan Nama/ID Pencarian Barang" class="form-control" />
              <span class="input-group-append">
                <button type="button" class="btn btn-info" >Cari!</button>
              </span>
            </div>
           </div>



           <br />
           <div id="result"></div>
          </div>
          <div style="clear:both"></div>
          <button type="submit" class="btn btn-primary" data-dismiss="modal">Close</button>
      </div>
     
    </div>
    <!-- /.modal-content -->
  </div>
  <!-- /.modal-dialog -->
</div>


<script src="<?php echo base_url();?>assets/js/jquery.min.js"></script>
<script>
$(document).ready(function(){

 load_data();

 function load_data(query)
 {
  $.ajax({
   url:"<?php echo base_url(); ?>kasir/fetch",
   method:"POST",
   data:{query:query},
   success:function(data){
    $('#result').html(data);
   }
  })
 }

 $('#search_text').keyup(function(){
  var search = $(this).val();
  if(search != '')
  {
   load_data(search);
  }
  else
  {
   load_data();
  }
 });
});


</script>
<script type="text/javascript">

  // barang
  $(document).on('click', '.pilih', function (e) {
    document.getElementById("id_barang2").value = $(this).attr('data-id_barang');
    document.getElementById("nama_barang2").value = $(this).attr('data-nama_barang');
    document.getElementById("kode2").value = $(this).attr('data-barcode');
    document.getElementById("harga_jual_ecer2").value = $(this).attr('data-harga_jual_ecer');
  

    $('#modalbarang').modal('hide');
  });
   

</script> 
<script>
  // https://tutorialweb.net/menangkap-tombol-keyboard-dengan-javascript/
document.onkeydown = function (e) {
  switch (e.keyCode) {
            // tombol shif
            case 16:
            $('#modalbarang').modal('show');
            break;
            // Esc
            case 27:
            $('#modalbarang').modal('hide');
            $('#modalbarang2').modal('hide');
            break;
            
            
            // F5
            case 116:
            location.reload(); 
            break;
        }
        //menghilangkan fungsi default tombol
        
    };
 
</script>




<script>
var input = document.getElementById("kode");
input.addEventListener("keyup", function(event) {
  if (event.keyCode === 113) {
    event.preventDefault();
    document.getElementById("ada1").focus();
  }

  if (event.keyCode === 35) {
    event.preventDefault();
    document.getElementById("potongan").focus();
  }
});
 
var input = document.getElementById("potongan");
input.addEventListener("keyup", function(event) {
 
  if (event.keyCode === 34) {
    event.preventDefault();
    document.getElementById("bayar").focus();
  }
});

</script> 