added percent in product fee 4
This commit is contained in:
@@ -89,6 +89,7 @@ import {
|
||||
unwrapApiRecord
|
||||
} from '@/utils/file'
|
||||
import { normalizeProductOrderLimitForm, validateProductOrderLimitForm } from '@/utils/productOrderLimit'
|
||||
import { normalizeCashFeeFlags, parseCashFeeValue } from '@/utils/productCashFee'
|
||||
import {
|
||||
isMeltedTradeGroup,
|
||||
resolveMeltedPriceSource,
|
||||
@@ -299,13 +300,11 @@ async function edit(record: Product) {
|
||||
editId = record.id
|
||||
let productData = cloneDeep(record) as Record<string, any>
|
||||
|
||||
if (!pickRawFileFromRecord(productData) && productData.file_id) {
|
||||
try {
|
||||
const detail = unwrapApiRecord(await getCustomerById(record.id))
|
||||
if (detail) productData = { ...productData, ...detail }
|
||||
} catch {
|
||||
/* use table row data */
|
||||
}
|
||||
try {
|
||||
const detail = unwrapApiRecord(await getCustomerById(record.id))
|
||||
if (detail) productData = { ...productData, ...detail }
|
||||
} catch {
|
||||
/* use table row data */
|
||||
}
|
||||
|
||||
methodOption.value = productData.reading_method ? '2' : '1'
|
||||
@@ -338,8 +337,10 @@ async function edit(record: Product) {
|
||||
show_in_assets: productData.show_in_assets ?? false,
|
||||
trade_by_quantity: productData.trade_by_quantity ?? false,
|
||||
override_trading_hours: productData.override_trading_hours ?? false,
|
||||
cash_fee_buy_is_percent: productData.cash_fee_buy_is_percent ?? false,
|
||||
cash_fee_sell_is_percent: productData.cash_fee_sell_is_percent ?? false,
|
||||
cash_fee_buy: parseCashFeeValue(productData.cash_fee_buy),
|
||||
cash_fee_sell: parseCashFeeValue(productData.cash_fee_sell),
|
||||
cash_fee_buy_is_percent: normalizeCashFeeFlags(productData.cash_fee_buy_is_percent),
|
||||
cash_fee_sell_is_percent: normalizeCashFeeFlags(productData.cash_fee_sell_is_percent),
|
||||
price_offset_percent: productData.price_offset_percent ?? 0,
|
||||
direct_price: productData.direct_price ?? 0,
|
||||
auto_open_at: start.isValid() ? start : dayjs('00:00:00', 'HH:mm:ss'),
|
||||
@@ -456,10 +457,10 @@ async function saveProduct() {
|
||||
return
|
||||
}
|
||||
|
||||
payload.cash_fee_buy = payload.cash_fee_buy ?? 0
|
||||
payload.cash_fee_sell = payload.cash_fee_sell ?? 0
|
||||
payload.cash_fee_buy_is_percent = Boolean(payload.cash_fee_buy_is_percent)
|
||||
payload.cash_fee_sell_is_percent = Boolean(payload.cash_fee_sell_is_percent)
|
||||
payload.cash_fee_buy = parseCashFeeValue(payload.cash_fee_buy)
|
||||
payload.cash_fee_sell = parseCashFeeValue(payload.cash_fee_sell)
|
||||
payload.cash_fee_buy_is_percent = normalizeCashFeeFlags(payload.cash_fee_buy_is_percent)
|
||||
payload.cash_fee_sell_is_percent = normalizeCashFeeFlags(payload.cash_fee_sell_is_percent)
|
||||
|
||||
if (usesMeltedPriceEditor(payload)) {
|
||||
if (isMeltedTradeGroup(payload.group_type)) {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/** پارس مقدار هزینه خرید/فروش (نقدی یا درصدی) قبل از ارسال به API */
|
||||
export function parseCashFeeValue(value: unknown): number {
|
||||
if (value === undefined || value === null) {
|
||||
return 0
|
||||
}
|
||||
|
||||
const raw = String(value).trim().replaceAll(',', '')
|
||||
if (raw === '') {
|
||||
return 0
|
||||
}
|
||||
|
||||
const num = Number(raw)
|
||||
return Number.isFinite(num) ? num : 0
|
||||
}
|
||||
|
||||
export function normalizeCashFeeFlags(value: unknown): boolean {
|
||||
if (value === true || value === 1 || value === '1' || value === 'true') {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
export function formatAdminCashFeeLabel(
|
||||
value: number | null | undefined,
|
||||
isPercent?: boolean | null,
|
||||
) {
|
||||
const raw = Number(value ?? 0)
|
||||
if (!raw) {
|
||||
return '۰'
|
||||
}
|
||||
|
||||
if (isPercent) {
|
||||
return `${raw}%`
|
||||
}
|
||||
|
||||
return String(raw)
|
||||
}
|
||||
Reference in New Issue
Block a user