<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(){
		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 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_ptype.value=="BLANK"){
			alert("Silakan pilih pos data.");
			form.jurnal_ptype.focus();
			return false;
		}else if(form.npwpno.value==""){
			alert("Silakan isi NPWP.");
			form.npwpno.focus();
			return false;
		}else if((form.tdebit.value==0) ){
			alert("Silakan isi detail.");
			form.tdebit.focus();
			return false;
		}else if((form.ttotal.value!=0) ){
			alert("Jurnal tidak balance.");
			form.ttotal.focus();
			return false;
		}else{
			var a = confirm("Apakah anda yakin akan menyimpan data?");
			if (a == true){
				form.action ='?page=Proses-Temp-Pengeluaran&Act=SAVEJ';
				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.currency.value==0) ){
			alert("Silakan pilih currency.");
			form.currency.focus();
			return false;
		}else{
			form.action ='?page=Proses-Temp-Pengeluaran&Act_Det=ADD_DET';
			form.method = 'post';
			form.submit();			
			return true;
		}
	}
	function delete_detail_click(id){
		form.action ='?page=Proses-Temp-Pengeluaran&Act_Det=DELETE_DET&id_deth='+id;
		form.method = 'post';
		form.submit();			
		return true;
	}
	function edit_detail_click(id){
		form.action ='?page=Proses-Temp-Pengeluaran&Act_Det=UPDATE_DET&id_deth='+id;
		form.method = 'post';
		form.submit();			
		return true;
	}
	function close_click(){
		form.action ='?page=Proses-Temp-Pengeluaran&Act=CLOSE'
		form.method = 'post';
		form.submit();		
		return true;
	}	
</script>
<body>
<form action="#" method="post" name="form" target="_self" enctype="multipart/form-data">
<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="fromdate" value="<?php echo $fromdate; ?>" size="50" />
			<input type="hidden" name="todate" value="<?php echo $todate; ?>" size="50" />
			<input type="hidden" name="trcid" value="<?php echo $trcid; ?>" size="50" />
			<input type="hidden" name="thn_acct"  id="thn_acct" value="<?php echo $thn_acct; ?>" size="50" />
	        <input type="text" name="jurnal_no" value="<?php echo $jurnal_no; ?>" size="20"/>			
      </td>
	  <td width="15%">Pos Data</td>
	  <td width="35%">:  
		<select name="jurnal_ptype">
		  <?php if($jurnal_ptype=="CS"){ ?>	
			<option value="BLANK" PILIH</option> 
			<option value="CS"selected="selected">Kas</option> 
			<option value="BK">Bank</option> 
			<option value="HT">Hutang</option> 
			<option value="PT">Piutang</option> 
			<option value="OT">Lain-Lain</option> 
		  <?php }elseif($jurnal_ptype=="BK"){ ?>
		    <option value="BLANK">PILIH</option> 
			<option value="CS">Kas</option> 
			<option value="BK" selected="selected">Bank</option> 
			<option value="HT">Hutang</option> 
			<option value="PT">Piutang</option> 
			<option value="OT">Lain-Lain</option> 
		  <?php }elseif($jurnal_ptype=="HT"){ ?>
		    <option value="BLANK">PILIH</option> 
			<option value="CS">Kas</option> 
			<option value="BK">Bank</option> 
			<option value="HT" selected="selected">Hutang</option> 
			<option value="PT">Piutang</option> 
			<option value="OT">Lain-Lain</option> 
		  <?php }elseif($jurnal_ptype=="PT"){ ?>
		   <option value="BLANK">PILIH</option> 
			<option value="CS">Kas</option> 
			<option value="BK">Bank</option> 
			<option value="HT">Hutang</option> 
			<option value="PT" selected="selected">Piutang</option> 
			<option value="OT">Lain-Lain</option> 
		  <?php }elseif($jurnal_ptype=="OT"){ ?>
			<option value="BLANK">PILIH</option> 
			<option value="CS">Kas</option> 
			<option value="BK">Bank</option> 
			<option value="HT">Hutang</option> 
			<option value="PT">Piutang</option> 
			<option value="OT" selected="selected">Lain-Lain</option> 
		  <?php }else{ ?>
			<option value="BLANK"selected="selected">PILIH</option> 
			<option value="CS">Kas</option> 
			<option value="BK">Bank</option> 
			<option value="HT">Hutang</option> 
			<option value="PT">Piutang</option> 
			<option value="OT">Lain-Lain</option> 
		  <?php }?>
		</select>	
	   </td>
	</tr>
	<tr>
		<td>Tanggal Jurnal</td>
		<td>: <input type="text" name="jurnal_date" value="<?php echo $jurnal_date; ?>" size="12" id="bpbdate" 
			   readonly="true" style="background-color:#CCFFFF " /> </td>
		<td>Nomor Faktur</td>
		<td>: <input type="text" name="fakturno" value="<?=$fakturno;?>" size="20" />	
		</td>
	</tr>
	<tr>
		<td>Supplier/Customer</td>
		<td>: <input type="text" name="supcustname" value="<?=$supcustname;?>" size="50" />		
        </td>
		<td>No NPWP</td>
		<td>: <input type="text" name="npwpno" value="<?=$npwpno;?>" size="20"></td>
	</tr>
	<tr>
		<td>No Invoice</td>
		<td>: <input type="text" name="invno" value="<?=$invno;?>"></td>
		<td>Tanggal Invoice</td>
		<td>: <input type="text" name="invdate" value="<?php echo $invdate; ?>" size="12" id="invdate" 
			   readonly="true" style="background-color:#CCFFFF " /></td>
	</tr>
	<tr>
		<td>No Dokumen</td>
		<td>: <input type="text" name="docno" value="<?=$docno;?>"></td>
		<td>Tanggal Dokumen</td>
		<td>: <input type="text" name="docdate" value="<?php echo $docdate; ?>" size="12" id="docdate" 
			   readonly="true" style="background-color:#CCFFFF " /></td>
	</tr>
	<tr>
		<td>Jenis Dokumen</td>
		<td>: <input type="text" name="doctype" value="<?=$doctype;?>" size="10"></td>
		<td>Mata Uang & Kurs</td>
		<td>: 
        	<select name="currency">
					<?php
					  $dataSql = mysql_query("SELECT currency FROM currency ORDER BY id ASC");
					  while ($dataRow = mysql_fetch_array($dataSql)) {
						if ($dataRow['currency']== $currency) {
							$cek = " selected";
						} else { $cek=""; }
						echo "<option value='$dataRow[currency]' $cek>$dataRow[currency]</option>";
					  }
					  $sqlData ="";
					?>
			</select> <input type="text" name="kurs" value="<?=$kurs;?>" size="10" style="text-align:right">
        </td>
	</tr>
	<tr>
		<td>Nilai IDR</td>
		<td>: <input type="text" name="nilaiidr" value="<?=$nilaiidr;?>" size="10" style="text-align:right"></td>
		<td>Nilai NonIDR</td>
		<td>: <input type="text" name="nilaiusd" value="<?=$nilaiusd;?>" size="10" style="text-align:right"></td>
	</tr>
	<tr>
		<td colspan="4">&nbsp;</td>
	</tr>
	<tr>
		<th colspan="4">DETAIL</th>
	</tr>
	<tr>
		<td colspan="4">
			<table width="100%" border="0">
				<tr>
					<td>No./Nama COA</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:#FFFFCC">                    
					<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">
			<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;
					$ttotal	  	  = $tdebit-$tkredit;
					$ttotal   	  = number_format($ttotal,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="ttotal" value="<?=$ttotal;?>" size="10" readonly style="text-align:center; background-color:#CCFFFF">
                    </td>
				</tr>
			</table>			
		</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>
</form>
</body>
</html> 
