<?php
	include "include/config_tpb.php"; 
?>
<html>
<head>
<script type="text/javascript">
	function setTrColor(obj, color)
	{
		obj.style.backgroundColor=color; 
		obj.onmouseout = function(){
				obj.style.backgroundColor=''; 
		}
	}
	$(document).ready(function(){
		$("#start_date").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	$(document).ready(function(){
		$("#end_date").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});		
	function cancel_click(){
		form.action ='?page=Proses-Pemasukan-BC262&Act=CANCEL';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function get_click(){
		var jenis_dokpab = $("#jenis_dokpab").val();
	    var jdp = jenis_dokpab.replace(' ', '%20');
		var start = document.getElementById("start_date").value;
		var end = document.getElementById("end_date").value;
		if(jdp=="BLANK"){
			alert("Jenis dokumen pabean harus dipilih terlebih dahulu");
			form.jenis_dokpab2.focus();
			return false;
		}else if(start==""){
			alert("Tanggal Awal tidak boleh kosong");
			form.start_date.focus();
			return false;
		}else if(end==""){
			alert("Tanggal akhir tidak boleh kosong");
			form.end_date.focus();
			return false;
		}else{
			form.action ='?page=Proses-Pemasukan-BC262&Act=GET';
			form.method = 'post';
			form.submit();			
			return true;
		}
	}
	function temp_click(){
		var jenis_dokpab = $("#jenis_dokpab").val();
	    var jdp = jenis_dokpab.replace(' ', '%20');
		if(jdp=="BLANK"){
			alert("Jenis dokumen pabean harus dipilih terlebih dahulu");
			form.jenis_dokpab2.focus();
			return false;
		}else{
			form.action ='?page=Proses-Pemasukan-BC262&Act=TEMP';
			form.method = 'post';
			form.submit();			
			return true;
		}	
	}
	function process_click(){
		var jenis_dokpab = $("#jenis_dokpab").val();
	    var jdp = jenis_dokpab.replace(' ', '%20');
		if(jdp=="BLANK"){
			alert("Jenis dokumen pabean harus dipilih terlebih dahulu");
			form.jenis_dokpab2.focus();
			return false;
		}else{
			form.action ='?page=Proses-Pemasukan-BC262&Act=PROCESS';
			form.method = 'post';
			form.submit();			
			return true;
		}	
	}
	function inventory_click(){
		form.action ='?page=Proses-Pemasukan-BC262&Act=INV';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function reg_click(){
		var jenis_dokpab = $("#jenis_dokpab").val();
	    var jdp = jenis_dokpab.replace(' ', '%20');
		if(jdp=="BLANK"){
			alert("Jenis dokumen pabean harus dipilih terlebih dahulu");
			form.jenis_dokpab2.focus();
			return false;
		}else{
			form.action ='?page=Proses-Pemasukan-BC262&Act=REG';
			form.method = 'post';
			form.submit();			
			return true;
		}	
	}
	function delete_click(){
		form.action ='?page=Proses-Pemasukan-BC262&Act=DEL_TEMP';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function deldettemp_click(id){
		form.action ='?page=Proses-Pemasukan-BC262&Act=DELDET_TEMP&id_temp='+id;
		form.method = 'post';
		form.submit();			
		return true;
	}
	function excel_click(){
		form.action ='./transaksi/interface/excel_temp_bc262.php';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function checkAll()
	{
		var inputs = document.getElementsByTagName('input');
		for (var i = 0; i< inputs.length; i++) {
			if (inputs[i].type == 'checkbox') {
				inputs[i].checked =true;
			}
		}
	}
	function uncheckAll()
	{
		var inputs = document.getElementsByTagName('input');
		for (var i = 0; i< inputs.length; i++) {
			if (inputs[i].type == 'checkbox') {
				inputs[i].checked =false;
			}
		}
	}
</script>
</head>
<form action="#" method="post" name="form" target="_self" enctype="multipart/form-data">
<table>
	<tr>
		<th colspan="2">INTERFACE DARI CEISA - BC 2.6.2</th>
	</tr>
	<tr>
		<td>Tanggal Dokumen :
			<input type="hidden" name="jenis_dokpab" id="jenis_dokpab" value="BC 2.6.2">
			<input type="text" id="start_date" name="start_date" value="<?=$start_date;?>" size="10" readonly> ~
		    <input type="text" id="end_date" name="end_date" value="<?=$end_date;?>" size="10" readonly>
		</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td colspan="2">
			<input type="button" name="get" value="GET" style="cursor:pointer" onClick="get_click();">
			<input type="button" name="temp" value="TEMP" style="cursor:pointer" onClick="temp_click();">
			<input type="button" name="process" value="PROCESS" style="cursor:pointer" onClick="process_click();">
			<input type="button" name="inventory" value="SEND TO INVENTORY" style="cursor:pointer" onClick="inventory_click();">
			<input type="button" name="register" value="REG. NEW CODE" style="cursor:pointer" onClick="reg_click();">
			<input type="button" name="delete" value="DELETE" style="cursor:pointer" onClick="delete_click();">
			<input type="button" name="batal" value="CLOSE" style="cursor:pointer" onClick="cancel_click();" />
			<input type="button" name="excel" value="EXCEL TEMP" style="cursor:pointer" onClick="excel_click();" />
		</td>
	</tr>
</table>	
<!--GET-->
<?php
if ($Act=="GET"){ 
	$maxid = mysql_fetch_array(mysql_query("SELECT MAX(flag) flag FROM log_incoming",$inv));
	$flag  = $maxid['flag']+1;
	$qr=mysql_query("SELECT a.id, a.nomor_aju as no_aju, date(a.tanggal_aju) tgl_aju,
							b.uraian_dokumen_pabean as jenis_dokumen, 
							a.nomor_daftar as no_dokumen, date(a.tanggal_daftar) as tgl_dokumen,
							a.nama_pengirim as nama_pemasok, d.nomor_dokumen as no_do, date(d.tanggal_dokumen) as tgl_do,
							e.nomor_dokumen as no_invoice, date(e.tanggal_dokumen) as tgl_invoice,
							c.seri_barang as no_urut, c.kode_barang, c.uraian as nama_barang, c.kode_satuan as satuan,
							c.jumlah_satuan as jumlah, a.kode_valuta as valuta, c.cif_rupiah as nilai_pab, c.netto as berat, c.cif,
							date(f.tanggal_jatuh_tempo) as jatuh_tempo, (g.nomor_dokumen) as no_izin,
							h.nomor_dokumen as no_dokpab_asal, date(h.tanggal_dokumen) as tgl_dokpab_asal, i.tgl_bpb, j.uraian_status,
							k.nomor_kontainer as no_kontainer, k.uraian_tipe_kontainer as tipe_kontainer,
							k.uraian_ukuran_kontainer as ukuran_kontainer, l.jumlah_kemasan, l.kode_jenis_kemasan as kode_kemasan, l.uraian_kemasan as jenis_kemasan,
							a.id_pengirim, m.uraian_tujuan_pemasukan tujuan, n.nomor_dokumen no_bpb, n.tanggal_dokumen tgl_bpb2, 
							o.nomor_dokumen no_kontrak, o.tanggal_dokumen tgl_kontrak,p.nomor_dokumen no_persetujuan, p.tanggal_dokumen tgl_persetujuan,
							a.ndpbm, c.spesifikasi_lain
						FROM tpb_header a
						INNER JOIN referensi_dokumen_pabean b ON b.kode_dokumen_pabean=a.kode_dokumen_pabean
						INNER JOIN tpb_barang c ON c.id_header=a.id
						LEFT JOIN (select id_header, nomor_dokumen, tanggal_dokumen from tpb_dokumen where kode_jenis_dokumen=217 group by id_header) AS d ON d.id_header=a.id
						LEFT JOIN (select id_header, nomor_dokumen, tanggal_dokumen from tpb_dokumen where kode_jenis_dokumen=380 group by id_header) AS e ON e.id_header=a.id
					    LEFT JOIN tpb_jaminan f ON f.id_header=a.id    
						LEFT JOIN (select id_header, nomor_dokumen, tanggal_dokumen from tpb_dokumen where kode_jenis_dokumen IN(03037) group by 
						id_header) AS g ON g.id_header=a.id 		
						LEFT JOIN (select id_header, nomor_dokumen, tanggal_dokumen from tpb_dokumen where kode_jenis_dokumen IN(261) group by 
						id_header) AS h ON h.id_header=a.id 	
						LEFT JOIN (SELECT id_header, date(a.waktu_status) as tgl_bpb 
								   FROM tpb_detil_status a
								   INNER JOIN referensi_status b ON b.kode_status=a.kode_status AND b.kode_dokumen=262  AND b.kode_status=80
								   GROUP BY id_header,date(a.waktu_status))as i ON i.id_header=a.id		
						LEFT JOIN referensi_status j ON j.kode_status=a.kode_status AND j.kode_dokumen=a.kode_dokumen_pabean
						LEFT JOIN (SELECT a.id_header, a.nomor_kontainer, b.uraian_tipe_kontainer, c.uraian_ukuran_kontainer FROM tpb_kontainer a
								   INNER JOIN referensi_tipe_kontainer b ON b.kode_tipe_kontainer=a.kode_tipe_kontainer
								   INNER JOIN referensi_ukuran_kontainer c ON c.kode_ukuran_kontainer=a.kode_ukuran_kontainer
								   GROUP BY a.id_header) as k ON k.id_header=a.id	
						LEFT JOIN (SELECT a.id_header, a.jumlah_kemasan, a.kode_jenis_kemasan, b.uraian_kemasan FROM tpb_kemasan a 
								   INNER JOIN referensi_kemasan b ON b.kode_kemasan=a.kode_jenis_kemasan
								   GROUP BY a.id_header) as l ON l.id_header=a.id	
						LEFT JOIN referensi_tujuan_pemasukan m ON m.kode_dokumen=262 AND m.kode_tujuan_pemasukan=a.kode_tujuan_pemasukan
						LEFT JOIN (select id_header, nomor_dokumen, tanggal_dokumen from tpb_dokumen where kode_jenis_dokumen=640 group by id_header) AS n ON n.id_header=a.id
            			LEFT JOIN (select id_header, nomor_dokumen, tanggal_dokumen from tpb_dokumen where kode_jenis_dokumen=315 group by id_header) AS o ON o.id_header=a.id
            			LEFT JOIN (select id_header, nomor_dokumen, tanggal_dokumen from tpb_dokumen where (kode_jenis_dokumen BETWEEN '03010' AND '03065') OR kode_jenis_dokumen IN('911') group by id_header) AS p ON p.id_header=a.id
					WHERE a.kode_dokumen_pabean=262 AND date(a.tanggal_daftar) BETWEEN '$start_date' AND '$end_date'
					ORDER BY a.nomor_aju, c.seri_barang ASC");
	while($d=mysql_fetch_array($qr)){
		$no_kont =""; $tipe_kont=""; $size_kont="";
		$qknt = mysql_query("SELECT a.nomor_kontainer, b.uraian_tipe_kontainer, c.uraian_ukuran_kontainer FROM tpb_kontainer a
								   INNER JOIN referensi_tipe_kontainer b ON b.kode_tipe_kontainer=a.kode_tipe_kontainer
								   INNER JOIN referensi_ukuran_kontainer c ON c.kode_ukuran_kontainer=a.kode_ukuran_kontainer where a.id_header='$d[id]'");
		while($dknt=mysql_fetch_array($qknt)){
			$no_kont 	= $no_kont."".$dknt['nomor_kontainer']."-";
			$tipe_kont  = $tipe_kont."".$dknt['uraian_tipe_kontainer']."-";
			$size_kont  = $size_kont."".$dknt['uraian_ukuran_kontainer']."-";
		}						   
		$nokont = substr($no_kont, 0,-1);
		$tipekont = substr($tipe_kont, 0,-1);
		$sizekont = substr($size_kont, 0,-1);
		#Validasi sudah interface / belum
		$qc=mysql_fetch_array(mysql_query("SELECT id FROM log_incoming WHERE id_header='$d[id]' AND no_urut='$d[no_urut]' AND log_status <> 5",$inv));
		if(empty($qc['id'])){
			mysql_query("INSERT INTO log_incoming SET no_bpb='$d[no_bpb]', tgl_bpb='$d[tgl_dokumen]', no_invoice='$d[no_invoice]', tgl_invoice='$d[tgl_invoice]', no_do='$d[no_do]', 
						 kode='$d[kode_barang]', jumlah='$d[jumlah]', valuta='$d[valuta]', nilai='$d[nilai_pab]', log_status=1, log_input=now(), flag='$flag',
						 log_user='$user_id', nm_pemasok='".mysql_real_escape_string($d['nama_pemasok'])."', jenis_dokpab='$d[jenis_dokumen]', no_dokpab='$d[no_dokumen]', tgl_dokpab='$d[tgl_dokumen]',
						 nm_barang='".mysql_real_escape_string($d['nama_barang'])."', satuan='$d[satuan]', berat='$d[berat]', no_aju='$d[no_aju]', tgl_aju='$d[tgl_aju]', no_urut='$d[no_urut]',
						 jatuh_tempo='$d[jatuh_tempo]', no_izin='$d[no_izin]', no_dokpab_asal='$d[no_dokpab_asal]', tgl_dokpab_asal='$d[tgl_dokpab_asal]',
						 no_kontainer='$nokont', ukuran_kontainer='$sizekont', tipe_kontainer='$tipekont', jumlah_kemasan='$d[jumlah_kemasan]', 
						 kode_kemasan='$d[kode_kemasan]', jenis_kemasan='$d[jenis_kemasan]', nilai_inv='$d[cif]',
						 status_dokpab='$d[uraian_status]', id_header='$d[id]',id_pemasok='$d[id_pengirim]',tujuan='$d[tujuan]',
						 no_kontrak='$d[no_kontrak]', tgl_kontrak='$d[tgl_kontrak]', no_persetujuan='$d[no_persetujuan]', 
						 tgl_persetujuan='$d[tgl_persetujuan]', inch_rate='$d[ndpbm]', incd_scno='$d[spesifikasi_lain]'",$inv);
		}else{
			mysql_query("UPDATE log_incoming SET no_bpb='$d[no_bpb]', tgl_bpb='$d[tgl_dokumen]', no_invoice='$d[no_invoice]', tgl_invoice='$d[tgl_invoice]', no_do='$d[no_do]', 
						 kode='$d[kode_barang]', jumlah='$d[jumlah]', valuta='$d[valuta]', nilai='$d[nilai_pab]', log_user='$user_id', nm_pemasok='".mysql_real_escape_string($d['nama_pemasok'])."', 
						 nm_barang='".mysql_real_escape_string($d['nama_barang'])."', satuan='$d[satuan]', berat='$d[berat]', no_aju='$d[no_aju]', tgl_aju='$d[tgl_aju]', jatuh_tempo='$d[jatuh_tempo]', 
						 no_izin='$d[no_izin]', no_dokpab_asal='$d[no_dokpab_asal]', tgl_dokpab_asal='$d[tgl_dokpab_asal]', status_dokpab='$d[uraian_status]',
						 no_kontainer='$nokont', ukuran_kontainer='$sizekont', tipe_kontainer='$tipekont', jumlah_kemasan='$d[jumlah_kemasan]', 
						 kode_kemasan='$d[kode_kemasan]', jenis_kemasan='$d[jenis_kemasan]', nilai_inv='$d[cif]', id_pemasok='$d[id_pengirim]',tujuan='$d[tujuan]',
						 no_kontrak='$d[no_kontrak]', tgl_kontrak='$d[tgl_kontrak]', no_persetujuan='$d[no_persetujuan]', 
						 tgl_persetujuan='$d[tgl_persetujuan]', inch_rate='$d[ndpbm]', incd_scno='$d[spesifikasi_lain]' 
						 WHERE id_header='$d[id]' AND log_status=1 AND no_urut='$d[no_urut]' ",$inv);
		}			 
	}
?>	
	<div class="scroll">
	<table width="150%">
		<tr bgcolor="#CCCCCC">
			<td align="center">No</td>
			<td align="center">Nomor Aju</td>
			<td align="center">No Urut</td>
			<td align="center">Tanggal Aju</td>
			<td align="center">Jenis Dokumen</td>
			<td align="center">Nomor Dokumen</td>
			<td align="center">Tanggal Dokumen</td>
			<td align="center">Pemasok</td>
			<td align="center">Kode Barang</td>
			<td align="center">Nama Barang</td>
			<td align="center">Satuan</td>
			<td align="center">Jumlah</td>
			<td align="center">Valuta</td>
			<td align="center">Nilai</td>
			<td align="center">Berat</td>
		</tr>
	<?php
	$no=1; $tqtyg=0; $tpriceg=0;
	$q=mysql_query("SELECT * FROM log_incoming WHERE log_status=1 AND tgl_dokpab BETWEEN '$start_date' AND '$end_date' 
	                AND jenis_dokpab='$jenis_dokpab' ORDER BY no_aju, no_urut ASC",$inv);
    while($d=mysql_fetch_array($q)){
		$tqtyg = $tqtyg + $d['jumlah'];
		$tpriceg = $tpriceg + $d['nilai'];
	?>	
		<tr onMouseOver="setTrColor(this, '#FF9900');">
			<td align="center"><?=$no;?>.</td>
			<td><?=$d['no_aju'];?></td>
			<td align="center"><?=$d['no_urut'];?></td>
			<td><?=$d['tgl_aju'];?></td>
			<td><?=$d['jenis_dokpab'];?></td>
			<td><?=$d['no_dokpab'];?></td>
			<td><?=$d['tgl_dokpab'];?></td>
			<td><?=$d['nm_pemasok'];?></td>
			<td><?=$d['kode'];?></td>
			<td><?=$d['nm_barang'];?></td>
			<td><?=$d['satuan'];?></td>
			<td align="right"><?=number_format($d['jumlah'],2,'.',',');?></td>
			<td align="center"><?=$d['valuta'];?></td>
			<td align="right"><?=number_format($d['nilai'],2,'.',',');?></td>
			<td align="right"><?=number_format($d['berat'],2,'.',',');?></td>
		</tr>		
	<?php $no++; } ?>
	<tr bgcolor="#CCFFFF">
		<td colspan="11">Total</td>
		<td align="right"><?=number_format($tqtyg,2,'.',',');?></td>
		<td>&nbsp;</td>
		<td align="right"><?=number_format($tpriceg,2,'.',',');?></td>
		<td>&nbsp;</td>
	</tr>
	</table>
	</div>
<?php }elseif(($Act=="TEMP") || ($Act=="REG") ){ ?>
	<div class="scroll"> 
	<table width="300%"> 
		<tr bgcolor="#CCCCCC">
			<td align="center">No</td>
			<td align="center">Pilih<br>
				<input type="radio" name="check" onClick="checkAll();">C
			    <input type="radio" name="check" onClick="uncheckAll();">U
			</td>
			<td align="center">Tgl Masuk</td>
			<td align="center">Nomor Aju</td>
			<td align="center">No Urut</td>
			<td align="center">Tanggal Aju</td>
			<td align="center">Kode</td>
			<td align="center">Nama Barang</td>
			<td align="center">Satuan</td>
			<td align="center">Kategori</td>
			<td align="center">Status Dokumen</td>
			<td align="center">No Masuk</td>			
			<td align="center">Jenis Dokumen</td>
			<td align="center">Nomor Dokumen</td>
			<td align="center">Tanggal Dokumen</td>
			<td align="center">Pemasok</td>
			<td align="center">No Invoice</td>
			<td align="center">Tgl Invoice</td>			
			<td align="center">Jumlah</td>
			<td align="center">Valuta</td>
			<td align="center">Nilai Pabean</td>
			<td align="center">Berat</td>			
			<td align="center">Jatuh Tempo</td>
			<td align="center">No Izin</td>	
			<td align="center">Nomor Dokumen Asal</td>
			<td align="center">Tanggal Dokumen Asal</td>	
			<td align="center">No Kontainer</td>
			<td align="center">Tipe Kontainer</td>
			<td align="center">Ukuran Kontainer</td>
			<td align="center">Kode Kemasan</td>
			<td align="center">Jenis Kemasan</td>
			<td align="center">Jumlah Kemasan</td>							
		</tr>
	<?php
	$no=1; $tqty=0; $tprice=0;
	$qr=mysql_query("SELECT * FROM log_incoming WHERE log_status=1 AND jenis_dokpab='$jenis_dokpab' AND tgl_dokpab BETWEEN '$start_date' AND '$end_date' ORDER BY no_aju, no_urut ASC",$inv);
    while($d=mysql_fetch_array($qr)){
		$kode = str_replace(' ', '',strtoupper($d['kode']));
		$vc = mysql_fetch_array(mysql_query("SELECT prod_code FROM product WHERE prod_code='$d[kode]' AND prod_cat <> '100'",$inv));
		$val_date = get_validationdate2($d['tgl_dokpab'],$inv);
		if(empty($vc['prod_code'])){
			$s_kode ="NO";
			$bgcolor0 ="#FF6A6A";
		}else{
			$s_kode ="READY";
			$bgcolor0 ="#000000";
		}
		if($d['status_dokpab']=="SPPD"){
			$bgcolor ="#000000";
		}else{
			$bgcolor ="#FF6A6A";
		}
		if($val_date=="NO"){
			$colord ="#FF0000";
		}else{
			$colord ="#000000";
		}
		$tqty = $tqty + $d['jumlah'];
		$tprice = $tprice + $d['nilai'];
		#Validasi komplit per nomor aju
		$val_item = get_valincoming($d['id_header'],$inv);
	?>	
		<tr onMouseOver="setTrColor(this, '#FF9900');">
			<td align="center"><?=$no;?>.</td>
			<td align="center">
				<?php 
					//if($s_kode =="NO" || $colord =="#FF0000" ){ 
					if($val_item=="NO"){
				?>
					&nbsp;
				<?php 
					//}elseif($s_kode =="READY"){ 
					}else{
				?>
					<input type="checkbox" id="pilih[<?=$d['id'];?>]" name="pilih[<?=$d['id'];?>]" value="<?=$d['id'];?>">
					
					<input type="hidden" name="tgl_dokpab2[<?=$d['id'];?>]" value="<?=$d['tgl_dokpab'];?>">
				<?php } ?>
			</td>
			<td align="center"><input type="text" name="tgl_bpb2[<?=$d['id'];?>]" value="<?=$d['tgl_bpb'];?>" size="10"></td>
			<td align="center"><?=$d['no_aju'];?></td>
			<td align="center"><?=$d['no_urut'];?></td>
			<td align="center"><?=$d['tgl_aju'];?></td>
			<td>
				<?php if($s_kode =="NO"){ ?>
				<input type="hidden" name="pilih_reg[<?=$d['id'];?>]" value="<?=$d['id'];?>">
				<input type="text" name="kd_barang[<?=$d['id'];?>]" value="<?=$d['kode'];?>" size="15" style="background-color:<?=$bgcolor0;?>">
				<?php }else{ ?>
					<?=$d['kode'];?>
				<?php } ?>
			</td>
			<td>
				<?php if($s_kode =="NO"){ ?>
				<input type="text" name="nm_barang[<?=$d['id'];?>]" value="<?=$d['nm_barang'];?>" size="35" style="background-color:<?=$bgcolor0;?>">
				<?php }else{ ?>
					<?=$d['nm_barang'];?>
				<?php } ?>
			</td>
			<td>
				<?php if($s_kode =="NO"){ ?>
				<input type="text" name="satuan[<?=$d['id'];?>]" value="<?=$d['satuan'];?>" size="4" style="background-color:<?=$bgcolor0;?>">
				<?php }else{ ?>
					<?=$d['satuan'];?>
				<?php } ?>
			</td>
			<td align="left">
				<?php if($s_kode =="NO"){ ?>
					<select name="kd_kategori[<?=$d['id'];?>]" style="background-color:<?=$bgcolor0;?>">	
						<option value="BLANK" selected="selected">PILIH</option>			
						<?php
						  $sql = mysql_query("SELECT * FROM product_category",$inv);
						  while ($data = mysql_fetch_array($sql)) {
							if ($data['id']== $kd_kategori) {
								$cek = " selected";
							} else { $cek=""; }
							echo "<option value='$data[id]' $cek>$data[prod_cat]</option>";
						  }
						  $sqlData ="";
						?>
					</select>
				<?php }else{ 
					$cat = mysql_fetch_array(mysql_query("SELECT b.prod_cat FROM product a INNER JOIN product_category b ON b.id=a.prod_cat 
					       WHERE replace(upper(prod_code),' ','')='$kode'",$inv));
					echo $cat['prod_cat'];	   
				} ?>
			</td>
			<td align="center"><?=$d['status_dokpab'];?></td>
			<td align="left"><?=$d['no_bpb'];?></td>			
			<td align="center"><?=$d['jenis_dokpab'];?></td>
			<td align="center"><?=$d['no_dokpab'];?></td>
			<td align="center"><font color="<?=$colord;?>"><?=$d['tgl_dokpab'];?></font></td>
			<td><?=$d['nm_pemasok'];?></td>
			<td align="center"><?=$d['no_invoice'];?></td>
			<td align="center"><?=$d['tgl_invoice'];?></td>			
			<td align="right"><?=number_format($d['jumlah'],2,'.',',');?></td>
			<td align="center"><?=$d['valuta'];?></td>
			<td align="right"><?=number_format($d['nilai'],2,'.',',');?></td>
			<td align="right"><?=number_format($d['berat'],2,'.',',');?></td>			
			<td align="center"><?=$d['jatuh_tempo'];?></td>
			<td align="center"><?=$d['no_izin'];?></td>
			<td align="center"><?=$d['no_dokpab_asal'];?></td>
			<td align="center"><?=$d['tgl_dokpab_asal'];?></td>
			<td align="center"><?=$d['no_kontainer'];?></td>
			<td align="center"><?=$d['tipe_kontainer'];?></td>
			<td align="center"><?=$d['ukuran_kontainer'];?></td>
			<td align="center"><?=$d['kode_kemasan'];?></td>
			<td align="center"><?=$d['jenis_kemasan'];?></td>
			<td align="center"><?=number_format($d['jumlah_kemasan'],2,'.',',');?></td>			
		</tr>		
	<?php $no++; } ?>
	<tr bgcolor="#CCFFFF">
			<td colspan="18">Total</td>
			<td align="right"><?=number_format($tqty,2,'.',',');?></td>
			<td>&nbsp;</td>
			<td align="right"><?=number_format($tprice,2,'.',',');?></td>
			<td colspan="10">&nbsp;</td>
		<td>
	</table>
	</div>
<?php }elseif(($Act=="PROCESS") || ($Act=="DELDET_TEMP")){ ?>
	<div class="scroll">
	<table width="150%">
		<tr bgcolor="#CCCCCC">
			<td align="center">No</td>	
			<td align="center">Tgl Masuk</td>	
			<td align="center">No Aju</td>
			<td align="center">No Urut</td>
			<td align="center">Tanggal Aju</td>
			<td align="center">Jenis</td>
			<td align="center">Nomor</td>
			<td align="center">Tanggal</td>
			<td align="center">Pemasok</td>
			<td align="center">Kode</td>
			<td align="center">Nama Barang</td>
			<td align="center">Satuan</td>
			<td align="center">Jumlah</td>
			<td align="center">Valuta</td>
			<td align="center">Nilai</td>
			<td align="center">Berat</td>
			<td align="center">Status</td>
			<td align="center">Action</td>
		</tr>
	<?php
	$no=1; $tqtyp=0; $tpricep=0;
	$qr=mysql_query("SELECT * FROM log_incoming WHERE log_status=2 AND jenis_dokpab='$jenis_dokpab' ORDER BY no_aju, no_urut ASC",$inv);
    while($d=mysql_fetch_array($qr)){
	$cek = mysql_fetch_array(mysql_query("SELECT a.id FROM incoming a INNER JOIN incoming_detail b ON b.incd_hid=a.id 
		       WHERE a.id_header=$d[id_header] AND b.no_urut=$d[no_urut]",$inv));
		if(empty($cek['id'])){
			$color ="#FF0000";
		}else{
			$color ="#000000";
		}
		$tqtyp = $tqtyp + $d['jumlah'];
		$tpricep = $tpricep + $d['nilai'];
	?>	
		<tr onMouseOver="setTrColor(this, '#FF9900');">
			<td align="center"><?=$no;?>.</td>	
			<td align="center"><?=$d['tgl_bpb'];?></td>
			<td align="center"><font color="<?=$color;?>"><?=$d['no_aju'];?></font></td>
			<td align="center"><font color="<?=$color;?>"><?=$d['no_urut'];?></font></td>
			<td align="center"><font color="<?=$color;?>"><?=$d['tgl_aju'];?></font></td>
			<td><font color="<?=$color;?>"><?=$d['jenis_dokpab'];?></font></td>
			<td><font color="<?=$color;?>"><?=$d['no_dokpab'];?></font></td>
			<td><font color="<?=$color;?>"><?=$d['tgl_dokpab'];?></font></td>
			<td><?=$d['nm_pemasok'];?></td>
			<td><font color="<?=$color;?>"><?=$d['kode'];?></font></td>
			<td><?=$d['nm_barang'];?></td>
			<td><?=$d['satuan'];?></td>
			<td align="right"><?=number_format($d['jumlah'],2,'.',',');?></td>
			<td align="center"><?=$d['valuta'];?></td>
			<td align="right"><?=number_format($d['nilai'],2,'.',',');?></td>
			<td align="right"><?=number_format($d['berat'],2,'.',',');?></td>
			<td align="center"><?=$d['status_dokpab'];?></td>
			<td align="center">
				<img src="images/delete.png" title="BATAL" style="cursor:pointer" onClick="deldettemp_click('<?=$d['id'];?>');">	
			</td>
		</tr>		
	<?php $no++; } ?>
	<tr bgcolor="#CCFFFF">
		<td colspan="12">Total</td>
		<td align="right"><?=number_format($tqtyp,2,'.',',');?></td>
		<td>&nbsp;</td>
		<td align="right"><?=number_format($tpricep,2,'.',',');?></td>	
		<td colspan="2">&nbsp;</td>	
		<td colspan="2">&nbsp;</td>	
	</tr>
	</table>
	</div>
<?php } ?>
</form>
</html> 
