<?php

  $id_um = $this->session->userdata("id_um");

  $nama_um = $this->session->userdata("nama_um");

  $kode_um = $this->session->userdata("kode_um");

?>



   



<!-- Page Heading -->

<form id="form-pka">

          <div class="d-sm-flex align-items-center justify-content-between mb-4">

            <h1 class="h3 mb-0 text-gray-800">FORM PKA <?=$pt?></h1>

            <input type="hidden" name="pt" value="<?=$pt?>">

            <!--<a href="javascript:void(0)" id="simpan_sementara" class="d-none d-sm-inline-block btn btn-sm btn-warning shadow-sm mb-4"><i class="fas fa-save fa-sm text-white-50"></i> Simpan Data Sementara</a>-->

          </div>

          <div class="row">

            <!-- Area Chart -->

            <div class="col-xl-12 col-lg-12" id="parent">

              <!-- Collapsable Card Example -->

              <div class="card shadow mb-4" id="card_1">

                <!-- Card Header - Accordion -->

                <a href="#page_1" class="d-block card-header py-3" id="page_1"  data-toggle="collapse" role="button" aria-expanded="true" aria-controls="page_1">

                  <h6 class="m-0 text-light">FORM PKA | Page #1 </h6>

                </a>

                <!-- Card Content - Collapse -->

                <div class="collapse show" id="page_1">

                  <div class="card-body">

                  <div class="row">

                    <input type="hidden" name="no_page[]" value="1">

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">Kode Mata Anggaran</label>

                      <input type="text" class="form-control" id="kma_1" name="kma[]" aria-describedby="emailHelp" placeholder="Kode Mata Anggaran" readonly>

                      <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small>

                    </div>

                    <div class="form-group  col-md-6">

                      <label for="exampleFormControlSelect1">Unit Misioner</label>

                      <input id="unitMis" type="text" class="form-control" value="<?=$nama_um?>" readonly>

                      <input type="hidden" value="<?=$id_um.','.$kode_um.','.$nama_um?>" class="form-control" id="unit_misioner_1" name="unit_misioner[]" onchange="kode_mata_anggaran(1)" required readonly>

                    </div>

                    <div class="form-group  col-md-6">

                      <label for="exampleFormControlSelect1">Jenis kegiatan</label>

                      <select class="form-control" id="jenis_kegiatan_1" name="jenis_kegiatan[]" onchange="kode_mata_anggaran(1)" required>

                      </select>

                    </div>

                    <div class="form-group  col-md-6">

                      <label for="exampleFormControlSelect1">Bidang </label>

                      <select class="form-control" id="bidang_1" name="bidang[]" onchange="kode_mata_anggaran(1)" required>

                      </select>

                    </div>

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">Nama Kegiatan</label>

                      <input type="text" class="form-control" id="nama_kegiatan_1" name="nama_kegiatan[]" aria-describedby="emailHelp" placeholder="Isi Nama Kegiatan Disini" required>

                      <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                    </div>

                    <div class="form-group  col-md-6">

                      <label for="exampleFormControlSelect1">Nomor Strategi</label>

                      <select class="form-control" id="nomor_strategi_1" name="nomor_strategi[]" required>

                      </select>

                      <small id="emailHelp" class="form-text text-muted">Taruh kursor di nomor strategi untuk melihat keterangan</small>

                      

                    </div>

                    <div class="form-group  col-md-6">

                      <label for="exampleFormControlTextarea1">Tujuan Kegiatan </label>

                      <textarea class="form-control" id="tujuan_kegiatan_1" name="tujuan_kegiatan[]" rows="3" required></textarea>

                    </div>

                    <div class="form-group  col-md-6">

                      <label for="exampleFormControlTextarea1">Lokasi Pelaksanaan Program </label>

                      <textarea class="form-control" id="lokasi_pp_1" name="lokasi_pp[]" rows="3" required></textarea>

                    </div>

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">Penanggung jawab program </label>

                      <!-- <input type="text" class="form-control" id="pen_jawab_program_1" name="pen_jawab_program[]" aria-describedby="emailHelp" placeholder="Isi Nama Kegiatan Disini" required> -->

                      <select class="form-control" id="pen_jawab_program_1" name="pen_jawab_program_1[]" required>

                      </select>

                      <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                    </div>

                    

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">Pendukung Program </label>

                      <!-- <input type="text" class="form-control" id="pendukung_program_1" name="pendukung_program_1[]" aria-describedby="emailHelp" placeholder="Isi Nama Kegiatan Disini" required> -->

                      <select class="form-control" id="pendukung_program_1" name="pendukung_program_1[]" multiple="multiple" required>

                      </select>

                      <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                    </div>

                    

                    

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">Waktu Awal Pelaksanan Program </label>

                      <input type="text" class="form-control timepicker" id="w_awal_pp_1" name="w_awal_pp[]" aria-describedby="emailHelp" placeholder="Silahkan Pilih Waktu Awal Pelaksanaan Program" required>

                      <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                    </div>

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">Waktu Akhir Pelaksanaan program</label>

                      <input type="text" class="form-control timepicker" id="w_akhir_pp_1" name="w_akhir_pp[]" aria-describedby="emailHelp" placeholder="Silahkan Pilih Waktu Akhir Pelaksanaan Program" required>

                      <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                    </div>

                    <div class="col-md-12">

                      <label for="exampleInputEmail1">Jenis Pengeluaran </label>

                        

                      <div id="insert-pengeluaran_1"></div>

                      <div class="d-sm-flex align-items-center justify-content-between mb-4">

                        <a href="javascript:void(0)" onclick="tambah_jp(1)" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm mb-4">

                            <i class="fas fa-plus fa-sm text-white-50"></i> Tambah Jenis Pengeluaran</a>

                        <input type="hidden" id="jumlah-pengeluaran_1" name="jumlah-pengeluaran_1[]" value="1" >

                      </div>

                    </div>

                    

                    <hr>

                    <div class="col-md-12">

                      <label for="exampleInputEmail1">Jenis Penerimaan </label>

                        

                      <div id="insert-penerimaan_1"></div>

                      <div class="d-sm-flex align-items-center justify-content-between mb-4">

                        <a href="javascript:void(0)" onclick="tambah_jpn(1)" class="d-none d-sm-inline-block btn btn-sm btn-info shadow-sm mb-4"><i class="fas fa-plus fa-sm text-white-50"></i> Tambah Jenis Penerimaan</a>

                        <input type="hidden" id="jumlah-penerimaan_1" name="jumlah-penerimaan_1[]" value="1">

                      </div>

                    </div>

            

                    

                    

                    

                    

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">Indikator Kuantitatif</label>

                      <input type="text" class="form-control" id="indikator_kuantitatif_1" name="indikator_kuantitatif[]" aria-describedby="emailHelp" placeholder="Isi Indikator Kuantitatif" required>

                      <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                    </div>

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">Indikator Kualitatif </label>

                      <input type="text" class="form-control" id="indikator_kuantitatif_1" name="indikator_kualitatif[]" aria-describedby="emailHelp" placeholder="Isi Indikator Kualitatif" required>

                      <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                    </div>

                    <div class="form-group  col-md-6">

                      <label for="exampleFormControlSelect1">Prioritas kegiatan</label>

                      <select class="form-control" id="prioritas_kegiatan_1" name="prioritas_kegiatan[]">

                      </select>

                    </div>

                    <div class="form-group  col-md-6">

                      <label for="exampleFormControlSelect1">Triwulan Kegiatan </label>

                      <select class="form-control" id="triwulan_1" name="triwulan_1[]" multiple="multiple" required>

                        <option value="">- Pilih Triwulan Kegiatan -</option>

                        <option value="1">Triwulan 1</option>

                        <option value="2">Triwulan 2</option>

                        <option value="3">Triwulan 3</option>

                        <option value="4">Triwulan 4</option>

                      </select>

                    </div>

                    <div class="form-group  col-md-12">

                      <label for="exampleFormControlTextarea1">Keterangan</label>

                      <textarea class="form-control" id="keterangan_1" name="keterangan[]" rows="3"></textarea>

                    </div>

                  </div>

                </div>

              </div>

            </div>

            <div id="insert_page"></div>

            <input type="hidden" id="jumlah_page" name="jumlah_page" value="1">

            

            

            <div class="modal-footer mt-2">

              <a href='javascript:void(0)' class="btn btn-primary btn-icon-split" id="btn-tambah-page">

                <span class="icon text-white-50">

                  <i class="fas fa-plus"></i>

                </span>

                <span class="text"> Tambah Kegiatan</span>

              </a>

              <!--<a href='javascript:void(0)' class="btn btn-warning btn-icon-split" id="simpan_sementara">-->

              <!--  <span class="icon text-white-50">-->

              <!--    <i class="fas fa-save"></i>-->

              <!--  </span>-->

              <!--  <span class="text"> Simpan Data Sementara</span>-->

              <!--</a>-->

              

              <button type="submit" name="simpan"  class="btn btn-warning btn-icon-split">

                <span class="icon text-white-50">

                  <i class="fas fa-file-export"></i>

                </span>

                <span class="text"> Simpan Data Sementara</span>

              </button>

              

              

              <button type="submit" id="btn-insert" name="submit"  class="btn btn-success btn-icon-split">

                <span class="icon text-white-50">

                  <i class="fas fa-file-export"></i>

                </span>

                <span class="text"> Submit Data</span>

              </button>

            </div>

          </div>

</form>

<script type="text/javascript">

  $(document).ready(function(){

    var base_url = "<?=base_url()?>";

    var kode_unit_misioner = "<?=$this->session->userdata("kode_um")?>";

    var nama_unit_misioner = "<?=$this->session->userdata("nama_um")?>";

    var time = function(){

      // var options = { 

      //   // now: "12:35", //hh:mm 24 hour format only, defaults to current time

      //   twentyFour: true, //Display 24 hour format, defaults to false

      //   // upArrow: 'wickedpicker__controls__control-up', //The up arrow class selector to use, for custom CSS

      //   // downArrow: 'wickedpicker__controls__control-down', //The down arrow class selector to use, for custom CSS

      //   // close: 'wickedpicker__close', //The close class selector to use, for custom CSS

      //   // hoverState: 'hover-state', //The hover state class to use, for custom CSS

      //   title: 'Ganti Waktu', //The Wickedpicker's title,

      //   showSeconds: true, //Whether or not to show seconds,

      //   secondsInterval: 15, //Change interval for seconds, defaults to 1

      //   minutesInterval: 10, //Change interval for minutes, defaults to 1

      //   // beforeShow: null, //A function to be called before the Wickedpicker is shown

      //   // show: null, //A function to be called when the Wickedpicker is shown

      //   // clearable: true, //Make the picker's input clearable (has clickable "x")

      // }; 

      // $('.timepicker').wickedpicker(options); 

      $('.timepicker').datepicker({

          format: 'dd MM yyyy',

          todayHighlight:true,

          toggleActive:true,

          autoclose:true,

          language:'id'

      });

    }

    time();

    

    

    /////////////////////////////////////////////////

    unit_misioner = function(param){

      jQuery.ajax({

        url: base_url+"unit_misioner/data_unit_misioner",

        dataType:'json',

        success:function(response){

          var data = response;

          var $id = $('#'+param);

          $id.empty();

          $id.append('<option value="">- Pilih Unit Misioner -</option>');

          for (var i = 0; i < data.length; i++) {

            $id.append('<option value="'+data[i].id_unit_misioner+','+data[i].kode+',' + data[i].nama + '">' + data[i].nama + '</option>');

          }        

        }            

      });

    }

    unit_misioner('unit_misioner_1');

    ////////////////////////////////////////////////

    ///////////////////////////////////////////////

    jenis_kegiatan = function(param){

      jQuery.ajax({

        url: base_url+"Jenis_kegiatan/data_jenis_kegiatan",

        dataType:'json',

        success:function(response){

          var data = response;

          var $id = $('#'+param);

          $id.empty();

          // $id.append('<option value=0>- Pilih Jenis Kegiatan -</option>');

          for (var i = 0; i < data.length; i++) {

            $id.append('<option value="'+data[i].id_jenis_kegiatan+','+data[i].kode+'">' + data[i].nama + '</option>');

          }        

        }            

      });

    }

    jenis_kegiatan('jenis_kegiatan_1');

    /////////////////////////////////////////////////

    ////////////////////////////////////////////////

    bidang = function(param){

      jQuery.ajax({

        url: base_url+"Bidang/data_bidang",

        dataType:'json',

        success:function(response){

          var data = response;

          var $id = $('#'+param);

          $id.empty();

          $id.append('<option value="">- Pilih Bidang -</option>');

          for (var i = 0; i < data.length; i++) {

            $id.append('<option value="'+data[i].id_bidang+','+data[i].kode+'">' + data[i].nama + '</option>');

          }        

        }            

      });

    }

    bidang('bidang_1');

    ///////////////////////////////////////////////

    //////////////////////////////////////////////

    prioritas_kegiatan = function(param){

      jQuery.ajax({

        url: base_url+"Prioritas_kegiatan/data_Prioritas_kegiatan",

        dataType:'json',

        success:function(response){

          var data = response;

          var $id = $('#'+param);

          $id.empty();

          $id.append('<option value=0>- Pilih Prioritas Kegiatan -</option>');

          for (var i = 0; i < data.length; i++) {

            $id.append('<option value="'+data[i].id_prioritas_kegiatan+'">' + data[i].nama + '</option>');

          }        

        }            

      });

    }

    prioritas_kegiatan('prioritas_kegiatan_1');

    //////////////////////////////////////////////

    nomor_strategi = function(param){

      jQuery.ajax({

        url: base_url+"Strategi/data_strategi",

        dataType:'json',

        success:function(response){

          var data = response;

          var $id = $('#'+param);

          $id.empty();

          $id.append('<option value=0>- Pilih Nomor Strategi -</option>');

          for (var i = 0; i < data.length; i++) {

            $id.append('<option value="'+data[i].id_strategi+'" data-toggle="tooltip" data-html="true" title="' + data[i].keterangan + '">('+data[i].head+') ' + data[i].kode_strategi + '</option>');

          }        

        }            

      });

    }

    

    $(function () {

      $('[data-toggle="tooltip"]').tooltip()

    })

    

    nomor_strategi('nomor_strategi_1');

    //////////////////////////////////////

    prioritas_kegiatan('prioritas_kegiatan_1');

    //////////////////////////////////////////////

    pnp = function(param){

      jQuery.ajax({

        url: base_url+"unit_misioner/data_unit_misioner",

        dataType:'json',

        success:function(response){

          var data = response;

          var $id = $('#'+param);

          $id.empty();

          $id.append('<option value=0>- Pilih Penanggung Jawab Program -</option>');

          for (var i = 0; i < data.length; i++) {

            $id.append('<option value="'+data[i].nama+'" title="'+data[i].keterangan+'">' + data[i].nama + '</option>');

          }        

        }            

      });

    }

    pnp('pen_jawab_program_1');

    pp = function(param){

      jQuery.ajax({

        url: base_url+"unit_misioner/data_unit_misioner",

        dataType:'json',

        success:function(response){

          var data = response;

          var $id = $('#'+param);

          $id.empty();

          $id.append('<option value=0>- Pilih Pendukung Program -</option>');

          for (var i = 0; i < data.length; i++) {

            $id.append('<option value="'+data[i].nama+'" title="'+data[i].keterangan+'">' + data[i].nama + '</option>');

          }        

        }            

      });

    }

    pp('pendukung_program_1');

    

    //////////////////////////////////////

    $( "#page_1" ).css( "background-color", "#"+randomColor());

    $( "#card_jp_1" ).css( "border-left","5px solid #"+randomColor());

    $("#btn-tambah-page").click(function(){

      var jumlah = parseInt($("#jumlah_page").val()); // Ambil jumlah data form pada textbox jumlah-form      

      var nextform = jumlah + 1; // Tambah 1 untuk jumlah form nya

      $("#insert_page").append(`

              <div class="card shadow mb-4" id="card_`+nextform+`">

                <!-- Card Header - Accordion -->

                <a href="#page_`+nextform+`" class="d-block card-header py-3" style="background-color: #`+randomColor()+`;" data-toggle="collapse" role="button" aria-expanded="true" aria-controls="page_`+nextform+`">

                  <h6 class="m-0 text-light">FORM PKA | Page #`+nextform+`</h6>

                </a>

                <!-- Card Content - Collapse -->

                <div class="collapse show" id="page_`+nextform+`">

                  <div class="card-body">

                  <div class="row">

                  <input type="hidden" name="no_page[]" value="`+ nextform +`">

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">1. Kode Mata Anggaran</label>

                      <input type="text" class="form-control" id="kma_`+ nextform +`" name="kma[]" aria-describedby="emailHelp" placeholder="Kode Mata Anggaran" readonly>

                      <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small>

                    </div>

                    <div class="form-group  col-md-6">

                      <label for="exampleFormControlSelect1">Unit Misioner</label>

                      <input type="text" class="form-control" value="<?=$nama_um?>" readonly>

                      <input type="hidden" value="<?=$id_um.','.$kode_um.','.$nama_um?>" class="form-control" id="unit_misioner_`+ nextform +`" name="unit_misioner[]" onchange="kode_mata_anggaran(`+ nextform +`)" required>

                    </div>

                    <div class="form-group  col-md-6"

                      <label for="exampleFormControlSelect1">Jenis kegiatan</label>

                      <select class="form-control" id="jenis_kegiatan_`+ nextform +`" name="jenis_kegiatan[]" onchange="kode_mata_anggaran(`+ nextform +`)" required>

                      </select>

                    </div>

                    <div class="form-group  col-md-6">

                      <label for="exampleFormControlSelect1">Bidang </label>

                      <select class="form-control" id="bidang_`+ nextform +`" name="bidang[]" onchange="kode_mata_anggaran(`+ nextform +`)" required>

                      </select>

                    </div>

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">Nama Kegiatan</label>

                      <input type="text" class="form-control" id="nama_kegiatan" name="nama_kegiatan[]" aria-describedby="emailHelp" placeholder="Isi Nama Kegiatan Disini" required>

                      <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                    </div>

                    <div class="form-group  col-md-6">

                      <label for="exampleFormControlSelect1">Nomor Strategi</label>

                      <select class="form-control" id="nomor_strategi_`+ nextform +`" name="nomor_strategi[] " required>

                      </select>

                      <small id="emailHelp" class="form-text text-muted">Taruh kursor di nomor strategi untuk melihat keterangan.</small>

                    </div>

                    <div class="form-group  col-md-6">

                      <label for="exampleFormControlTextarea1">Tujuan Kegiatan </label>

                      <textarea class="form-control" id="tujuan_kegiatan_`+ nextform +`" name="tujuan_kegiatan[]" rows="3" required></textarea>

                    </div>

                    <div class="form-group  col-md-6">

                      <label for="exampleFormControlTextarea1">Lokasi Pelaksanaan Program </label>

                      <textarea class="form-control" id="lokasi_pp_`+ nextform +`" name="lokasi_pp[]" rows="3" required></textarea>

                    </div>

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">Penanggung jawab program </label>

                       <select class="form-control" id="pen_jawab_program_`+ nextform +`" name="pen_jawab_program_`+ nextform +`[]"  required>

                      </select>

                      <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                    </div>

                    

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">Pendukung Program </label>

                      <select class="form-control" id="pendukung_program_`+ nextform +`" name="pendukung_program_`+ nextform +`[]" multiple="multiple" required>

                      </select>

                      <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                    </div>

                    

                    

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">Waktu Awal Pelaksanan Program </label>

                      <input type="text" class="form-control timepicker" id="w_awal_pp_`+ nextform +`" name="w_awal_pp[]" aria-describedby="emailHelp" placeholder="Silahkan Pilih Waktu Awal Pelaksanaan Program" required>

                      <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                    </div>

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">Waktu Akhir Pelaksanaan program</label>

                      <input type="text" class="form-control timepicker" id="w_akhir_pp_`+ nextform +`" name="w_akhir_pp[]" aria-describedby="emailHelp" placeholder="Silahkan Pilih Waktu Akhir Pelaksanaan Program" required>

                      <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                    </div>

                    

                    

                    <div class="col-md-12">

                      <label for="exampleInputEmail1">Jenis pengeluaran </label>

                        

                      <div id="insert-pengeluaran_`+ nextform +`"></div>

                      <div class="d-sm-flex align-items-center justify-content-between mb-4">

                        <a href="javascript:void(0)" onclick="tambah_jp(`+ nextform +`)" class="d-none d-sm-inline-block btn btn-sm btn-info shadow-sm mb-4"><i class="fas fa-plus fa-sm text-white-50"></i> Tambah Jenis Pengeluaran</a>

                        <input type="hidden" id="jumlah-pengeluaran_`+ nextform +`" name="jumlah-pengeluaran_`+ nextform +`[]" value="1">

                      </div>

                    </div>

                    

                    <hr>

                    <div class="col-md-12">

                      <label for="exampleInputEmail1">Jenis Penerimaan </label>

                        

                      <div id="insert-penerimaan_`+ nextform +`"></div>

                      <div class="d-sm-flex align-items-center justify-content-between mb-4">

                        <a href="javascript:void(0)" onclick="tambah_jpn(`+ nextform +`)" class="d-none d-sm-inline-block btn btn-sm btn-info shadow-sm mb-4"><i class="fas fa-plus fa-sm text-white-50"></i> Tambah Jenis Penerimaan</a>

                        <input type="hidden" id="jumlah-penerimaan_`+ nextform +`" name="jumlah-penerimaan_`+ nextform +`[]" value="1">

                      </div>

                    </div>

                    

                    

                    

                    

                    

                    

                    

                    

                    

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">Indikator Kuantitatif</label>

                      <input type="text" class="form-control" id="indikator_kuantitatif_`+ nextform +`" name="indikator_kuantitatif[]" aria-describedby="emailHelp" placeholder="Isi Indikator Kuantitatif" required>

                      <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                    </div>

                    <div class="form-group col-md-6">

                      <label for="exampleInputEmail1">Indikator Kualitatif </label>

                      <input type="text" class="form-control" id="indikator_kualitatif_`+ nextform +`" name="indikator_kualitatif[]" aria-describedby="emailHelp" placeholder="Isi Indikator Kualitatif" required>

                      <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                    </div>

                    <div class="form-group  col-md-6">

                      <label for="exampleFormControlSelect1">Prioritas kegiatan</label>

                      <select class="form-control" id="prioritas_kegiatan_`+ nextform +`" name="prioritas_kegiatan[]">

                      </select>

                    </div>

                    <div class="form-group  col-md-6">

                      <label for="exampleFormControlSelect1">Triwulan Kegiatan </label>

                      <select class="form-control" id="triwulan_`+ nextform +`" name="triwulan_`+ nextform +`[]" multiple="multiple" required>

                        <option value="">- Pilih Triwulan Kegiatan -</option>

                        <option value="1">Triwulan 1</option>

                        <option value="2">Triwulan 2</option>

                        <option value="3">Triwulan 3</option>

                        <option value="4">Triwulan 4</option>

                      </select>

                    </div>

                    <div class="form-group  col-md-12">

                      <label for="exampleFormControlTextarea1">Keterangan</label>

                      <textarea class="form-control" id="keterangan_`+ nextform +`" name="keterangan[]" rows="3"></textarea>

                    </div>

                  </div>

                  <a href="javascript:void(0)" onclick="remove(`+ nextform +`)" class="d-none d-sm-inline-block btn btn-sm btn-danger shadow-sm mb-4"><i class="fa fa-trush fa-sm text-white-50"></i>Remove</a>

                </div>

              </div>

            </div>

                `);

      time();

      $("#jumlah_page").val(nextform);

      unit_misioner("unit_misioner_"+nextform);

      jenis_kegiatan("jenis_kegiatan_"+nextform);

      bidang("bidang_"+nextform);

      nomor_strategi("nomor_strategi_"+nextform);

      prioritas_kegiatan("prioritas_kegiatan_"+nextform);

      triwulan(nextform);

      pnp('pen_jawab_program_'+nextform);

      pen_jawab_program(nextform)

      pp('pendukung_program_'+nextform);

      pendukung_program(nextform)

      

                // sebagai("seb_"+nextform+"_1");

    });

    remove = function(param){

      var p = document.getElementById('insert_page');

      var e = document.getElementById('card_'+param);

      p.removeChild(e);//menghapus elemen child dengan id error bila kita menginput nama

    }

    //tambah petugas

    tambah_jp = function(param){

      var jumlah = parseInt($("#jumlah-pengeluaran_"+param).val()); // Ambil jumlah data form pada textbox jumlah-form      

      var nextpengeluaran = jumlah + 1; // Tambah 1 untuk jumlah form nya

      $("#insert-pengeluaran_"+param).append(`

        <div class="card  shadow mb-2"  id="peng_`+ param +`_`+ nextpengeluaran +`" style="border-left: 5px solid #`+randomColor()+`">

                        <div class="card-body">

                          <div class="row">

                            <div class="form-group col-md-4">

                              <label for="exampleInputEmail1">Jenis Pengeluaran </label>

                              <input type="text" class="form-control" id="jp_`+ param +`_`+ nextpengeluaran +`" onkeyup="jp_up('`+ param +`_`+ nextpengeluaran +`')" name="jp_`+ param +`[]" aria-describedby="emailHelp" placeholder=" Jenis Pengeluaran" required>

                              <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                            </div>

                            <div class="form-group col-md-4">

                              <label for="exampleInputEmail1">Jumlah Satuan  </label>

                              <input type="text" class="form-control" value="0" id="js_`+ param +`_`+ nextpengeluaran +`" onkeyup="js_up('`+ param +`_`+ nextpengeluaran +`')" name="js_`+ param +`[]" placeholder="Jumlah Satuan" required>

                              <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                            </div>

                            <div class="form-group col-md-4">

                              <label for="exampleInputEmail1">Bulanan</label>

                              <input type="text" class="form-control" value="0" id="bl_`+ param +`_`+ nextpengeluaran +`" onkeyup="bl_up('`+ param +`_`+ nextpengeluaran +`')" name="bl_`+ param +`[]" placeholder="Bulanan" required>

                              <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                            </div>

                            <div class="form-group col-md-4">

                              <label for="exampleInputEmail1">Tahunan</label>

                              <input type="text" class="form-control" value="0" id="th_`+ param +`_`+ nextpengeluaran +`" onkeyup="th_up('`+ param +`_`+ nextpengeluaran +`')" name="th_`+ param +`[]" placeholder="Tahunan" required>

                              <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                            </div>

                            <div class="form-group col-md-4">

                              <label for="exampleInputEmail1">Nilai Satuan </label>

                              <div class="input-group mb-3">

                                <div class="input-group-prepend">

                                  <span class="input-group-text" id="basic-addon1">Rp.</span>

                                </div>

                                <input type="text" class="form-control" id="ns_`+ param +`_`+ nextpengeluaran +`" name="ns_`+ param +`[]" onkeyup="ns_up('`+ param +`_`+ nextpengeluaran +`')"  placeholder="Nilai Satuan (Tidak pakai koma dan titik)" aria-label="Nilai Satuan" aria-describedby="basic-addon1" required>

                              </div>

                              <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                            </div>

                            <div class="form-group col-md-4">

                              <label for="exampleInputEmail1">Pengeluaran</label>

                              <div class="input-group mb-3">

                                <div class="input-group-prepend">

                                  <span class="input-group-text" id="basic-addon1">Rp.</span>

                                </div>

                                <input type="text" class="form-control" value="0" id="pn_`+ param +`_`+ nextpengeluaran +`" name="pn_`+ param +`[]" onkeyup="formatRp('pn_`+ param +`_`+ nextpengeluaran +`')" placeholder="Pengeluaran" aria-label="Pengeluaran" aria-describedby="basic-addon1" readonly required>

                              </div>

                              <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                            </div>

                          </div>

                          <a href="javascript:void(0)" onclick="remove_pengeluaran('`+ param +`','`+ nextpengeluaran +`')" class="d-none d-sm-inline-block btn btn-sm btn-danger shadow-sm mb-4"><i class="fas fa-plus fa-sm text-white-50"></i>Remove Pengeluaran</a>

                        </div>

                      </div>

      `);

      $("#jumlah-pengeluaran_"+param).val(nextpengeluaran);

    }

    tambah_jpn = function(param){

      var jumlah = parseInt($("#jumlah-penerimaan_"+param).val()); // Ambil jumlah data form pada textbox jumlah-form      

      var nextpenerimaan = jumlah + 1; // Tambah 1 untuk jumlah form nya

      $("#insert-penerimaan_"+param).append(`

        <div class="card shadow mb-2"  id="pen_`+ param +`_`+ nextpenerimaan +`" style="border-left: 5px solid #`+randomColor()+`">

                        <div class="card-body">

                          <div class="row">

                            <div class="form-group col-md-4">

                              <label for="exampleInputEmail1">Jenis Penerimaan </label>

                              <input type="text" class="form-control" id="jpn_`+ param +`" name="jpn_`+ param +`[]" aria-describedby="emailHelp" placeholder=" Jenis Penerimaan" required>

                              <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                            </div>

                            <div class="form-group col-md-4">

                              <label for="exampleInputEmail1">Jumlah Satuan  </label>

                              <input type="text" class="form-control" id="jspn_`+ param +`_`+ nextpenerimaan +`" onkeyup="jspn_up('`+ param +`_`+ nextpenerimaan +`')" name="jspn_`+ param +`[]" placeholder="Jumlah Satuan" required>

                              <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                            </div>

                            <div class="form-group col-md-4">

                              <label for="exampleInputEmail1">Bulanan</label>

                              <input type="text" class="form-control" id="blpn_`+ param +`_`+ nextpenerimaan +`" onkeyup="blpn_up('`+ param +`_`+ nextpenerimaan +`')"  name="blpn_`+ param +`[]" placeholder="Bulanan" required>

                              <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                            </div>

                            <div class="form-group col-md-4">

                              <label for="exampleInputEmail1">Tahunan</label>

                              <input type="text" class="form-control" id="thpn_`+ param +`_`+ nextpenerimaan +`" onkeyup="thpn_up('`+ param +`_`+ nextpenerimaan +`')" name="thpn_`+ param +`[]" placeholder="Tahunan" required>

                              <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                            </div>

                            <div class="form-group col-md-4">

                              <label for="exampleInputEmail1">Nilai Satuan </label>

                              <div class="input-group mb-3">

                                <div class="input-group-prepend">

                                  <span class="input-group-text" id="basic-addon1">Rp.</span>

                                </div>

                                <input type="text" class="form-control" id="nspn_`+ param +`_`+ nextpenerimaan +`" onkeyup="nspn_up('`+ param +`_`+ nextpenerimaan +`')" name="nspn_`+ param +`[]" onkeyup="formatRp('nspn_`+ param +`_`+ nextpenerimaan +`')"  placeholder="Nilai Satuan(Tidak pakai koma dan titik)" aria-label="Nilai Satuan" aria-describedby="basic-addon1" required>

                              </div>

                              <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                            </div>

                            <div class="form-group col-md-4">

                              <label for="exampleInputEmail1">Penerimaan</label>

                              <div class="input-group mb-3">

                                <div class="input-group-prepend">

                                  <span class="input-group-text" id="basic-addon1">Rp.</span>

                                </div>

                                <input type="text" class="form-control" value="0" id="pnpn_`+ param +`_`+ nextpenerimaan +`" name="pnpn_`+ param +`[]" onkeyup="formatRp('pnpn_`+ param +`_`+ nextpenerimaan +`')" placeholder="Penerimaan" aria-label="Penerimaan" aria-describedby="basic-addon1" readonly>

                              </div>

                              <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->

                            </div>

                          </div>

                          <a href="javascript:void(0)" onclick="remove_penerimaan('`+ param +`','`+ nextpenerimaan +`')" class="d-none d-sm-inline-block btn btn-sm btn-danger shadow-sm mb-4"><i class="fas fa-plus fa-sm text-white-50"></i>Remove Penerimaan</a>

                        </div>

                      </div>

      `);

      $("#jumlah-penerimaan_"+param).val(nextpenerimaan);

    }

    kode_mata_anggaran = function(param){

      var bid = $("#bidang_"+param).val();

      // var unit = $("#unit_misioner_"+param).val();

      var jkp = $("#jenis_kegiatan_"+param).val();

      if(bid == "" ){

        var bidang = "xx";

      }else{

        var bidang = bid.split(",")[1];

      }

      // if(unit == "" ){

      //   var unit_misioner = "xx";

      // }else{

      //   var unit_misioner = unit.split(",")[1];

      // }

      if(jkp == 0 ){

        var jenis_kegiatan = "x";

      }else{

        var jenis_kegiatan = jkp.split(",")[1];

      }

      var jum_param = String(param);

      if(jum_param.length ==1){

        var jadi_param = "00"+param;

      }else if(jum_param.length == 2){

        var jadi_param = "0"+param;

      }else{

        var jadi_param = param;

      }

      $("#kma_"+param).val(bidang+"-"+kode_unit_misioner+"-"+jenis_kegiatan+"-"+jadi_param+"-<?=date("y")?>");

      // $("#kma_"+param).val(bidang);

    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    

    $(function() {

     var buttonpressed;

     $(' #form-pka button[type=submit]').click(function() {

          buttonpressed = $(this).attr('name')

     })

     $('#form-pka').submit(function() {

        var form_data = new FormData($('#form-pka')[0]);

        if(buttonpressed == 'simpan'){

             var locale = {

              OK: 'I Suppose',

              CONFIRM: 'Simpan',

              CANCEL: 'Batal'

          };

                      

          bootbox.addLocale('custom', locale);

                      

          bootbox.prompt({ 

            title: "Masukan Nama File", 

            locale: 'custom',

            callback: function (value) {

                  // console.log('This was logged in the callback: ' + result);

            if (value == null) {

            }else if (value == ""){

              swal({

                title: `Nama Belum Diisi`,

                icon: "info"

              });

            }else{

                  $.ajax({

                    url             : base_url + 'Save_pka/insert_save_pka/'+value, 

                    type            : "POST",

                    dataType        : 'json',

                    mimeType        : 'multipart/form-data',

                    data            : form_data,

                    contentType     : false,

                    cache           : false,

                    processData     : false,

                    success         : function(response){

                      // swal.close();

                        if(response == true){

                            // $('#'+id_modal).modal('hide'); 

                            Command: toastr["success"]("Data Berhasil Disimpan Sementara", "Berhasil");
                            
                            SendWaNotif();

                            getcontens('page/data_pka');

                        }else{

                            Command: toastr["error"]("Simpan error, data tidak berhasil disimpan", "Error");

                        }

                    },

                    error: function(jqXHR, textStatus, errorThrown) {

                      $('#loading').modal('show');

                            Command: toastr["error"](errorThrown, "Error");

                    },

                    beforeSend: function () {

                      $('#loading').modal('show');

                    },

                    complete: function () {

                        $('#loading').modal('hide');

                    }

              });

            }

            }

          });

        }else{

            bootbox.confirm("Apakah Anda Yakin Akan Mengirim Data?", function(result){ 

                if (result==true) {

                  $.ajax({

                        url             : base_url + 'pka/insert_pka', 

                        type            : "POST",

                        dataType        : 'json',

                        mimeType        : 'multipart/form-data',

                        data            : form_data,

                        contentType     : false,

                        cache           : false,

                        processData     : false,

                        success         : function(response){

                          // swal.close();

                            if(response == true){

                                // $('#'+id_modal).modal('hide');  

                                // swal.close();

                                Command: toastr["success"]("Data Berhasil Dikirim", "Berhasil");
                                
                                SendWaNotif();

                                getcontens('page/data_pka')

                            }else{

                                Command: toastr["error"]("Simpan error, data tidak berhasil disimpan", "Error");

                            }

                        },

                        error: function(jqXHR, textStatus, errorThrown) {

                          $('#loading').modal('show');

                                Command: toastr["error"](errorThrown, "Error");

                        },

                        beforeSend: function () {

                          $('#loading').modal('show');

                        },

                        complete: function () {

                            $('#loading').modal('hide');

                        }

                  });

                }

              });

        }

        return(false)

     })

    })

    
    function SendWaNotif()
    {
        $.ajax({
          type: "POST",
          url: base_url + "Pka/SendWaAfterNotif", // the URL of the controller action method
          data: null, // optional data
          success: function(result) {
                // do something with result
                console.log('send wa success.');
          },                
          error : function(req, status, error) {
                // do something with error  
                console.log('send wa filed.');
          }
      });
    }

    

        

        // $("#form-pka").submit(function(){

        //       var form_data = new FormData($('#form-pka')[0]);

            

                  

        //         return false;

        //   });

    

    $("#simpan_sementara").click(function(){

      var form_data = new FormData($('#form-pka')[0]);

     

          

          return false;

      });

    remove_pengeluaran = function(param1,param2){

      $('#peng_'+param1+'_'+param2).remove();

    }

    remove_penerimaan = function(param1,param2){

      $('#pen_'+param1+'_'+param2).remove();

    }

    formatRp = function(bbb){

      var ggg = $("#"+bbb).val(); 

      $("#"+bbb).val(formatRupiah(ggg, ''));

    }

    js_up = function(no){

      var angka = $("#js_"+no).val(); 

      $("#js_"+no).val(formatRupiah(angka, ''));

      var js = $("#js_"+no).val();

      var bl = $("#bl_"+no).val();

      var th = $("#th_"+no).val();

      var ns = $("#ns_"+no).val();

      var tot = js.replace(/[^\w\s]/gi, '')*bl.replace(/[^\w\s]/gi, '')*th.replace(/[^\w\s]/gi, '')*ns.replace(/[^\w\s]/gi, '');

      $("#pn_"+no).val(formatRupiah(String(tot),''))

    }

    bl_up = function(no){

      var angka = $("#bl_"+no).val(); 

      $("#bl_"+no).val(formatRupiah(angka, ''));

      var js = $("#js_"+no).val();

      var bl = $("#bl_"+no).val();

      var th = $("#th_"+no).val();

      var ns = $("#ns_"+no).val();

      var tot = js.replace(/[^\w\s]/gi, '')*bl.replace(/[^\w\s]/gi, '')*th.replace(/[^\w\s]/gi, '')*ns.replace(/[^\w\s]/gi, '');

      $("#pn_"+no).val(formatRupiah(String(tot),''))

    }

    th_up = function(no){

      var angka = $("#th_"+no).val(); 

      $("#th_"+no).val(formatRupiah(angka, ''));

      var js = $("#js_"+no).val();

      var bl = $("#bl_"+no).val();

      var th = $("#th_"+no).val();

      var ns = $("#ns_"+no).val();

      var tot = js.replace(/[^\w\s]/gi, '')*bl.replace(/[^\w\s]/gi, '')*th.replace(/[^\w\s]/gi, '')*ns.replace(/[^\w\s]/gi, '');

      $("#pn_"+no).val(formatRupiah(String(tot),''))

    }

    ns_up = function(no){

      var angka = $("#ns_"+no).val(); 

      $("#ns_"+no).val(formatRupiah(angka, ''));

      var js = $("#js_"+no).val();

      var bl = $("#bl_"+no).val();

      var th = $("#th_"+no).val();

      var ns = $("#ns_"+no).val();

      var tot = js.replace(/[^\w\s]/gi, '')*bl.replace(/[^\w\s]/gi, '')*th.replace(/[^\w\s]/gi, '')*ns.replace(/[^\w\s]/gi, '');

      $("#pn_"+no).val(formatRupiah(String(tot),''))

    }

    jspn_up = function(no){

      var angka = $("#jspn_"+no).val(); 

      $("#jspn_"+no).val(formatRupiah(angka, ''));

      var jspn = $("#jspn_"+no).val();

      var blpn = $("#blpn_"+no).val();

      var thpn = $("#thpn_"+no).val();

      var nspn = $("#nspn_"+no).val();

      var tot = jspn.replace(/[^\w\s]/gi, '')*blpn.replace(/[^\w\s]/gi, '')*thpn.replace(/[^\w\s]/gi, '')*nspn.replace(/[^\w\s]/gi, '');

      $("#pnpn_"+no).val(formatRupiah(String(tot),''))

    }

    blpn_up = function(no){

      var angka = $("#blpn_"+no).val(); 

      $("#blpn_"+no).val(formatRupiah(angka, ''));

      var jspn = $("#jspn_"+no).val();

      var blpn = $("#blpn_"+no).val();

      var thpn = $("#thpn_"+no).val();

      var nspn = $("#nspn_"+no).val();

      var tot = jspn.replace(/[^\w\s]/gi, '')*blpn.replace(/[^\w\s]/gi, '')*thpn.replace(/[^\w\s]/gi, '')*nspn.replace(/[^\w\s]/gi, '');

      $("#pnpn_"+no).val(formatRupiah(String(tot),''))

    }

    thpn_up = function(no){

      var angka = $("#thpn_"+no).val(); 

      $("#thpn_"+no).val(formatRupiah(angka, ''));

      var jspn = $("#jspn_"+no).val();

      var blpn = $("#blpn_"+no).val();

      var thpn = $("#thpn_"+no).val();

      var nspn = $("#nspn_"+no).val();

      var tot = jspn.replace(/[^\w\s]/gi, '')*blpn.replace(/[^\w\s]/gi, '')*thpn.replace(/[^\w\s]/gi, '')*nspn.replace(/[^\w\s]/gi, '');

      $("#pnpn_"+no).val(formatRupiah(String(tot),''))

    }

    nspn_up = function(no){

      var angka = $("#nspn_"+no).val(); 

      $("#nspn_"+no).val(formatRupiah(angka, ''));

      var jspn = $("#jspn_"+no).val();

      var blpn = $("#blpn_"+no).val();

      var thpn = $("#thpn_"+no).val();

      var nspn = $("#nspn_"+no).val();

      var tot = jspn.replace(/[^\w\s]/gi, '')*blpn.replace(/[^\w\s]/gi, '')*thpn.replace(/[^\w\s]/gi, '')*nspn.replace(/[^\w\s]/gi, '');

      $("#pnpn_"+no).val(formatRupiah(String(tot),''))

    }

    triwulan = function(no_page){

      $("#triwulan_"+no_page).select2({

        placeholder: "Silahkan Pilih Triwulan"

      });

    }

    triwulan("1");

    pen_jawab_program = function(no_page){

      $("#pen_jawab_program_"+no_page).select2({

        placeholder: " Silahkan Pilih Penanggung Jawab Program"

      });

    }

    pen_jawab_program("1");

    pendukung_program = function(no_page){

      $("#pendukung_program_"+no_page).select2({

        placeholder: " Silahkan Pilih Pendukung Program"

      });

    }

    pendukung_program("1");

    /* Fungsi */

    function formatRupiah(angka, prefix)

    {

        var number_string = angka.replace(/[^,\d]/g, '').toString(),

            split    = number_string.split(','),

            sisa     = split[0].length % 3,

            rupiah     = split[0].substr(0, sisa),

            ribuan     = split[0].substr(sisa).match(/\d{3}/gi);

            

        if (ribuan) {

            separator = sisa ? '.' : '';

            rupiah += separator + ribuan.join('.');

        }

        

        rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;

        return prefix == undefined ? rupiah : (rupiah ? '' + rupiah : '');

    }

    

    

    

    

    

    $.extend({

    xResponse: function(url, data) {

        // local var

        var theResponse = null;

        // jQuery ajax

        $.ajax({

            url: url,

            type: 'POST',

            data: data,

            dataType: "html",

            async: false,

            success: function(respText) {

                theResponse = respText;

            }

        });

        // Return the response text

        return theResponse;

    }

});

    

    

    

    

  });

</script>

