<?php
	include "../dashboard/header.php";
  include "../koneksi.php";
?>
<style type="text/css">
  .upload {
    margin-top: 20px;
  }
  .dowblanko{
      background-color: darkblue;
      font-size: 16px;
      border: none;
      color: white;
      padding: 5px;
      padding-left: 10px;
      padding-right: 10px;
      margin-bottom: 1px;
      margin-left: 3px;
    }
    .porm-control{
      background-color: black;
      font-size: 16px;
      border: none;
      color: white;
      padding: 5px;
      padding-left: 10px;
      padding-right: 10px;
      margin-bottom: 1px;
      margin-left: 3px;
    }
    .impbtn{
      background-color: darkgreen;
      font-size: 17px;
      border: none;
      color: white;
      padding: 5px;
      padding-left: 12px;
      padding-right: 12px;
      margin-bottom: 1px;
      margin-left: 3px;
    }
</style>
<div class="row">
  <div class="col-md-6">
  <div class="row">
    <div class="col-md-10">
    <div class="pagetitle">
  	<h3>LIST INCOMING</h3>
    </div>
    </div><div class="col-md-1">
    <a onclick="myFunction()" style="color: #00008B; font-size: 25px;" ><i class="bi bi-printer-fill"></i></a>
    </div><div class="col-md-1">
    <a href="inc_bb.php?id=<?php echo $_GET['id']; ?>" style="color: #00008B; font-size: 25px;" ><i class="bi bi-file-earmark-excel-fill"></i></a>
  </div></div>
  <?php
				$data = mysqli_query ($koneksi, " SELECT incoming.IncomingID,
                                                  incoming.Date_Inc,
                                                  incoming.MaterialID,
                                                  material.RawMat,
                                                  material.Qty,
                                                  incoming.Supplier,
                                                  incoming.No_SJ,
                                                  incoming.Qty_Inc,
                                                  incoming.`Desc`
                                              FROM incoming
                                              INNER JOIN material
                                              ON incoming.MaterialID=material.MaterialID
                                              WHERE IncomingID ='$_GET[id]'");
				$row = mysqli_fetch_array ($data);
   ?>
   <table class="table">
   	<tr>
   		<td>Tanggal Datang  :</td>
   		<td><?php echo date ("d-m-Y", strtotime( $row['Date_Inc'])); ?></td>
   	</tr>
   	<tr>
   		<td width="50%">Material  :</td>
   		<td><?php echo $row['RawMat']; ?></td>
   	</tr>
   	<tr>
   		<td>Supplier  :</td>
   		<td><?php echo $row['Supplier']; ?></td>
   	</tr>
   	<tr>
   		<td>No. SJ  :</td>
   		<td><?php echo $row['No_SJ']; ?></td>
   	</tr>
   	<tr>
   		<td>Quantity  :</td>
   		<td><?php echo $row['Qty_Inc']; ?></td>
   	</tr>
   </table>

   <?php 
   $data1 = mysqli_query ($koneksi, " select PBB_ID from pbb 
   where IncomingID = '$_GET[id]'");
   $jml_pbb = mysqli_num_rows($data1);
   if(empty($jml_pbb)) {
   $qtyinc = $row['Qty_Inc']/$row['Qty']
   ?>
  <div class="upload">
   <div class="pagetitle">
  	<h3>UPLOAD INCOMING</h3>
  </div>
   <table>
  <tr>
    <td>
      <label for="downloadblangko">Step 1</label>
    </td><td>
<button class="dowblanko" onclick="location.href='blangko.php?id=<?php echo $row['IncomingID']; ?>&qty=<?php echo $qtyinc; ?>'"> Download Blangko Excel </button></td>
  </tr><tr>
    <td>
      <label for="uploadfile">Step 2</label>
    </td><td>
    <form method="post" enctype="multipart/form-data" action="upload.php?id=<?php echo $row['IncomingID']; ?>&qty=<?php echo $qtyinc; ?>">
    <div class="form-group">
        <input type="file" name="berkas_excel" class="form-control porm-control" id="exampleInputFile">
    </div></td>
    </tr>
    <tr>
    <td><label for="Importexcel">Step 3</label></td>
    <td><button type="submit" class="impbtn">Import</button></td>
    </tr>
</table>
</form>
</div>
<?php } ?>


  </div>


  <div class="col-md-6">
  	 <div class="pagetitle">
  	<h3>RINCIAN INCOMING</h3>
  </div>
  
  <div style="width:95%;height:500px;overflow:scroll;align: left;" >
  <div id="data-mahasiswa"></div>
  </div>
  <p style="margin-top: 5px">
    <a href="#" style="color: #0000FF" class='editbtn' id="tambah" data-id="<?php echo $row['IncomingID']; ?>"><i class="bi bi-plus-square"></i> Tambah Data</a>
    &ensp;|&ensp;
		<a href="#" style="color: #DC143C" data-href="hapus_pbball.php?id=<?php echo $row['IncomingID']; ?>" data-toggle="modal" data-target="#confirm-delete"><i class="bi bi-trash-fill"></i> Hapus Semua</a> 
  </p>

	<!-- Modal -->
	<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
            
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Kofirmasi Hapus</h4>
                </div>
            
                <div class="modal-body">
                    <p>Apakah anda mau melanjutkan menghapus data?</p>
                    <p class="debug-url"></p>
                </div>
                
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <a class="btn btn-danger btn-ok">Delete</a>
                </div>
            </div>
        </div>
    </div>

  <script>
	function GetURLParameter(sParam)
		{
			var sPageURL = window.location.search.substring(1);
			var sURLVariables = sPageURL.split('&');
			for (var i = 0; i < sURLVariables.length; i++) 
			{
				var sParameterName = sURLVariables[i].split('=');
				if (sParameterName[0] == sParam) 
				{
					return sParameterName[1];
				}
			}
		}
		var id = GetURLParameter('id');

  function myFunction() {
    window.open("cek_List.php?id="+id);
  }
	
		$(document).ready(function(){
	var data = "data_pbb.php?id="+id;
	$('#data-mahasiswa').load(data);
	
	
	$(document).on('click','#tambah',function(e){
		e.preventDefault();
		$("#modal-tambah").modal('show');
		$.post('addpbb.php',
			{id:$(this).attr('data-id')},
			function(html){
				$("#data-tambah").html(html);
			}   
		);
	});
	
	$("#form-tambah").submit(function(e) {
		e.preventDefault();
		
		$("#error_inc_id").html('');
		$("#error_lot").html('');
		$("#error_bag").html('');
		
		var dataform = $("#form-tambah").serialize();
		$.ajax({
			url: "pbb.php",
			type: "post",
			data: dataform,
			success: function(result) {
				var hasil = JSON.parse(result);
				if (hasil.hasil !== "sukses") {
					$("#error_inc_id").html(hasil.error.inc_id);
					$("#error_lot").html(hasil.error.lot);
					$("#error_bag").html(hasil.error.bag);
				} else {
					$('#modal-tambah').modal('hide');
					$("#inc_id").val('');
					$("#lot").val('');
					$("#bag").val('');
					$('#data-mahasiswa').load(data);
				}
			}
		});
	});
	
	$('#confirm-delete').on('show.bs.modal', function(e) {
            $(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
            
        });


});
  </script>
  <?php include 'modal_pbb.php';?>
  </div>
</div>



  </div>
  </div>

</div>