<div class="main-content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12 mb-2">
                <div class="card">
                    <div class="card-header"><h3><i class="ik ik-pie-chart"></i> Monitoring Belanja Pemerintah Per KPP</h3></div>
                    <div class="card-body">
                        <form class="forms-sample" method="get" action="<?php echo base_url('bendahara/beranda/kanwil') ?>">
                            <div class="row">
                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label for="cari_tahun">Tahun</label>
                                        <select class="form-control" id="cari_tahun" name="cari_tahun">
                                            <?php
                                                foreach ($ref_tahun as $row) {
                                                    if ($row->TAHUN == $cari_tahun) {
                                                        $isSelected = 'selected="selected"';
                                                    } 
                                                    else {
                                                        $isSelected = '';
                                                    }
                                                    echo "<option value='".$row->TAHUN."' ".$isSelected.">".$row->TAHUN."</option>";
                                                }
                                            ?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label for="cari_bulan_awal">Bulan</label>
                                        <select class="form-control" id="cari_bulan_awal" name="cari_bulan_awal">
                                            <?php
                                                foreach ($ref_bulan as $row) {
                                                    if ($row->KODE == $cari_bulan_awal) {
                                                        $isSelected = 'selected="selected"';
                                                    } 
                                                    else {
                                                        $isSelected = '';
                                                    }
                                                    echo "<option value='".$row->KODE."' ".$isSelected.">".ucfirst(strtolower($row->NM_PANJANG))."</option>";
                                                }
                                            ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-1 text-center" style="margin: 35px -25px 0px -25px;">
                                    s/d
                                </div>
                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label for="cari_bulan_akhir">&nbsp;</label>
                                        <select class="form-control" id="cari_bulan_akhir"  name="cari_bulan_akhir">
                                            <?php
                                                foreach ($ref_bulan as $row) {
                                                    if ($row->KODE == $cari_bulan_akhir) {
                                                        $isSelected = 'selected="selected"';
                                                    } 
                                                    else {
                                                        $isSelected = '';
                                                    }
                                                    echo "<option value='".$row->KODE."' ".$isSelected.">".ucfirst(strtolower($row->NM_PANJANG))."</option>";
                                                }
                                            ?>
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <?php
                                $cari_kanwil_disabled = 'false';
                            
                                if (session('tpkantor') == 'Kanwil') {
                                    $cari_kanwil_disabled = 'true';
                                }
                            ?>

                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="cari_kanwil">Kanwil</label>
                                        <select class="form-control" id="cari_kanwil" name="cari_kanwil" data-disabled="<?php echo $cari_kanwil_disabled ?>">
                                            <option value=''>Semua</option>
                                            <?php
                                                foreach ($ref_kanwil as $row) {
                                                    if ($row->KODE == $cari_kanwil) {
                                                        $isSelected = 'selected="selected"';
                                                    } 
                                                    else {
                                                        $isSelected = '';
                                                    }
                                                    echo "<option value='".$row->KODE ."' ".$isSelected.">".$row->NAMA."</option>";
                                                }
                                            ?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label for="cari_tahun">Sumber Dana</label>
                                        <select class="form-control" id="cari_sumber_dana" name="cari_sumber_dana">
                                            <option value="">Semua</option>
                                            <option value="APBN" <?php echo $cari_sumber_dana == "APBN" ? "selected='selected'" : "" ?>>APBN</option>
                                            <option value="APBD" <?php echo $cari_sumber_dana == "APBD" ? "selected='selected'" : "" ?>>APBD</option>
                                            <option value="APBDes" <?php echo $cari_sumber_dana == "APBDes" ? "selected='selected'" : "" ?>>APBDes</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <button type="submit" class="btn btn-primary mr-2">Proses</button>
                        </form>
                    </div>
                </div>

                <div class="card">
                    <ul class="nav nav-pills custom-pills justify-content-center" id="pills-tab" role="tablist">
                        <li class="nav-item">
                            <a class="nav-link active" id="pills-timeline-tab" data-toggle="pill" href="#penyerapan_pagu" role="tab" aria-controls="pills-timeline" aria-selected="true">Penyerapan Pagu</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" id="pills-profile-tab" data-toggle="pill" href="#realisasi_pajak" role="tab" aria-controls="pills-profile" aria-selected="false">Realisasi Pajak</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" id="pills-setting-tab" data-toggle="pill" href="#grafik_timeline" role="tab" aria-controls="pills-setting" aria-selected="false">Grafik Timeline</a>
                        </li>
                    </ul>
                </div>
                
                <?php
                    if($cari_sumber_dana == "APBN") {
                        $summary_pagu_total = $data_beranda_total->APBN_PAGU_TOTAL;
                        $summary_realisasi_total = $data_beranda_total->APBN_REAL_TOTAL;
                        $summary_estimasi_total = $data_beranda_total->APBN_ESTI_TOTAL_PAGU;
                        $summary_bayar_total = $data_beranda_total->APBN_BAYAR_TOTAL;
                        $summary_taxgap_pagu = $data_beranda_total->APBN_TAXGAP_PAGU;
                        $summary_taxgap_realisasi = $data_beranda_total->APBN_TAXGAP_REAL;
                        $summary_tax_collection = $data_beranda_total->APBN_TAX_COLLECTION;
                    }
                    else if($cari_sumber_dana == "APBD") {
                        $summary_pagu_total = $data_beranda_total->APBD_PAGU_TOTAL;
                        $summary_realisasi_total = $data_beranda_total->APBD_REAL_TOTAL;
                        $summary_estimasi_total = $data_beranda_total->APBD_ESTI_TOTAL_PAGU;
                        $summary_bayar_total = $data_beranda_total->APBD_BAYAR_TOTAL;
                        $summary_taxgap_pagu = $data_beranda_total->APBD_TAXGAP_PAGU;
                        $summary_taxgap_realisasi = $data_beranda_total->APBD_TAXGAP_REAL;
                        $summary_tax_collection = $data_beranda_total->APBD_TAX_COLLECTION;
                    }
                    else if($cari_sumber_dana == "APBDes") {
                        $summary_pagu_total = $data_beranda_total->APBDES_PAGU_TOTAL;
                        $summary_realisasi_total = $data_beranda_total->APBDES_REAL_TOTAL;
                        $summary_estimasi_total = $data_beranda_total->APBDES_ESTI_TOTAL_PAGU;
                        $summary_bayar_total = $data_beranda_total->APBDES_BAYAR_TOTAL;
                        $summary_taxgap_pagu = $data_beranda_total->APBDES_TAXGAP_PAGU;
                        $summary_taxgap_realisasi = $data_beranda_total->APBDES_TAXGAP_REAL;
                        $summary_tax_collection = $data_beranda_total->APBDES_TAX_COLLECTION;
                    }
                    else {
                        $summary_pagu_total = $data_beranda_total->ALL_PAGU_TOTAL;
                        $summary_realisasi_total = $data_beranda_total->ALL_REAL_TOTAL;
                        $summary_estimasi_total = $data_beranda_total->ALL_ESTI_TOTAL_PAGU;
                        $summary_bayar_total = $data_beranda_total->ALL_BAYAR_TOTAL;
                        $summary_taxgap_pagu = $data_beranda_total->ALL_TAXGAP_PAGU;
                        $summary_taxgap_realisasi = $data_beranda_total->ALL_TAXGAP_REAL;
                        $summary_tax_collection = $data_beranda_total->ALL_TAX_COLLECTION;
                    }
                ?>
                
                <div class="tab-content" id="pills-tabContent">
                    <div class="tab-pane fade show active" id="penyerapan_pagu" role="tabpanel" aria-labelledby="pills-timeline-tab">
                        <div class="row clearfix">
                            <div class="col-lg-6 col-md-6 col-sm-12">
                                <div class="widget">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Total Pagu</h6>
                                                <h2><?php echo number_format($summary_pagu_total, 0, ",", ".") ?></h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-share-2"></i>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="progress progress-sm">
                                        <div class="progress-bar bg-warning" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%;"></div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-6 col-md-6 col-sm-12">
                                <div class="widget">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Realisasi Pagu</h6>
                                                <h2><?php echo number_format($summary_realisasi_total, 0, ",", ".") ?></h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-trending-up"></i>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="progress progress-sm">
                                        <div class="progress-bar bg-success" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%;"></div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-6 col-md-6 col-sm-12">
                                <div class="widget">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Sisa Pagu</h6>
                                                <h2><?php echo number_format($summary_pagu_total-$summary_realisasi_total, 0, ",", ".") ?></h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-alert-triangle"></i>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="progress progress-sm">
                                        <div class="progress-bar bg-info" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%;"></div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-6 col-md-6 col-sm-12" id="scroll_back">
                                <div class="widget">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Penyerapan Pagu</h6>
                                                <h2><?php echo $summary_pagu_total > 0 ? number_format(($summary_realisasi_total/$summary_pagu_total)*100, 2, ",", ".") : "0,00" ?>%</h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-percent"></i>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="progress progress-sm">
                                        <div class="progress-bar bg-danger" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%;"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="realisasi_pajak" role="tabpanel" aria-labelledby="pills-profile-tab">
                        <div class="row clearfix">
                            <div class="col-lg-6 col-md-6 col-sm-12">
                                <div class="widget">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Estimasi Pajak (Total Pagu)</h6>
                                                <h2><?php echo number_format($summary_estimasi_total, 0, ",", ".") ?></h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-crosshair"></i>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="progress progress-sm">
                                        <div class="progress-bar bg-success" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%;"></div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-6 col-md-6 col-sm-12">
                                <div class="widget">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Realisasi Pajak</h6>
                                                <h2><?php echo number_format($summary_bayar_total, 0, ",", ".") ?></h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-trending-up"></i>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="progress progress-sm">
                                        <div class="progress-bar bg-warning" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%;"></div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-6 col-md-6 col-sm-12">
                                <div class="widget">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Tax Gap (Total Pagu)</h6>
                                                <h2><?php echo number_format($summary_estimasi_total-$summary_bayar_total, 0, ",", ".") ?></h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-alert-triangle"></i>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="progress progress-sm">
                                        <div class="progress-bar bg-danger" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%;"></div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-6 col-md-6 col-sm-12">
                                <div class="widget">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Tax Collection</h6>
                                                <h2><?php echo number_format((float) str_replace(",", ".", $summary_tax_collection), 2, ",", ".") ?>%</h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-percent"></i>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="progress progress-sm">
                                        <div class="progress-bar bg-info" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%;"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="grafik_timeline" role="tabpanel" aria-labelledby="pills-setting-tab">
                        <div class="card">
                            <div class="card-body">
                                <div id="grafik_area"></div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="card" style="display: table;">
                    <div class="card-body">

                        <?php
                            $page_curr = $cari_page;
                            $page_count = ceil($data_beranda_total->KUANTITAS / $cari_limit);

                            if($page_count >= 5) {
                                $page_bottom = $page_curr - 2;
                                $page_option = 5;
                                
                                if($page_bottom <= 0) $page_bottom = 1;
                                if($page_bottom + $page_option - 1 > $page_count) $page_bottom = $page_count - $page_option + 1;
                            }
                            else {
                                $page_option = $page_count;
                                $page_bottom = 1;
                            }
                            
                            $page_arr = [];
                            for($i = $page_bottom; $i <= $page_bottom + $page_option - 1; $i++) {
                                $page_arr[] = $i;
                            }
                        ?>

                        <style>
                            .page-link {
                                padding-right: 10px !important;
                                padding-left: 10px !important;
                            }

                            #cari_limit {
                                width: 175px;
                                margin-right: 30px;
                            }
                        </style>

                        <div class="row mb-3">
                            <div class="col-lg-12">
                                <table>
                                    <tr>
                                        <td>
                                            <select class="form-control" name="cari_limit" id="cari_limit">
                                                <option value="25">25 Per Halaman</option>
                                                <option value="50">50 Per Halaman</option>
                                                <option value="100">100 Per Halaman</option>
                                                <option value="200">200 Per Halaman</option>
                                            </select>
                                        </td>
                                        <td>
                                            <ul class="pagination mb-0">
                                                <li class="page-item">
                                                    <a class="page-link first" href="<?php echo remove_url_param(current_url()."?".$_SERVER['QUERY_STRING'], "cari_page")."&cari_page=1#scroll_back"; ?>" data-toggle="tooltip" data-placement="top" title="Halaman Awal">
                                                        <i class="ik ik-chevrons-left"></i>
                                                    </a>
                                                </li>

                                                <?php if($page_curr > 1) { ?>
                                                    <li class="page-item">
                                                        <a class="page-link prev" href="<?php echo remove_url_param(current_url()."?".$_SERVER['QUERY_STRING'], "cari_page")."&cari_page=".($page_curr - 1)."#scroll_back"; ?>" data-toggle="tooltip" data-placement="top" title="Halaman Sebelumnya">
                                                            <i class="ik ik-chevron-left"></i>
                                                        </a>
                                                    </li>
                                                <?php } ?>

                                                <?php 
                                                    if(count($page_arr) > 0) { 
                                                        if($page_arr[0] > 1) { 
                                                            ?>
                                                                <li class="page-item">
                                                                    <a class="page-link">...</a>
                                                                </li>
                                                            <?php 
                                                        }
                                                     } 
                                                ?>

                                                <?php
                                                    foreach($page_arr as $val) {
                                                        if($page_curr == $val) $page_active = " active";
                                                        else $page_active = "";
                                                        ?>
                                                            <li class="page-item<?php echo $page_active ?>">
                                                                <a class="page-link" href="<?php echo remove_url_param(current_url()."?".$_SERVER['QUERY_STRING'], "cari_page")."&cari_page=".$val."#scroll_back"; ?>"><?php echo number_format($val, 0, ",", ".") ?></a>
                                                            </li>
                                                        <?php
                                                    }
                                                ?>
                                                
                                                <?php 
                                                    if(count($page_arr) > 0) {
                                                        if($page_arr[count($page_arr) - 1] < $page_count) { 
                                                            ?>
                                                                <li class="page-item">
                                                                    <a class="page-link">...</a>
                                                                </li>
                                                            <?php 
                                                        }
                                                     } 
                                                ?>

                                                <?php if($page_curr < $page_count) { ?>
                                                    <li class="page-item">
                                                        <a class="page-link next" href="<?php echo remove_url_param(current_url()."?".$_SERVER['QUERY_STRING'], "cari_page")."&cari_page=".($page_curr + 1)."#scroll_back"; ?>" aria-label="Next" data-toggle="tooltip" data-placement="top" title="Halaman Selanjutnya">
                                                            <i class="ik ik-chevron-right"></i>
                                                        </a>
                                                    </li>
                                                <?php } ?>

                                                <li class="page-item">
                                                    <a class="page-link last" href="<?php echo remove_url_param(current_url()."?".$_SERVER['QUERY_STRING'], "cari_page")."&cari_page=".$page_count."#scroll_back"; ?>" data-toggle="tooltip" data-placement="top" title="Halaman Akhir">
                                                        <i class="ik ik-chevrons-right"></i>
                                                    </a>
                                                </li>
                                            </ul>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>

                        <style>
                            .table {
                                margin-bottom: 0px;
                            }
                            a {
                                color: #007bff;
                            }
                            .table thead th {
                                text-align: center;
                                vertical-align: middle;
                            }
                            .table thead th.thead_sub {
                                font-size: 11px;
                            }
                        </style>

                        <table class="table table-sm table-striped table-bordered" id="table_area">
                            <thead class="thead-dark">
                                <tr role="row">
                                    <th rowspan="2" colspan="1">No</th>
                                    <th rowspan="2" colspan="1">Kanwil</th>
                                    <th rowspan="2" colspan="1">KPP</th>

                                    <?php if($cari_sumber_dana == "" || $cari_sumber_dana == "APBN") { ?>
                                        <th colspan="8" rowspan="1">APBN</th>
                                    <?php } ?>

                                    <?php if($cari_sumber_dana == "" || $cari_sumber_dana == "APBD") { ?>
                                        <th colspan="8" rowspan="1">APBD</th>
                                    <?php } ?>

                                    <?php if($cari_sumber_dana == "" || $cari_sumber_dana == "APBDes") { ?>
                                        <th colspan="8" rowspan="1">APBDes</th>
                                    <?php } ?>
                                    
                                    <?php if($cari_sumber_dana == "") { ?>
                                        <th colspan="8" rowspan="1">Total</th>
                                    <?php } ?>

                                </tr>
                                <tr role="row">

                                    <?php if($cari_sumber_dana == "" || $cari_sumber_dana == "APBN") { ?>
                                        <th>Total Pagu</th>
                                        <th>Realisasi Pagu</th>
                                        <th>Estimasi Pajak (Total Pagu)</th>
                                        <th>Estimasi Pajak (Realisasi Pagu)</th>
                                        <th>Realisasi Pajak</th>
                                        <th>Tax Gap (Total Pagu)</th>
                                        <th>Tax Gap (Realisasi Pagu)</th>
                                        <th>Tax Collection</th>
                                    <?php } ?>
                                    
                                    <?php if($cari_sumber_dana == "" || $cari_sumber_dana == "APBD") { ?>
                                        <th>Total Pagu</th>
                                        <th>Realisasi Pagu</th>
                                        <th>Estimasi Pajak (Total Pagu)</th>
                                        <th>Estimasi Pajak (Realisasi Pagu)</th>
                                        <th>Realisasi Pajak</th>
                                        <th>Tax Gap (Total Pagu)</th>
                                        <th>Tax Gap (Realisasi Pagu)</th>
                                        <th>Tax Collection</th>
                                    <?php } ?>
                                    
                                    <?php if($cari_sumber_dana == "" || $cari_sumber_dana == "APBDes") { ?>
                                        <th>Total Pagu</th>
                                        <th>Realisasi Pagu</th>
                                        <th>Estimasi Pajak (Total Pagu)</th>
                                        <th>Estimasi Pajak (Realisasi Pagu)</th>
                                        <th>Realisasi Pajak</th>
                                        <th>Tax Gap (Total Pagu)</th>
                                        <th>Tax Gap (Realisasi Pagu)</th>
                                        <th>Tax Collection</th>
                                    <?php } ?>

                                    <?php if($cari_sumber_dana == "") { ?>
                                        <th>Total Pagu</th>
                                        <th>Realisasi Pagu</th>
                                        <th>Estimasi Pajak (Total Pagu)</th>
                                        <th>Estimasi Pajak (Realisasi Pagu)</th>
                                        <th>Realisasi Pajak</th>
                                        <th>Tax Gap (Total Pagu)</th>
                                        <th>Tax Gap (Realisasi Pagu)</th>
                                        <th>Tax Collection</th>
                                    <?php } ?>

                                </tr>
                                <tr>
                                    <th class="thead_sub">1</th>
                                    <th class="thead_sub">2</th>
                                    <th class="thead_sub">3</th>

                                    <?php if($cari_sumber_dana == "" || $cari_sumber_dana == "APBN") { ?>
                                        <th class="thead_sub">4</th>
                                        <th class="thead_sub">5</th>
                                        <th class="thead_sub">6</th>
                                        <th class="thead_sub">7</th>
                                        <th class="thead_sub">8</th>
                                        <th class="thead_sub">9</th>
                                        <th class="thead_sub">10</th>
                                        <th class="thead_sub">11</th>
                                    <?php } ?>

                                    <?php if($cari_sumber_dana == "" || $cari_sumber_dana == "APBD") { ?>
                                        <th class="thead_sub">12</th>
                                        <th class="thead_sub">13</th>
                                        <th class="thead_sub">14</th>
                                        <th class="thead_sub">15</th>
                                        <th class="thead_sub">16</th>
                                        <th class="thead_sub">17</th>
                                        <th class="thead_sub">18</th>
                                        <th class="thead_sub">19</th>
                                    <?php } ?>

                                    <?php if($cari_sumber_dana == "" || $cari_sumber_dana == "APBDes") { ?>
                                        <th class="thead_sub">20</th>
                                        <th class="thead_sub">21</th>
                                        <th class="thead_sub">22</th>
                                        <th class="thead_sub">23</th>
                                        <th class="thead_sub">24</th>
                                        <th class="thead_sub">25</th>
                                        <th class="thead_sub">26</th>
                                        <th class="thead_sub">27</th>
                                    <?php } ?>

                                    <?php if($cari_sumber_dana == "") { ?>
                                        <th class="thead_sub">28</th>
                                        <th class="thead_sub">29</th>
                                        <th class="thead_sub">30</th>
                                        <th class="thead_sub">31</th>
                                        <th class="thead_sub">32</th>
                                        <th class="thead_sub">33</th>
                                        <th class="thead_sub">34</th>
                                        <th class="thead_sub">35</th>
                                    <?php } ?>
                                    
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    $nomor = ($cari_page * $cari_limit) - $cari_limit;

                                    foreach ($data_beranda as $idx => $row) {
                                        $nomor = $nomor + 1;
                                        ?>
                                            <tr>
                                                <td class="text-center"><?php echo number_format($nomor, 0, ",", "."); ?></td>
                                                <td><?php echo $row->NM_KANWIL; ?></td>
                                                <td><a href="<?= base_url() ?>bendahara/beranda/kpp?cari_tahun=<?php echo $cari_tahun; ?>&cari_bulan_awal=<?php echo $cari_bulan_awal; ?>&cari_bulan_akhir=<?php echo $cari_bulan_akhir; ?>&cari_kanwil=<?php echo $row->KD_KANWIL; ?>&cari_kpp=<?php echo $row->KD_KPP; ?>" data-toggle="tooltip" data-placement="top" title="Lihat Kabupaten/Kota"><?php echo $row->NM_KPP; ?></a></td>

                                                <?php if($cari_sumber_dana == "" || $cari_sumber_dana == "APBN") { ?>
                                                    <td class="text-right"><a href="<?= base_url() ?>bendahara/apbn?cari_tahun=<?php echo $cari_tahun; ?>&cari_bulan_awal=<?php echo $cari_bulan_awal; ?>&cari_bulan_akhir=<?php echo $cari_bulan_akhir; ?>&cari_kanwil=<?php echo $row->KD_KANWIL; ?>&cari_kpp=<?php echo $row->KD_KPP; ?>" data-toggle="tooltip" data-placement="top" title="Lihat Rincian"><?php echo number_format($row->APBN_PAGU_TOTAL, 0, ",", ".") ?></a></td>
                                                    <td class="text-right"><?php echo number_format($row->APBN_REAL_TOTAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->APBN_ESTI_TOTAL_PAGU, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->APBN_ESTI_TOTAL_REAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->APBN_BAYAR_TOTAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->APBN_TAXGAP_PAGU, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->APBN_TAXGAP_REAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format((float) str_replace(",", ".", $row->APBN_TAX_COLLECTION), 2, ",", ".") ?>%</td>
                                                <?php } ?>

                                                <?php if($cari_sumber_dana == "" || $cari_sumber_dana == "APBD") { ?>
                                                    <td class="text-right"><a href="<?= base_url() ?>bendahara/apbd?cari_tahun=<?php echo $cari_tahun; ?>&cari_bulan_awal=<?php echo $cari_bulan_awal; ?>&cari_bulan_akhir=<?php echo $cari_bulan_akhir; ?>&cari_kanwil=<?php echo $row->KD_KANWIL; ?>&cari_kpp=<?php echo $row->KD_KPP; ?>" data-toggle="tooltip" data-placement="top" title="Lihat Rincian"><?php echo number_format($row->APBD_PAGU_TOTAL, 0, ",", ".") ?></a></td>
                                                    <td class="text-right"><?php echo number_format($row->APBD_REAL_TOTAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->APBD_ESTI_TOTAL_PAGU, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->APBD_ESTI_TOTAL_REAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->APBD_BAYAR_TOTAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->APBD_TAXGAP_PAGU, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->APBD_TAXGAP_REAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format((float) str_replace(",", ".", $row->APBD_TAX_COLLECTION), 2, ",", ".") ?>%</td>
                                                <?php } ?>

                                                <?php if($cari_sumber_dana == "" || $cari_sumber_dana == "APBDes") { ?>
                                                    <td class="text-right"><a href="<?= base_url() ?>bendahara/apbdes?cari_tahun=<?php echo $cari_tahun; ?>&cari_bulan_awal=<?php echo $cari_bulan_awal; ?>&cari_bulan_akhir=<?php echo $cari_bulan_akhir; ?>&cari_kanwil=<?php echo $row->KD_KANWIL; ?>&cari_kpp=<?php echo $row->KD_KPP; ?>" data-toggle="tooltip" data-placement="top" title="Lihat Rincian"><?php echo number_format($row->APBDES_PAGU_TOTAL, 0, ",", ".") ?></a></td>
                                                    <td class="text-right"><?php echo number_format($row->APBDES_REAL_TOTAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->APBDES_ESTI_TOTAL_PAGU, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->APBDES_ESTI_TOTAL_REAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->APBDES_BAYAR_TOTAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->APBDES_TAXGAP_PAGU, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->APBDES_TAXGAP_REAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format((float) str_replace(",", ".", $row->APBDES_TAX_COLLECTION), 2, ",", ".") ?>%</td>
                                                <?php } ?>

                                                <?php if($cari_sumber_dana == "") { ?>
                                                    <td class="text-right"><?php echo number_format($row->ALL_PAGU_TOTAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->ALL_REAL_TOTAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->ALL_ESTI_TOTAL_PAGU, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->ALL_ESTI_TOTAL_REAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->ALL_BAYAR_TOTAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->ALL_TAXGAP_PAGU, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format($row->ALL_TAXGAP_REAL, 0, ",", ".") ?></td>
                                                    <td class="text-right"><?php echo number_format((float) str_replace(",", ".", $row->ALL_TAX_COLLECTION), 2, ",", ".") ?>%</td>
                                                <?php } ?>

                                            </tr>
                                        <?php
                                    }
                                ?>
                            </tbody>
                            <thead class="thead-dark">
                                <tr>
                                    <th>Jumlah</th>
                                    <th></th>
                                    <th></th>

                                    <?php if($cari_sumber_dana == "" || $cari_sumber_dana == "APBN") { ?>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBN_PAGU_TOTAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBN_REAL_TOTAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBN_ESTI_TOTAL_PAGU, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBN_ESTI_TOTAL_REAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBN_BAYAR_TOTAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBN_TAXGAP_PAGU, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBN_TAXGAP_REAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format((float) str_replace(",", ".", $data_beranda_total->APBN_TAX_COLLECTION), 2, ",", ".") ?>%</th>
                                    <?php } ?>
                                    
                                    <?php if($cari_sumber_dana == "" || $cari_sumber_dana == "APBD") { ?>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBD_PAGU_TOTAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBD_REAL_TOTAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBD_ESTI_TOTAL_PAGU, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBD_ESTI_TOTAL_REAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBD_BAYAR_TOTAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBD_TAXGAP_PAGU, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBD_TAXGAP_REAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format((float) str_replace(",", ".", $data_beranda_total->APBD_TAX_COLLECTION), 2, ",", ".") ?>%</th>
                                    <?php } ?>
                                    
                                    <?php if($cari_sumber_dana == "" || $cari_sumber_dana == "APBDes") { ?>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBDES_PAGU_TOTAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBDES_REAL_TOTAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBDES_ESTI_TOTAL_PAGU, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBDES_ESTI_TOTAL_REAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBDES_BAYAR_TOTAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBDES_TAXGAP_PAGU, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->APBDES_TAXGAP_REAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format((float) str_replace(",", ".", $data_beranda_total->APBDES_TAX_COLLECTION), 2, ",", ".") ?>%</th>
                                    <?php } ?>

                                    <?php if($cari_sumber_dana == "") { ?>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->ALL_PAGU_TOTAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->ALL_REAL_TOTAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->ALL_ESTI_TOTAL_PAGU, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->ALL_ESTI_TOTAL_REAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->ALL_BAYAR_TOTAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->ALL_TAXGAP_PAGU, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format($data_beranda_total->ALL_TAXGAP_REAL, 0, ",", ".") ?></th>
                                        <th class="text-right"><?php echo number_format((float) str_replace(",", ".", $data_beranda_total->ALL_TAX_COLLECTION), 2, ",", ".") ?>%</th>
                                    <?php } ?>

                                </tr>
                        </thead>
                        </table>
                    </div>
                </div>
            </div>    
        </div>
    </div>
</div>

<script>
    $(document).ready(function() {
        $('#cari_limit').change(function() {
            <?php
                $url_curr = current_url()."?".$_SERVER['QUERY_STRING'];
                $url_curr = remove_url_param($url_curr, "cari_limit");
                $url_curr = remove_url_param($url_curr, "cari_page");
            ?>

            window.location.href='<?php echo $url_curr."&cari_page=1&cari_limit="; ?>' + $('#cari_limit').val() + "#scroll_back";
        });

        $('#cari_limit').val('<?php echo $cari_limit ?>');
    });
</script>

<script>
    $(document).ready(function() {
        if($("#cari_kanwil").data('disabled') == true) $('#cari_kanwil').attr('disabled', true);
        else $('#cari_kanwil').attr('disabled', false);
    });
</script>

<script>
    $(document).ready(function() {
        Highcharts.setOptions({
            lang: {
                numericSymbols: [' Ribu', ' Juta', ' Miliar', ' Triliun', ' Kuadriliun', ' Kuintiliun']
            }
        });

        var options = {
            chart: {
                renderTo: 'grafik_area',
                zoomType: 'xy'
            },
            title: {
                text: ''
            },
            subtitle: {
                text: ''
            },
            xAxis: [{
                categories: ['Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Ags', 'Sep', 'Okt', 'Nov', 'Des'],
                crosshair: true
            }],
            yAxis: [
                {
                    title: {
                        text: 'Realisasi Pagu'
                    }
                }, 
                {
                    title: {
                        text: 'Realisasi Pajak',
                    },
                    opposite: true
                }
            ],
            tooltip: {
                shared: true
            },
            legend: {
                enabled: true,
                verticalAlign: 'top',
                align: 'center',
                y: 0,
                margin: 20
            },
            exporting: {
                enabled: false
            },
            credits: {
                enabled: false
            },
            plotOptions: {
                series: {
                    pointWidth: 100
                }
            },
            series: [
                {
                    yAxis: 0,
                    name: "Realisasi Pagu",
                    type:  "spline",
                    color:"red"
                },
                {
                    yAxis: 1,
                    name: "Realisasi Pajak",
                    type: "spline",
                    color: "green"
                }
            ]
        }

        chart = new Highcharts.Chart(options);

        $.getJSON("<?php echo base_url('bendahara/beranda/data_kanwil_grafik_timeline')."?".$_SERVER['QUERY_STRING']; ?>", function(json) {
            options.series[0]['data'] = json['realisasi_pagu'];
            options.series[1]['data'] = json['realisasi_pajak'];
            chart = new Highcharts.Chart(options);
        });
    });
</script>