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

@@ -702,10 +702,26 @@ function round2 (value) {
} }
function parseNumber (val) { function parseNumber (val) {
const normalized = String(val ?? '') if (typeof val === 'number') return Number.isFinite(val) ? val : 0
.replace(/\s/g, '') const text = String(val ?? '').trim().replace(/\s/g, '')
.replace(/\./g, '') if (!text) return 0
.replace(',', '.')
const lastComma = text.lastIndexOf(',')
const lastDot = text.lastIndexOf('.')
let normalized = text
if (lastComma >= 0 && lastDot >= 0) {
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) const n = Number(normalized)
return Number.isFinite(n) ? n : 0 return Number.isFinite(n) ? n : 0
} }
@@ -713,11 +729,7 @@ function parseNumber (val) {
function parseNullableNumber (val) { function parseNullableNumber (val) {
const text = String(val ?? '').trim() const text = String(val ?? '').trim()
if (!text) return null if (!text) return null
const normalized = text const n = parseNumber(text)
.replace(/\s/g, '')
.replace(/\./g, '')
.replace(',', '.')
const n = Number(normalized)
return Number.isFinite(n) ? n : null return Number.isFinite(n) ? n : null
} }

View File

@@ -6,10 +6,36 @@ function toText (value) {
} }
function toNumber (value) { function toNumber (value) {
const n = Number(value) const n = parseFlexibleNumber(value)
return Number.isFinite(n) ? Number(n.toFixed(2)) : 0 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) { function mapRow (raw, index, baseIndex = 0) {
return { return {
id: baseIndex + index + 1, id: baseIndex + index + 1,
@@ -137,7 +163,7 @@ export const useProductPricingStore = defineStore('product-pricing-store', {
updateCell (row, field, val) { updateCell (row, field, val) {
if (!row || !field) return if (!row || !field) return
row[field] = toNumber(String(val ?? '').replace(',', '.')) row[field] = toNumber(val)
}, },
updateBrandGroupSelection (row, val) { updateBrandGroupSelection (row, val) {