garage-erp/apps/dashboard/shared/components/document-totals-summary.tsx
humam kerdiah 4bfd8c84a9 feat: add template checkpoint edit dialog and vendor management components
- Implemented TemplateCheckpointEditDialog for creating and editing inspection checkpoints.
- Added VendorActions component for managing vendor actions including edit, activate/deactivate, and delete.
- Created VendorContext for managing vendor state across components.
- Developed VendorGeneralInfo component to display detailed vendor information.
- Introduced AedSymbol and Money components for consistent currency representation.
- Added PromptDialog for user input prompts throughout the application.
- Implemented RelationLink component for unified related-data display in CRUD tables.
- Created InspectionTemplatesClient for API interactions related to inspection templates.
2026-05-18 12:08:42 +04:00

112 lines
3.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client"
import type { ReactNode } from "react"
import { Separator } from "@/shared/components/ui/separator"
import { cn } from "@/shared/lib/utils"
import type { DocumentTotals } from "@/shared/hooks/use-document-totals"
import { Money } from "@/shared/components/money"
export type DocumentTotalsSummaryProps = {
totals: DocumentTotals
discountType?: string | null
taxLabel?: string | null
/** Override labels for line groups, keyed by group name */
groupLabels?: Record<string, number>
}
function SummaryRow({
label,
value,
muted = false,
className,
}: {
label: string
value: ReactNode
muted?: boolean
className?: string
}) {
return (
<div className={cn("flex items-center justify-between text-sm", className)}>
<span className={muted ? "text-muted-foreground" : ""}>{label}</span>
<span className={muted ? "text-muted-foreground" : ""}>{value}</span>
</div>
)
}
export function DocumentTotalsSummary({
totals,
discountType,
taxLabel,
groupLabels,
}: DocumentTotalsSummaryProps) {
const {
subTotal,
lineItemDiscount,
transactionDiscount,
totalDiscount,
taxAmount,
total,
hasLineItems,
} = totals
if (!hasLineItems) return null
return (
<div className="space-y-2">
{/* Group breakdowns */}
{groupLabels &&
Object.entries(groupLabels).map(([label, amount]) => (
<SummaryRow
key={label}
label={label}
value={<Money value={amount} />}
muted
/>
))}
{groupLabels && Object.keys(groupLabels).length > 0 && <Separator />}
{/* Subtotal */}
<SummaryRow label="Subtotal" value={<Money value={subTotal} />} />
{/* Line-item discount */}
{discountType === "line_item_level" && lineItemDiscount > 0 && (
<SummaryRow
label="Line Discounts"
value={<Money value={lineItemDiscount} prefix=" " />}
muted
/>
)}
{/* Transaction-level discount */}
{discountType === "transaction_level" && transactionDiscount > 0 && (
<SummaryRow
label="Discount"
value={<Money value={transactionDiscount} prefix=" " />}
muted
/>
)}
{/* Tax */}
{taxAmount > 0 && (
<SummaryRow
label={taxLabel ?? "Tax"}
value={<Money value={taxAmount} prefix="+ " />}
muted
/>
)}
<Separator />
{/* Total */}
<div className={cn(
"flex items-center justify-between rounded-md px-3 py-2 text-sm font-semibold",
"bg-primary/10 text-primary",
)}>
<span>Total</span>
<span><Money value={total} /></span>
</div>
</div>
)
}