update print out
This commit is contained in:
@@ -33,25 +33,35 @@
|
||||
}
|
||||
|
||||
|
||||
function formatCurrency(value) {
|
||||
if (!value) return '';
|
||||
function formatCurrency(value, isDiskon = false) {
|
||||
// Konversi value ke string, pastikan bukan null/undefined
|
||||
let stringValue = value === null || value === undefined ? '' : String(value);
|
||||
|
||||
// Jika input adalah elemen, ambil nilainya
|
||||
const numericValue = typeof value === 'string' ? value : value.value;
|
||||
// Ganti koma dengan titik untuk memastikan parsing numerik
|
||||
stringValue = stringValue.replace(/,/g, '.');
|
||||
|
||||
// Hapus semua karakter non-digit
|
||||
const cleanValue = numericValue.toString().replace(/[^\d]/g, '');
|
||||
// Hapus karakter non-numerik kecuali titik
|
||||
let numericValue = stringValue.replace(/[^\d.]/g, '');
|
||||
|
||||
// Format ke currency
|
||||
const formattedValue = new Intl.NumberFormat('id-ID').format(cleanValue);
|
||||
// Parse nilai numerik
|
||||
const parsedValue = parseFloat(numericValue);
|
||||
|
||||
// Jika input adalah elemen, update nilainya
|
||||
if (typeof value !== 'string') {
|
||||
value.value = formattedValue;
|
||||
}
|
||||
|
||||
return formattedValue;
|
||||
if (isDiskon) {
|
||||
// Format untuk diskon
|
||||
return isNaN(parsedValue) ? '' : parsedValue.toLocaleString('id-ID', {
|
||||
minimumFractionDigits: 0,
|
||||
maximumFractionDigits: 2
|
||||
});
|
||||
} else {
|
||||
// Format untuk mata uang tanpa desimal
|
||||
return isNaN(parsedValue) ? '' : parsedValue.toLocaleString('id-ID', {
|
||||
minimumFractionDigits: 0,
|
||||
maximumFractionDigits: 0
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function previewImage(input, previewId) {
|
||||
if (input.files && input.files[0]) {
|
||||
|
||||
Reference in New Issue
Block a user