Browse Source

update price format ribuan, and format save to DB for price

pull/1/head
bnu 2 years ago
parent
commit
8567c15742
  1. 26
      src/function/function.js
  2. 15
      src/function/materialResource.js

26
src/function/function.js

@ -208,11 +208,37 @@ function updateActivity(id)
});
}
/* 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();

15
src/function/materialResource.js

@ -12,7 +12,19 @@ function resetFormAssignMaterial() {
// $("#hide-form-material").hide();
};
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),

Loading…
Cancel
Save