<?php
include "../include/config.php";
include "../function/inc_function.php";
$prodid = $_GET['prodid'];

?>
<table width="100%" border="0">
    <tr>
  		<td align="center"><strong>DATA HISTORY BARANG</strong></td>
    </tr>	
</table>
<br>
<!-- Master Barang -->
<table width="100%" border="0" bgcolor="#000">	
	<tr bgcolor="#ccffff">
		<td colspan="3">1. Master Barang</td>
	</tr>
	<tr bgcolor="#D1D1D1">
		<th align="center">Kode Barang</th>
		<th align="center">Nama Barang</th>
		<th align="center">Satuan</th>
	</tr>
	<?php 
		$qm = mysql_query("SELECT * FROM product WHERE id='$prodid'");
		while($dm=mysql_fetch_array($qm)){
	?>
	<tr bgcolor="#fff">
		<td align="center"><?=$dm['prod_code'];?></td>
		<td align="center"><?=$dm['prod_name'];?></td>
		<td align="center"><?=$dm['prod_sat'];?></td>
	</tr>
		<?php } ?>
</table>
<br>
<!-- Pemasukan -->
<table width="100%" border="0" bgcolor="#000">	
	<tr bgcolor="#ccffff">
		<td colspan="4">2. Pemasukan</td>
	</tr>
	<tr bgcolor="#D1D1D1">
		<th align="center">Jenis</th>
		<th align="center">Nomor</th>
		<th align="center">Tanggal</th>
		<th align="center">Jumlah</th>
	</tr>
	<?php $tinc = 0;
		$qinc = mysql_query("SELECT a.inch_doctype, a.inch_docno, a.inch_docdate, b.incd_qty FROM incoming a INNER JOIN incoming_detail b ON b.incd_hid=a.id 
		WHERE a.inch_status=20 AND a.inch_doctype NOT IN('NONDOK','NONDOKUMEN','NONCUSTOMS') AND b.incd_prodid='$prodid' ORDER BY a.inch_docdate DESC");
		while($dinc=mysql_fetch_array($qinc)){
			$tinc = $tinc + $dinc['incd_qty'];
	?>
	<tr bgcolor="#fff">
		<td align="center"><?=$dinc['inch_doctype'];?></td>
		<td align="center"><?=$dinc['inch_docno'];?></td>
		<td align="center"><?=$dinc['inch_docdate'];?></td>
		<td align="right"><?=number_format($dinc['incd_qty'],2,'.',',');?></td>
	</tr>
		<?php } ?>
	<tr bgcolor="#ffffcc">
		<td align="right" colspan="3">TOTAL</td>
		<td align="right"><?=number_format($tinc,2,'.',',');?></td>
	</tr>	
</table>
<br>
<!-- Transfer Produksi -->
<table width="100%" border="0" bgcolor="#000">	
	<tr bgcolor="#ccffff">
		<td colspan="4">3. Pengeluaran : Transfer ke Produksi</td>
	</tr>
	<tr bgcolor="#D1D1D1">
		<th align="center">Nomor</th>
		<th align="center">Tanggal</th>
		<th align="center">Jumlah</th>
	</tr>
	<?php $ttrf= 0;
		$qtrf = mysql_query("SELECT a.trf_spbno, a.trf_spbdate, b.trfd_qty FROM transfer a INNER JOIN transfer_detailexbc b ON b.trfd_hid=a.id 
		WHERE a.trf_status=20 AND b.trfd_prodid='$prodid' ORDER BY a.trf_spbdate DESC");
		while($dtrf=mysql_fetch_array($qtrf)){
			$ttrf = $ttrf + $dtrf['trfd_qty'];
	?>
	<tr bgcolor="#fff">
		<td align="center"><?=$dtrf['trf_spbno'];?></td>
		<td align="center"><?=$dtrf['trf_spbdate'];?></td>
		<td align="right"><?=number_format($dtrf['trfd_qty'],2,'.',',');?></td>
	</tr>
		<?php } ?>
	<tr bgcolor="#ffffcc">
		<td align="right" colspan="2">TOTAL</td>
		<td align="right"><?=number_format($ttrf,2,'.',',');?></td>
	</tr>	
</table>
<br>
<!-- Pengeluaran -->
<table width="100%" border="0" bgcolor="#000">	
	<tr bgcolor="#ccffff">
		<td colspan="4">4. Pengeluaran : dengan dokumen Beacukai</td>
	</tr>
	<tr bgcolor="#D1D1D1">
		<th align="center">Jenis</th>
		<th align="center">Nomor</th>
		<th align="center">Tanggal</th>
		<th align="center">Jumlah</th>
	</tr>
	<?php $tout = 0;
		$qout = mysql_query("SELECT a.outh_doctype, a.outh_docno, a.outh_docdate, b.outd_qty FROM outgoing a INNER JOIN outgoing_detail b ON b.outd_hid=a.id 
		WHERE a.outh_status=20 AND a.outh_doctype NOT IN('NONDOK','NONDOKUMEN','SCRAP') AND b.outd_prodid='$prodid' ORDER BY a.outh_docdate DESC");
		while($dout=mysql_fetch_array($qout)){
			$tout = $tout + $dout['outd_qty'];
	?>
	<tr bgcolor="#fff">
		<td align="center"><?=$dout['outh_doctype'];?></td>
		<td align="center"><?=$dout['outh_docno'];?></td>
		<td align="center"><?=$dout['outh_docdate'];?></td>
		<td align="right"><?=number_format($dout['outd_qty'],2,'.',',');?></td>
	</tr>
		<?php } ?>
	<tr bgcolor="#ffffcc">
		<td align="right" colspan="3">TOTAL</td>
		<td align="right"><?=number_format($tout,2,'.',',');?></td>
	</tr>	
</table>
<br>
<!-- Workorder -->
<table width="100%" border="0" bgcolor="#000">	
	<tr bgcolor="#ccffff">
		<td colspan="7">5. Pemakaian : dengan workorder</td>
	</tr>
	<tr bgcolor="#D1D1D1">
		<th align="center">Nomor</th>
		<th align="center">Tanggal</th>
		<th align="center">Jumlah</th>
		<th align="center">Kode Brg Jadi</th>
		<th align="center">Nama Brg Jadi</th>
		<th align="center">Satuan Brg Jadi</th>
		<th align="center">Jumlah Brg Jadi</th>
	</tr>
	<?php $two = 0;
		$qwo = mysql_query("SELECT a.wo_no, a.wo_date, c.wod_qty, a.wo_qty, d.prod_code, d.prod_name, d.prod_sat
		FROM workorder a INNER JOIN workorder_detail c ON c.wod_hid=a.id INNER JOIN product d ON d.id=a.wo_prodid
		WHERE a.wo_status=20 AND c.wod_prodid='$prodid' ORDER BY a.wo_date DESC");
		while($dwo=mysql_fetch_array($qwo)){
			$two = $two + $dwo['wod_qty'];
	?>
	<tr bgcolor="#fff">
		<td align="center"><?=$dwo['wo_no'];?></td>
		<td align="center"><?=$dwo['wo_date'];?></td>
		<td align="right"><?=number_format($dwo['wod_qty'],2,'.',',');?></td>
		<td align="center"><?=$dwo['prod_code'];?></td>
		<td align="left"><?=$dwo['prod_name'];?></td>
		<td align="center"><?=$dwo['prod_sat'];?></td>
		<td align="right"><?=number_format($dwo['wo_qty'],2,'.',',');?></td>
	</tr>
		<?php } ?>
	<tr bgcolor="#ffffcc">
		<td align="right" colspan="2">TOTAL</td>
		<td align="right"><?=number_format($two,2,'.',',');?></td>
		<td colspan="4">&nbsp;</td>
	</tr>	
</table>
<!--	
<table width="100%" border="1">	
  <tr>
    <th align="center" bgcolor="#9df990" colspan="4">BARANG</th>
	<th align="center" bgcolor="#D1D1D1" colspan="7">TRANSFER</th>
  </tr>
  <tr>
    <th align="center" bgcolor="#9df990">NO</th>
	<th align="center" bgcolor="#9df990">KODE BARANG</th>
	<th align="center" bgcolor="#9df990">NAMA BARANG</th>
	<th align="center" bgcolor="#9df990">SATUAN</th>	
	<th align="center" bgcolor="#D1D1D1">NO</th>
	<th align="center" bgcolor="#D1D1D1">NOMOR TRANSFER</th>
    <th align="center" bgcolor="#D1D1D1">TGL TRANSFER</th>
	<th align="center" bgcolor="#D1D1D1">JUMLAH</th>
	<th align="center" bgcolor="#D1D1D1">PIC</th>
	<th align="center" bgcolor="#D1D1D1">USERID</th>
	<th align="center" bgcolor="#D1D1D1">TGL INPUT</th>
  </tr>
	<?php	
		$no = 1;
		$qd = mysql_query("SELECT b.trfd_prodid, c.prod_code,c.prod_name,c.prod_sat FROM transfer a
		  INNER JOIN transfer_detailexbc b ON b.trfd_hid=a.id INNER JOIN product c ON c.id=b.trfd_prodid
		  WHERE a.trf_spbdate BETWEEN '$fromdate' AND '$todate' AND a.trf_status=20 AND a.trf_category =1
		 GROUP BY b.trfd_prodid, c.prod_code,c.prod_name,c.prod_sat ORDER BY c.prod_code ASC");		
		while($dd=mysql_fetch_object($qd)){			
		?> 
		 <tr>
			<td align="center"><?=$no;?></td>			
			<td align="left"><?=$dd->prod_code;?></td>
			<td align="left"><?=$dd->prod_name;?></td>			
			<td align="center"><?=$dd->prod_sat;?></td>				
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>		
		</tr>
	  <?php 
		$no2=1;
		$qd2 = mysql_query("SELECT a.trf_spbno, a.trf_spbdate,b.trfd_qty, a.trf_pic, a.trf_inputby, a.trf_inputdate FROM transfer a
		  INNER JOIN transfer_detailexbc b ON b.trfd_hid=a.id INNER JOIN product c ON c.id=b.trfd_prodid
		  WHERE a.trf_spbdate BETWEEN '$fromdate' AND '$todate' AND a.trf_status=20 AND a.trf_category =1 AND b.trfd_prodid='$dd->trfd_prodid'
		  ORDER BY a.trf_spbdate ASC");
		while($dd2=mysql_fetch_object($qd2)){	  
	  ?>
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td align="center"><?=$no2;?></td>			
			<td align="center"><?=$dd2->trf_spbno;?></td>
			<td align="center"><?=$dd2->trf_spbdate;?></td>			
			<td align="right"><?=number_format($dd2->trfd_qty,2,'.','');?></td>
			<td align="left"><?=$dd2->trf_pic;?></td>
			<td align="left"><?=$dd2->trf_inputby;?></td>			
			<td align="center"><?=$dd2->trf_inputdate;?></td>	
		</tr>
	  
	  <?php $no2++;} $no++; }  ?>	
</table>

<table width="100%" border="0">
    <tr>
  		<td colspan="11" align="left"><strong>HISTORY WORK ORDER</strong></td>
    </tr>
</table>	
<table width="100%" border="1">	
  <tr>
    <th align="center" bgcolor="#9df990" colspan="4">BARANG</th>
	<th align="center" bgcolor="#D1D1D1" colspan="7">WORK ORDER</th>
  </tr>
  <tr>
    <th align="center" bgcolor="#9df990">NO</th>
	<th align="center" bgcolor="#9df990">KODE BARANG</th>
	<th align="center" bgcolor="#9df990">NAMA BARANG</th>
	<th align="center" bgcolor="#9df990">SATUAN</th>	
	<th align="center" bgcolor="#D1D1D1">NO</th>
	<th align="center" bgcolor="#D1D1D1">NOMOR WO</th>
    <th align="center" bgcolor="#D1D1D1">TGL WO</th>
	<th align="center" bgcolor="#D1D1D1">JUMLAH</th>
	<th align="center" bgcolor="#D1D1D1">PIC</th>
	<th align="center" bgcolor="#D1D1D1">USERID</th>
	<th align="center" bgcolor="#D1D1D1">TGL INPUT</th>
  </tr>
	<?php	
		$no3 = 1;
		$qd3 = mysql_query("SELECT b.trfd_prodid, c.prod_code,c.prod_name,c.prod_sat FROM transfer a
		  INNER JOIN transfer_detailexbc b ON b.trfd_hid=a.id INNER JOIN product c ON c.id=b.trfd_prodid
		  WHERE a.trf_spbdate BETWEEN '$fromdate' AND '$todate' AND a.trf_status=20 AND a.trf_category =1
		 GROUP BY b.trfd_prodid, c.prod_code,c.prod_name,c.prod_sat ORDER BY c.prod_code ASC");		
		while($dd3=mysql_fetch_object($qd3)){			
		?> 
		 <tr>
			<td align="center"><?=$no3;?></td>			
			<td align="left"><?=$dd3->prod_code;?></td>
			<td align="left"><?=$dd3->prod_name;?></td>			
			<td align="center"><?=$dd3->prod_sat;?></td>				
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>		
		</tr>
	  <?php 
		$no4=1;
		$qd4 = mysql_query("SELECT a.wo_no, a.wo_date, c.wod_qty, a.wo_pic, a.wo_inputby, a.wo_inputdate
		FROM workorder a 
		INNER JOIN workorder_detail c ON c.wod_hid=a.id INNER JOIN product d ON d.id=c.wod_prodid
		WHERE a.wo_date BETWEEN '$fromdate' AND '$todate' AND a.wo_status=20 AND c.wod_prodid='$dd3->trfd_prodid' ORDER BY a.wo_date ASC");
		while($dd4=mysql_fetch_object($qd4)){	  
	  ?>
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td align="center"><?=$no4;?></td>			
			<td align="center"><?=$dd4->wo_no;?></td>
			<td align="center"><?=$dd4->wo_date;?></td>			
			<td align="right"><?=number_format($dd4->wod_qty,2,'.','');?></td>
			<td align="left"><?=$dd4->wo_pic;?></td>
			<td align="left"><?=$dd4->wo_inputby;?></td>			
			<td align="center"><?=$dd4->wo_inputdate;?></td>	
		</tr>
	  
	  <?php $no4++;} $no3++; }  ?>	
</table>-->