Add account balance claims board with opt-in module and range settings.

EOF

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-17 21:24:15 +03:30
co-authored by Cursor
parent 634af8a653
commit de23e4d505
16 changed files with 1162 additions and 14 deletions
+9
View File
@@ -101,6 +101,15 @@ export const NAV_HUBS: NavHubDef[] = [
tint: 'violet',
module: 'customers',
},
{
to: '/settings/account-balances',
title: 'تعیین محدوده مانده',
desc: 'بازه مانده مالی و وزنی برای کاریز مطالبات',
icon: 'dollar',
tint: 'amber',
admin: true,
module: 'account_balances',
},
],
},
{
+16
View File
@@ -575,6 +575,15 @@ export const router = createRouter({
component: () => import('@/views/TahesabSettingsView.vue'),
meta: { roles: ['owner', 'admin'] as UserRole[] },
},
{
path: 'settings/account-balances',
name: 'account-balance-settings',
component: () => import('@/views/AccountBalanceSettingsView.vue'),
meta: {
roles: ['owner', 'admin'] as UserRole[],
module: 'account_balances',
},
},
{
path: 'settings/woocommerce',
name: 'woocommerce-settings',
@@ -668,6 +677,13 @@ router.beforeEach((to) => {
const modules = auth.user?.enabledModules;
if (modules && !modules.includes('tahesab')) return { name: 'home' };
}
if (
to.name === 'account-balance-settings' ||
String(to.path).startsWith('/settings/account-balances')
) {
const modules = auth.user?.enabledModules;
if (modules && !modules.includes('account_balances')) return { name: 'home' };
}
if (!canOpenPath(auth.user?.role, auth.user?.permissions, String(to.path))) {
return { name: 'home' };
}
@@ -0,0 +1,252 @@
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue';
import axios from 'axios';
import { api } from '@/lib/api';
import {
ACCOUNT_BALANCE_WEIGHT_KEYS,
ACCOUNT_BALANCE_WEIGHT_LABELS,
type AccountBalanceRangeDto,
type AccountBalanceSettingsDto,
type UpdateAccountBalanceSettingsRequest,
} from '@mento/shared';
import { UiButton, UiCard, UiField, UiInput, UiPageHeader } from '@/components/ui';
type RangeDraft = { enabled: boolean; min: string; max: string };
const loading = ref(false);
const saving = ref(false);
const evaluating = ref(false);
const error = ref('');
const ok = ref('');
const firstStageName = ref('مطالبه مشتریان');
const rial = reactive<RangeDraft>({ enabled: false, min: '', max: '' });
const weights = reactive<Record<string, RangeDraft>>(
Object.fromEntries(
ACCOUNT_BALANCE_WEIGHT_KEYS.map((key) => [
key,
{ enabled: false, min: '', max: '' } satisfies RangeDraft,
]),
),
);
const weightKeys = computed(() =>
[...new Set([...ACCOUNT_BALANCE_WEIGHT_KEYS, ...Object.keys(weights)])].sort((a, b) =>
weightLabel(a).localeCompare(weightLabel(b), 'fa'),
),
);
function weightLabel(key: string) {
return ACCOUNT_BALANCE_WEIGHT_LABELS[key] ?? key;
}
function toDraft(range: AccountBalanceRangeDto | null | undefined): RangeDraft {
if (!range) return { enabled: false, min: '', max: '' };
return { enabled: true, min: String(range.min), max: String(range.max) };
}
function parseDraft(draft: RangeDraft): AccountBalanceRangeDto | null {
if (!draft.enabled) return null;
const min = Number(String(draft.min).replace(/,/g, ''));
const max = Number(String(draft.max).replace(/,/g, ''));
if (!Number.isFinite(min) || !Number.isFinite(max)) {
throw new Error('بازه نامعتبر');
}
return { min, max: Math.max(min, max) };
}
function applySettings(data: AccountBalanceSettingsDto) {
firstStageName.value = data.firstStageName || 'مطالبه مشتریان';
Object.assign(rial, toDraft(data.rial));
for (const key of Object.keys(weights)) {
delete weights[key];
}
for (const key of ACCOUNT_BALANCE_WEIGHT_KEYS) {
weights[key] = toDraft(null);
}
for (const [key, range] of Object.entries(data.weights ?? {})) {
weights[key] = toDraft(range);
}
}
async function load() {
loading.value = true;
error.value = '';
try {
const { data } = await api.get<AccountBalanceSettingsDto>('/account-balances/settings');
applySettings(data);
} catch (e) {
error.value = axios.isAxiosError(e)
? Array.isArray(e.response?.data?.message)
? e.response.data.message.join('، ')
: String(e.response?.data?.message || 'بارگذاری تنظیمات ناموفق بود.')
: 'بارگذاری تنظیمات ناموفق بود.';
} finally {
loading.value = false;
}
}
async function save() {
saving.value = true;
error.value = '';
ok.value = '';
try {
const weightPayload: Record<string, AccountBalanceRangeDto | null> = {};
for (const key of weightKeys.value) {
weightPayload[key] = parseDraft(weights[key] ?? { enabled: false, min: '', max: '' });
}
const body: UpdateAccountBalanceSettingsRequest = {
firstStageName: firstStageName.value.trim() || 'مطالبه مشتریان',
rial: parseDraft(rial),
weights: weightPayload,
};
const { data } = await api.put<AccountBalanceSettingsDto>('/account-balances/settings', body);
applySettings(data);
ok.value = 'تنظیمات ذخیره شد. کاریز مطالبات آماده است.';
} catch (e) {
error.value =
e instanceof Error && e.message === 'بازه نامعتبر'
? 'برای بازه‌های فعال، حداقل و حداکثر عددی وارد کنید.'
: axios.isAxiosError(e)
? Array.isArray(e.response?.data?.message)
? e.response.data.message.join('، ')
: String(e.response?.data?.message || 'ذخیره ناموفق بود.')
: 'ذخیره ناموفق بود.';
} finally {
saving.value = false;
}
}
async function runEvaluate() {
evaluating.value = true;
error.value = '';
ok.value = '';
try {
await api.post('/account-balances/evaluate');
ok.value = 'بروزرسانی مطالبات اجرا شد.';
} catch (e) {
error.value = axios.isAxiosError(e)
? String(e.response?.data?.message || 'اجرای ارزیابی ناموفق بود.')
: 'اجرای ارزیابی ناموفق بود.';
} finally {
evaluating.value = false;
}
}
onMounted(load);
</script>
<template>
<section class="page">
<UiPageHeader
title="تعیین محدوده مانده"
description="بازه مانده مالی و وزنی مشتریان ته‌حساب برای ساخت فعالیت در کاریز مطالبات."
/>
<p v-if="error" class="error">{{ error }}</p>
<p v-if="ok" class="ok">{{ ok }}</p>
<p v-if="loading" class="muted">در حال بارگذاری…</p>
<UiCard v-else title="محدوده‌ها">
<p class="hint">
اعداد با همان علامت ته‌حساب هستند: منفی = بد، مثبت = بس. بازه خالی/خاموش برای آن معیار اعمال نمی‌شود.
اگر حداقل یکی از بازه‌های فعال با مانده مشتری بخورد، فعالیت پیگیری ساخته می‌شود.
</p>
<UiField label="عنوان ستون اول کاریز مطالبات">
<UiInput v-model="firstStageName" maxlength="80" placeholder="مطالبه مشتریان" />
</UiField>
<div class="range-block">
<label class="toggle">
<input v-model="rial.enabled" type="checkbox" />
<span>مانده مالی (ریال)</span>
</label>
<div v-if="rial.enabled" class="range-row">
<UiField label="از">
<UiInput v-model="rial.min" inputmode="decimal" placeholder="مثلاً -1000000" />
</UiField>
<UiField label="تا">
<UiInput v-model="rial.max" inputmode="decimal" placeholder="مثلاً 0" />
</UiField>
</div>
</div>
<div v-for="key in weightKeys" :key="key" class="range-block">
<label class="toggle">
<input v-model="weights[key].enabled" type="checkbox" />
<span>{{ weightLabel(key) }}</span>
</label>
<div v-if="weights[key]?.enabled" class="range-row">
<UiField label="از">
<UiInput v-model="weights[key].min" inputmode="decimal" placeholder="مثلاً -10" />
</UiField>
<UiField label="تا">
<UiInput v-model="weights[key].max" inputmode="decimal" placeholder="مثلاً 0" />
</UiField>
</div>
</div>
<div class="actions">
<UiButton type="button" :disabled="saving" @click="save">
{{ saving ? 'در حال ذخیره…' : 'ذخیره' }}
</UiButton>
<UiButton type="button" variant="ghost" :disabled="evaluating" @click="runEvaluate">
{{ evaluating ? 'در حال اجرا…' : 'اجرای الانِ مطالبات' }}
</UiButton>
</div>
<p class="muted tiny">
جاب خودکار هر روز ساعت ۸ و ۱۳ به وقت تهران اجرا می‌شود. دکمهٔ دستی همان ارزیابی را فوری می‌زند.
</p>
</UiCard>
</section>
</template>
<style scoped>
.page {
display: grid;
gap: 1rem;
}
.hint,
.muted {
color: var(--muted, #64748b);
font-size: 0.9rem;
line-height: 1.6;
}
.tiny {
font-size: 0.8rem;
}
.error {
color: #b91c1c;
}
.ok {
color: #047857;
}
.range-block {
display: grid;
gap: 0.6rem;
padding: 0.75rem 0;
border-top: 1px solid var(--border, #e2e8f0);
}
.toggle {
display: inline-flex;
align-items: center;
gap: 0.5rem;
font-weight: 600;
}
.range-row {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 0.75rem;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 0.6rem;
margin-top: 0.75rem;
}
@media (max-width: 640px) {
.range-row {
grid-template-columns: 1fr;
}
}
</style>
+8 -3
View File
@@ -549,7 +549,7 @@ function openCreateBoard() {
}
function openEditBoard() {
if (!currentBoard.value) return;
if (!currentBoard.value || currentBoard.value.systemKey) return;
boardMemberQuery.value = '';
boardModal.value = {
mode: 'edit',
@@ -1562,7 +1562,12 @@ onUnmounted(() => {
<UiIcon name="plus" :size="14" />
گروه جدید
</button>
<button type="button" class="board-menu-action" @click="openEditBoard">
<button
v-if="!currentBoard?.systemKey"
type="button"
class="board-menu-action"
@click="openEditBoard"
>
<UiIcon name="pencil" :size="14" />
ویرایش این گروه
</button>
@@ -2111,7 +2116,7 @@ onUnmounted(() => {
</li>
</ul>
<UiButton
v-if="boardModal.mode === 'edit' && currentBoard && !currentBoard.isDefault"
v-if="boardModal.mode === 'edit' && currentBoard && !currentBoard.isDefault && !currentBoard.systemKey"
variant="ghost"
size="sm"
type="button"