<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: 0;
    padding: 0;
}
#_body{
	margin: 20px;
	width: 560px;
	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;
}
._infoTab{
	width: 100%;
}
._infoLbl{
	width: 80px;
}
._infoColon{
	width: 15px;
}
._detTab{
	width: 100%;
	margin-top: 10px;
	table-layout: fixed;
	border-collapse: collapse;
	border: 1px solid #000;
}
._borderRight{

}
._detTab tr th{
	font-weight: normal;
	font-size: 14px;
	padding: 3px;
	border: 1px solid #000;
	box-sizing: border-box;
}
._detTab tr td{
	font-size: 14px;
	padding: 3px;
	border: 1px solid #000;
	box-sizing: border-box;
	word-wrap: break-word;
}
._colOp{ width: 45px; }
._colTgl{ width: 100px; }
._colNopol{ width: 85px; }
._colNetto{ width: 85px; }
._colHarga{ width: 85px; }
._colJumlah{ width: 112px; }
._bottom{
	border-top: 1px solid #000;
}
._footer{
	border-bottom: 1px solid #000;
}
.font12{
	font-size: 12px;
}
._warn{
	font-weight: bold;
	text-decoration: underline;
}
._sign{
	width: 100%;
}
._sign td{
	font-size: 14px;
	vertical-align: top;
}
</style>

<?php
$date = new Date;
$konversi = new Konversi;

// chunk detail rows into pages, PAGE_SIZE rows each
$pageSize = 10;
$bag = array();
$pg = 1;
$nom = 1;
foreach($this->data->det as $r){
	$bag[$pg][] = $r;
	if($nom >= $pageSize){
		$nom = 1;
		$pg++;
	}else{
		$nom++;
	}
}

// grand totals across ALL pages, computed up front
$totNetto = 0;
$totJumlah = 0;
foreach($this->data->det as $r){
	$totNetto += $r->netto;
	$totJumlah += $r->jumlah;
}

$no = 1;
foreach($bag as $noPage => $det){
?>
<div id="_body">
    <h3 align="center">INVOICE</h3>
    <br><br>
	<table class="_infoTab" cellspacing="0" cellpadding="0">
		<tr>
			<td style="width: 330px; vertical-align: top">
				<table cellspacing="0" cellpadding="0">
					<tr>
						<td class="_infoLbl">Supplier</td>
						<td class="_infoColon">:</td>
						<td><b><?php echo $this->login['pt'] ?></b></td>
					</tr>
					<tr>
						<td class="_infoLbl">Alamat</td>
						<td class="_infoColon">:</td>
						<td><?php echo $this->login['alamat_cabang'] ?></td>
					</tr>
					<tr>
						<td class="_infoLbl">NPWP</td>
						<td class="_infoColon">:</td>
						<td><?php echo $this->login['npwp'] ?></td>
					</tr>
				</table>
			</td>
			<td style="width: 230px; vertical-align: top">
				<p class="_hed2">No : <?php echo $this->data->data->nonjl ?></p>
			</td>
		</tr>
		<tr>
			<td colspan="2" style="padding-top: 10px;">
				<table cellspacing="0" cellpadding="0">
					<tr>
						<td class="_infoLbl">Customer</td>
						<td class="_infoColon">:</td>
						<td><b><?php echo $this->data->data->nm_sub ?></b></td>
					</tr>
					<tr>
						<td class="_infoLbl">Alamat</td>
						<td class="_infoColon">:</td>
						<td>
							<?php echo $this->data->sub->alamat ?><br>
							<?php echo $this->data->sub->kota ?>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<table class="_detTab" cellspacing="0" cellpadding="0">
					<thead>
						<tr>
							<th align="left" class="_colOp" style="width: 80px;">OP</th>
							<th align="left" class="_colTgl" style="width: 110px;">Tgl Bongkar</th>
							<th align="left" class="_colNopol" style="width: 110px;">Nopol</th>
							<th align="right" class="_colNetto" style="width: 90px;">Netto</th>
							<th align="right" class="_colHarga" style="width: 90px;">Harga</th>
							<th align="right" class="_colJumlah _borderRight" style="width: 120px;">Jumlah</th>
						</tr>
					</thead>
					<tbody>
						<?php
						$subT = 0;
						foreach($det as $row){
							$jpak = $this->em->getFind("jpak", "*", array("nopak = '".$row->noref."'"));
						?>
							<tr>
								<td align="center" class="_colOp" style="width: 80px;">
    								<?php 
                                    	$noref_parts = explode("-", $row->noref);
                                    	$op = explode(".", end($noref_parts))[0];
                                    	echo $op;
                                    ?>
                                </td>
								<td align="left" class="_colTgl" style="width: 110px;"><?php echo $date->tglIndo($jpak->tgl) ?></td>
								<td align="left" class="_colNopol" style="width: 110px;"><?php echo $jpak->nopol ?></td>
								<td align="right" class="_colNetto" style="width: 90px;"><?php echo number_format($row->qty) ?></td>
								<td align="right" class="_colHarga" style="width: 90px;"><?php echo number_format($row->harga) ?></td>
								<td align="right" class="_colJumlah _borderRight" style="width: 120px;"><?php echo number_format($row->total) ?></td>
							</tr>
						<?php
						}
						$sis = $pageSize - count($det);
						for($i = 1; $i <= $sis; $i++){
						?>
							<tr>
								<td style="width: 80px;">&nbsp;</td>
								<td style="width: 110px;">&nbsp;</td>
								<td style="width: 110px;">&nbsp;</td>
								<td style="width: 90px;">&nbsp;</td>
								<td style="width: 90px;">&nbsp;</td>
								<td class="_borderRight" style="width: 120px;">&nbsp;</td>
							</tr>
						<?php
						}
						$pph = $this->data->data->gtot * 0.0025;
		                ?>
						<tr>
							<td colspan="5" class="_bottom">
								TOTAL
							</td>
							<td class="_bottom _borderRight" style="text-align: right; font-weight: bold"><?php echo number_format($this->data->data->gtot) ?></td>
						</tr>
						<tr>
							<td colspan="5" class="_bottom font12" style="border-top: none">
								PPH 0,25%
							</td>
							<td class="_bottom _borderRight" style="border-top: none; text-align: right"><?php echo number_format($pph) ?></td>
						</tr>
						<tr>
							<td colspan="5" class="_bottom _footer" style="border-top: none; height: 50px;">
								GRAND TOTAL
							</td>
							<td class="_bottom _footer _borderRight" style="border-top: none; text-align: right; height: 50px; font-weight: bold"><?php echo number_format($this->data->data->gtot - $pph) ?></td>
						</tr>
					</tbody>
				</table>
				<?php if($noPage == count($bag)){ ?>

                <table style="width:100%; margin-top:12px;" cellspacing="0" cellpadding="0">
                    <tr>
                        <td style="width:75px; vertical-align:top;">
                            Terbilang
                        </td>
                        <td style="width:10px; vertical-align:top;">
                            :
                        </td>
                        <td>
                            <?php echo strtoupper($konversi->konversi($this->data->data->gtot)); ?>
                            RUPIAH
                        </td>
                    </tr>
                </table>
                
                <table style="width:100%; margin-top:20px;" cellspacing="0" cellpadding="0">
                    <tr>
                
                        <!-- LEFT -->
                        <td style="width:55%; vertical-align:top;">
                
                            <p>Untuk pembayaran <?php echo strtolower($this->data->det[0]->nm_inv) ?></p>
                
                            <p class="_warn" style="margin-top:10px;">
                                Perhatian, invoice ini digunakan untuk bukti penjualan
                            </p>
                
                            <div style="height:35px;"></div>
                
                            <p>Pembayaran di transfer ke :</p>
                
                            <p style="margin-top:10px;">
                                <strong><?php echo $this->login['pt']; ?></strong>
                            </p>
                
                            <p style="margin-top:5px;">
                                <strong><?php echo $this->login['no_rek']; ?></strong>
                            </p>
                
                            <p style="margin-top:5px;">
                                <strong><?php echo $this->login['nm_bank']; ?></strong>
                            </p>
                
                        </td>
                
                        <!-- RIGHT -->
                        <td style="width:45%; vertical-align:top; text-align:right;">
                
                            <p align="center">
                                <?php echo $this->login['nm_kota']; ?>,
                                <?php echo $date->tglIndo($this->data->data->tgl); ?>
                                <br><br><br><br><br><br><br><br>
                                <?php echo $this->login['ttd_nama']; ?>
                            </p>
                        </td>
                
                    </tr>
                </table>
                
                <?php } ?>
			</td>
		</tr>
	</table>
</div>
<?php
if($noPage == count($bag)){
}else{
?>
<div class="page-break"></div>
<?php
	}
}
?>
