price calulator changed 8
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
|||||||
usesQuantityTrade,
|
usesQuantityTrade,
|
||||||
} from '@/utils/productCategories'
|
} from '@/utils/productCategories'
|
||||||
import { formatInventoryCardValue } from '@/utils/productAssets'
|
import { formatInventoryCardValue } from '@/utils/productAssets'
|
||||||
|
import { formatGoldAmount } from '@/utils/usePrice'
|
||||||
|
|
||||||
/** @deprecated از isMeltedTradeGroup استفاده کنید */
|
/** @deprecated از isMeltedTradeGroup استفاده کنید */
|
||||||
export const BOURSECU_GROUP_ABSHODE = PRODUCT_CATEGORY_ABSHODE
|
export const BOURSECU_GROUP_ABSHODE = PRODUCT_CATEGORY_ABSHODE
|
||||||
@@ -635,6 +636,59 @@ export function resolveTransactionTradeProduct(
|
|||||||
return item.wallet?.product ?? null
|
return item.wallet?.product ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MELTED_GOLD_TRANSACTION_DECIMALS = 5
|
||||||
|
|
||||||
|
/** معامله آبشده / کیف طلای اصلی — نه سکه و محصول تعدادی */
|
||||||
|
export function isMeltedGoldTransaction(
|
||||||
|
item?: (TransactionTradeProductSource & { type?: number | null; title?: string | null }) | null,
|
||||||
|
): boolean {
|
||||||
|
if (!item) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const tradeProduct = resolveTransactionTradeProduct(item)
|
||||||
|
if (tradeProduct) {
|
||||||
|
if (usesQuantityTrade(tradeProduct) && !isMeltedTradeGroup(tradeProduct.group_type)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (isMeltedTradeGroup(tradeProduct.group_type)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if (isCountBasedProduct(tradeProduct)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = (item.title ?? '').trim()
|
||||||
|
const meltedLabel = getMeltedGoldTradeLabel()
|
||||||
|
if (title.includes(PRODUCT_CATEGORY_ABSHODE) || (meltedLabel && title.includes(meltedLabel))) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.type !== 1 && item.type !== 2) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMeltedTradeGroup(item.wallet?.product?.group_type)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const tradeTitle = (tradeProduct?.title ?? '').trim()
|
||||||
|
if (tradeTitle === meltedLabel || tradeTitle.includes(PRODUCT_CATEGORY_ABSHODE)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return !item.wallet?.product && !tradeTitle
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatTransactionGoldAmount(
|
||||||
|
item?: (TransactionTradeProductSource & { type?: number | null; title?: string | null }) | null,
|
||||||
|
amount?: number | null,
|
||||||
|
): string {
|
||||||
|
const decimals = isMeltedGoldTransaction(item) ? MELTED_GOLD_TRANSACTION_DECIMALS : 3
|
||||||
|
return formatGoldAmount(amount, decimals)
|
||||||
|
}
|
||||||
|
|
||||||
/** برچسب قیمت حین معامله — نام و واحد همان محصول معاملهشده */
|
/** برچسب قیمت حین معامله — نام و واحد همان محصول معاملهشده */
|
||||||
export function getTransactionTradePriceLabel(product?: (ProductUnitSource & { title?: string | null }) | null) {
|
export function getTransactionTradePriceLabel(product?: (ProductUnitSource & { title?: string | null }) | null) {
|
||||||
if (!product) {
|
if (!product) {
|
||||||
|
|||||||
@@ -143,10 +143,10 @@ export function getTransactionGoldAmount(item: TransactionPriceSource): number {
|
|||||||
return gold
|
return gold
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatGoldAmount(amount?: number | null): string {
|
export function formatGoldAmount(amount?: number | null, decimals = 3): string {
|
||||||
const num = Number(amount)
|
const num = Number(amount)
|
||||||
if (!Number.isFinite(num)) return '0'
|
if (!Number.isFinite(num)) return '0'
|
||||||
return formatGroupedPrice(Number(num.toFixed(3)), false)
|
return formatGroupedPrice(Number(num.toFixed(decimals)), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** وزن فلز (گرم/کیلو) — بدون گرد کردن به بالا (برخلاف usePriceWithoutType) */
|
/** وزن فلز (گرم/کیلو) — بدون گرد کردن به بالا (برخلاف usePriceWithoutType) */
|
||||||
|
|||||||
@@ -214,7 +214,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<BasicButton class="mb-20 mt-5 w-full" type="primary" @click="ok(); confirmAction= false">ثبت نهایی</BasicButton>
|
<BasicButton
|
||||||
|
class="mb-20 mt-5 w-full"
|
||||||
|
type="primary"
|
||||||
|
:disabled="loading"
|
||||||
|
@click="ok"
|
||||||
|
>
|
||||||
|
ثبت نهایی
|
||||||
|
</BasicButton>
|
||||||
</BasicActionSheet>
|
</BasicActionSheet>
|
||||||
<BasicModal
|
<BasicModal
|
||||||
v-else
|
v-else
|
||||||
@@ -269,7 +276,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<BasicButton class="mt-5 w-full" type="primary" @click="ok(); confirmAction = false">
|
<BasicButton class="mt-5 w-full" type="primary" :disabled="loading" @click="ok">
|
||||||
ثبت نهایی
|
ثبت نهایی
|
||||||
</BasicButton>
|
</BasicButton>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
@@ -794,6 +801,9 @@ function okConfirm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function ok() {
|
async function ok() {
|
||||||
|
if (loading.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (isStoreClosed()) {
|
if (isStoreClosed()) {
|
||||||
message.warning(getStoreClosedMessage())
|
message.warning(getStoreClosedMessage())
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<div class="dtxn-row__meta">
|
<div class="dtxn-row__meta">
|
||||||
<span>{{ toJalaliOutOfUTC(props.item.expire_at) }}</span>
|
<span>{{ toJalaliOutOfUTC(props.item.expire_at) }}</span>
|
||||||
<span :class="goldAmount >= 0 ? 'text-green-600' : 'text-red-600'">
|
<span :class="goldAmount >= 0 ? 'text-green-600' : 'text-red-600'">
|
||||||
{{ formatGoldAmount(goldAmount) }} {{ props.item.unit }}
|
{{ formatTransactionGoldAmount(props.item, goldAmount) }} {{ props.item.unit }}
|
||||||
</span>
|
</span>
|
||||||
<span v-if="isGold">
|
<span v-if="isGold">
|
||||||
قیمت معامله:
|
قیمت معامله:
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
:class="goldAmount >= 0 ? 'text-green-600' : 'text-red-600'"
|
:class="goldAmount >= 0 ? 'text-green-600' : 'text-red-600'"
|
||||||
class="text-gray-500 text-xs number-ltr"
|
class="text-gray-500 text-xs number-ltr"
|
||||||
>
|
>
|
||||||
{{ formatGoldAmount(goldAmount) }}
|
{{ formatTransactionGoldAmount(props.item, goldAmount) }}
|
||||||
<div>{{ props.item.unit }}</div>
|
<div>{{ props.item.unit }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-gray-500 flex gap-1 text-xs items-center number-ltr">
|
<div class="text-gray-500 flex gap-1 text-xs items-center number-ltr">
|
||||||
@@ -115,12 +115,12 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import Icon from '@/components/BasicPacks/BasicIcon.vue'
|
import Icon from '@/components/BasicPacks/BasicIcon.vue'
|
||||||
import {
|
import {
|
||||||
formatGoldAmount,
|
|
||||||
getTransactionGoldAmount,
|
getTransactionGoldAmount,
|
||||||
getTransactionTradePrice,
|
getTransactionTradePrice,
|
||||||
resolveTransactionStatusLabel,
|
resolveTransactionStatusLabel,
|
||||||
usePriceWithoutType,
|
usePriceWithoutType,
|
||||||
} from '@/utils/usePrice'
|
} from '@/utils/usePrice'
|
||||||
|
import { formatTransactionGoldAmount } from '@/utils/productDealMethod'
|
||||||
import BasicActionSheet from '@/components/BasicPacks/BasicActionSheet.vue'
|
import BasicActionSheet from '@/components/BasicPacks/BasicActionSheet.vue'
|
||||||
import BasicModal from '@/components/BasicPacks/BasicModal.vue'
|
import BasicModal from '@/components/BasicPacks/BasicModal.vue'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
]"
|
]"
|
||||||
>
|
>
|
||||||
<div class="flex items-center gap-1">
|
<div class="flex items-center gap-1">
|
||||||
<div class="text-base">{{ formatGoldAmount(item.gold) }}</div>
|
<div class="text-base">{{ formatTransactionGoldAmount(item, item.gold) }}</div>
|
||||||
{{ item.unit }}
|
{{ item.unit }}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col items-end text-xs text-yellow-700">
|
<div class="flex flex-col items-end text-xs text-yellow-700">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<div class="text-base ml-1">{{ formatGoldAmount(item.balance_gold) }}</div>
|
<div class="text-base ml-1">{{ formatTransactionGoldAmount(item, item.balance_gold) }}</div>
|
||||||
{{ metalWalletBalanceUnit }}
|
{{ metalWalletBalanceUnit }}
|
||||||
</div>
|
</div>
|
||||||
<div v-if="getProductUnitWeightLabel(metalWalletProduct)" class="text-gray-500">
|
<div v-if="getProductUnitWeightLabel(metalWalletProduct)" class="text-gray-500">
|
||||||
@@ -115,9 +115,10 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { formatGoldAmount, resolveTransactionStatusLabel, usePriceWithoutType } from '@/utils/usePrice'
|
import { resolveTransactionStatusLabel, usePriceWithoutType } from '@/utils/usePrice'
|
||||||
import type { Transaction } from '@/models/transaction'
|
import type { Transaction } from '@/models/transaction'
|
||||||
import {
|
import {
|
||||||
|
formatTransactionGoldAmount,
|
||||||
getCashWalletLabel,
|
getCashWalletLabel,
|
||||||
getProductTotalWeightLabel,
|
getProductTotalWeightLabel,
|
||||||
getProductUnitWeightLabel,
|
getProductUnitWeightLabel,
|
||||||
|
|||||||
Reference in New Issue
Block a user