'use client'; import React from 'react'; import type { OrderSpec, SystemSetting } from '@/types'; import { formatDateTime, formatNumber, formatVnd } from '@/lib/format'; import { DIGITAL_MATERIAL_LABELS, FINISHING_CATEGORY_LABELS, PRODUCT_TYPE_LABELS, PRODUCT_UNITS, WORK_TYPE_LABELS } from '@/lib/engine/constants'; export interface QuoteDocumentProps { kind: 'quote' | 'job'; spec: OrderSpec; settings: SystemSetting; code?: string; date: string; customer: { name: string; phone: string; company?: string; email?: string }; notes?: string; } const cell = 'border border-slate-300 px-2 py-1.5 align-top'; const head = 'border border-slate-300 px-2 py-1.5 bg-slate-100 font-semibold text-left'; function techText(spec: OrderSpec) { const { input, result } = spec; if (result.chosenTech === 'offset') return 'In offset'; return input.digitalMode === 'without_paper' ? `In nhanh KTS (Konica${input.digitalMaterial ? ` – ${DIGITAL_MATERIAL_LABELS[input.digitalMaterial]}` : ''})` : 'In nhanh KTS (kèm giấy)'; } function colorsText(spec: OrderSpec) { const { input } = spec; const two = input.printSides === '2_side' || input.productType === 'catalogue'; return two ? `2 mặt (${input.colorsFront}/${input.colorsBack || input.colorsFront} màu)` : `1 mặt (${input.colorsFront} màu)`; } /** Phiếu báo giá khách hàng / Lệnh sản xuất – khổ A4, dùng chung cho xem trước và in */ export function QuoteDocument(props: QuoteDocumentProps) { return (
{props.kind === 'quote' ? : }
); } function QuoteSheet({ spec, settings, code, date, customer, notes }: QuoteDocumentProps) { const { input, result, paper } = spec; const c = result.costs; const unit = PRODUCT_UNITS[input.productType]; const goods = c.preTaxTotal + c.discountAmount; // tiền hàng trước giảm giá return (

{settings.companyName}

{settings.companyAddress &&

{settings.companyAddress}

}

{settings.companyPhone && <>ĐT: {settings.companyPhone}} {settings.companyPhone && settings.companyEmail && ' · '} {settings.companyEmail && <>Email: {settings.companyEmail}}

BÁO GIÁ

{code ?? 'BẢN NHÁP'}

Ngày: {formatDateTime(date, false)}

Kính gửi:

{customer.name || 'Quý khách hàng'}

{customer.company &&

{customer.company}

}

Liên hệ:

{customer.phone || '—'}

{customer.email &&

{customer.email}

}

1. Quy cách sản phẩm

Tên sản phẩm {input.jobName} Loại {PRODUCT_TYPE_LABELS[input.productType]}
Kích thước {input.widthMm} × {input.heightMm} mm{input.productType === 'catalogue' ? ` · ${input.pages} trang` : ''} Số lượng {formatNumber(input.quantity)} {unit}
Chất liệu {paper.name} In {techText(spec)} · {colorsText(spec)}
Gia công {c.finishingDetails.length > 0 ? c.finishingDetails.map((f) => f.name + (f.sides === 2 ? ' (2 mặt)' : '')).join(' · ') : 'Xén thành phẩm'}

2. Chi phí

{c.discountAmount > 0 && ( )} {c.vatPercent > 0 && ( <> )}
STT Nội dung ĐVT SL Đơn giá Thành tiền
1 {input.jobName} {input.widthMm}×{input.heightMm}mm · {paper.name} · {colorsText(spec)} {unit} {formatNumber(input.quantity)} {formatNumber(goods / input.quantity, true)} {formatVnd(goods)}
Chiết khấu −{formatVnd(c.discountAmount)}
Cộng tiền hàng {formatVnd(c.preTaxTotal)}
Thuế VAT ({formatNumber(c.vatPercent, true)}%) {formatVnd(c.vatAmount)}
Tổng cộng thanh toán {formatVnd(c.finalPrice)}

Đơn giá bình quân: {formatVnd(c.unitPrice)} / {unit} {c.vatPercent > 0 ? ' (đã gồm VAT)' : c.vatPercent === 0 ? ' (chưa gồm VAT)' : ''}.

{notes && (
Ghi chú: {notes}
)}

Thông tin thanh toán

{settings.bankName &&

Ngân hàng: {settings.bankName}

} {settings.bankAccount &&

Tài khoản: {settings.bankAccount}

}

Nội dung CK: Tên KH + SĐT{code ? ` + ${code}` : ''}

Điều khoản

{settings.quoteFooterNote}

Xác nhận của khách hàng

(Ký, ghi rõ họ tên)

Đại diện {settings.companyName ? 'nhà in' : 'xưởng in'}

(Ký, đóng dấu)

); } function JobTicket({ spec, code, date, customer, notes }: QuoteDocumentProps) { const { input, result, paper } = spec; const q = result.quantities; const im = result.imposition; const unit = PRODUCT_UNITS[input.productType]; return (
Nội bộ xưởng

Lệnh sản xuất

Bài in: {input.jobName} · Khách: {customer.name || 'Khách vãng lai'} {customer.phone && `(${customer.phone})`}

Mã lệnh

{code ?? 'BẢN NHÁP'}

{formatDateTime(date, false)}

0 ? ` · cách con ${im.gapMm}mm` : ''}`], ...(result.chosenTech === 'offset' ? ([ ['Kiểu in', result.printing.workType ? WORK_TYPE_LABELS[result.printing.workType] : 'In 1 mặt'], ['Kẽm CTP', `${result.printing.platesCount} lá · ${result.printing.passes} lần lên máy`], ] as [string, string][]) : []), ['Tờ in thực', `${formatNumber(q.netPrintSheets)} tờ`], ['Bù hao in / gia công', `${formatNumber(q.printWasteSheets)} / ${formatNumber(q.finishingWasteSheets)} tờ`], ['Tổng lượt in', `${formatNumber(q.impressions)} lượt`], ]} />

TỔNG TỜ IN GIAO THỢ MÁY: {formatNumber(q.totalPrintSheets)} tờ khổ {im.printSheet.widthMm}×{im.printSheet.heightMm} mm

{result.costs.finishingDetails.length > 0 ? ( {result.costs.finishingDetails.map((f) => ( ))}
Công đoạn Nhóm Quy cách Ký nhận
{f.name} {FINISHING_CATEGORY_LABELS[f.category] ?? f.category} {f.sides === 2 ? '2 mặt · ' : ''} {formatNumber(f.quantity, true)} {f.unit}
) : (

Chỉ xén, đóng gói thành phẩm.

)}
{notes && (

Ghi chú: {notes}

)}
{['Ra kẽm / file', 'Thợ cắt giấy', 'Thợ máy in', 'Gia công / QC'].map((r) => (

{r}

))}
); } function Box({ label, value }: { label: string; value: string }) { return (

{label}

{value}

); } function Stage({ title, children }: { title: string; children: React.ReactNode }) { return (

{title}

{children}
); } function Grid({ items }: { items: [string, string][] }) { return (
{items.map(([k, v]) => (
{k}
{v}
))}
); } /** Sơ đồ bình trang tĩnh (để in) */ function SheetDiagram({ spec }: { spec: OrderSpec }) { const im = spec.result.imposition; const W = im.printSheet.widthMm; const H = im.printSheet.heightMm; return ( {im.gripperMarginMm > 3 && } {im.boxes.map((b) => ( {b.index} ))} ); }