<style type="text/css">
@page  
{ 
	margin: 0mm 0mm 0mm 1mm;  
} 
@media screen {
	.page-break	{ height:10px; border-top:1px dotted #999; margin-bottom:13px; }
}
@media print {
	.page-break { height:0; page-break-before:always; margin:0; border-top:none; }
}
#_body{
	margin: 20px;
	width: 700px;
	font-family: arial;
}
._hed{
	font-size: 14px;
	font-weight: bold;
}
._hed2{
	font-size: 14px;
}
p{
	margin: 0px;
	margin-bottom: 0px;
	font-size: 14px;
}
div{
	font-size: 14px;
}
._hed3{
	margin-top: -15px;
	margin-left: 110px;
}
._hed4{
	margin-top: -15px;
	margin-left: 60px;
}
._detTab{
	width: 100%;
	border-top: 1px solid #000;
	margin-top: 10px;
}
._borderRight{

}
._detTab tr th{
	font-weight: normal;
	font-size: 14px;
	padding: 3px;
	padding-bottom: 2px;
	border-bottom: 1px solid #000;
}
._detTab tr td{
	font-size: 14px;
	padding: 3px;
	padding-top: 1px;
	padding-bottom: 1px;
}
._bottom{
	border-top: 1px solid #000;
}
._footer{
	border-bottom: 1px solid #000;
}
._tot{
	width: 100%
}
._tot tr th{
	font-weight: normal;
	font-size: 14px;
}
._tot tr td{
	font-size: 14px;
}
.font12{
	font-size: 12px;
}
._height25{
	height: 50px;
}
._ttd tr td{
	text-align: center;
	width: 100px;
}
</style>

<?php
if(!empty($this->data->cabang->tgl_pengukuhan)){
	$this->data->cabang->tgl_pengukuhan = date("d-m-Y", strtotime($this->data->cabang->tgl_pengukuhan));
}

$date = new Date;

$bag = array();
$nom = 1;
$pg = 1;
foreach($this->data->det as $r){
	$bag[$pg][] = $r;
	if($nom > 10){
		$nom = 1;
		$pg++;
	}else{
		$nom++;
	}
}

?>

<?php 
$no = 1;
$kode = new Kode;
$disRp1 = 0;
$disRp2 = 0;
$disPer1 = 0;
$disPer2 = 0;
$bruto = 0;
$disc = 0;
$netto = 0;
$cab = 'HO';
$cab = $this->em->getFind("cabang", "*", array("kd_cabang = '".$cab."'"));
foreach($bag as $noPage => $det){
?>
<div id="_body">

	<table style="width: 100%">
	
		<tr>
			<td style="width: 400px; vertical-align: top">
				<?php?>
				<p class="_hed"><?php echo $cab->nm_cabang ?></p>
				<p class="_hed2">TELP. <?php echo $cab->telp ?></p>
				<p class="_hed2">KETERANGAN</p>
				<p class="_hed2 _hed3">: <?php echo $this->data->data->ket ?></p>
				<p class="_hed2">NOMOR</p>
				<p class="_hed2 _hed3">: <?php echo $this->data->data->nonbl ?></p>
			</td>
			<td style="width: 300px;">
				<p class="_hed">NOTA PEMBELIAN</p>
				<p class="_hed2" >Surabaya,<?php echo $date->tglIndo($this->data->data->tgl) ?></p>
				<p class="_hed2">Kepada Yth :</p>
				<p class="_hed2"><?php echo $this->data->data->nm_sub.' ('.$this->data->data->kd_sub.')' ?></p>
				<p class="_hed2"><?php echo $this->data->sub->alamat ?></p>
				<p class="_hed2"><?php echo $this->data->sub->kota ?></p>
				
			</td>
		</tr>
		<tr>
			<td colspan="3">
				<!--
				<p style="font-weight: bold;">NOTA NO : <?php echo $this->data->data->nonjl ?></p>
				<p style="font-weight: bold; margin-top: -13px; text-align: center;  width: 100%">BUKTI NOTA PENJUALAN</p>
				-->
			</td>
		</tr>
		<tr>
			<td colspan="3">
				<table class="_detTab" cellspacing="0" cellpadding="0">
					<thead>
						<tr>
							<th align="right" style="width: 30px;">No</th>
							<th style="width: 350px;">Description Of Good</th>
							<th align="right" style="width: 70px;">Qty</th>
							<th align="right" style="width: 80px;">Price</th>
							<th align="right" class="_borderRight" style="width: 80px;">Value</th>
						</tr>
					</thead>
					<tbody>
						<?php 
						$subT = 0;
						foreach($det as $row){ 
							$tot = $kode->totBertingkat($row);
							
							$disRp1  = $disRp1 + $tot['disrp1'];
							$disRp2  = $disRp2 + $tot['disrp2'];
							$disPer1 = $disPer1 + $tot['disper1'];
							$disPer2 = $disPer2 + $tot['disper2'];

							$bruto 	= $bruto + $tot['bruto'];
							$disc 	= $disc + $tot['dis'];
							$netto 	= $netto + $tot['tot'];
							$subT = $subT + $tot['tot'];
						?>
							<tr>
								<td align="right"><?php echo $no++ ?></td>
								<td><div style="width: 330px"><?php echo $row->nm_inv ?></div></td>
								<td align="right"><?php echo $row->qty.' '.$row->satuan ?></td>
								<td align="right"><?php echo number_format($row->harga) ?></td>
								<td align="right" class="_borderRight"><?php echo number_format($tot['tot']) ?></td>
							</tr>
						<?php 
						} 
						$max = 11;
						$sis = $max - count($this->data->det);
						for($i = 1; $i <= $sis; $i++){
						?>
							<tr>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<td class="_borderRight">&nbsp;</td>
							</tr>
						<?php } 
						if($noPage == count($bag)){
						?>
						<tr>
							<td colspan="2" rowspan="4" class="_bottom" style="border-left: none; border-bottom: none; font-size: 11px; vertical-align: top">
								<?php 
								$konversi = new Konversi;
								?>
								<p>Terbilang : </p>
								<p style="margin-top: -16px; margin-left: 70px; padding-right: 10px;"><?php echo strtoupper($konversi->konversi($this->data->data->gtot)) ?> RUPIAH</p>

								
								<table class="_ttd" style="width: 400px">
									<tr>
										<td>Mengetahui</td>
										<td>Pembuat</td>
									</tr>
									<tr>
										<td style="height: 30px;">&nbsp;</td>
									</tr>
									<tr>
										<td>( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</td>
										<td>( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</td>
									</tr>
								</table>
								
							</td>
							<td colspan="2" class="_bottom">
								SUB TOTAL
							</td>
							<?php
							$dpp = $this->data->data->gtot - $this->data->data->ppn_nilai;
							?>
							<td align="right" class="_bottom _borderRight"><?php echo number_format($subT) ?></td>
						</tr>
						<tr>
							<td colspan="2" class="_bottom" style="border-top: none">
								TOTAL
							</td>
							<td align="right" class="_bottom _borderRight" style="border-top: none"><?php echo number_format($bruto) ?></td>
						</tr>
						<tr>
							<td colspan="2" class="_bottom" style="border-top: none">
								DISC (<?php echo number_format($this->data->data->diskg, 2).'%+'.number_format($this->data->data->diskg2, 2).'%' ?>)
							</td>
							<td align="right" class="_bottom _borderRight" style="border-top: none"><?php echo number_format($this->data->data->diskg_nilai) ?></td>
						</tr>
						<tr>
							<td colspan="2" class="_bottom _footer" style="border-top: none; height: 50px;">
								Grand Total
							</td>
							<td align="right" class="_bottom _footer _borderRight" style="border-top: none; height: 50px"><?php echo number_format($this->data->data->gtot) ?></td>
						</tr>
						<?php }else{ ?>
							<td colspan="3" rowspan="4" class="_bottom" style="border-left: none; border-bottom: none; font-size: 11px; vertical-align: top">
							</td>
							<td colspan="1" class="_bottom">
								SUB TOTAL
							</td>
							<td align="right" class="_bottom _borderRight"><?php echo number_format($subT) ?></td>
						<?php } ?>
					</tbody>
				</table>
			</td>
		</tr>
	</table>

</div>

<?php
if($noPage == count($bag)){
}else{
?>
<div class="page-break"></div>
<?php 
	}
} 
?>
<script type="text/javascript">
function showDiv() {
	// window.print();
	// window.close();
	// clearInterval(timer);
}
var timer = setInterval( showDiv, 1000);

</script>
