<html>
<head>
<script type="text/javascript"  language="javascript">
	$(document).ready(function(){
		$("#bpbdate").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	$(document).ready(function(){
		$("#invdate").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	$(document).ready(function(){
		$("#docdate").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	$(document).ready(function(){
		$("#tglaju").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	function popupsup(){
		window.open("popup/popup_supp.php?","mywindow","menubar=1,scrollbars=1,resizable=1,width=600,height=250");
	}
	function popupcust(){
		window.open("popup/popup_cust.php?","mywindow","menubar=1,scrollbars=1,resizable=1,width=600,height=250");
	}
	function openwindow1(){
		window.open("popup/popup_barang.php?","mywindow","menubar=1,scrollbars=1,resizable=1,width=600,height=250");
	}
	function pilih(id){
		var y  = document.getElementById("inch_purpid");		
		$.ajax({type: "POST",
			url: "transaksi/manual/load_purpose.php", 
			data: "docid="+id,
			success: function(result){			
			y.innerHTML="<option value='0'>PILIH</option>";
			arr_data = result.split("XX");
			if(id==1){ /*BC 2.3 */
				var option = document.createElement("option");
					option.text = arr_data[1];
					option.value = arr_data[0];
					y.add(option);
				var option = document.createElement("option");
					option.text = arr_data[3];
					option.value = arr_data[2];
					y.add(option);						
			}else if(id==3){ /*BC 2.6.2 */
				var option = document.createElement("option");
					option.text = arr_data[1];
					option.value = arr_data[0];
					y.add(option);
				var option = document.createElement("option");
					option.text = arr_data[3];
					option.value = arr_data[2];
					y.add(option);						
			}else if(id==4){ /*BC 2.7 */
				var option = document.createElement("option");
					option.text = arr_data[1];
					option.value = arr_data[0];
					y.add(option);
				var option = document.createElement("option");
					option.text = arr_data[3];
					option.value = arr_data[2];
					y.add(option);						
			}else if(id==5){ /*BC 4.0 */
				var option = document.createElement("option");
					option.text = arr_data[1];
					option.value = arr_data[0];
					y.add(option);					
			}
		}});
	}
	$(document).ready(function(){
		var inc = {
			source: "transaksi/akuntansi/json_transaksi_jurnal.php",					
			select: function(event, ui){
				$("#acctno").val(ui.item.j_acctno); 
				$("#acctname").val(ui.item.j_name1); 
				/*$("#acctdesc").val(ui.item.j_name2); */
			},
			minLength: 1
		};
		$("#acctnod").autocomplete(inc);		
	});	
	function currency_click(currency){
		var rate ='<?=$rate;?>';
		if(currency=="IDR"){
			$("#jurnal_rate").val(0);
		}else{
			$("#jurnal_rate").val(rate);
		}
	 }
	 function save_click(){
		var thn_acct    = $("#thn_acct").val();
		var jurnal_date = document.getElementsByName("jurnal_date")[0].value;
		var p_date      = jurnal_date.substr(0,4);
		if(p_date != thn_acct){
			alert("Tanggal jurnal "+jurnal_date+"\n tidak sama dengan periode aktif "+thn_acct);
			form.jurnal_date.focus();
			return false;
		}else if(form.jurnal_no.value==""){
			alert("Silakan isi no jurnal.");
			form.jurnal_no.focus();
			return false;
		}else if(form.jurnal_type.value==0){
			alert("Silakan pilih Tipe Jurnal.");
			form.jurnal_type.focus();
			return false;
		}else if((form.sup_id.value=="") ){
			alert("Silakan isi supplier/customer.");
			form.sup_name.focus();
			return false;
		}else if((form.jurnal_invno.value=="") ){
			alert("Silakan isi nomor invoice.");
			form.jurnal_invno.focus();
			return false;
		}else if((form.jurnal_girono.value=="") ){
			alert("Silakan isi nomor giro.");
			form.jurnal_girono.focus();
			return false;
		}else if((form.jurnal_iddept.value==0) ){
			alert("Silakan pilih departemen.");
			form.jurnal_iddept.focus();
			return false;
		}else if((form.jurnal_ptype.value==0) ){
			alert("Silakan pilih tipe pembayaran.");
			form.jurnal_ptype.focus();
			return false;
		}else if((form.jurnal_ptype.value=="Bank") && (form.jurnal_idbank.value==0) ){
			alert("Silakan pilih bank.");
			form.jurnal_idbank.focus();
			return false;
		}else if((form.jurnal_currency.value==0) ){
			alert("Silakan pilih currency.");
			form.jurnal_currency.focus();
			return false;
		}else if((form.jurnal_chequeno.value=="") ){
			alert("Silakan isi nomor cek.");
			form.jurnal_chequeno.focus();
			return false;
		}else if((form.tdebit.value==0) ){
			alert("Silakan isi detail.");
			form.tdebit.focus();
			return false;
		}else if((form.total.value!=0) ){
			alert("Jurnal tidak balance.");
			form.total.focus();
			return false;
		}else{
			var a = confirm("Apakah anda yakin akan menyimpan data?");
			if (a == true){
				form.action ='?page=Proses-Jurnal-Ref&Act=SAVE';
				form.method = 'post';
				form.submit();			
				return true;
			}
		}
	}
	function save_click2(){
		if(form.jurnal_no.value==""){
			alert("Silakan isi no jurnal.");
			form.jurnal_no.focus();
			return false;
		}else if((form.jurnal_invno.value=="") ){
			alert("Silakan isi nomor invoice.");
			form.jurnal_invno.focus();
			return false;
		}else if((form.jurnal_iddept.value==0) ){
			alert("Silakan pilih departemen.");
			form.jurnal_iddept.focus();
			return false;
		}else if((form.jurnal_currency.value==0) ){
			alert("Silakan pilih currency.");
			form.jurnal_currency.focus();
			return false;
		}else if((form.tdebit.value==0) ){
			alert("Silakan isi detail.");
			form.tdebit.focus();
			return false;
		}else if((form.total.value!=0) ){
			alert("Jurnal tidak balance.");
			form.total.focus();
			return false;
		}else{
			var a = confirm("Apakah anda yakin akan menyimpan data?");
			if (a == true){
				form.action ='?page=Proses-Jurnal-Ref&Act=SAVE2';
				form.method = 'post';
				form.submit();			
				return true;
			}
		}
	}
	function add_det_click(){
		if(form.acctno.value==""){
			alert("Silakan isi nomor account.");
			form.acctno.focus();
			return false;
		}else if((form.acctdesc.value=="") ){
			alert("Silakan isi keterangan.");
			form.acctdesc.focus();
			return false; 
		}else if((form.acctamount.value=="") ){
			alert("Silakan nilai.");
			form.acctamount.focus();
			return false;
		}else if((form.jurnal_currency.value==0) ){
			alert("Silakan pilih currency.");
			form.jurnal_currency.focus();
			return false;
		}else{
			form.action ='?page=Proses-Jurnal-Ref&Act_Det=ADD_DET';
			form.method = 'post';
			form.submit();			
			return true;
		}
	}
	function add_det_click2(){
		if((form.jurnal_currency.value==0) ){
			alert("Silakan pilih currency.");
			form.jurnal_currency.focus();
			return false;
		}else{
			form.action ='?page=Proses-Jurnal-Ref&Act_Det=ADD_DET2';
			form.method = 'post';
			form.submit();			
			return true;
		}
	}
	function edit_detail_click(id){
		form.action ='?page=Proses-Jurnal-Ref&Act_Det=UPDATE_DET&id_deth='+id;
		form.method = 'post';
		form.submit();			
		return true;
	}
	function delete_detail_click(id){
		form.action ='?page=Proses-Jurnal-Ref&Act_Det=DELETE_DET&id_deth='+id;
		form.method = 'post';
		form.submit();			
		return true;
	}
	function close_click(){
		form.action ='?page=Proses-Jurnal-Ref&Act=CLOSE'
		form.method = 'post';
		form.submit();		
		return true;
	}	
/*---Show & Hide----*/
	var IE5up = document.getElementById && document.all;
	var NS6up = document.getElementById &&! document.all;
	var NS4 = document.layers;
	var IE4 = document.all &&! window.print;
	function bank_hide(layerid) {
		if(IE5up || NS6up)
		document.getElementById(layerid).style.visibility = "hidden";
		else if(NS4)
		document.layers[layerid].visibility = "hidden";
		else if(IE4)
		document.all[layerid].style.visibility = "hidden";
	}
	function bank_show(layerid) {
		if(IE5up || NS6up)
		document.getElementById(layerid).style.visibility = "visible";
		else if(NS4)
		document.layers[layerid].visibility = "visible";
		else if(IE4)
		document.all[layerid].style.visibility = "visible";
	}
	function pay_click(id)
	{
		var bankid = 'myBank';
		if(id == 'Bank'){
			bank_show(bankid);
		}else{
			bank_hide(bankid);
			document.getElementById("myBank").value=0;
		}
	}
	/*---End Show & Hide---*/
	function sup_click(id){
		form.action ='?page=Proses-Jurnal-Ref&Act=SEL_SUP&supcust_code='+id
		form.method = 'post';
		form.submit();		
		return true;
	}	
	function cust_click(id){
		form.action ='?page=Proses-Jurnal-Ref&Act=SEL_SUP&cust_id='+id
		form.method = 'post';
		form.submit();		
		return true;
	}	
	function jt_click(id){
		form.action ='?page=Proses-Jurnal-Ref&Act=JTC&jurnal_type='+id
		form.method = 'post';
		form.submit();		
		return true;
	}	
	function excel_hutang_click(){
		form.action ='./transaksi/akuntansi/export_pending_hutang.php';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function excel_piutang_click(){
		form.action ='./transaksi/akuntansi/export_pending_piutang.php';
		form.method = 'post';
		form.submit();			
		return true;
	}
</script>
<?php if($jurnal_ptype=="Bank"){?>
<body onLoad="bank_show('myBank');">
<?php }else{ ?>
<body onLoad="bank_hide('myBank');">
<?php } ?>
<form action="?page=Proses-Jurnal-Ref" method="post" name="form" target="_self" enctype="multipart/form-data">
<?php if(($Act == "ADD" || $Act == "DETAIL" || $Act_Det == "ADD_DET" || $Act_Det == "DELETE_DET" || $Act_Det == "UPDATE_DET" || $Act == "SEL_SUP" || $Act_Det == "ADD_DET2" || $Act == "JTC") && ($jurnal_trcid==0)){ ?>
<table width="100%" cellpadding="2" cellspacing="1" class="table-list" style="margin-top:0px;">
	<tr>
	  <th colspan="4">TRANSAKSI JURNAL BC</th>
	</tr>
	<tr>
	  <td width="15%">No Jurnal</td>
	  <td width="35%">: 
      		<input type="hidden" name="jurnal_id" value="<?php echo $jurnal_id; ?>" size="50" />
			<input type="hidden" name="fromdate" value="<?php echo $fromdate; ?>" size="50" />
			<input type="hidden" name="todate" value="<?php echo $todate; ?>" size="50" />
			<input type="hidden" name="thn_acct"  id="thn_acct" value="<?php echo $thn_acct; ?>" size="50" />
	        <?php if(empty($jurnal_id)){ ?>
	        <input type="text" name="jurnal_no" value="<?php echo $jurnal_no; ?>" size="20"/>
			<?php }else{ ?>
			<input type="text" name="jurnal_no" value="<?php echo $jurnal_no; ?>" size="20" readonly="true" style="background-color:#CCFFFF "/>
			<?php } ?>
            <select name="jurnal_type" onChange="jt_click(this.value);">
            	<?php if($jurnal_type=="AP"){ ?>
                <option value="0">PILIH</option>
                <option value="AP" selected>AP</option>
                <option value="AR">AR</option>
				<option value="OT">OT</option>
                <?php }elseif($jurnal_type=="AR"){ ?>
                <option value="0">PILIH</option>
                <option value="AP">AP</option>
                <option value="AR" selected>AR</option>
				<option value="OT">OT</option>
				<?php }elseif($jurnal_type=="OT"){ ?>
                <option value="0">PILIH</option>
                <option value="AP">AP</option>
                <option value="AR">AR</option>
				<option value="OT" selected>OT</option>
                <?php }else{ ?>
                <option value="0" selected>PILIH</option>
                <option value="AP">AP</option>
                <option value="AR">AR</option>
				<option value="OT">OT</option>
                <?php } ?>
            </select>
      </td>
	  <td width="15%">Departemen</td>
	  <td width="35%">: <select name="jurnal_iddept">
      				<option value="0" selected="selected">PILIH</option>
					<?php
					  $dataSql = mysql_query("SELECT id,dept_name FROM departement ORDER BY id ASC");
					  while ($dataRow = mysql_fetch_array($dataSql)) {
						if ($dataRow['id']== $jurnal_iddept) {
							$cek = " selected";
						} else { $cek=""; }
						echo "<option value='$dataRow[id]' $cek>$dataRow[dept_name]</option>";
					  }
					  $sqlData ="";
					?>
				 </select></td>
	</tr>
	<tr>
		<td>Tanggal Jurnal</td>
		<td>: <input type="text" name="jurnal_date" value="<?php if(empty($jurnal_date)){$jurnal_date=$date;} echo $jurnal_date; ?>" size="12" id="bpbdate" 
				  readonly="true" style="background-color:#CCFFFF " /> </td>
		<td>Tipe Pembayaran</td>
		<td>: <select name="jurnal_ptype"  onChange="pay_click(this.value);">
        		<option value="0" selected="selected">PILIH</option>
					<?php
					  $dataSql = mysql_query("SELECT bbt_tipe FROM buku_besar_tipe WHERE id IN(1,2,5)");
					  while ($dataRow = mysql_fetch_array($dataSql)) {
						if ($dataRow['bbt_tipe']== $jurnal_ptype) {
							$cek = " selected";
						} else { $cek=""; }
						echo "<option value='$dataRow[bbt_tipe]' $cek>$dataRow[bbt_tipe]</option>";
					  }
					  $sqlData ="";
					?>
				 </select>
		 		<select name="jurnal_idbank" class="select-field" id="myBank">
              <option value="0">PILIH</option> 
                <?php
                  $dataSql = mysql_query("SELECT * FROM master_bank WHERE mb_status=10 ORDER BY mb_bank ASC");
                  while ($dataRow = mysql_fetch_array($dataSql)) {
                    if ($dataRow['id']== $jurnal_idbank) {
                        $cek = " selected";
                    } else { $cek=""; }
                    echo "<option value='$dataRow[id]' $cek>$dataRow[mb_bank]</option>";
                  }
                  $sqlData ="";
                ?>
             </select>
		</td>
	</tr>
	<tr>
		<td>Supplier/Customer</td>
		<td colspan="3">: 
				<input type="hidden" name="npwp" value="<?php echo $npwp; ?>" size="50" />
				<input type="hidden" name="sup_id" value="<?php echo $sup_id; ?>" size="50" />
				<input type="hidden" name="sup_name" value="<?php echo $sup_name; ?>" size="50" />
				<select name="supcust_code" onChange="sup_click(this.value);">
				  <option value="0" selected="selected">PILIH</option>
					<?php
					  $dataSql = 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 ORDER BY a.nama ASC");
					  while ($dataRow = mysql_fetch_array($dataSql)) {
						if ($dataRow['kode']== $supcust_code) {
							$cek = " selected";
						} else { $cek=""; }
						echo "<option value='$dataRow[kode]' $cek>$dataRow[nama]</option>";
					  }
					  $sqlData ="";
					?>
				</select>
	    </td>
		<!--<td>Customer</td>
		<td>: 
			<?php if($jurnal_type=="AR"){ ?>
				<select name="cust_id" onChange="cust_click(this.value);">
				  <option value="0" selected="selected">PILIH</option>
					<?php
					  $dataSql = mysql_query("SELECT id, cust_name FROM customer WHERE cust_status=10 ORDER BY cust_name ASC");
					  while ($dataRow = mysql_fetch_array($dataSql)) {
						if ($dataRow['id']== $cust_id) {
							$cek = " selected";
						} else { $cek=""; }
						echo "<option value='$dataRow[id]' $cek>$dataRow[cust_name]</option>";
					  }
					  $sqlData ="";
					?>
				</select>
			<?php }else{ ?>
				&nbsp;
			<?php } ?>
		</td>-->
	</tr>
	<tr>
		<td>No Invoice</td>
		<td>: <input type="text" name="jurnal_invno" value="<?=$jurnal_invno;?>"></td>
		<td>Mata Uang & Kurs</td>
		<td>: 
        <select name="jurnal_currency">
        		<option value="0" selected="selected">PILIH</option>
					<?php
					  $dataSql = mysql_query("SELECT currency FROM currency ORDER BY id ASC");
					  while ($dataRow = mysql_fetch_array($dataSql)) {
						if ($dataRow['currency']== $jurnal_currency) {
							$cek = " selected";
						} else { $cek=""; }
						echo "<option value='$dataRow[currency]' $cek>$dataRow[currency]</option>";
					  }
					  $sqlData ="";
					?>
				 </select> <input id="jurnal_rate" type="text" name="jurnal_rate" value="<?=$jurnal_rate;?>" size="10" style="text-align:right">
        </td>
	</tr>
	<tr>
		<td>Tanggal Jatuh Tempo</td>
		<td>: <input type="text" name="jurnal_duedate" value="<?php if(empty($jurnal_duedate)){$jurnal_duedate=$date;} echo $jurnal_duedate; ?>" size="12" id="invdate" 
				  readonly="true" style="background-color:#CCFFFF " />
		</td>
		<td>No Chek</td>
		<td>: <input type="text" name="jurnal_chequeno" value="<?=$jurnal_chequeno;?>"></td>
	</tr>
	<tr>
		<td>No Giro</td>
		<td>: <input type="text" name="jurnal_girono" value="<?=$jurnal_girono;?>"></td>
		<td>No Faktur</td>
		<td>: <input type="text" name="jurnal_nofaktur" value="<?=$jurnal_nofaktur;?>"></td>
	</tr>
	<tr>
		<td colspan="4">&nbsp;</td>
	</tr>
	<?php if($jurnal_type=="AP"){ ?>
	<tr>
		<th colspan="4">DETAIL HUTANG</th>
	</tr>
	<tr>
		<td colspan="4">
			<table width="100%" border="0">
			  <tr>
				<th rowspan="2">No</th>
				<th rowspan="2">Tanggal</th>
				<th rowspan="2">No.Invoice</th>
				<th rowspan="2">Keterangan</th>
				<th colspan="2">Sisa Hutang</th>
				<th rowspan="2">Bayar</th>
				<th rowspan="2">No.Account</th>
				<th rowspan="2">Status
					<input type="button" name="Add_Detail" value="Tambah" style="cursor:pointer" onClick="add_det_click2();">
					<input type="button" name="Excel_Detail" value="Excel" style="cursor:pointer" onClick="excel_hutang_click();">
				</th>
			  </tr>
			  <tr>
			  	<th>Non IDR</th>
				<th>IDR</th>
			  </tr>
			  	<?php
				#Nama Supplier
				#$nm = mysql_fetch_array(mysql_query("SELECT sup_code, sup_name FROM supplier WHERE id='$sup_id'"));
				#$jd = mysql_fetch_array(mysql_query("SELECT jd_acctno FROM jurnal_master_detail WHERE jd_code='$supcust_code'"));
				$no=1;$tnilai=0;$tpay=0;$tsisa=0; $tnilai_usd=0;$tpay_usd=0;$tsisa_usd=0;
				$qd=mysql_query("SELECT a.* FROM (
					SELECT a.jurnal_idpemasok npwp, a.jurnal_date tanggal, a.jurnal_invno noreferensi, b.jurnald_desc keterangan, 0 debit_idr, 0 debit_nidr,
					b.jurnald_amount kredit_idr, b.jurnald_amount_usd kredit_nidr, b.jurnald_acctno
					FROM jurnal a INNER JOIN jurnal_detail b ON b.jurnal_no=a.jurnal_no INNER JOIN jurnal_master c ON c.j_acctno=b.jurnald_acctno AND c.j_tampilhtpt='Y'
					WHERE a.jurnal_status=20 AND a.jurnal_type='HT' AND a.jurnal_date BETWEEN '$start_dateacct' AND '$end_dateacct' AND b.jurnald_status=20					
					UNION ALL 
					SELECT sa_idpemasok npwp, sa_date tanggal, sa_noref noreferensi, 'Saldo Awal' keterangan, 0 debit_idr, 0 debit_nidr,
					sa_price kredit_idr, sa_price_usd kredit_nidr, sa_acctno jurnald_acctno
					FROM stock_acct a INNER JOIN jurnal_master c ON c.j_acctno=a.sa_acctno AND c.j_tampilhtpt='Y' 
					WHERE sa_status=20 AND sa_date BETWEEN '$start_dateacct' AND '$end_dateacct') a 
					WHERE a.npwp='$npwp' ORDER BY a.tanggal ASC");
				while($dd=mysql_fetch_array($qd)){	
					$py =mysql_fetch_array(mysql_query("SELECT SUM(a.jurnald_amount) payment FROM jurnal_detail a INNER JOIN jurnal b ON b.jurnal_no=a.jurnal_no 
			             WHERE a.jurnald_invno_acct='$dd[noreferensi]' AND a.jurnald_status<>100 AND b.jurnal_status=20 AND b.jurnal_type='AP'"));
					$py_usd =mysql_fetch_array(mysql_query("SELECT SUM(a.jurnald_amount_usd) payment FROM jurnal_detail a INNER JOIN jurnal b ON b.jurnal_no=a.jurnal_no 
			             WHERE a.jurnald_invno_acct='$dd[noreferensi]' AND a.jurnald_status<>100 AND b.jurnal_status=20 AND b.jurnal_type='AP'"));
					$sisa   = $dd['kredit_idr'] - $py['payment']; 
					$sisa_usd   = $dd['kredit_nidr'] - $py_usd['payment']; 
					# cek settingan master GL
					#$cekhtpt = mysql_fetch_array(mysql_query("SELECT j_tampilhtpt FROM jurnal_master WHERE j_acctno='$dd[jurnald_acctno]'"));
					#if($cekhtpt['j_tampilhtpt']=="Y" && $sisa>0){
					if($sisa>0){
					$tnilai = $tnilai+$dd['kredit_idr'];
					$tpay   = $tpay+$py['payment'];
					$tsisa  = $tsisa+$sisa;	
					#usd
					$tnilai_usd = $tnilai_usd+$dd['kredit_nidr'];
					$tpay_usd   = $tpay_usd+$py_usd['payment'];
					$tsisa_usd  = $tsisa_usd+$sisa_usd;	
				?>
				 <tr>
					<td align="center"><?=$no;?>.</td>
					<td align="center"><?=$dd['tanggal'];?></td>
					<td align="center"><?=$dd['noreferensi'];?></td>
					<td align="left"><?=$dd['keterangan'];?></td>
					<td align="right"><?=number_format($sisa_usd,2,'.',',');?></td>
					<td align="right"><?=number_format($sisa,2,'.',',');?></td>
					<td align="center">
						<input type="hidden" name="jurnald_desc2[<?=$no;?>]" value="<?=$dd['keterangan'];?>">
						<!--<input type="hidden" name="jurnald_acctno2[<?=$no;?>]" value="<?=$jd['jd_acctno'];?>">-->
						<input type="hidden" name="pilih2[<?=$no;?>]" value="<?=$no;?>">
						<input type="hidden" name="jurnald_invno_acct2[<?=$no;?>]" value="<?=$dd['noreferensi'];?>">
						<input type="text" name="jurnald_amount2[<?=$no;?>]" size="10" value="0" style="text-align:right">
					</td>
					<td align="right">
						<select name="jurnald_acctno2[<?=$no;?>]">
							<?php
							  $dataSql = mysql_query("SELECT jd_acctno FROM jurnal_master_detail WHERE jd_code='$supcust_code'");
							  while ($dataRow = mysql_fetch_array($dataSql)) {								
								echo "<option value='$dataRow[jd_acctno]'>$dataRow[jd_acctno]</option>";
							  }
							  $sqlData ="";
							?>
						 </select>
					</td>
					<td align="center">
						<select name="jurnald_status2[<?=$no;?>]">
							<option value="0" selected="selected">Pilih</option>
							<option value="10">Debit</option>
							<option value="20">Kredit</option>
						</select>
					</td>
				  </tr>	  
			  <?php $no++; } } ?> 
			</table>
		</td>
	</tr>	
	<?php }elseif($jurnal_type=="AR"){ ?>
	<tr>
		<th colspan="4">DETAIL PIUTANG</th>
	</tr>
	<tr>
		<td colspan="4">
			<table width="100%" border="0">
			 <tr>
				<th rowspan="2">No</th>
				<th rowspan="2">Tanggal</th>
				<th rowspan="2">No.Invoice</th>
				<th rowspan="2">Keterangan</th>
				<th colspan="2">Sisa Piutang</th>
				<th rowspan="2">Bayar</th>
				<th rowspan="2">No.Account</th>
				<th rowspan="2">Status
					<input type="button" name="Add_Detail" value="Tambah" style="cursor:pointer" onClick="add_det_click2();">
					<input type="button" name="Excel_Detail" value="Excel" style="cursor:pointer" onClick="excel_piutang_click();">
				</th>
			  </tr>
			  <tr>
			  	<th>Non IDR</th>
				<th>IDR</th>
			  </tr>
			  	<?php
				#Nama Supplier
				#$nm = mysql_fetch_array(mysql_query("SELECT cust_code, cust_name FROM customer WHERE id='$cust_id'"));
				#$jd = mysql_fetch_array(mysql_query("SELECT jd_acctno FROM jurnal_master_detail WHERE jd_code='$supcust_code'"));
				$no=1;$tnilai=0;$tpay=0;$tsisa=0; $tnilai_usd=0;$tpay_usd=0;$tsisa_usd=0;
				$qd=mysql_query("SELECT a.* FROM (
					SELECT a.jurnal_idpemasok npwp, a.jurnal_date tanggal, a.jurnal_invno noreferensi, b.jurnald_desc keterangan, 0 debit_idr, 0 debit_nidr,
					b.jurnald_amount kredit_idr, b.jurnald_amount_usd kredit_nidr, b.jurnald_acctno
					FROM jurnal a	INNER JOIN jurnal_detail b ON b.jurnal_no=a.jurnal_no INNER JOIN jurnal_master c ON c.j_acctno=b.jurnald_acctno AND c.j_tampilhtpt='Y'
					WHERE a.jurnal_status=20 AND a.jurnal_type='PT' AND a.jurnal_date BETWEEN '$start_dateacct' AND '$end_dateacct' AND b.jurnald_status=10					
					UNION ALL
					SELECT sa_idpemasok npwp, sa_date tanggal, sa_noref noreferensi, 'Saldo Awal' keterangan, 0 debit_idr, 0 debit_nidr,
					sa_price kredit_idr, sa_price_usd kredit_nidr, sa_acctno jurnald_acctno
					FROM stock_acct a INNER JOIN jurnal_master c ON c.j_acctno=a.sa_acctno AND c.j_tampilhtpt='Y'	
					WHERE sa_status=30 AND sa_date BETWEEN '$start_dateacct' AND '$end_dateacct') a 
					WHERE a.npwp='$npwp' ORDER BY a.tanggal ASC");
				while($dd=mysql_fetch_array($qd)){	
					$py =mysql_fetch_array(mysql_query("SELECT SUM(a.jurnald_amount) payment FROM jurnal_detail a INNER JOIN jurnal b ON b.jurnal_no=a.jurnal_no 
			             WHERE a.jurnald_invno_acct='$dd[noreferensi]' AND a.jurnald_status<>100 AND b.jurnal_status=20 AND b.jurnal_type='AR'"));
					$py_usd =mysql_fetch_array(mysql_query("SELECT SUM(a.jurnald_amount_usd) payment FROM jurnal_detail a INNER JOIN jurnal b ON b.jurnal_no=a.jurnal_no 
			             WHERE a.jurnald_invno_acct='$dd[noreferensi]' AND a.jurnald_status<>100 AND b.jurnal_status=20 AND b.jurnal_type='AR'"));
					$sisa   = $dd['kredit_idr'] - $py['payment']; 
					$sisa_usd   = $dd['kredit_nidr'] - $py_usd['payment']; 
					# cek settingan master GL
					#$cekhtpt = mysql_fetch_array(mysql_query("SELECT j_tampilhtpt FROM jurnal_master WHERE j_acctno='$dd[jurnald_acctno]'"));
					#if($cekhtpt['j_tampilhtpt']=="Y" && $sisa>0){
					if($sisa>0){
					$tnilai = $tnilai+$dd['kredit_idr'];
					$tpay   = $tpay+$py['payment'];
					$tsisa  = $tsisa+$sisa;	
					#usd
					$tnilai_usd = $tnilai_usd+$dd['kredit_nidr'];
					$tpay_usd   = $tpay_usd+$py_usd['payment'];
					$tsisa_usd  = $tsisa_usd+$sisa_usd;	
				?>
				 <tr>
					<td align="center"><?=$no;?>.</td>
					<td align="center"><?=$dd['tanggal'];?></td>
					<td align="center"><?=$dd['noreferensi'];?></td>
					<td align="left"><?=$dd['keterangan'];?></td>
					<td align="right"><?=number_format($sisa_usd,2,'.',',');?></td>
					<td align="right"><?=number_format($sisa,2,'.',',');?></td>
					<td align="center">
						<input type="hidden" name="jurnald_desc2[<?=$no;?>]" value="<?=$dd['keterangan'];?>">
						<!--<input type="hidden" name="jurnald_acctno2[<?=$no;?>]" value="<?=$jd['jd_acctno'];?>">-->
						<input type="hidden" name="pilih2[<?=$no;?>]" value="<?=$no;?>">
						<input type="hidden" name="jurnald_invno_acct2[<?=$no;?>]" value="<?=$dd['noreferensi'];?>">
						<input type="text" name="jurnald_amount2[<?=$no;?>]" size="10" value="0" style="text-align:right">
					</td>
					<td align="right">
						<select name="jurnald_acctno2[<?=$no;?>]">
							<?php
							  $dataSql = mysql_query("SELECT jd_acctno FROM jurnal_master_detail WHERE jd_code='$supcust_code'");
							  while ($dataRow = mysql_fetch_array($dataSql)) {								
								echo "<option value='$dataRow[jd_acctno]'>$dataRow[jd_acctno]</option>";
							  }
							  $sqlData ="";
							?>
						 </select>
					</td>
					<td align="center">
						<select name="jurnald_status2[<?=$no;?>]">
							<option value="0" selected="selected">Pilih</option>
							<option value="10">Debit</option>
							<option value="20">Kredit</option>
						</select>
					</td>
				  </tr>	  
			  <?php $no++; } } ?> 
			</table>
		</td>
	</tr>
	<?php } ?>
	<tr>
		<th colspan="4">DETAIL ACCOUNT</th>
	</tr>
	<tr>
		<td colspan="4">
			<table width="100%" border="0">
				<tr>
					<td>No./Nama Account</td>
					<td>Keterangan</td>
					<td>Nilai</td>	
					<td>Status</td>				
					<td>Action</td>
				</tr>
				<tr>
					<td><input type="hidden" name="acctno" id="acctno" style="width:100px; background-color:#CCFFFF">
                    <input type="text" name="acctnod" id="acctnod" style="width:350px; background-color:#CCFFFF">                    
					<input type="hidden" name="acctname" id="acctname" style="width:250px; text-align:left; background-color:#CCFFFF" readonly>
                    </td>
					<td><textarea name="acctdesc" cols="50" rows="2"></textarea></td>
					<td><input type="text" id="acctamount" name="acctamount" style="width:100px; text-align:right"></td>	
					<td>
						<select name="acctstatus">
							<option value="0" selected="selected">Pilih</option>
							<option value="10">Debit</option>
							<option value="20">Kredit</option>
						</select>
					</td>				
					<td><input type="button" name="Add_Detail" value="Tambah" style="cursor:pointer" onClick="add_det_click();"></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td colspan="4">&nbsp;</td>
	</tr>
	<tr>
		<td colspan="4">
		  <?php if(empty($jurnal_id)){  ?>			
			<table width="100%">
				<tr>
					<th align="center" rowspan="3">No.</th>
					<th align="center" rowspan="3">No Account</th>
					<th align="center" rowspan="3">Nama Account</th>
					<th align="center" rowspan="3">Keterangan</th>
					<th align="center" colspan="4">Nilai</th>
					<th align="center" rowspan="3">Action</th>
				</tr>
                <tr>
                	<th align="center" colspan="2">Debit</th>
                    <th align="center" colspan="2">Kredit</th>
                </tr>
				 <tr>
                	<th align="center">Non IDR</th>
                    <th align="center">IDR</th>
					<th align="center">Non IDR</th>
                    <th align="center">IDR</th>
                </tr>
				<?php
					$no=0; $tdebit=0; $tkredit=0; $tdebit_usd=0; $tkredit_usd=0;
					$qd = mysql_query("SELECT a.id, a.jurnald_desc, b.j_acctno,b.j_name1,b.j_name2,
									   CASE WHEN a.jurnald_status=10 THEN a.jurnald_amount ELSE 0 END AS debit,
									   CASE WHEN a.jurnald_status=20 THEN a.jurnald_amount ELSE 0 END AS kredit,
									   CASE WHEN a.jurnald_status=10 THEN a.jurnald_amount_usd ELSE 0 END AS debit_usd,
									   CASE WHEN a.jurnald_status=20 THEN a.jurnald_amount_usd ELSE 0 END AS kredit_usd,
									   a.jurnald_status
									   FROM jurnal_temp a
									   INNER JOIN jurnal_master b ON b.j_acctno=a.jurnald_acctno
									   WHERE a.jurnald_inputby='$user_id' AND a.jurnald_status IN(10,20) ORDER BY a.jurnald_status, a.id DESC");
					while($dt=mysql_fetch_object($qd)){	   
				    $no++;
					$tdebit   = $tdebit + $dt->debit;
					$tkredit  = $tkredit + $dt->kredit;
					$tdebit_usd   = $tdebit_usd + $dt->debit_usd;
					$tkredit_usd  = $tkredit_usd + $dt->kredit_usd;
					$total	  = number_format($tdebit,2,'.','')-number_format($tkredit,2,'.','');
				?> 
				  <tr>
					<td style="width:20px;" align="center"><?=$no;?>
						<input type="hidden" name="id_det[<?=$dt->id;?>]" value="<?=$dt->id;?>">
						<input type="hidden" name="jurnald_status[<?=$dt->id;?>]" value="<?=$dt->jurnald_status;?>">
					</td>
					<td style="width:100px;" align="center"><input type="text" name="j_acctno[<?=$dt->id;?>]" value="<?=$dt->j_acctno;?>" size="10"></td>
					<td style="width:150px;" align="left"><input type="text" name="j_name1[<?=$dt->id;?>]" value="<?=$dt->j_name1;?>"></td>
                    <td style="width:350px;" align="left"><textarea name="jurnald_desc[<?=$dt->id;?>]" cols="50" rows="2"><?=$dt->jurnald_desc;?></textarea></td>
					<td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==10){ ?>
						<input type="text" name="debit_usd[<?=$dt->id;?>]" value="<?=$dt->debit_usd;?>" size="10" style="text-align:right;">
						<?php }else{ ?>
						&nbsp;<input type="hidden" name="debit_usd[<?=$dt->id;?>]" value="<?=$dt->debit_usd;?>" size="10" style="text-align:right;">
						<?php } ?>
					</td>
                    <td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==10){ ?>
						<input type="text" name="debit[<?=$dt->id;?>]" value="<?=$dt->debit;?>" size="10" style="text-align:right;">
						<?php }else{ ?>
						&nbsp;<input type="hidden" name="debit[<?=$dt->id;?>]" value="<?=$dt->debit;?>" size="10" style="text-align:right;">
						<?php } ?>
					</td>
					<td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==20){ ?>
						<input type="text" name="kredit_usd[<?=$dt->id;?>]" value="<?=$dt->kredit_usd;?>" size="10" style="text-align:right;">
						<?php }else{ ?>
						&nbsp;<input type="hidden" name="kredit_usd[<?=$dt->id;?>]" value="<?=$dt->kredit_usd;?>" size="10" style="text-align:right;">
						<?php } ?>
					</td>
                    <td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==20){ ?>
						<input type="text" name="kredit[<?=$dt->id;?>]" value="<?=$dt->kredit;?>" size="10" style="text-align:right;">
						<?php }else{ ?>
						&nbsp;<input type="hidden" name="kredit[<?=$dt->id;?>]" value="<?=$dt->kredit;?>" size="10" style="text-align:right;">
						<?php } ?>
					</td>
					<td style="width:170px;" align="center">
						<img src="images/btn_edit.png" width="20" height="20"  border="0"  title="Edit" style="cursor:pointer" onClick="edit_detail_click('<?=$dt->id;?>');"/>
						<img src="images/btn_delete.png" width="20" height="20"  border="0"  title="Hapus" style="cursor:pointer" onClick="delete_detail_click('<?=$dt->id;?>');"/>
					</td>
				</tr>
				<?php } ?>
				<tr>
					<td colspan="4" align="right">Total</td>
					<td align="right"><?=number_format($tdebit_usd,2,'.',',');?></td>
                    <td align="right"><?=number_format($tdebit,2,'.',',');?></td>
					<td align="right"><?=number_format($tkredit_usd,2,'.',',');?></td>
                    <td align="right"><?=number_format($tkredit,2,'.',',');?></td>
					<td align="center">
                    	<input type="hidden" name="tdebit" value="<?=$tdebit;?>">
						<input type="hidden" name="tdebit_usd" value="<?=$tdebit_usd;?>">
                        <input type="text" name="total" value="<?=$total;?>" size="10" readonly style="text-align:center; background-color:#CCFFFF">
                    </td>
				</tr>
			</table>
			<?php }else{ ?>
			<table width="100%">
				<tr>
					<th align="center" rowspan="3">No.</th>
					<th align="center" rowspan="3">No Account</th>
					<th align="center" rowspan="3">Nama Account</th>
					<th align="center" rowspan="3">Keterangan</th>
					<th align="center" colspan="4">Nilai</th>
					<th align="center" rowspan="3">Action</th>
				</tr>
                <tr>
                	<th align="center" colspan="2">Debit</th>
                    <th align="center" colspan="2">Kredit</th>
                </tr>
				 <tr>
                	<th align="center">Non IDR</th>
                    <th align="center">IDR</th>
					<th align="center">Non IDR</th>
                    <th align="center">IDR</th>
                </tr>
				<?php
					$no=0; $tdebit=0; $tkredit=0; $tdebit_usd=0; $tkredit_usd=0;
					$qd = mysql_query("SELECT a.id, a.jurnald_desc, b.j_acctno,b.j_name1,b.j_name2,
									   CASE WHEN a.jurnald_status=10 THEN a.jurnald_amount ELSE 0 END AS debit,
									   CASE WHEN a.jurnald_status=20 THEN a.jurnald_amount ELSE 0 END AS kredit,
									   CASE WHEN a.jurnald_status=10 THEN a.jurnald_amount_usd ELSE 0 END AS debit_usd,
									   CASE WHEN a.jurnald_status=20 THEN a.jurnald_amount_usd ELSE 0 END AS kredit_usd,
									   a.jurnald_status
									   FROM jurnal_detail a
									   INNER JOIN jurnal_master b ON b.j_acctno=a.jurnald_acctno
									   WHERE a.jurnal_no='$jurnal_no' ORDER BY a.id ASC");
					while($dt=mysql_fetch_object($qd)){	   
				    $no++;
					$tdebit   = $tdebit + $dt->debit;
					$tkredit  = $tkredit + $dt->kredit;
					$tdebit_usd   = $tdebit_usd + $dt->debit_usd;
					$tkredit_usd  = $tkredit_usd + $dt->kredit_usd;
					$total	  = number_format($tdebit,2,'.','')-number_format($tkredit,2,'.','');
				?> 
				  <tr>
					<td style="width:20px;" align="center">
						<?=$no;?><input type="hidden" name="id_det[<?=$dt->id;?>]" value="<?=$dt->id;?>">
						<input type="hidden" name="jurnald_status[<?=$dt->id;?>]" value="<?=$dt->jurnald_status;?>">
					</td>
					<td style="width:100px;" align="center">
						<input type="text" name="j_acctno[<?=$dt->id;?>]" value="<?=$dt->j_acctno;?>" size="10">
					</td>
					<td style="width:150px;" align="left">
						<input type="text" name="j_name1[<?=$dt->id;?>]" value="<?=$dt->j_name1;?>">
					</td>
                    <td style="width:350px;" align="left">
						<textarea name="jurnald_desc[<?=$dt->id;?>]" cols="50" rows="2"><?=$dt->jurnald_desc;?></textarea>
					</td>
					<td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==10){ ?>
						<input type="text" name="debit_usd[<?=$dt->id;?>]" value="<?=$dt->debit_usd;?>" size="10" style="text-align:right;">
						<?php }else{ ?>
						&nbsp;<input type="hidden" name="debit_usd[<?=$dt->id;?>]" value="<?=$dt->debit_usd;?>" size="10" style="text-align:right;">
						<?php } ?>
					</td>
                    <td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==10){ ?>
						<input type="text" name="debit[<?=$dt->id;?>]" value="<?=$dt->debit;?>" size="10" style="text-align:right;">
						<?php }else{ ?>
						&nbsp;<input type="hidden" name="debit[<?=$dt->id;?>]" value="<?=$dt->debit;?>" size="10" style="text-align:right;">
						<?php } ?>
					</td>
					<td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==20){ ?>
						<input type="text" name="kredit_usd[<?=$dt->id;?>]" value="<?=$dt->kredit_usd;?>" size="10" style="text-align:right;">
						<?php }else{ ?>
						&nbsp;<input type="hidden" name="kredit_usd[<?=$dt->id;?>]" value="<?=$dt->kredit_usd;?>" size="10" style="text-align:right;">
						<?php } ?>
					</td>
                    <td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==20){ ?>
						<input type="text" name="kredit[<?=$dt->id;?>]" value="<?=$dt->kredit;?>" size="10" style="text-align:right;">
						<?php }else{ ?>
						&nbsp;<input type="hidden" name="kredit[<?=$dt->id;?>]" value="<?=$dt->kredit;?>" size="10" style="text-align:right;">
						<?php } ?>
					</td>
					<td style="width:170px;" align="center">
						<img src="images/btn_delete.png" width="20" height="20"  border="0"  title="Hapus" style="cursor:pointer" onClick="delete_detail_click('<?=$dt->id;?>');"/>
					</td>
				</tr>
				<?php } ?>
				<tr>
					<td colspan="4" align="right">Total</td>
					<td align="right"><?=number_format($tdebit_usd,2,'.',',');?></td>
                    <td align="right"><?=number_format($tdebit,2,'.',',');?></td>
					<td align="right"><?=number_format($tkredit_usd,2,'.',',');?></td>
                    <td align="right"><?=number_format($tkredit,2,'.',',');?></td>
					<td align="center">
                    	<input type="hidden" name="tdebit" value="<?=$tdebit;?>">
						<input type="hidden" name="tdebit_usd" value="<?=$tdebit_usd;?>">
                        <input type="text" name="total" value="<?=$total;?>" size="10" readonly style="text-align:center; background-color:#CCFFFF">
                    </td>
				</tr>
			</table>
			<?php } ?>
		</td>
	</tr>
	<tr>
		<td colspan="4">&nbsp;</td>
	</tr>
	<tr>
		<td colspan="4" align="center">
			<input type="button" name="btnSave" value="SIMPAN" style="cursor:pointer;" onClick="save_click();">
			<input type="button" value="BATAL" name="batal" style="cursor:pointer"  onClick="close_click();" />
		</td>
    </tr>
</table>
<?php }else{ ?>
<table width="100%" cellpadding="2" cellspacing="1" class="table-list" style="margin-top:0px;">
	<tr>
	  <th colspan="4">TRANSAKSI JURNAL BC</th>
	</tr>
	<tr>
	  <td width="15%">No Jurnal</td>
	  <td width="35%">: 
      		<input type="hidden" name="jurnal_id" value="<?php echo $jurnal_id; ?>" size="50" />
			<input type="hidden" name="fromdate" value="<?php echo $fromdate; ?>" size="50" />
			<input type="hidden" name="todate" value="<?php echo $todate; ?>" size="50" />
	        <?php if(empty($jurnal_id)){ ?>
	        <input type="text" name="jurnal_no" value="<?php echo $jurnal_no; ?>" size="20"/>
			<?php }else{ ?>
			<input type="text" name="jurnal_no" value="<?php echo $jurnal_no; ?>" size="20" readonly="true" style="background-color:#CCFFFF "/>
			<?php } ?>            
      </td>
	  <td width="15%">Departemen</td>
	  <td width="35%">: <select name="jurnal_iddept">
      				<option value="0" selected="selected">PILIH</option>
					<?php
					  $dataSql = mysql_query("SELECT id,dept_name FROM departement ORDER BY id ASC");
					  while ($dataRow = mysql_fetch_array($dataSql)) {
						if ($dataRow['id']== $jurnal_iddept) {
							$cek = " selected";
						} else { $cek=""; }
						echo "<option value='$dataRow[id]' $cek>$dataRow[dept_name]</option>";
					  }
					  $sqlData ="";
					?>
				 </select></td>
	</tr>
	<tr>
		<td>Tanggal Jurnal</td>
		<td>: <input type="text" name="jurnal_date" value="<?php if(empty($jurnal_date)){$jurnal_date=$date;} echo $jurnal_date; ?>" size="12" id="bpbdate" 
				  readonly="true" style="background-color:#CCFFFF " /> </td>
		<td>Mata Uang</td>
		<td>: <select name="jurnal_currency">
				<option value="0" selected="selected">PILIH</option>
				<?php
				  $dataSql = mysql_query("SELECT currency FROM currency ORDER BY id ASC");
				  while ($dataRow = mysql_fetch_array($dataSql)) {
					if ($dataRow['currency']== $jurnal_currency) {
						$cek = " selected";
					} else { $cek=""; }
					echo "<option value='$dataRow[currency]' $cek>$dataRow[currency]</option>";
				  }
				  $sqlData ="";
				?>
			</select>
			
		</td>
	</tr>
	<tr>
		<td>Supplier/Customer</td>
		<td>: 
				<input type="hidden" name="jurnal_menu" value="<?php echo $jurnal_menu; ?>" size="50" />
				<input type="hidden" name="jurnal_rate" value="<?php echo $jurnal_rate; ?>" size="50" />
				<input type="hidden" name="npwp" value="<?php echo $npwp; ?>" size="50" />				
				<!--<select name="supcust_code">
				  <option value="0" selected="selected">PILIH</option>
					<?php
					  $dataSql = 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 ORDER BY a.nama ASC");
					  while ($dataRow = mysql_fetch_array($dataSql)) {
						if ($dataRow['kode']== $supcust_code) {
							$cek = " selected";
						} else { $cek=""; }
						echo "<option value='$dataRow[kode]' $cek>$dataRow[nama]</option>";
					  }
					  $sqlData ="";
					?>
				</select>-->
				<?php if($jurnal_menu=="BC" || $jurnal_menu=="BCINC"){ ?>
					<input type="hidden" name="sup_id" value="<?php echo $sup_id; ?>" size="50" />
					<input type="text" name="sup_name" value="<?=$sup_name;?>" size="45" readonly="true" style="background-color:#CCFFFF " />
					<a href="javascript: popupsup('');"><img src="images/popup.png" height="15" width="15" title="master Supplier" border="0" />
				<?php }else{ ?>	
					<input type="hidden" name="cust_id" value="<?php echo $cust_id; ?>" size="45" />
					<input type="text" name="cust_name" value="<?=$cust_name;?>" size="45" readonly="true" style="background-color:#CCFFFF " />
					<a href="javascript: popupcust('');"><img src="images/popup.png" height="15" width="15" title="master Customer" border="0" />
				<?php } ?>
				
	    </td>
		<td>NPWP</td>
		<td>: <input type="text" name="npwp" value="<?=$npwp;?>" size="25"></td>
	</tr>
	<tr>
		<td>No Invoice</td>
		<td>: <input type="text" name="jurnal_invno" value="<?=$jurnal_invno;?>"></td>
		<td>No Faktur</td>
		<td>: <input type="text" name="jurnal_nofaktur" value="<?=$jurnal_nofaktur;?>"></td>
	</tr>	
	<tr>
		<td>Tanggal Jatuh Tempo</td>
		<td>: <input type="text" name="jurnal_duedate" value="<?php if(empty($jurnal_duedate)){$jurnal_duedate=$date;} echo $jurnal_duedate; ?>" size="12" id="invdate" 
				  readonly="true" style="background-color:#CCFFFF " />
		</td>
		<td>No Chek</td>
		<td>: <input type="text" name="jurnal_chequeno" value="<?=$jurnal_chequeno;?>"></td>
	</tr>
	<tr>
		<td>No Giro</td>
		<td>: <input type="text" name="jurnal_girono" value="<?=$jurnal_girono;?>"></td>
		<td></td>
		<td></td>
	</tr>
	<tr>
		<td colspan="4">&nbsp;</td>
	</tr>	
	<!--<tr>
		<th colspan="4">DETAIL ACCOUNT</th>
	</tr>
	<tr>
		<td colspan="4">
			<table width="100%" border="0">
				<tr>
					<td>No./Nama Account</td>
					<td>Keterangan</td>
					<td>Nilai</td>	
					<td>Status</td>				
					<td>Action</td>
				</tr>
				<tr>
					<td><input type="hidden" name="acctno" id="acctno" style="width:100px; background-color:#CCFFFF">
                    <input type="text" name="acctnod" id="acctnod" style="width:350px; background-color:#CCFFFF">                    
					<input type="hidden" name="acctname" id="acctname" style="width:250px; text-align:left; background-color:#CCFFFF" readonly>
                    </td>
					<td><textarea name="acctdesc" cols="50" rows="2"></textarea></td>
					<td><input type="text" id="acctamount" name="acctamount" style="width:100px; text-align:right"></td>	
					<td>
						<select name="acctstatus">
							<option value="0" selected="selected">Pilih</option>
							<option value="10">Debit</option>
							<option value="20">Kredit</option>
						</select>
					</td>				
					<td><input type="button" name="Add_Detail" value="Tambah" style="cursor:pointer" onClick="add_det_click();"></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td colspan="4">&nbsp;</td>
	</tr>-->
	<tr>
		<td colspan="4">
		  <?php if(empty($jurnal_id)){  ?>			
			<table width="100%">
				<tr>
					<th align="center" rowspan="3">No.</th>
					<th align="center" rowspan="3">No Account</th>
					<th align="center" rowspan="3">Nama Account</th>
					<th align="center" rowspan="3">Keterangan</th>
					<th align="center" colspan="4">Nilai</th>
					<th align="center" rowspan="3">Action</th>
				</tr>
                <tr>
                	<th align="center" colspan="2">Debit</th>
                    <th align="center" colspan="2">Kredit</th>
                </tr>
				 <tr>
                	<th align="center">Non IDR</th>
                    <th align="center">IDR</th>
					<th align="center">Non IDR</th>
                    <th align="center">IDR</th>
                </tr>
				<?php
					$no=0; $tdebit=0; $tkredit=0; $tdebit_usd=0; $tkredit_usd=0;
					$qd = mysql_query("SELECT a.id, a.jurnald_desc, b.j_acctno,b.j_name1,b.j_name2,
									   CASE WHEN a.jurnald_status=10 THEN a.jurnald_amount ELSE 0 END AS debit,
									   CASE WHEN a.jurnald_status=20 THEN a.jurnald_amount ELSE 0 END AS kredit,
									   CASE WHEN a.jurnald_status=10 THEN a.jurnald_amount_usd ELSE 0 END AS debit_usd,
									   CASE WHEN a.jurnald_status=20 THEN a.jurnald_amount_usd ELSE 0 END AS kredit_usd,
									   a.jurnald_status
									   FROM jurnal_temp a
									   INNER JOIN jurnal_master b ON b.j_acctno=a.jurnald_acctno
									   WHERE a.jurnald_inputby='$user_id' AND a.jurnald_status IN(10,20) ORDER BY a.id ASC");
					while($dt=mysql_fetch_object($qd)){	   
				    $no++;
					$tdebit   = $tdebit + $dt->debit;
					$tkredit  = $tkredit + $dt->kredit;
					$tdebit_usd   = $tdebit_usd + $dt->debit_usd;
					$tkredit_usd  = $tkredit_usd + $dt->kredit_usd;
					$total	  = number_format($tdebit,2,'.','')-number_format($tkredit,2,'.','');
				?> 
				  <tr>
					<td style="width:20px;" align="center"><?=$no;?></td>
					<td style="width:100px;" align="center"><?=$dt->j_acctno;?></td>
					<td style="width:150px;" align="left"><?=$dt->j_name1;?></td>
                    <td style="width:350px;" align="left"><?=$dt->jurnald_desc;?></td>
					<td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==10){ ?>
						<?=number_format($dt->debit_usd,2,'.',',');?>	
						<?php }else{ ?>
						&nbsp;
						<?php } ?>
					</td>
                    <td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==10){ ?>
						<?=number_format($dt->debit,0,'',',');?>
						<?php }else{ ?>
						&nbsp;
						<?php } ?>
					</td>
					<td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==20){ ?>
						<?=number_format($dt->kredit_usd,2,'.',',');?>
						<?php }else{ ?>
						&nbsp;
						<?php } ?>
					</td>
                    <td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==20){ ?>
						<?=number_format($dt->kredit,0,'',',');?>
						<?php }else{ ?>
						&nbsp;
						<?php } ?>
					</td>
					<td style="width:170px;" align="center">
						<img src="images/btn_delete.png" width="20" height="20"  border="0"  title="Hapus" style="cursor:pointer" onClick="delete_detail_click('<?=$dt->id;?>');"/>
					</td>
				</tr>
				<?php } ?>
				<tr>
					<td colspan="4" align="right">Total</td>
					<td align="right"><?=number_format($tdebit_usd,2,'.',',');?></td>
                    <td align="right"><?=number_format($tdebit,0,'',',');?></td>
					<td align="right"><?=number_format($tkredit_usd,2,'.',',');?></td>
                    <td align="right"><?=number_format($tkredit,0,'',',');?></td>
					<td align="center">
                    	<input type="hidden" name="tdebit" value="<?=$tdebit;?>">
						<input type="hidden" name="tdebit_usd" value="<?=$tdebit_usd;?>">
                        <input type="text" name="total" value="<?=$total;?>" size="10" readonly style="text-align:center; background-color:#CCFFFF">
                    </td>
				</tr>
			</table>
			<?php }else{ ?>
			<table width="100%">
				<tr>
					<th align="center" rowspan="3">No.</th>
					<th align="center" rowspan="3">No Account</th>
					<th align="center" rowspan="3">Nama Account</th>
					<th align="center" rowspan="3">Keterangan</th>
					<th align="center" colspan="4">Nilai</th>
					<th align="center" rowspan="3">Action</th>
				</tr>
                <tr>
                	<th align="center" colspan="2">Debit</th>
                    <th align="center" colspan="2">Kredit</th>
                </tr>
				 <tr>
                	<th align="center">Non IDR</th>
                    <th align="center">IDR</th>
					<th align="center">Non IDR</th>
                    <th align="center">IDR</th>
                </tr>
				<?php
					$no=0; $tdebit=0; $tkredit=0; $tdebit_usd=0; $tkredit_usd=0;
					$qd = mysql_query("SELECT a.id, a.jurnald_desc, b.j_acctno,b.j_name1,b.j_name2,
									   CASE WHEN a.jurnald_status=10 THEN a.jurnald_amount ELSE 0 END AS debit,
									   CASE WHEN a.jurnald_status=20 THEN a.jurnald_amount ELSE 0 END AS kredit,
									   CASE WHEN a.jurnald_status=10 THEN a.jurnald_amount_usd ELSE 0 END AS debit_usd,
									   CASE WHEN a.jurnald_status=20 THEN a.jurnald_amount_usd ELSE 0 END AS kredit_usd,
									   a.jurnald_status
									   FROM jurnal_detail a
									   INNER JOIN jurnal_master b ON b.j_acctno=a.jurnald_acctno
									   WHERE a.jurnal_no='$jurnal_no' ORDER BY a.jurnald_status, a.id DESC");
					while($dt=mysql_fetch_object($qd)){	   
				    $no++;
					$tdebit   = $tdebit + $dt->debit;
					$tkredit  = $tkredit + $dt->kredit;
					$tdebit_usd   = $tdebit_usd + $dt->debit_usd;
					$tkredit_usd  = $tkredit_usd + $dt->kredit_usd;
					$total	  = number_format($tdebit,2,'.','')-number_format($tkredit,2,'.','');
				?> 
				  <tr>
					<td style="width:20px;" align="center">
						<?=$no;?><input type="hidden" name="id_det[<?=$dt->id;?>]" value="<?=$dt->id;?>">
						<input type="hidden" name="jurnald_status[<?=$dt->id;?>]" value="<?=$dt->jurnald_status;?>">
					</td>
					<td style="width:100px;" align="center">
						<input type="text" name="j_acctno[<?=$dt->id;?>]" value="<?=$dt->j_acctno;?>" size="10">
					</td>
					<td style="width:150px;" align="left">
						<input type="text" name="j_name1[<?=$dt->id;?>]" value="<?=$dt->j_name1;?>">
					</td>
                    <td style="width:350px;" align="left">
						<textarea name="jurnald_desc[<?=$dt->id;?>]" cols="50" rows="2"><?=$dt->jurnald_desc;?></textarea>
					</td>
					<td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==10){ ?>
						<input type="text" name="debit_usd[<?=$dt->id;?>]" value="<?=$dt->debit_usd;?>" size="10" style="text-align:right;">
						<?php }else{ ?>
						&nbsp;<input type="hidden" name="debit_usd[<?=$dt->id;?>]" value="<?=$dt->debit_usd;?>" size="10" style="text-align:right;">
						<?php } ?>
					</td>
                    <td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==10){ ?>
						<input type="text" name="debit[<?=$dt->id;?>]" value="<?=$dt->debit;?>" size="10" style="text-align:right;">
						<?php }else{ ?>
						&nbsp;<input type="hidden" name="debit[<?=$dt->id;?>]" value="<?=$dt->debit;?>" size="10" style="text-align:right;">
						<?php } ?>
					</td>
					<td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==20){ ?>
						<input type="text" name="kredit_usd[<?=$dt->id;?>]" value="<?=$dt->kredit_usd;?>" size="10" style="text-align:right;">
						<?php }else{ ?>
						&nbsp;<input type="hidden" name="kredit_usd[<?=$dt->id;?>]" value="<?=$dt->kredit_usd;?>" size="10" style="text-align:right;">
						<?php } ?>
					</td>
                    <td style="width:150px;" align="right">
						<?php if($dt->jurnald_status==20){ ?>
						<input type="text" name="kredit[<?=$dt->id;?>]" value="<?=$dt->kredit;?>" size="10" style="text-align:right;">
						<?php }else{ ?>
						&nbsp;<input type="hidden" name="kredit[<?=$dt->id;?>]" value="<?=$dt->kredit;?>" size="10" style="text-align:right;">
						<?php } ?>
					</td>
					<td style="width:170px;" align="center">
						<img src="images/btn_delete.png" width="20" height="20"  border="0"  title="Hapus" style="cursor:pointer" onClick="delete_detail_click('<?=$dt->id;?>');"/>
					</td>
				</tr>
				<?php } ?>
				<tr>
					<td colspan="4" align="right">Total</td>
					<td align="right"><?=number_format($tdebit_usd,2,'.',',');?></td>
                    <td align="right"><?=number_format($tdebit,2,'.',',');?></td>
					<td align="right"><?=number_format($tkredit_usd,2,'.',',');?></td>
                    <td align="right"><?=number_format($tkredit,2,'.',',');?></td>
					<td align="center">
                    	<input type="hidden" name="tdebit" value="<?=$tdebit;?>">
						<input type="hidden" name="tdebit_usd" value="<?=$tdebit_usd;?>">
                        <input type="text" name="total" value="<?=$total;?>" size="10" readonly style="text-align:center; background-color:#CCFFFF">
                    </td>
				</tr>
			</table>
			<?php } ?>
		</td>
	</tr>
	<tr>
		<td colspan="4">&nbsp;</td>
	</tr>
	<tr>
		<td colspan="4" align="center">
			<input type="button" name="btnSave" value="SIMPAN" style="cursor:pointer;" onClick="save_click2();">
			<input type="button" value="BATAL" name="batal" style="cursor:pointer"  onClick="close_click();" />
		</td>
    </tr>
</table>
<?php } ?>
</form>
</body>
</html> 
