<html>
<head>
<link rel="stylesheet" href="include/freeze/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="include/freeze/css/fixedColumns.dataTables.min.css">
<script type="text/javascript" src="include/freeze/js/jquery-3.5.1.js"></script>
<script type="text/javascript" src="include/freeze/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="include/freeze/js/dataTables.fixedColumns.min.js"></script>
<script type="text/javascript" language="javascript">
	var f=jQuery.noConflict();  
	f(document).ready(function() {
		var table = f('#myTables').DataTable( {
			scrollY:        "450px",
			scrollX:        true,
			scrollCollapse: true,
			paging:         false,
			fixedColumns:   {
				leftColumns:4
			}
		} );
	} );	
	$(document).ready(function(){ 
		$("#fromdate").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	$(document).ready(function(){
		$("#todate").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});	
	function setTrColor(obj, color)
	{
		obj.style.backgroundColor=color;
		obj.onmouseout = function(){
				obj.style.backgroundColor=''; 
		}
	}
	function search_click(){
		form.action ='?page=Data-Temp-Pengeluaran&Act=CARI';
		form.method = 'post';
		form.submit();			
		return true;
	}	
	function save_click(){
		form.action ='?page=Proses-Temp-Pengeluaran&Act=SAVE';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function print_click(id){
		window.open("popup/print_pengeluaran.php?outh_id="+id,"mywindow","menubar=1,scrollbars=1,resizable=1,width=700,height=1000");
	}
	function edit_amount(id){
		window.open("transaksi/akuntansi/popup_edit_pengeluaran.php?outh_id="+id,"mywindow","menubar=1,scrollbars=1,resizable=1,width=800,height=400");
	}
	function detail_click(id,fromdate,todate){
		form.action ='?page=Proses-Temp-Pengeluaran&Act=DETAIL&outh_id='+id+'&fromdate='+fromdate+'&todate='+todate;
		form.method = 'post';
		form.submit();		
		return true;
	}
	function detail2_click(id,fromdate,todate){
		form.action ='?page=Proses-Temp-Pengeluaran&Act=DETAIL2&outh_id='+id+'&fromdate='+fromdate+'&todate='+todate;
		form.method = 'post';
		form.submit();		
		return true;
	}
	function excel_click(){
		form.action ='./transaksi/akuntansi/export_temp_pengeluaran.php';
		form.method = 'post';
		form.submit();			
		return true;
	}
</script>
<style type="text/css">
    th, td { white-space: nowrap; }
    div.dataTables_wrapper {
        width: 100%;
        margin: 0 auto;
    }
</style>
</head>
<?php
	$fromdate = isset($_REQUEST['fromdate']) ? $_REQUEST['fromdate'] : $date;
	$todate   = isset($_REQUEST['todate']) ? $_REQUEST['todate'] : $date;
	$cust_name2= isset($_REQUEST['cust_name2']) ? $_REQUEST['cust_name2'] : "SEMUA";
	if($cust_name2=="SEMUA"){$custname = "";}else{ $custname = "AND nm_penerima LIKE '%$cust_name2%'"; }
?>
<body>
<form action="#" method="post" name="form" enctype="multipart/form-data">
<table width="100%" border="0" cellspacing="1" cellpadding="1">
  <tr>
	<td colspan="10" align="center"><h1><b>DATA OUTBOX (PENGELUARAN)</b></h1></td>
  </tr>
  <tr>
	<td colspan="10">Periode :
	     <input type="text" id="fromdate" name="fromdate" size="9" value="<?=$fromdate;?>" style="border-collapse:inherit"  readonly="true">&nbsp;s/d&nbsp;
	     <input type="text" id="todate" name="todate" size="9" value="<?=$todate;?>" style="border-collapse:inheri" readonly="true">
	     Customer : <input type="text" name="cust_name2" size="30" value="<?=$cust_name2;?>" style="border-collapse:inheri">
		 <input type="button" name="cari" value="CARI" style="cursor:pointer" onClick="search_click();">
		 <input type="button" name="save" value="SIMPAN" style="cursor:pointer" onClick="save_click();">
		 <input type="button" name="export" value="EXCEL" style="cursor:pointer" onClick="excel_click();" />
	</td>		
  </tr>
</table>
<table id="myTables" class="stripe row-border order-column">
 <thead>	
   <tr>
	<th rowspan="2">No</th>
	<th rowspan="2">Jenis</th>
	<th rowspan="2">No. Daftar</th>
	<th rowspan="2">Tgl Daftar</th>
	<th rowspan="2">Penerima</th>
	<th rowspan="2">Valuta</th>
	<th colspan="2">Nilai</th>
	<th rowspan="2">Maklon</th>
	<th rowspan="2">Kurs</th>
	<th rowspan="2">Pos Data</th>
	<th rowspan="2">No Jurnal</th>
	<th rowspan="2">Tgl Jurnal<br>YYYY-MM-DD</th>
	<th rowspan="2">No Inv</th>
	<th rowspan="2">Tgl Inv<br>YYYY-MM-DD</th>
	<th rowspan="2">No Faktur</th>
	<th rowspan="2">NPWP</th>
	<th rowspan="2">Debit 1</th>
	<th rowspan="2">Debit 2</th>
	<th rowspan="2">Debit 3</th>
	<th rowspan="2">Debit 4</th>	
	<th rowspan="2">Kredit 1</th>
	<th rowspan="2">Kredit 2</th>
	<th rowspan="2">Kredit 3</th>
	<th rowspan="2">Kredit 4</th>	
	<th rowspan="2">Action</th>
  </tr>
  <tr>
	<th>Non IDR</th>
	<th>IDR</th>
  </tr>
  </thead>
	<tbody>
  <?php
    $no=1; $gtprice=0;
	$qd = mysql_query("SELECT * FROM outgoing WHERE outh_status=20 AND outh_docdate BETWEEN '$fromdate' AND '$todate' AND (outh_paytype is null OR outh_paytype='') 
	      $custname ORDER BY id DESC");
	while($dd=mysql_fetch_array($qd)){		
		$cek = mysql_fetch_array(mysql_query("SELECT outd_currency, SUM(outd_price) nilai_idr, SUM(outd_price_usd) nilai_nidr, SUM(harga_maklon) h_maklon  FROM outgoing_detail 
		       WHERE outd_hid='$dd[id]' GROUP BY outd_currency"));
		if($dd['outh_rate']>0){$outh_rate=$dd['outh_rate'];}else{$outh_rate=0;}
		if(!empty($dd['outh_jurnaldate'])){$outh_jurnaldate=$dd['outh_jurnaldate'];}else{$outh_jurnaldate="";}	
		if($cek['outd_currency']=="IDR"){$debkred=$cek['nilai_idr'];}else{$debkred=$cek['nilai_nidr'];}   
	?> 
	 <tr onMouseOver="setTrColor(this, '#FF9900');">
		<td align="center"><?=$no;?>.</td>
		<td align="center"><?=$dd['outh_doctype'];?></td>
		<td align="center"><?=$dd['outh_docno'];?></td>
        <td align="center"><?=$dd['outh_docdate'];?></td>
        <td align="left"><?=$dd['nm_penerima'];?></td>
		<td align="center">
		  <select name="outh_currency[<?=$dd['id'];?>]">
			<?php
			  $dataSql = mysql_query("SELECT currency FROM currency ORDER BY id ASC");
			  while ($dataRow = mysql_fetch_array($dataSql)) {
			  		if($dataRow['currency']==$cek['outd_currency']){
						$cek1 ="selected";
					}else{ $cek1 ="";}
				echo "<option value='$dataRow[currency]' $cek1>$dataRow[currency]</option>";
			  }
			  $sqlData ="";
			?>
		 </select>
		</td>
		<td align="right"><a href="javascript: edit_amount(<?=$dd['id'];?>)"><?=number_format($cek['nilai_nidr'],0,'',',');?></a></td>
		<td align="right"><a href="javascript: edit_amount(<?=$dd['id'];?>)"><?=number_format($cek['nilai_idr'],0,'',',');?></a></td>
		<td align="right"><?=number_format($cek['h_maklon'],0,'',',');?></td>
		<!--<td align="center"><input type="text" size="10" name="outh_ajd_nidr[<?=$dd['id'];?>]" value="<?=$dd['outh_ajd_nidr'];?>" style="text-align:right"/></td>
		<td align="center"><input type="text" size="10" name="outh_ajd[<?=$dd['id'];?>]" value="<?=$dd['outh_ajd'];?>" style="text-align:right"/></td>-->
		<td align="center"><input type="text" size="10" name="outh_rate[<?=$dd['id'];?>]" value="<?=$outh_rate;?>" style="text-align:right"/></td>
		<td align="center">
		   <input type="hidden" name="outh_doctype[<?=$dd['id'];?>]" value="<?=$dd['outh_doctype'];?>" />
		   <input type="hidden" name="outh_docno[<?=$dd['id'];?>]" value="<?=$dd['outh_docno'];?>" />
		   <input type="hidden" name="outh_nilai[<?=$dd['id'];?>]" value="<?=$cek['nilai_idr'];?>" />
		   <input type="hidden" name="outh_nilai_nidr[<?=$dd['id'];?>]" value="0" />
		   <!--<input type="hidden" name="outh_currency[<?=$dd['id'];?>]" value="<?=$cek['outd_currency'];?>" />-->
		   <input type="hidden" name="cust_name[<?=$dd['id'];?>]" value="<?=$dd['nm_penerima'];?>" />
           <input type="hidden" name="pilih[<?=$dd['id'];?>]" value="<?=$dd['id'];?>" />
		   <select name="type[<?=$dd['id'];?>]">
				<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> 
		 </select>
		</td>
		<td align="center">
		   <input type="text" name="outh_jurnalno[<?=$dd['id'];?>]" value="<?=$dd['outh_jurnalno'];?>" size="20"/>
		</td>
		<td align="center">
		   <input type="text" name="outh_jurnaldate[<?=$dd['id'];?>]" value="<?=$dd['outh_invdate'];?>" size="8" maxlength="10"/>
		</td>
		<td align="center">
		   <input type="text" name="outh_invno_acct[<?=$dd['id'];?>]" value="<?=$dd['outh_invno'];?>" size="30"/>
		</td>
		<td align="center">
		   <input type="text" name="outh_invdate_acct[<?=$dd['id'];?>]" value="<?=$dd['outh_invdate'];?>" size="10"/>
		</td>
		<td align="center">
		   <input type="text" name="outh_dono[<?=$dd['id'];?>]" value="<?=$dd['outh_dono'];?>" size="20"/>
		</td>
		<td align="center">
		   <input type="text" name="id_penerima[<?=$dd['id'];?>]" value="<?=$dd['id_penerima'];?>" size="20"/>
		</td>
		<td align="center">
		  <select name="outh_debit1[<?=$dd['id'];?>]">
		   <option value="BLANK" selected="selected">PILIH</option> 
			<?php
			  $dataSql = mysql_query("SELECT j_acctno, j_name1 FROM jurnal_master WHERE j_status=10 ORDER BY j_acctno ASC");
			  while ($dataRow = mysql_fetch_array($dataSql)){
				echo "<option value='$dataRow[j_acctno]'>$dataRow[j_acctno]-$dataRow[j_name1]</option>";
			  }	
			  $sqlData ="";
			?>
		 </select><input type="text" size="10" name="outh_damount1[<?=$dd['id'];?>]" value="<?=$debkred;?>" style="text-align:right"/>
		</td>
		<td align="center">
		  <select name="outh_debit2[<?=$dd['id'];?>]">
		   <option value="BLANK" selected="selected">PILIH</option> 
			<?php
			  $dataSql = mysql_query("SELECT j_acctno, j_name1 FROM jurnal_master WHERE j_status=10 ORDER BY j_acctno ASC");
			  while ($dataRow = mysql_fetch_array($dataSql)){
				echo "<option value='$dataRow[j_acctno]'>$dataRow[j_acctno]-$dataRow[j_name1]</option>";
			  }	
			  $sqlData ="";
			?>
		 </select><input type="text" size="10" name="outh_damount2[<?=$dd['id'];?>]" value="0" style="text-align:right"/>
		</td>
		<td align="center">
		  <select name="outh_debit3[<?=$dd['id'];?>]">
		   <option value="BLANK" selected="selected">PILIH</option> 
			<?php
			  $dataSql = mysql_query("SELECT j_acctno, j_name1 FROM jurnal_master WHERE j_status=10 ORDER BY j_acctno ASC");
			  while ($dataRow = mysql_fetch_array($dataSql)){
				echo "<option value='$dataRow[j_acctno]'>$dataRow[j_acctno]-$dataRow[j_name1]</option>";
			  }	
			  $sqlData ="";
			?>
		 </select><input type="text" size="10" name="outh_damount3[<?=$dd['id'];?>]" value="0" style="text-align:right"/>
		</td>
		<td align="center">
		  <select name="outh_debit4[<?=$dd['id'];?>]">
		   <option value="BLANK" selected="selected">PILIH</option> 
			<?php
			  $dataSql = mysql_query("SELECT j_acctno, j_name1 FROM jurnal_master WHERE j_status=10 ORDER BY j_acctno ASC");
			  while ($dataRow = mysql_fetch_array($dataSql)){
				echo "<option value='$dataRow[j_acctno]'>$dataRow[j_acctno]-$dataRow[j_name1]</option>";
			  }	
			  $sqlData ="";
			?>
		 </select><input type="text" size="10" name="outh_damount4[<?=$dd['id'];?>]" value="0" style="text-align:right"/>
		</td>		
		<td align="center">
		  <select name="outh_kredit1[<?=$dd['id'];?>]">
		   <option value="BLANK" selected="selected">PILIH</option> 
			<?php
			  $dataSql = mysql_query("SELECT j_acctno, j_name1 FROM jurnal_master WHERE j_status=10 ORDER BY j_acctno ASC");
			  while ($dataRow = mysql_fetch_array($dataSql)) {
				echo "<option value='$dataRow[j_acctno]'>$dataRow[j_acctno]-$dataRow[j_name1]</option>";
			  }
			  $sqlData ="";
			?>
		 </select><input type="text" size="10" name="outh_kamount1[<?=$dd['id'];?>]" value="<?=$debkred;?>" style="text-align:right"/>
		</td>
		<td align="center">
		  <select name="outh_kredit2[<?=$dd['id'];?>]">
		   <option value="BLANK" selected="selected">PILIH</option> 
			<?php
			  $dataSql = mysql_query("SELECT j_acctno, j_name1 FROM jurnal_master WHERE j_status=10 ORDER BY j_acctno ASC");
			  while ($dataRow = mysql_fetch_array($dataSql)) {
				echo "<option value='$dataRow[j_acctno]'>$dataRow[j_acctno]-$dataRow[j_name1]</option>";
			  }	
			  $sqlData ="";
			?>
		 </select><input type="text" size="10" name="outh_kamount2[<?=$dd['id'];?>]" value="0" style="text-align:right"/>
		</td>	
		<td align="center">
		  <select name="outh_kredit3[<?=$dd['id'];?>]">
		   <option value="BLANK" selected="selected">PILIH</option> 
			<?php
			  $dataSql = mysql_query("SELECT j_acctno, j_name1 FROM jurnal_master WHERE j_status=10 ORDER BY j_acctno ASC");
			  while ($dataRow = mysql_fetch_array($dataSql)) {
				echo "<option value='$dataRow[j_acctno]'>$dataRow[j_acctno]-$dataRow[j_name1]</option>";
			  }	
			  $sqlData ="";
			?>
		 </select><input type="text" size="10" name="outh_kamount3[<?=$dd['id'];?>]" value="0" style="text-align:right"/>
		</td>	
		<td align="center">
		  <select name="outh_kredit4[<?=$dd['id'];?>]">
		   <option value="BLANK" selected="selected">PILIH</option> 
			<?php
			  $dataSql = mysql_query("SELECT j_acctno, j_name1 FROM jurnal_master WHERE j_status=10 ORDER BY j_acctno ASC");
			  while ($dataRow = mysql_fetch_array($dataSql)) {
				echo "<option value='$dataRow[j_acctno]'>$dataRow[j_acctno]-$dataRow[j_name1]</option>";
			  }
			  $sqlData ="";
			?>
		 </select><input type="text" size="10" name="outh_kamount4[<?=$dd['id'];?>]" value="0" style="text-align:right"/>
		</td>			
		<td align="center">
			<img src="images/btn_edit.png" width="20" height="20" border="0" title="Jurnal per 1 Dok" style="cursor:pointer" onClick="detail_click('<?=$dd['id'];?>','<?=$fromdate;?>','<?=$todate;?>');" />
			<img src="images/btn_print.png" height="20" width="20" title="Print" border="0" style="cursor:pointer" onClick="print_click('<?=$dd['id'];?>');" />
			<img src="images/btn_edit.png" width="20" height="20" border="0" title="Jurnal ke banyak supplier" style="cursor:pointer" onClick="detail2_click('<?=$dd['id'];?>','<?=$fromdate;?>','<?=$todate;?>');" />
		</td>
	  </tr>	  
  <?php $no++; }  ?> 
  </tbody> 
</table>
</form>
</body>
</html>
