text: $(document).ready(function(){
      if (localStorage.getItem('create_success')) {
          const msg = localStorage.getItem('msg');
          Command: toastr['success'](msg, "SUKSES");
          localStorage.clear('create_success');
          localStorage.clear('msg');
      }
      if (localStorage.getItem('submit_success')) {
          const msg = localStorage.getItem('msg');
          Command: toastr['success'](msg, "SUKSES");
          localStorage.clear('submit_success');
          localStorage.clear('msg');
      }
      if (localStorage.getItem('edit_success')) {
          const msg = localStorage.getItem('msg');
          Command: toastr['info'](msg, "SUKSES");
          localStorage.clear('edit_success');
          localStorage.clear('msg');
      }
      if (localStorage.getItem('delete_success')) {
          const msg = localStorage.getItem('msg');
          Command: toastr['error'](msg, "SUKSES");
          localStorage.clear('delete_success');
          localStorage.clear('msg');
      }
  })
  
  function base_url() {
      var pathparts = location.pathname.split('/');
      if (location.host == '10.110.1.193') {
          var url = location.origin+'/'+pathparts[1].trim('/')+'/';
      } else {
          var url = location.origin+'/'; 
      }
      return url;
  }
  
  const Toast = Swal.mixin({
      toast: true,
      position: 'top-end',
      showConfirmButton: false,
      timer: 4000,
      timerProgressBar: true,
      didOpen: (toast) => {
        toast.addEventListener('mouseenter', Swal.stopTimer)
        toast.addEventListener('mouseleave', Swal.resumeTimer)
      }
    })
    
  
  $('[data-toggle="tooltip"]').tooltip({
      trigger : 'hover'
  })
  
  $('.mask-number-format').inputmask("decimal", {
      radixPoint: ",",
      autoGroup: true,
      groupSeparator: ".",
      groupSize: 3,
      autoUnmask: true
  });
  
  $(".default-select2").select2({
      width: 'auto'
  });
  
  $('.switchery').each(function() {
      new Switchery(this, { color:'rgb(52, 143, 226)', secondaryColor: 'red', size: 'small' })
  });
  
  $(".reset").on('click',function(e){
      e.preventDefault();
      $('input:not([type="hidden"]:not(".immune-reset"))').val('');
      $('textarea').val('');
      $('.default-select2').val('').trigger('change');
      $('.custom-datepicker, .start-date-period, .end-date-period').val('');
  });
  
  $('.custom-datepicker').datepicker({
      'format': 'dd-mm-yyyy',
      'todayHighlight': true,
      'autoclose': true
  })
  
  $(".start-date-period").daterangepicker({
      'locale': {
          'format': 'DD/MM/YYYY',
          "monthNames": [
              "Januari",
              "Februari",
              "Maret",
              "April",
              "Mei",
              "Juni",
              "Juli",
              "Agustus",
              "September",
              "Oktober",
              "November",
              "Desember"
          ]
      },
      'singleDatePicker': true,
      'showDropdowns': true,
      'autoApply': true,
      'todayHighlight': true
  }).on('change', function () {
      $('.end-date-period').daterangepicker({
          'locale': {
              'format': 'DD/MM/YYYY',
              "monthNames": [
                  "Januari",
                  "Februari",
                  "Maret",
                  "April",
                  "Mei",
                  "Juni",
                  "Juli",
                  "Agustus",
                  "September",
                  "Oktober",
                  "November",
                  "Desember"
              ]
          },
          'dateFormat': "dd/mm/yyyy",
          'singleDatePicker': true,
          'showDropdowns': true,
          'autoApply': true,
          'todayHighlight': true,
          'minDate': this.value
      });
  })
  
  $('.end-date-period').daterangepicker({
      'locale': {
          'format': 'DD/MM/YYYY',
          "monthNames": [
              "Januari",
              "Februari",
              "Maret",
              "April",
              "Mei",
              "Juni",
              "Juli",
              "Agustus",
              "September",
              "Oktober",
              "November",
              "Desember"
          ]
      },
      'dateFormat': "dd/mm/yyyy",
      'singleDatePicker': true,
      'showDropdowns': true,
      'autoApply': true,
      'todayHighlight': true
  })
  
  $('.clear-start').on('click', function(){
      if ($(".start-date-period").val()) {
          $(".start-date-period").val('').trigger('change');
      }
  })
  
  $('.clear-end').on('click', function(){
      $(".end-date-period").val('');
  })
  
  toastr.options = {
      "closeButton": false,
      "debug": false,
      "newestOnTop": false,
      "progressBar": true,
      "positionClass": "toast-top-right",
      "preventDuplicates": false,
      "onclick": null,
      "showDuration": "300",
      "hideDuration": "1000",
      "timeOut": "6000",
      "extendedTimeOut": "1000",
      "showEasing": "swing",
      "hideEasing": "linear",
      "showMethod": "fadeIn",
      "hideMethod": "fadeOut"
  };
  
  function number_format(angka) {
      var number_string = angka.toString().replace(/[^,\d]/g, "");
      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 rupiah;
  };
  
  function metric_date(val, tipe) {
      var d = new Date(val),
      month = '' + (d.getMonth() + 1),
      day = '' + d.getDate(),
      year = d.getFullYear();
      hour = '' + d.getHours();
      min = '' + d.getMinutes();
      if (month.length < 2) 
          month = '0' + month;
      if (day.length < 2) 
          day = '0' + day;
      if (hour.length < 2) 
          hour = '0' + hour;
      if (min.length < 2) 
          min = '0' + min;
      if (tipe == '1') {
          return [day, month, year].join('/');
      } else {
          return [day, month, year].join('/')+' '+[hour, min].join(':');
      }
  }
  
  function cancel() {
      Swal.fire({
          title: 'Anda yakin?',
          html: 'Anda akan membatalkan proses.',
          icon: 'warning',
          confirmButtonText: 'OK',
          allowOutsideClick: false
      }).then((result) => {
          if (result.value) {
              if (localStorage.getItem('last_url')) {
                  window.location.href = localStorage.getItem('last_url');
              } else {
                  window.location.href = base_url()+'home';
              }
          }
      });
  }
  
  $('.status-change').on('change', function(){
      let val = $(this)[0].checked;
      let id = $(this).data('id');
      let table = $(this).data('table');
      let obj = '';
      switch(table) {
          case 'user': obj = 'User'; break;
          default : obj = '';
      }
      Swal.fire({
          title: 'Mohon Tunggu',
          html: 'Sedang mengupdate data...',
          allowOutsideClick: false,
          didOpen: function () {
              Swal.showLoading();
              $.ajax({
                  url: base_url()+'global_update_status',
                  type: 'post',
                  headers: {
                      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                  },
                  data: {
                      'table': table,
                      'id': id,
                      'value': val
                  },
                  dataType: 'JSON',
                  success: function(res) {
                      Swal.close();
                      if (val === true) {
                          toastr.success(obj+' berhasil diaktifkan.');
                      } else {
                          toastr.error(obj+' berhasil dinonaktifkan.');
                      }
                  },
                  error: function(xhr) {
                      Swal.fire({
                          title: 'Oops!',
                          html: 'Gagal menyimpan data!<br>Halaman akan dimuat ulang.',
                          icon: 'error',
                          allowOutsideClick: false
                      }).then((result) => {
                          location.reload()
                      });
                  }
              })
          }
      })
  })
  
  $('.commit-delete').on('click', function(){
      let table = $(this).data('table');
      let id = $(this).data('id');
      Swal.fire({
          title: 'Anda yakin?',
          text: 'Data barang akan dihapus.',
          icon: 'warning',
          confirmButtonText: 'Ya',
          showCancelButton: true,
          cancelButtonText: 'Tidak',
          cancelButtonColor: '#d33',
          allowOutsideClick: false
      }).then((result) => {
          if (result.value) {
              Swal.fire({
                  title: 'Mohon Tunggu',
                  html: 'Sedang menghapus data...',
                  allowOutsideClick: false,
                  didOpen: function () {
                      Swal.showLoading();
                      $.ajax({
                          url: base_url()+"global_delete",
                          type: 'post',
                          headers: {
                              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                          },
                          data: {
                              'table': table,
                              'id': id
                          },
                          dataType: 'JSON',
                          success: function(res) {
                              Swal.fire({
                                  title: 'Sukses',
                                  html: res.invest_house,
                                  icon: 'success',
                                  confirmButtonText: 'OK',
                                  allowOutsideClick: false
                              }).then((result) => {
                                  if (result.value) {
                                      location.reload();
                                  }
                              });
                          },
                          error: function(xhr) {
                              Swal.fire({
                                  title: 'Oops!',
                                  html: xhr.responseJSON.invest_house,
                                  icon: 'error',
                                  allowOutsideClick: false
                              })
                          }
                      })
                  }
              })
          }
      });
  })
  
  function addZero(i) {
      if (i < 10) {
          i = "0" + i;
      }
      return i;
  }
  
  function date_indonesia(val,tipe) {
      var date = new Date(val);
      var tahun = date.getFullYear();
      var bulan = date.getMonth();
      var tanggal = date.getDate();
      var hari = date.getDay();
      var jam = date.getHours();
      var menit = date.getMinutes();
  
      switch (hari) {
          case 0: hari = "Minggu"; break;
          case 1: hari = "Senin"; break;
          case 2: hari = "Selasa"; break;
          case 3: hari = "Rabu"; break;
          case 4: hari = "Kamis"; break;
          case 5: hari = "Jumat"; break;
          case 6: hari = "Sabtu"; break;
      }
  
      switch (bulan) {
          case 0: bulan = "Januari"; break;
          case 1: bulan = "Februari"; break;
          case 2: bulan = "Maret"; break;
          case 3: bulan = "April"; break;
          case 4: bulan = "Mei"; break;
          case 5: bulan = "Juni"; break;
          case 6: bulan = "Juli"; break;
          case 7: bulan = "Agustus"; break;
          case 8: bulan = "September"; break;
          case 9: bulan = "Oktober"; break;
          case 10: bulan = "November"; break;
          case 11: bulan = "Desember"; break;
      }
      if (tipe == 1) {
          return tanggal+' '+bulan+' '+tahun;
      } else if (tipe == 2) {
          return addZero(jam)+' : '+addZero(menit);
      } else {
          return hari+', '+tanggal+' '+bulan+' '+tahun+' | '+addZero(jam)+' : '+addZero(menit);
      }
  }
  
  function getBase64(file,id) {
      var reader = new FileReader();
      reader.readAsDataURL(file);
      console.log(id);
      reader.onload = function () {
          $('input[data-base64="'+id+'"]').val(reader.result);
      };
      reader.onerror = function (error) {
          Swal.fire({
              title: 'Oops!',
              html: error,
              icon: 'error',
              allowOutsideClick: false
          })
      };
  }