2026-10-18 18:49:49 +03:30
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { onMounted, ref } from 'vue';
|
|
|
|
|
import axios from 'axios';
|
2026-10-18 21:06:18 +03:30
|
|
|
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,
|
|
|
|
|
List as AList,
|
|
|
|
|
Row as ARow,
|
|
|
|
|
Select as ASelect,
|
|
|
|
|
Typography,
|
2026-10-21 21:47:00 +03:30
|
|
|
message,
|
2026-10-18 21:06:18 +03:30
|
|
|
} from 'ant-design-vue';
|
2026-10-18 18:49:49 +03:30
|
|
|
import { api } from '@/lib/api';
|
|
|
|
|
import type { FinancialAccountDto, OrgUserDto } from '@mento/shared';
|
2026-10-21 21:47:00 +03:30
|
|
|
import MoneyInput from '@/components/MoneyInput.vue';
|
2026-10-18 18:49:49 +03:30
|
|
|
import { toman } from './treasury-format';
|
2026-10-21 21:47:00 +03:30
|
|
|
import { parseMoneyNumber } from '@/lib/money';
|
2026-10-18 18:49:49 +03:30
|
|
|
|
2026-10-21 21:47:00 +03:30
|
|
|
const { Text: ATypographyText } = Typography;
|
2026-10-18 21:06:18 +03:30
|
|
|
const AListItem = AList.Item;
|
|
|
|
|
const AListItemMeta = AList.Item.Meta;
|
|
|
|
|
const ASelectOption = ASelect.Option;
|
|
|
|
|
|
2026-10-18 18:49:49 +03:30
|
|
|
type PayrollRow = {
|
|
|
|
|
id: string;
|
|
|
|
|
fullName: string;
|
|
|
|
|
period: string;
|
|
|
|
|
payable: string;
|
|
|
|
|
remaining: string;
|
|
|
|
|
status: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const rows = ref<PayrollRow[]>([]);
|
|
|
|
|
const users = ref<OrgUserDto[]>([]);
|
|
|
|
|
const accounts = ref<FinancialAccountDto[]>([]);
|
|
|
|
|
const error = ref('');
|
|
|
|
|
const ok = ref('');
|
2026-10-21 21:47:00 +03:30
|
|
|
const saving = ref(false);
|
|
|
|
|
const form = ref({
|
|
|
|
|
userId: undefined as string | undefined,
|
|
|
|
|
period: '',
|
|
|
|
|
baseAmount: '',
|
|
|
|
|
benefits: '',
|
|
|
|
|
bonus: '',
|
|
|
|
|
deductions: '',
|
|
|
|
|
});
|
|
|
|
|
const pay = ref({ id: '', amount: '', accountId: undefined as string | undefined });
|
2026-10-18 18:49:49 +03:30
|
|
|
|
|
|
|
|
function apiMessage(e: unknown) {
|
|
|
|
|
if (!axios.isAxiosError(e)) return 'عملیات ناموفق بود.';
|
|
|
|
|
const msg = (e.response?.data as { message?: string | string[] })?.message;
|
|
|
|
|
return Array.isArray(msg) ? msg.join('، ') : msg || 'عملیات ناموفق بود.';
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-21 21:47:00 +03:30
|
|
|
function onFinishFailed() {
|
|
|
|
|
message.warning('لطفاً فیلدهای الزامی را کامل کنید.');
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-18 18:49:49 +03:30
|
|
|
async function load() {
|
|
|
|
|
const [payroll, people, acc] = await Promise.all([
|
|
|
|
|
api.get<PayrollRow[]>('/treasury/payroll'),
|
|
|
|
|
api.get<OrgUserDto[]>('/users'),
|
|
|
|
|
api.get<FinancialAccountDto[]>('/treasury/accounts'),
|
|
|
|
|
]);
|
|
|
|
|
rows.value = payroll.data;
|
|
|
|
|
users.value = people.data.filter((row) => row.isActive !== false);
|
|
|
|
|
accounts.value = acc.data.filter((row) => row.isActive);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function createRow() {
|
|
|
|
|
error.value = '';
|
2026-10-21 21:47:00 +03:30
|
|
|
ok.value = '';
|
|
|
|
|
saving.value = true;
|
2026-10-18 18:49:49 +03:30
|
|
|
try {
|
2026-10-21 21:47:00 +03:30
|
|
|
const baseAmount = parseMoneyNumber(String(form.value.baseAmount ?? ''), 0) ?? 0;
|
|
|
|
|
await api.post('/treasury/payroll', {
|
|
|
|
|
userId: form.value.userId,
|
|
|
|
|
period: form.value.period,
|
|
|
|
|
baseAmount,
|
|
|
|
|
benefits: parseMoneyNumber(String(form.value.benefits ?? ''), 0) ?? 0,
|
|
|
|
|
bonus: parseMoneyNumber(String(form.value.bonus ?? ''), 0) ?? 0,
|
|
|
|
|
deductions: parseMoneyNumber(String(form.value.deductions ?? ''), 0) ?? 0,
|
|
|
|
|
});
|
|
|
|
|
form.value = {
|
|
|
|
|
userId: undefined,
|
|
|
|
|
period: '',
|
|
|
|
|
baseAmount: '',
|
|
|
|
|
benefits: '',
|
|
|
|
|
bonus: '',
|
|
|
|
|
deductions: '',
|
|
|
|
|
};
|
2026-10-18 18:49:49 +03:30
|
|
|
ok.value = 'حقوق ثبت شد و تا پرداخت، موجودی حساب تغییر نمیکند.';
|
|
|
|
|
await load();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
error.value = apiMessage(e);
|
2026-10-21 21:47:00 +03:30
|
|
|
} finally {
|
|
|
|
|
saving.value = false;
|
2026-10-18 18:49:49 +03:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function payRow() {
|
|
|
|
|
error.value = '';
|
2026-10-21 21:47:00 +03:30
|
|
|
ok.value = '';
|
|
|
|
|
saving.value = true;
|
2026-10-18 18:49:49 +03:30
|
|
|
try {
|
2026-10-21 21:47:00 +03:30
|
|
|
const amount = parseMoneyNumber(String(pay.value.amount ?? ''), 0);
|
|
|
|
|
if (amount == null || amount <= 0) {
|
|
|
|
|
error.value = 'مبلغ پرداخت معتبر نیست.';
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-10-18 18:49:49 +03:30
|
|
|
await api.post(`/treasury/payroll/${pay.value.id}/pay`, {
|
2026-10-21 21:47:00 +03:30
|
|
|
amount,
|
2026-10-18 18:49:49 +03:30
|
|
|
accountId: pay.value.accountId,
|
|
|
|
|
clientKey: crypto.randomUUID(),
|
|
|
|
|
});
|
|
|
|
|
ok.value = 'پرداخت حقوق از حساب ثبت شد.';
|
2026-10-21 21:47:00 +03:30
|
|
|
pay.value = { id: '', amount: '', accountId: undefined };
|
2026-10-18 18:49:49 +03:30
|
|
|
await load();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
error.value = apiMessage(e);
|
2026-10-21 21:47:00 +03:30
|
|
|
} finally {
|
|
|
|
|
saving.value = false;
|
2026-10-18 18:49:49 +03:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-18 21:06:18 +03:30
|
|
|
function startPay(row: PayrollRow) {
|
2026-10-21 21:47:00 +03:30
|
|
|
pay.value = {
|
|
|
|
|
id: row.id,
|
|
|
|
|
amount: row.remaining,
|
|
|
|
|
accountId: accounts.value[0]?.id,
|
|
|
|
|
};
|
2026-10-18 21:06:18 +03:30
|
|
|
}
|
|
|
|
|
|
2026-10-18 18:49:49 +03:30
|
|
|
onMounted(() => {
|
|
|
|
|
void load().catch(() => {
|
|
|
|
|
error.value = 'بارگذاری حقوق ناموفق بود.';
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2026-10-21 21:47:00 +03:30
|
|
|
<a-flex vertical :gap="16">
|
2026-10-18 21:06:18 +03:30
|
|
|
<a-alert v-if="error" type="error" show-icon :message="error" />
|
|
|
|
|
<a-alert v-if="ok" type="success" show-icon :message="ok" />
|
|
|
|
|
|
|
|
|
|
<a-card :bordered="false">
|
|
|
|
|
<a-divider orientation="right">ثبت دوره</a-divider>
|
2026-10-21 21:47:00 +03:30
|
|
|
<a-form
|
|
|
|
|
layout="vertical"
|
|
|
|
|
:model="form"
|
|
|
|
|
@finish="createRow"
|
|
|
|
|
@finishFailed="onFinishFailed"
|
|
|
|
|
>
|
2026-10-18 21:06:18 +03:30
|
|
|
<a-row :gutter="[16, 0]">
|
|
|
|
|
<a-col :xs="24" :md="12">
|
2026-10-21 21:47:00 +03:30
|
|
|
<a-form-item
|
|
|
|
|
label="پرسنل"
|
|
|
|
|
name="userId"
|
|
|
|
|
:rules="[{ required: true, message: 'پرسنل الزامی است' }]"
|
|
|
|
|
>
|
2026-11-04 10:02:31 +03:30
|
|
|
<a-select show-search option-filter-prop="label"
|
2026-10-21 21:47:00 +03:30
|
|
|
v-model:value="form.userId"
|
|
|
|
|
allow-clear
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
placeholder="انتخاب"
|
|
|
|
|
>
|
2026-11-04 10:02:31 +03:30
|
|
|
<a-select-option v-for="user in users" :key="user.id" :value="user.id" :label="user.fullName">
|
2026-10-18 21:06:18 +03:30
|
|
|
{{ user.fullName }}
|
|
|
|
|
</a-select-option>
|
|
|
|
|
</a-select>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :xs="24" :md="8">
|
2026-10-21 21:47:00 +03:30
|
|
|
<a-form-item
|
|
|
|
|
label="دوره"
|
|
|
|
|
name="period"
|
|
|
|
|
:rules="[{ required: true, message: 'دوره الزامی است' }]"
|
|
|
|
|
>
|
2026-10-18 21:06:18 +03:30
|
|
|
<a-input v-model:value="form.period" placeholder="۱۴۰۵-۰۷" />
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :xs="24" :md="8">
|
2026-10-21 21:47:00 +03:30
|
|
|
<a-form-item
|
|
|
|
|
label="پایه"
|
|
|
|
|
name="baseAmount"
|
|
|
|
|
:rules="[{ required: true, message: 'مبلغ پایه الزامی است' }]"
|
|
|
|
|
>
|
|
|
|
|
<MoneyInput v-model="form.baseAmount" :decimals="0" />
|
2026-10-18 21:06:18 +03:30
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :xs="24" :md="8">
|
|
|
|
|
<a-form-item label="مزایا" name="benefits">
|
2026-10-21 21:47:00 +03:30
|
|
|
<MoneyInput v-model="form.benefits" :decimals="0" />
|
2026-10-18 21:06:18 +03:30
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :xs="24" :md="8">
|
|
|
|
|
<a-form-item label="پاداش" name="bonus">
|
2026-10-21 21:47:00 +03:30
|
|
|
<MoneyInput v-model="form.bonus" :decimals="0" />
|
2026-10-18 21:06:18 +03:30
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :xs="24" :md="8">
|
|
|
|
|
<a-form-item label="کسورات" name="deductions">
|
2026-10-21 21:47:00 +03:30
|
|
|
<MoneyInput v-model="form.deductions" :decimals="0" />
|
2026-10-18 21:06:18 +03:30
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
</a-row>
|
2026-10-21 21:47:00 +03:30
|
|
|
<a-button type="primary" html-type="submit" :loading="saving">ثبت حقوق</a-button>
|
2026-10-18 21:06:18 +03:30
|
|
|
</a-form>
|
|
|
|
|
|
|
|
|
|
<template v-if="pay.id">
|
|
|
|
|
<a-divider orientation="right">پرداخت حقوق</a-divider>
|
2026-10-21 21:47:00 +03:30
|
|
|
<a-form
|
|
|
|
|
layout="vertical"
|
|
|
|
|
:model="pay"
|
|
|
|
|
@finish="payRow"
|
|
|
|
|
@finishFailed="onFinishFailed"
|
|
|
|
|
>
|
2026-10-18 21:06:18 +03:30
|
|
|
<a-row :gutter="[16, 0]">
|
|
|
|
|
<a-col :xs="24" :md="8">
|
2026-10-21 21:47:00 +03:30
|
|
|
<a-form-item
|
|
|
|
|
label="مبلغ"
|
|
|
|
|
name="amount"
|
|
|
|
|
:rules="[{ required: true, message: 'مبلغ الزامی است' }]"
|
|
|
|
|
>
|
|
|
|
|
<MoneyInput v-model="pay.amount" :decimals="0" />
|
2026-10-18 21:06:18 +03:30
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :xs="24" :md="8">
|
2026-10-21 21:47:00 +03:30
|
|
|
<a-form-item
|
|
|
|
|
label="حساب"
|
|
|
|
|
name="accountId"
|
|
|
|
|
:rules="[{ required: true, message: 'حساب الزامی است' }]"
|
|
|
|
|
>
|
2026-11-04 10:02:31 +03:30
|
|
|
<a-select show-search option-filter-prop="label"
|
2026-10-21 21:47:00 +03:30
|
|
|
v-model:value="pay.accountId"
|
|
|
|
|
allow-clear
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
placeholder="انتخاب حساب"
|
|
|
|
|
>
|
|
|
|
|
<a-select-option
|
|
|
|
|
v-for="account in accounts"
|
|
|
|
|
:key="account.id"
|
|
|
|
|
:value="account.id"
|
2026-11-04 10:02:31 +03:30
|
|
|
:label="account.name"
|
2026-10-21 21:47:00 +03:30
|
|
|
>
|
2026-10-18 21:06:18 +03:30
|
|
|
{{ account.name }}
|
|
|
|
|
</a-select-option>
|
|
|
|
|
</a-select>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
</a-row>
|
2026-10-21 21:47:00 +03:30
|
|
|
<a-button type="primary" html-type="submit" :loading="saving">ثبت پرداخت</a-button>
|
2026-10-18 21:06:18 +03:30
|
|
|
</a-form>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<a-divider orientation="right">فهرست</a-divider>
|
|
|
|
|
<a-empty v-if="!rows.length" description="رکورد حقوقی ثبت نشده است." />
|
|
|
|
|
<a-list v-else item-layout="horizontal" :data-source="rows">
|
|
|
|
|
<template #renderItem="{ item }">
|
|
|
|
|
<a-list-item>
|
|
|
|
|
<template #actions>
|
|
|
|
|
<a-typography-text strong>{{ toman(item.payable) }}</a-typography-text>
|
|
|
|
|
<a-button
|
|
|
|
|
v-if="item.status !== 'settled' && item.status !== 'void'"
|
|
|
|
|
type="link"
|
|
|
|
|
@click="startPay(item)"
|
|
|
|
|
>
|
|
|
|
|
پرداخت
|
|
|
|
|
</a-button>
|
|
|
|
|
</template>
|
|
|
|
|
<a-list-item-meta>
|
|
|
|
|
<template #title>{{ item.fullName }}</template>
|
|
|
|
|
<template #description>
|
|
|
|
|
{{ item.period }} · مانده {{ toman(item.remaining) }} · {{ item.status }}
|
|
|
|
|
</template>
|
|
|
|
|
</a-list-item-meta>
|
|
|
|
|
</a-list-item>
|
|
|
|
|
</template>
|
|
|
|
|
</a-list>
|
|
|
|
|
</a-card>
|
2026-10-21 21:47:00 +03:30
|
|
|
</a-flex>
|
2026-10-18 21:06:18 +03:30
|
|
|
</template>
|