<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-Upload-Jurnal&Act=CANCEL';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function get_click(){
		form.action ='?page=Proses-Upload-Jurnal&Act=GET';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function temp_click(){
		form.action ='?page=Proses-Upload-Jurnal&Act=TEMP';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function process_click(){
		form.action ='?page=Proses-Upload-Jurnal&Act=PROCESS';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function inventory_click(){
		form.action ='?page=Proses-Upload-Jurnal&Act=INV';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function reg_click(){
		form.action ='?page=Proses-Upload-Jurnal&Act=REG';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function delete_click(){
		form.action ='?page=Proses-Upload-Jurnal&Act=DEL_TEMP';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function deldettemp_click(id){
		form.action ='?page=Proses-Upload-Jurnal&Act=DELDET_TEMP&id_temp='+id;
		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;
			}
		}
	}
	function search_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-Upload-Jurnal&Act=SEARCH';
			form.method = 'post';
			form.submit();			
			return true;
		}
	}
	function detail_dokumen_click(id_header,no_urut,status){
		window.open("popup/detail_dokumen_asal.php?id_header="+id_header+"&no_urut="+no_urut+"&status="+status,"mywindow","menubar=1,scrollbars=1,resizable=1,width=1050,height=1000");
	}
	function excel_click(){
		form.action ='./transaksi/interface/excel_temp_bc25.php';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function template_click(){
		form.action ='./transaksi/akuntansi/template_upload_jurnal.php';
		form.method = 'post';
		form.submit();		
		return true;
	}
</script>
</head>
<form action="#" method="post" name="form" target="_self" enctype="multipart/form-data">
<table>
	<tr>
		<th colspan="2">UPLOAD DATA JURNAL UMUM</th>
	</tr>
	<tr>
		<td>Masukan File Data :
			<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=="GET"){ ?>
	<div class="scroll">
	<table width="100%">
		<tr bgcolor="#CCCCCC">
			<td align="center">No</td>
			<td align="center">No Jurnal</td>
			<td align="center">Tanggal Jurnal</td>
			<td align="center">No Referensi</td>
			<td align="center">Kode Sup/Cust</td>
			<td align="center">Nama Sup/Cust</td>
			<td align="center">Kode Account</td>
			<td align="center">Nama Account</td>
			<td align="center">Nilai</td>
		</tr>
	<?php
	$no=1; $tqtyg=0; 
	$q=mysql_query("SELECT * FROM jurnal_temp WHERE jurnald_status=50 ORDER BY id ASC",$inv);
    while($d=mysql_fetch_array($q)){
		$tqtyg = $tqtyg + $d['jurnald_amount'];
	?>	
		<tr onMouseOver="setTrColor(this, '#FF9900');">
			<td align="center"><?=$no;?>.</td>
			<td><?=$d['jurnal_no'];?></td>
			<td><?=$d['jurnal_date'];?></td>
			<td><?=$d['jurnal_invno'];?></td>
			<td><?=$d['jurnal_suppcode'];?></td>
			<td><?=$d['jurnal_suppname'];?></td>
			<td><?=$d['jurnald_acctno'];?></td>
			<td><?=$d['jurnald_acctname'];?></td>
			<td align="right"><?=number_format($d['jurnald_amount'],2,'.',',');?></td>
		</tr>		
	<?php $no++; } ?>
	<tr bgcolor="#CCFFFF">
		<td colspan="8">Total</td>
		<td align="right"><?=number_format($tqtyg,2,'.',',');?></td>
	</tr>
	</table>
	</div>
<?php }elseif(($Act=="TEMP") || ($Act=="REG") || ($Act=="SEARCH")){ ?>
	<div class="scroll">
	<table width="200%">
		<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 Jurnal</td>	
			<td align="center">Tgl Jurnal</td>	
			<td align="center">No Referensi</td>	
			<td align="center">Kode Sup/Cust</td>
			<td align="center">Nama Sup/Cust</td>		
			<td align="center">Tipe Jurnal</td>
			<td align="center">Tipe Pembayaran</td>
			<td align="center">Tgl JT</td>
			<td align="center">Currency</td>		
			<td align="center">Kurs</td>
			<td align="center">Pos Data</td>
			<td align="center">Kode Account</td>
			<td align="center">Nama Account</td>
			<td align="center">Keterangan</td>
			<td align="center">Debit</td>	
			<td align="center">Kredit</td>
			<td align="center">Balance</td>
		</tr>
	<?php
	$no=0; $tqty=0; $tdebit=0; $tkredit=0;
	$qr=mysql_query("SELECT *, CASE WHEN jurnal_post='Debit' THEN jurnald_amount ELSE 0 END AS debit,
				     CASE WHEN jurnal_post='Kredit' THEN jurnald_amount ELSE 0 END AS kredit 
				     FROM jurnal_temp WHERE jurnald_status=50 ORDER BY id ASC",$inv);
    while($d=mysql_fetch_array($qr)){
		$no++;		
		#jurnal tipe	
		if(strtoupper($d['jurnal_type']) !="AR" && strtoupper($d['jurnal_type']) !="AP" && strtoupper($d['jurnal_type']) !="OT" &&
		   strtoupper($d['jurnal_type']) !="PT" && strtoupper($d['jurnal_type']) !="HT"){
			$colorvtype ="#FF0000";
		}else{
			$colorvtype ="#000000";
		}	
		#sup/cust
		$vsup = mysql_fetch_array(mysql_query("SELECT a.id, a.kode, a.nama, snpwp, CONCAT_WS(' - ', a.kode, a.nama) codename, a.tipe FROM
			(SELECT id, sup_code kode, sup_name nama, sup_npwp snpwp, 'SUP' tipe FROM supplier WHERE sup_status=10
			UNION
			SELECT id, cust_code kode, cust_name nama, cust_npwp snpwp, 'CUS' tipe FROM customer WHERE cust_status=10) a
			WHERE a.kode='$d[jurnal_suppcode]' ORDER BY a.nama ASC ",$inv));
		if(empty($vsup['id'])){
			$colorvsup ="#FF0000";
		}else{
			$colorvsup ="#000000";
		}	
		#paytype	
		if(strtoupper($d['jurnal_ptype']) !="KAS" && strtoupper($d['jurnal_ptype']) !="BANK" && strtoupper($d['jurnal_ptype']) !="HUTANG" && 
		   strtoupper($d['jurnal_ptype']) !="PIUTANG" && strtoupper($d['jurnal_ptype']) !="LAIN-LAIN"){
			$colorvptype ="#FF0000";
		}else{
			$colorvptype ="#000000";
		}	
		#pos data	
		if(strtoupper($d['jurnal_post']) !="DEBIT" && strtoupper($d['jurnal_post']) !="KREDIT"){
			$colorvpos ="#FF0000";
		}else{
			$colorvpos ="#000000";
		}
		#jurnal account
		$vacctno = mysql_fetch_array(mysql_query("SELECT j_acctno FROM jurnal_master  WHERE j_acctno='$d[jurnald_acctno]' ORDER BY j_acctno ASC",$inv));
		if(empty($vacctno['j_acctno'])){
			$colorvacctno ="#FF0000";
		}else{
			$colorvacctno ="#000000";
		}
		#jurnal no
		$vjrlno = mysql_fetch_array(mysql_query("SELECT jurnal_no FROM jurnal WHERE jurnal_no='$d[jurnal_no]'",$inv));
		if(!empty($vjrlno['jurnal_no'])){
			$colorvjrlno ="#FF0000";
		}else{
			$colorvjrlno ="#000000";
		}
		#periode aktif
		if(substr($d['jurnal_date'],0,4) != $thn_acct){
			$colorvjrldt ="#FF0000";
		}else{
			$colorvjrldt ="#000000";
		}
		$val_item = get_valjurnal_upl($d['jurnal_no'],$inv);
		$tqty    = $tqty + $d['jurnald_amount'];
		$tdebit  = $tdebit + $d['debit'];
		$tkredit = $tkredit + $d['kredit'];
		$tbalance = number_format($tkredit,2,'.','')-number_format($tdebit,2,'.','');
		
	?>	
	    <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'];?>">
					<input type="hidden" name="debit[<?=$d['id'];?>]" value="<?=$d['debit'];?>">
					<input type="hidden" name="kredit[<?=$d['id'];?>]" value="<?=$d['kredit'];?>">
				<?php }?>
			</td>
			<td align="center"><font color="<?=$colorvjrlno;?>"><?=$d['jurnal_no'];?></font></td>
			<td align="center"><font color="<?=$colorvjrldt;?>"><?=$d['jurnal_date'];?></font></td>
			<td align="center"><?=$d['jurnal_invno'];?></td>	
			<td align="left"><font color="<?=$colorvsup;?>"><?=$d['jurnal_suppcode'];?></font></td>	
			<td align="left"><font color="<?=$colorvsup;?>"><?=$d['jurnal_suppname'];?></font></td>
			<td><font color="<?=$colorvtype;?>"><?=$d['jurnal_type'];?></font></td>
			<td><font color="<?=$colorvptype;?>"><?=$d['jurnal_ptype'];?></font></td>
			<td align="center"><?=$d['jurnal_duedate'];?></td>					
			<td align="center"><?=$d['jurnal_currency'];?></td>
			<td align="right"><?=number_format($d['jurnal_rate'],2,'.',',');?></td>
			<td align="center"><font color="<?=$colorvpos;?>"><?=$d['jurnal_post'];?></font></td>
			<td align="center"><font color="<?=$colorvacctno;?>"><?=$d['jurnald_acctno'];?></font></td>
			<td><font color="<?=$colorvacctno;?>"><?=$d['jurnald_acctname'];?></font></td>
			<td><?=$d['jurnald_desc'];?></td>					
			<td align="right"><?=number_format($d['debit'],2,'.',',');?></td>
			<td align="right"><?=number_format($d['kredit'],2,'.',',');?></td>
			<td align="right">&nbsp;</td>
		</tr>	
		<?php } ?>	
		<tr bgcolor="#CCFFFF">
			<td colspan="16">Total</td>
			<td align="right"><?=number_format($tdebit,2,'.',',');?></td>
			<td align="right"><?=number_format($tkredit,2,'.',',');?></td>
			<td align="center">
				<input type="text" size="4" name="tbalance" value="<?=number_format($tbalance,2,'.',',');?>" style="text-align:center" readonly="true">
			</td>
		</tr>
	</table>
	</div>
<?php }elseif(($Act=="PROCESS") || ($Act=="DELDET_TEMP")){ ?>
	<div class="scroll">
	<table width="100%">
		<tr bgcolor="#CCCCCC">
			<td align="center">No</td>
			<td align="center">No Jurnal</td>
			<td align="center">Tanggal Jurnal</td>
			<td align="center">No Referensi</td>
			<td align="center">Kode Sup/Cust</td>
			<td align="center">Nama Sup/Cust</td>
			<td align="center">Kode Account</td>
			<td align="center">Nama Account</td>
			<td align="center">Debit</td>	
			<td align="center">Kredit</td>
			<td align="center">Balance</td>
			<td align="center">Action</td>
		</tr>
	<?php
	$no=1; $tqtyp=0; $tdebit=0; $tkredit=0;
	$qr=mysql_query("SELECT * , CASE WHEN jurnal_post='Debit' THEN jurnald_amount ELSE 0 END AS debit,
				     CASE WHEN jurnal_post='Kredit' THEN jurnald_amount ELSE 0 END AS kredit 
					 FROM jurnal_temp WHERE jurnald_status=500 ORDER BY id ASC",$inv);
    while($d=mysql_fetch_array($qr)){
		$tqtyp = $tqtyp + $d['jurnald_amount'];
		$tdebit  = $tdebit + $d['debit'];
		$tkredit = $tkredit + $d['kredit'];
		$tbalance = number_format($tkredit,2,'.','')-number_format($tdebit,2,'.','');
	?>	
		<tr onMouseOver="setTrColor(this, '#FF9900');">
			<td align="center"><?=$no;?>.</td>
			<td><?=$d['jurnal_no'];?></td>
			<td><?=$d['jurnal_date'];?></td>
			<td><?=$d['jurnal_invno'];?></td>
			<td><?=$d['jurnal_suppcode'];?></td>
			<td><?=$d['jurnal_suppname'];?></td>
			<td><?=$d['jurnald_acctno'];?></td>
			<td><?=$d['jurnald_acctname'];?></td>
			<td align="right"><?=number_format($d['debit'],2,'.',',');?></td>
			<td align="right"><?=number_format($d['kredit'],2,'.',',');?></td>
			<td align="right">&nbsp;</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="8">Total</td>
		<td align="right"><?=number_format($tdebit,2,'.',',');?></td>
		<td align="right"><?=number_format($tkredit,2,'.',',');?></td>
		<td align="center">
			<input type="text" size="4" name="tbalance" value="<?=number_format($tbalance,2,'.',',');?>" style="text-align:center" readonly="true">
		</td>
		<td>&nbsp;</td>
	</tr>
	</table>
	</div>
<?php } ?>
</form>
</html> 
