<?php
	include "../dashboard/header.php";
  include "../koneksi.php";
?>
<style type="text/css">
</style>
<div class="row">
  <div class="col-md-6">
  <div class="row">
    <div class="col-md-8">
    <div class="pagetitle">
  	<h3>PACKING LIST</h3>
    </div>
    </div>
    <div class="col-md-2">
    <button type="button" class="btn btn-primary btn-sm" id="tambah-coa" data-id="<?php echo $_GET['id']; ?>"> COA </button>
    </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="p_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 
                              deliverytbl.Del_ID,
                              deliverytbl.DateKirim,
                              customer.CustomerName,
                              product.SLoc,
                              product.QtyUnit,
                              ekspedisi.Ekspedisi,
                              detailekspedisi.DetailEkspedisi_ID,
                              detailekspedisi.Sopir,
                              deliverytbl.NoDN,   
                              deliverytbl.Expedisi,   
                              deliverytbl.Cont,   
                              deliverytbl.Seal,   
                              deliverytbl.QtyKirim    
                      from 
                      deliverytbl
                      INNER JOIN detail_po
                      ON deliverytbl.DetailPO_ID=detail_po.DetailPO_ID
                      INNER JOIN po_tbl
                      ON detail_po.PO_ID=po_tbl.PO_ID
                      INNER JOIN customer
                      ON po_tbl.CustomerID=customer.CustomerID
                      INNER JOIN product
                      ON detail_po.ProductID=product.ProductID
                      INNER JOIN detailekspedisi
                      ON deliverytbl.DetailEkspedisi_ID=detailekspedisi.DetailEkspedisi_ID
                      INNER JOIN ekspedisi
                      ON detailekspedisi.EkspedisiID=ekspedisi.EkspedisiID
                      WHERE Del_ID ='$_GET[id]'");
        
        while($row = mysqli_fetch_array ($data)):
      ?>
   <table class="table">
   	<tr>
   		<td>Tanggal Kirim  :</td>
   		<td><?php echo date ("d-m-Y", strtotime( $row['DateKirim'])); ?></td>
   	</tr>
    <tr>
      <td>Nomor DN  :</td>
      <td><?php echo $row['NoDN']; ?></td>
    </tr>
   	<tr>
   		<td>Customer  :</td>
   		<td><?php echo $row['CustomerName']; ?></td>
   	</tr>
   	<tr>
   		<td>Quantity  :</td>
   		<td>
        <?php echo $row['QtyKirim']; ?>&ensp;
        <?php echo substr($row['SLoc'], 0, 3); ?>@
        <?php echo $row['QtyUnit']*$row['QtyKirim']; ?> PCS
      </td>
   	</tr>
    <?php if($row['DetailEkspedisi_ID'] == '6') { ?> 
    <tr>
      <td><a href="#" style="color: #0000FF" class='editbtn' id="tambah-cont" data-id="<?php echo $row['Del_ID']; ?>">Container  :</a></td>
      <td><?php echo $row['Cont']; ?></td>
    </tr>
    <tr>
      <td>SEAL  :</td>
      <td><?php echo $row['Seal']; ?></td>
    </tr>
    <?php } else { ?>
    <tr>
      <td>Ekspedisi  :</td>
      <td><?php echo $row['Ekspedisi']; ?></td>
    </tr>
    <tr>
      <td>Sopir  :</td>
      <td><?php echo $row['Sopir']; ?></td>
    </tr>
    <?php } ?>
   	<?php endwhile; ?>
   </table>
<?php 
        $data2 = mysqli_query ($koneksi, " SELECT
                                        sum(stpj.Qty) as jumlah,
                                        stpj.Del_ID, 
                                        product.ItemDescription,
                                        product.SLoc
                                FROM stpj 
                                INNER JOIN plan
                                ON stpj.PlanID=plan.PlanID
                                INNER JOIN product
                                ON plan.ProductID=product.ProductID
                                where stpj.Del_ID='$_GET[id]' ");
  

        $row2 = mysqli_fetch_array ($data2) ?>


  <div class="row">
    <div class="col-md-8">
    <h4><?php echo $row2['ItemDescription']; ?></h4>
    </div><div class="col-md-4">
    <h4 style="text-align: right;"><?php echo $row2['jumlah']; ?><?php echo substr($row2['SLoc'], 0, 3); ?></h4>
    </div></div>
  <div style="width:100%;height:350px;overflow:scroll;align: left;" >
  <div id="data-kirim"></div>
  </div>
  </div>

<?php 
        $data1 = mysqli_query ($koneksi, " SELECT 
                                        sum(stpj.Qty) as jumlah,
                                        product.ProductID,
                                        product.ItemDescription,
                                        product.SLoc
                                FROM stpj 
                                INNER JOIN plan
                                ON stpj.PlanID=plan.PlanID
                                INNER JOIN product
                                ON plan.ProductID=product.ProductID
                                where product.ProductID='$_GET[prod]' AND stpj.Del_ID IS NULL AND stpj.`Lock`='0'");
  

        $row1 = mysqli_fetch_array ($data1) ?>
  <div class="col-md-6">
    <div class="row">
    <div class="col-md-8">
  	<h4><?php echo $row1['ItemDescription']; ?></h4>
  </div><div class="col-md-3">
    <h4 style="text-align: right;"><?php echo $row1['jumlah']; ?><?php echo substr($row1['SLoc'], 0, 3); ?></h4>
    </div></div>

  <div style="width:100%;height:540px;overflow:scroll;align: left;" >
  <div id="data-mahasiswa"></div>
  </div>

  <div id="modal-tambah-cont" class="modal fade" role="dialog">
		<div class="modal-dialog modal-md">
			<div class="modal-content">
				<form role="form" id="form-edit" method="post" action="input-cont.php" autocomplete="off">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">&times;</button>
					<h4 class="modal-title">Masukkan Data Container</h4>
				</div>
					<div class="modal-body">
						<div id="data-tambah-cont">
						
						</div>				
					</div>
					
					<div class="modal-footer">
						<button type="button" class="btn btn-info" data-dismiss="modal">Batal</button>
						<button type="submit" class="btn btn-primary" >Simpan</button>
					</div>
				</form>		
			</div>
		</div>
	</div>

  <div id="modal-coa" class="modal fade" role="dialog">
		<div class="modal-dialog modal-md">
			<div class="modal-content">
				<form role="form" id="form-edit" method="post" action="" autocomplete="off">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">&times;</button>
					<h4 class="modal-title">Data Packing List</h4>
				</div>
					<div class="modal-body">
						<div id="data-coa">
						
						</div>				
					</div>
					
					<div class="modal-footer">
						<button type="button" class="btn btn-info" data-dismiss="modal"> Ok </button>
					</div>
				</form>		
			</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');
    var prod = GetURLParameter('prod');

function myFunction() {
  window.open("pack_List.php?id="+id);
}
	
$(document).ready(function(){
	var data = "data_plist.php?prod="+prod+"&id="+id;
	$('#data-mahasiswa').load(data);
	

});

$(document).ready(function(){
  var data = "kirim_plist.php?prod="+prod+"&id="+id;
  $('#data-kirim').load(data);
  

});

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

  $(document).on('click','#buka-coa',function(e){
		e.preventDefault();
    var fold = $(this).attr('data-fold');
    var lot = $(this).attr('data-lot');
    var urlcoa = "pdf.php?fold="+fold+"&lot="+lot;
    window.open(urlcoa);
	  });

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

  $("#form-tambah-cont").submit(function(e) {
		e.preventDefault();
		
		$("#error_expedisi").html('');
		$("#error_cont").html('');
		$("#error_seal").html('');
		
		var dataform = $("#form-tambah-cont").serialize();
		$.ajax({
			url: "plist.php",
			type: "post",
			data: dataform,
			success: function(result) {
				var hasil = JSON.parse(result);
				if (hasil.hasil !== "sukses") {
					$("#error_expedisi").html(hasil.error.expedisi);
					$("#error_cont").html(hasil.error.cont);
					$("#error_seal").html(hasil.error.seal);
				} else {
					$('#modal-tambah-cont').modal('hide');
					$("#del_id").val('');
					$("#expedisi").val('');
					$("#cont").val('');
					$("#seal").val('');
				}
			}
		});
	});
  </script>
  </div>
</div>



  </div>
  </div>

</div>