text: $(function(){
      // SUB MENU
      $(".tombolTambahDataSubMenu").on('click',function(){
          $('#newSubMenuModalLabel').html('Add New Sub Menu');
          $("form[name='frmSubMenu'] button[type='submit']").html('Add');
          $("form[name='frmSubMenu'] #act").val('add');
          $("form[name='frmSubMenu'] #title").val('');
          $("form[name='frmSubMenu'] #menu_id").val('');
          $("form[name='frmSubMenu'] #orderlist").val('');
          $("form[name='frmSubMenu'] #url").val('');
          $("form[name='frmSubMenu'] #icon").val('');
          $("form[name='frmSubMenu'] #is_active").prop('checked',true);
      });
      $(".tampilModalUbahNewSubMenu").on('click',function(){
          $('#newSubMenuModalLabel').html('Update Sub Menu');
          $("form[name='frmSubMenu'] button[type='submit']").html('Update');
          const id = $(this).data('id');
          $.ajax({
              url: $(this).data('baseurl')+'Menu/subMenuGetId',
              data: {id:id},
              method: 'post',
              dataType: 'json',
              success: function(data){
                  $("form[name='frmSubMenu'] #act").val('edit');
                  $("form[name='frmSubMenu'] #id").val(id);
                  $("form[name='frmSubMenu'] #title").val(data.Title);
                  $("form[name='frmSubMenu'] #menu_id").val(data.MenuId);
                  $("form[name='frmSubMenu'] #orderlist").val(data.OrderList);
                  $("form[name='frmSubMenu'] #url").val(data.Url);
                  $("form[name='frmSubMenu'] #icon").val(data.Icon);
                  if(data.IsActive == '1'){
                      $("form[name='frmSubMenu'] #is_active").prop('checked',true);
                  } else{
                      $("form[name='frmSubMenu'] #is_active").prop('checked',false);
                  }
              }
          });
      });
      // PRODUCT
      $(".tombolTambahDataProduct").on('click',function(){
          const baseurl = $(this).data('baseurl');
          $("#newProductModalLabel").html("Add New Product");
          $("form[name='frmProduct'] #act").val('add');
          $("form[name='frmProduct'] #id").val("");
          $("form[name='frmProduct'] #description").val('');
          $("form[name='frmProduct'] #harga").val('');
          $("form[name='frmProduct'] #jenis").val('');
          $("form[name='frmProduct'] #oldjenis").val('');
          $("form[name='frmProduct'] #nama").val('');
          $("form[name='frmProduct'] #tipe").val('');
          $("form[name='frmProduct'] #rangekredit").val('');
          $("form[name='frmProduct'] #is_active").prop('checked',true);
          urlprefix = 'assets/img/sample/default.png';
          $("#img-show").attr('src', baseurl+urlprefix);
          $("#fancybox-a").attr('href', baseurl+urlprefix);
          $("form[name='frmProduct'] #oldimage").val('');
          for (let index = 2; index < 5; index++) {
              $("#img-show"+index).attr('src', baseurl+urlprefix);
              $("#fancybox-a"+index).attr('href', baseurl+urlprefix);
              $("form[name='frmProduct'] #oldimage"+index).val('');
          }
      });
      $(".tampilModalUbahNewProduct").on('click',function(){
          $("#newProductModalLabel").html("Update Product");
          $("form[name='frmProduct'] button[type='submit']").html('Update');
          const id = $(this).data('id');
          const baseurl = $(this).data('baseurl');
          let urlprefix = "";
          let arra_index = 1;
          let string_index = "";
          let arra = [];
          $.ajax({
              url: baseurl+'Data/productGetId',
              data: {id:id},
              method: 'post',
              dataType: 'json',
              success: function(data){
                  let arra = [data.gambar,data.gambar2,data.gambar3,data.gambar4];
                  $("form[name='frmProduct'] #act").val('edit');
                  $("form[name='frmProduct'] #id").val(id);
                  $("form[name='frmProduct'] #description").val(data.Description);
                  $("form[name='frmProduct'] #harga").val(data.Harga);
                  $("form[name='frmProduct'] #jenis").val(data.Jenis);
                  $("form[name='frmProduct'] #oldjenis").val(data.Jenis);
                  $("form[name='frmProduct'] #nama").val(data.Nama);
                  $("form[name='frmProduct'] #tipe").val(data.Tipe);
                  $("form[name='frmProduct'] #rangekredit").val(data.RangeKredit);
                      
                  if(data.Stts == '1'){
                      $("form[name='frmProduct'] #is_active").prop('checked',true);
                  } else{
                      $("form[name='frmProduct'] #is_active").prop('checked',false);
                  }
  
                  $.each(arra,function(i,objectgambar){
                      if(arra_index != 1){
                          string_index = arra_index;
                      }
                      if(objectgambar == 'default.png'){
                          urlprefix = 'assets/img/sample/';
                      } else{
                          if(data.Jenis == "1"){
                              urlprefix = 'assets/img/motorHonda/';
                          } else{
                              urlprefix = 'assets/img/sample/';
                          }
                      }
                      $("#img-show"+string_index).attr('src', baseurl+urlprefix+objectgambar);
                      $("#fancybox-a"+string_index).attr('href', baseurl+urlprefix+objectgambar);
                      $("form[name='frmProduct'] #oldimage"+string_index).val(objectgambar);
                      arra_index++
                  });
              }
          });
      });
      // STRUCTURE CREDIT
      $(".tombolTambahDataCreditStructure").on('click',function(){
          $("#newStructureCreditModalLabel").html('Add Credit Structure');
          $("form[name='frmStructureCredit'] button[type='submit']").html('Add');
              $("form[name='frmStructureCredit'] #act").val('add');
              $("form[name='frmStructureCredit'] #id").val('');
              $("form[name='frmStructureCredit'] #um").val('');
              $("form[name='frmStructureCredit'] #top").val('');
              $("form[name='frmStructureCredit'] #angsuran").val('');
              $("form[name='frmStructureCredit'] #is_active").prop('checked',true);
      });
      $(".tampilModalUbahNewStructureCredit").on('click',function(){
          $("#newStructureCreditModalLabel").html('Update Credit Structure');
          $("form[name='frmStructureCredit'] button[type='submit']").html('Update');
          const id = $(this).data('id');
          const baseurl = $(this).data('baseurl');
          $.ajax({
              url: baseurl+'Data/creditGetId',
              data: {id:id},
              method: 'post',
              dataType: 'json',
              success: function(data){
                  $("form[name='frmStructureCredit'] #act").val('edit');
                  $("form[name='frmStructureCredit'] #id").val(id);
                  $("form[name='frmStructureCredit'] #um").val(data.Um);
                  $("form[name='frmStructureCredit'] #top").val(data.Top);
                  $("form[name='frmStructureCredit'] #angsuran").val(data.Value);
                  if(data.Stts == '1'){
                      $("form[name='frmStructureCredit'] #is_active").prop('checked',true);
                  } else{
                      $("form[name='frmStructureCredit'] #is_active").prop('checked',false);
                  }
              }
          });
      });
      // SLIDESHOW
      $(".tombolTambahDataSlideShow").on("click",function(){
          const baseurl = $(this).data('baseurl');
          $("#newSlideShowModalLabel").html("Add New SlideShow");
          $("form[name='frmSlideShow'] button[type='submit']").html('Add');
          $("form[name='frmSlideShow'] #act").val('add');
          $("form[name='frmSlideShow'] #id").val('');
          urlprefix = 'assets/img/slideshow/default.png';
          $("#img-show").attr('src', baseurl+urlprefix);
          $("#fancybox-a").attr('href', baseurl+urlprefix);
          $("form[name='frmSlideShow'] #is_active").prop('checked',true);
          $("form[name='frmSlideShow'] #oldimage").val('');
          $("form[name='frmSlideShow'] #place").val('');
      });
      $(".tampilModalUbahNewSlideShow").on("click",function(){
          $("#newSlideShowModalLabel").html("Update SlideShow");
          $("form[name='frmSlideShow'] button[type='submit']").html('Update');
          const id = $(this).data('id');
          const baseurl = $(this).data('baseurl');
          let urlprefix = "";
          $.ajax({
              url: baseurl+'Data/slideshowGetId',
              data: {id:id},
              method: 'post',
              dataType: 'json',
              success: function(data){
                  $("form[name='frmSlideShow'] #act").val('edit');
                  $("form[name='frmSlideShow'] #id").val(id);
                      urlprefix = 'assets/img/slideshow/';
                  $("#img-show").attr('src', baseurl+urlprefix+data.Gambar);
                  $("#fancybox-a").attr('href', baseurl+urlprefix+data.Gambar);
                  if(data.Stts == '1'){
                      $("form[name='frmSlideShow'] #is_active").prop('checked',true);
                  } else{
                      $("form[name='frmSlideShow'] #is_active").prop('checked',false);
                  }
                  $("form[name='frmSlideShow'] #oldimage").val(data.Gambar);
                  $("form[name='frmSlideShow'] #place").val(data.Place);
              }
          });
      });
      // MASTER JENIS PRODUCT
      $(".tombolTambahDataMasterJenisProduct").on("click",function(){
          $("#newMasterJenisProductModalLabel").html("Add New Master Jenis Product");
          $("form[name='frmMasterJenisProduct'] button[type='submit']").html('Add');
          $("form[name='frmMasterJenisProduct'] #act").val('add');
          $("form[name='frmMasterJenisProduct'] #id").val("");
          $("form[name='frmMasterJenisProduct'] #nama").val("");
          $("form[name='frmMasterJenisProduct'] #commision").val("");
          $("form[name='frmMasterJenisProduct'] #is_active").prop('checked',true);
      });
      $(".tampilModalUbahNewMasterJenisProduct").on("click",function(){
          $("#newMasterJenisProductModalLabel").html("Update Master Jenis Product");
          $("form[name='frmMasterJenisProduct'] button[type='submit']").html('Update');
          const id = $(this).data('id');
          const baseurl = $(this).data('baseurl');
          let urlprefix = "";
          $.ajax({
              url: baseurl+'Data/masterJenisProductGetId',
              data: {id:id},
              method: 'post',
              dataType: 'json',
              success: function(data){
                  $("form[name='frmMasterJenisProduct'] #act").val('edit');
                  $("form[name='frmMasterJenisProduct'] #id").val(id);
                  $("form[name='frmMasterJenisProduct'] #nama").val(data.Nama);
                  $("form[name='frmMasterJenisProduct'] #commision").val(data.Commision);
                  if(data.Stts == '1'){
                      $("form[name='frmMasterJenisProduct'] #is_active").prop('checked',true);
                  } else{
                      $("form[name='frmMasterJenisProduct'] #is_active").prop('checked',false);
                  }
              }
          });
      });
      // JENIS PRODUCT
      $(".tombolTambahDataJenisProduct").on("click",function(){
          $("#newJenisProductModalLabel").html("Add New Jenis Product");
          $("form[name='frmJenisProduct'] button[type='submit']").html('Add');
          $("form[name='frmJenisProduct'] #act").val('add');
          $("form[name='frmJenisProduct'] #id").val("");
          $("form[name='frmJenisProduct'] #nama").val("");
          $("form[name='frmJenisProduct'] #jenisproduct").val("");
          $("form[name='frmJenisProduct'] #is_active").prop('checked',true);
      });
      $(".tampilModalUbahNewJenisProduct").on("click",function(){
          $("#newJenisProductModalLabel").html("Update Jenis Product");
          $("form[name='frmJenisProduct'] button[type='submit']").html('Update');
          const id = $(this).data('id');
          const baseurl = $(this).data('baseurl');
          let urlprefix = "";
          $.ajax({
              url: baseurl+'Data/JenisProductGetId',
              data: {id:id},
              method: 'post',
              dataType: 'json',
              success: function(data){
                  $("form[name='frmJenisProduct'] #act").val('edit');
                  $("form[name='frmJenisProduct'] #id").val(id);
                  $("form[name='frmJenisProduct'] #nama").val(data.Nama);
                  $("form[name='frmJenisProduct'] #jenisproduct").val(data.Tipe);
                  if(data.Stts == '1'){
                      $("form[name='frmJenisProduct'] #is_active").prop('checked',true);
                  } else{
                      $("form[name='frmJenisProduct'] #is_active").prop('checked',false);
                  }
              }
          });
      });
      // LISING
      $(".tombolTambahDataLising").on("click",function(){
          $("#newLisingModalLabel").html("Add New Lising");
          $("form[name='frmLising'] button[type='submit']").html('Add');
          $("form[name='frmLising'] #act").val('add');
          $("form[name='frmLising'] #id").val("");
          $("form[name='frmLising'] #nama").val('');
          $("form[name='frmLising'] #is_active").prop('checked',true);
      });
      $(".tampilModalUbahLising").on("click",function(){
          $("#newLisingModalLabel").html("Update Lising");
          $("form[name='frmLising'] button[type='submit']").html('Update');
          const id = $(this).data('id');
          const baseurl = $(this).data('baseurl');
          let urlprefix = "";
          $.ajax({
              url: baseurl+'Data/LisingGetId',
              data: {id:id},
              method: 'post',
              dataType: 'json',
              success: function(data){
                  $("form[name='frmLising'] #act").val('edit');
                  $("form[name='frmLising'] #id").val(id);
                  $("form[name='frmLising'] #nama").val(data.Nama);
                  if(data.Stts == '1'){
                      $("form[name='frmLising'] #is_active").prop('checked',true);
                  } else{
                      $("form[name='frmLising'] #is_active").prop('checked',false);
                  }
              }
          });
      });
      // TOP
      $(".tombolTambahDataTop").on("click",function(){
          $("#newTopModalLabel").html("Add New Top");
          $("form[name='frmTop'] button[type='submit']").html('Add');
          $("form[name='frmTop'] #act").val('add');
          $("form[name='frmTop'] #id").val("");
          $("form[name='frmTop'] #nama").val("");
          $("form[name='frmTop'] #is_active").prop('checked',true);
      });
      $(".tampilModalUbahTop").on("click",function(){
          $("#newTopModalLabel").html("Update Top");
          $("form[name='frmTop'] button[type='submit']").html('Update');
          const id = $(this).data('id');
          const baseurl = $(this).data('baseurl');
          let urlprefix = "";
          $.ajax({
              url: baseurl+'Data/TopGetId',
              data: {id:id},
              method: 'post',
              dataType: 'json',
              success: function(data){
                  $("form[name='frmTop'] #act").val('edit');
                  $("form[name='frmTop'] #id").val(id);
                  $("form[name='frmTop'] #nama").val(data.Top);
                  if(data.Stts == '1'){
                      $("form[name='frmTop'] #is_active").prop('checked',true);
                  } else{
                      $("form[name='frmTop'] #is_active").prop('checked',false);
                  }
              }
          });
      });
      // JOB
      $(".tombolTambahDataJob").on("click",function(){
          $("#newJobModalLabel").html("Add New Job");
          $("form[name='frmJob'] button[type='submit']").html('Add');
          $("form[name='frmJob'] #act").val('add');
          $("form[name='frmJob'] #id").val("");
          $("form[name='frmJob'] #nama").val("");
          $("form[name='frmJob'] #is_active").prop('checked',true);
      });
      $(".tampilModalUbahJob").on("click",function(){
          $("#newJobModalLabel").html("Update Job");
          $("form[name='frmJob'] button[type='submit']").html('Update');
          const id = $(this).data('id');
          const baseurl = $(this).data('baseurl');
          let urlprefix = "";
          $.ajax({
              url: baseurl+'Data/JobGetId',
              data: {id:id},
              method: 'post',
              dataType: 'json',
              success: function(data){
                  $("form[name='frmJob'] #act").val('edit');
                  $("form[name='frmJob'] #id").val(id);
                  $("form[name='frmJob'] #nama").val(data.Nama);
                  if(data.Stts == '1'){
                      $("form[name='frmJob'] #is_active").prop('checked',true);
                  } else{
                      $("form[name='frmJob'] #is_active").prop('checked',false);
                  }
              }
          });
      });
      // ADJUSTMENT
      $(".tampilModalUbahNewUser").on("click",function(){
          $("#newUserModalLabel").html("Update User");
          $("form[name='frmUser'] button[type='submit']").html('Update');
          const id = $(this).data('id');
          const baseurl = $(this).data('baseurl');
          let urlprefix = "";
          $.ajax({
              url: baseurl+'Data/adjustmentGetId',
              data: {id:id},
              method: 'post',
              dataType: 'json',
              success: function(data){
                  $("form[name='frmUser'] #act").val('edit');
                  $("form[name='frmUser'] #id").val(id);
                  $("form[name='frmUser'] #nama").val(data.Nama);
                  $("form[name='frmUser'] #username").val(data.Username);
                  $("form[name='frmUser'] #alamatktp").val(data.AlamatKtp);
                  $("form[name='frmUser'] #alamatnow").val(data.AlamatNow);
                  $("form[name='frmUser'] #job").val(data.Job);
                  $("form[name='frmUser'] #norek").val(data.NoRek);
                  $("form[name='frmUser'] #nohp").val(data.NoHp);
                  $("form[name='frmUser'] #point").val(data.Point);
                  $("form[name='frmUser'] #type").val(data.Type);
                  $("form[name='frmUser'] #oldimage").val(data.Photo);
                  urlprefix = 'assets/img/userPhoto/';
                  $("#show-photo").attr('src', baseurl+urlprefix+data.Photo);
                  $("#fancy-photo").attr('href', baseurl+urlprefix+data.Photo);
                  if(data.Stts == '1'){
                      $("form[name='frmUser'] #is_active").prop('checked',true);
                  } else{
                      $("form[name='frmUser'] #is_active").prop('checked',false);
                  }
              }
          });
      });
      // TRANSACTION
      $(".tampilDetailTransaction").on("click",function(){
          const id = $(this).data('id');
          const baseurl = $(this).data('baseurl');
          const urlimg = $(this).data('urlimg');
          let urlprefix = "";
          $.ajax({
              url: baseurl+'Data/transactionGetId',
              data: {id:id},
              method: 'post',
              dataType: 'json',
              success: function(data){
                  $("form[name='frmTransaction'] #namaproduk").val(data.NamaProduk+' - '+data.TipeProduk);
                  $("form[name='frmTransaction'] #hargaproduk").val(data.Harga);
                  $("form[name='frmTransaction'] #namastnkbpkb").val(data.NamaStnkBpkb);
                  $("form[name='frmTransaction'] #nohp1").val(data.NoHp1);
                  $("form[name='frmTransaction'] #nohp2").val(data.NoHp2);
                  $("form[name='frmTransaction'] #message").val(data.Message);
                  $("form[name='frmTransaction'] #descstts").val(data.DescStts);
  
                  urlprefix = 'assets/img/ktp/';
                  $("#ktp-img").attr('src', urlimg+urlprefix+data.Ktp);
                  $("#ktp-fancy").attr('href', urlimg+urlprefix+data.Ktp);
                  $("#ktp-download").attr('href', urlimg+urlprefix+data.Ktp);
  
                  if(data.Kk != null){
                      urlprefix = 'assets/img/kk/';
                      $("#kk-img").attr('src', urlimg+urlprefix+data.Kk);
                      $("#kk-fancy").attr('href', urlimg+urlprefix+data.Kk);
                      $("#kk-download").attr('href', urlimg+urlprefix+data.Kk);
                  } else{
                      $("#kk-img").attr('src', baseurl+'assets/img/sample/default.png');
                      $("#kk-fancy").attr('href', baseurl+'assets/img/sample/default.png');
                      $("#kk-download").attr('href', baseurl+'assets/img/sample/default.png');
                  }
                  $("form[name='frmTransaction'] #namaagent").val(data.NamaAgent+' - '+data.EmailAgent);
                  $("form[name='frmTransaction'] #type").val(data.Type);
                  if(data.Type == "CREDIT"){
                      $("form[name='frmTransaction'] #lising").val(data.NamaLising);
                      $("form[name='frmTransaction'] #top").val(data.NamaTop+'x');
                      $("form[name='frmTransaction'] #dp").val(data.Dp);
                      $("form[name='frmTransaction'] #angsuran").val(data.Angsuran);
                      $("form[name='frmTransaction'] #namaibu").val(data.NamaIbu);
                      $("form[name='frmTransaction'] #pekerjaan").val(data.Pekerjaan);
                      $("form[name='frmTransaction'] #tempatkerjausaha").val(data.TempatKerjaUsaha);
                      $("form[name='frmTransaction'] #lamakerjausaha").val(data.LamaKerjaUsaha);
                      $("form[name='frmTransaction'] #penghasilanbulan").val(data.PenghasilanBulanan);
                      $("form[name='frmTransaction'] #pengeluaran").val(data.Pengeluaran);
                      $("form[name='frmTransaction'] #pekerjaanpasangan").val(data.PekerjaanPasangan);
                      $("form[name='frmTransaction'] #penghasilanpasangan").val(data.PenghasilanPasangan);
                      $("form[name='frmTransaction'] #alamatsurvey").val(data.AlamatSurvey);
                  } else{
                      $("form[name='frmTransaction'] #lising").val("");
                      $("form[name='frmTransaction'] #top").val("");
                      $("form[name='frmTransaction'] #dp").val("");
                      $("form[name='frmTransaction'] #angsuran").val("");
                      $("form[name='frmTransaction'] #namaibu").val("");
                      $("form[name='frmTransaction'] #pekerjaan").val("");
                      $("form[name='frmTransaction'] #tempatkerjausaha").val("");
                      $("form[name='frmTransaction'] #lamakerjausaha").val("");
                      $("form[name='frmTransaction'] #penghasilanbulan").val("");
                      $("form[name='frmTransaction'] #pengeluaran").val("");
                      $("form[name='frmTransaction'] #pekerjaanpasangan").val("");
                      $("form[name='frmTransaction'] #penghasilanpasangan").val("");
                      $("form[name='frmTransaction'] #alamatsurvey").val("");
                  }
              }
          });
      });
      // TRANSACTION EXPORT
      $("form[name='transaction'] .btn-export-excel").on("click",function(e){
          e.preventDefault();
          const data = $("form[name='transaction']").serialize();
          const url = $("form[name='transaction'] input[name='urlexportexcel']").val();
          const method = "post";
          $.ajax({
              url: url,
              method: method,
              data: data,
              dataType: 'json',
              timeout: 10000,
              beforeSend: function(){
                  $(".loading-div").show();
              },
              success: function(result){
                  // console.log(result);
                  $(".loading-div").hide();
                  if(result.status){
                  let r = confirm("File berhasil di generate, apakah anda ingin mendownload file excel tersebut?");
                      if(r){
                          document.location.href = result.namafile;
                      }
                  } else{
                      alert('Warning Oooops '+result.session);
                  }
              },
              error: function (jqXHR, exception) {
                  var msg = '';
                  if (jqXHR.status === 0) {
                      msg = 'Not connect.\n Verify Network.';
                  } else if (jqXHR.status == 404) {
                      msg = 'Requested page not found. [404]';
                  } else if (jqXHR.status == 500) {
                      msg = 'Internal Server Error [500].';
                  } else if (exception === 'parsererror') {
                      msg = 'Requested JSON parse failed.';
                  } else if (exception === 'timeout') {
                      msg = 'Time out error.';
                  } else if (exception === 'abort') {
                      msg = 'Ajax request aborted.';
                  } else {
                      msg = 'Uncaught Error.\n' + jqXHR.responseText;
                  }
                  alert('Error Something Wrong '+msg);
                  $(".loading-div").hide();
              },
              complete: function(result){
                  console.log('complete');
                  $(".loading-div").hide();
              }
          });
      });
      // TRANSACTION APPROVAL DESCRIPTION
      $(".rejectTransaction").on("click",function(){
          $("#transactionApprovalModalLabel").html('Reject Description');
          $("form[name='frmTransactionApproval'] #message").val("");
          const idtrans = $(this).data('idtrans');
          $("form[name='frmTransactionApproval'] #idtrans").val(idtrans);
      });
  
      $(".checkbox-roleaccess").on('click',function(){
          const role = $(this).data('role');
          const menu = $(this).data('menu');
          const baseurl = $(this).data('baseurl');
          $.ajax({
              url: baseurl+'admin/changeaccess',
              type: 'post',
              data:{
                  menuId : menu,
                  roleId: role
              },
              success: function(){
                  document.location.href = baseurl+'admin/roleaccess/'+role;
              }
          });
      });
      $('.custom-file-input').on('change',function(){
          let fileName = $(this).val().split('\\').pop();
          $(this).next('.custom-file-label').addClass('selected').html(fileName);
      });
      $(".datex").datepicker({
          dateFormat  : "dd-mm-yy",
          changeMonth : true,
          changeYear  : true,
          // yearRange	  : "-70:-15"
      });
      $(".datex2").datepicker({
          dateFormat  : "yy-mm-dd",
          changeMonth : true,
          changeYear  : true,
          // yearRange	  : "-70:-15"
      });
  });