From 8567c15742cdc264108ab2a25b6553c5932413c5 Mon Sep 17 00:00:00 2001 From: bnu Date: Mon, 11 Jul 2022 23:46:07 +0700 Subject: [PATCH] update price format ribuan, and format save to DB for price --- src/function/function.js | 28 +++++++++++++++++++++++++++- src/function/materialResource.js | 17 ++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/function/function.js b/src/function/function.js index 8947df8..e449c1b 100644 --- a/src/function/function.js +++ b/src/function/function.js @@ -208,11 +208,37 @@ function updateActivity(id) }); } -function formatRupiah(n) { +/* Fungsi format ribuan label*/ +function formatRupiah(n) { var parts=n.toString().split("."); return parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".") + (parts[1] ? "," + parts[1] : ""); } +/* Fungsi format ribuan inputan*/ +function formatRibuanInput(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 ? 'Rp. ' + rupiah : ''); +} + +/* Fungsi replace titik, untuk save ke DB*/ +function formatReplaceTitikRibuan(param){ + let myStr = param; + let newStr = myStr.replace('.', ''); + return newStr; +} + function formatDate(params){ let today = new Date(params); let yyyy = today.getFullYear(); diff --git a/src/function/materialResource.js b/src/function/materialResource.js index 650d2be..687b190 100644 --- a/src/function/materialResource.js +++ b/src/function/materialResource.js @@ -12,7 +12,19 @@ function resetFormAssignMaterial() { // $("#hide-form-material").hide(); }; -$(document).ready(function () { + +var rupiah = document.getElementById('price-req-material'); + rupiah.addEventListener('keyup', function (e) { + rupiah.value = formatRibuanInput(this.value); + }); + +$(document).ready(function () { + // var rupiah = document.getElementById('price-req-material'); + // rupiah.addEventListener('keyup', function(e){ + // rupiah.value = formatRupiah(this.value, 'Rp. '); + // }); + + var tableMaterial = $("#table-material").DataTable({ "processing": true, "serverSide": true, @@ -134,7 +146,6 @@ $(document).ready(function () { let plan_date = $("#required-date-plan-material").val(); let uom = $("#uom-req-material").val(); let price = $("#price-req-material").val(); - let material_id = null; let payload = { @@ -144,7 +155,7 @@ $(document).ready(function () { proyek_id: proyekId, uom: uom, qty: qty_planning, - price: price + price: formatReplaceTitikRibuan(price) } $.ajax({ data: JSON.stringify(payload),