feat(patients): service quantity in visit session
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -44,7 +44,7 @@ export default function NewSessionPage() {
|
||||
const nav = useNavigate();
|
||||
const qc = useQueryClient();
|
||||
|
||||
const [selectedServices, setSelectedServices] = useState<{ uuid: string; name: string; price: number }[]>([]);
|
||||
const [selectedServices, setSelectedServices] = useState<{ uuid: string; name: string; price: number; qty: number }[]>([]);
|
||||
const [sectionUuid, setSectionUuid] = useState('');
|
||||
const [itemUuid, setItemUuid] = useState('');
|
||||
const [baseId, setBaseId] = useState('');
|
||||
@@ -107,14 +107,17 @@ export default function NewSessionPage() {
|
||||
if (!itemUuid) return;
|
||||
const found = itemsData?.data?.find(i => i.uuid === itemUuid);
|
||||
if (!found || selectedServices.some(s => s.uuid === found.uuid)) return;
|
||||
setSelectedServices(p => [...p, { uuid: found.uuid, name: found.name, price: found.price_rials }]);
|
||||
setSelectedServices(p => [...p, { uuid: found.uuid, name: found.name, price: found.price_rials, qty: 1 }]);
|
||||
setItemUuid('');
|
||||
};
|
||||
|
||||
const setQty = (uuid: string, qty: number) =>
|
||||
setSelectedServices(p => p.map(s => s.uuid === uuid ? { ...s, qty: Math.max(1, qty) } : s));
|
||||
|
||||
const visit = Number(form.watch('visit_price_rials')) || 0;
|
||||
const base = Number(form.watch('base_insurance_discount_percent')) || 0;
|
||||
const supp = Number(form.watch('supplementary_discount_percent')) || 0;
|
||||
const servicesTotal = useMemo(() => selectedServices.reduce((s, x) => s + x.price, 0), [selectedServices]);
|
||||
const servicesTotal = useMemo(() => selectedServices.reduce((s, x) => s + x.price * x.qty, 0), [selectedServices]);
|
||||
const afterBase = Math.round(visit * (1 - base / 100));
|
||||
const afterSupp = Math.round(afterBase * (1 - supp / 100));
|
||||
const finalPrice = calcFinal(visit, base, supp, servicesTotal);
|
||||
@@ -130,7 +133,7 @@ export default function NewSessionPage() {
|
||||
});
|
||||
|
||||
const submit = form.handleSubmit((d) => {
|
||||
createMut.mutate({ ...d, services: selectedServices.map(s => ({ service_item_uuid: s.uuid })) });
|
||||
createMut.mutate({ ...d, services: selectedServices.map(s => ({ service_item_uuid: s.uuid, quantity: s.qty })) });
|
||||
});
|
||||
|
||||
const summaryRow = (label: string, val: number, strong = false) => (
|
||||
@@ -196,16 +199,21 @@ export default function NewSessionPage() {
|
||||
</button>
|
||||
</div>
|
||||
{selectedServices.length > 0 && (
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6 }}>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
{selectedServices.map(svc => (
|
||||
<span key={svc.uuid} style={{ display: 'inline-flex', alignItems: 'center', gap: 8, background: 'var(--primary-soft)', borderRadius: 20, padding: '4px 10px', fontSize: 12.5 }}>
|
||||
<span style={{ fontWeight: 500 }}>{svc.name}</span>
|
||||
<span style={{ color: 'var(--primary)', fontWeight: 600 }}>{formatRial(svc.price)}</span>
|
||||
<div key={svc.uuid} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '8px 12px', borderRadius: 10, border: '1px solid var(--border)' }}>
|
||||
<span style={{ flex: 1, fontWeight: 500, fontSize: 13 }}>{svc.name}</span>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
|
||||
<button type="button" className="mini-btn" onClick={() => setQty(svc.uuid, svc.qty - 1)} disabled={svc.qty <= 1}>−</button>
|
||||
<span style={{ minWidth: 26, textAlign: 'center', fontWeight: 600, fontSize: 13 }}>{svc.qty}</span>
|
||||
<button type="button" className="mini-btn" onClick={() => setQty(svc.uuid, svc.qty + 1)}>+</button>
|
||||
</div>
|
||||
<span style={{ color: 'var(--primary)', fontWeight: 600, fontSize: 13, minWidth: 90, textAlign: 'left' }} dir="ltr">{formatRial(svc.price * svc.qty)}</span>
|
||||
<button type="button" style={{ background: 'none', border: 'none', cursor: 'pointer', color: 'var(--danger)', padding: 0, display: 'flex' }}
|
||||
onClick={() => setSelectedServices(p => p.filter(s => s.uuid !== svc.uuid))}>
|
||||
<XMarkIcon style={{ width: 14 }} />
|
||||
<XMarkIcon style={{ width: 15 }} />
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user