Add a small internal warehouse and party balances when Tahesab is off.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-10 22:24:16 +03:30
co-authored by Cursor
parent 55432ff979
commit 212d02f664
19 changed files with 1449 additions and 6 deletions
@@ -0,0 +1,173 @@
<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue';
import axios from 'axios';
import { api } from '@/lib/api';
import { formatMoney } from '@/lib/money';
import { useAuthStore } from '@/stores/auth';
import { canManageSettings } from '@/lib/roles';
import UiButton from '@/components/ui/UiButton.vue';
import UiInput from '@/components/ui/UiInput.vue';
import type { PartyBalanceDto } from '@mento/shared';
const props = defineProps<{
personId: string;
}>();
const auth = useAuthStore();
const canWrite = computed(() => canManageSettings(auth.user?.role));
const loading = ref(false);
const error = ref('');
const data = ref<PartyBalanceDto | null>(null);
const opening = ref('');
const saving = ref(false);
async function load() {
loading.value = true;
error.value = '';
try {
const { data: row } = await api.get<PartyBalanceDto>(
`/inventory/party/${props.personId}`,
);
data.value = row;
opening.value = String(row.openingAmount);
} catch {
error.value = 'بارگذاری مانده ناموفق بود.';
} finally {
loading.value = false;
}
}
async function saveOpening() {
if (!canWrite.value || saving.value) return;
const amount = Number(opening.value);
if (!Number.isFinite(amount)) return;
saving.value = true;
error.value = '';
try {
const { data: row } = await api.patch<PartyBalanceDto>(
`/inventory/party/${props.personId}/opening`,
{ amount },
);
data.value = row;
} catch (e) {
const msg = axios.isAxiosError(e)
? (e.response?.data as { message?: string })?.message
: null;
error.value = typeof msg === 'string' ? msg : 'ذخیره مانده اول دوره ناموفق بود.';
} finally {
saving.value = false;
}
}
watch(
() => props.personId,
() => {
void load();
},
);
onMounted(load);
</script>
<template>
<article v-if="data?.enabled" class="box">
<header>
<h3>مانده حساب داخلی</h3>
<p>از فاکتور و پرداخت‌های منتکت — وقتی ته‌حساب وصل نیست</p>
</header>
<p v-if="error" class="error">{{ error }}</p>
<p v-else-if="loading" class="muted">در حال بارگذاری…</p>
<template v-else>
<dl>
<div>
<dt>اول دوره</dt>
<dd>{{ formatMoney(data.openingAmount, data.currency) }}</dd>
</div>
<div>
<dt>فاکتورها</dt>
<dd>{{ formatMoney(data.invoicedAmount, data.currency) }}</dd>
</div>
<div>
<dt>پرداخت‌ها</dt>
<dd>{{ formatMoney(data.paidAmount, data.currency) }}</dd>
</div>
<div class="total">
<dt>مانده</dt>
<dd>{{ formatMoney(data.balance, data.currency) }}</dd>
</div>
</dl>
<form v-if="canWrite" class="open-form" @submit.prevent="saveOpening">
<label>
مانده اول دوره
<UiInput v-model="opening" type="number" />
</label>
<UiButton type="submit" :disabled="saving">
{{ saving ? 'ذخیره…' : 'ثبت' }}
</UiButton>
</form>
</template>
</article>
</template>
<style scoped>
.box {
background: #fff;
border: 1px solid var(--line);
border-radius: var(--radius);
padding: 1rem 1.1rem;
margin-bottom: 0.85rem;
}
h3 {
margin: 0;
font-size: 0.95rem;
}
header p,
.muted {
margin: 0.25rem 0 0;
color: var(--muted);
font-size: 0.8rem;
}
.error {
color: var(--danger, #dc2626);
font-weight: 600;
}
dl {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 0.65rem;
margin: 0.85rem 0 0;
}
dt {
color: var(--muted);
font-size: 0.78rem;
}
dd {
margin: 0.15rem 0 0;
font-weight: 700;
}
.total dd {
color: var(--accent-deep, #0f766e);
}
.open-form {
display: flex;
align-items: end;
gap: 0.5rem;
margin-top: 0.85rem;
}
.open-form label {
display: grid;
gap: 0.3rem;
font-size: 0.8rem;
color: var(--muted);
flex: 1;
}
</style>