fixed amount 2
This commit is contained in:
@@ -20,6 +20,8 @@ export interface Product {
|
|||||||
percent_fee_sell: number | undefined
|
percent_fee_sell: number | undefined
|
||||||
cash_fee_buy: number | undefined
|
cash_fee_buy: number | undefined
|
||||||
cash_fee_sell: number | undefined
|
cash_fee_sell: number | undefined
|
||||||
|
cash_fee_buy_is_percent?: boolean
|
||||||
|
cash_fee_sell_is_percent?: boolean
|
||||||
order_limit_enabled?: boolean
|
order_limit_enabled?: boolean
|
||||||
min_order_cash?: number | null
|
min_order_cash?: number | null
|
||||||
max_order_cash?: number | null
|
max_order_cash?: number | null
|
||||||
@@ -56,6 +58,8 @@ export interface PInventory {
|
|||||||
percent_fee_sell: number
|
percent_fee_sell: number
|
||||||
cash_fee_buy: number
|
cash_fee_buy: number
|
||||||
cash_fee_sell: number
|
cash_fee_sell: number
|
||||||
|
cash_fee_buy_is_percent?: boolean
|
||||||
|
cash_fee_sell_is_percent?: boolean
|
||||||
reading_method: any
|
reading_method: any
|
||||||
created_at: any
|
created_at: any
|
||||||
updated_at: any
|
updated_at: any
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
export type ProductCashFeeSource = {
|
||||||
|
cash_fee_buy?: number | null
|
||||||
|
cash_fee_sell?: number | null
|
||||||
|
cash_fee_buy_is_percent?: boolean | null
|
||||||
|
cash_fee_sell_is_percent?: boolean | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 5 => 5% ، 0.05 => 5% (اعشاری) */
|
||||||
|
export function resolveFeePercentRatio(percentValue?: number | null) {
|
||||||
|
const offset = Number(percentValue ?? 0)
|
||||||
|
if (!offset) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Math.abs(offset) > 0 && Math.abs(offset) < 1) {
|
||||||
|
return offset
|
||||||
|
}
|
||||||
|
|
||||||
|
return offset / 100
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveProductCashFeeRial(
|
||||||
|
feeValue: number | null | undefined,
|
||||||
|
isPercent: boolean | null | undefined,
|
||||||
|
basePriceRial: number,
|
||||||
|
) {
|
||||||
|
const raw = Number(feeValue ?? 0)
|
||||||
|
if (!raw || !Number.isFinite(raw)) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isPercent) {
|
||||||
|
return Math.round(raw)
|
||||||
|
}
|
||||||
|
|
||||||
|
const base = Number(basePriceRial)
|
||||||
|
if (!base || base <= 0) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.round(Math.abs(base * resolveFeePercentRatio(raw)))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveProductCashFeeBuyRial(product: ProductCashFeeSource, basePriceRial: number) {
|
||||||
|
return resolveProductCashFeeRial(
|
||||||
|
product.cash_fee_buy,
|
||||||
|
product.cash_fee_buy_is_percent,
|
||||||
|
basePriceRial,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveProductCashFeeSellRial(product: ProductCashFeeSource, basePriceRial: number) {
|
||||||
|
return resolveProductCashFeeRial(
|
||||||
|
product.cash_fee_sell,
|
||||||
|
product.cash_fee_sell_is_percent,
|
||||||
|
basePriceRial,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatProductCashFeeLabel(
|
||||||
|
feeValue: number | null | undefined,
|
||||||
|
isPercent?: boolean | null,
|
||||||
|
) {
|
||||||
|
const raw = Number(feeValue ?? 0)
|
||||||
|
if (!raw) {
|
||||||
|
return '۰'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPercent) {
|
||||||
|
return `${raw}%`
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${raw} ریال`
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
usesQuantityTrade,
|
usesQuantityTrade,
|
||||||
} from '@/utils/productCategories'
|
} from '@/utils/productCategories'
|
||||||
import { formatInventoryCardValue } from '@/utils/productAssets'
|
import { formatInventoryCardValue } from '@/utils/productAssets'
|
||||||
|
import { resolveProductCashFeeBuyRial, resolveProductCashFeeSellRial } from '@/utils/productCashFee'
|
||||||
import { TRADE_GRAM_DISPLAY_DECIMALS } from '@/utils/serviceFee'
|
import { TRADE_GRAM_DISPLAY_DECIMALS } from '@/utils/serviceFee'
|
||||||
import { formatGoldAmount } from '@/utils/usePrice'
|
import { formatGoldAmount } from '@/utils/usePrice'
|
||||||
|
|
||||||
@@ -371,7 +372,7 @@ export function resolveProductTradeBuyUnitPrice(product?: Product | null) {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const basePrice = (product.price ?? 0) + (product.cash_fee_buy ?? 0)
|
const basePrice = (product.price ?? 0) + resolveProductCashFeeBuyRial(product, product.price ?? 0)
|
||||||
return basePrice * productPriceAmountFactor(product)
|
return basePrice * productPriceAmountFactor(product)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,7 +381,7 @@ export function resolveProductTradeSellUnitPrice(product?: Product | null) {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const basePrice = (product.price ?? 0) - (product.cash_fee_sell ?? 0)
|
const basePrice = (product.price ?? 0) - resolveProductCashFeeSellRial(product, product.price ?? 0)
|
||||||
return basePrice * productPriceAmountFactor(product)
|
return basePrice * productPriceAmountFactor(product)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { Product } from '@/models/products'
|
import type { Product } from '@/models/products'
|
||||||
import { getTradeBuyPrice, getTradeSellPrice, lastPrice } from '@/utils/price'
|
import { getTradeBuyPrice, getTradeSellPrice, lastPrice } from '@/utils/price'
|
||||||
|
import { resolveProductCashFeeBuyRial, resolveProductCashFeeSellRial } from '@/utils/productCashFee'
|
||||||
import { isMetalCommodityGroup, isMeltedProductUsingAppPrice, isMeltedTradeGroup, usesQuantityTrade } from '@/utils/productCategories'
|
import { isMetalCommodityGroup, isMeltedProductUsingAppPrice, isMeltedTradeGroup, usesQuantityTrade } from '@/utils/productCategories'
|
||||||
import { productPriceAmountFactor } from '@/utils/productDealMethod'
|
import { productPriceAmountFactor } from '@/utils/productDealMethod'
|
||||||
|
|
||||||
@@ -104,7 +105,7 @@ export function getProductBuyPrice(product: Product): number {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const fee = Number(product.cash_fee_buy ?? 0)
|
const fee = resolveProductCashFeeBuyRial(product, base)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isMeltedProductUsingAppPrice(product)
|
isMeltedProductUsingAppPrice(product)
|
||||||
@@ -159,7 +160,7 @@ export function getProductSellPrice(product: Product): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isMeltedProductUsingAppPrice(product) || isMeltedTradeGroup(product.group_type) || usesQuantityTrade(product)) {
|
if (isMeltedProductUsingAppPrice(product) || isMeltedTradeGroup(product.group_type) || usesQuantityTrade(product)) {
|
||||||
return base - Number(product.cash_fee_sell ?? 0)
|
return base - resolveProductCashFeeSellRial(product, base)
|
||||||
}
|
}
|
||||||
|
|
||||||
return base
|
return base
|
||||||
|
|||||||
@@ -232,6 +232,7 @@ import type { Product } from '@/models/products'
|
|||||||
import { useFundUserStore } from '@/store/fundStore'
|
import { useFundUserStore } from '@/store/fundStore'
|
||||||
import {useConfigStore} from "@/store/configStore";
|
import {useConfigStore} from "@/store/configStore";
|
||||||
import { calcFeeInGrams, calcPayablePriceRial, calcSellGoldDebit, feeDeductFromGold, loadServiceFeeFromSettings } from '@/utils/serviceFee'
|
import { calcFeeInGrams, calcPayablePriceRial, calcSellGoldDebit, feeDeductFromGold, loadServiceFeeFromSettings } from '@/utils/serviceFee'
|
||||||
|
import { resolveProductCashFeeBuyRial, resolveProductCashFeeSellRial } from '@/utils/productCashFee'
|
||||||
import { formatCashWalletBalanceText, formatGoldWalletBalanceText } from '@/utils/productDealMethod'
|
import { formatCashWalletBalanceText, formatGoldWalletBalanceText } from '@/utils/productDealMethod'
|
||||||
import { getCashWalletBalance } from '@/utils/productAssets'
|
import { getCashWalletBalance } from '@/utils/productAssets'
|
||||||
import { isStoreClosed, getStoreClosedMessage } from '@/utils/storeHours'
|
import { isStoreClosed, getStoreClosedMessage } from '@/utils/storeHours'
|
||||||
@@ -283,13 +284,12 @@ const basePriceValue = computed(() => {
|
|||||||
const product = props?.ProductItem
|
const product = props?.ProductItem
|
||||||
if (!product) return undefined
|
if (!product) return undefined
|
||||||
|
|
||||||
const { price_profit = 0, price = 0, cash_fee_buy = 0, cash_fee_sell = 0 } = product
|
const { price_profit = 0, price = 0 } = product
|
||||||
const base = price_profit + price
|
const base = price_profit + price
|
||||||
|
const buyFee = resolveProductCashFeeBuyRial(product, base)
|
||||||
|
const sellFee = resolveProductCashFeeSellRial(product, base)
|
||||||
|
|
||||||
const rawPrice = isBuy.value
|
return isBuy.value ? base + buyFee : base - sellFee
|
||||||
? base + cash_fee_buy
|
|
||||||
: base - cash_fee_sell
|
|
||||||
return rawPrice
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const finalPrice = computed(() => {
|
const finalPrice = computed(() => {
|
||||||
@@ -299,15 +299,17 @@ const finalPrice = computed(() => {
|
|||||||
const product = props?.ProductItem
|
const product = props?.ProductItem
|
||||||
if (!product) return 0
|
if (!product) return 0
|
||||||
|
|
||||||
const { price_profit = 0, price = 0, cash_fee_buy = 0, cash_fee_sell = 0 } = product
|
const { price_profit = 0, price = 0 } = product
|
||||||
|
|
||||||
const base = price_profit + price
|
const base = price_profit + price
|
||||||
|
const buyFee = resolveProductCashFeeBuyRial(product, base)
|
||||||
|
const sellFee = resolveProductCashFeeSellRial(product, base)
|
||||||
|
|
||||||
if (isBuy.value) {
|
if (isBuy.value) {
|
||||||
return gold * (base + cash_fee_buy)
|
return gold * (base + buyFee)
|
||||||
} else {
|
|
||||||
return gold * (base - cash_fee_sell)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return gold * (base - sellFee)
|
||||||
})
|
})
|
||||||
|
|
||||||
const payablePrice = computed(() =>
|
const payablePrice = computed(() =>
|
||||||
@@ -533,20 +535,30 @@ watch(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
function productFeeBase(product?: Product) {
|
||||||
|
return (product?.price_profit ?? 0) + (product?.price ?? 0)
|
||||||
|
}
|
||||||
|
|
||||||
function calculateCash(val: number) {
|
function calculateCash(val: number) {
|
||||||
priceErrorVisible.value = false
|
priceErrorVisible.value = false
|
||||||
if (!lastPrice.value) return
|
if (!lastPrice.value) return
|
||||||
|
|
||||||
|
const product = props?.ProductItem
|
||||||
|
if (!product) return
|
||||||
|
|
||||||
|
const base = productFeeBase(product)
|
||||||
|
const buyFee = resolveProductCashFeeBuyRial(product, base)
|
||||||
|
const sellFee = resolveProductCashFeeSellRial(product, base)
|
||||||
const tradeBuy = getTradeBuyPrice(lastPrice.value)
|
const tradeBuy = getTradeBuyPrice(lastPrice.value)
|
||||||
form.value.goldVazn = parseFloat((val * ((props?.ProductItem?.price) + (props?.ProductItem?.cash_fee_buy))) / tradeBuy).toFixed(1)
|
form.value.goldVazn = parseFloat(String((val * (base + buyFee)) / tradeBuy)).toFixed(1)
|
||||||
if (isBuy.value) {
|
if (isBuy.value) {
|
||||||
form.value.goldCash = val
|
form.value.goldCash = val
|
||||||
? parseFloat(String(val * ((props?.ProductItem?.price) + (props?.ProductItem?.cash_fee_buy))))
|
? parseFloat(String(val * (base + buyFee)))
|
||||||
: 0
|
: 0
|
||||||
if (!val) form.value.goldVazn = 0
|
if (!val) form.value.goldVazn = 0
|
||||||
} else {
|
} else {
|
||||||
form.value.goldCash = val
|
form.value.goldCash = val
|
||||||
? parseFloat(String((val * props?.ProductItem?.price) - (props?.ProductItem?.cash_fee_sell)))
|
? parseFloat(String(val * base - sellFee))
|
||||||
: 0
|
: 0
|
||||||
if (!val) form.value.goldVazn = 0
|
if (!val) form.value.goldVazn = 0
|
||||||
}
|
}
|
||||||
@@ -554,9 +566,16 @@ function calculateCash(val: number) {
|
|||||||
|
|
||||||
function calculateGold(val: number) {
|
function calculateGold(val: number) {
|
||||||
if (price.value) {
|
if (price.value) {
|
||||||
|
const product = props?.ProductItem
|
||||||
|
if (!product) return
|
||||||
|
|
||||||
|
const base = productFeeBase(product)
|
||||||
|
const buyFee = resolveProductCashFeeBuyRial(product, base)
|
||||||
|
const sellFee = resolveProductCashFeeSellRial(product, base)
|
||||||
|
|
||||||
if (isBuy.value) {
|
if (isBuy.value) {
|
||||||
if (val) {
|
if (val) {
|
||||||
form.value.goldValue = toFixedDownThreeChar(parseFloat(val / (((props?.ProductItem?.price_profit) + (props?.ProductItem?.price)) + (props?.ProductItem?.cash_fee_buy))))
|
form.value.goldValue = toFixedDownThreeChar(parseFloat(String(val / (base + buyFee))))
|
||||||
if (parseInt(finalPrice.value) > 0) priceErrorVisible.value = true
|
if (parseInt(finalPrice.value) > 0) priceErrorVisible.value = true
|
||||||
if (parseInt(finalPrice.value) === 0) priceErrorVisible.value = false
|
if (parseInt(finalPrice.value) === 0) priceErrorVisible.value = false
|
||||||
}
|
}
|
||||||
@@ -571,7 +590,7 @@ function calculateGold(val: number) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (val) {
|
if (val) {
|
||||||
form.value.goldValue = toFixedDownThreeChar(parseFloat(val / (((props?.ProductItem?.price_profit) + (props?.ProductItem?.price)) + (props?.ProductItem?.cash_fee_sell))))
|
form.value.goldValue = toFixedDownThreeChar(parseFloat(String(val / (base - sellFee))))
|
||||||
if (parseInt(finalPrice.value) > 0) priceErrorVisible.value = true
|
if (parseInt(finalPrice.value) > 0) priceErrorVisible.value = true
|
||||||
if (parseInt(finalPrice.value) === 0) priceErrorVisible.value = false
|
if (parseInt(finalPrice.value) === 0) priceErrorVisible.value = false
|
||||||
} else if (val.toString() === '') {
|
} else if (val.toString() === '') {
|
||||||
|
|||||||
@@ -281,6 +281,7 @@ import type { TableEngineInput, TableOutput } from '@/models/table'
|
|||||||
import { getTransactionTable } from '@/api/transaction'
|
import { getTransactionTable } from '@/api/transaction'
|
||||||
import { getLastPrices, getTradeBuyPrice, getTradeSellPrice, lastPrice, setIntervalGetAllPrice, stopPriceInterval } from '@/utils/price'
|
import { getLastPrices, getTradeBuyPrice, getTradeSellPrice, lastPrice, setIntervalGetAllPrice, stopPriceInterval } from '@/utils/price'
|
||||||
import { getProductBuyPrice, getProductSellPrice, isProductPriceInactive } from '@/utils/productPrice'
|
import { getProductBuyPrice, getProductSellPrice, isProductPriceInactive } from '@/utils/productPrice'
|
||||||
|
import { resolveProductCashFeeBuyRial, resolveProductCashFeeSellRial } from '@/utils/productCashFee'
|
||||||
import { Product } from '@/models/products'
|
import { Product } from '@/models/products'
|
||||||
import BasicSelect from '@/components/BasicPacks/BasicSelect.vue'
|
import BasicSelect from '@/components/BasicPacks/BasicSelect.vue'
|
||||||
import Bg_main from '@/components/bg_main.vue'
|
import Bg_main from '@/components/bg_main.vue'
|
||||||
@@ -402,22 +403,9 @@ interface Prop {
|
|||||||
const props = withDefaults(defineProps<Prop>(), {})
|
const props = withDefaults(defineProps<Prop>(), {})
|
||||||
const emit = defineEmits<{ ordered: [] }>()
|
const emit = defineEmits<{ ordered: [] }>()
|
||||||
const isBuy = ref<boolean>(true)
|
const isBuy = ref<boolean>(true)
|
||||||
const buyTotalPrice = computed(() => {
|
const buyTotalPrice = computed(() => resolveProductTradeBuyUnitPrice(props?.ProductItem))
|
||||||
const item = props?.ProductItem
|
|
||||||
if (!item) return 0
|
|
||||||
const basePrice = (item.price ?? 0) + (item.cash_fee_buy ?? 0)
|
|
||||||
|
|
||||||
return basePrice * productPriceAmountFactor(item)
|
const sellTotalPrice = computed(() => resolveProductTradeSellUnitPrice(props?.ProductItem))
|
||||||
})
|
|
||||||
|
|
||||||
const sellTotalPrice = computed(() => {
|
|
||||||
const item = props?.ProductItem
|
|
||||||
if (!item) return 0
|
|
||||||
|
|
||||||
const basePrice = (item.price ?? 0) - (item.cash_fee_sell ?? 0)
|
|
||||||
|
|
||||||
return basePrice * productPriceAmountFactor(item)
|
|
||||||
})
|
|
||||||
const buyFee = computed(() => ((props?.ProductItem?.amount * (props?.ProductItem?.percent_fee_buy ?? 0) * (props?.ProductItem?.price ?? 0)).toFixed(0)))
|
const buyFee = computed(() => ((props?.ProductItem?.amount * (props?.ProductItem?.percent_fee_buy ?? 0) * (props?.ProductItem?.price ?? 0)).toFixed(0)))
|
||||||
const sellFee = computed(() => ((props?.ProductItem?.amount * (props?.ProductItem?.percent_fee_sell ?? 0) * (props?.ProductItem?.sellPrice ?? 0)).toFixed(0)))
|
const sellFee = computed(() => ((props?.ProductItem?.amount * (props?.ProductItem?.percent_fee_sell ?? 0) * (props?.ProductItem?.sellPrice ?? 0)).toFixed(0)))
|
||||||
|
|
||||||
@@ -738,7 +726,8 @@ function calculateCash(val: number) {
|
|||||||
// form.value.goldVazn = parseFloat((val * (( props?.ProductItem?.price) + (props?.ProductItem?.cash_fee_buy)))/lastPrice.value?.buy).toFixed(2)
|
// form.value.goldVazn = parseFloat((val * (( props?.ProductItem?.price) + (props?.ProductItem?.cash_fee_buy)))/lastPrice.value?.buy).toFixed(2)
|
||||||
if (isBuy.value) {
|
if (isBuy.value) {
|
||||||
if (val){
|
if (val){
|
||||||
const unitPrice = (props?.ProductItem?.price ?? 0) + (props?.ProductItem?.cash_fee_buy ?? 0)
|
const base = props?.ProductItem?.price ?? 0
|
||||||
|
const unitPrice = base + resolveProductCashFeeBuyRial(props?.ProductItem, base)
|
||||||
form.value.goldCash = parseFloat(String(val * unitPrice * productPriceAmountFactor(props?.ProductItem))).toFixed(0)
|
form.value.goldCash = parseFloat(String(val * unitPrice * productPriceAmountFactor(props?.ProductItem))).toFixed(0)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -748,7 +737,8 @@ function calculateCash(val: number) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (val){
|
if (val){
|
||||||
const unitPrice = (props?.ProductItem?.price ?? 0) - (props?.ProductItem?.cash_fee_sell ?? 0)
|
const base = props?.ProductItem?.price ?? 0
|
||||||
|
const unitPrice = base - resolveProductCashFeeSellRial(props?.ProductItem, base)
|
||||||
form.value.goldCash = parseFloat(String(val * unitPrice * productPriceAmountFactor(props?.ProductItem))).toFixed(0)
|
form.value.goldCash = parseFloat(String(val * unitPrice * productPriceAmountFactor(props?.ProductItem))).toFixed(0)
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@@ -839,8 +829,11 @@ async function initPrice() {
|
|||||||
await getLastPrices()
|
await getLastPrices()
|
||||||
// await setIntervalGetPrice()
|
// await setIntervalGetPrice()
|
||||||
loading.value = true
|
loading.value = true
|
||||||
props.ProductItem.price = lastPrice?.value?.price? (lastPrice?.value?.price + props.ProductItem?.cash_fee_buy) * props.ProductItem?.amount: 0
|
const livePrice = lastPrice?.value?.price ?? 0
|
||||||
props.ProductItem.sellPrice = lastPrice?.value?.price? (lastPrice?.value?.price - props.ProductItem?.percent_fee_sell) * props.ProductItem?.amount:0
|
const buyFee = resolveProductCashFeeBuyRial(props.ProductItem, livePrice)
|
||||||
|
const sellFee = resolveProductCashFeeSellRial(props.ProductItem, livePrice)
|
||||||
|
props.ProductItem.price = livePrice ? (livePrice + buyFee) * props.ProductItem.amount : 0
|
||||||
|
props.ProductItem.sellPrice = livePrice ? (livePrice - sellFee) * props.ProductItem.amount : 0
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user