// Currency Separator var commaCounter = 10; var Url = document.currentScript.getAttribute('myUrl'); var ta = document.currentScript.getAttribute('ta'); function numberSeparator(Number) { Number += ''; for (var i = 0; i < commaCounter; i++) { Number = Number.replace(',', ''); } x = Number.split('.'); y = x[0]; z = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(y)) { y = y.replace(rgx, '$1' + ',' + '$2'); } commaCounter++; return y + z; } function setIndoDate(n){ if (n){ arrDate = n.split("-"); return arrDate[2] + "/" + arrDate[1] + "/" + arrDate[0]; }else{ return ""; } } function setIndoDateOracle(n){ if (n){ arrDateSpace = n.split(" "); arrDate = arrDateSpace[0].split("-"); return arrDate[2] + "/" + arrDate[1] + "/" + arrDate[0]; }else{ return "-"; } } // Set Currency Separator to input fields $(document).on('keypress , paste', '.number-separator', function (e) { if (/^-?\d*[,.]?(\d{0,3},)*(\d{3},)?\d{0,3}$/.test(e.key)) { $('.number-separator').on('input', function () { e.target.value = numberSeparator(e.target.value); }); } else { e.preventDefault(); return false; } }); function setDatePicker(input){ $(input).datetimepicker({ format: "DD/MM/YYYY", useCurrent: false }) } function setDateRangePicker(input1, input2){ $(input1).datetimepicker({ format: "DD/MM/YYYY", useCurrent: false }) $(input1).on("change.datetimepicker", function (e) { $(input2).val("") $(input2).datetimepicker('minDate', e.date); }) $(input2).datetimepicker({ format: "DD/MM/YYYY", useCurrent: false }) } function setMonthPicker(input){ $(input).datetimepicker({ format: "MM", useCurrent: false, viewMode: "months" }) } function setYearPicker(input){ $(input).datetimepicker({ format: "YYYY", useCurrent: false, viewMode: "years" }) } function setYearRangePicker(input1, input2){ $(input1).datetimepicker({ format: "YYYY", useCurrent: false, viewMode: "years" }) $(input1).on("change.datetimepicker", function (e) { $(input2).val("") $(input2).datetimepicker('minDate', e.date); }) $(input2).datetimepicker({ format: "YYYY", useCurrent: false, viewMode: "years" }) } $('body').on('focus',".indo_date", function(){ $(this).daterangepicker({ singleDatePicker: true, showDropdowns: true, minYear: 1990, locale: { format: 'DD/MM/YYYY' }, drops: "down", autoApply: true, }); $(this).on("keypress",function(){ return false; }) }); $("body").on('keyup', ".number-separator-indo", function(){ var n = parseFloat($(this).val().replace(/\D/g,''),10); $(this).val(new Intl.NumberFormat('id-ID').format(n)); }); var replaceValue = (n) =>{ n = n == "" ? "0" : n; return parseFloat(n.replace(/\D/g,''),10); } function separateNumberIndo(n){ return new Intl.NumberFormat('id-ID').format(n) } calculate = () =>{ let gajiPokok = replaceValue($("#rincian_gaji_pokok").val()); let tunjangan_suami_istri = replaceValue($("#rincian_tunjangan_suami_istri").val()); let tunjangan_anak = replaceValue($("#rincian_tunjangan_anak").val()); let tunjangan_lain = replaceValue($("#rincian_tunjangan_lain").val()); let tunjangan_jabatan = replaceValue($("#rincian_tunjangan_jabatan").val()); let tunjangan_beras = replaceValue($("#rincian_tunjangan_beras").val()); let tunjangan_pph = replaceValue($("#rincian_tunjangan_pph").val()); let pembulatan = replaceValue($("#rincian_pembulatan").val()); let potongan_beras = replaceValue($("#rincian_potongan_beras").val()); let potongan_iuran_pfk = replaceValue($("#rincian_potongan_iuran_pfk").val()); let potongan_pph = replaceValue($("#rincian_potongan_pph").val()); let potongan_lain = replaceValue($("#rincian_potongan_lain").val()); // console.log(gajiPokok); let totGajiKotor = gajiPokok + tunjangan_suami_istri + tunjangan_anak + tunjangan_lain + tunjangan_jabatan + tunjangan_beras + tunjangan_pph + pembulatan; let totPotongan = potongan_beras + potongan_iuran_pfk + potongan_pph + potongan_lain; let totGajiBersih = totGajiKotor - totPotongan; // console.log(totGajiBersih); $("#rincian_total_potongan").val(separateNumberIndo(totPotongan)); $("#rincian_total_gaji_kotor").val(separateNumberIndo(totGajiKotor)); $("#rincian_total_gaji_bersih").val(separateNumberIndo(totGajiBersih)); } $(document).on("change", ".calculate_field", function(){ calculate(); }); calculateDebt = () =>{ let total = 0; if ($(".calculate_field_debt").length == 0){ $("#rincian_utang_total").val(0); $("#rincian_utang_angsur").val(0); $("#sisa_utang").val(0); $(".uraian_debt").prop("required", false); }else{ $(".calculate_field_debt").each(function(i,x){ let val = $($(".calculate_field_debt")[i]).val(); total += replaceValue(val); }); $("#rincian_utang_total").val(separateNumberIndo(total)); let totalUtang = replaceValue($("#rincian_utang_total").val()); let totalAngsur = replaceValue($("#rincian_utang_angsur").val()); $("#sisa_utang").val(separateNumberIndo(totalUtang - totalAngsur)); if (total > 0){ $(".uraian_debt").prop("required", true); } } } $(document).on("change", ".calculate_field_debt", function(){ calculateDebt(); }); $('.skpd_search').select2({ placeholder: 'Pilih SKPD', ajax: { url:Url+'/skpd-search', dataType: 'json', delay: 250, processResults: function (data) { return { results: $.map(data, function (item) { return { text: item.name, id: item.id } }) }; }, cache: true } }); $('.prog_search').select2({ placeholder: 'Pilih Program', ajax: { url: Url+'/item-search-prog', dataType: 'json', delay: 250, processResults: function (data) { return { results: $.map(data, function (item) { return { text: item.name, id: item.id } }) }; }, cache: true } }); $('.keg_search').select2({ placeholder: 'Pilih Kegiatan', ajax: { url: Url+'/item-search-keg', dataType: 'json', delay: 250, processResults: function (data) { return { results: $.map(data, function (item) { return { text: item.name, id: item.id } }) }; }, cache: true } }); $('.sk_search').select2({ placeholder: 'Pilih Sub Kegiatan', ajax: { url: Url+'/item-search-sk', dataType: 'json', delay: 250, processResults: function (data) { return { results: $.map(data, function (item) { return { text: item.name, id: item.id } }) }; }, cache: true } }); $('.rsk_search').select2({ placeholder: 'Pilih Rinci Sub Kegiatan', ajax: { url: Url+'/item-search-rsk', dataType: 'json', delay: 250, processResults: function (data) { return { results: $.map(data, function (item) { return { text: item.name, id: item.id } }) }; }, cache: true } }); $('.jenis_belanja_search').select2({ placeholder: 'Pilih Jenis Belanja', ajax: { url: Url+'/item-search-jenisbelanja', dataType: 'json', delay: 250, processResults: function (data) { return { results: $.map(data, function (item) { return { text: item.name, id: item.id } }) }; }, cache: true } }); $('.sub_jenis_belanja_search').select2({ placeholder: 'Pilih Sub Jenis Belanja', ajax: { url: Url+'/item-search-subjenisbelanja', dataType: 'json', delay: 250, processResults: function (data) { return { results: $.map(data, function (item) { return { text: item.name, id: item.id } }) }; }, cache: true } }); let subJenisDana = (idGrup)=>{ $('.sub_jenis_dana').select2({ placeholder: 'Pilih Sub Jenis Dana', ajax: { url: Url+'/item-search-subjenisdana?id_grup='+idGrup, dataType: 'json', delay: 250, processResults: function (data) { return { results: $.map(data, function (item) { return { text: item.name, id: item.id_name } }) }; }, cache: true } }); } $('.sps_search').select2({ placeholder: 'Pilih DBH / DAK', ajax: { url: Url+'/item-search-sps?ta='+ta, dataType: 'json', delay: 250, processResults: function (data) { return { results: $.map(data, function (item) { return { text: item.name, id: item.id } }) }; }, cache: true } }); $(document).on("click",".modalButton",function (e){ $("#overlayLoader").removeClass("d-flex"); $("#overlayLoader").addClass("d-flex"); $('.modal-body').html("
`+y.message+`