feat(admin): signed profit/discount fields for special price packages
Let buy/sell extras be entered as profit or discount so negative values work in the editor and table. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -27,6 +27,7 @@ export function sanitizeNumericString(
|
||||
const allowDecimal = options.allowDecimal !== false
|
||||
let s = persian2english(String(raw ?? '').trim())
|
||||
.replace(/[٬,\s]/g, '')
|
||||
.replace(/[−–—]/g, '-')
|
||||
.replace(/٫/g, '.')
|
||||
.replace(/\//g, '.')
|
||||
|
||||
|
||||
@@ -2,11 +2,15 @@ import { persian2english, parseNumericValue, sanitizeNumericString } from '@core
|
||||
|
||||
export function usePrice(price: number | string, digit = true, unit = 'ریال') {
|
||||
const n = typeof price === 'number' ? price : parseNumericValue(price)
|
||||
let _price = Number.isFinite(n) ? String(n) : persian2english(String(price ?? ''))
|
||||
if (digit && Number.isFinite(n)) {
|
||||
const finite = Number.isFinite(n)
|
||||
const sign = finite && n < 0 ? '-' : ''
|
||||
const abs = finite ? Math.abs(n) : NaN
|
||||
let _price = finite ? String(abs) : persian2english(String(price ?? ''))
|
||||
if (digit && Number.isFinite(abs)) {
|
||||
_price = _price.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
||||
}
|
||||
return `${_price} ${unit}`
|
||||
const shown = finite ? `${sign}${_price}` : _price
|
||||
return unit ? `${shown} ${unit}` : shown
|
||||
}
|
||||
|
||||
export function useTowDecimal(num: string | number): string | number {
|
||||
|
||||
Reference in New Issue
Block a user