<?php 
include "../include/config.php"; 
include "../function/inc_function.php"; 
ob_start();
$dlv_id = isset($_REQUEST['dlv_id']) ? $_REQUEST['dlv_id'] :'';
$hd = mysql_fetch_array(mysql_query("SELECT a.*, b.cust_name, b.cust_address
									  FROM delivery a 
									  LEFT JOIN customer b ON b.id=a.dlv_idcust
									  WHERE a.id='$dlv_id'"));
$dlv = mysql_fetch_array(mysql_query("SELECT a.*,b.prod_code,b.prod_name,b.prod_sat
						  FROM delivery_detail a
						  LEFT JOIN product b ON b.id=a.dlvd_prodid
						  WHERE a.dlvd_hid='$dlv_id' "));
$comp = mysql_fetch_array(mysql_query("SELECT * FROM profil"));									  
?>
<html>
<head>
<link rel='stylesheet' type='text/css' href="../include/css/print_styles.css" />	
</head>
<body>
<div id="popup">
<table width="100%">
	<tr>
		<td width="220" border="0"></td>
		<td width="200" border="0"><img src="../images/Hab Dong Indo Logo.png" width="200" height="50"></td>
		<td width="300" border="0"><b><?=$comp['prof_name'];?></b><br><?=wordwrap($comp['prof_address'],50,"<br>\n",TRUE);?></td>
	</tr>
</table>
<br>
<table>
	<tr>
		<td colspan="4" valign="middle" align="center" height="20"><b>PACKING LIST</b></td>
	</tr>
	<tr >
		<td rowspan="2" colspan="3" ><b>Seller / Exporter<br><br><?=wordwrap($comp['prof_name'],50,"<br>\n",TRUE);?><br><?=wordwrap($comp['prof_address'],50,"<br>\n",TRUE);?> <br>
		Telp : <?=wordwrap($comp['prof_telp'],50,"<br>\n",TRUE);?><br>
		Tax ID : <?=wordwrap($comp['prof_npwp'],50,"<br>\n",TRUE);?></b></td>
		<td width="350"><b>Invoice No and Date</b>
			<table>
				<tr>
				  <col width="200">
					<td border="0"><?=wordwrap($hd['dlv_invno'],25,"<br>\n",TRUE);?></td>
				  </col>
				  <col width="130">
					<td border="0" align="right"><?=date("d-M-Y",strtotime($hd['dlv_invdate']));?></td>
				  </col>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td><b>LC No and Issue Date</b>
			<table>
				<tr>
				  <col width="200">
					<td border="0"><?=wordwrap($hd['dlv_lcno'],25,"<br>\n",TRUE);?></td>
				  </col>
				  <col width="130">
					<td border="0" align="right">
						<?php if($hd['dlv_issudate'] != "0000-00-00"){ ?>
							<?=date("d-M-Y",strtotime($hd['dlv_issudate']));?>
						<?php } ?>
					</td>
				  </col>
				</tr>
			</table>
		</td>
	</tr>
	
	<tr>
		<td colspan="3">
			<b>Consignee</b><br>
			<?=wordwrap($hd['cust_name'],55,"<br>\n",TRUE);?><br>
			<?php echo nl2br(str_replace('','',htmlspecialchars($hd['cust_address']))); ?>
		</td>
		<td><b>Mark & Nos.</b>
			<table>
				<tr>
				  <col width="200">
					<td border="0"><?=wordwrap($hd['dlv_mark'],25,"<br>\n",TRUE);?></td>
				  </col>
				  <col width="130">
					<td align="right" border="0"><?=wordwrap($hd['dlv_nos'],14,"<br>\n",TRUE);?></td>
				  </col>
				</tr>
			</table>
		</td>
	</tr>
	
	<tr>
		<td colspan="3"><b>Notify Party</b><br><?=wordwrap($hd['dlv_notifyparty'],55,"<br>\n",TRUE);?></td>
		<td><b>Remarks</b><br><?=wordwrap($hd['dlv_remarks'],50,"<br>\n",TRUE);?></td>
	</tr>
	
	<tr>
	<col width="120">
		<td><b>Carrier / Vessel</b><br><?=$hd['dlv_carrier_vesel'];?></td>
	</col>
	<col width="120">
		<td><b>Voy No.</b><br><?=$hd['dlv_voyno'];?></td>
	</col>
	<col width="120">
		<td><b>Sailing on or about</b><br>
		<?php if($hd['dlv_sailingdate'] != "0000-00-00"){ ?>
			<?=date("d-M-Y",strtotime($hd['dlv_sailingdate']));?>
		<?php } ?>
		</td>
	</col>
	<col width="100">
		<td><b>Term / Method of Payment</b>
			<table>
				<tr>
				  <col width="200">
					<td border="0"><?=wordwrap($hd['dlv_payterms'],25,"<br>\n",TRUE);?></td>
				  </col>
				  <col width="130">
					<td border="0" align="right"><?=$hd['dlv_mop'];?></td>
				  </col>
				</tr>
			</table>
		</td>
	</col>
	</tr>
	</table>
	
	<table>
	<tr>
		<td colspan="2"><b>Port of Loading</b><br><?=$hd['dlv_portofloading'];?></td>
		<td colspan="2"><b>Port of Discharge</b><br><?=$hd['dlv_portofdischarge'];?></td>
		<td colspan="3"><b>Final Destination</b><br><?=wordwrap($hd['dlv_finaldestination'],37,"<br>\n",TRUE);?></td>
	</tr>
	
	<tr align="center" valign="middle">
		<col width="100">
		<td><b>Number of<br>Package</b></td>
		</col>
		<col width="230">
		<td><b>Description of Goods</b></td>
		</col>
		<col width="60">
		<td><b>Qty</b></td>
		</col>
		<col width="60">
		<td><b>Unit</b></td>
		</col>
		<col width="70">
		<td><b>N/W<br>(Kg)</b></td>
		</col>
		<col width="70">
		<td><b>G/W<br>(Kg)</b></td>
		</col>
		<col width="100">
		<td><b>Measurement(M3)</b></td>
		</col>
	</tr>
    <?php
	$no=0; $t_netto=0; $t_brutto=0; $t_measure=0; $t_qty=0;
	$query = mysql_query("SELECT SUM(a.dlvd_qtypackages) qtypackages ,a.dlvd_unitpackages,a.dlvd_model,a.dlvd_pono,b.prod_code,b.prod_name,b.prod_sat, 
						  SUM(a.dlvd_qty) qty,a.dlvd_unitprice, SUM(a.dlvd_netto) netto, SUM(a.dlvd_bruto) bruto, SUM(a.dlvd_measure) measure
						  FROM delivery_detail a
						  LEFT JOIN product b ON b.id=a.dlvd_prodid
						  WHERE a.dlvd_hid='$dlv_id' GROUP BY a.dlvd_unitpackages, a.dlvd_prodid ORDER BY b.prod_name ASC ");
	while($data=mysql_fetch_object($query)){
		$no++;
		$t_netto = $t_netto+$data->netto;
		$t_brutto = $t_brutto+$data->bruto;
		$t_measure = $t_measure+$data->measure;
		$t_qty = $t_qty+$data->qty;
		$prodsat = $data->prod_sat;
	?>
	 <tr>
		<td align="center" style="border-bottom:none;"><?=$data->qtypackages;?> <?=$data->dlvd_unitpackages;?></td>
		<td style="border-bottom:none;"><?=wordwrap($data->prod_name,30,"<br>\n",TRUE);?><br>
			Model : <?=wordwrap($data->dlvd_model,30,"<br>\n",TRUE);?> <br>
			P/N : <?=$data->prod_code;?><br>
			P/O No :<?=$data->dlvd_pono;?> </td>
		<td align="right" style="border-bottom:none;"><?=number_format($data->qty,2,'.',',');?></td>
		<td align="center" style="border-bottom:none;"><?=$data->prod_sat;?></td>
		<td align="right" style="border-bottom:none;"><?=number_format($data->netto,3,'.',',');?></td>
		<td align="right" style="border-bottom:none;"><?=number_format($data->bruto,3,'.',',');?></td>
		<td align="right" style="border-bottom:none;"><?=number_format($data->measure,2,'.',',');?></td>
	</tr>
	<tr >
	<td height="30" style="border-bottom:none;"></td>
	<td style="border-bottom:none;"></td>
	<td style="border-bottom:none;"></td>
	<td style="border-bottom:none;"></td>
	<td style="border-bottom:none;"></td>
	<td style="border-bottom:none;"></td>
	<td style="border-bottom:none;"></td>
	</tr>	
	<?php } ?>
	<tr>
		<td colspan="7"></td>
	</tr>
	<tr>
		<td colspan="2" align="center" height="25" valign="middle">Total</td>
		<td align="right" valign="middle"><?=number_format($t_qty,3,'.',',');?></td>
		<td align="center" valign="middle"><?=$prodsat;?></td>
		<td align="right" valign="middle"><?=number_format($t_netto,3,'.',',');?></td>
		<td align="right" valign="middle"><?=number_format($t_brutto,3,'.',',');?></td>
		<td align="right" valign="middle"><?=number_format($t_measure,2,'.',',');?></td>
	</tr>
	<tr>
		<td colspan="4" valign="middle">
			<?php echo nl2br(str_replace('','',htmlspecialchars($hd['dlv_notepl']))); ?>
		</td>
		<td colspan="3"><br><br><br>
			<table border="0" align="center">
				<tr>
					<td border="0" height="80"></td>
				</tr>
				<tr>
					<td border="0" align="center"><?=$hd['dlv_signed'];?></td>
				</tr>
				<tr>
					<td border="0">Sign By----------------------------------------------</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</div>
</body>
</html>


<?php   
	 #PDF
	 $filename="Invoice.pdf";   
	 $content = ob_get_clean();  
	 require_once('../function/html2pdf/html2pdf.class.php');  
	 try  
	 {  
	  $html2pdf = new HTML2PDF('P','A4','en', false, 'ISO-8859-15',array(5, 5, 5, 5));
	  $html2pdf->setDefaultFont('Arial');  
	  $html2pdf->writeHTML($content, isset($_GET['vuehtml']));  
	  $html2pdf->Output($filename);  
	 }  
	 catch(HTML2PDF_exception $e) { echo $e; }
?> 
