<?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-11">
    <div class="pagetitle">
  	<h3>PACKING LIST</h3>
    </div>
    </div><div class="col-md-1">
    <a href="plan_list.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 
                                            plan.PlanID,
                                            plan.DatePlan,
                                            plan.MesinID,
                                            mesin.Mesin,
                                            plan.ProductID,
                                            product.ItemDescription,
                                            product.SLoc,
                                            plan.QtyPlan,
                                            plan.Prioritas,
                                            plan.MaterialID,
                                            material.RawMat,
                                            plan.POOR,
                                            plan.WH_Conf
                                    from 
                                    plan
                                    INNER JOIN mesin
                                    ON plan.MesinID=mesin.MesinID
                                    INNER JOIN product
                                    ON plan.ProductID=product.ProductID
                                    INNER JOIN material
                                    ON plan.MaterialID=material.MaterialID
										WHERE PlanID ='$_GET[id]'");
		$row = mysqli_fetch_array ($data);
   ?>
   <table class="table">
   	<tr>
   		<td>Tanggal Plan  :</td>
   		<td><?php echo date ("d-m-Y", strtotime( $row['DatePlan'])); ?></td>
   	</tr>
   	<tr>
   		<td width="50%">Mesin  :</td>
   		<td><?php echo $row['Mesin']; ?></td>
   	</tr>
   	<tr>
   		<td>Product  :</td>
   		<td><?php echo $row['ItemDescription']; ?></td>
   	</tr>
   	<tr>
   		<td>Material  :</td>
   		<td><?php echo $row['RawMat']; ?></td>
   	</tr>
   	<tr>
   		<td>Quantity  :</td>
   		<td><?php echo $row['QtyPlan']; ?></td>
   	</tr>
   	<tr>
   		<td>POOR  :</td>
   		<td><?php echo $row['POOR']; ?></td>
   	</tr>
   </table>
   <?php
    if ($row['WH_Conf']=='0'){ ?>
   <div style="margin-top: 5px">
   <a style="width: 100%" class="btn btn-primary btn-lg btn-block editbtn" id="terima-stpj" data-id="<?php echo $_GET['id']; ?>" >Data STPJ</a>
   </div>
    <?php } elseif($row['WH_Conf']=='1') { ?>
      <div style="margin-top: 5px">
      <a style="width: 100%" data-href="unconfirm.php?id=<?php echo $_GET['id']; ?>&qty=<?php echo $_GET['qty']; ?>" class="btn btn-lg btn-warning btn-block editbtn"   data-toggle="modal" data-target="#confirm-ok">Return STPJ</a>
    </div>
   <?php }
   $data1 = mysqli_query ($koneksi, " select STPJ_ID from stpj 
   where PlanID = '$_GET[id]'");
   $jml_stpj = mysqli_num_rows($data1);
   if(empty($jml_stpj)) {
   ?>
  <div class="upload">
   <div class="pagetitle">
  	<h3>UPLOAD S T P J</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['PlanID']; ?>&qty=<?php echo  $row['QtyPlan']; ?>'"> 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['PlanID']; ?>&qty=<?php echo $row['SLoc']=='BOX2'?$row['QtyPlan']/15:$row['QtyPlan']; ?>">
    <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>S T P J</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['PlanID']; ?>"><i class="bi bi-plus-square"></i> Tambah Data</a>
    <a href="#" style="color: #0000FF" class='editbtn' id="addstd" data-id="<?php echo $row['PlanID']; ?>"><i class="bi bi-plus-square"></i> Tambah Data2</a>
    &ensp;|&ensp;
    <?php if(!empty($jml_stpj)) { ?>
		<a href="#" style="color: #DC143C" data-href="hapus_stpjall.php?id=<?php echo $row['PlanID']; ?>" data-toggle="modal" data-target="#confirm-delete"><i class="bi bi-trash-fill"></i> Hapus Semua</a> 
    <?php } ?>
  </p>

	<!-- Modal -->
  <div id="modal-terima-stpj" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Serah Terima STPJ</h4>
        </div>
          <div class="modal-body">
            <div id="data-terima-stpj">
            
            </div>        
          </div>
          
          <div class="modal-footer">
          <a href="confirm.php?id=<?php echo $_GET['id']; ?>&qty=<?php echo $_GET['qty']; ?>" style="width: 100%" class="btn btn-success btn-lg btn-block editbtn" >Confirm STPJ</a>
          </div>
        </form>   
      </div>
    </div>
  </div>

  <div class="modal fade" id="confirm-ok" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-md">
            <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">Return Data</h4>
                </div>
            
                <div class="modal-body">
                    <p>Apakah anda setuju data akan dikembalikan?</p>
                    <p>Data akan segera dikeluarkan dari stok..</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-success btn-val" style="width: 25%;">OK</a>
                </div>
            </div>
        </div>
    </div>


    <div id="modal-addstd" class="modal fade" role="dialog"  data-bs-keyboard="false" data-bs-backdrop="static">
		<div class="modal-dialog modal-lg">
			<div class="modal-content">
				<form role="form" id="form-edit" method="post" action="input-addlot.php" autocomplete="off">
				<div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">Input Data Serah Terima Produk Jadi</h4>
				</div>
					<div class="modal-body">
						<div id="data-addstd">
						
						</div>				
					</div>
					
					<div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                  <button type="submit" class="btn btn-primary" >Simpan</button>
					</div>
				</form>		
			</div>
		</div>
	</div>

	<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');
	
		$(document).ready(function(){
	var data = "data_stpj.php?id="+id;
	$('#data-mahasiswa').load(data);

  $(document).on('click','#terima-stpj',function(e){
    e.preventDefault();
    $("#modal-terima-stpj").modal('show');
    $.post('terima-stpj-info.php',
      {
        id:$(this).attr('data-id'),
        shift:$(this).attr('data-shift')
      },
      function(html){
        $("#data-terima-stpj").html(html);
      }   
    );
  });

   $('#confirm-ok').on('show.bs.modal', function(e) {
            $(this).find('.btn-val').attr('href', $(e.relatedTarget).data('href'));
            
        });
	
    $(document).on('click','#addstd',function(e){
			e.preventDefault();
			$("#modal-addstd").modal('show');
			$.post('addlot.php',
				{
					id:$(this).attr('data-id'),
					prod:$(this).attr('data-prod')
				},
				function(html){
					$("#data-addstd").html(html);
				}   
			);
		});
	
	$(document).on('click','#tambah',function(e){
		e.preventDefault();
		$("#modal-tambah").modal('show');
		$.post('addstpj.php',
			{id:$(this).attr('data-id')},
			function(html){
				$("#data-tambah").html(html);
			}   
		);
	});
	
	$("#form-tambah").submit(function(e) {
		e.preventDefault();
		
		$("#error_plan_id").html('');
		$("#error_kode").html('');
		$("#error_nolot").html('');
		$("#error_nick").html('');
		
		var dataform = $("#form-tambah").serialize();
		$.ajax({
			url: "stpj.php",
			type: "post",
			data: dataform,
			success: function(result) {
				var hasil = JSON.parse(result);
				if (hasil.hasil !== "sukses") {
					$("#error_plan_id").html(hasil.error.plan_id);
					$("#error_kode").html(hasil.error.kode);
					$("#error_nolot").html(hasil.error.nolot);
					$("#error_nick").html(hasil.error.nolot);
				} else {
					$('#modal-tambah').modal('hide');
					$("#plan_id").val('');
					$("#kode").val('');
					$("#nolot").val('');
					$("#nick").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_stpj.php';?>
  </div>
</div>



  </div>
  </div>

</div>