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:
@@ -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