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:
2026-08-17 13:10:59 +03:30
co-authored by Cursor
parent 8636fd1aea
commit 7440a53c80
6 changed files with 180 additions and 13 deletions
+1
View File
@@ -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, '.')
+7 -3
View File
@@ -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 {