
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCU3tdTex4BWClD0vauHsj01n2pydE0_O4&v=weekly"
      defer></script>
<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
<script src="<?=base_url()?>/assets/plupload/moxie.min.js"></script>
<script src="<?=base_url()?>/assets/plupload/plupload.dev.js"></script>
<script src="https://cdn.ckeditor.com/ckeditor5/36.0.1/classic/ckeditor.js"></script>

<div class="content-wrapper">
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1 class="m-0">Detail Pengajuan Perubahan Pangkalan</h1>
                </div><!-- /.col -->
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="<?=base_url()?>home">Home</a></li>
                    <li class="breadcrumb-item"><a href="<?=base_url()?>admin_pengajuan_perubahan_pangkalan">Data Pengajuan Perubahan Pangkalan</a></li>
                    <li class="breadcrumb-item active">Detail Pengajuan Perubahan Pangkalan</li>
                    </ol>
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.container-fluid -->
    </div>
    <hr/>
    <style>
        .select2-container .select2-selection--single{
            height: 38px !important;
        }
    </style>
    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <?php
                    if ($data->status == 'draft'){
                    ?>
                    <div class="alert alert-secondary alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <h5><i class="icon fas fa-info"></i> Info</h5>
                        Pengajuan Perubahan Pangkalan ini masih pada tahap draft.
                    </div>
                    <?php
                    }elseif ($data->status == 'waiting'){
                    ?>
                    <div class="alert alert-info alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <h5><i class="icon fas fa-info"></i> Info</h5>
                        Pengajuan Perubahan Pangkalan ini masuk ke dalam proses pemeriksaan.
                    </div>
                    <?php
                    }elseif ($data->status == 'revision'){
                    ?>
                    <div class="alert alert-warning alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <h5><i class="icon fas fa-info"></i> Alert</h5>
                        Pengajuan Perubahan Pangkalan ini perlu perbaikan.
                    </div>
                    <?php
                    }elseif ($data->status == 'approve'){
                    ?>
                    <div class="alert alert-success alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <h5><i class="icon fas fa-info"></i> Aktif</h5>
                        Pangkalan ini sudah diterima dan telah aktif.
                    </div>
                    <?php
                    }elseif ($data->status == 'reject'){
                    ?>
                    <div class="alert alert-danger alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <h5><i class="icon fas fa-info"></i> Alert</h5>
                        Pengajuan Perubahan Pangkalan ini ditolak.
                    </div>
                    <?php
                    }
                    ?>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="card card-primary card-outline card-tabs">
                        <div class="card-header">
                            <ul class="nav nav-tabs" id="tabs-tab" role="tablist">
                                <li class="nav-item">
                                    <a class="nav-link active" id="tabs-data-pokok-tab" data-toggle="pill" href="#tabs-data-pokok" role="tab" aria-controls="tabs-data-pokok" aria-selected="true"><i class="fas fa-users"></i> Data Pokok</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" id="tabs-data-pemilik-tab" data-toggle="pill" href="#tabs-data-pemilik" role="tab" aria-controls="tabs-data-pemilik" aria-selected="false"><i class="fas fa-users"></i> Data Pemilik</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" id="tabs-lokasi-tab" data-toggle="pill" href="#tabs-lokasi" role="tab" aria-controls="tabs-lokasi" aria-selected="false"><i class="far fa-file-alt"></i> Lokasi</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" id="tabs-dokumen-tab" data-toggle="pill" href="#tabs-dokumen" role="tab" aria-controls="tabs-dokumen" aria-selected="false"><i class="far fa-file-alt"></i> Dokumen</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" id="tabs-rekap-tab" data-toggle="pill" href="#tabs-rekap" role="tab" aria-controls="tabs-rekap" aria-selected="false"><i class="far fa-file-alt"></i> Rekapitulasi</a>
                                </li>
                            </ul>
                        </div>
                        <div class="card-body">
                            <div class="tab-content" id="tabs-tabContent">
                                <div class="tab-pane text-left fade show active" id="tabs-data-pokok" role="tabpanel" aria-labelledby="tabs-data-pokok-tab">
                                    <form id="f1" action="#" method="post" enctype="multipart/form-data">
                                        <input type="hidden" name="id" value="<?=$data->id_perubahan?>">
                                        <div class="form-group">
                                            <label for="id_tipe_pangkalan">Tipe Pangkalan</label>
                                            <select class="select2 form-control form-control-border" id="id_tipe_pangkalan" placeholder="Pilih Tipe Pangkalan" name="id_tipe_pangkalan">
                                                <option value="<?=$data->id_tipe_pangkalan?>" selected><?=$data->nama_tipe?></option>
                                            </select>
                                            <span id="eid_tipe_pangkalan" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="id_registrasi">ID Registrasi</label>
                                            <input type="text" class="form-control form-control-border" id="id_registrasi" placeholder="ID Registrasi" name="id_registrasi" value="<?=$data->id_registrasi?>">
                                            <span id="eid_registrasi" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="nama_pangkalan">Nama Pangkalan</label>
                                            <input type="text" class="form-control form-control-border" id="nama_pangkalan" placeholder="Nama Pangkalan" name="nama_pangkalan" value="<?=$data->nama_pangkalan?>">
                                            <span id="enama_pangkalan" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="no_telepon">Nomor Telepon</label>
                                            <input type="text" class="form-control form-control-border" id="no_telepon" placeholder="Nomor Telepon" name="no_telepon" value="<?=$data->no_telepon?>">
                                            <span id="eno_telepon" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="no_sku">Nomor SKU</label>
                                            <input type="text" class="form-control form-control-border" id="no_sku" placeholder="Nomor SKU" name="no_sku" value="<?=$data->no_sku?>">
                                            <span id="eno_sku" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="card">
                                            <div class="card-body d-flex">
                                                <div class="ml-2">
                                                    <p>
                                                        <b>SKU</b><br>
                                                        <?php
                                                            $status_sku = false;
                                                            if (!empty($data->sku))
                                                            {
                                                                $status_sku=true;
                                                                echo 'File : '.$data->sku;
                                                            }else{
                                                                echo 'No File Available';
                                                            }
                                                        ?>
                                                    </p>
                                                </div>
                                                <div class="ml-auto">
                                                    <?php
                                                    if (!$status_sku){
                                                        if (($data->status=='draft') || ($data->status=='revision')){
                                                    ?>
                                                    
                                                    <?php
                                                    }
                                                    }else{
                                                        ?>

                                                        <?php
                                                        if (($data->status=='draft') || ($data->status=='revision')){
                                                        ?>
                                                        
                                                        <?php
                                                        }
                                                        ?>
                                                        <a class="btn btn-app bg-success" href="javascript:download_file('<?=$data->sku?>','sku');">
                                                            <i class="fas fa-download"></i> Download
                                                        </a>
                                                        <?php
                                                    }
                                                    ?>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="kuantiti">Qty Tabung / Bulan</label>
                                            <input type="number" class="form-control form-control-border" id="kuantiti" placeholder="Kuantiti" name="kuantiti" value="<?=$data->kuantiti?>">
                                            <span id="ekuantiti" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="tipe_pembayaran">Tipe Pembayaran</label>
                                            <select class="select2 form-control form-control-border" id="tipe_pembayaran" placeholder="Pilih Tipe Pembayaran" name="tipe_pembayaran">
                                                <option value="<?=$data->tipe_pembayaran?>" selected><?=$data->tipe_pembayaran?></option>
                                                <option value="CASH">CASH</option>
                                                <option value="CASHLESS">CASHLESS</option>
                                            </select>
                                            <span id="etipe_pembayaran" class="error invalid-feedback"></span>
                                        </div>
                                    </form>
                                    <hr/>
                                    <?php
                                    if (($data->status=='draft') || ($data->status=='revision')){
                                    ?>
                                    
                                    <?php
                                    }
                                    ?>
                                </div>
                                <div class="tab-pane text-left fade" id="tabs-data-pemilik" role="tabpanel" aria-labelledby="tabs-data-pemilik-tab">
                                    <form id="f2" action="#" method="post" enctype="multipart/form-data">
                                        <input type="hidden" name="id" value="<?=$data->id_perubahan?>">
                                        <div class="form-group">
                                            <label for="nama_pemilik">Nama Pemilik</label>
                                            <input type="text" class="form-control form-control-border" id="nama_pemilik" placeholder="Nama Pemilik" name="nama_pemilik" value="<?=$data->nama_pemilik?>">
                                            <span id="enama_pemilik" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="no_ktp_pemilik">Nomor KTP Pemilik</label>
                                            <input type="text" class="form-control form-control-border" id="no_ktp_pemilik" placeholder="Nomor KTP Pemilik" name="no_ktp_pemilik" value="<?=$data->no_ktp_pemilik?>">
                                            <span id="eno_ktp_pemilik" class="error invalid-feedback"></span>
                                        </div>
                                        
                                        <div class="form-group">
                                            <label for="no_hp_pemilik">Nomor HP Pemilik</label>
                                            <input type="text" class="form-control form-control-border" id="no_hp_pemilik" name="no_hp_pemilik" data-inputmask='"mask": "(+62) 999-99999999"' data-mask value="<?=$data->no_hp_pemilik?>">
                                            <span id="eno_hp" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="email">Email</label>
                                            <input type="email" class="form-control form-control-border" id="email" name="email" placeholder="Email Pemilik" value="<?=$data->email?>">
                                            <span id="eemail" class="error invalid-feedback"></span>
                                        </div>
                                    </form>
                                    <hr/>
                                    <?php
                                    if (($data->status=='draft') || ($data->status=='revision')){
                                    ?>
                                    
                                    <?php
                                    }
                                    ?>
                                </div>
                                <div class="tab-pane text-left fade" id="tabs-lokasi" role="tabpanel" aria-labelledby="tabs-lokasi-tab">
                                    <form id="f3" action="#" method="post" enctype="multipart/form-data">
                                        <div class="form-group">
                                            <label for="alamat">Alamat</label>
                                            <textarea class="form-control form-control-border" id="alamat" placeholder="Alamat" name="alamat"><?=$data->alamat?></textarea>
                                            <span id="ealamat" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="kode_pos">Kode Pos</label>
                                            <input type="text" class="form-control form-control-border" id="kode_pos" placeholder="Kode Pos" name="kode_pos" value="<?=$data->kode_pos?>">
                                            <span id="ekode_pos" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="provinsi">Provinsi</label>
                                            <select class="select2 form-control form-control-border" style="width: 100%" id="provinsi" placeholder="Pilih Provinsi" name="provinsi">
                                                <option value="<?=$data->provinsi?>" selected><?=$data->nama_provinsi?></option>
                                            </select>
                                            <span id="eprovinsi" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="kabupaten">Kabupaten</label>
                                            <select class="select2 form-control form-control-border" style="width: 100%" id="kabupaten" placeholder="Pilih Kabupaten" name="kabupaten">
                                                <option value="<?=$data->kabupaten?>" selected><?=$data->nama_kabupaten?></option>
                                            </select>
                                            <span id="ekabupaten" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="kecamatan">Kecamatan</label>
                                            <select class="select2 form-control form-control-border" style="width: 100%" id="kecamatan" placeholder="Pilih Kecamatan" name="kecamatan">
                                                <option value="<?=$data->kecamatan?>" selected><?=$data->nama_kecamatan?></option>
                                            </select>
                                            <span id="ekecamatan" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="kelurahan">Kelurahan</label>
                                            <select class="select2 form-control form-control-border" style="width: 100%" id="kelurahan" placeholder="Pilih Kelurahan" name="kelurahan">
                                                <option value="<?=$data->kelurahan?>" selected><?=$data->nama_kelurahan?></option>
                                            </select>
                                            <span id="ekelurahan" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="lat">Latitude</label>
                                            <input type="text" class="form-control form-control-border" id="lat" name="lat" value="<?=$data->lat?>">
                                            <span id="elat" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="lng">Longitude</label>
                                            <input type="text" class="form-control form-control-border" id="lng" name="lng" value="<?=$data->lng?>">
                                            <span id="elng" class="error invalid-feedback"></span>
                                        </div>
                                        <div class="form-group">
                                            <div id="map">
                                            </div>
                                        </div>
                                        <div class="card">
                                            <div class="card-body d-flex">
                                                <div class="ml-2">
                                                    <p>
                                                        <b>Foto Luar</b><br>
                                                        <?php
                                                            $status_foto_luar = false;
                                                            if (!empty($data->foto_luar))
                                                            {
                                                                $status_foto_luar=true;
                                                                ?>
                                                                <img class="img-fluid" src="<?=base_url()?>uploads/agen/perubahan_pangkalan/dokumen/foto_luar/<?=$data->foto_luar?>">
                                                                <?php
                                                            }else{
                                                                echo 'No File Available';
                                                            }
                                                        ?>
                                                    </p>
                                                </div>
                                                <div class="ml-auto">
                                                    <?php
                                                    if (!$status_foto_luar){
                                                        if (($data->status=='draft') || ($data->status=='revision')){
                                                    ?>
                                                   
                                                    <?php
                                                        }
                                                    }else{
                                                        ?>
                                                        <?php
                                                        if (($data->status=='draft') || ($data->status=='revision')){
                                                        ?>
                                                        
                                                        <?php
                                                        }
                                                        ?>
                                                        <a class="btn btn-app bg-success" href="javascript:download_file('<?=$data->foto_luar?>','foto_luar');">
                                                            <i class="fas fa-download"></i> Download
                                                        </a>
                                                        <?php
                                                    }
                                                    ?>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="card">
                                            <div class="card-body d-flex">
                                                <div class="ml-2">
                                                    <p>
                                                        <b>Foto Dalam</b><br>
                                                        <?php
                                                            $status_foto_dalam = false;
                                                            if (!empty($data->foto_dalam))
                                                            {
                                                                $status_foto_dalam=true;
                                                                ?>
                                                                <img class="img-fluid" src="<?=base_url()?>uploads/agen/perubahan_pangkalan/dokumen/foto_dalam/<?=$data->foto_dalam?>">
                                                                <?php
                                                            }else{
                                                                echo 'No File Available';
                                                            }
                                                        ?>
                                                    </p>
                                                </div>
                                                <div class="ml-auto">
                                                    <?php
                                                    if (!$status_foto_dalam){
                                                        if (($data->status=='draft') || ($data->status=='revision')){
                                                    ?>
                                                    
                                                    <?php
                                                        }
                                                    }else{
                                                        ?>
                                                        <?php
                                                        if (($data->status=='draft') || ($data->status=='revision')){
                                                            ?>
                                                        
                                                        <?php
                                                        }
                                                        ?>
                                                        <a class="btn btn-app bg-success" href="javascript:download_file('<?=$data->foto_dalam?>','foto_dalam');">
                                                            <i class="fas fa-download"></i> Download
                                                        </a>
                                                        <?php
                                                    }
                                                    ?>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                    <?php
                                    if (($data->status=='draft') || ($data->status=='revision')){
                                    ?>
                                    
                                    <?php
                                    }
                                    ?>
                                </div>
                                <div class="tab-pane text-left fade" id="tabs-dokumen" role="tabpanel" aria-labelledby="tabs-dokumen-tab">
                                    <div class="card">
                                        <div class="card-body d-flex">
                                            <div class="ml-2">
                                                <p>
                                                    <b>KTP</b><br>
                                                    <?php
                                                        $status1 = false;
                                                        if (!empty($data->ktp))
                                                        {
                                                            $status1=true;
                                                            ?>
                                                            <img class="img-fluid" src="<?=base_url()?>uploads/agen/perubahan_pangkalan/dokumen/ktp/<?=$data->ktp?>">
                                                            <?php
                                                        }else{
                                                            echo 'No File Available';
                                                        }
                                                    ?>
                                                </p>
                                            </div>
                                            <div class="ml-auto">
                                                <?php
                                                if (!$status1){
                                                    if (($data->status=='draft') || ($data->status=='revision')){
                                                ?>
                                                
                                                <?php
                                                    }
                                                }else{
                                                    ?>
                                                    <?php
                                                    if (($data->status=='draft') || ($data->status=='revision')){
                                                        ?>
                                                    
                                                    <?php
                                                    }
                                                    ?>
                                                    <a class="btn btn-app bg-success" href="javascript:download_file('<?=$data->ktp?>','ktp');">
                                                        <i class="fas fa-download"></i> Download
                                                    </a>
                                                    <?php
                                                }
                                                ?>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="card">
                                        <div class="card-body d-flex">
                                            <div class="ml-2">
                                                <p>
                                                    <b>Foto Selfie KTP</b><br>
                                                    <?php
                                                        $status2 = false;
                                                        if (!empty($data->selfie_ktp))
                                                        {
                                                            $status2=true;
                                                            ?>
                                                            <img class="img-fluid" src="<?=base_url()?>uploads/agen/perubahan_pangkalan/dokumen/selfie_ktp/<?=$data->selfie_ktp?>">
                                                            <?php
                                                        }else{
                                                            echo 'No File Available';
                                                        }
                                                    ?>
                                                </p>
                                            </div>
                                            <div class="ml-auto">
                                                <?php
                                                if (!$status2){
                                                    if (($data->status=='draft') || ($data->status=='revision')){
                                                ?>
                                                
                                                <?php
                                                    }
                                                }else{
                                                    ?>
                                                    <?php
                                                    if (($data->status=='draft') || ($data->status=='revision')){
                                                    ?>
                                                    
                                                    <?php
                                                    }
                                                    ?>
                                                    <a class="btn btn-app bg-success" href="javascript:download_file('<?=$data->selfie_ktp?>','selfie_ktp');">
                                                        <i class="fas fa-download"></i> Download
                                                    </a>
                                                    <?php
                                                }
                                                ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="tab-pane text-left fade" id="tabs-rekap" role="tabpanel" aria-labelledby="tabs-rekap-tab">
                                    <h5>Rekapitulasi</h5>
                                    <div class="card">
                                        <div class="card-body">
                                            <?php
                                            $status_pangkalan = '<span class="btn btn-sm btn-secondary bg-gradient-secondary">Draft</span>';
                                            if ($data->status == 'waiting')
                                            {
                                                $status_pangkalan ='<span class="btn btn-sm btn-primary bg-gradient-primary">Menunggu Pemeriksaan</span>';
                                            }elseif($data->status == 'revision'){
                                                $status_pangkalan ='<span class="btn btn-sm btn-warning bg-gradient-warning">Permintaan Perbaikan</span>';
                                            }elseif($data->status == 'reject'){
                                                $status_pangkalan = '<span class="btn btn-sm btn-danger bg-gradient-danger">Ditolak</span>';
                                            }elseif($data->status == 'approve'){
                                                $status_pangkalan = '<span class="btn btn-sm btn-success bg-gradient-success">Aktif</span>';
                                            }
                                            ?>
                                            Status Pengajuan Perubahan Pangkalan : <?=$status_pangkalan?>
                                        </div>
                                    </div>
                                    <div class="card card-danger card-outline">
                                        <div class="card-header">
                                            <h3 class="card-title">
                                                Statistik Kecamatan Tujuan
                                            </h3>
                                        </div>
                                        <div class="card-body">
                                            <table class="table">
                                                <thead>
                                                    <tr>
                                                        <th>Atribut</th>
                                                        <th>Nilai</th>
                                                        <th>Status</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <tr>
                                                        <td colspan="3"><?=$stat_kabupaten[0]->nama_kabupaten?></td>
                                                    </tr>
                                                    <tr>
                                                        <td colspan="3"><?=$stat_kecamatan[0]->nama_kecamatan?></td>
                                                    </tr>
                                                    <tr>
                                                        <td><b>Jumlah Penduduk</b></td>
                                                        <td><b><?=number_format($stat_kecamatan[0]->jumlah_penduduk,0,",",".")?></b></td>
                                                        <td></td>
                                                    </tr>
                                                    <tr>
                                                        <td><b>Jumlah Pangkalan Eksisting</b></td>
                                                        <td><b><?=$stat_kecamatan[0]->jumlah_pangkalan?></b></td>
                                                        <td></td>
                                                    </tr>
                                                    <tr>
                                                        <td><b>Jumlah Distribusi</b></td>
                                                        <td><b><?=number_format($stat_kecamatan[0]->jumlah_distribusi,0,",",".")?></b></td>
                                                        <td></td>
                                                    </tr>
                                                    <tr>
                                                        <td><b>Indeks Konsumsi Kabupaten / Kota</b></td>
                                                        <td><b><?=number_format($stat_kabupaten[0]->jumlah_alokasi/$stat_kabupaten[0]->jumlah_penduduk,2,",",".")?></b></td>
                                                        <td></td>
                                                    </tr>
                                                    <tr>
                                                        <td><b>Kebutuhan Alokasi</b></td>
                                                        <td><b><?=number_format(($stat_kabupaten[0]->jumlah_alokasi/$stat_kabupaten[0]->jumlah_penduduk) * $stat_kecamatan[0]->jumlah_penduduk,0,",",".")?></b></td>
                                                        <td></td>
                                                    </tr>
                                                    <tr>
                                                        <td><b>Plus Minus Alokasi</b></td>
                                                        <td><b><?php
                                                        $kebutuhan_alokasi = ($stat_kabupaten[0]->jumlah_alokasi/$stat_kabupaten[0]->jumlah_penduduk) * $stat_kecamatan[0]->jumlah_penduduk;
                                                        $distribusi = $stat_kecamatan[0]->jumlah_distribusi;
                                                        $plus_minus = $kebutuhan_alokasi - $distribusi;
                                                        $plus_minus = $plus_minus * -1;
                                                        if ($plus_minus > 0)
                                                        {
                                                            ?>
                                                            <span class="text-red">(<?=number_format($plus_minus,0,",",".")?>)</span>
                                                            <?php
                                                        }else{
                                                            ?>
                                                            <span class="text-green"><?=number_format($plus_minus,0,",",".")?></span>
                                                            <?php
                                                        }
                                                        ?></b></td>
                                                        <td>
                                                            <?php
                                                            if ($plus_minus > 0)
                                                            {
                                                                ?>
                                                                <span class="text-red">Kecamatan masih kekurangan alokasi. Rating pengajuan 70%.</span>
                                                                <?php
                                                            }else{
                                                                ?>
                                                                <span class="text-green">Kecamatan sudah kelebihan alokasi. Rating pengajuan 40%.</span>
                                                                <?php
                                                            }
                                                            ?>
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                    <div class="card card-warning card-outline">
                                        <div class="card-header">
                                            <h3 class="card-title">
                                                Tim Pemeriksa
                                            </h3>
                                        </div>
                                        <div class="card-body">
                                            <table class="table">
                                                <tr>
                                                    <td width="300">Petugas</td>
                                                    <td width="5">:</td>
                                                    <td><?=$approval->nama_petugas?></td>
                                                </tr>
                                                <tr>
                                                    <td width="300">Tanggal Status</td>
                                                    <td width="5">:</td>
                                                    <td><?=$approval->tgl_status_all?></td>
                                                </tr>
                                                <tr>
                                                    <td>Komentar Tim Pemeriksaan</td>
                                                    <td>:</td>
                                                    <td><p>Petugas : <?=$komentar_latest[0]->nama?></p><p>Tanggal : <?=$komentar_latest[0]->tanggal?></p>
                                                    <p>Pesan : <br><?=$komentar_latest[0]->komentar?></p>
                                                    <hr/>
                                                    <p>
                                                        <textarea name="komentar" id="editor" class="form-control mb-2"></textarea>
                                                        <button id="b_kirim_komentar" class="btn btn-sm bg-gradient-primary">Update Komentar</button>
                                                    </p>
                                                    <p><button id="b_lihat_riwayat_komentar" class="btn btn-sm bg-gradient-success" data-toggle="modal" data-target="#modal-komentar">Lihat Riwayat Komentar</button></td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                    <div class="card card-success card-outline">
                                        <div class="card-body">
                                            <button id="b_approve" class="btn btn-sm bg-gradient-success">Approve Pengajuan</button>
                                            <button id="b_revision" class="btn btn-sm bg-gradient-warning">Minta Perbaikan</button>
                                            <button id="b_reject" class="btn btn-sm bg-gradient-danger">Reject Pengajuan</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <div class="modal fade" id="modal-komentar" style="display: none;" aria-hidden="true">
        <div class="modal-dialog modal-xl">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">Riwayat Komentar</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">
                    <table id="tbl_data1" class="table table-striped table-bordered display compact" style="width:100%">
                        <thead>
                            <tr>
                                <th>Tanggal</th>
                                <th>Pemeriksa</th>
                                <th>Komentar</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
                <div class="modal-footer justify-content-between">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <style>
        #map {
            width: 100%;
            height: 500px;
        }

        .ck-editor__editable[role="textbox"] {
                /* editing area */
                min-height: 200px;
                margin-bottom: 10px;
            }
    </style>
    <script>
        $(document).ready(function () {
            var table_komentar;

            $('#modal-komentar').on('shown.bs.modal', function (event) {
                table_komentar = $("#tbl_data1").DataTable({
                    processing: true,
                    serverSide: true,
                    pageLength:10,
                    scrollX: true,
                    dom: "<'row mb-3'<'col-sm-12'B>>" +
                    "<'row mb-2'<'col-sm-6'f><'col-sm-6'p>>" +
                    "<'row'<'col-sm-12'tr>>" +
                    "<'row'<'col-sm-5'i><'col-sm-7'p>>",
                    language : {
                        searchBuilder: {
                            button: '<span class="fas fa-search"> Filter</span>',
                        }
                    },
                    ajax: {
                        url : '<?=base_url()?>admin_get_komentar_pengajuan_perubahan_pangkalan/<?=$data->id_perubahan?>',
                        type : 'POST'
                    },
                    columns: [
                        { data: 'tanggal' },
                        { data: 'nama' },
                        { data: 'komentar' },
                    ],
                    buttons: [
                        'searchBuilder',
                        'copyHtml5',
                        {
                            extend: 'excelHtml5',
                            text: 'Export Excel',
                            orientation: 'landscape',
                            exportOptions: {
                                columns: [ ':not(.not-export)' ]
                            }
                        },
                        {
                            extend: 'csvHtml5',
                            text: 'Export CSV',
                            orientation: 'landscape',
                            exportOptions: {
                                columns: [ ':not(.not-export)' ]
                            }
                        },
                        {
                            extend: 'pdfHtml5',
                            text: 'Export PDF',
                            orientation: 'landscape',
                            exportOptions: {
                                columns: [ ':not(.not-export)' ]
                            }
                        }
                    ]
                });
            });

            $('#modal-komentar').on('hidden.bs.modal', function (event) {
                table_komentar.destroy();
            });
        });
    </script>
    <script>
        $(document).ready(function () {
            var editor1;
            ClassicEditor.create( document.querySelector( '#editor' ) ).then( editor => {
                    console.log( 'Editor was initialized', editor );
                    editor1 = editor;
                } )
                .catch( err => {
                    console.error( err.stack );
                } );

            $("#b_kirim_komentar").click(function () {
                Swal.fire({
                    title:'Processing..',
                    html:'<p>Please wait..</p>',
                    allowOutsideClick:false
                });
                Swal.showLoading();
                
                var tkomentar = editor1.getData();
                $.post("<?=base_url()?>admin_perubahan_pangkalan_komentar_add",{id:'<?=$data->id_perubahan?>',komentar:tkomentar}).done(function (data) {
                    Swal.fire({
                        text:'komentar berhasil disimpan!',
                        icon : 'success'
                    }).then(function () {
                        window.location.href = '<?=base_url()?>admin_view_pengajuan_perubahan_pangkalan_add/<?=$data->id_perubahan?>';
                    });
                }).fail(function (data) {
                    Swal.fire({
                        text:'Terjadi kesalahan pada saat penyimpanan!',
                        icon : 'error'
                    });
                });
            });

            $("#b_approve").click(function () {
                Swal.fire({
                    title:'Processing..',
                    html:'<p>Please wait..</p>',
                    allowOutsideClick:false
                });
                Swal.showLoading();

                $.post("<?=base_url()?>admin_pengajuan_perubahan_pangkalan_approve",{id:'<?=$data->id_perubahan?>'}).done(function (data) {
                    Swal.fire({
                        text:'pengajuan berhasil di-approved!',
                        icon : 'success'
                    }).then(function () {
                        window.location.href = '<?=base_url()?>admin_view_pengajuan_perubahan_pangkalan/<?=$data->id_perubahan?>';
                    });
                }).fail(function (data) {
                    Swal.fire({
                        text:'Terjadi kesalahan pada saat penyimpanan!',
                        icon : 'error'
                    });
                });
            });

            $("#b_revision").click(function () {
                Swal.fire({
                    title:'Processing..',
                    html:'<p>Please wait..</p>',
                    allowOutsideClick:false
                });
                Swal.showLoading();

                $.post("<?=base_url()?>admin_pengajuan_perubahan_pangkalan_revision",{id:'<?=$data->id_perubahan?>'}).done(function (data) {
                    Swal.fire({
                        text:'status pengajuan berhasil di-simpan!',
                        icon : 'success'
                    }).then(function () {
                        window.location.href = '<?=base_url()?>admin_view_pengajuan_perubahan_pangkalan_add/<?=$data->id_perubahan?>';
                    });
                }).fail(function (data) {
                    Swal.fire({
                        text:'Terjadi kesalahan pada saat penyimpanan!',
                        icon : 'error'
                    });
                });
            });

            $("#b_reject").click(function () {
                Swal.fire({
                    title:'Processing..',
                    html:'<p>Please wait..</p>',
                    allowOutsideClick:false
                });
                Swal.showLoading();

                $.post("<?=base_url()?>admin_pengajuan_perubahan_pangkalan_reject",{id:'<?=$data->id_perubahan?>'}).done(function (data) {
                    Swal.fire({
                        text:'status pengajuan berhasil di-simpan!',
                        icon : 'success'
                    }).then(function () {
                        window.location.href = '<?=base_url()?>admin_view_pengajuan_perubahan_pangkalan_add/<?=$data->id_perubahan?>';
                    });
                }).fail(function (data) {
                    Swal.fire({
                        text:'Terjadi kesalahan pada saat penyimpanan!',
                        icon : 'error'
                    });
                });
            });
        });
    </script>
    
    <script>
        function download_file(filename,target)
        {
            var link = document.createElement('a');
            link.download = filename;
            link.href ="<?=base_url()?>/uploads/agen/perubahan_pangkalan/dokumen/"+target+"/"+filename;  
            link.click();
        }
    </script>
    
    <script>
        var map;
        var markers = [];
        var iconBase;
        var icons;
        $(document).ready(function () {
            function initMap() {
                map = new google.maps.Map(document.getElementById("map"), {
                    zoom: 12,
                    center: { lat: 3.6424551, lng: 98.5994535 },
                });

                iconBase =
                    "<?=base_url()?>/src/img/";
                icons = {
                    info: {
                        icon: iconBase + "logistic.png",
                    },
                };

                <?php
                if (!empty($data->lat) && !empty($data->lng))
                {
                ?>
                    var marker = new google.maps.Marker({
                        position: new google.maps.LatLng(<?=$data->lat?>, <?=$data->lng?>),
                        icon: icons['info'].icon,
                        map: map,
                        title:'Lokasi',
                    });
                    markers.push(marker);
                    map.panTo(marker.position);
                <?php
                }
                ?>
            }

            initMap();
            
            function addMarker(position, emap) {
                while (markers.length>0)
                {
                    markers[markers.length-1].setMap(null);
                    markers.pop();
                }

                var marker = new google.maps.Marker({
                    position: position,
                    map: emap,
                    icon: icons['info'].icon,
                    title:'Lokasi'
                });
                
                markers.push(marker);
                marker.setAnimation(google.maps.Animation.BOUNCE);
                map.panTo(marker.position);

                var LatLng1 = markers[0].position.toUrlValue().split(",");

                $("input[name='lat']").val(LatLng1[0]);
                $("input[name='lng']").val(LatLng1[1]);
            }
        });
    </script>
</div>