<?php include "../koneksi.php"; ?>
<!DOCTYPE html>
<!-- Designined by CodingLab | www.youtube.com/codinglabyt -->
<html lang="en" dir="ltr">
  <head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="bootstrap.css">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
   </head>
   <style type="text/css">
    @media all{
      .table-print tr td{
            border-bottom: 1px solid #ddd;
      }
      .table-print tr th{
            border-bottom: 1px solid black;
      }
      .table-borderprint tr td{
            border:1px solid black;
      }
      .table-borderprint tr th{
            border:1px solid black;
      }
    }
     </style>
<body style="font-size: 12px">
<table class="table" style="width:100%">
	<td width="30%">
<img src="../image/logojj.png" alt="">
	</td>
	<td width="10%"></td>
	<td width="20%">
		<h4>Packing List</h4>
	</td>
	<td width="40%"></td>
</table>
<?php 
        $data1 = mysqli_query ($koneksi, " select 
                              deliverytbl.Del_ID,
                              deliverytbl.DateKirim,
                              deliverytbl.DetailPO_ID,
                              detail_po.PO_ID,
                              po_tbl.No_PO,
                              po_tbl.CustomerID,
                              customer.CustomerName,
                              detail_po.ProductID,
                              product.ItemDescription,
                              product.SLoc,
                              product.QtyUnit,
                              deliverytbl.DetailEkspedisi_ID,
                              detailekspedisi.EkspedisiID,
                              ekspedisi.Ekspedisi,
                              detailekspedisi.Sopir,
                              detailekspedisi.NoPolisi,
                              detailekspedisi.NoHP,
                              deliverytbl.NoDN,   
                              deliverytbl.QtyKirim,    
                              deliverytbl.Expedisi,    
                              deliverytbl.Cont,
                              deliverytbl.Seal

                      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]'");
        
    	$row1 = mysqli_fetch_array ($data1)
      ?>

<table style="width:100%">
<tr>
	<td width="10%"></td>
	<td width="10%">
				Tanggal
	</td>
	<td width="40%">
		<?php echo date ("d M Y", strtotime( $row1['DateKirim'])); ?>
	</td>
	<?php if($row1['DetailEkspedisi_ID'] == '6') { ?>
	<td width="12%">
				Ekspedisi
	</td>
	<td width="30%">
		<?php echo $row1['Expedisi']; ?>
	</td>
	<?php } else { ?>
	<td width="12%">
				Ekspedisi
	</td>
	<td width="30%">
		<?php echo $row1['Ekspedisi']; ?>
	</td>
	<?php } ?>
</tr>
<tr>
	<td width="10%"></td>
	<td width="10%">
				No DN
	</td>
	<td width="40%">
		<?php echo $row1['NoDN']; ?>
	</td>
	<?php if($row1['DetailEkspedisi_ID'] == '6') { ?>
	<td width="12%">
			No Container
	</td>
	<td width="30%">
		<?php echo $row1['Cont']; ?>
	</td>
	<?php } else { ?>
	<td width="12%">
				No Polisi
	</td>
	<td width="30%">
		<?php echo $row1['NoPolisi']; ?>
	</td>
	<?php } ?>
</tr>
<tr>
	<td width="10%"></td>
	<td width="10%">
				Customer
	</td>
	<td width="40%">
		<?php echo $row1['CustomerName']; ?>
	</td>
	<?php if($row1['DetailEkspedisi_ID'] == '6') { ?>
	<td width="12%">
			No SEAL
	</td>
	<td width="30%">
		<?php echo $row1['Seal']; ?>
	</td>
	<?php } else { ?>
	<td width="12%">
				Sopir
	</td>
	<td width="30%">
		<?php echo $row1['Sopir']; ?>
	</td>
	<?php } ?>
</tr>
<tr>
	<td width="10%"></td>
	<td width="10%">
				Product
	</td>
	<td width="40%">
		<?php echo $row1['ItemDescription']; ?>
	</td>
	<?php if($row1['DetailEkspedisi_ID'] == '6') { ?>
	<td width="12%">
	</td>
	<td width="30%">
	</td>
	<?php } else { ?>
	<td width="12%">
				No. HP
	</td>
	<td width="30%">
		<?php echo $row1['NoHP']; ?>
	</td>
	<?php } ?>
</tr>
</table>
<table class="table-print" style="width:100%; text-align: center;">
	<thead>
		<tr>
			<th width="5%">
				No.
			</th>
			<th width="25%">
				Kode
			</th>
			<th width="15%">
				NoLot
			</th>
			<th width="15%">
				Date
			</th>
			<th width="15%">
				Quantity
			</th>
			<?php if($row1['SLoc'] === 'NTN2') { ?>
			<th width="15%">
				No. Nick
			</th>
			<?php } else { ?>
			<th width="15%">
				Description
			</th>
			<?php } ?>
		</thead>
		</tr>
			<?php
				$no = 1;
				$data = mysqli_query ($koneksi, " SELECT 
                                        stpj.STPJ_ID,
                                        stpj.Del_ID,
                                        plan.PlanID,
                                        plan.DatePlan,
                                        plan.POOR,
                                        product.ProductID,
                                        product.ItemDescription,
                                        product.SLoc,
                                        product.QtyUnit,
                                        stpj.Kode,
                                        stpj.NoLot,
                                        stpj.Nick,
                                        stpj.Qty
                                FROM stpj 
                                INNER JOIN plan
                                ON stpj.PlanID=plan.PlanID
                                INNER JOIN product
                                ON plan.ProductID=product.ProductID
                                where stpj.Del_ID='$_GET[id]'
                                Order by plan.DatePlan, stpj.kode ASC");
	

				while($row = mysqli_fetch_array ($data)): ?>
		<tr>
			<td width="5%">
				<?php echo $no++; ?>
			</td>
			<td width="25%">
				<?php echo $row['POOR']; ?>-<?php if ($row['Kode']<10) {
					echo '00'.$row['Kode'];
				} else if ($row['Kode']<100) {
				    echo '0'.$row['Kode'];
				} else {
					echo $row['Kode'];
				} 
				?>-<?php echo substr(preg_replace('/[^A-Za-z0-9]/', '', $row['DatePlan']), 2, 4); ?>
			</td>
			<td width="10%">
				<?php echo $row['NoLot']; ?>
			</td>
			<td width="15%">
				<?php echo date ("d/m/Y", strtotime($row['DatePlan'])); ?>
			</td>
			<td width="20%">
				<?php echo number_format($row['Qty']*$row['QtyUnit'],0,".","."); ?>
			</td>
			<?php if($row1['SLoc'] === 'NTN2') { ?>
			<td width="15%">
				<?php echo $row['Nick']; ?>
			</td>
			<?php } else { ?>
			<td width="15%">
				<?php echo $row['Qty']; ?>
				<?php echo substr($row['SLoc'], 0, 3); ?>
			</td>
			<?php } ?>
		</tr>
			<?php endwhile; ?>
	</table>
	<table class="table-print" style="width:100%">
	<thead><tr><th></th></thead>
	</table>
	<table class="table" style="width:100%">
		<td width="25%">
		<table class="table-borderprint" style="width:100%; margin-top: 15px;">
		<tr>
			<td width="100%">
				Dibuat Oleh
			</td>
		</tr>
		<tr>
			<td width="100%" height="50px">
			</td>
		</tr>
		<tr>
			<td width="100%">
				Harun S.
			</td>
		</tr>
	</table>
	<span style="font-size: 10px; font-style: italic;" >002/FORM-CORP/SOP901/PL/REV.01</span>
	</td>
	<td width="25%"></td>
		<td width="50%">
	<table class="table" style="width:100%">
		<?php
		$data3 = mysqli_query ($koneksi, " SELECT 
				stpj.STPJ_ID,
				product.SLoc,
				product.QtyUnit,
				stpj.NoLot,
				sum(stpj.Qty) AS qty
		FROM stpj 
		INNER JOIN plan
		ON stpj.PlanID=plan.PlanID
		INNER JOIN product
		ON plan.ProductID=product.ProductID
		where stpj.Del_ID='$_GET[id]'");

		$row3 = mysqli_fetch_array ($data3) ?>
		<tr>
			<th width="30%">
				TOTAL
			</th>
			<th width="30%">
				<?php echo number_format($row3['qty']*$row3['QtyUnit'],0,".","."); ?>
				PCS
			</th>
			<th width="30%">
				<?php echo $row3['qty']; ?>
				<?php echo substr($row3['SLoc'], 0, 3); ?>
			</th>
		</tr>
	</table>
	<?php if ($row1['CustomerID']==='3' || $row1['CustomerID']==='9') { ?>
	<table class="table table-bordered" style="width:100%">
		<tr>
			<th width="30%">
				No Lot
			</th>
			<th width="30%" colspan="2">
				Quantity
			</th>
			<th width="40%" colspan="2">
				Total
			</th>
		</tr>
		<?php
		$data2 = mysqli_query ($koneksi, " SELECT 
				stpj.STPJ_ID,
				product.SLoc,
				product.QtyUnit,
				stpj.NoLot,
				sum(stpj.Qty) AS qty
		FROM stpj 
		INNER JOIN plan
		ON stpj.PlanID=plan.PlanID
		INNER JOIN product
		ON plan.ProductID=product.ProductID
		where stpj.Del_ID='$_GET[id]'
		GROUP BY stpj.NoLot");

		while($row2 = mysqli_fetch_array ($data2)): ?>
		<tr>
			<td width="30%">
				<?php echo $row2['NoLot']; ?>
			</td>
			<td width="15%">
				<?php echo $row2['qty']; ?>
			</td>
			<td width="15%">
        		<?php echo substr($row2['SLoc'], 0, 3); ?>
			</td>
			<td width="20%">
				<?php echo number_format($row2['qty']*$row2['QtyUnit'],0,".","."); ?>
			</td>
			<td width="20%">
				PCS
			</td>
		</tr>
		<?php endwhile; ?>
	</table>
	<?php } ?>
				</td>
</body>
</html>