feat: gate treasury as an org module and group money inputs
Link optional invoice and cheque settlements to cash accounts, and let superadmin enable the finance module per organization. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -97,10 +97,46 @@ async function load() {
|
||||
|
||||
async function setStatus(row: ChequeDto, next: ChequeStatus) {
|
||||
if (row.status === next) return;
|
||||
let financialAccountId: string | undefined;
|
||||
if (next === 'cleared' && row.status !== 'cleared') {
|
||||
const accountsRes = await api
|
||||
.get<Array<{ id: string; name: string; isActive: boolean }>>('/treasury/accounts')
|
||||
.catch(() => null);
|
||||
if (!accountsRes) {
|
||||
savingId.value = row.id;
|
||||
try {
|
||||
const { data } = await api.patch<ChequeDto>(`/cheques/${row.id}`, { status: next });
|
||||
items.value = items.value.map((item) => (item.id === row.id ? data : item));
|
||||
} catch {
|
||||
error.value = 'تغییر وضعیت چک ناموفق بود.';
|
||||
} finally {
|
||||
savingId.value = '';
|
||||
}
|
||||
return;
|
||||
}
|
||||
const accounts = accountsRes.data;
|
||||
const active = accounts.filter((item) => item.isActive);
|
||||
if (!active.length) {
|
||||
error.value = 'برای وصول چک ابتدا یک حساب صندوق بسازید.';
|
||||
return;
|
||||
}
|
||||
if (active.length === 1) {
|
||||
financialAccountId = active[0]!.id;
|
||||
} else {
|
||||
const picked = window.prompt(`نام حساب صندوق را بنویسید: ${active.map((item) => item.name).join('، ')}`);
|
||||
const match = active.find((item) => item.name.trim() === picked?.trim());
|
||||
if (!match) {
|
||||
error.value = 'حساب صندوق انتخاب نشد.';
|
||||
return;
|
||||
}
|
||||
financialAccountId = match.id;
|
||||
}
|
||||
}
|
||||
savingId.value = row.id;
|
||||
try {
|
||||
const { data } = await api.patch<ChequeDto>(`/cheques/${row.id}`, {
|
||||
status: next,
|
||||
...(financialAccountId ? { financialAccountId } : {}),
|
||||
});
|
||||
items.value = items.value.map((item) => (item.id === row.id ? data : item));
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user