<?php 
session_start();
ob_start();
include "../../include/config.php"; 
include "../../function/inc_function.php"; 
$user_id  	= $_SESSION['USER_ID'];
$user_name  = $_SESSION['USER_NAME'];
$jurnal_id  = $_REQUEST['jurnal_id'];

$sqlShow 	= mysql_query("SELECT prof_name FROM profil");
$dataShow 	= mysql_fetch_array($sqlShow);
$hd = mysql_fetch_array(mysql_query("SELECT a.*,d.dept_name, e.mb_bank FROM jurnal a
					   LEFT JOIN departement d ON d.id=a.jurnal_iddept
					   LEFT JOIN master_bank e ON e.id=a.jurnal_idbank					   	   
					   WHERE a.id='$jurnal_id'"));
if(empty($hd['jurnal_suppname'])){ $nama=$hd['jurnal_custname'];}else{$nama=$hd['jurnal_suppname'];}

?>
<html>
<head>
<link rel='stylesheet' type='text/css' href="../../include/css/printdoc_styles.css" />
</head>
<body>
<table align='center' class="tables_inoutsss">
	<tr>
		<th align='left'><h3><?php echo strtoupper($dataShow['prof_name']);?></h3> </th>
	</tr>
	<tr>
		<h4><th align='left'><?php $infoKbSql  = mysql_query("SELECT * from profil");
		$infoKbRow  = mysql_fetch_array($infoKbSql);
		echo $infoKbRow['prof_city'];?>
		</th></h4>
	</tr>
</table>
<br>
<table border='0' align="right" class="tables_inouts">
	<tr>
		<th align='left'><?php echo "Date	: "; echo date('d/m/y'); ?> </th>
	</tr>
	<tr>
		<th align='left'><?php echo "Time	: "; echo date ('H:i:s a'); ?> </th>
	</tr>
	<tr>
		<th align='left'><?php echo "User ID	: "; ?> <?=$user_name;?> </th>
	</tr>
</table>

<table align='center'>
	<tr>
		<td><h2>PAYMENT VOUCHER</h2></td>
	</tr>
</table>

<table align='center' class="tables_inoutss">
	<tr>
		<th align='left'><?php echo "Date	: "; echo $hd['jurnal_date']; ?> </th>
		<th align='right'><?php echo "VOUCHER NO : $hd[jurnal_no] "; ?> </th>
	</tr>
</table>

<table align="center" class="tables_inout">	
    <tr>
        <th colspan='3' style="width:450px;">Division : <?=$hd['dept_name'];?></th>
        <th colspan='3' style="width:450px;">Cash/Bank : <?=$hd['jurnal_ptype'];?></th>
	</tr>
	<tr>
        <th colspan='3'>Cust/Supp : <?=$nama;?></th>
        <th colspan='3'>Invoice No : <?=$hd['jurnal_invno'];?></th>
	</tr>
	<tr>
        <th colspan='3'>Faktur No : <?=$hd['jurnal_nofaktur'];?></th>
        <th colspan='3'>&nbsp;</th>
	</tr>
	<tr>
		<th rowspan='2'>Acc No.</th>
		<th rowspan='2'>Acc Name.</th>
		<th rowspan='2' colspan='2'>Description</th>
		<th colspan='2'>Ammount</th>
	</tr>
	<tr>
		
		<th >Debet</th>
		<th >Kredit</th>
	</tr>
	<?php
		$no=0; $tdebit=0; $tkredit=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='$hd[jurnal_no]' ORDER BY a.jurnald_status, a.id DESC");
		while($dt=mysql_fetch_array($qd)){	   
		$no++;
		if($hd['jurnal_currency']!='IDR'){
			$debit 	  = $dt['debit_usd'];
			$kredit   = $dt['kredit_usd'];
			$tdebit   = $tdebit + $debit;
			$tkredit  = $tkredit + $kredit;
		}else{
			$debit 	  = $dt['debit'];
			$kredit   = $dt['kredit'];
			$tdebit   = $tdebit + $debit;
			$tkredit  = $tkredit + $kredit;
		}
		$total	  = $tdebit-$tkredit
		
	?> 	
	<tr>
		<th><?=$dt['j_acctno'];?></th>
		<th align='left' style='text-align:left'><?=$dt['j_name1'];?></th>
		<th colspan='2' align='left' style='text-align:left'><?=$dt['jurnald_desc'];?></th>
		<th align='right'><?=number_format($debit,2,'.',',');?></th>
		<th align='right'><?=number_format($kredit,2,'.',',');?></th>
	</tr>	
	<?php } ?>
    <tr>
		<th colspan="4" align="right">Total</th>
		<th align='right'><?=number_format($tdebit,2,'.',',');?></th>
		<th align='right'><?=number_format($tkredit,2,'.',',');?></th>
	</tr>
    <tr>
		<th></th>
		<th></th>
		<th colspan='2'></th>
		<th ></th>
		<th ></th>
	</tr>
	<tr>
		<th colspan='2'>Currency : <?=$hd['jurnal_currency'];?></th>
		<th colspan='2'>No. Cheque : <?=$hd['jurnal_chequeno'];?></th>
		<th colspan='2'>Bank Name : <?=$hd['mb_bank'];?> </th>
	</tr>
	
	<tr>
		<th colspan='2'>Due Date : <?=$hd['jurnal_duedate'];?> </th>
		<th colspan='2'>No. Giro : <?=$hd['jurnal_girono'];?></th>
		<th colspan='2'>Rate : <?=$hd['jurnal_rate'];?></th>
	</tr>

	<tr>
		<th>In Change</th>
		<th>Gen. Mgr</th>
		<th>Dir.</th>
		<th>Pres Dir.</th>
		<th>Received By</th>
		<th>Tanggal/Nama</th>
	</tr>	
	<tr>
		<td style="height:90px;width:150px;">&nbsp;</td>
		<td style="width:150px;">&nbsp;</td>
		<td style="width:150px;">&nbsp;</td>
		<td style="width:150px;">&nbsp;</td>
		<td style="width:150px;">&nbsp;</td>
		<td style="width:150px;">&nbsp;</td>
	</tr>

	</table>
<?php  
	 #PDF
	 /*$filename="Jurnal_Account_Payable.pdf";   
	 $content = ob_get_clean();  
	 //$content = '<page style="font-family: Arial;">'.nl2br($content).'</page>';  
	 require_once('../../function/html2pdf/html2pdf.class.php');  
	 try  
	 {  
	  //$html2pdf = new HTML2PDF('P',array(240,280),'en', false, 'ISO-8859-15',array(0, 0, 0, 0));  
	  $html2pdf = new HTML2PDF('P','A4','en', false, 'ISO-8859-15',array(0, 0, 0, 0));
	  $html2pdf->setDefaultFont('Arial');  
	  $html2pdf->writeHTML($content, isset($_GET['vuehtml']));  
	  $html2pdf->Output($filename);  
	 }  
	 catch(HTML2PDF_exception $e) { echo $e; }*/
?> 