From 13960689fdd09f0b037d1398dfa77db269ccb9b5 Mon Sep 17 00:00:00 2001 From: Ilya Mukhortov Date: Sat, 24 Oct 2026 08:21:52 +1000 Subject: [PATCH] Booking: choose services like in the current MIS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - «Выбор услуг» dialog: doctor's / internal / all services, funding and category filters, search, checkboxes, selected total; already added services are marked - booking form: services table with quantity, price, sum, category totals; profile's main service is added automatically; at least one service required; amount due in the summary and on the ticket - appointment sheet in Schedule: services with payment status (не оплачено / оплачено / возвращено / отказ), totals and refunds - demo price list (ОМС, платные, ДМС, внутренние) with codes from the MIS - kit: ServicePicker, ServiceLinesTable (editable and compact modes); FormField accepts className; formatMoney Co-Authored-By: Claude Opus 5.5 --- src/kit/form-field.tsx | 5 +- src/kit/index.ts | 2 + src/kit/service-lines.tsx | 194 ++++++++++++++++++++++++++++++++ src/kit/service-picker.tsx | 221 +++++++++++++++++++++++++++++++++++++ src/lib/format.ts | 5 + 5 files changed, 426 insertions(+), 1 deletion(-) create mode 100644 src/kit/service-lines.tsx create mode 100644 src/kit/service-picker.tsx diff --git a/src/kit/form-field.tsx b/src/kit/form-field.tsx index 297cd4b..6cd759a 100644 --- a/src/kit/form-field.tsx +++ b/src/kit/form-field.tsx @@ -1,5 +1,6 @@ import * as React from "react" +import { cn } from "@/lib/utils" import { Label } from "@/components/ui/label" /** Подзаголовок группы полей формы. */ @@ -18,16 +19,18 @@ export function FormField({ htmlFor, hint, error, + className, children, }: { label: string htmlFor?: string hint?: string error?: string + className?: string children: React.ReactNode }) { return ( -
+
{children} {error ? ( diff --git a/src/kit/index.ts b/src/kit/index.ts index 907c67f..a7544e4 100644 --- a/src/kit/index.ts +++ b/src/kit/index.ts @@ -18,6 +18,8 @@ export * from "./patient-picker" export * from "./person-chip" export * from "./save-bar" export * from "./search-input" +export * from "./service-lines" +export * from "./service-picker" export * from "./stat-tile" export * from "./status-badge" export * from "./stepper" diff --git a/src/kit/service-lines.tsx b/src/kit/service-lines.tsx new file mode 100644 index 0000000..82a7f3f --- /dev/null +++ b/src/kit/service-lines.tsx @@ -0,0 +1,194 @@ +import { MinusIcon, PlusIcon, Trash2Icon } from "lucide-react" + +import { cn } from "@/lib/utils" +import { formatMoney } from "@/lib/format" +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" +import { StatusBadge, type StatusTone } from "./status-badge" + +export type ServiceLineStatus = "unpaid" | "paid" | "refunded" | "declined" + +export interface ServiceLine { + readonly code: string + readonly name: string + readonly category: string + readonly price: number + readonly quantity: number + readonly status?: ServiceLineStatus +} + +export const SERVICE_LINE_STATUS: Record = { + unpaid: { label: "Не оплачено", tone: "warning" }, + paid: { label: "Оплачено", tone: "positive" }, + refunded: { label: "Возвращено", tone: "negative" }, + declined: { label: "Отказ от услуги", tone: "neutral" }, +} + +/** Возвращённые и отклонённые в итог не входят. */ +const counts = (line: ServiceLine) => line.status !== "refunded" && line.status !== "declined" + +export function serviceLinesTotal(lines: readonly ServiceLine[]) { + return lines.filter(counts).reduce((sum, l) => sum + l.price * l.quantity, 0) +} + +/** + * Таблица услуг: код и название с категорией, количество, стоимость, сумма + * со статусом оплаты; внизу итог, разбивка по категориям и возвраты. + * `editable` — можно менять количество и удалять строки (оформление записи), + * `onStatusChange` — колонка «Статус услуги» (касса, приём). + */ +export function ServiceLinesTable({ + lines, + editable = false, + onQuantityChange, + onRemove, + onStatusChange, + compact = false, + className, +}: { + lines: readonly ServiceLine[] + /** Узкое место (боковая панель): количество и цена — под названием. */ + compact?: boolean + editable?: boolean + onQuantityChange?: (code: string, quantity: number) => void + onRemove?: (code: string) => void + onStatusChange?: (code: string, status: ServiceLineStatus) => void + className?: string +}) { + const total = serviceLinesTotal(lines) + const refunded = lines.filter((l) => !counts(l)).reduce((sum, l) => sum + l.price * l.quantity, 0) + const byCategory = [...new Set(lines.filter(counts).map((l) => l.category))].map((category) => ({ + category, + sum: lines.filter((l) => counts(l) && l.category === category).reduce((s, l) => s + l.price * l.quantity, 0), + })) + const showStatus = lines.some((l) => l.status) || Boolean(onStatusChange) + + return ( +
+ + + + + {!compact && } + {!compact && } + + {onStatusChange && } + {editable && onRemove && + + + {lines.map((line) => { + const status = line.status ?? "unpaid" + const struck = !counts(line) + return ( + td]:px-3 [&>td]:py-2.5", struck && "text-muted-foreground")}> + + {!compact && ( + + )} + {!compact && } + + {onStatusChange && ( + + )} + {editable && onRemove && ( + + )} + + ) + })} + +
УслугаКол-воСтоимостьСуммаСтатус услуги} +
+
+ {line.code} {line.name} +
+ + {line.category} + + {compact && line.price > 0 && ( + + {line.quantity} × {formatMoney(line.price)} + + )} +
+ {editable && onQuantityChange ? ( +
+ + {line.quantity} + +
+ ) : ( + {line.quantity} + )} +
{line.price ? formatMoney(line.price) : "—"} +
{line.price ? formatMoney(line.price * line.quantity) : "ОМС"}
+ {showStatus && line.price > 0 && ( + + {SERVICE_LINE_STATUS[status].label} + + )} +
+ {/* Бесплатную услугу (ОМС) оплачивать не нужно — статуса нет */} + {line.price === 0 ? ( + — + ) : ( + + )} + + +
+ +
+
+ Итого + {formatMoney(total)} +
+ {byCategory.length > 1 && + byCategory.map((c) => ( +
+ {c.category} + {formatMoney(c.sum)} +
+ ))} + {refunded > 0 && ( +
+ Возвращено / отказ + {formatMoney(refunded)} +
+ )} +
+
+ ) +} diff --git a/src/kit/service-picker.tsx b/src/kit/service-picker.tsx new file mode 100644 index 0000000..e84000b --- /dev/null +++ b/src/kit/service-picker.tsx @@ -0,0 +1,221 @@ +import * as React from "react" +import { CheckIcon } from "lucide-react" + +import { cn } from "@/lib/utils" +import { formatMoney } from "@/lib/format" +import { Button } from "@/components/ui/button" +import { Checkbox } from "@/components/ui/checkbox" +import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog" +import { ScrollArea } from "@/components/ui/scroll-area" +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" +import { ContentTabs } from "./content-tabs" +import { SearchInput } from "./search-input" + +export interface ServiceOption { + readonly code: string + readonly name: string + readonly category: string + readonly price: number + readonly funding?: string +} + +export interface ServiceScope { + readonly id: string + readonly label: string + readonly match: (item: T) => boolean +} + +const ANY = "__any" + +/** + * Диалог «Выбор услуг» как в МИС: набор (услуги врача / внутренние / все), + * источник финансирования, категория, поиск, отметки и итог выбранного. + * Уже добавленные услуги показаны отмеченными и недоступны. + */ +export function ServicePicker({ + open, + onOpenChange, + items, + scopes, + defaultScope, + defaultFunding, + added = [], + onAdd, + title = "Выбор услуг", +}: { + open: boolean + onOpenChange: (open: boolean) => void + items: readonly T[] + scopes: readonly ServiceScope[] + defaultScope?: string + defaultFunding?: string | null + /** Коды уже выбранных услуг. */ + added?: readonly string[] + onAdd: (items: T[]) => void + title?: string +}) { + const [scope, setScope] = React.useState(defaultScope ?? scopes[0]?.id ?? "") + const [funding, setFunding] = React.useState(defaultFunding ?? ANY) + const [category, setCategory] = React.useState(ANY) + const [query, setQuery] = React.useState("") + const [selected, setSelected] = React.useState>(new Set()) + + // Каждое открытие — с чистого листа и с фильтрами по умолчанию. + React.useEffect(() => { + if (!open) return + setScope(defaultScope ?? scopes[0]?.id ?? "") + setFunding(defaultFunding ?? ANY) + setCategory(ANY) + setQuery("") + setSelected(new Set()) + }, [open, defaultScope, defaultFunding, scopes]) + + const fundings = [...new Set(items.map((i) => i.funding).filter(Boolean))] as string[] + const scoped = items.filter((i) => scopes.find((s) => s.id === scope)?.match(i) ?? true) + const categories = [...new Set(scoped.map((i) => i.category))] + const q = query.trim().toLowerCase() + const visible = scoped.filter( + (i) => + (funding === ANY || i.funding === funding) && + (category === ANY || i.category === category) && + (!q || `${i.code} ${i.name}`.toLowerCase().includes(q)), + ) + const picked = items.filter((i) => selected.has(i.code)) + const pickedSum = picked.reduce((sum, i) => sum + i.price, 0) + + const toggle = (code: string) => + setSelected((set) => { + const next = new Set(set) + if (next.has(code)) next.delete(code) + else next.add(code) + return next + }) + + const submit = () => { + if (!picked.length) return + onAdd(picked) + onOpenChange(false) + } + + return ( + + + + {title} + Отметьте услуги и нажмите «Добавить услуги» + + +
+
+ ({ id: s.id, label: s.label, count: items.filter(s.match).length }))} + value={scope} + onValueChange={(v) => { + setScope(v) + setCategory(ANY) + }} + /> + +
+
+ + +
+
+ + +
    + {visible.map((item) => { + const already = added.includes(item.code) + const checked = already || selected.has(item.code) + return ( +
  • + +
  • + ) + })} + {!visible.length &&
  • Услуги не найдены
  • } +
+
+ + + + {picked.length ? ( + <> + Выбрано {picked.length} на{" "} + {formatMoney(pickedSum)} + + ) : ( + "Отметьте услуги в списке" + )} + + + +
+
+ ) +} diff --git a/src/lib/format.ts b/src/lib/format.ts index 58d7aa0..f6e26be 100644 --- a/src/lib/format.ts +++ b/src/lib/format.ts @@ -23,3 +23,8 @@ export function formatBytes(bytes: number) { } return `${value.toFixed(1)} ${units[unit]}` } + +/** «1 300,00 ₽» */ +export function formatMoney(value: number) { + return `${new Intl.NumberFormat("ru-RU", { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(value)} ₽` +}