<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta name="robots" content="noindex, nofollow">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="Enambelasapp.my.id" />
    <meta name="author" content="Suroto" />
    <link rel="icon" type="image/png" href="<?php echo base_url('assets/') ?>/img/favicon.png"/>
    <!--[if IE]>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <![endif]-->
    <title>Laporan Pengeluaran Rekap</title>
    <link href="<?php echo base_url() ?>/assets/css/bootstrap.css" rel="stylesheet" />
    <link href="<?php echo base_url() ?>/assets/css/font-awesome.css" rel="stylesheet" />
    <link href="<?php echo base_url() ?>/assets/css/style.css" rel="stylesheet" />
<?php 
$namafile= 'rinci'.bulan($bln) . $thn . ".xls";
header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=$namafile");
?>
</head>
<body>
<div class="container">
    <div align="right" class="no-print" id="formFilter" style="background-color: #F5F5F5;padding: 4px">
    <a href=""><button type="button" class="btn btn-success" onclick="window.print();return false;">Print</button></a>
    </div>
    <h4 align="center">LAPORAN PENGELUARAN REKAP</h4>
    <h5 align="center">BULAN :  <?php echo bulan($bln) . " " . $thn; ?></h5>

<table id="tbBiaya" class="table table-bordered table-responsive">
<thead>
     <tr>
        <th style="width:50px;">No</th>
        <th>Tanggal</th>
		<th>Kedai</th>
        <th>Penjualan</th>
        <th>Pb1</th>
		<th>Lain Lain</th>
        <th>PENDAPATAN</th>
		<th>B.CV</th>
        <th>B.Dapur</th>
		<th>B.Kedai</th>
		<th>B.Sentul</th>
		<th>BIAYA</th>
		<th>Transfer</th>
		<th>Gopay</th>
		<th>Grab</th>
		<th>Shopeepay</th>
		<th>Shopeefood</th>
		<th>BANK</th>
		<th>PENGELUARAN</th>
		<th>Saldo</th>
    </tr>
</thead>
<tbody>
    <?php foreach ($biaya->result() as $key): ?>
<?php
$query_jual = $this->db3->query("SELECT SUM(a.nilai) AS tk FROM kasumumdetail a
						left join kasumumheader b on a.nobukti=b.nobukti
						WHERE b.tgl='$key->tgl' AND a.rekno like '4%' and b.reff='$key->reff';");
$query_pb1 = $this->db3->query("SELECT SUM(a.nilai) AS tk FROM kasumumdetail a
						left join kasumumheader b on a.nobukti=b.nobukti
						WHERE b.tgl='$key->tgl' AND (a.rekno='830100' or a.rekno like '82%' or a.rekno like '89%') and b.reff='$key->reff';");
$query_ll = $this->db3->query("SELECT SUM(a.nilai) AS tk FROM kasumumdetail a
						left join kasumumheader b on a.nobukti=b.nobukti
						WHERE a.dk='K' and b.tgl='$key->tgl' AND (a.rekno >= '130300' and  a.rekno <= '130999') and b.reff='$key->reff';");

						
$query_do = $this->db3->query("SELECT SUM(a.nilai) AS tk FROM kasumumdetail a
						left join kasumumheader b on a.nobukti=b.nobukti
						WHERE b.tgl='$key->tgl' AND a.rekno like '632100' and a.cc='2005' and b.reff='$key->reff';");
$query_gopay = $this->db3->query("SELECT SUM(a.nilai) AS tk FROM kasumumdetail a
						left join kasumumheader b on a.nobukti=b.nobukti
						WHERE b.tgl='$key->tgl' AND a.rekno like '42%' and b.reff='$key->reff';");						
$query_grab = $this->db3->query("SELECT SUM(a.nilai) AS tk FROM kasumumdetail a
						left join kasumumheader b on a.nobukti=b.nobukti
						WHERE b.tgl='$key->tgl' AND a.rekno like '43%' and b.reff='$key->reff';");												
$query_shopee = $this->db3->query("SELECT SUM(a.nilai) AS tk FROM kasumumdetail a
						left join kasumumheader b on a.nobukti=b.nobukti
						WHERE b.tgl='$key->tgl' AND a.rekno like '44%' and b.reff='$key->reff';");	
$query_spay = $this->db3->query("SELECT SUM(a.nilai) AS tk FROM kasumumdetail a
						left join kasumumheader b on a.nobukti=b.nobukti
						WHERE b.tgl='$key->tgl' AND a.rekno like '41%' and a.cc='2004' and b.reff='$key->reff';");	
$query_biayacv = $this->db3->query("SELECT SUM(if(a.dk='D',a.nilai,-a.nilai)) AS tk FROM kasumumdetail a
						left join kasumumheader b on a.nobukti=b.nobukti
						WHERE b.tgl='$key->tgl' AND (a.rekno like '61%' or a.rekno like '16%') and b.reff='$key->reff';");	
$query_biayadpr = $this->db3->query("SELECT SUM(if(a.dk='D',a.nilai,-a.nilai)) AS tk FROM kasumumdetail a
						left join kasumumheader b on a.nobukti=b.nobukti
						WHERE a.dk='D' and b.tgl='$key->tgl' AND (a.rekno like '62%' or a.rekno like '15%' or a.rekno like '21%' or a.rekno like '13%'  )  and b.reff='$key->reff';");							
$query_biayakedai = $this->db3->query("SELECT SUM(a.nilai) AS tk FROM kasumumdetail a
						left join kasumumheader b on a.nobukti=b.nobukti
						WHERE b.tgl='$key->tgl' AND a.rekno like '63%' and b.reff='$key->reff';");													
$query_biayastl = $this->db3->query("SELECT SUM(a.nilai) AS tk FROM kasumumdetail a
						left join kasumumheader b on a.nobukti=b.nobukti
						WHERE b.tgl='$key->tgl' AND a.rekno like '64%' and b.reff='$key->reff';");													
$query_transfer = $this->db3->query("SELECT SUM(a.nilai) AS tk FROM kasumumdetail a
						left join kasumumheader b on a.nobukti=b.nobukti
						WHERE b.tgl='$key->tgl' AND a.rekno like '120300' and a.dk='D' and b.reff='$key->reff';");																			
						
$a = $query_jual->row_array();
$b = $query_pb1->row_array();
$m = $query_ll->row_array();
$c = $query_do->row_array();
$d = $query_gopay->row_array();
$e = $query_grab->row_array();
$f = $query_shopee->row_array();
$g = $query_spay->row_array();
$h = $query_biayacv->row_array();
$i = $query_biayadpr->row_array();
$j = $query_biayakedai->row_array();
$k = $query_biayastl->row_array();
$l = $query_transfer->row_array();

$totp=$a['tk']+$b['tk']+$m['tk'];
$tot1=$d['tk']+$e['tk']+$f['tk']+$g['tk']+$l['tk'];
$tot2=$h['tk']+$i['tk']+$j['tk']+$k['tk'];
$totl=$h['tk']+$i['tk']+$j['tk']+$k['tk']+$d['tk']+$e['tk']+$f['tk']+$g['tk']+$l['tk'];
$tot = $a['tk']+$b['tk']+$m['tk']-$d['tk']-$e['tk']-$f['tk']-$g['tk']-$h['tk']-$i['tk']-$j['tk']-$k['tk']-$l['tk'];
?>
    <tr>
        <td style="text-align:center;"><?php echo $no++ ?></td>
        <td><?php echo date_indo($key->tgl) ?></td>
		<td><?php echo $key->nmcolector ?></td>
        <td style="text-align:right;"><?php echo number_format($a['tk'], 0, '.', ',') ?></td>
		<td style="text-align:right;"><?php echo number_format($b['tk'], 0, '.', ',') ?></td>
		<td style="text-align:right;"><?php echo number_format($m['tk'], 0, '.', ',') ?></td>
        <td style="text-align:right;text-primary;"><b><?php echo number_format($totp, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><?php echo number_format($h['tk'], 0, '.', ',') ?></td>
		<td style="text-align:right;"><?php echo number_format($i['tk'], 0, '.', ',') ?></td>
		<td style="text-align:right;"><?php echo number_format($j['tk'], 0, '.', ',') ?></td>
		<td style="text-align:right;"><?php echo number_format($k['tk'], 0, '.', ',') ?></td>
		<td style="text-align:right;text-primary;"><b><?php echo number_format($tot2, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><?php echo number_format($l['tk'], 0, '.', ',') ?></td>
		<td style="text-align:right;"><?php echo number_format($d['tk'], 0, '.', ',') ?></td>
		<td style="text-align:right;"><?php echo number_format($e['tk'], 0, '.', ',') ?></td>
		<td style="text-align:right;"><?php echo number_format($f['tk'], 0, '.', ',') ?></td>
		<td style="text-align:right;"><?php echo number_format($g['tk'], 0, '.', ',') ?></td>
		<td style="text-align:right;text-primary;"><b><?php echo number_format($tot1, 0, '.', ',') ?></b></td>
        <td style="text-align:right;text-danger;"><b><?php echo number_format($totl, 0, '.', ',') ?></b></td>
		<td style="text-align:right;text-success;"><b><?php echo number_format($tot, 0, '.', ',') ?></b></td>
    </tr>
    <?php
$tot_a += $a['tk'];
$tot_b += $b['tk'];
$tot_m += $m['tk'];
$tot_c += $c['tk'];
$tot_d += $d['tk'];
$tot_e += $e['tk'];
$tot_f += $f['tk'];
$tot_g += $g['tk'];
$tot_h += $h['tk'];
$tot_i += $i['tk'];
$tot_j += $j['tk'];
$tot_k += $k['tk'];
$tot_l += $l['tk'];
$tot_totp += $totp;
$tot_tot1 += $tot1;
$tot_tot2 += $tot2;
$tot_totl += $totl;
$tot_tot += $tot;
?>
    <?php endforeach?>
</tbody>
<tfoot>
    <tr>
        <td colspan="3" style="text-align:center;"><b>Total</b></td>
        <td style="text-align:right;"><b><?php echo number_format($tot_a, 0, '.', ',') ?></b></td>
        <td style="text-align:right;"><b><?php echo number_format($tot_b, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><b><?php echo number_format($tot_m, 0, '.', ',') ?></b></td>
        <td style="text-align:right;"><b><?php echo number_format($tot_totp, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><b><?php echo number_format($tot_h, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><b><?php echo number_format($tot_i, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><b><?php echo number_format($tot_j, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><b><?php echo number_format($tot_k, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><b><?php echo number_format($tot_tot2, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><b><?php echo number_format($tot_l, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><b><?php echo number_format($tot_d, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><b><?php echo number_format($tot_e, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><b><?php echo number_format($tot_f, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><b><?php echo number_format($tot_g, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><b><?php echo number_format($tot_tot1, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><b><?php echo number_format($tot_totl, 0, '.', ',') ?></b></td>
		<td style="text-align:right;"><b><?php echo number_format($tot_tot, 0, '.', ',') ?></b></td>
</tfoot>
</table>
</div>
</body>
</html>