garage-erp/apps/dashboard/modules/invoices/invoice-parts-section.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

105 lines
3.8 KiB
TypeScript

"use client"
import { Wrench } from "lucide-react"
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from "@/shared/components/ui/card"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/shared/components/ui/table"
import { formatNumber } from "@/shared/utils/formatters"
import { Money } from "@/shared/components/money"
type InvoicePart = {
id: number
invoice_id: number
part_id: number
quantity: string | number
rate: string | number
description?: string
chart_of_account?: string
department_id?: number
created_at?: string
updated_at?: string
}
type InvoicePartsSectionProps = {
parts?: InvoicePart[]
}
export function InvoicePartsSection({ parts = [] }: InvoicePartsSectionProps) {
if (!parts || parts.length === 0) {
return null
}
const subtotal = parts.reduce((sum, part) => {
const qty = parseFloat(String(part.quantity))
const rate = parseFloat(String(part.rate))
return sum + (qty * rate)
}, 0)
return (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Wrench className="size-4" />
Parts
</CardTitle>
</CardHeader>
<CardContent>
<div className="overflow-x-auto">
<Table>
<TableHeader>
<TableRow>
<TableHead>Description</TableHead>
<TableHead className="text-right">Quantity</TableHead>
<TableHead className="text-right">Rate</TableHead>
<TableHead className="text-right">Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{parts.map((part) => {
const qty = parseFloat(String(part.quantity))
const rate = parseFloat(String(part.rate))
const amount = qty * rate
return (
<TableRow key={part.id}>
<TableCell className="max-w-xs truncate">
{part.description || `Part #${part.part_id}`}
</TableCell>
<TableCell className="text-right">
{formatNumber(qty)}
</TableCell>
<TableCell className="text-right">
{<Money value={rate} />}
</TableCell>
<TableCell className="text-right font-medium">
{<Money value={amount} />}
</TableCell>
</TableRow>
)
})}
<TableRow className="bg-muted/50 font-medium">
<TableCell colSpan={3} className="text-right">
Subtotal
</TableCell>
<TableCell className="text-right">
{<Money value={subtotal} />}
</TableCell>
</TableRow>
</TableBody>
</Table>
</div>
</CardContent>
</Card>
)
}