<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> Rincian Belanja Pemerintah APBN</h3></div>
                    <div class="card-body">
                        <form class="forms-sample" method="get" action="<?php echo base_url('bendahara/apbn') ?>">
                            <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';
                                $cari_kpp_disabled = 'false';
                            
                                if (session('tpkantor') == 'KPP') {
                                    $cari_kanwil_disabled = 'true';
                                    $cari_kpp_disabled = 'true';
                                } 
                                else 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-4">
                                    <div class="form-group">
                                        <label for="cari_kpp">KPP</label>
                                        <select class="form-control" id="cari_kpp" name="cari_kpp" data-temp="<?php echo $cari_kpp ?>" data-disabled="<?php echo $cari_kpp_disabled ?>">
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="cari_seksi">Seksi</label>
                                        <select class="form-control" id="cari_seksi" name="cari_seksi" data-temp="<?php echo $cari_seksi ?>">
                                            <option value=''>Semua</option>
                                            <?php
                                                foreach ($ref_seksi as $row) {
                                                    echo "<option value='".$row->KODESIE ."'>".$row->NAMA_UNIT_ES4."</option>";
                                                }
                                            ?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="cari_ar">Account Representative</label>
                                        <select class="form-control" id="cari_ar" name="cari_ar" data-temp="<?php echo $cari_ar ?>">
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="cari_kabkot">Kabupaten/Kota</label>
                                        <select class="form-control" id="cari_kabkot" name="cari_kabkot" data-temp="<?php echo $cari_kabkot ?>">
                                        </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>
                
                <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($data_apbn_total->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($data_apbn_total->REAL_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($data_apbn_total->PAGU_TOTAL-$data_apbn_total->REAL_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 $data_apbn_total->PAGU_TOTAL > 0 ? number_format(($data_apbn_total->REAL_TOTAL/$data_apbn_total->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>ESTI Pajak (Total Pagu)</h6>
                                                <h2><?php echo number_format($data_apbn_total->ESTI_TOTAL_PAGU, 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($data_apbn_total->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($data_apbn_total->TAXGAP_TOTAL_PAGU, 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(",", ".", $data_apbn_total->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">

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

                        <?php
                            $page_curr = $cari_page;
                            $page_count = ceil($data_apbn_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>
                                    <th rowspan="2" colspan="1">Kabupaten/Kota</th>
                                    <th rowspan="2" colspan="1">Seksi</th>
                                    <th rowspan="2" colspan="1">AR</th>
                                    <th rowspan="1" colspan="3">Satuan Kerja</th>
                                    <th rowspan="1" colspan="6">Total Pagu</th>
                                    <th rowspan="1" colspan="6">Realisasi Pagu</th>
                                    <th rowspan="1" colspan="6">ESTI Pajak (Total Pagu)</th>
                                    <th rowspan="1" colspan="6">ESTI Pajak (Realisasi Pagu)</th>
                                    <th rowspan="1" colspan="7">Realisasi Pajak</th>
                                    <th rowspan="1" colspan="6">Tax Gap (Total Pagu)</th>
                                    <th rowspan="1" colspan="6">Tax Gap (Realisasi Pagu)</th>
                                    <th rowspan="2" colspan="1">Tax Collection</th>
                                </tr>
                                <tr role="row">
                                    <th>NPWP</th>
                                    <th>Nama</th>
                                    <th>Kode</th>
                                    <th>Pegawai</th>
                                    <th>Barang/Jasa</th>
                                    <th>Modal</th>
                                    <th>Sosial</th>
                                    <th>Lainnya</th>
                                    <th>Jumlah</th>
                                    <th>Pegawai</th>
                                    <th>Barang/Jasa</th>
                                    <th>Modal</th>
                                    <th>Sosial</th>
                                    <th>Lainnya</th>
                                    <th>Jumlah</th>
                                    <th>PPh 21</th>
                                    <th>PPh 22</th>
                                    <th>PPh 23</th>
                                    <th>PPh 4(2)</th>
                                    <th>PPN</th>
                                    <th>Jumlah</th>
                                    <th>PPh 21</th>
                                    <th>PPh 22</th>
                                    <th>PPh 23</th>
                                    <th>PPh 4(2)</th>
                                    <th>PPN</th>
                                    <th>Jumlah</th>
                                    <th>PPh 21</th>
                                    <th>PPh 22</th>
                                    <th>PPh 23</th>
                                    <th>PPh 4(2)</th>
                                    <th>PPN</th>
                                    <th>Lainnya</th>
                                    <th>Jumlah</th>
                                    <th>PPh 21</th>
                                    <th>PPh 22</th>
                                    <th>PPh 23</th>
                                    <th>PPh 4(2)</th>
                                    <th>PPN</th>
                                    <th>Jumlah</th>
                                    <th>PPh 21</th>
                                    <th>PPh 22</th>
                                    <th>PPh 23</th>
                                    <th>PPh 4(2)</th>
                                    <th>PPN</th>
                                    <th>Jumlah</th>
                                </tr>
                                <tr>
                                    <th class="thead_sub">1</th>
                                    <th class="thead_sub">2</th>
                                    <th class="thead_sub">3</th>
                                    <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>
                                    <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>
                                    <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>
                                    <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>
                                    <th class="thead_sub">36</th>
                                    <th class="thead_sub">37</th>
                                    <th class="thead_sub">38</th>
                                    <th class="thead_sub">39</th>
                                    <th class="thead_sub">40</th>
                                    <th class="thead_sub">40</th>
                                    <th class="thead_sub">40</th>
                                    <th class="thead_sub">40</th>
                                    <th class="thead_sub">41</th>
                                    <th class="thead_sub">42</th>
                                    <th class="thead_sub">43</th>
                                    <th class="thead_sub">44</th>
                                    <th class="thead_sub">45</th>
                                    <th class="thead_sub">46</th>
                                    <th class="thead_sub">47</th>
                                    <th class="thead_sub">48</th>
                                    <th class="thead_sub">49</th>
                                    <th class="thead_sub">50</th>
                                    
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    $nomor = ($cari_page * $cari_limit) - $cari_limit;

                                    foreach ($data_apbn 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><?php echo $row->NM_KPP; ?></td>
                                                <td><?php echo ucwords(strtolower($row->KABKOTA)); ?></td>
                                                <td><?php echo $row->NM_SEKSI; ?></td>
                                                <td><?php echo ucwords(strtolower($row->NM_AR)); ?></td>
                                                <td><?php echo $row->NPWP; ?></td>
                                                <td><?php echo ucwords(strtolower($row->NAMA_SATKER)); ?></td>
                                                <td><?php echo $row->KODE_SATKER; ?></td>
                                                <td class="text-right"><?php echo number_format($row->PAGU_PEGAWAI, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->PAGU_BARANG, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->PAGU_MODAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->PAGU_SOSIAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->PAGU_LAINNYA, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->PAGU_TOTAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->REAL_PEGAWAI, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->REAL_BARANG, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->REAL_MODAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->REAL_SOSIAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->REAL_LAINNYA, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->REAL_TOTAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->ESTI_PPH21_PAGU, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->ESTI_PPH22_PAGU, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->ESTI_PPH23_PAGU, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->ESTI_PPH42_PAGU, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->ESTI_PPN_PAGU, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->ESTI_TOTAL_PAGU, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->ESTI_PPH21_REAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->ESTI_PPH22_REAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->ESTI_PPH23_REAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->ESTI_PPH42_REAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->ESTI_PPN_REAL, 0, ",", ".") ?></td>                               
                                                <td class="text-right"><?php echo number_format($row->ESTI_TOTAL_REAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->BAYAR_PPH21, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->BAYAR_PPH22, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->BAYAR_PPH23, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->BAYAR_PPH42, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->BAYAR_PPN, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->BAYAR_LAINNYA, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->BAYAR_TOTAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->TAXGAP_PPH21_PAGU, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->TAXGAP_PPH22_PAGU, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->TAXGAP_PPH23_PAGU, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->TAXGAP_PPH42_PAGU, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->TAXGAP_PPN_PAGU, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->TAXGAP_TOTAL_PAGU, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->TAXGAP_PPH21_REAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->TAXGAP_PPH22_REAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->TAXGAP_PPH23_REAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->TAXGAP_PPH42_REAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->TAXGAP_PPN_REAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format($row->TAXGAP_TOTAL_REAL, 0, ",", ".") ?></td>
                                                <td class="text-right"><?php echo number_format((float) str_replace(",", ".", $row->TAX_COLLECTION), 2, ",", ".") ?>%</td>
                                            </tr>
                                        <?php
                                    }
                                ?>
                            </tbody>
                            <thead class="thead-dark">
                                <tr>
                                    <th>Jumlah</th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->PAGU_PEGAWAI, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->PAGU_BARANG, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->PAGU_MODAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->PAGU_SOSIAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->PAGU_LAINNYA, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->PAGU_TOTAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->REAL_PEGAWAI, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->REAL_BARANG, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->REAL_MODAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->REAL_SOSIAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->REAL_LAINNYA, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->REAL_TOTAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->ESTI_PPH21_PAGU, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->ESTI_PPH22_PAGU, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->ESTI_PPH23_PAGU, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->ESTI_PPH42_PAGU, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->ESTI_PPN_PAGU, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->ESTI_TOTAL_PAGU, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->ESTI_PPH21_REAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->ESTI_PPH22_REAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->ESTI_PPH23_REAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->ESTI_PPH42_REAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->ESTI_PPN_REAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->ESTI_TOTAL_REAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->BAYAR_PPH21, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->BAYAR_PPH22, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->BAYAR_PPH23, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->BAYAR_PPH42, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->BAYAR_PPN, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->BAYAR_LAINNYA, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->BAYAR_TOTAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->TAXGAP_PPH21_PAGU, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->TAXGAP_PPH22_PAGU, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->TAXGAP_PPH23_PAGU, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->TAXGAP_PPH42_PAGU, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->TAXGAP_PPN_PAGU, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->TAXGAP_TOTAL_PAGU, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->TAXGAP_PPH21_REAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->TAXGAP_PPH22_REAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->TAXGAP_PPH23_REAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->TAXGAP_PPH42_REAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->TAXGAP_PPN_REAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format($data_apbn_total->TAXGAP_TOTAL_REAL, 0, ",", ".") ?></th>
                                    <th class="text-right"><?php echo number_format((float) str_replace(",", ".", $data_apbn_total->TAX_COLLECTION), 2, ",", ".") ?>%</th>
                                </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() {
        $('#cari_kanwil').change(function() {
            var cari_kanwil = $('#cari_kanwil').val();

            if(cari_kanwil == '') $('#cari_kpp').attr('disabled', true);
            else {
                if($("#cari_kpp").data('disabled') == true) $('#cari_kpp').attr('disabled', true);
                else $('#cari_kpp').attr('disabled', false);
            }

            $('#cari_kpp').empty().append("<option value=''>Semua</option>").val('');

           if (cari_kanwil != '') {
                $.ajax({
                    url: "<?php echo base_url('bendahara/general/get_ref_kpp'); ?>",
                    method: "GET",
                    data: {
                        kanwil: cari_kanwil
                    },
                    dataType: "JSON",
                    success: function(data) {
                        $.each(data, function(key, value) {
                            $('#cari_kpp').append('<option value="' + value.KD_KPP + '">' + value.NM_KANTOR + '</option>');
                        });
                        
                        if($("#cari_kpp").data('temp') != "") {
                            $('#cari_kpp').val($("#cari_kpp").data('temp')).change();
                            $("#cari_kpp").data('temp', '');
                        }
                        else $("#cari_kpp").change();
                    }
                });
            }
            else $("#cari_kpp").change();
        });

        $('#cari_kpp').change(function() {
            var cari_kpp = $('#cari_kpp').val();

            if(cari_kpp == '') {
                $('#cari_seksi').attr('disabled', true);
                $('#cari_kabkot').attr('disabled', true);
            }
            else {
                $('#cari_seksi').attr('disabled', false);
                $('#cari_kabkot').attr('disabled', false);
            }

            if($("#cari_seksi").data('temp') != "") {
                $('#cari_seksi').val($("#cari_seksi").data('temp')).change();
                $("#cari_seksi").data('temp', '');
            }
            else $('#cari_seksi').val('').change();

            $('#cari_kabkot').empty().append("<option value=''>Semua</option>");

            if (cari_kpp != '') {
                $.ajax({
                    url: "<?php echo base_url('bendahara/general/get_ref_kabkot'); ?>",
                    method: "GET",
                    data: {
                        kpp: cari_kpp
                    },
                    dataType: "JSON",
                    success: function(data) {
                        $.each(data, function(key, value) {
                            $('#cari_kabkot').append('<option value="' + value.NM_DATI2 + '">' + value.NM_DATI2.split(" ").map(s => s.charAt(0).toUpperCase() + s.substr(1).toLowerCase()).join(" ") + '</option>');
                        });
                        
                        if($("#cari_kabkot").data('temp') != "") {
                            $('#cari_kabkot').val($("#cari_kabkot").data('temp')).change();
                            $("#cari_kabkot").data('temp', '');
                        }
                    }
                });
            }
        });

        $('#cari_seksi').change(function() {
            var cari_kpp = $('#cari_kpp').val();
            var cari_seksi = $('#cari_seksi').val();

            if(cari_seksi == '') $('#cari_ar').attr('disabled', true);
            else $('#cari_ar').attr('disabled', false);

            $('#cari_ar').empty().append("<option value=''>Semua</option>");

            if (cari_kpp != '' && cari_seksi != '') {
                $.ajax({
                    url: "<?php echo base_url('bendahara/general/get_ref_ar'); ?>",
                    method: "GET",
                    data: {
                        kpp: cari_kpp,
                        seksi: cari_seksi
                    },
                    dataType: "JSON",
                    success: function(data) {
                        $.each(data, function(key, value) {
                            $('#cari_ar').append('<option value="' + value.NIP + '">' + value.NAMA.split(" ").map(s => s.charAt(0).toUpperCase() + s.substr(1).toLowerCase()).join(" ") + '</option>');
                        });
                        
                        if($("#cari_ar").data('temp') != "") {
                            $('#cari_ar').val($("#cari_ar").data('temp')).change();
                            $("#cari_ar").data('temp', '');
                        }
                    }
                });
            }
        });

        if($("#cari_kanwil").data('disabled') == true) $('#cari_kanwil').attr('disabled', true);
        else $('#cari_kanwil').attr('disabled', false);

        $('#cari_kanwil').change();
    });
</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/apbn/data_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>