feat: add visit price requirement feature
- Introduced a new boolean flag `require_visit_price` in the `EntityInsurancePricing` to enforce visit price for appointments. - Updated the appointment creation endpoints to validate `visit_price_rials` based on the new flag. - Added `visit_price_rials` field to the `Appointment` entity to store the visit price. - Enhanced the `PatientService` to validate visit price during session creation. - Updated API documentation to reflect changes in appointment and insurance pricing. - Implemented a new service `VisitPriceRequirementResolver` to determine if a visit price is required for a doctor based on their pricing settings. - Added migrations to update the database schema for the new fields.
This commit is contained in:
@@ -4,11 +4,13 @@ import { toast } from 'sonner';
|
||||
import { api } from '../lib/api';
|
||||
import { formatRial, rialToToman, tomanToRial } from '../lib/utils';
|
||||
|
||||
interface Pricing { free_visit_price_rials: number }
|
||||
interface Pricing { free_visit_price_rials: number; require_visit_price: boolean }
|
||||
|
||||
export default function FreeVisitPrice() {
|
||||
const qc = useQueryClient();
|
||||
const [value, setValue] = useState('');
|
||||
const [required, setRequired] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const { data } = useQuery<{ data: Pricing }>({
|
||||
queryKey: ['insurance-pricing'],
|
||||
@@ -17,11 +19,17 @@ export default function FreeVisitPrice() {
|
||||
const pricing = (data as any)?.data as Pricing | undefined;
|
||||
|
||||
useEffect(() => {
|
||||
if (pricing) setValue(String(rialToToman(pricing.free_visit_price_rials ?? 0)));
|
||||
if (pricing) {
|
||||
setValue(String(rialToToman(pricing.free_visit_price_rials ?? 0)));
|
||||
setRequired(!!pricing.require_visit_price);
|
||||
}
|
||||
}, [pricing]);
|
||||
|
||||
const saveMut = useMutation({
|
||||
mutationFn: () => api.put('/api/v1/insurance-pricing', { free_visit_price_rials: tomanToRial(Number(value) || 0) }),
|
||||
mutationFn: () => api.put('/api/v1/insurance-pricing', {
|
||||
free_visit_price_rials: tomanToRial(Number(value) || 0),
|
||||
require_visit_price: required,
|
||||
}),
|
||||
onSuccess: () => {
|
||||
toast.success('قیمت ویزیت ذخیره شد');
|
||||
qc.invalidateQueries({ queryKey: ['insurance-pricing'] });
|
||||
@@ -29,6 +37,15 @@ export default function FreeVisitPrice() {
|
||||
onError: (e: Error) => toast.error(e.message),
|
||||
});
|
||||
|
||||
const save = () => {
|
||||
if (required && (Number(value) || 0) <= 0) {
|
||||
setError('با فعال بودن «الزامی کردن هزینه ویزیت»، قیمت ویزیت آزاد الزامی است');
|
||||
return;
|
||||
}
|
||||
setError('');
|
||||
saveMut.mutate();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="card" style={{ padding: 20, marginBottom: 16 }}>
|
||||
<h2 style={{ fontSize: 14, fontWeight: 700, margin: '0 0 4px' }}>قیمت ویزیت آزاد</h2>
|
||||
@@ -37,19 +54,46 @@ 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 }}>
|
||||
قیمت (تومان){required && <span style={{ color: 'var(--danger)' }}> *</span>}
|
||||
</label>
|
||||
<input
|
||||
type="number" min={0} dir="ltr" className="input" style={{ width: 200 }}
|
||||
value={value} onChange={(e) => setValue(e.target.value)}
|
||||
aria-invalid={!!error}
|
||||
value={value} onChange={(e) => { setValue(e.target.value); setError(''); }}
|
||||
/>
|
||||
</div>
|
||||
<button className="btn primary sm" disabled={saveMut.isPending} onClick={() => saveMut.mutate()}>
|
||||
<button className="btn primary sm" disabled={saveMut.isPending} onClick={save}>
|
||||
{saveMut.isPending ? '...' : 'ذخیره'}
|
||||
</button>
|
||||
{value !== '' && (
|
||||
<span style={{ fontSize: 12, color: 'var(--text-3)', marginBottom: 8 }}>{formatRial(tomanToRial(Number(value) || 0))}</span>
|
||||
)}
|
||||
</div>
|
||||
{error && (
|
||||
<p style={{ fontSize: 12, color: 'var(--danger)', margin: '6px 0 0' }}>{error}</p>
|
||||
)}
|
||||
|
||||
<label style={{ display: 'inline-flex', alignItems: 'center', gap: 10, fontSize: 13, cursor: 'pointer', marginTop: 16 }}>
|
||||
<span style={{
|
||||
position: 'relative', width: 42, height: 22, borderRadius: 999, flexShrink: 0,
|
||||
background: required ? 'var(--primary)' : '#c4c4c4', transition: 'background .2s',
|
||||
}}>
|
||||
<input
|
||||
type="checkbox" checked={required} role="switch" aria-label="الزامی کردن هزینه ویزیت"
|
||||
onChange={(e) => { setRequired(e.target.checked); setError(''); }}
|
||||
style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', margin: 0, opacity: 0, cursor: 'pointer' }}
|
||||
/>
|
||||
<span style={{
|
||||
position: 'absolute', top: 2, insetInlineStart: required ? 22 : 2, width: 18, height: 18,
|
||||
borderRadius: 999, background: '#fff', transition: 'inset-inline-start .2s', boxShadow: '0 1px 2px rgba(0,0,0,.2)',
|
||||
}} />
|
||||
</span>
|
||||
الزامی کردن هزینه ویزیت
|
||||
</label>
|
||||
<p style={{ fontSize: 12, color: 'var(--text-3)', margin: '6px 0 0', lineHeight: 1.7 }}>
|
||||
با فعال شدن این گزینه، وارد کردن هزینه ویزیت در تنظیمات، ثبت مراجعه (سرویس)، فاکتور سرویس و ثبت نوبت الزامی میشود و بدون آن امکان ذخیره وجود ندارد.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { PlusIcon, MinusIcon } from '@heroicons/react/24/outline';
|
||||
import { api } from '../../lib/api';
|
||||
import type { ApiResponse } from '../../lib/api';
|
||||
import type { PatientProfile, ServiceSection, ServiceItem } from '../../types';
|
||||
import { formatRial } from '../../lib/utils';
|
||||
import { formatRial, rialToToman, tomanToRial } from '../../lib/utils';
|
||||
import SearchableSelect from '../ui/SearchableSelect';
|
||||
import PersianDateInput from '../ui/PersianDateInput';
|
||||
import { UserTick, FilesServiceAddCard, ClockP, TrashRed } from '../icons/FilesServiceIcons';
|
||||
@@ -76,6 +76,7 @@ export default function CreateStep({ recordUuid, profile, onCreated, onCancel }:
|
||||
const [selectedConsumables, setSelectedConsumables] = useState<{ uuid: string; name: string; price: number; qty: number }[]>([]);
|
||||
const [packageUuid, setPackageUuid] = useState('');
|
||||
const [visitPrice, setVisitPrice] = useState('0');
|
||||
const [visitPriceError, setVisitPriceError] = useState('');
|
||||
const [baseId, setBaseId] = useState('');
|
||||
const [suppId, setSuppId] = useState('');
|
||||
const [basePercent, setBasePercent] = useState('0');
|
||||
@@ -103,13 +104,14 @@ export default function CreateStep({ recordUuid, profile, onCreated, onCancel }:
|
||||
const { data: contractsData } = useQuery<{ data: { data: Contract[] } }>({
|
||||
queryKey: ['tenant-insurances'], queryFn: () => api.get('/api/v1/billing/tenant-insurances'),
|
||||
});
|
||||
const { data: pricingData } = useQuery<{ data: { free_visit_price_rials: number } }>({
|
||||
const { data: pricingData } = useQuery<{ data: { free_visit_price_rials: number; require_visit_price: boolean } }>({
|
||||
queryKey: ['insurance-pricing'], queryFn: () => api.get('/api/v1/insurance-pricing'),
|
||||
});
|
||||
const freeVisit = (pricingData as any)?.data?.free_visit_price_rials ?? 0;
|
||||
const requireVisit = (pricingData as any)?.data?.require_visit_price ?? false;
|
||||
|
||||
useEffect(() => {
|
||||
if (freeVisit > 0 && (!visitPrice || visitPrice === '0')) setVisitPrice(String(freeVisit));
|
||||
if (freeVisit > 0 && (!visitPrice || visitPrice === '0')) setVisitPrice(String(rialToToman(freeVisit)));
|
||||
}, [freeVisit]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
const contracts = (contractsData as any)?.data?.data as Contract[] | undefined ?? [];
|
||||
@@ -194,7 +196,8 @@ export default function CreateStep({ recordUuid, profile, onCreated, onCancel }:
|
||||
};
|
||||
|
||||
// ── قیمتها (آینهی سرور) ────────────────────────────────────────────────
|
||||
const visit = Number(visitPrice) || 0;
|
||||
// فیلد «قیمت ویزیت» تومان است؛ محاسبات و API ریالیاند.
|
||||
const visit = tomanToRial(Number(visitPrice) || 0);
|
||||
const base = Number(basePercent) || 0;
|
||||
const supp = Number(suppPercent) || 0;
|
||||
const servicesTotal = useMemo(() => selectedServices.reduce((s, x) => s + x.price * x.qty, 0), [selectedServices]);
|
||||
@@ -222,6 +225,11 @@ export default function CreateStep({ recordUuid, profile, onCreated, onCancel }:
|
||||
});
|
||||
|
||||
const submit = () => {
|
||||
if (requireVisit && visit <= 0) {
|
||||
setVisitPriceError('هزینه ویزیت الزامی است');
|
||||
toast.error('هزینه ویزیت الزامی است');
|
||||
return;
|
||||
}
|
||||
createMut.mutate({
|
||||
visit_price_rials: visit,
|
||||
base_insurance_discount_percent: showInsurance ? base : 0,
|
||||
@@ -366,8 +374,18 @@ export default function CreateStep({ recordUuid, profile, onCreated, onCancel }:
|
||||
|
||||
{/* قیمت ویزیت */}
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<span style={fieldLabel}>قیمت ویزیت (تومان)</span>
|
||||
<input className="input" type="number" min={0} dir="ltr" aria-label="قیمت ویزیت" value={visitPrice} onChange={(e) => setVisitPrice(e.target.value)} />
|
||||
<span style={fieldLabel}>
|
||||
قیمت ویزیت (تومان){requireVisit && <span style={{ color: 'var(--danger)' }}> *</span>}
|
||||
</span>
|
||||
<input
|
||||
className="input" type="number" min={0} dir="ltr" aria-label="قیمت ویزیت"
|
||||
aria-invalid={!!visitPriceError}
|
||||
value={visitPrice}
|
||||
onChange={(e) => { setVisitPrice(e.target.value); setVisitPriceError(''); }}
|
||||
/>
|
||||
{visitPriceError && (
|
||||
<span style={{ fontSize: 12, color: 'var(--danger)', display: 'block', marginTop: 4 }}>{visitPriceError}</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* بیمه — منطق موجود NewSessionPage؛ فقط وقتی سرویس تحت پوشش یا بیمار بیمه دارد */}
|
||||
|
||||
Reference in New Issue
Block a user