A receipt or payment only reduces the party balance, while an income or expense keeps both amounts. Finance screens stack into cards on a phone so the forms and lists stay readable. Co-authored-by: Cursor <cursoragent@cursor.com>
231 lines
7.7 KiB
Vue
231 lines
7.7 KiB
Vue
<script setup lang="ts">
|
|
import { onMounted, onUnmounted, ref } from 'vue';
|
|
import { useRoute, useRouter } from 'vue-router';
|
|
import {
|
|
Alert as AAlert,
|
|
Button as AButton,
|
|
Card as ACard,
|
|
Col as ACol,
|
|
Divider as ADivider,
|
|
Empty as AEmpty,
|
|
Flex as AFlex,
|
|
Form as AForm,
|
|
FormItem as AFormItem,
|
|
Input as AInput,
|
|
Row as ARow,
|
|
Space as ASpace,
|
|
Statistic as AStatistic,
|
|
Table as ATable,
|
|
Descriptions as ADescriptions,
|
|
DescriptionsItem as ADescriptionsItem,
|
|
List as AList,
|
|
} from 'ant-design-vue';
|
|
import type { TableColumnsType } from 'ant-design-vue';
|
|
import { api } from '@/lib/api';
|
|
import type { FinancialAccountDto, FinancialMovementDto } from '@mento/shared';
|
|
import MoneyInput from '@/components/MoneyInput.vue';
|
|
import { toman } from './treasury-format';
|
|
import { useTreasuryMobile } from './useTreasuryMobile';
|
|
import { formatJalaliNumeric } from '@/lib/jalali';
|
|
import { parseMoneyNumber } from '@/lib/money';
|
|
import { useTreasuryPageChrome } from './treasuryPageChrome';
|
|
|
|
const route = useRoute();
|
|
const router = useRouter();
|
|
const pageChrome = useTreasuryPageChrome();
|
|
const account = ref<FinancialAccountDto | null>(null);
|
|
const items = ref<FinancialMovementDto[]>([]);
|
|
const error = ref('');
|
|
const stated = ref<string | number | null>('');
|
|
const reason = ref('');
|
|
const note = ref('');
|
|
const busy = ref(false);
|
|
|
|
const isMobile = useTreasuryMobile();
|
|
const AListItem = AList.Item;
|
|
const columns: TableColumnsType<FinancialMovementDto> = [
|
|
{
|
|
title: 'تاریخ',
|
|
key: 'occurredAt',
|
|
customRender: ({ record }) => formatJalaliNumeric(new Date(record.occurredAt)),
|
|
},
|
|
{
|
|
title: 'شرح',
|
|
key: 'memo',
|
|
customRender: ({ record }) => record.memo || '—',
|
|
},
|
|
{ title: 'نوع', dataIndex: 'kindLabel', key: 'kindLabel' },
|
|
{
|
|
title: 'ورودی',
|
|
key: 'in',
|
|
customRender: ({ record }) => (record.direction === 'in' ? toman(record.amount) : '—'),
|
|
},
|
|
{
|
|
title: 'خروجی',
|
|
key: 'out',
|
|
customRender: ({ record }) => (record.direction === 'out' ? toman(record.amount) : '—'),
|
|
},
|
|
{
|
|
title: 'مانده',
|
|
key: 'balanceAfter',
|
|
customRender: ({ record }) => (record.balanceAfter ? toman(record.balanceAfter) : '—'),
|
|
},
|
|
];
|
|
|
|
async function load() {
|
|
const { data } = await api.get<{ account: FinancialAccountDto; items: FinancialMovementDto[] }>(
|
|
`/treasury/accounts/${route.params.id}/ledger`,
|
|
);
|
|
account.value = data.account;
|
|
items.value = data.items;
|
|
pageChrome?.set({
|
|
title: data.account.name || 'جزئیات حساب',
|
|
description: 'گردش قطعی این حساب',
|
|
});
|
|
}
|
|
|
|
async function reconcile() {
|
|
error.value = '';
|
|
note.value = '';
|
|
busy.value = true;
|
|
try {
|
|
const amount = parseMoneyNumber(String(stated.value ?? ''), 0);
|
|
const { data } = await api.post<{ difference: string; systemBalance: string }>(
|
|
'/treasury/reconciliations',
|
|
{
|
|
accountId: route.params.id,
|
|
statedBalance: amount ?? 0,
|
|
},
|
|
);
|
|
note.value = `اختلاف ${toman(data.difference)} نسبت به موجودی سیستم ${toman(data.systemBalance)}. موجودی خودکار عوض نشد.`;
|
|
} catch {
|
|
error.value = 'ثبت مغایرت ناموفق بود.';
|
|
} finally {
|
|
busy.value = false;
|
|
}
|
|
}
|
|
|
|
async function adjust(direction: 'in' | 'out') {
|
|
error.value = '';
|
|
busy.value = true;
|
|
try {
|
|
const amount = parseMoneyNumber(String(stated.value ?? ''), 0);
|
|
await api.post('/treasury/adjustments', {
|
|
accountId: route.params.id,
|
|
amount: amount ?? 0,
|
|
direction,
|
|
reason: reason.value,
|
|
});
|
|
await load();
|
|
note.value = 'اصلاح موجودی ثبت شد.';
|
|
} catch {
|
|
error.value = 'اصلاح موجودی ناموفق بود.';
|
|
} finally {
|
|
busy.value = false;
|
|
}
|
|
}
|
|
|
|
onMounted(() => {
|
|
void load().catch(() => {
|
|
error.value = 'گردش حساب بارگذاری نشد.';
|
|
});
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
pageChrome?.clear();
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<a-flex vertical :gap="16">
|
|
<a-space>
|
|
<a-button type="link" @click="router.push('/finance/accounts')">بازگشت به حسابها</a-button>
|
|
</a-space>
|
|
|
|
<a-alert v-if="error" type="error" show-icon :message="error" />
|
|
<a-alert v-if="note" type="success" show-icon :message="note" />
|
|
|
|
<a-row v-if="account" :gutter="[16, 16]">
|
|
<a-col :xs="24" :sm="12" :md="6">
|
|
<a-card :bordered="false">
|
|
<a-statistic title="موجودی فعلی" :value="toman(account.balance)" />
|
|
</a-card>
|
|
</a-col>
|
|
<a-col :xs="24" :sm="12" :md="6">
|
|
<a-card :bordered="false">
|
|
<a-statistic title="مانده افتتاحیه" :value="toman(account.openingBalance)" />
|
|
</a-card>
|
|
</a-col>
|
|
<a-col :xs="24" :sm="12" :md="6">
|
|
<a-card :bordered="false">
|
|
<a-statistic title="ورودی" :value="toman(account.periodIn)" />
|
|
</a-card>
|
|
</a-col>
|
|
<a-col :xs="24" :sm="12" :md="6">
|
|
<a-card :bordered="false">
|
|
<a-statistic title="خروجی" :value="toman(account.periodOut)" />
|
|
</a-card>
|
|
</a-col>
|
|
</a-row>
|
|
|
|
<a-card v-if="account" :bordered="false">
|
|
<a-divider orientation="right">مغایرت و اصلاح</a-divider>
|
|
<a-form layout="vertical">
|
|
<a-row :gutter="[16, 0]">
|
|
<a-col :xs="24" :md="8">
|
|
<a-form-item label="موجودی واقعی">
|
|
<MoneyInput addon-after="تومان" v-model="stated" :decimals="0" />
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :xs="24" :md="8">
|
|
<a-form-item label="علت اصلاح">
|
|
<a-input v-model:value="reason" />
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :xs="24" :md="8">
|
|
<a-form-item label=" ">
|
|
<a-space wrap>
|
|
<a-button :loading="busy" @click="reconcile">ثبت مغایرت</a-button>
|
|
<a-button :loading="busy" @click="adjust('in')">اصلاح ورود</a-button>
|
|
<a-button :loading="busy" @click="adjust('out')">اصلاح خروج</a-button>
|
|
</a-space>
|
|
</a-form-item>
|
|
</a-col>
|
|
</a-row>
|
|
</a-form>
|
|
|
|
<a-divider orientation="right">گردش حساب</a-divider>
|
|
<a-empty v-if="!items.length" description="گردشی ثبت نشده است." />
|
|
<a-list v-else-if="isMobile" :data-source="items">
|
|
<template #renderItem="{ item }">
|
|
<a-list-item>
|
|
<a-card :title="formatJalaliNumeric(new Date(item.occurredAt))" style="width: 100%">
|
|
<a-descriptions :column="1" bordered>
|
|
<a-descriptions-item label="شرح">{{ item.memo || '—' }}</a-descriptions-item>
|
|
<a-descriptions-item label="نوع">{{ item.kindLabel }}</a-descriptions-item>
|
|
<a-descriptions-item label="ورودی">
|
|
{{ item.direction === 'in' ? toman(item.amount) : '—' }}
|
|
</a-descriptions-item>
|
|
<a-descriptions-item label="خروجی">
|
|
{{ item.direction === 'out' ? toman(item.amount) : '—' }}
|
|
</a-descriptions-item>
|
|
<a-descriptions-item label="مانده">
|
|
{{ item.balanceAfter ? toman(item.balanceAfter) : '—' }}
|
|
</a-descriptions-item>
|
|
</a-descriptions>
|
|
</a-card>
|
|
</a-list-item>
|
|
</template>
|
|
</a-list>
|
|
<a-table
|
|
v-else-if="items.length"
|
|
:columns="columns"
|
|
:data-source="items"
|
|
:pagination="false"
|
|
row-key="id"
|
|
:scroll="{ x: true }"
|
|
/>
|
|
</a-card>
|
|
</a-flex>
|
|
</template>
|