feat(currency): update currency display to toman in admin panel; implement conversion functions for rial to toman and vice versa
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
# واحد پول = تومان در پنل ادمین (نمایش ÷۱۰ / ورودی ×۱۰) — ذخیره و درگاه ریال میماند
|
||||
|
||||
## پروژه
|
||||
|
||||
`clinicpro` (admin frontend — React). **cross-repo:** پرامپت همتا برای سایت عمومی: `nobat724_front/.claude/prompt/currency-toman-display-front.md`.
|
||||
|
||||
## زمینه
|
||||
|
||||
واحد پول در **نمایشِ کل محصول باید تومان** باشد، ولی طبق تصمیم:
|
||||
- **ذخیرهسازی DB و API و ارسال به درگاه پرداخت همچنان ریال میماند** (بدون migration، نام ستون/فیلدهای `*_rials` ثابت). درگاه ملت ریال میخواهد و مقدارِ ذخیرهشده درست است.
|
||||
- فقط **لایهٔ نمایش** مقدار ریال را ÷۱۰ کرده و با برچسب «تومان» نشان دهد، و **فرمهای ورودیِ پول** مقدارِ تومانِ واردشده را ×۱۰ کرده و بهصورت ریال ذخیره کنند.
|
||||
|
||||
الان ناهماهنگ است: `formatRial` عددِ **ریال** را میگیرد ولی برچسب «تومان» میچسباند (پس ۱۰ برابر نشان میدهد)، و فرمهای قیمت با برچسب «(ریال)» مقدار را مستقیم ریال ذخیره میکنند.
|
||||
|
||||
## مشکل / هدف
|
||||
|
||||
در پنل ادمین، همهٔ مبالغ **به تومان** نمایش داده و دریافت شوند؛ تبدیل تومان↔ریال فقط در لایهٔ UI (نمایش/فرم) انجام شود. DB/API/درگاه تغییری نکنند.
|
||||
|
||||
## فایلهای مرتبط
|
||||
|
||||
| فایل | نقش |
|
||||
|------|-----|
|
||||
| `clinicpro/assets/admin/lib/utils.ts` | helper مرکزی تبدیل + `formatRial` (نمایش تومان) |
|
||||
| `clinicpro/assets/admin/lib/utils.test.ts` | بهروزرسانی انتظار تست |
|
||||
| `clinicpro/assets/admin/pages/SettingsPage.tsx` | ۳ ورودی قیمت (appointment_fee/sms_panel_fee/sms_price) تومان |
|
||||
| `clinicpro/assets/admin/components/FreeVisitPrice.tsx` | ورودی قیمت تومان |
|
||||
| `clinicpro/assets/admin/components/ServiceTariffModal.tsx` | ورودی تعرفه تومان |
|
||||
| `clinicpro/assets/admin/components/TenantInsuranceContracts.tsx` | ورودی فرانشیز/سقف تعهد تومان |
|
||||
| `clinicpro/assets/admin/pages/SmsWalletPage.tsx` | مبلغ شارژ (ورودی) + نمایش قیمت هر پیامک |
|
||||
| (در صورت وجود) صفحهٔ تسویه/برداشت که `amount_rials` ورودی میگیرد | ورودی مبلغ تومان |
|
||||
|
||||
> نمایشهای دیگر (Payments، Subscription، RepresentationFinance، Dashboard و…) از `formatRial` استفاده میکنند؛ با اصلاح مرکزی خودکار تومان میشوند (۲۲ مصرف `formatRial`).
|
||||
|
||||
## وضعیت فعلی
|
||||
|
||||
### `lib/utils.ts`
|
||||
```ts
|
||||
export function formatRial(amount: number): string {
|
||||
return new Intl.NumberFormat('fa-IR').format(amount) + ' تومان';
|
||||
}
|
||||
```
|
||||
عدد ریال را بدون تبدیل، با برچسب «تومان» نشان میدهد → ۱۰ برابر.
|
||||
|
||||
### `SettingsPage.tsx` (ورودیها ریال ذخیره میشوند)
|
||||
```tsx
|
||||
appointment_fee_rials: s.appointment_fee_rials ?? '150000',
|
||||
sms_panel_fee_rials: s.sms_panel_fee_rials ?? '1500000',
|
||||
sms_price_rials: s.sms_price_rials ?? '500',
|
||||
// ...
|
||||
<input {...register('appointment_fee_rials')} ... placeholder="150000" />
|
||||
```
|
||||
مقدار مستقیم بهصورت ریال در `site_config` PATCH میشود.
|
||||
|
||||
### نمونهٔ نمایش (Subscription)
|
||||
```tsx
|
||||
{formatRial(period.price_rials)} // price_rials ریال است
|
||||
```
|
||||
|
||||
## وظایف
|
||||
|
||||
### ۱. helperهای تبدیل + اصلاح `formatRial` (utils.ts)
|
||||
|
||||
```ts
|
||||
export const RIAL_PER_TOMAN = 10;
|
||||
export const rialToToman = (rial: number): number => Math.round((Number(rial) || 0) / RIAL_PER_TOMAN);
|
||||
export const tomanToRial = (toman: number): number => Math.round((Number(toman) || 0) * RIAL_PER_TOMAN);
|
||||
|
||||
// ورودی همچنان «مقدار ریال» است (سازگاری با ۲۲ فراخوانی)، ولی خروجی به تومان نمایش داده میشود.
|
||||
export function formatRial(rial: number): string {
|
||||
return new Intl.NumberFormat('fa-IR').format(rialToToman(rial)) + ' تومان';
|
||||
}
|
||||
```
|
||||
> نام `formatRial` را برای سازگاری با تمام مصرفکنندهها نگه دار (فقط رفتارش توماننمایش میشود). اگر خواستی برای خوانایی `formatToman` را هم بهعنوان alias صادر کن.
|
||||
|
||||
### ۲. فرمهای ورودی پول — تومان بگیر، ریال ذخیره کن
|
||||
|
||||
الگوی کلی: مقدار ذخیرهشده (ریال) را با `rialToToman` در فرم نشان بده؛ هنگام submit با `tomanToRial` به ریال تبدیل کن؛ برچسب واحد را «تومان» کن.
|
||||
|
||||
**`SettingsPage.tsx`:**
|
||||
- `defaultValues`: `appointment_fee_rials: String(rialToToman(Number(s.appointment_fee_rials ?? 1500000)))` و مشابه برای `sms_panel_fee_rials`، `sms_price_rials` (پیشفرضها را هم به تومان تبدیل کن: مثلاً `150000` ریال → نمایش `15000`).
|
||||
- هنگام ذخیره (onSubmit/PATCH): این سه فیلد را `tomanToRial(...)` کن و سپس بفرست، تا `site_config` همچنان ریال بگیرد.
|
||||
- placeholder/برچسبها را از ریال به تومان بهروز کن (مثلاً placeholder «15000»).
|
||||
|
||||
**`FreeVisitPrice.tsx` / `ServiceTariffModal.tsx` / `TenantInsuranceContracts.tsx`:**
|
||||
- برچسبهای «قیمت (ریال)»، «تعرفه (ریال)»، «فرانشیز (ریال)»، «سقف تعهد (ریال)» → «(تومان)».
|
||||
- مقدار پیشفرضِ فرم = `rialToToman(storedRial)`؛ هنگام ذخیره = `tomanToRial(inputToman)` قبل از ارسال به API.
|
||||
|
||||
**`SmsWalletPage.tsx`:**
|
||||
- مبلغ شارژ که کاربر وارد میکند = تومان → قبل از ارسال `tomanToRial`.
|
||||
- نمایش «قیمت هر پیامک» و موجودی کیفپول از `formatRial` استفاده کند (خودکار تومان).
|
||||
|
||||
**صفحهٔ تسویه/برداشت (اگر `amount_rials` را از ورودی میگیرد):** مقدار تومانِ واردشده را `tomanToRial` کن و بفرست؛ نمایش موجودی/سقف با `formatRial`.
|
||||
|
||||
### ۳. برچسبهای ثابت «ریال» در JSX
|
||||
|
||||
هر جای UI که رشتهٔ «ریال» بهصورت ثابت کنار عدد آمده (نه از طریق `formatRial`) به «تومان» تغییر کند و عددش اگر خام ریال است با `rialToToman` تبدیل شود. (با `grep -rn "ریال" assets/admin` پیدا کن.)
|
||||
|
||||
### ۴. تست
|
||||
|
||||
`lib/utils.test.ts`: انتظار `formatRial` را به تومان بهروز کن (مثلاً ورودی `150000` ریال → خروجی شامل `15,000` و «تومان»).
|
||||
|
||||
## نکات مهم
|
||||
|
||||
- **DB/API/درگاه دست نخورد:** هیچ کلید `*_rials`، هیچ endpoint، و `MellatGateway`/`PaymentManager` تغییر نمیکند. مقدارِ رفته به درگاه همان ریالِ ذخیرهشده است (درست).
|
||||
- **تبدیل فقط در مرز UI:** نمایش `rialToToman`، ورودی `tomanToRial`. هیچ مقدارِ تبدیلشدهای نباید در API/DB ذخیره شود مگر بعد از `tomanToRial` (که دوباره ریال است).
|
||||
- **گرد کردن:** قیمتها مضرب ۱۰ ریالاند؛ `Math.round` امن است. اگر مقداری مضرب ۱۰ نبود، تومانِ گردشده نمایش داده میشود (پذیرفتنی).
|
||||
- **دوبارهتبدیل نشود:** مراقب باش جایی که قبلاً `formatRial` اعمال شده دوباره ÷۱۰ نکنی (double convert).
|
||||
- تستها: `ddev exec npx tsc --noEmit`، `ddev exec yarn dev` بدون خطا؛ سپس چشمی: Settings (قیمتها تومان و ذخیره درست)، Payments/Subscription/Dashboard (اعداد ۱۰ برابر کوچکتر از قبل و برچسب تومان).
|
||||
- backend docs تغییری ندارد (واحد API ریال میماند).
|
||||
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { toast } from 'sonner';
|
||||
import { api } from '../lib/api';
|
||||
import { formatRial } from '../lib/utils';
|
||||
import { formatRial, rialToToman, tomanToRial } from '../lib/utils';
|
||||
|
||||
interface Pricing { free_visit_price_rials: number }
|
||||
|
||||
@@ -17,11 +17,11 @@ export default function FreeVisitPrice() {
|
||||
const pricing = (data as any)?.data as Pricing | undefined;
|
||||
|
||||
useEffect(() => {
|
||||
if (pricing) setValue(String(pricing.free_visit_price_rials ?? 0));
|
||||
if (pricing) setValue(String(rialToToman(pricing.free_visit_price_rials ?? 0)));
|
||||
}, [pricing]);
|
||||
|
||||
const saveMut = useMutation({
|
||||
mutationFn: () => api.put('/api/v1/insurance-pricing', { free_visit_price_rials: Number(value) || 0 }),
|
||||
mutationFn: () => api.put('/api/v1/insurance-pricing', { free_visit_price_rials: tomanToRial(Number(value) || 0) }),
|
||||
onSuccess: () => {
|
||||
toast.success('قیمت ویزیت ذخیره شد');
|
||||
qc.invalidateQueries({ queryKey: ['insurance-pricing'] });
|
||||
@@ -37,7 +37,7 @@ export default function FreeVisitPrice() {
|
||||
</p>
|
||||
<div style={{ display: 'flex', alignItems: 'flex-end', gap: 10 }}>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||||
<label style={{ fontSize: 11.5, fontWeight: 600 }}>قیمت (ریال)</label>
|
||||
<label style={{ fontSize: 11.5, fontWeight: 600 }}>قیمت (تومان)</label>
|
||||
<input
|
||||
type="number" min={0} dir="ltr" className="input" style={{ width: 200 }}
|
||||
value={value} onChange={(e) => setValue(e.target.value)}
|
||||
@@ -47,7 +47,7 @@ export default function FreeVisitPrice() {
|
||||
{saveMut.isPending ? '...' : 'ذخیره'}
|
||||
</button>
|
||||
{value !== '' && (
|
||||
<span style={{ fontSize: 12, color: 'var(--text-3)', marginBottom: 8 }}>{formatRial(Number(value) || 0)}</span>
|
||||
<span style={{ fontSize: 12, color: 'var(--text-3)', marginBottom: 8 }}>{formatRial(tomanToRial(Number(value) || 0))}</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { PencilIcon, CheckIcon, XMarkIcon } from '@heroicons/react/24/outline';
|
||||
import { toast } from 'sonner';
|
||||
import { api } from '../lib/api';
|
||||
import { formatRial, formatNumber } from '../lib/utils';
|
||||
import { formatRial, formatNumber, rialToToman, tomanToRial } from '../lib/utils';
|
||||
import Modal from './ui/Modal';
|
||||
import PriceInput from './ui/PriceInput';
|
||||
import SearchableSelect from './ui/SearchableSelect';
|
||||
@@ -52,7 +52,7 @@ export default function ServiceTariffModal({ item, onClose }: { item: ServiceIte
|
||||
}, [currentYear, tariffs]);
|
||||
|
||||
const addMut = useMutation({
|
||||
mutationFn: () => api.put(`/api/v1/service-items/${item!.uuid}/tariffs/${Number(year)}`, { price_rials: price }),
|
||||
mutationFn: () => api.put(`/api/v1/service-items/${item!.uuid}/tariffs/${Number(year)}`, { price_rials: tomanToRial(price) }),
|
||||
onSuccess: () => {
|
||||
toast.success('تعرفه ذخیره شد');
|
||||
setYear('');
|
||||
@@ -65,7 +65,7 @@ export default function ServiceTariffModal({ item, onClose }: { item: ServiceIte
|
||||
|
||||
const editMut = useMutation({
|
||||
mutationFn: (vars: { year: number; price: number }) =>
|
||||
api.put(`/api/v1/service-items/${item!.uuid}/tariffs/${vars.year}`, { price_rials: vars.price }),
|
||||
api.put(`/api/v1/service-items/${item!.uuid}/tariffs/${vars.year}`, { price_rials: tomanToRial(vars.price) }),
|
||||
onSuccess: () => {
|
||||
toast.success('تعرفه ویرایش شد');
|
||||
setEditYear(null);
|
||||
@@ -75,7 +75,7 @@ export default function ServiceTariffModal({ item, onClose }: { item: ServiceIte
|
||||
onError: (e: Error) => toast.error(e.message),
|
||||
});
|
||||
|
||||
const startEdit = (t: TariffRow) => { setEditYear(t.year); setEditPrice(t.price_rials); };
|
||||
const startEdit = (t: TariffRow) => { setEditYear(t.year); setEditPrice(rialToToman(t.price_rials)); };
|
||||
|
||||
return (
|
||||
<Modal open={!!item} onClose={onClose} title={`تعرفههای سالانه — ${item?.name ?? ''}`} size="md">
|
||||
@@ -105,7 +105,7 @@ export default function ServiceTariffModal({ item, onClose }: { item: ServiceIte
|
||||
/>
|
||||
</div>
|
||||
<div style={{ minWidth: 0 }}>
|
||||
<label className="field-label">تعرفه (ریال)</label>
|
||||
<label className="field-label">تعرفه (تومان)</label>
|
||||
<PriceInput className="input" style={{ height: 40 }} value={price} onChange={setPrice} placeholder="مبلغ" min={0} />
|
||||
</div>
|
||||
<button className="btn primary" style={{ height: 40 }} disabled={year === '' || addMut.isPending} onClick={() => addMut.mutate()}>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { TrashIcon, PlusIcon, PencilIcon } from '@heroicons/react/24/outline';
|
||||
import { toast } from 'sonner';
|
||||
import { api } from '../lib/api';
|
||||
import { formatRial } from '../lib/utils';
|
||||
import { formatRial, rialToToman, tomanToRial } from '../lib/utils';
|
||||
import SearchableSelect from './ui/SearchableSelect';
|
||||
|
||||
interface Contract {
|
||||
@@ -66,16 +66,16 @@ export default function TenantInsuranceContracts() {
|
||||
setAddOpen(false);
|
||||
setInsuranceId(String(c.insurance_id));
|
||||
setCoverage(String(c.coverage_percent ?? ''));
|
||||
setFranchise(String(c.franchise_rials ?? ''));
|
||||
setCeiling(c.annual_ceiling_rials != null ? String(c.annual_ceiling_rials) : '');
|
||||
setFranchise(c.franchise_rials != null ? String(rialToToman(c.franchise_rials)) : '');
|
||||
setCeiling(c.annual_ceiling_rials != null ? String(rialToToman(c.annual_ceiling_rials)) : '');
|
||||
};
|
||||
|
||||
const editMut = useMutation({
|
||||
mutationFn: () =>
|
||||
api.patch(`/api/v1/billing/tenant-insurances/${editUuid}`, {
|
||||
coverage_percent: Number(coverage) || 0,
|
||||
franchise_rials: Number(franchise) || 0,
|
||||
annual_ceiling_rials: ceiling === '' ? null : Number(ceiling),
|
||||
franchise_rials: tomanToRial(Number(franchise) || 0),
|
||||
annual_ceiling_rials: ceiling === '' ? null : tomanToRial(Number(ceiling)),
|
||||
}),
|
||||
onSuccess: () => {
|
||||
toast.success('قرارداد بیمه ویرایش شد');
|
||||
@@ -90,8 +90,8 @@ export default function TenantInsuranceContracts() {
|
||||
api.post('/api/v1/billing/tenant-insurances', {
|
||||
insurance_id: Number(insuranceId),
|
||||
coverage_percent: Number(coverage) || 0,
|
||||
franchise_rials: Number(franchise) || 0,
|
||||
annual_ceiling_rials: ceiling === '' ? null : Number(ceiling),
|
||||
franchise_rials: tomanToRial(Number(franchise) || 0),
|
||||
annual_ceiling_rials: ceiling === '' ? null : tomanToRial(Number(ceiling)),
|
||||
}),
|
||||
onSuccess: () => {
|
||||
toast.success('قرارداد بیمه فعال شد');
|
||||
@@ -145,11 +145,11 @@ export default function TenantInsuranceContracts() {
|
||||
<input type="number" min={0} max={100} dir="ltr" className="input" style={{ width: 100 }} value={coverage} onChange={(e) => setCoverage(e.target.value)} />
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||||
<label style={{ fontSize: 11.5, fontWeight: 600 }}>فرانشیز (ریال)</label>
|
||||
<label style={{ fontSize: 11.5, fontWeight: 600 }}>فرانشیز (تومان)</label>
|
||||
<input type="number" min={0} dir="ltr" className="input" style={{ width: 130 }} value={franchise} onChange={(e) => setFranchise(e.target.value)} />
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||||
<label style={{ fontSize: 11.5, fontWeight: 600 }}>سقف تعهد (ریال)</label>
|
||||
<label style={{ fontSize: 11.5, fontWeight: 600 }}>سقف تعهد (تومان)</label>
|
||||
<input type="number" min={0} dir="ltr" className="input" style={{ width: 130 }} placeholder="بینهایت" value={ceiling} onChange={(e) => setCeiling(e.target.value)} />
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 6 }}>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import {
|
||||
formatRial,
|
||||
rialToToman,
|
||||
tomanToRial,
|
||||
formatNumber,
|
||||
toDate,
|
||||
formatDate,
|
||||
@@ -19,16 +21,25 @@ import {
|
||||
const PERSIAN_DIGITS = /[۰-۹]/;
|
||||
|
||||
describe('formatRial', () => {
|
||||
it('عدد را با جداکننده فارسی و پسوند تومان برمیگرداند', () => {
|
||||
const out = formatRial(1000);
|
||||
it('مقدار ریال را ÷۱۰ به تومان تبدیل و با پسوند تومان برمیگرداند', () => {
|
||||
const out = formatRial(150000); // ۱۵۰٬۰۰۰ ریال = ۱۵٬۰۰۰ تومان
|
||||
expect(out).toContain('تومان');
|
||||
expect(out).toMatch(PERSIAN_DIGITS);
|
||||
expect(out).toContain(new Intl.NumberFormat('fa-IR').format(15000));
|
||||
});
|
||||
it('صفر را هم فرمت میکند', () => {
|
||||
expect(formatRial(0)).toContain('تومان');
|
||||
});
|
||||
});
|
||||
|
||||
describe('rialToToman / tomanToRial', () => {
|
||||
it('ریال↔تومان با ضریب ۱۰', () => {
|
||||
expect(rialToToman(150000)).toBe(15000);
|
||||
expect(tomanToRial(15000)).toBe(150000);
|
||||
expect(tomanToRial(rialToToman(500))).toBe(500);
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatNumber', () => {
|
||||
it('رقم فارسی برمیگرداند', () => {
|
||||
expect(formatNumber(1234)).toMatch(PERSIAN_DIGITS);
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export function formatRial(amount: number): string {
|
||||
return new Intl.NumberFormat('fa-IR').format(amount) + ' تومان';
|
||||
// واحد ذخیره/API ریال است؛ نمایش تومان (÷۱۰) و ورودی ×۱۰.
|
||||
export const RIAL_PER_TOMAN = 10;
|
||||
export const rialToToman = (rial: number): number => Math.round((Number(rial) || 0) / RIAL_PER_TOMAN);
|
||||
export const tomanToRial = (toman: number): number => Math.round((Number(toman) || 0) * RIAL_PER_TOMAN);
|
||||
|
||||
// ورودی مقدار ریال است (سازگاری با همهٔ فراخوانیها) ولی خروجی به تومان نمایش داده میشود.
|
||||
export function formatRial(rial: number): string {
|
||||
return new Intl.NumberFormat('fa-IR').format(rialToToman(rial)) + ' تومان';
|
||||
}
|
||||
|
||||
export function formatNumber(n: number): string {
|
||||
|
||||
@@ -11,7 +11,7 @@ import { toast } from 'sonner';
|
||||
import { api } from '../lib/api';
|
||||
import type { ApiResponse } from '../lib/api';
|
||||
import type { ServiceSection, ServiceItem, ClinicStaff } from '../types';
|
||||
import { formatRial } from '../lib/utils';
|
||||
import { formatRial, rialToToman, tomanToRial } from '../lib/utils';
|
||||
import Modal from '../components/ui/Modal';
|
||||
import PriceInput from '../components/ui/PriceInput';
|
||||
import ConfirmDialog from '../components/ui/ConfirmDialog';
|
||||
@@ -124,14 +124,22 @@ function ClinicServicesPageInner() {
|
||||
});
|
||||
|
||||
const createItem = useMutation({
|
||||
mutationFn: (body: ItemForm & { section_uuid: string }) => api.post('/api/v1/service-item', body),
|
||||
mutationFn: (body: ItemForm & { section_uuid: string }) => api.post('/api/v1/service-item', {
|
||||
...body,
|
||||
price_rials: tomanToRial(body.price_rials),
|
||||
insurance_price_rials: tomanToRial(body.insurance_price_rials ?? 0),
|
||||
}),
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['service-items', selectedSection?.uuid] }); setItemModal(null); itemForm.reset(); toast.success('سرویس ایجاد شد'); },
|
||||
onError: (e: any) => toast.error(e.message),
|
||||
});
|
||||
|
||||
const editItem = useMutation({
|
||||
mutationFn: ({ uuid, body }: { uuid: string; body: ItemForm }) =>
|
||||
api.patch(`/api/v1/service-item/${uuid}`, body),
|
||||
api.patch(`/api/v1/service-item/${uuid}`, {
|
||||
...body,
|
||||
price_rials: tomanToRial(body.price_rials),
|
||||
insurance_price_rials: tomanToRial(body.insurance_price_rials ?? 0),
|
||||
}),
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['service-items', selectedSection?.uuid] }); setItemModal(null); toast.success('سرویس ویرایش شد'); },
|
||||
onError: (e: any) => toast.error(e.message),
|
||||
});
|
||||
@@ -155,10 +163,10 @@ function ClinicServicesPageInner() {
|
||||
const openEditItem = (item: ServiceItem) => {
|
||||
itemForm.reset({
|
||||
name: item.name,
|
||||
price_rials: item.price_rials,
|
||||
price_rials: rialToToman(item.price_rials),
|
||||
staff_uuid: item.staff?.uuid ?? '',
|
||||
insurance_covered: item.insurance_covered ?? false,
|
||||
insurance_price_rials: item.insurance_price_rials ?? 0,
|
||||
insurance_price_rials: rialToToman(item.insurance_price_rials ?? 0),
|
||||
});
|
||||
setItemModal(item);
|
||||
};
|
||||
@@ -434,7 +442,7 @@ function ClinicServicesPageInner() {
|
||||
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
|
||||
<div>
|
||||
<label className="field-label">قیمت پایه (ریال) *</label>
|
||||
<label className="field-label">قیمت پایه (تومان) *</label>
|
||||
<div className="field">
|
||||
<PriceInput
|
||||
value={itemForm.watch('price_rials') ?? 0}
|
||||
@@ -488,7 +496,7 @@ function ClinicServicesPageInner() {
|
||||
|
||||
{itemForm.watch('insurance_covered') && (
|
||||
<div style={{ padding: '0 16px 16px', borderTop: '1px solid var(--border)', paddingTop: 14 }}>
|
||||
<label className="field-label">قیمت تقریبی با بیمه (ریال)</label>
|
||||
<label className="field-label">قیمت تقریبی با بیمه (تومان)</label>
|
||||
<div className="field" style={{ background: 'var(--surface)' }}>
|
||||
<PriceInput
|
||||
value={itemForm.watch('insurance_price_rials') ?? 0}
|
||||
|
||||
@@ -57,7 +57,7 @@ export default function PaymentsPage() {
|
||||
{
|
||||
key: 'amount',
|
||||
header: 'مبلغ',
|
||||
render: (p) => <><b>{formatRial(p.amount)}</b> <span className="muted" style={{ fontSize: 11 }}>تومان</span></>,
|
||||
render: (p) => <b>{formatRial(p.amount)}</b>,
|
||||
},
|
||||
{
|
||||
key: 'status',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { toast } from 'sonner';
|
||||
import { api } from '../lib/api';
|
||||
import type { ApiResponse } from '../lib/api';
|
||||
import { formatRial, formatDate } from '../lib/utils';
|
||||
import { formatRial, formatDate, tomanToRial } from '../lib/utils';
|
||||
import Pagination from '../components/ui/Pagination';
|
||||
|
||||
interface WalletBalance { balance_rials: number }
|
||||
@@ -81,11 +81,12 @@ export default function RepresentationSettlementPage() {
|
||||
});
|
||||
|
||||
const submit = () => {
|
||||
const n = Number(amount);
|
||||
const n = Number(amount); // تومان
|
||||
if (!n || n <= 0) { toast.error('مبلغ نامعتبر است'); return; }
|
||||
if (n > balance) { toast.error('مبلغ بیشتر از موجودی قابل برداشت است'); return; }
|
||||
const rial = tomanToRial(n);
|
||||
if (rial > balance) { toast.error('مبلغ بیشتر از موجودی قابل برداشت است'); return; }
|
||||
if (!ibanId) { toast.error('انتخاب شماره شبا الزامی است'); return; }
|
||||
createMut.mutate({ amount_rials: n, iban_id: ibanId });
|
||||
createMut.mutate({ amount_rials: rial, iban_id: ibanId });
|
||||
};
|
||||
|
||||
const cards = [
|
||||
@@ -125,7 +126,7 @@ export default function RepresentationSettlementPage() {
|
||||
) : (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
|
||||
<input
|
||||
type="number" min={0} dir="ltr" value={amount} placeholder="مبلغ به ریال"
|
||||
type="number" min={0} dir="ltr" value={amount} placeholder="مبلغ به تومان"
|
||||
onChange={(e) => setAmount(e.target.value)}
|
||||
style={{ width: 200, height: 38, padding: '0 12px', borderRadius: 'var(--r-sm)', border: '1px solid var(--border)', background: 'var(--surface)', color: 'var(--text)', fontSize: 13.5, boxSizing: 'border-box' }}
|
||||
/>
|
||||
|
||||
@@ -5,7 +5,7 @@ import { z } from 'zod';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { api } from '../lib/api';
|
||||
import type { ApiResponse } from '../lib/api';
|
||||
import { formatDateTime } from '../lib/utils';
|
||||
import { formatDateTime, rialToToman, tomanToRial } from '../lib/utils';
|
||||
import {
|
||||
Cog6ToothIcon, ClockIcon, CalculatorIcon, CreditCardIcon, ChatBubbleLeftRightIcon,
|
||||
MagnifyingGlassIcon, CheckCircleIcon, ExclamationTriangleIcon, EyeIcon, EyeSlashIcon,
|
||||
@@ -62,9 +62,10 @@ const toForm = (s: Partial<Settings>): FormValues => ({
|
||||
upgrade_commission_percent: s.upgrade_commission_percent ?? '20',
|
||||
tax_enabled: s.tax_enabled ?? '0',
|
||||
tax_percent: s.tax_percent ?? '10',
|
||||
sms_panel_fee_rials: s.sms_panel_fee_rials ?? '1500000',
|
||||
sms_price_rials: s.sms_price_rials ?? '500',
|
||||
appointment_fee_rials: s.appointment_fee_rials ?? '150000',
|
||||
// ذخیره ریال است؛ در فرم به تومان نمایش/ویرایش میشود.
|
||||
sms_panel_fee_rials: String(rialToToman(Number(s.sms_panel_fee_rials ?? 1500000))),
|
||||
sms_price_rials: String(rialToToman(Number(s.sms_price_rials ?? 500))),
|
||||
appointment_fee_rials: String(rialToToman(Number(s.appointment_fee_rials ?? 150000))),
|
||||
payment_test_mode: s.payment_test_mode ?? '0',
|
||||
mellat_enabled: s.mellat_enabled ?? '1',
|
||||
mellat_sandbox: s.mellat_sandbox ?? '0',
|
||||
@@ -189,7 +190,13 @@ export default function SettingsPage() {
|
||||
return () => clearTimeout(t);
|
||||
}, [savedFlash]);
|
||||
|
||||
const onSubmit = (values: FormValues) => mutation.mutate(values);
|
||||
const onSubmit = (values: FormValues) => mutation.mutate({
|
||||
...values,
|
||||
// فرم به تومان است؛ برای ذخیره به ریال تبدیل کن.
|
||||
sms_panel_fee_rials: String(tomanToRial(Number(values.sms_panel_fee_rials))),
|
||||
sms_price_rials: String(tomanToRial(Number(values.sms_price_rials))),
|
||||
appointment_fee_rials: String(tomanToRial(Number(values.appointment_fee_rials))),
|
||||
});
|
||||
|
||||
// Ctrl/Cmd+S saves
|
||||
useEffect(() => {
|
||||
@@ -371,16 +378,16 @@ export default function SettingsPage() {
|
||||
)}
|
||||
|
||||
<div className="settings-grid" style={{ marginTop: 18 }}>
|
||||
<Field label="مبلغ هر نوبت" hint="مبلغی که بیمار هنگام رزرو آنلاین پرداخت میکند. ۱۵۰٬۰۰۰ ریال = ۱۵٬۰۰۰ تومان.">
|
||||
<Field label="مبلغ هر نوبت" hint="مبلغی که بیمار هنگام رزرو آنلاین پرداخت میکند (تومان).">
|
||||
<div className="input-suffix">
|
||||
<input {...register('appointment_fee_rials')} type="number" min={0} dir="ltr" className="input" style={{ maxWidth: 200 }} placeholder="150000" />
|
||||
<span className="suf">ریال</span>
|
||||
<input {...register('appointment_fee_rials')} type="number" min={0} dir="ltr" className="input" style={{ maxWidth: 200 }} placeholder="15000" />
|
||||
<span className="suf">تومان</span>
|
||||
</div>
|
||||
</Field>
|
||||
<Field label="هزینه ثابت پنل پیامک" hint="از مبلغ هر تراکنش کسر میشود. ۱٬۵۰۰٬۰۰۰ ریال = ۱۵۰٬۰۰۰ تومان.">
|
||||
<Field label="هزینه ثابت پنل پیامک" hint="از مبلغ هر تراکنش کسر میشود (تومان).">
|
||||
<div className="input-suffix">
|
||||
<input {...register('sms_panel_fee_rials')} type="number" min={0} dir="ltr" className="input" style={{ maxWidth: 200 }} placeholder="1500000" />
|
||||
<span className="suf">ریال</span>
|
||||
<input {...register('sms_panel_fee_rials')} type="number" min={0} dir="ltr" className="input" style={{ maxWidth: 200 }} placeholder="150000" />
|
||||
<span className="suf">تومان</span>
|
||||
</div>
|
||||
</Field>
|
||||
</div>
|
||||
@@ -468,8 +475,8 @@ export default function SettingsPage() {
|
||||
: <><ExclamationTriangleIcon style={{ width: 18, height: 18, color: 'var(--danger)' }} /><span style={{ color: 'var(--danger)' }}>تنظیمنشده — مقدار KAVENEGAR_API_KEY را در فایل env قرار دهید</span></>}
|
||||
</div>
|
||||
</Field>
|
||||
<Field label="هزینه هر پیامک" hint="مبلغ کسرشده از کیف پول به ازای هر پیامک ارسالی (ریال). مبنای محاسبهٔ تعداد پیامک از موجودی.">
|
||||
<input {...register('sms_price_rials')} type="number" min={0} dir="ltr" className="input" style={{ maxWidth: 200 }} placeholder="500" />
|
||||
<Field label="هزینه هر پیامک" hint="مبلغ کسرشده از کیف پول به ازای هر پیامک ارسالی (تومان). مبنای محاسبهٔ تعداد پیامک از موجودی.">
|
||||
<input {...register('sms_price_rials')} type="number" min={0} dir="ltr" className="input" style={{ maxWidth: 200 }} placeholder="50" />
|
||||
</Field>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { api } from '../lib/api';
|
||||
import type { ApiResponse, PaginatedResponse } from '../lib/api';
|
||||
import type { SmsWalletBalance, SmsWalletLog, SmsSettings } from '../types';
|
||||
import { usePaymentConfig } from '../hooks/usePaymentConfig';
|
||||
import { formatRial, formatNumber, formatDateTime } from '../lib/utils';
|
||||
import { formatRial, formatNumber, formatDateTime, tomanToRial } from '../lib/utils';
|
||||
import Modal from '../components/ui/Modal';
|
||||
import Pagination from '../components/ui/Pagination';
|
||||
import SearchableSelect from '../components/ui/SearchableSelect';
|
||||
@@ -21,7 +21,7 @@ import PageHeader from '../components/ui/PageHeader';
|
||||
import FeatureGate from '../components/ui/FeatureGate';
|
||||
|
||||
const chargeSchema = z.object({
|
||||
amount_rials: z.coerce.number().min(10000, 'حداقل مبلغ ۱۰,۰۰۰ ریال است'),
|
||||
amount_rials: z.coerce.number().min(1000, 'حداقل مبلغ ۱٬۰۰۰ تومان است'),
|
||||
});
|
||||
type ChargeForm = z.infer<typeof chargeSchema>;
|
||||
|
||||
@@ -70,7 +70,7 @@ function SmsWalletPageInner() {
|
||||
const chargeMutation = useMutation({
|
||||
mutationFn: ({ amount_rials }: ChargeForm) =>
|
||||
api.post<{ data: { payment_url: string } }>('/api/v1/sms/wallet/charge', {
|
||||
gateway, amount_rials,
|
||||
gateway, amount_rials: tomanToRial(amount_rials),
|
||||
frontend_address: `${window.location.origin}${window.location.pathname}`,
|
||||
}),
|
||||
onSuccess: (res: any) => {
|
||||
@@ -525,18 +525,18 @@ function SmsWalletPageInner() {
|
||||
)}
|
||||
|
||||
<div className="field">
|
||||
<label>مبلغ (ریال)</label>
|
||||
<label>مبلغ (تومان)</label>
|
||||
<input
|
||||
{...chargeForm.register('amount_rials')}
|
||||
type="number" min={10000}
|
||||
placeholder="500000" dir="ltr"
|
||||
type="number" min={1000}
|
||||
placeholder="50000" dir="ltr"
|
||||
/>
|
||||
{chargeForm.formState.errors.amount_rials && (
|
||||
<span className="field-error">{chargeForm.formState.errors.amount_rials.message}</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{watchAmount && Number(watchAmount) >= 10000 && (
|
||||
{watchAmount && Number(watchAmount) >= 1000 && (
|
||||
<div style={{
|
||||
background: isTestMode ? 'var(--warning-bg)' : 'var(--primary-soft)',
|
||||
border: `1px solid ${isTestMode ? 'var(--warning)' : 'color-mix(in oklch, var(--primary) 40%, transparent)'}`,
|
||||
@@ -544,8 +544,8 @@ function SmsWalletPageInner() {
|
||||
fontSize: 13, color: isTestMode ? 'var(--warning)' : 'var(--primary)', fontWeight: 500,
|
||||
}}>
|
||||
{isTestMode
|
||||
? `پرداخت آزمایشی ${formatRial(Number(watchAmount))}`
|
||||
: `پرداخت ${formatRial(Number(watchAmount))} از طریق ${gateway === 'mellat' ? 'بانک ملت' : 'سپ'}`
|
||||
? `پرداخت آزمایشی ${formatRial(tomanToRial(Number(watchAmount)))}`
|
||||
: `پرداخت ${formatRial(tomanToRial(Number(watchAmount)))} از طریق ${gateway === 'mellat' ? 'بانک ملت' : 'سپ'}`
|
||||
}
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user