'use client'; import React, { useState } from 'react'; import { CalculationInput, CalculationResult, PaperType, SystemSetting } from '@/types'; import { Printer, X, FileText, Wrench, Download, Check } from 'lucide-react'; interface QuotePrintModalProps { isOpen: boolean; onClose: () => void; input: CalculationInput; result: CalculationResult; paperType: PaperType; settings?: SystemSetting; quoteCode?: string; customerInfo?: { name: string; phone: string; company?: string; email?: string; address?: string; }; } export const QuotePrintModal: React.FC = ({ isOpen, onClose, input, result, paperType, settings, quoteCode = 'BG-202609-001', customerInfo = { name: 'Quý Khách Hàng', phone: '', company: '', }, }) => { const [activeDoc, setActiveDoc] = useState<'quote' | 'job_ticket'>('quote'); if (!isOpen) return null; const defaultSettings: SystemSetting = settings || { companyName: 'XƯỞNG IN ẤN & THIẾT KẾ PRINTCAL', companyAddress: 'Tòa nhà PrintCal, Số 123 Đường In Ấn, TP.HCM', companyPhone: '0900.888.999 - 028.3888.9999', companyEmail: 'baogia@printcal.vn', bankAccount: '19038889999999 - Techcombank (CN TP.HCM) - CTK: PRINTCAL VIETNAM', bankName: 'Techcombank Chi nhánh TP.HCM', quoteFooterNote: '1. Báo giá có hiệu lực trong vòng 15 ngày.\n2. Giá trên chưa bao gồm phí vận chuyển ngoại tỉnh.\n3. Thời gian giao hàng tính từ lúc duyệt bản in mẫu và đặt cọc 50%.\n4. Đảm bảo chất lượng màu sắc chuẩn theo file thiết kế.', defaultProfitMargin: 25, defaultVatPercent: 8, }; const todayStr = new Date().toLocaleDateString('vi-VN'); const handlePrint = () => { window.print(); }; return (
{/* Container Modal */}
{/* Header điều khiển (Không in) */}
{/* Nội dung tài liệu A4 để xem & in */}
{activeDoc === 'quote' ? ( // ================= PHIẾU BÁO GIÁ KHÁCH HÀNG =================
{/* Tiêu đề nhà in */}

{defaultSettings.companyName}

{defaultSettings.companyAddress}

Hotline: {defaultSettings.companyPhone} | Email: {defaultSettings.companyEmail}

BÁO GIÁ DỊCH VỤ {quoteCode}

Ngày: {todayStr}

{/* Thông tin khách hàng */}
Khách hàng / Công ty: {customerInfo.name || 'Khách Hàng'} {customerInfo.company &&

{customerInfo.company}

}
Số điện thoại / Email: {customerInfo.phone || 'Chưa cung cấp'} {customerInfo.email &&

{customerInfo.email}

}
{/* Bảng chi tiết quy cách in ấn */}

1. Quy Cách Sản Phẩm

Tên ấn phẩm: {input.jobName} Số lượng: {input.quantity.toLocaleString('vi-VN')} {input.productType === 'hop_giay' ? 'hộp' : input.productType === 'tui_giay' ? 'túi' : 'cái/cuốn'}
Kích thước: {input.widthMm} × {input.heightMm} mm Chất liệu giấy: {paperType.name}
Công nghệ in: {result.chosenTech === 'offset' ? 'In Offset Công Nghiệp (Chuẩn màu cao)' : 'In Nhanh Kỹ Thuật Số (Chất lượng cao)'} Số màu in: {input.printSides === '2_side' ? `In 2 mặt (${input.colorsFront || 4} màu / ${input.colorsBack || 4} màu)` : `In 1 mặt (${input.colorsFront || 4} màu)`}
Gia công sau in: {result.costs.finishingDetails.length > 0 ? (
    {result.costs.finishingDetails.map((f, i) => (
  • {f.name}
  • ))}
) : ( Xén thành phẩm chuẩn )}
{/* Bảng báo giá chi tiết */}

2. Bảng Giá Chi Tiết

{result.costs.discountAmount > 0 && ( )} {result.costs.vatAmount > 0 && ( )}
STT Nội Dung Ấn Phẩm ĐVT Số Lượng Đơn Giá Thành Tiền
01 {input.jobName} {input.widthMm}x{input.heightMm}mm, Giấy {paperType.name}, In {input.printSides === '2_side' ? '2 mặt' : '1 mặt'} Chiếc {input.quantity.toLocaleString('vi-VN')} {result.costs.unitPrice.toLocaleString('vi-VN')}đ {result.costs.finalPrice.toLocaleString('vi-VN')}đ
Chiết khấu ưu đãi: -{result.costs.discountAmount.toLocaleString('vi-VN')}đ
Thuế VAT ({input.vatPercent}%): +{result.costs.vatAmount.toLocaleString('vi-VN')}đ
TỔNG CỘNG THANH TOÁN: {result.costs.finalPrice.toLocaleString('vi-VN')} VNĐ
{/* Thông tin chuyển khoản & Điều khoản */}

Thông Tin Thanh Toán:

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

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

Nội dung CK: Tên KH + SĐT + {quoteCode}

Điều Khoản Giao Nhận:

{defaultSettings.quoteFooterNote}

{/* Chữ ký xác nhận */}
ĐẠI DIỆN KHÁCH HÀNG (Ký và ghi rõ họ tên)
ĐẠI DIỆN XƯỞNG IN (Ký, đóng dấu xác nhận)
) : ( // ================= LỆNH SẢN XUẤT XƯỞNG IN =================
NỘI BỘ XƯỞNG

LỆNH SẢN XUẤT IN ẤN

Đơn hàng: {input.jobName}

MÃ LỆNH {quoteCode}

Ngày tạo: {todayStr}

{/* Thông số kỹ thuật xưởng in */}
Số lượng thành phẩm: {input.quantity.toLocaleString('vi-VN')} con
Khổ thành phẩm (sau xén): {input.widthMm} × {input.heightMm} mm
Công nghệ in: {result.chosenTech}
{/* KHÂU 1: CẮT XẢ GIẤY MẸ */}

Khâu 1: Chuẩn Bị & Cắt Xả Giấy

Loại giấy: {paperType.name}
Khổ giấy mẹ: {result.imposition.parentSheet.name}
Cách chia khổ in: Chia {result.imposition.cutsPerParentSheet} ({result.imposition.printSheet.widthMm}x{result.imposition.printSheet.heightMm}mm)
Tổng giấy mẹ cần: {result.quantities.parentSheetsNeeded} tờ ({result.quantities.ramsNeeded} Ram / ~{result.quantities.kgNeeded} Kg)
{/* KHÂU 2: MÁY IN OFFSET / KTS */}

Khâu 2: In Ấn Máy {result.chosenTech.toUpperCase()}

Số con / tờ in: {result.imposition.upsPerPrintSheet} con/tờ
Kiểu in & Màu: {input.printSides === '2_side' ? 'In 2 mặt (CMYK)' : 'In 1 mặt'}
Tờ in thực tế (Net): {result.quantities.netPrintSheets} tờ
Bù hao in + gia công: +{result.quantities.printWasteSheets + result.quantities.finishingWasteSheets} tờ
TỔNG TỜ IN BÀN GIAO THỢ MÁY: {result.quantities.totalPrintSheets} TỜ IN KHỔ {result.imposition.printSheet.widthMm}×{result.imposition.printSheet.heightMm}MM
{/* KHÂU 3: GIA CÔNG SAU IN */}

Khâu 3: Danh Mục Gia Công Hoàn Thiện

{result.costs.finishingDetails.length > 0 ? ( {result.costs.finishingDetails.map((f, idx) => ( ))}
Công đoạn Loại Quy cách kỹ thuật Ký nhận thợ
{f.name} {f.category} {f.formula} __________
) : (

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

)}
{/* Chữ ký các bộ phận sản xuất */}
Ra Kẽm / File
Thợ Cắt Giấy
Thợ Máy In
Thợ Gia Công QC
)}
); };