Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-04-20 10:19:02 +03:00
parent 8462df878f
commit 18c9a99a57
2 changed files with 49 additions and 11 deletions

View File

@@ -6,10 +6,36 @@ function toText (value) {
}
function toNumber (value) {
const n = Number(value)
const n = parseFlexibleNumber(value)
return Number.isFinite(n) ? Number(n.toFixed(2)) : 0
}
function parseFlexibleNumber (value) {
if (typeof value === 'number') return value
const text = String(value ?? '').trim().replace(/\s/g, '')
if (!text) return 0
const lastComma = text.lastIndexOf(',')
const lastDot = text.lastIndexOf('.')
let normalized = text
if (lastComma >= 0 && lastDot >= 0) {
// Keep the last separator as decimal, remove the other as thousand.
if (lastComma > lastDot) {
normalized = text.replace(/\./g, '').replace(',', '.')
} else {
normalized = text.replace(/,/g, '')
}
} else if (lastComma >= 0) {
normalized = text.replace(/\./g, '').replace(',', '.')
} else {
normalized = text.replace(/,/g, '')
}
const n = Number(normalized)
return Number.isFinite(n) ? n : 0
}
function mapRow (raw, index, baseIndex = 0) {
return {
id: baseIndex + index + 1,
@@ -137,7 +163,7 @@ export const useProductPricingStore = defineStore('product-pricing-store', {
updateCell (row, field, val) {
if (!row || !field) return
row[field] = toNumber(String(val ?? '').replace(',', '.'))
row[field] = toNumber(val)
},
updateBrandGroupSelection (row, val) {