<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;
	margin-left: 0px !important;
	width: 750px;
}
._hed{
	font-size: 18px;
	font-weight: bold;
}
._hed2{
	font-size: 14px;
}
p{
	margin: 0px;
	margin-bottom: 3px;
	font-size: 14px;
}
div{
	font-size: 14px;
}
._hed3{
	margin-top: -15px;
	margin-left: 130px;
}
._hed4{
	margin-top: -15px;
	margin-left: 80px;
}
._detTab{
	width: 100%;
	border-top: 1px solid #000;
}
._detTab tr th{
	font-weight: normal;
	font-size: 14px;
	padding: 3px;
	padding-bottom: 2px;
	border-bottom: 1px solid #000;
	border-left: 1px solid #000;
}
._detTab tr td{
	font-size: 14px;
	padding: 3px;
	border-left: 1px solid #000;
}
._right{
    border-right: 1px solid #000;
}
._bottom{
	border-top: 1px solid #000;
}
._footer{
	border-bottom: 1px solid #000;
}
._none{
    border: none;
}
._tot{
	width: 100%
}
._tot tr th{
	font-weight: normal;
	font-size: 14px;
}
._tot tr td{
	font-size: 14px;
}
</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;
$konversi = new Konversi;

$pages = [];
$page = 1;
$ctr = 1;
$no = 1;
foreach ($this->data->det as $row) {
    $pages[$page][] = $row;

    if ($ctr == 12) {
        $ctr = 1;
        $page++;
    } else {
        $ctr++;
    }
}

foreach ($pages as $pageIndex => $detPage) { ?>

<div id="_body">

	<table style="width: 100%">
		<tr>
			<td style="width: 46%;">
				<?php if($this->data->data->ppn_nilai!=0){ ?>
					<p class="_hed"><?php echo $this->data->cabang->nm_cabang ?></p>
					<p class="hed">JTH. TEMPO</p>
				    <p class="_hed2 _hed4">: <?php echo $date->tglIndo($date->nextDayDate($this->data->data->tgl, $this->data->data->top))?></p>
				<?php } else { ?>
				    <p class="_hed"><?php echo $this->data->cabang->kop ?></p>
				    <p class="_hed">&nbsp;</p>
				<?php } ?>
				
				<p class="hed">SALES</p>
				<p class="_hed2 _hed4">: <?php echo $this->data->data->nm_sales ?></p>
				<p class="_hed2">KETERANGAN</p>
				<p class="_hed2 _hed4">: <?php echo $this->data->data->ket ?></p>
				<p class="hed2">NOTA NO.</p>
				<p class="_hed2 _hed4">: <?php echo $this->data->data->nonjl ?></p>
			</td>

			<td style="width: 53%;">
				<p class="_hed2"><?php echo $this->data->cabang->manager.', '.$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="2" align="center"><b>SURAT JALAN</b></td>
		</tr>

		<tr>
			<td colspan="2">
				<table class="_detTab" cellspacing="0" cellpadding="0" style="width:90%;">
					<thead>
						<tr>
							<th style="width: 4%;">No</th>
							<th style="width: 12%;">Kode</th>
							<th style="width: 70%;">Nama Barang</th>
							<th style="width: 12%;" align="right" class="_right">Qty</th>
						</tr>
					</thead>

					<tbody>
					<?php
					foreach ($detPage as $row) {
					?>
						<tr>
							<td><?php echo $no++ ?></td>
							<td><?php echo $row->kd_inv ?></td>
							<td><?php echo substr($row->nm_inv, 0, 50) ?></td>
							<td align="right" class="_right"><?php echo number_format($row->qty,2).' '.$row->satuan ?></td>
						</tr>
					<?php } ?>
                    
                    <?php if ($pageIndex == count($pages)) { ?>
					<tr>
						<td colspan="4" class="_bottom" style="border-left:none;border-bottom:none;">
							<div style="width:100%;margin-top: 20px">
								<table style="width:100%;">
								    <tr>
								       <td class="_none" style="width:50%;" colspan="2" align="center">Penerima</td>
								       <td class="_none" style="width:50%;" align="center">Dibuat oleh</td>
								    </tr>
								    <tr><td class="_none">&nbsp;</td><td class="_none">&nbsp;</td><td class="_none">&nbsp;</td></tr>
								    <tr>
								       <td class="_none" align="center">(</td>
								       <td class="_none" align="center">)</td>
								       <td class="_none" align="center">( <?php echo $this->data->data->chusr ?> )</td>
								    </tr>
								</table>
							</div>
						</td>
					</tr>
					<?php }else{ ?>
					<tr>
						<td colspan="4" class="_bottom" style="border-left:none;border-bottom:none;">
							&nbsp;
						</td>
					</tr>  
					<?php } ?>

					</tbody>
				</table>
			</td>
		</tr>
	</table>

</div>

<?php if ($pageIndex < count($pages)) { ?>
	<div class="page-break"></div>
<?php } ?>

<?php } // end foreach pages ?>

