<form class="form-horizontal" method="post" id="formUjiSampel">
<div class="row">
  <!-- begin col-8 -->
  <div class="col-lg-12">
      <!-- begin panel -->
      <div class="panel panel-grey">
          <div class="panel-heading">
            <a href="#" onclick="goBack()" class="btn btn-primary m-b-5"><span class="fa fa-arrow-left"></span> Kembali</a>
          </div>
          <div class="panel-body">

            <div class="bg-default">

                <input type='hidden' name='id_uji_hidden' <?php echo !empty($edit) ? "value='".$edit['id_uji']."'": ""; ?>>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Jenis Layanan<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <select name="id_jenis_layanan" onchange="regLab(this.value);" class="form-control default-select2" required>
                            <option readonly></option>
                            <?php foreach ($jenis_layanan as $r) { ?>
                                <option value="<?php echo $r['singkatan'] ?>" <?php echo !empty($edit) && $r['singkatan'] === $edit['singkatan_layanan'] ? 'selected' : '' ?>><?php echo $r['nama_jenis'] ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Registrasi Laboratorium<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <input class="form-control" name="registrasi_laboratorium" <?php echo !empty($edit) ? "value='".$edit['registrasi_laboratorium']."'": ""; ?> id="registrasi_laboratorium" type="text" placeholder="Masukkan Registrasi Laboratorium" required readonly>
                    </div>
                </div>
                <div class="form-group m-b-12 tgl_ambil">
                    <label class="col-md-3 col-form-label control-label">Tanggal Pukul Pengambilan<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <input class="form-control datepicker-default tgl_pukul_pengambilan2" autocomplete="false" name="tgl_pukul_pengambilan" <?php echo !empty($edit) ? "value='".date('m/d/Y', strtotime($edit['tgl_pukul_pengambilan']))."'": ""; ?> id="tgl_pukul_pengambilan" type="text" placeholder="Masukkan Tanggal Pukul Pengambilan">
                        
                        <input class="form-control datetimepicker1 tgl_pukul_pengambilan" autocomplete="false" name="tgl_pukul_pengambilan" <?php echo !empty($edit) ? "value='".date('m/d/Y h:i A', strtotime($edit['tgl_pukul_pengambilan']))."'": ""; ?> id="tgl_pukul_pengambilan" type="text" placeholder="Masukkan Tanggal Pukul Pengambilan">

                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Tanggal Pukul Registrasi<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <input class="form-control tgl_pukul_registrasi datetimepicker1" autocomplete="false" name="tgl_pukul_registrasi" <?php echo !empty($edit) ? "value='".date('m/d/Y h:i A', strtotime($edit['tgl_pukul_registrasi']))."'": ""; ?> id="tgl_pukul_registrasi" type="text" placeholder="Masukkan Tanggal Pukul Registrasi" required>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Perkiraan Estimasi Selesai LHP<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <button type="button" class="btn btn-xs btn-inverse" onclick="get_estimasi();">Auto Set</button>
                        <span class="per_auto text-danger"></span>
                        <input class="form-control perkiraan_estimasi_selesai_lhp datetimepicker1" autocomplete="false" name="perkiraan_estimasi_selesai_lhp" <?php echo !empty($edit) ? "value='".date('m/d/Y h:i A', strtotime($edit['perkiraan_estimasi_selesai_lhp']))."'": ''; ?> id="perkiraan_estimasi_selesai_lhp" type="text" placeholder="Masukkan perkiraan estimasi selesai LHP">
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Asal Instansi/Umum<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <input class="form-control" name="instansi_umum" <?php echo !empty($edit) ? "value='".$edit['instansi_umum']."'": ""; ?> id="instansi_umum" type="text" placeholder="Masukkan Asal Instansi/Umum" required>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Alamat<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <input class="form-control" name="alamat" <?php echo !empty($edit) ? "value='".$edit['alamat']."'": ""; ?> id="alamat" type="text" placeholder="Masukkan Alamat" required>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Nama Pemohon<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <input class="form-control" name="nama_pemohon" <?php echo !empty($edit) ? "value='".$edit['nama_pemohon']."'": ""; ?> id="nama_pemohon" type="text" placeholder="Masukkan Nama Pemohon" required>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Nomor Telepon<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <input class="form-control" name="nomor_telepon" <?php echo !empty($edit) ? "value='".$edit['nomor_telepon']."'": ""; ?> id="nomor_telepon" type="text" placeholder="Masukkan Nomor Telepon" required>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Email Pemohon<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <input class="form-control" name="email_pemohon" <?php echo !empty($edit) ? "value='".$edit['email_pemohon']."'": ""; ?> id="email_pemohon" type="email" placeholder="Masukkan Email Pemohon" required>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Sumber Dana<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <input class="form-control" name="sumber_dana" <?php echo !empty($edit) ? "value='".$edit['sumber_dana']."'": ""; ?> id="sumber_dana" type="text" placeholder="Masukkan Sumber Dana" required>
                    </div>
                </div>
                <div class="hidden">

                </div>

            </div>
        </div>
        <div class="panel-footer">
          <div class="form-group m-b-12">
              <label class="col-md-3 col-form-label control-label"></label>
              <div class="col-md-6">
                  <button type='submit' class='btn btn-success m-b-5' style='margin-right: 5px;'>Simpan</button>
                  <a href="#" onclick="goBack()" class="btn btn-danger m-b-5">Batal</a>
              </div>
          </div>
        </div>
      </div>
  </div>
  </form>

  <script>
    $('.tgl_ambil').hide();
    <?php if(!empty($edit['singkatan_layanan']) && $edit['singkatan_layanan'] == 'A') { ?>
    $('.tgl_ambil').show();
    $('.tgl_pukul_pengambilan2').hide();
    <?php } else if(!empty($edit['singkatan_layanan']) && in_array($edit['singkatan_layanan'], array('P', 'PS'))) {?>
      $('.tgl_ambil').show();
      $('.tgl_pukul_pengambilan').hide();
    <?php } ?>
    function regLab(x){
        <?php if(empty($edit)) { ?>
            $("#registrasi_laboratorium").val('<?php echo $jumlahUji.'.'.date("m.Y") ?>'+x);
        <?php }else { ?>
            <?php
                $reg = explode('.', $edit['registrasi_laboratorium']);
                $reg[2] = substr($reg[2],0,4);
            ?>
            $("#registrasi_laboratorium").val('<?php echo $reg[0].'.'.$reg[1].'.'.$reg[2] ?>'+x);
        <?php } ?>

        if(x == 'A' || x == 'P' || x == 'PS'){
          if(x == 'P' || x == 'PS') {
            $('.tgl_pukul_pengambilan').hide();
            $('.tgl_pukul_pengambilan2').show();
          }else{
            $('.tgl_pukul_pengambilan').show();
            $('.tgl_pukul_pengambilan2').hide();
          }
          $('.tgl_ambil').show();
          //$('.hidden').html('');
        }else {
          $('.tgl_ambil').hide();
          $('.tgl_pukul_pengambilan').removeAttr('required');
          $('.tgl_pukul_pengambilan').removeAttr('value');

          $('.tgl_pukul_pengambilan2').removeAttr('required');
          $('.tgl_pukul_pengambilan2').removeAttr('value');
          //$('.hidden').html("<input type='hidden' name='tgl_pukul_pengambilan'>");

        }
    }
  </script>
  <script>
    function get_estimasi() {
      if($('.tgl_pukul_registrasi').val() == ''){
        $('.per_auto').html('Harap tanggal pukul registrasi diisi terlebih dahulu');
      }else{
        $('.per_auto').html('');
      }
      var split_tgl = $('.tgl_pukul_registrasi').val().split(' ');
      split_tgl[0] = split_tgl[0].split('/');

      var startDate = split_tgl[0][2]+'-'+split_tgl[0][1]+'-'+split_tgl[0][0]+' '+split_tgl[1];
      startDate = new Date(startDate.replace(/-/g, "/"));

      var endDate = "", noOfDaysToAdd = 16, count = 0;
      while(count < noOfDaysToAdd){
          endDate = new Date(startDate.setDate(startDate.getDate() + 1));
          if(endDate.getDay() != 0 && endDate.getDay() != 6){
            count++;
          }
      }
      var fmonth = endDate.getMonth() + 1;
      var fhour = endDate.getHours();
      var fminutes = endDate.getMinutes();
      if(fminutes.length < 2){
        fminutes = '0'+fminutes;
      }

      var fdate = endDate.getDate()+'/'+fmonth+'/'+endDate.getFullYear()+' '+fhour+':'+fminutes;

      if(isNaN(endDate.getMonth())) fdate='';

      $('.perkiraan_estimasi_selesai_lhp').val(fdate);//You can format this date as per your requirement
    }
</script>
