fix: removed df parameter and added format parameter
This commit is contained in:
parent
90bf761eb3
commit
eb5d362e00
@ -28,13 +28,13 @@ export function getMeta(doctype) {
|
|||||||
function getFormattedFloat(fieldname, doc) {
|
function getFormattedFloat(fieldname, doc) {
|
||||||
let df = doctypeMeta[doctype]?.fields.find((f) => f.fieldname == fieldname)
|
let df = doctypeMeta[doctype]?.fields.find((f) => f.fieldname == fieldname)
|
||||||
let precision = df?.precision || null
|
let precision = df?.precision || null
|
||||||
return formatNumber(doc[fieldname], "", precision)
|
return formatNumber(doc[fieldname], '', precision)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFormattedCurrency(fieldname, doc) {
|
function getFormattedCurrency(fieldname, doc) {
|
||||||
let currency = window.sysdefaults.currency || 'USD'
|
let currency = window.sysdefaults.currency || 'USD'
|
||||||
|
|
||||||
let df = doctypeMeta[doctype]?.fields.find((f) => f.fieldname == fieldname)
|
let df = doctypeMeta[doctype]?.fields.find((f) => f.fieldname == fieldname)
|
||||||
|
let precision = df?.precision || null
|
||||||
|
|
||||||
if (df && df.options) {
|
if (df && df.options) {
|
||||||
if (df.options.indexOf(':') != -1) {
|
if (df.options.indexOf(':') != -1) {
|
||||||
@ -44,7 +44,7 @@ export function getMeta(doctype) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatCurrency(doc[fieldname], df, currency)
|
return formatCurrency(doc[fieldname], '', currency, precision)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import { get } from '@vueuse/core'
|
||||||
|
|
||||||
const NUMBER_FORMAT_INFO = {
|
const NUMBER_FORMAT_INFO = {
|
||||||
'#,###.##': { decimalStr: '.', groupSep: ',' },
|
'#,###.##': { decimalStr: '.', groupSep: ',' },
|
||||||
'#.###,##': { decimalStr: ',', groupSep: '.' },
|
'#.###,##': { decimalStr: ',', groupSep: '.' },
|
||||||
@ -159,14 +161,11 @@ export function formatNumber(v, format, decimals) {
|
|||||||
return (isNegative ? '-' : '') + part[0] + part[1]
|
return (isNegative ? '-' : '') + part[0] + part[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatCurrency(value, df, currency = 'USD') {
|
export function formatCurrency(value, format, currency = 'USD', precision = 2) {
|
||||||
if (!value || !df) return ''
|
value = value == null || value === '' ? 0 : value
|
||||||
|
|
||||||
let precision
|
if (typeof precision != 'number') {
|
||||||
if (typeof df.precision == 'number') {
|
precision = cint(precision || window.sysdefaults.currency_precision || 2)
|
||||||
precision = df.precision
|
|
||||||
} else {
|
|
||||||
precision = cint(df.precision || window.sysdefaults.currency_precision || 2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If you change anything below, it's going to hurt a company in UAE, a bit.
|
// If you change anything below, it's going to hurt a company in UAE, a bit.
|
||||||
@ -183,9 +182,7 @@ export function formatCurrency(value, df, currency = 'USD') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
value = value == null || value === '' ? '' : value
|
format = getNumberFormat(format)
|
||||||
|
|
||||||
let format = getNumberFormat()
|
|
||||||
let symbol = getCurrencySymbol(currency)
|
let symbol = getCurrencySymbol(currency)
|
||||||
|
|
||||||
if (symbol) {
|
if (symbol) {
|
||||||
@ -195,6 +192,10 @@ export function formatCurrency(value, df, currency = 'USD') {
|
|||||||
return formatNumber(value, format, precision)
|
return formatNumber(value, format, precision)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getNumberFormat(format = null) {
|
||||||
|
return format || window.sysdefaults.number_format || '#,###.##'
|
||||||
|
}
|
||||||
|
|
||||||
function getCurrencySymbol(currencyCode) {
|
function getCurrencySymbol(currencyCode) {
|
||||||
try {
|
try {
|
||||||
const formatter = new Intl.NumberFormat('en-US', {
|
const formatter = new Intl.NumberFormat('en-US', {
|
||||||
@ -213,10 +214,6 @@ function getCurrencySymbol(currencyCode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNumberFormat() {
|
|
||||||
return window.sysdefaults.number_format || '#,###.##'
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNumberFormatInfo(format) {
|
function getNumberFormatInfo(format) {
|
||||||
let info = NUMBER_FORMAT_INFO[format]
|
let info = NUMBER_FORMAT_INFO[format]
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user