Show cached rial and weight balances on balance-claims activity cards and details.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import type {
|
||||
ActivityAccountBalanceDto,
|
||||
ActivityDto,
|
||||
ActivityFieldValues,
|
||||
ActivityFilter,
|
||||
@@ -15,6 +16,12 @@ import type {
|
||||
PaginatedResponse,
|
||||
UpdateActivityRequest,
|
||||
} from '@mento/shared';
|
||||
import {
|
||||
ACCOUNT_BALANCE_CLAIMS_TAG,
|
||||
ACCOUNT_BALANCE_WEIGHT_KEYS,
|
||||
ACCOUNT_BALANCE_WEIGHT_LABELS,
|
||||
parseAccountBalanceWeightFields,
|
||||
} from '@mento/shared';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import * as path from 'node:path';
|
||||
@@ -38,6 +45,7 @@ import { tehranDayKey } from '../routines/routine-dates';
|
||||
import { buildSearchWhere, ci } from '../common/search';
|
||||
import { activityPriorWhere } from '../common/prior-archive';
|
||||
import { leadsDeepWhere } from '../common/data-access';
|
||||
import { extractMandehRaw } from '../integrations/tahesab/tahesab-methods';
|
||||
import { ActivityStagesService, type BoardStageContext } from './activity-stages.service';
|
||||
import {
|
||||
ActivityTypesService,
|
||||
@@ -363,10 +371,24 @@ export class ActivitiesService {
|
||||
]);
|
||||
|
||||
const ctx = await this.ctx(organizationId);
|
||||
const [todayDto, overdueDto, upcomingDto] = await Promise.all([
|
||||
this.withAccountBalances(
|
||||
organizationId,
|
||||
today.map((row) => this.toDto(row, ctx)),
|
||||
),
|
||||
this.withAccountBalances(
|
||||
organizationId,
|
||||
overdue.map((row) => this.toDto(row, ctx)),
|
||||
),
|
||||
this.withAccountBalances(
|
||||
organizationId,
|
||||
upcoming.map((row) => this.toDto(row, ctx)),
|
||||
),
|
||||
]);
|
||||
return {
|
||||
today: today.map((row) => this.toDto(row, ctx)),
|
||||
overdue: overdue.map((row) => this.toDto(row, ctx)),
|
||||
upcoming: upcoming.map((row) => this.toDto(row, ctx)),
|
||||
today: todayDto,
|
||||
overdue: overdueDto,
|
||||
upcoming: upcomingDto,
|
||||
todayCount,
|
||||
overdueCount,
|
||||
};
|
||||
@@ -418,7 +440,10 @@ export class ActivitiesService {
|
||||
]);
|
||||
|
||||
return {
|
||||
items: rows.map((row) => this.toDto(row, ctx)),
|
||||
items: await this.withAccountBalances(
|
||||
organizationId,
|
||||
rows.map((row) => this.toDto(row, ctx)),
|
||||
),
|
||||
total,
|
||||
page,
|
||||
limit: take,
|
||||
@@ -689,7 +714,8 @@ export class ActivitiesService {
|
||||
orderBy: { fullName: 'asc' },
|
||||
});
|
||||
}
|
||||
return dto;
|
||||
const [enriched] = await this.withAccountBalances(organizationId, [dto]);
|
||||
return enriched;
|
||||
}
|
||||
|
||||
async create(
|
||||
@@ -1635,6 +1661,105 @@ export class ActivitiesService {
|
||||
}
|
||||
}
|
||||
|
||||
/** فقط فعالیتهای تگ مطالبات؛ مانده از کش تهحساب بدون فراخوانی زنده */
|
||||
private async withAccountBalances(
|
||||
organizationId: string,
|
||||
items: ActivityDto[],
|
||||
): Promise<ActivityDto[]> {
|
||||
if (!items.length) return items;
|
||||
const claimItems = items.filter((item) =>
|
||||
(item.tags ?? []).includes(ACCOUNT_BALANCE_CLAIMS_TAG),
|
||||
);
|
||||
if (!claimItems.length) return items;
|
||||
|
||||
const personIds = [
|
||||
...new Set(
|
||||
claimItems
|
||||
.map((item) => item.person?.id)
|
||||
.filter((id): id is string => Boolean(id)),
|
||||
),
|
||||
];
|
||||
const balanceByPerson = new Map<string, ActivityAccountBalanceDto | null>();
|
||||
if (personIds.length) {
|
||||
const links = await this.prisma.personAccountingLink.findMany({
|
||||
where: {
|
||||
personId: { in: personIds },
|
||||
person: { organizationId },
|
||||
},
|
||||
include: {
|
||||
balanceCache: true,
|
||||
connection: { select: { isDefault: true } },
|
||||
},
|
||||
orderBy: [{ linkedAt: 'desc' }],
|
||||
});
|
||||
const bestByPerson = new Map<string, (typeof links)[number]>();
|
||||
for (const link of links) {
|
||||
const prev = bestByPerson.get(link.personId);
|
||||
if (!prev) {
|
||||
bestByPerson.set(link.personId, link);
|
||||
continue;
|
||||
}
|
||||
const prevScore =
|
||||
(prev.balanceCache ? 2 : 0) + (prev.connection.isDefault ? 1 : 0);
|
||||
const nextScore =
|
||||
(link.balanceCache ? 2 : 0) + (link.connection.isDefault ? 1 : 0);
|
||||
if (nextScore > prevScore) bestByPerson.set(link.personId, link);
|
||||
}
|
||||
for (const personId of personIds) {
|
||||
const link = bestByPerson.get(personId);
|
||||
balanceByPerson.set(
|
||||
personId,
|
||||
link?.balanceCache
|
||||
? this.cacheToAccountBalance(link.balanceCache)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return items.map((item) => {
|
||||
if (!(item.tags ?? []).includes(ACCOUNT_BALANCE_CLAIMS_TAG)) return item;
|
||||
const personId = item.person?.id;
|
||||
return {
|
||||
...item,
|
||||
accountBalance: personId
|
||||
? (balanceByPerson.get(personId) ?? null)
|
||||
: null,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private cacheToAccountBalance(cache: {
|
||||
rialBalance: number | null;
|
||||
goldBalance: number | null;
|
||||
rawResponse: unknown;
|
||||
fetchedAt: Date;
|
||||
}): ActivityAccountBalanceDto {
|
||||
const fields = parseAccountBalanceWeightFields(
|
||||
extractMandehRaw(cache.rawResponse).fields,
|
||||
);
|
||||
const weights = ACCOUNT_BALANCE_WEIGHT_KEYS.map((key) => {
|
||||
const value =
|
||||
fields[key] ??
|
||||
(key === 'MandeyeVazni' ? cache.goldBalance : null) ??
|
||||
null;
|
||||
if (value == null || !Number.isFinite(value)) return null;
|
||||
return {
|
||||
key,
|
||||
label: ACCOUNT_BALANCE_WEIGHT_LABELS[key] ?? key,
|
||||
value,
|
||||
};
|
||||
}).filter((row): row is NonNullable<typeof row> => row != null);
|
||||
|
||||
return {
|
||||
rialBalance:
|
||||
cache.rialBalance != null && Number.isFinite(cache.rialBalance)
|
||||
? cache.rialBalance
|
||||
: null,
|
||||
weights,
|
||||
fetchedAt: cache.fetchedAt.toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
private toDto(row: ActivityRow, ctx?: DtoContext): ActivityDto {
|
||||
const fields =
|
||||
row.fields && typeof row.fields === 'object' && !Array.isArray(row.fields)
|
||||
|
||||
@@ -158,6 +158,7 @@ function toCard(item: ActivityDto, stageId: string): PipelineDeal {
|
||||
assigneeIds: (item.assignees ?? []).map((a) => a.id),
|
||||
priority: item.priority,
|
||||
activityStatus: item.status,
|
||||
accountBalance: item.accountBalance ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { theme } from 'ant-design-vue';
|
||||
import type { ActivityAccountBalanceDto } from '@mento/shared';
|
||||
import { formatTahesabBedBes } from '@/lib/tahesab';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
balance: ActivityAccountBalanceDto | null | undefined;
|
||||
/** فشردهتر برای کارت کانبان */
|
||||
compact?: boolean;
|
||||
}>(),
|
||||
{ compact: false },
|
||||
);
|
||||
|
||||
const { token } = theme.useToken();
|
||||
|
||||
type Line = {
|
||||
key: string;
|
||||
label: string;
|
||||
text: string;
|
||||
value: number | null;
|
||||
};
|
||||
|
||||
const lines = computed<Line[]>(() => {
|
||||
const bal = props.balance;
|
||||
if (!bal) return [];
|
||||
const out: Line[] = [];
|
||||
if (bal.rialBalance != null && Number.isFinite(bal.rialBalance)) {
|
||||
out.push({
|
||||
key: 'rial',
|
||||
label: 'مانده ریالی',
|
||||
text: `${formatTahesabBedBes(bal.rialBalance, 0)} ریال`,
|
||||
value: bal.rialBalance,
|
||||
});
|
||||
}
|
||||
for (const w of bal.weights ?? []) {
|
||||
if (w.value == null || !Number.isFinite(w.value)) continue;
|
||||
out.push({
|
||||
key: w.key,
|
||||
label: w.label,
|
||||
text: `${formatTahesabBedBes(w.value, 3)} گرم`,
|
||||
value: w.value,
|
||||
});
|
||||
}
|
||||
return out;
|
||||
});
|
||||
|
||||
const visible = computed(() => lines.value.length > 0);
|
||||
|
||||
function toneColor(value: number | null) {
|
||||
if (value == null || !Number.isFinite(value) || value === 0) {
|
||||
return token.value.colorTextSecondary;
|
||||
}
|
||||
return value < 0 ? token.value.colorError : token.value.colorSuccess;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a-flex
|
||||
v-if="visible"
|
||||
vertical
|
||||
:gap="compact ? 2 : 4"
|
||||
:style="{ minWidth: 0, width: '100%' }"
|
||||
>
|
||||
<a-typography-text
|
||||
v-for="line in lines"
|
||||
:key="line.key"
|
||||
dir="ltr"
|
||||
:style="{
|
||||
margin: 0,
|
||||
display: 'block',
|
||||
fontSize: `${compact ? token.fontSizeSM : token.fontSize}px`,
|
||||
fontWeight: 600,
|
||||
color: toneColor(line.value),
|
||||
textAlign: 'right',
|
||||
direction: 'rtl',
|
||||
}"
|
||||
:title="`${line.label}: ${line.text}`"
|
||||
>
|
||||
<a-typography-text
|
||||
type="secondary"
|
||||
:style="{
|
||||
fontSize: `${token.fontSizeSM}px`,
|
||||
fontWeight: 500,
|
||||
marginInlineEnd: '6px',
|
||||
}"
|
||||
>
|
||||
{{ line.label }}:
|
||||
</a-typography-text>
|
||||
{{ line.text }}
|
||||
</a-typography-text>
|
||||
</a-flex>
|
||||
</template>
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { canCollaborateOnActivity, canMutateActivity } from '@/lib/activity-access';
|
||||
import ActivityCommentSheet from '@/components/activities/ActivityCommentSheet.vue';
|
||||
import ActivityAccountBalances from '@/components/activities/ActivityAccountBalances.vue';
|
||||
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -555,6 +556,16 @@ function openFull() {
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<div
|
||||
v-if="activity.accountBalance"
|
||||
:style="{ marginTop: '12px' }"
|
||||
>
|
||||
<a-typography-text type="secondary" :style="{ display: 'block', marginBottom: '4px' }">
|
||||
مانده حساب
|
||||
</a-typography-text>
|
||||
<ActivityAccountBalances :balance="activity.accountBalance" />
|
||||
</div>
|
||||
|
||||
<a-divider :style="{ margin: '16px 0 12px' }" />
|
||||
<a-flex justify="space-between" align="center" :style="{ marginBottom: '8px' }">
|
||||
<a-typography-text strong>یادداشت</a-typography-text>
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
theme,
|
||||
} from 'ant-design-vue';
|
||||
import DealQuickActivityPopover from '@/components/pipeline/DealQuickActivityPopover.vue';
|
||||
import ActivityAccountBalances from '@/components/activities/ActivityAccountBalances.vue';
|
||||
import { calendarDaysBetween, formatJalaliNumeric } from '@/lib/jalali';
|
||||
import { userAvatarSrc } from '@/lib/userAvatars';
|
||||
import type { PipelineAccent, PipelineDeal, PipelineUiCopy } from '@/lib/pipeline-board';
|
||||
@@ -244,6 +245,12 @@ const cardStyle = computed(() => ({
|
||||
>
|
||||
{{ deal.description }}
|
||||
</a-typography-text>
|
||||
<ActivityAccountBalances
|
||||
v-if="deal.accountBalance"
|
||||
:balance="deal.accountBalance"
|
||||
compact
|
||||
:style="{ marginTop: '6px' }"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<span :data-card-id="deal.id">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { currencySuffix } from '@/lib/money';
|
||||
import { matchesSearch } from '@/lib/search';
|
||||
import type {
|
||||
ActivityAccountBalanceDto,
|
||||
ActivityPriority,
|
||||
ActivityStatus,
|
||||
DealActivityCue,
|
||||
@@ -39,6 +40,8 @@ export type PipelineDeal = {
|
||||
activityCue?: DealActivityCue;
|
||||
/** خلاصه فعالیتها برای پاپآپ دکمهٔ تقویم */
|
||||
activitySummaries?: DealActivitySummaryDto[];
|
||||
/** مانده ریالی/وزنی فقط برای کارتهای کاریز مطالبات */
|
||||
accountBalance?: ActivityAccountBalanceDto | null;
|
||||
};
|
||||
|
||||
export type PipelineUiCopy = {
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
import UiIcon from '@/components/UiIcon.vue';
|
||||
import ExcelImportFlow from '@/components/ExcelImportFlow.vue';
|
||||
import ActivitiesKanban from '@/components/activities/ActivitiesKanban.vue';
|
||||
import ActivityAccountBalances from '@/components/activities/ActivityAccountBalances.vue';
|
||||
import ActivityDeskFilters from '@/components/activities/ActivityDeskFilters.vue';
|
||||
import ActivityStagesManager from '@/components/activities/ActivityStagesManager.vue';
|
||||
import ActivityTypesManager from '@/components/activities/ActivityTypesManager.vue';
|
||||
@@ -1773,6 +1774,11 @@ onUnmounted(() => {
|
||||
{{ item.title }}
|
||||
</RouterLink>
|
||||
<p v-if="subtitle(item)" class="sub">{{ subtitle(item) }}</p>
|
||||
<ActivityAccountBalances
|
||||
v-if="item.accountBalance"
|
||||
:balance="item.accountBalance"
|
||||
compact
|
||||
/>
|
||||
<p v-if="item.tags?.length" class="row-tags">
|
||||
<span v-for="t in item.tags.slice(0, 3)" :key="t">#{{ t }}</span>
|
||||
<span v-if="item.tags.length > 3">+{{ toFaDigits(item.tags.length - 3) }}</span>
|
||||
@@ -1905,6 +1911,11 @@ onUnmounted(() => {
|
||||
<UiIcon name="star" :size="14" class="star" />
|
||||
</RouterLink>
|
||||
<p v-if="subtitle(item)" class="sub">{{ subtitle(item) }}</p>
|
||||
<ActivityAccountBalances
|
||||
v-if="item.accountBalance"
|
||||
:balance="item.accountBalance"
|
||||
compact
|
||||
/>
|
||||
<p class="meta-line">
|
||||
<span v-if="item.person">
|
||||
<UiIcon name="user" :size="13" />
|
||||
|
||||
@@ -17,6 +17,7 @@ import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||||
import ActivityCommentSheet from '@/components/activities/ActivityCommentSheet.vue';
|
||||
import ActivityPostponeSheet from '@/components/activities/ActivityPostponeSheet.vue';
|
||||
import ActivityFieldsView from '@/components/activities/ActivityFieldsView.vue';
|
||||
import ActivityAccountBalances from '@/components/activities/ActivityAccountBalances.vue';
|
||||
import StagePathStrip from '@/components/StagePathStrip.vue';
|
||||
import { Button as AButton, message, Modal } from 'ant-design-vue';
|
||||
import type {
|
||||
@@ -1237,6 +1238,9 @@ onUnmounted(() => {
|
||||
#{{ t }}
|
||||
</RouterLink>
|
||||
</div>
|
||||
<div v-if="activity.accountBalance" class="claim-balances">
|
||||
<ActivityAccountBalances :balance="activity.accountBalance" />
|
||||
</div>
|
||||
</div>
|
||||
<span class="type-ico" :style="typeColorStyle(draftTypeView!.color)">
|
||||
<UiIcon :name="draftTypeView!.icon" :size="22" />
|
||||
@@ -2030,6 +2034,10 @@ onUnmounted(() => {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.claim-balances {
|
||||
margin-top: 0.65rem;
|
||||
}
|
||||
|
||||
.tag {
|
||||
background: #f0fdfa;
|
||||
color: #0f766e;
|
||||
|
||||
@@ -35,6 +35,7 @@ import ActivityFieldsEditor from '@/components/activities/ActivityFieldsEditor.v
|
||||
import { useActivityPriorities } from '@/lib/activity-priorities';
|
||||
import { typeColorStyle, useActivityTypes } from '@/lib/activity-types';
|
||||
import type {
|
||||
ActivityAccountBalanceDto,
|
||||
ActivityBoardDto,
|
||||
ActivityDto,
|
||||
ActivityImageDto,
|
||||
@@ -51,6 +52,7 @@ import type {
|
||||
PipelineBoardDto,
|
||||
TeamDto,
|
||||
} from '@mento/shared';
|
||||
import ActivityAccountBalances from '@/components/activities/ActivityAccountBalances.vue';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
@@ -101,6 +103,8 @@ const keepTypeId = ref('');
|
||||
const priority = ref<ActivityPriority>('medium');
|
||||
const description = ref('');
|
||||
const tagsRaw = ref('');
|
||||
/** فقط فعالیتهای کاریز مطالبات از API میآید */
|
||||
const accountBalance = ref<ActivityAccountBalanceDto | null>(null);
|
||||
const PHOTO_TOO_LARGE = 'حجم عکس باید زیر 200 کیلوبایت باشد';
|
||||
const PHOTO_LIMIT = 8;
|
||||
type PendingPhoto = { localId: string; name: string; dataUrl: string; file: File };
|
||||
@@ -438,6 +442,7 @@ function resetForm() {
|
||||
priority.value = 'medium';
|
||||
description.value = '';
|
||||
tagsRaw.value = '';
|
||||
accountBalance.value = null;
|
||||
clearPhotos();
|
||||
createdActivityId.value = '';
|
||||
defaultDue();
|
||||
@@ -515,6 +520,7 @@ async function load() {
|
||||
description.value = data.description ?? '';
|
||||
needsNote.value = Boolean(data.description?.trim());
|
||||
tagsRaw.value = (data.tags ?? []).join('، ');
|
||||
accountBalance.value = data.accountBalance ?? null;
|
||||
splitDue(data.dueAt);
|
||||
durationMinutes.value = data.durationMinutes ?? 30;
|
||||
reminderAt.value = data.reminderAt
|
||||
@@ -1641,6 +1647,12 @@ watch([id, isNew], () => void load(), { immediate: true });
|
||||
<dt>مشتری مرتبط</dt>
|
||||
<dd>{{ selectedPerson?.fullName || '—' }}</dd>
|
||||
</div>
|
||||
<div v-if="accountBalance">
|
||||
<dt>مانده حساب</dt>
|
||||
<dd>
|
||||
<ActivityAccountBalances :balance="accountBalance" />
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>وضعیت انجام</dt>
|
||||
<dd>
|
||||
|
||||
@@ -2253,6 +2253,19 @@ export const ACTIVITY_EDIT_POLICY_LABELS: Record<ActivityEditPolicy, string> = {
|
||||
assignees: "همهٔ مسئولان",
|
||||
};
|
||||
|
||||
/** ماندهٔ کششدهٔ تهحساب برای کارت/جزئیات فعالیت مطالبات */
|
||||
export interface ActivityAccountBalanceWeightDto {
|
||||
key: string;
|
||||
label: string;
|
||||
value: number;
|
||||
}
|
||||
|
||||
export interface ActivityAccountBalanceDto {
|
||||
rialBalance: number | null;
|
||||
weights: ActivityAccountBalanceWeightDto[];
|
||||
fetchedAt: string | null;
|
||||
}
|
||||
|
||||
export interface ActivityDto {
|
||||
id: string;
|
||||
type: ActivityType;
|
||||
@@ -2280,6 +2293,11 @@ export interface ActivityDto {
|
||||
importSource?: string;
|
||||
promotedFromPriorAt?: string | null;
|
||||
tags: string[];
|
||||
/**
|
||||
* فقط برای فعالیتهای کاریز مطالبات (تگ balance_claims):
|
||||
* مانده ریالی/وزنی از کش تهحساب؛ null یعنی لینک/کش نیست.
|
||||
*/
|
||||
accountBalance?: ActivityAccountBalanceDto | null;
|
||||
person: PersonSummaryDto | null;
|
||||
company: CompanySummaryDto | null;
|
||||
deal: DealSummaryDto | null;
|
||||
|
||||
Reference in New Issue
Block a user