fix product price
This commit is contained in:
@@ -84,8 +84,20 @@ export function hasProductUnitWeight(product?: ProductUnitSource | null) {
|
|||||||
return amount > 0
|
return amount > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ضریب قیمت — محصول بدون وزن قطعه همیشه ۱ */
|
/** ضریب قیمت — فقط «متغیر» بدون مرجع اتوماتیک: قیمت هر گرم × وزن */
|
||||||
export function productPriceAmountFactor(product?: ProductUnitSource | null) {
|
export function productPriceAmountFactor(product?: ProductUnitSource | null) {
|
||||||
|
if (product?.reading_method) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCountBasedProduct(product)) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Number(product?.direct_price ?? 0) !== 0) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
if (hasProductUnitWeight(product)) {
|
if (hasProductUnitWeight(product)) {
|
||||||
const amount = Number(product?.amount ?? 0)
|
const amount = Number(product?.amount ?? 0)
|
||||||
return amount > 0 ? amount : 1
|
return amount > 0 ? amount : 1
|
||||||
@@ -358,9 +370,7 @@ export function resolveProductTradeBuyUnitPrice(product?: Product | null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const basePrice = (product.price ?? 0) + (product.cash_fee_buy ?? 0)
|
const basePrice = (product.price ?? 0) + (product.cash_fee_buy ?? 0)
|
||||||
return product.direct_price === 0
|
return basePrice * productPriceAmountFactor(product)
|
||||||
? basePrice * (product.amount ?? 0)
|
|
||||||
: basePrice
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveProductTradeSellUnitPrice(product?: Product | null) {
|
export function resolveProductTradeSellUnitPrice(product?: Product | null) {
|
||||||
@@ -369,9 +379,7 @@ export function resolveProductTradeSellUnitPrice(product?: Product | null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const basePrice = (product.price ?? 0) - (product.cash_fee_sell ?? 0)
|
const basePrice = (product.price ?? 0) - (product.cash_fee_sell ?? 0)
|
||||||
return product.direct_price === 0
|
return basePrice * productPriceAmountFactor(product)
|
||||||
? basePrice * (product.amount ?? 0)
|
|
||||||
: basePrice
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDefaultTypeDealOptions(context?: ProductDealMethodContext | null, isBuy = true): SelectItem[] {
|
function getDefaultTypeDealOptions(context?: ProductDealMethodContext | null, isBuy = true): SelectItem[] {
|
||||||
|
|||||||
@@ -116,9 +116,7 @@ export function getProductBuyPrice(product: Product): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const withFee = base + fee
|
const withFee = base + fee
|
||||||
return product.direct_price === 0
|
return withFee * productPriceAmountFactor(product)
|
||||||
? withFee * productPriceAmountFactor(product)
|
|
||||||
: withFee
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getProductBaseSellPrice(product: Product): number {
|
function getProductBaseSellPrice(product: Product): number {
|
||||||
|
|||||||
@@ -306,6 +306,7 @@ import {
|
|||||||
shouldShowProductDealMethodSelect,
|
shouldShowProductDealMethodSelect,
|
||||||
resolveProductTradeBuyUnitPrice,
|
resolveProductTradeBuyUnitPrice,
|
||||||
resolveProductTradeSellUnitPrice,
|
resolveProductTradeSellUnitPrice,
|
||||||
|
productPriceAmountFactor,
|
||||||
formatProductWeightAmount,
|
formatProductWeightAmount,
|
||||||
getProductQuantityUnit,
|
getProductQuantityUnit,
|
||||||
getProductTotalWeightLabel,
|
getProductTotalWeightLabel,
|
||||||
@@ -409,9 +410,7 @@ const buyTotalPrice = computed(() => {
|
|||||||
if (!item) return 0
|
if (!item) return 0
|
||||||
const basePrice = (item.price ?? 0) + (item.cash_fee_buy ?? 0)
|
const basePrice = (item.price ?? 0) + (item.cash_fee_buy ?? 0)
|
||||||
|
|
||||||
return item.direct_price === 0
|
return basePrice * productPriceAmountFactor(item)
|
||||||
? basePrice * (item.amount ?? 0)
|
|
||||||
: basePrice
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const sellTotalPrice = computed(() => {
|
const sellTotalPrice = computed(() => {
|
||||||
@@ -420,9 +419,7 @@ const sellTotalPrice = computed(() => {
|
|||||||
|
|
||||||
const basePrice = (item.price ?? 0) - (item.cash_fee_sell ?? 0)
|
const basePrice = (item.price ?? 0) - (item.cash_fee_sell ?? 0)
|
||||||
|
|
||||||
return item.direct_price === 0
|
return basePrice * productPriceAmountFactor(item)
|
||||||
? basePrice * (item.amount ?? 0)
|
|
||||||
: basePrice
|
|
||||||
})
|
})
|
||||||
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)))
|
||||||
@@ -758,12 +755,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){
|
||||||
if(props?.ProductItem?.direct_price === 0){
|
const unitPrice = (props?.ProductItem?.price ?? 0) + (props?.ProductItem?.cash_fee_buy ?? 0)
|
||||||
form.value.goldCash = parseFloat(val * props?.ProductItem?.amount * (props?.ProductItem?.price + props?.ProductItem?.cash_fee_buy)).toFixed(0)
|
form.value.goldCash = parseFloat(String(val * unitPrice * productPriceAmountFactor(props?.ProductItem))).toFixed(0)
|
||||||
}
|
|
||||||
else {
|
|
||||||
form.value.goldCash = parseFloat(val * (props?.ProductItem?.price + props?.ProductItem?.cash_fee_buy)).toFixed(0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
form.value.goldCash = 0
|
form.value.goldCash = 0
|
||||||
@@ -772,13 +765,8 @@ function calculateCash(val: number) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (val){
|
if (val){
|
||||||
if(props?.ProductItem?.direct_price === 0){
|
const unitPrice = (props?.ProductItem?.price ?? 0) - (props?.ProductItem?.cash_fee_sell ?? 0)
|
||||||
form.value.goldCash = parseFloat(val * props?.ProductItem?.amount * (props?.ProductItem?.price - props?.ProductItem?.cash_fee_sell)).toFixed(0)
|
form.value.goldCash = parseFloat(String(val * unitPrice * productPriceAmountFactor(props?.ProductItem))).toFixed(0)
|
||||||
}
|
|
||||||
else{
|
|
||||||
form.value.goldCash = parseFloat(val * (props?.ProductItem?.price - props?.ProductItem?.cash_fee_sell)).toFixed(0)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
form.value.goldCash = 0
|
form.value.goldCash = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user