<?php 
include "../include/config.php"; 
include "../function/inc_function.php"; 
$start_date = get_startdate();
$end_date   = get_enddate();
$start_date_m2year = start_date_m2year($start_date);
$wo_id = isset($_REQUEST['wo_id']) ? $_REQUEST['wo_id'] :'';
$hd   = mysql_fetch_object(mysql_query("SELECT a.*, b.dept_name, c.prod_code, c.prod_name, c.prod_sat FROM workorder a INNER JOIN departement b ON b.id=a.wo_deptid 
	    INNER JOIN product c ON c.id=a.wo_prodid WHERE a.id='$wo_id'"));
$comp = mysql_fetch_object(mysql_query("SELECT prof_city FROM profil"));									  
?>
<html>
<head>
<link rel='stylesheet' type='text/css' href="../include/css/print_styles.css" />	
</head>
<body>
<div id="popup">
<h3 align="center">WORK ORDER</h1>
<h5>Nomor:<?=$hd->wo_no;?>  Tanggal:<?=DateToIndo($hd->wo_date);?> </h5>
<hr size="3"></hr>
<p id="text1">
	Dari :<br>
	<?=$hd->wo_pic;?><br>
	<?=$hd->dept_name;?><br><br>
	No.Lot: <?=$hd->wo_lotno;?><br><br>
	Bersama dengan ini kami sampaikan telah proses produksi sejumlah barang sebagai berikut:<br>
    Barang Jadi : <?=$hd->prod_code;?>-<?=$hd->prod_name;?> Sejumlah : <?=number_format($hd->wo_qty,2,'.',',');?> <?=$hd->prod_sat;?><br><br>
	Rincian Bahan Baku dan Bahan Penolong sebagai berikut:
</p>
<table width="100%">
	<tr>
	</tr>
	<tr>
		<th>No.</th>
		<th>Kode Barang</th>
		<th>Nama Barang</th>
		<th>Jumlah</th>
		<th>Harga</th>
		<th>Nilai</th>
		<th>Satuan</th>
	</tr>
    <?php
	$no=0;$tprice=0;
	$query = mysql_query("SELECT a.*, b.prod_code,b.prod_name,b.prod_sat, b.prod_cat
						  FROM workorder_detail a
						  INNER JOIN product b ON b.id=a.wod_prodid
						  WHERE a.wod_hid='$wo_id' ");
	while($data=mysql_fetch_object($query)){
		$no++;
		if($data->prod_cat==1 || $data->prod_cat==6){
			$iprice = get_unitprice_bb($start_date_m2year,$end_date,$data->wod_prodid);
		}elseif($data->prod_cat==3){
			$iprice = 0;
		}elseif($data->prod_cat==5){
			$iprice = 0;
		}
		$price  = $iprice*$data->wod_qty;
		$tprice = $tprice+$price;
	?>
	 <tr>
		<td align="center"><?=$no;?>.</td>
		<td><?=$data->prod_code;?></td>
		<td><?=$data->prod_name;?></td>
		<td align="right"><?=number_format($data->wod_qty,2,'.',',');?></td>
		<td align="right"><?=number_format($iprice,2,'.',',');?></td>
		<td align="right"><?=number_format($price,2,'.',',');?></td>
		<td align="center"><?=$data->prod_sat;?></td>
	</tr>	
	<?php } ?>
	<tr>
		<td colspan="5" align="right">Total</td>
		<td align="right"><?=number_format($tprice,2,'.',',');?></td>
		<td align="right">&nbsp;</td>
	</tr>
</table>
<p id="text1">
	Atas perhatian dan kerjasamanya disampaikan terima kasih.<br>
	<?=$comp->prof_city;?>, <?=DateToIndo($hd->wo_date);?><br>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hormat kami <br><br><br><br><br><br>
	(............................................)
	
</p>
</div>
</body>
</html>
