<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-BC23&Act=CANCEL';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function get_click(){
		form.action ='?page=Proses-Pemasukan-BC23&Act=GET40';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function temp_click(){
		form.action ='?page=Proses-Pemasukan-BC23&Act=TEMP40';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function process_click(){
		form.action ='?page=Proses-Pemasukan-BC23&Act=PROCESS40';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function inventory_click(){
		form.action ='?page=Proses-Pemasukan-BC23&Act=INV40';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function reg_click(){
		form.action ='?page=Proses-Pemasukan-BC23&Act=REG40';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function delete_click(){
		form.action ='?page=Proses-Pemasukan-BC23&Act=DEL_TEMP40';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function deldettemp_click(id, id_header, no_urut){
		form.action ='?page=Proses-Pemasukan-BC23&Act=DELDET_TEMP40&id_temp='+id+'&tmp_id_header='+id_header+'&tmp_no_urut='+no_urut;
		form.method = 'post';
		form.submit();			
		return true;
	}
	$(document).ready(function(){
		var inc = {
			source: "json_inc.php",					
			select: function(event, ui){
				$("#kd_barang").val(ui.item.kd_barang); 
				$("#nm_barang").val(ui.item.nm_barang); 
				$("#satuan").val(ui.item.satuan); 
			},
			minLength: 1
		};
		$("#kd_barang").autocomplete(inc);		
	});
	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">UPLOAD DATA PEMASUKAN BC 2.3 DARI CEISA 4.0</th>
	</tr>
	<tr>
		<td>Masukan Dokumen :
			<input name="userfile" type="file"> 
		</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="TEMPLATE" style="cursor:pointer" onClick="template_click();" />-->
		</td>
	</tr>
</table>
<!--GET-->
<?php
#Cek stock
$start_date2 = get_startdate2($inv);
$end_date2   = get_enddate2($inv);
$bulan2    	 = substr($start_date2,5,2);
$tahun2  	 = substr($start_date2,0,4);
if ($Act=="GET40"){ ?>
	<div class="scroll">
	<table width="100%">
		<tr bgcolor="#CCCCCC">
			<td align="center">No</td>
			<td align="center">No Aju</td>
			<td align="center">No Urut</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>
		</tr>
	<?php
	$no=1; $tqtyg=0; $tpriceg=0;
	$q=mysql_query("SELECT * FROM log_incoming WHERE log_status=86 AND jenis_dokpab='BC 2.3' ORDER BY no_aju, no_urut ASC");
    while($d=mysql_fetch_array($q)){
		if($d['valuta']=="IDR"){$nilai = $d['cif_rupiah'];}else{$nilai = $d['non_rupiah'];}
		$tqtyg = $tqtyg + $d['jumlah'];
		$tpriceg = $tpriceg + $nilai;
	?>	
		<tr onMouseOver="setTrColor(this, '#FF9900');">
			<td align="center"><?=$no;?>.</td>
			<td><?=$d['no_aju'];?></td>
			<td><?=$d['no_urut'];?></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($nilai,2,'.',',');?></td>
		</tr>		
	<?php $no++; } ?>
	<tr bgcolor="#CCFFFF">
		<td colspan="10">Total</td>
		<td align="right"><?=number_format($tqtyg,2,'.',',');?></td>
		<td>&nbsp;</td>
		<td align="right"><?=number_format($tpriceg,2,'.',',');?></td>
	</tr>
	</table>
	</div>
<?php }elseif(($Act=="TEMP40") || ($Act=="REG40") || ($Act=="SEARCH")){ ?>
	<div class="scroll">
	<table width="220%">
		<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">No Aju</td>	
			<td align="center">Tgl Aju</td>	
			<td align="center">No Urut</td>	
			<td align="center">Jenis</td>
			<td align="center">Nomor</td>
			<td align="center">Tanggal</td>				
			<td align="center">Nama Pemasok</td>
			<td align="center">Kode Barang</td>
			<td align="center">Nama Barang</td>
			<td align="center">Tipe</td>	
			<td align="center">Ukuran</td>	
			<td align="center">Satuan</td>	
			<td align="center">Kategori</td>		
			<td align="center">Jumlah</td>
			<td align="center">Valuta</td>
			<td align="center">Nilai</td>
			<td align="center">No Masuk</td>	
			<td align="center">Tgl Masuk</td>
			<td align="center">No Invoice</td>	
			<td align="center">Tgl Invoice</td>		
			<td align="center">No SPPB</td>	
			<td align="center">Tgl SPPB</td>	
			<!--<td align="center">Tipe & Harga Dokumen</td>-->	
		</tr>
	<?php
	$no=0; $tqty=0; $tprice=0;
	$qr=mysql_query("SELECT * FROM log_incoming WHERE log_status=86 AND jenis_dokpab='BC 2.3' ORDER BY no_aju, no_urut ASC");
    while($d=mysql_fetch_array($qr)){
		$no++;
		#$kode = str_replace(' ', '',strtoupper($d['kode']));
		$vc = mysql_fetch_array(mysql_query("SELECT id,prod_code,prod_cat FROM product WHERE prod_code='$d[kode]' AND prod_cat<>'100'"));
		#$stock = get_stock($start_date2,$end_date2,$bulan2,$tahun2,$vc['id'],$vc['prod_cat'],$inv);		
		$val_date = get_validationdate2($d['tgl_dokpab'],$inv);
		$val_jns = mysql_fetch_array(mysql_query("SELECT doc_type FROM document_type WHERE doc_type='$d[jenis_dokpab]' AND doc_status=1"));
		if(!empty($val_jns['doc_type'])){
			$bgcolorjns ="#000000";
		}else{
			$bgcolorjns ="#FF6A6A";
		}
		if(empty($vc['prod_code'])){
			$s_kode ="NO";
			$bgcolor0 ="#FF6A6A";
		}else{
			$s_kode ="READY";
			$bgcolor0 ="#000000";
		}		
		if($val_date=="NO"){
			$colord ="#FF0000";
		}else{
			$colord ="#000000";
		}
		if($d['jumlah'] <=0){
			$bgcolorjml ="#FF6A6A";
		}else{
			$bgcolorjml ="#000000";
		}
		$tqty = $tqty + $d['jumlah'];		
		#validasi item komplit/tidak/no aju
		$val_item = get_valincoming_upl40($d['no_dokpab'],$d['jenis_dokpab'],$inv);
		if($d['valuta']=="IDR"){$nilai = $d['nilai'];}else{$nilai = $d['non_rupiah'];}
		$tprice = $tprice + $nilai;
		
	?>	
	    <tr onMouseOver="setTrColor(this, '#FF9900');">
			<td align="center"><?=$no;?>.</td>
			<td align="center">
				<?php if($val_item =="NO"){	?>
					&nbsp;
				<?php }else{ ?>
					<input type="checkbox" id="pilih[<?=$d['id'];?>]" name="pilih[<?=$d['id'];?>]" value="<?=$d['id'];?>">
				<?php }?>
			</td>
			<td align="center"><?=$d['no_aju'];?></td>
			<td align="center"><?=$d['tgl_aju'];?></td>
			<td align="center"><?=$d['no_urut'];?></td>
			<td align="center"><font color="<?=$bgcolorjns;?>"><?=$d['jenis_dokpab'];?></font></td>
			<td align="center"><?=$d['no_dokpab'];?></td>
			<td align="center"><font color="<?=$colord;?>"><?=$d['tgl_dokpab'];?></font></td>		
			<td align="left"><?=$d['nm_pemasok'];?></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="tipe[<?=$d['id'];?>]" value="<?=$d['tipe'];?>" size="15" style="background-color:<?=$bgcolor0;?>">
				<?php }else{ ?>
					<?=$d['tipe'];?>
				<?php } ?>
			</td>
			<td>
				<?php if($s_kode =="NO"){ ?>
				<input type="text" name="ukuran[<?=$d['id'];?>]" value="<?=$d['ukuran'];?>" size="15" style="background-color:<?=$bgcolor0;?>">
				<?php }else{ ?>
					<?=$d['ukuran'];?>
				<?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 prod_code='$d[kode]'",$inv));
					echo $cat['prod_cat'];	   
				} ?>
			</td>			
			<td align="right"><font color="<?=$bgcolorjml;?>"><?=number_format($d['jumlah'],2,'.',',');?></font></td>
			<td align="center"><?=$d['valuta'];?></td>
			<td align="right"><?=number_format($nilai,2,'.',',');?></td>	
			<td align="center"><?=$d['no_bpb'];?></td>
			<td align="center"><?=$d['tgl_bpb'];?></td>
			<td align="center"><?=$d['no_invoice'];?></td>
			<td align="center"><?=$d['tgl_invoice'];?></td>
			<td align="center"><?=$d['no_sppb'];?></td>
			<td align="center"><?=$d['tgl_sppb'];?></td>
			<!--<td align="right"><?=$d['tipe_dokumen'];?> & <?=$d['harga_dokumen'];?></td>-->				
		</tr>	
		<?php } ?>	
		<tr bgcolor="#CCFFFF">
			<td colspan="15">Total</td>
			<td align="right"><?=number_format($tqty,2,'.',',');?></td>
			<td>&nbsp;</td>
			<td align="right"><?=number_format($tprice,2,'.',',');?></td>
			<td colspan="6">&nbsp;</td>
		</tr>
	</table>
	</div>
<?php }elseif(($Act=="PROCESS40") || ($Act=="DELDET_TEMP40")){ ?>
	<div class="scroll">
	<table width="100%">
		<tr bgcolor="#CCCCCC">
			<td align="center">No</td>
			<td align="center">No Aju</td>
			<td align="center">No Urut</td>
			<td align="center">Jenis</td>
			<td align="center">Nomor</td>
			<td align="center">Tanggal</td>
			<td align="center">Penerima</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">Action</td>
		</tr>
	<?php
	$no=1; $tqtyp=0; $tpricep=0;	
	$qr=mysql_query("SELECT * FROM log_incoming WHERE log_status=87 AND jenis_dokpab='BC 2.3' ORDER BY no_aju, no_urut ASC");
    while($d=mysql_fetch_array($qr)){
		$prd = mysql_fetch_array(mysql_query("SELECT id,prod_cat FROM product WHERE prod_code='$d[kode]' AND prod_cat<>100"));
		$vc  = mysql_fetch_array(mysql_query("SELECT a.outh_sjno FROM outgoing a INNER JOIN outgoing_detail b ON b.outd_hid=a.id 
											 WHERE a.id_header='$d[id_header]' AND b.no_urut='$d[no_urut]' AND a.outh_status<>100"));
		$stock = get_stock($start_date2,$end_date2,$bulan2,$tahun2,$prd['id'],$prd['prod_cat'],$inv);										 
		if(empty($vc['outh_sjno'])){
			$color ="#FF0000";
		}else{
			$color ="#000000";
		}
		if($d['valuta']=="IDR"){$nilai = $d['cif_rupiah'];}else{$nilai = $d['non_rupiah'];}
		$tqtyp = $tqtyp + $d['jumlah'];
		$tpricep = $tpricep + $nilai;
	?>	
		<tr onMouseOver="setTrColor(this, '#FF9900');">
			<td align="center"><?=$no;?>.</td>
			<td align="center"><font color="<?=$color;?>"><?=$d['no_aju'];?></font></td>
			<td align="center"><font color="<?=$color;?>"><?=$d['no_urut'];?></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><?=$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($nilai,2,'.',',');?></td>
			<td align="center">
				<img src="images/delete.png" title="BATAL" style="cursor:pointer" onClick="deldettemp_click('<?=$d['id'];?>','<?=$d['id_header'];?>',
				'<?=$d['no_urut'];?>');">	
			</td>
		</tr>		
	<?php $no++; } ?>
	<tr bgcolor="#CCFFFF">
		<td colspan="10">Total</td>
		<td align="right"><?=number_format($tqtyp,2,'.',',');?></td>
		<td>&nbsp;</td>
		<td align="right"><?=number_format($tpricep,2,'.',',');?></td>
		<td>&nbsp;</td>
	</tr>
	</table>
	</div>
<?php } ?>
</form>
</html> 
