
<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()?>agen_pengajuan_perubahan_pangkalan_add">Data Pengajuan Perubahan Pangkalan Baru</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. Silahkan lengkapi data pengajuan dan kirim pengajuan dengan menekan tombol [Kirim Pengajuan] pada menu Rekapitulasi.
                    </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. Silahkan menunggu notifikasi selanjutnya.
                    </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. Silahkan perbaiki data pengajuan dan kirim pengajuan kembali dengan menekan tombol [Kirim Pengajuan] pada menu Rekapitulasi.
                    </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. Anda dapat melihat alasan penolakan pada bagian komentar Tim Pemeriksa pada menu Rekapitulasi.
                    </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')){
                                                    ?>
                                                    <button class="btn btn-app bg-info" id="btn_browse_sku">
                                                        <i class="fas fa-file-upload"></i> Upload
                                                    </button>
                                                    <?php
                                                    }
                                                    }else{
                                                        ?>

                                                        <?php
                                                        if (($data->status=='draft') || ($data->status=='revision')){
                                                        ?>
                                                        <a class="btn btn-app bg-danger" href="javascript:delete_file('<?=$data->sku?>','sku');">
                                                            <i class="fas fa-trash"></i> Delete
                                                        </a>
                                                        <?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')){
                                    ?>
                                    <button id="btn_simpan1" class="btn bg-gradient-primary"><span class="fas fa-check"></span> Update Data</button>
                                    <?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')){
                                    ?>
                                    <button id="btn_simpan2" class="btn bg-gradient-primary"><span class="fas fa-check"></span> Update Data</button>
                                    <?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')){
                                                    ?>
                                                    <button class="btn btn-app bg-info" id="btn_browse_foto_luar">
                                                        <i class="fas fa-file-upload"></i> Upload
                                                    </button>
                                                    <?php
                                                        }
                                                    }else{
                                                        ?>
                                                        <?php
                                                        if (($data->status=='draft') || ($data->status=='revision')){
                                                        ?>
                                                        <a class="btn btn-app bg-danger" href="javascript:delete_file('<?=$data->foto_luar?>','foto_luar');">
                                                            <i class="fas fa-trash"></i> Delete
                                                        </a>
                                                        <?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')){
                                                    ?>
                                                    <button class="btn btn-app bg-info" id="btn_browse_foto_dalam">
                                                        <i class="fas fa-file-upload"></i> Upload
                                                    </button>
                                                    <?php
                                                        }
                                                    }else{
                                                        ?>
                                                        <?php
                                                        if (($data->status=='draft') || ($data->status=='revision')){
                                                            ?>
                                                        <a class="btn btn-app bg-danger" href="javascript:delete_file('<?=$data->foto_dalam?>','foto_dalam');">
                                                            <i class="fas fa-trash"></i> Delete
                                                        </a>
                                                        <?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')){
                                    ?>
                                    <button id="btn_simpan3" class="btn bg-gradient-primary"><span class="fas fa-check"></span> Update Lokasi</button>
                                    <?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')){
                                                ?>
                                                <button class="btn btn-app bg-info" id="btn_browse_ktp">
                                                    <i class="fas fa-file-upload"></i> Upload
                                                </button>
                                                <?php
                                                    }
                                                }else{
                                                    ?>
                                                    <?php
                                                    if (($data->status=='draft') || ($data->status=='revision')){
                                                        ?>
                                                    <a class="btn btn-app bg-danger" href="javascript:delete_file('<?=$data->ktp?>','ktp');">
                                                        <i class="fas fa-trash"></i> Delete
                                                    </a>
                                                    <?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')){
                                                ?>
                                                <button class="btn btn-app bg-info" id="btn_browse_selfie_ktp">
                                                    <i class="fas fa-file-upload"></i> Upload
                                                </button>
                                                <?php
                                                    }
                                                }else{
                                                    ?>
                                                    <?php
                                                    if (($data->status=='draft') || ($data->status=='revision')){
                                                    ?>
                                                    <a class="btn btn-app bg-danger" href="javascript:delete_file('<?=$data->selfie_ktp?>','selfie_ktp');">
                                                        <i class="fas fa-trash"></i> Delete
                                                    </a>
                                                    <?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>
                                    <p>Pada halaman ini dapat dilihat rekapitulasi data pengajuan atau informasi pangkalan. Status pangkalan dapat dibagi menjadi  yaitu :
                                        <ul>
                                            <li>Draft, Tahap awal pengisian data pengajuan dimana agen / user dapat merubah data dan kemudian mengirimkan pengajuan untuk diperiksa.</li>
                                            <li>Menunggu Pemeriksaan, Tahap ini pengajuan akan diperiksa oleh tim pemeriksa. Agen / User akan mendapatkan notifikasi jika pengajuan telah selesai diperiksa.</li>
                                            <li>Permintaan Perbaikan, Tahap ini merupakan tahap dimana data pengajuan membutuhkan perbaikan. Agen / User dapat merubah data pengajuan sesuai dengan permintaan perbaikan dan mengajukan pemeriksaan kembali.</li>
                                            <li>Aktif, Tahap ini merupakan tahap dimana pangkalan telah dinyatakn aktif.</li>
                                            <li>Ditolak, pada tahap ini pengajuan ditolak dan tidak dapat diteruskan.</li>
                                        </ul>
                                    </p>
                                    <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 Pangkalan : <?=$status_pangkalan?>
                                        </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><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">
                                            <?php
                                            if (($data->status=='draft') || ($data->status=='revision')){
                                            ?>
                                            <button id="b_kirim_pengajuan" class="btn btn-sm bg-gradient-primary">Kirim Pengajuan</button>
                                            <button id="b_hapus_pengajuan" class="btn btn-sm bg-gradient-danger">Batalkan dan Hapus Pengajuan Ini</button>
                                            <?php
                                            }
                                            ?>
                                        </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;
            }
    </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()?>agen_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 () {
            <?php
            if (($data->status=='draft') || ($data->status=='revision')){
            ?>
            $("#b_kirim_pengajuan").click(function () {
                Swal.fire({
                    title:'Kirim Pengajuan',
                    html: '<p>Warning, Pastikan data telah lengkap dan sesuai sebelum mengirimkan pengajuan. Pengajuan yang dikirimkan tidak dapat dirubah selama proses pemeriksaan!</p>',
                    showDenyButton: true,
                    showCancelButton: true,
                    confirmButtonText: 'Yes',
                    denyButtonText: 'No',
                }).then((result) => {
                    if (result.isConfirmed) {
                        Swal.fire({
                            title:'Processing..',
                            html:'<p>Please wait..</p>',
                            allowOutsideClick:false
                        });
                        Swal.showLoading();
                        $.post("<?=base_url()?>agen_kirim_pengajuan_perubahan_pangkalan",{id:'<?=$data->id_perubahan?>'}).done(function (data) {
                            Swal.fire({
                                text:'pengajuan berhasil dikirimkan!',
                                icon : 'success'
                            }).then(function () {
                                window.location.href = '<?=base_url()?>agen_view_pengajuan_perubahan_pangkalan_add/<?=$data->id_perubahan?>';
                            });
                        }).fail(function (data) {
                            Swal.fire({
                                text:'Terjadi kesalahan pada saat penyimpanan!',
                                icon : 'error'
                            });
                        });
                    }else{
                        Swal.fire('Operasi dibatalkan..', '', 'info');
                    }
                });
            });

            $("#b_hapus_pengajuan").click(function () {
                Swal.fire({
                    title:'Batalkan / Hapus Pengajuan',
                    html: '<p>Yakin ingin menghapus pengajuan ini?</p>',
                    showDenyButton: true,
                    showCancelButton: true,
                    confirmButtonText: 'Yes',
                    denyButtonText: 'No',
                }).then((result) => {
                    if (result.isConfirmed) {
                        Swal.fire({
                            title:'Processing..',
                            html:'<p>Please wait..</p>',
                            allowOutsideClick:false
                        });
                        Swal.showLoading();
                        $.post("<?=base_url()?>agen_hapus_pengajuan_perubahan_pangkalan",{id:'<?=$data->id_perubahan?>'}).done(function (data) {
                            Swal.fire({
                                text:'pengajuan berhasil dihapus!',
                                icon : 'success'
                            }).then(function () {
                                window.location.href = '<?=base_url()?>agen_pengajuan_perubahan_pangkalan';
                            });
                        }).fail(function (data) {
                            Swal.fire({
                                text:'Terjadi kesalahan pada saat penghapusan!',
                                icon : 'error'
                            });
                        });
                    }else{
                        Swal.fire('Operasi dibatalkan..', '', 'info');
                    }
                });
            });
            <?php
            }
            ?>
        });
    </script>
    <script>
        $(document).ready(function () {
            <?php
            if (($data->status=='draft') || ($data->status=='revision')){
            ?>
            function init_uploader(target) {
                var uploader = new plupload.Uploader({
                    'multi_selection' : false,
                    'unique_names' : true,
                    'browse_button' : 'btn_browse_'+target,
                    'chunk_size':'1024kb',
                    'max_retries' : 3,
                    'url' : '<?=base_url()?>agen_perubahan_pangkalan_upload/'+target+'/<?=$data->id_perubahan?>',
                });

                uploader.init();

                uploader.bind("BeforeUpload", function(up,file) {
                    file.name = <?=$data->id_pangkalan?>+'_'+file.target_name;

                    var params = up.settings.multipart_params;
                    params.key = file.name;
                    params.Filename = file.name;
                });

                uploader.bind('UploadProgress', function(up, file) {
                    /*document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";*/
                    $("#filelist_inner").html(file.name + ' : ' + file.percent + '%');
                    $("#filelist").attr('aria-valuenow',file.percent);
                    $("#filelist_inner").attr('style','width:'+file.percent+'%');
                });

                uploader.bind('UploadComplete', function(up, file, info) {
                    Swal.fire({
                        text:'Uploading Sukses',
                        icon : 'success',
                        allowOutsideClick:false
                    }).then(function () {
                        window.location.href = '<?=base_url()?>agen_view_pengajuan_perubahan_pangkalan_add/<?=$data->id_perubahan?>';
                    });
                });

                uploader.bind('Error', function(up, err) {
                    up.stop();
                    console.log(err);
                    Swal.fire({
                        text:'Uploading Failed! Error : '+err.message,
                        icon : 'error',
                        allowOutsideClick:false
                    });
                });

                uploader.bind('FilesAdded', function(up, files) {
                    if(up.files.length > 1)
                    {
                        tfile = up.files[0];
                        up.removeFile(tfile);
                    }

                    upload(up);
                });

                return uploader;
            }

            function upload(up)
            {
                if (up.files.length <= 0)
                {
                    Swal.fire({
                        title:'Upload',
                        html:'Tidak ada file yang akan diupload..',
                        icon : 'error',
                        allowOutsideClick:false
                    }).then(function () {
                        return false;
                    });
                }

                Swal.fire({
                    title:'Uploading..',
                    html:'<div id="filelist" class="progress" role="progressbar" aria-label="test" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"><div class="progress-bar progress-bar-striped progress-bar-animated" id="filelist_inner" style="width: 0%">0%</div></div>',
                    allowOutsideClick:false
                });
                Swal.showLoading();
                up.start();
            }

            var uploader_sku = init_uploader('sku');
            var uploader_ktp = init_uploader('ktp');
            var uploader_ktp = init_uploader('selfie_ktp');
            var uploader_foto_luar = init_uploader('foto_luar');
            var uploader_foto_dalam = init_uploader('foto_dalam');
            <?php
            }
            ?>
        });
    </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();
        }

        <?php
        if (($data->status=='draft') || ($data->status=='revision')){
        ?>
        function delete_file(filename,target)
        {
            Swal.fire({
                title:'Delete File..',
                html: '<p>Yakin ingin menghapus file ini?</p>',
                showDenyButton: true,
                showCancelButton: true,
                confirmButtonText: 'Yes',
                denyButtonText: 'No',
            }).then((result) => {
                if (result.isConfirmed) {
                    Swal.fire({
                        text: 'Menghapus file.. Silahkan tunggu..',
                        allowOutsideClick: false
                    });
                    Swal.showLoading();
                    $.post("<?=base_url()?>agen_perubahan_pangkalan_delete_upload/"+target+"/<?=$data->id_perubahan?>",{file_name:filename}).done(function (data) {
                        if (data.message == 'delete success')
                        {
                            Swal.fire({
                                text:'File berhasil dihapus!',
                                icon : 'success'
                            }).then(function () {
                                window.location.href = '<?=base_url()?>agen_view_pengajuan_perubahan_pangkalan_add/<?=$data->id_perubahan?>';
                            });
                        }
                    }).fail(function (data) {
                        Swal.fire({
                            text:'Terjadi kesalahan pada saat operasi delete!',
                            icon : 'error'
                        });
                    });
                } else if (result.isDenied) {
                    Swal.fire('Operasi dibatalkan..', '', 'info');
                }
            });
        }
        <?php
        }
        ?>
    </script>
    <script>
        $(document).ready(function () {
            var textra_query = '';
            var textra_kab = "kode_provinsi='<?=$data->provinsi?>'";
            var textra_kec = "kode_kabupaten='<?=$data->kabupaten?>'";
            var textra_kel = "kode_kecamatan='<?=$data->kecamatan?>'";

            $(".select2").select2();

            $("select[name='provinsi']").select2({
                placeholder: "Pilih Provinsi",
                ajax: {
                    url: "<?= base_url() ?>select_provinsi",
                    dataType: 'json',
                    method: 'POST',
                    data: function(params) {
                        var query = {
                            search: params.term,
                            extra_query: textra_query,
                            page: params.page || 1
                        }
                        return JSON.stringify(query);
                    }
                }
            });

            $("select[name='provinsi']").on('select2:select', function (e) {
                var data = e.params.data;
                textra_kab = "kode_provinsi='"+data.id+"'";

                $("select[name='kabupaten']").val(null).trigger('change');
                $("select[name='kecamatan']").val(null).trigger('change');
                $("select[name='kelurahan']").val(null).trigger('change');
            });

            $("select[name='kabupaten']").select2({
                placeholder: "Pilih Kabupaten",
                ajax: {
                    url: "<?= base_url() ?>select_kabupaten",
                    dataType: 'json',
                    method: 'POST',
                    data: function(params) {
                        var query = {
                            search: params.term,
                            extra_query: textra_kab,
                            page: params.page || 1
                        }
                        return JSON.stringify(query);
                    }
                }
            });

            $("select[name='kabupaten']").on('select2:select', function (e) {
                var data = e.params.data;
                textra_kec = "kode_kabupaten='"+data.id+"'";
                $("select[name='kecamatan']").val(null).trigger('change');
                $("select[name='kelurahan']").val(null).trigger('change');
            });

            $("select[name='kecamatan']").select2({
                placeholder: "Pilih Kecamatan",
                ajax: {
                    url: "<?= base_url() ?>select_kecamatan",
                    dataType: 'json',
                    method: 'POST',
                    data: function(params) {
                        var query = {
                            search: params.term,
                            extra_query: textra_kec,
                            page: params.page || 1
                        }
                        return JSON.stringify(query);
                    }
                }
            });

            $("select[name='kecamatan']").on('select2:select', function (e) {
                var data = e.params.data;
                textra_kel = "kode_kecamatan='"+data.id+"'";
                $("select[name='kelurahan']").val(null).trigger('change');
            });

            $("select[name='kelurahan']").select2({
                placeholder: "Pilih Kelurahan",
                ajax: {
                    url: "<?= base_url() ?>select_kelurahan",
                    dataType: 'json',
                    method: 'POST',
                    data: function(params) {
                        var query = {
                            search: params.term,
                            extra_query: textra_kel,
                            page: params.page || 1
                        }
                        return JSON.stringify(query);
                    }
                }
            });

            $('[data-mask]').inputmask();

            <?php
            if (($data->status=='draft') || ($data->status=='revision')){
            ?>
            $("#btn_simpan1").click(function () { $("#f1").submit(); });
            $("#btn_simpan2").click(function () { $("#f2").submit(); });
            $("#btn_simpan3").click(function () { $("#f3").submit(); });

            $("#f1").submit(function (e) {
                e.preventDefault();
                Swal.fire({
                    text: 'Menyimpan data.. Silahkan tunggu..',
                    allowOutsideClick: false
                });
                Swal.showLoading();
                var data_kirim = $("#f1").serialize();
                $(".invalid-feedback").hide();
                $.post("<?=base_url()?>agen_update_perubahan_pangkalan_pokok/<?=$data->id_perubahan?>",data_kirim).done(function (data) {
                    if (data.status == 'success')
                    {
                        Swal.fire({
                            text:'Data Pokok berhasil diupdate!',
                            icon : 'success'
                        }).then(function () {
                            window.location.href = '<?=base_url()?>agen_view_pengajuan_perubahan_pangkalan_add/<?=$data->id_perubahan?>';
                        });
                    }
                }).fail(function (data) {
                    if(data.statusText == 'input'){
                        Object.keys(data.responseJSON.messages).forEach(function(key){
                            $("#e"+key).html(data.responseJSON.messages[key]);
                            $("#e"+key).show();
                        });
                        Swal.close();
                    }else{
                        Swal.fire({
                            text:'Terjadi kesalahan pada saat penyimpanan!',
                            icon : 'error'
                        });
                    }
                });
            });

            $("#f2").submit(function (e) {
                e.preventDefault();
                Swal.fire({
                    text: 'Menyimpan data.. Silahkan tunggu..',
                    allowOutsideClick: false
                });
                Swal.showLoading();
                var data_kirim = $("#f2").serialize();
                $(".invalid-feedback").hide();
                $.post("<?=base_url()?>agen_update_perubahan_pangkalan_pemilik/<?=$data->id_perubahan?>",data_kirim).done(function (data) {
                    if (data.status == 'success'){
                        Swal.fire({
                            text:'Data Lokasi berhasil diupdate!',
                            icon : 'success'
                        }).then(function () {
                            window.location.href = '<?=base_url()?>agen_view_pengajuan_perubahan_pangkalan_add/<?=$data->id_perubahan?>';
                        });
                    }
                }).fail(function (data) {
                    if(data.statusText == 'input'){
                        Object.keys(data.responseJSON.messages).forEach(function(key){
                            $("#e"+key).html(data.responseJSON.messages[key]);
                            $("#e"+key).show();
                        });
                        Swal.close();
                    }else{
                        Swal.fire({
                            text:'Terjadi kesalahan pada saat penyimpanan!',
                            icon : 'error'
                        });
                    }
                });
            });

            $("#f3").submit(function (e) {
                e.preventDefault();
                Swal.fire({
                    text: 'Menyimpan data.. Silahkan tunggu..',
                    allowOutsideClick: false
                });
                Swal.showLoading();
                var data_kirim = $("#f3").serialize();
                $(".invalid-feedback").hide();
                $.post("<?=base_url()?>agen_update_perubahan_pangkalan_lokasi/<?=$data->id_perubahan?>",data_kirim).done(function (data) {
                    if (data.status == 'success'){
                        Swal.fire({
                            text:'Data Lokasi berhasil diupdate!',
                            icon : 'success'
                        }).then(function () {
                            window.location.href = '<?=base_url()?>agen_view_pengajuan_perubahan_pangkalan_add/<?=$data->id_perubahan?>';
                        });
                    }
                }).fail(function (data) {
                    if(data.statusText == 'input'){
                        Object.keys(data.responseJSON.messages).forEach(function(key){
                            $("#e"+key).html(data.responseJSON.messages[key]);
                            $("#e"+key).show();
                        });
                        Swal.close();
                    }else{
                        Swal.fire({
                            text:'Terjadi kesalahan pada saat penyimpanan!',
                            icon : 'error'
                        });
                    }
                });
            });
            <?php
            }
            ?>
        });
    </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
                }
                ?>

                <?php
                if (($data->status=='draft') || ($data->status=='revision')){
                ?>
                google.maps.event.addListener(map, "click", (event) => {
                    addMarker(event.latLng, map);
                    var LatLng1 = event.latLng.toUrlValue().split(",");
                    var koordinat = LatLng1[0]+","+LatLng1[1];
                });
                <?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>