<hr class="thick-line" style="clear:both;">
<div id="left">
	<?php
	$this->nativesession->set_flash_session('url_requested', base_url(uri_string()));
	echo form_open(base_url().'jurnal_induk_list/search');
	$attributes = array('name' => 'search', 'id' => 'search-box', 'type' => 'text','size' => '50','placeholder'=>"  Ketik kata kunci  ");
	echo form_input($attributes);
	$data = array(
		'enc' => $enc
	);
	echo form_hidden($data);
	echo "<span>  </span>";
	$attributes = array('value' => 'Search', 'id' => 'search-btn1', 'type' => 'submit');
	echo form_submit($attributes);
	echo form_close('');
	?>
</div>
<div id="left" style="margin-left:50px;">
	<input type="submit" value="Excel" onclick="tableToExcel('tablePerkaraAll', 'name', 'BUKU INDUK KEUANGAN PERKARA.xls')" class="btn"></input>
</div>

<div id="pages">
    <div id="selector"></div>
</div>
<div class="cssTable">
	<table id="tablePerkaraAll">
		<col  width="7%" />
        <col  width="12%" />
        <col  width="17%" />
        <col  width="20%" />
        <col  width="15%" />
        <col  width="20%" />
        <col  width="20%" />
        <col  width="12%" />
        <col  width="12%" />
        <col  width="14%" />
		<tbody>
			<tr>
				<td>No</td>
				<td onclick="sorting()">Tanggal Transaksi</td>
				<td onclick="sorting()">Nomor Perkara</td>
				<td onclick="sorting()">Tahapan Proses</td>
				<td onclick="sorting()">Kategori Biaya</td>
				<td onclick="sorting()">Jenis Biaya</td>
				<td onclick="sorting()">Uraian</td>
				<td>Penerimaan</td>
				<td>Pengeluaran</td>
				<td>Keterangan</td>
			</tr>

			<?php
			$terima=0;
			$keluar=0;
			$t_terima=0;
			$t_keluar=0;
			$tgl_sebelumnya='';$i=1;
			$oldTgl = '';
			$printdaridb = FALSE;
			if($page_number==1){
				$prevpage = 1;
			}else{
				$prevpage = $this->nativesession->get_flash_session('previousPage', $page_number);
			}
			if(($page_number-$prevpage)==1){
				#$tgl_sebelumnya = $this->nativesession->get_flash_session('previousPage');
				$t_terima+=intval($this->nativesession->get_flash_session('prevTerima'));
				$t_keluar+=intval($this->nativesession->get_flash_session('prevKeluar'));
			}elseif($page_number!=1){
				$printdaridb = TRUE;
				
			}
			
			$this->nativesession->set_flash_session('previousPage', $page_number);
				$x=1;
				if($list_jurnal_biaya!=''){
					if($list_jurnal_biaya->num_rows>0){
						if($page_active<1){	$con = 1;}else{$con = $page_active;}
						$repeat=false;
						$stop=false;
		    			foreach ($list_jurnal_biaya->result() as $row) {
		    				if($x<=50){
				    			if($tgl_sebelumnya=='' || $tgl_sebelumnya==$row->tanggal_transaksi){
				    				$t_terima+=intval($row->penerimaan);
				    				$t_keluar+=intval($row->pengeluaran);

			    				echo "<tr>";
				    				echo '<td valign=\"middle\">'.$con.'</td>';
				    				echo '<td valign=\"middle\">'.$this->tanggalhelper->convertToInputDate($row->tanggal_transaksi).'</td>';
				    				echo '<td valign=\"middle\">'.$row->nomor_perkara.'</td>';
				    				echo '<td valign=\"middle\">'.$row->tahapan_proses.'</td>';
				    				echo '<td valign=\"middle\">'.$row->kategori_nama.'</td>';
				    				echo '<td valign=\"middle\">'.$row->jenis_biaya_nama.'</td>';
				    				echo '<td valign=\"middle\">'.$row->uraian.'</td>';
				    				echo '<td valign=\"middle\" align="right">'.number_format(intval($row->penerimaan), 0, ',', '.').'</td>';
				    				echo '<td valign=\"middle\" align="right">'.number_format(intval($row->pengeluaran), 0, ',', '.').'</td>';
				    				echo '<td>'.$row->keterangan.'</td>';
			    				echo "</tr>";
				    			}else{
				    				if($printdaridb==TRUE){
					    				$t_terima=intval($totalTerima);
					    				$t_keluar=intval($totalKeluar);
					    			}
									echo "<tr>";
			                            echo "<th bgcolor=\"#008C4B\" colspan=\"7\" style=\"text-align: center;\"><font color=\"#fff\">Sub Total</td>";
			                            echo "<th align=\"right\" bgcolor=\"#008C4B\" style=\"text-align: right;\" ><font color=\"#fff\">Rp. ".number_format($t_terima, 0, ',', '.')."</td>";
			                            echo "<th class=\"info\" bgcolor=\"#008C4B\" style=\"text-align: right;\"><font color=\"#fff\">Rp. ".number_format($t_keluar, 0, ',', '.')."</td>";
			                            echo "<th class=\"info\" bgcolor=\"#008C4B\" style=\"text-align: right;\"></td>";
			                        echo "</tr>";
									echo "<tr>";
			                            echo "<th bgcolor=\"#CCCfff\" colspan=\"10\" style=\"text-align: left;\"><font color=\"#000\">Tanggal Transaksi => ".$this->tanggalhelper->convertToInputDate($row->tanggal_transaksi)."</td>";
			                        echo "</tr>";

		                        $t_terima=0;
		                        $t_keluar=0;
		                        $t_terima+=intval($row->penerimaan);
				    			$t_keluar+=intval($row->pengeluaran);

			    				echo "<tr>";
				    				echo '<td valign=\"middle\">'.$con.'</td>';
				    				echo '<td valign=\"middle\">'.$this->tanggalhelper->convertToInputDate($row->tanggal_transaksi).'</td>';
				    				echo '<td valign=\"middle\">'.$row->nomor_perkara.'</td>';
				    				echo '<td valign=\"middle\">'.$row->tahapan_proses.'</td>';
				    				echo '<td valign=\"middle\">'.$row->kategori_nama.'</td>';
				    				echo '<td valign=\"middle\">'.$row->jenis_biaya_nama.'</td>';
				    				echo '<td valign=\"middle\">'.$row->uraian.'</td>';
				    				echo '<td valign=\"middle\" align="right">'.number_format(intval($row->penerimaan), 0, ',', '.').'</td>';
				    				echo '<td valign=\"middle\" align="right">'.number_format(intval($row->pengeluaran), 0, ',', '.').'</td>';
				    				echo '<td>'.$row->keterangan.'</td>';
			    				echo "</tr>";

				    			}
				    			$lastRow['tanggal_transaksi'] ='';
				    			if($x==50){
				    				$lastRow = $list_jurnal_biaya->last_row('array');
				    			}

				    			if($i==($list_jurnal_biaya->num_rows-1) AND $row->tanggal_transaksi != $lastRow['tanggal_transaksi']){
					    			
					    			echo "<tr>";
			                            echo "<th bgcolor=\"#008C4B\" colspan=\"7\" style=\"text-align: center;\"><font color=\"#fff\">Sub Total</td>";
			                            echo "<th align=\"right\" bgcolor=\"#008C4B\" style=\"text-align: right;\" ><font color=\"#fff\">Rp. ".number_format($t_terima, 0, ',', '.')."</td>";
			                            echo "<th class=\"info\" bgcolor=\"#008C4B\" style=\"text-align: right;\"><font color=\"#fff\">Rp. ".number_format($t_keluar, 0, ',', '.')."</td>";
			                            echo "<th class=\"info\" bgcolor=\"#008C4B\" style=\"text-align: right;\"></td>";
			                        echo "</tr>";
				    			}else{
				    				$this->nativesession->set_flash_session('prevTgl', $row->tanggal_transaksi);
				    				$this->nativesession->set_flash_session('prevTerima', $t_terima);
				    				$this->nativesession->set_flash_session('prevKeluar', $t_keluar);
				    			}
				    			
				    			$tgl_sebelumnya=$row->tanggal_transaksi;
				    			$i++;
				    			$x++;
			    				$con++;
			    				$oldTgl = $row->tanggal_transaksi;
			    			}
		    		}
			    	}else{
		    			echo "<tr><td colspan='10' align='center'>Data Tidak diTemukan</td></tr>";
		    		}
				}else{
		    		echo "<tr><td colspan='10' align='center'>Data Tidak diTemukan</td></tr>";
		    	}
			?>
		</tbody>
	</table>
</div>
<a id="dlink" href="#" style="display:none;"></a>
<div id="pages_bottom" style="width:100%;padding-left:5px;padding-top:5px;">
    <div id="selector_bottom"></div>
</div>
<?php
$url = base_url().$page_url.'/sort/';
?>
<script type="text/javascript">
	function sorting(){
		message_error_show_parent('Sorting Transaksi Harian di Buku induk diasble');
	}
	<?php $enc = (!empty($enc)) ? "/".$enc : $enc;?>
	function searchDetilShow(){
		window.open('<?php echo base_url();?>search<?php echo $enc; ?>','_self')
	}

	var tableToExcel = (function () {
        var uri = 'data:application/vnd.ms-excel;base64,'
        , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
        , base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
        , format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }
        return function (table, name, filename) {
            if (!table.nodeType) table = document.getElementById(table)
            var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }

            document.getElementById("dlink").href = uri + base64(format(template, ctx));
            document.getElementById("dlink").download = filename;
            document.getElementById("dlink").click();
            closeLoading();
        }
    })()
</script>
