fix(digital-print): khong bu hao in nhanh, chuan hoa binh bai A4/A5/A6/Namecard va phoi giay INTC
Browse filesFiles changed (4)
40 unmodified lines414243444546444 unmodified lines49149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454591 unmodified lines63763863964064164264364440 unmodified linesSearch,} from 'lucide-react';export default function HomePage() {const [activeTab, setActiveTab] = useState<ActiveTab>('calculator');444 unmodified lines</button></div>{/* Selected Paper Preview Card */}<divonClick={() => setIsPaperModalOpen(true)}className="group relative cursor-pointer border border-slate-300 hover:border-blue-500 bg-white hover:bg-blue-50/20 p-3 rounded-xl transition-all shadow-2xs"><div className="flex items-start justify-between gap-2"><div><div className="flex items-center gap-2 mb-1"><span className="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-bold bg-amber-50 text-amber-800 border border-amber-200">NCC: {selectedPaper?.supplier || 'Thuận Phát'}</span><span className="font-mono text-xs text-slate-500 font-semibold">{selectedPaper?.code}</span></div><h4 className="font-bold text-slate-900 text-sm group-hover:text-blue-600 transition-colors">{selectedPaper?.name || 'Chưa chọn giấy'}</h4><p className="text-[11px] text-slate-500 mt-0.5">Định lượng: <strong className="text-blue-700">{selectedPaper?.gsm} gsm</strong> • Khổ mẹ: <strong>{selectedPaper?.parentWidthCm} × {selectedPaper?.parentHeightCm} cm</strong></p></div><div className="text-right shrink-0"><div className="text-[11px] font-medium text-slate-500">Đơn giá áp dụng:</div><div className="font-black text-emerald-700 text-sm">{((result?.quantities?.parentSheetsNeeded || 0) >= 500? (selectedPaper?.priceAbove500 || selectedPaper?.pricePerRam || 0): (selectedPaper?.priceBelow500 || selectedPaper?.priceAbove500 || selectedPaper?.pricePerRam || 0)).toLocaleString('vi-VN')} đ/ram</div><div className="text-[10px] text-slate-400">{(result?.quantities?.parentSheetsNeeded || 0) >= 500? 'Mức ≥ 500 tờ (nguyên ram)': 'Mức < 500 tờ (bán lẻ)'}</div></div></div><div className="mt-2 pt-2 border-t border-slate-100 flex items-center justify-between text-[11px]"><span className="text-slate-400">Bấm vào đây để tìm theo NCC, loại giấy, định lượng gsm...</span><span className="text-blue-600 font-semibold group-hover:underline">Đổi giấy →</span></div></div></div>{/* Số mặt in & Công nghệ in */}91 unmodified lines</div>{digitalMode === 'with_paper' ? (<div className="text-[11px] text-sky-800 bg-white/70 p-2 rounded-lg border border-sky-100"><strong>Bảng giá INTC (14.03.2026):</strong> Trọn gói công in + giấy theo mã giấy. Khổ in 325×430 & 325×355mm. Phụ phí SL ít: <50 tờ (+30k), <100 tờ (+20k), ≥100 tờ miễn phí.</div>) : (<div className="text-[11px] text-sky-800 bg-white/70 p-2 rounded-lg border border-sky-100 space-y-2">40 unmodified lines4142434445464748495051525354555657585960616263444 unmodified lines50850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364491 unmodified lines73673773873974074174274374474574674774874975075175275375440 unmodified linesSearch,} from 'lucide-react';const INTC_PAPER_PRESETS = [{ code: 'C100', label: 'C100' },{ code: 'C120', label: 'C120' },{ code: 'C150', label: 'C150' },{ code: 'C200', label: 'C200' },{ code: 'C250', label: 'C250' },{ code: 'C300', label: 'C300' },{ code: 'I250', label: 'I250' },{ code: 'I300', label: 'I300' },{ code: 'I350', label: 'I350' },{ code: 'F100', label: 'F100' },{ code: 'F120', label: 'F120' },{ code: 'F180', label: 'F180' },{ code: 'F230', label: 'F230' },{ code: 'F250', label: 'F250' },];export default function HomePage() {const [activeTab, setActiveTab] = useState<ActiveTab>('calculator');444 unmodified lines</button></div>{/* Thanh chọn nhanh 16 mã giấy INTC khi in nhanh kèm giấy */}{((printTech === 'digital' || (printTech === 'auto' && result?.chosenTech === 'digital')) && digitalMode === 'with_paper') && (<div className="mb-2.5 p-2.5 bg-sky-50/80 border border-sky-200 rounded-xl space-y-1.5 shadow-2xs"><div className="flex items-center justify-between text-[11px] font-bold text-sky-950"><span className="flex items-center gap-1"><Sparkles className="w-3.5 h-3.5 text-sky-600" />Chọn nhanh 16 mã giấy INTC (14.03.2026):</span><span className="text-[10px] text-emerald-700 bg-emerald-100/80 px-2 py-0.5 rounded-md font-bold border border-emerald-200">Trọn gói in + giấy • 0 bù hao</span></div><div className="flex flex-wrap gap-1">{INTC_PAPER_PRESETS.map((preset) => {const isSelected = selectedPaper?.code.toUpperCase().includes(preset.code);return (<buttonkey={preset.code}type="button"onClick={() => {const matched = papers.find((p) => p.code.toUpperCase().includes(preset.code));if (matched) setPaperTypeId(matched.id);}}className={`px-2 py-1 rounded text-[11px] font-semibold transition-all ${isSelected? 'bg-sky-600 text-white shadow-2xs ring-2 ring-sky-300': 'bg-white hover:bg-sky-100 text-slate-700 border border-slate-200'}`}>{preset.label}</button>);})}</div></div>)}{/* Selected Paper Preview Card */}{((printTech === 'digital' || (printTech === 'auto' && result?.chosenTech === 'digital')) && digitalMode === 'with_paper') ? (<divonClick={() => setIsPaperModalOpen(true)}className="group relative cursor-pointer border border-sky-300 hover:border-sky-500 bg-sky-50/40 hover:bg-sky-50/70 p-3 rounded-xl transition-all shadow-2xs"><div className="flex items-start justify-between gap-2"><div><div className="flex items-center gap-2 mb-1"><span className="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-bold bg-sky-100 text-sky-900 border border-sky-300">Phôi In Kèm Giấy INTC</span><span className="font-mono text-xs text-sky-700 font-bold">{selectedPaper?.code}</span></div><h4 className="font-bold text-slate-900 text-sm group-hover:text-sky-600 transition-colors">{selectedPaper?.name || 'Chưa chọn giấy'}</h4><p className="text-[11px] text-slate-600 mt-0.5">Định lượng: <strong className="text-sky-700">{selectedPaper?.gsm} gsm</strong> • Khổ phôi in: <strong>32.5 × 43 cm</strong> (hoặc 32.5 × 35.5 cm)</p></div><div className="text-right shrink-0"><div className="text-[11px] font-medium text-slate-500">Tiền phôi giấy:</div><div className="font-black text-emerald-700 text-sm">0 đ (Đã gồm trong giá in)</div><div className="text-[10px] text-emerald-600 font-bold">In bao nhiêu tính bấy nhiêu</div></div></div><div className="mt-2 pt-2 border-t border-sky-200/60 flex items-center justify-between text-[11px]"><span className="text-slate-600 flex items-center gap-1"><span className="text-emerald-700 font-bold">✓ Không bù hao:</span> Đúng {result?.quantities?.totalPrintSheets || Math.ceil(quantity / 2)} tờ in phôi thực tế</span><span className="text-sky-600 font-semibold group-hover:underline">Đổi loại giấy →</span></div></div>) : (<divonClick={() => setIsPaperModalOpen(true)}className="group relative cursor-pointer border border-slate-300 hover:border-blue-500 bg-white hover:bg-blue-50/20 p-3 rounded-xl transition-all shadow-2xs"><div className="flex items-start justify-between gap-2"><div><div className="flex items-center gap-2 mb-1"><span className="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-bold bg-amber-50 text-amber-800 border border-amber-200">NCC: {selectedPaper?.supplier || 'Thuận Phát'}</span><span className="font-mono text-xs text-slate-500 font-semibold">{selectedPaper?.code}</span></div><h4 className="font-bold text-slate-900 text-sm group-hover:text-blue-600 transition-colors">{selectedPaper?.name || 'Chưa chọn giấy'}</h4><p className="text-[11px] text-slate-500 mt-0.5">Định lượng: <strong className="text-blue-700">{selectedPaper?.gsm} gsm</strong> • Khổ mẹ: <strong>{selectedPaper?.parentWidthCm} × {selectedPaper?.parentHeightCm} cm</strong></p></div><div className="text-right shrink-0"><div className="text-[11px] font-medium text-slate-500">Đơn giá áp dụng:</div><div className="font-black text-emerald-700 text-sm">{((result?.quantities?.parentSheetsNeeded || 0) >= 500? (selectedPaper?.priceAbove500 || selectedPaper?.pricePerRam || 0): (selectedPaper?.priceBelow500 || selectedPaper?.priceAbove500 || selectedPaper?.pricePerRam || 0)).toLocaleString('vi-VN')} đ/ram</div><div className="text-[10px] text-slate-400">{(result?.quantities?.parentSheetsNeeded || 0) >= 500? 'Mức ≥ 500 tờ (nguyên ram)': 'Mức < 500 tờ (bán lẻ)'}</div></div></div><div className="mt-2 pt-2 border-t border-slate-100 flex items-center justify-between text-[11px]"><span className="text-slate-400">Bấm vào đây để tìm theo NCC, loại giấy, định lượng gsm...</span><span className="text-blue-600 font-semibold group-hover:underline">Đổi giấy →</span></div></div>)}</div>{/* Số mặt in & Công nghệ in */}91 unmodified lines</div>{digitalMode === 'with_paper' ? (<div className="text-[11px] text-sky-900 bg-white/90 p-2.5 rounded-lg border border-sky-100 space-y-1"><div className="flex items-center justify-between font-bold"><span>📦 Bảng giá INTC (14.03.2026) - Trọn gói in & phôi giấy:</span><span className="text-[10px] text-emerald-700 bg-emerald-50 px-2 py-0.5 rounded font-bold border border-emerald-200">Không bù hao (0 tờ)</span></div><div className="text-slate-600">Khổ in phôi cắt sẵn 32.5×43cm & 32.5×35.5cm. Số tờ in cần chạy: <strong className="text-sky-950 font-bold">{result?.quantities?.totalPrintSheets || 0} tờ phôi</strong>.</div><div className="text-[10px] text-slate-500">Phụ phí SL ít: <50 tờ (+30k), <100 tờ (+20k), ≥100 tờ miễn phí hoàn toàn.</div></div>) : (<div className="text-[11px] text-sky-800 bg-white/70 p-2 rounded-lg border border-sky-100 space-y-2">
109 unmodified lines11011111211311411511613 unmodified lines1301311321331341351369 unmodified lines1461471481491501511522 unmodified lines155156157158159160109 unmodified lines<div className="py-2 flex justify-between items-center"><span className="flex items-center gap-1.5 text-slate-600"><Layers className="w-3.5 h-3.5 text-blue-600" />Tiền giấy ({quantities.parentSheetsNeeded} tờ mẹ):</span><span className="font-semibold text-slate-900">{costs.paperCost === 0 && costs.digitalDetails?.mode === 'with_paper' ? (13 unmodified lines<div className="py-2 flex justify-between items-center"><span className="flex items-center gap-1.5 text-slate-600"><Sparkles className="w-3.5 h-3.5 text-indigo-600" />Tiền in {chosenTech === 'offset' ? (costs.plateCost === 0 ? '(Gói trọn gồm kẽm)' : `(${costs.platesCount} kẽm + công)`) : `(${costs.digitalDetails?.mode === 'with_paper' ? 'Kèm giấy INTC' : 'Gia công Konica'})`}:</span><span className="font-semibold text-slate-900">{costs.totalPrintCost.toLocaleString('vi-VN')}đ</span></div>9 unmodified lines<span className="text-sky-700">Khổ: {costs.digitalDetails.sheetSizeName || imposition.printSheet.name}</span></div><div className="flex justify-between text-slate-600"><span>Đơn giá: {costs.digitalDetails.ratePerSheet.toLocaleString('vi-VN')}đ / tờ in</span>{costs.shortRunFee && costs.shortRunFee > 0 ? (<span className="font-bold text-amber-700 bg-amber-50 px-1.5 py-0.5 rounded">Phụ phí SL ít: +{costs.shortRunFee.toLocaleString('vi-VN')}đ2 unmodified lines<span className="text-emerald-700 font-semibold">Miễn phụ phí</span>)}</div></div>)}109 unmodified lines11011111211311411511611711813 unmodified lines1321331341351361371381391409 unmodified lines1501511521531541551562 unmodified lines159160161162163164165166167109 unmodified lines<div className="py-2 flex justify-between items-center"><span className="flex items-center gap-1.5 text-slate-600"><Layers className="w-3.5 h-3.5 text-blue-600" />{chosenTech === 'digital' && costs.digitalDetails?.mode === 'with_paper'? `Phôi giấy INTC (${quantities.totalPrintSheets} tờ):`: `Tiền giấy (${quantities.parentSheetsNeeded} tờ mẹ):`}</span><span className="font-semibold text-slate-900">{costs.paperCost === 0 && costs.digitalDetails?.mode === 'with_paper' ? (13 unmodified lines<div className="py-2 flex justify-between items-center"><span className="flex items-center gap-1.5 text-slate-600"><Sparkles className="w-3.5 h-3.5 text-indigo-600" />{chosenTech === 'offset'? `Tiền in ${costs.plateCost === 0 ? '(Gói trọn gồm kẽm)' : `(${costs.platesCount} kẽm + công)`}:`: `Tiền in (${quantities.totalPrintSheets} tờ, Không bù hao):`}</span><span className="font-semibold text-slate-900">{costs.totalPrintCost.toLocaleString('vi-VN')}đ</span></div>9 unmodified lines<span className="text-sky-700">Khổ: {costs.digitalDetails.sheetSizeName || imposition.printSheet.name}</span></div><div className="flex justify-between text-slate-600"><span>Đơn giá: {costs.digitalDetails.ratePerSheet.toLocaleString('vi-VN')}đ / tờ in ({quantities.totalPrintSheets} tờ)</span>{costs.shortRunFee && costs.shortRunFee > 0 ? (<span className="font-bold text-amber-700 bg-amber-50 px-1.5 py-0.5 rounded">Phụ phí SL ít: +{costs.shortRunFee.toLocaleString('vi-VN')}đ2 unmodified lines<span className="text-emerald-700 font-semibold">Miễn phụ phí</span>)}</div><div className="text-[10px] text-emerald-700 font-semibold pt-0.5 flex items-center gap-1"><span>✓</span> In đúng {quantities.totalPrintSheets} tờ thực tế (Không bù hao)</div></div>)}
215 unmodified lines2162172182192202212222232242252262272282292302312322332347 unmodified lines242243244245246247248103 unmodified lines3523533543553563573583593603612 unmodified lines36436536636736836937037137221 unmodified lines394395396397398399400219 unmodified lines6206216226236246256266276286296306316326336343 unmodified lines638639640641642643644645646215 unmodified lines}// Bù hao gia công theo %finishingWasteSheets += Math.ceil((netPrintSheets * totalFinishingWastePercent) / 100);// 4. Bù hao in ấn & Tổng số tờ inlet printWasteSheets = 0;if (chosenTech === 'offset') {printWasteSheets = offsetMachine?.defaultWasteSheets ?? 100;} else {printWasteSheets = digitalMachine?.defaultWasteSheets ?? 4;}const totalPrintSheets = netPrintSheets + printWasteSheets + finishingWasteSheets;const cuts = Math.max(1, imposition.cutsPerParentSheet);const parentSheetsNeeded = Math.ceil(totalPrintSheets / cuts);const ramsNeeded = Math.round((parentSheetsNeeded / 500) * 100) / 100;// Tính kg giấy = Số tờ lớn * Dài (m) * Rộng (m) * (gsm / 1000)7 unmodified lines// Nếu số tờ mẹ >= 500 (trên 1 ram) áp dụng giá sỉ nguyên ram, nếu < 500 tờ áp dụng giá lẻ dưới ramconst isWholesale = parentSheetsNeeded >= 500;const effectiveRamPrice = isWholesale ? priceAbove500 : priceBelow500;let paperCost = Math.round(parentSheetsNeeded * (effectiveRamPrice / 500));// 6. Tiền in ấnlet plateCost = 0;103 unmodified lines? digitalPricingKemGiay: DEFAULT_DIGITAL_KEM_GIAY;// Tìm dòng giá phù hợp theo mã giấylet matchedPricing = kemGiayList.find((kg) =>paperType.code.toUpperCase().includes(kg.paperCode.toUpperCase()));// Nếu không khớp chính xác mã, so khớp theo tiền tố chất liệu (C, I, F) + GSM gần nhấtif (!matchedPricing) {2 unmodified linesif (pName.includes('ivory') || paperType.code.toUpperCase().startsWith('I')) prefix = 'I';else if (pName.includes('fort') || pName.includes('ford') || paperType.code.toUpperCase().startsWith('F')) prefix = 'F';const sameType = kemGiayList.filter((kg) => kg.paperCode.startsWith(prefix));if (sameType.length > 0) {matchedPricing = sameType.reduce((prev, curr) =>Math.abs(curr.gsm - paperType.gsm) < Math.abs(prev.gsm - paperType.gsm) ? curr : prev);} else {21 unmodified linessheetSizeName,ratePerSheet,shortRunFee,note: `Bảng giá In Nhanh Kèm Giấy INTC (Đã gồm công in + giấy ${matchedPricing?.paperName || ''}). Phí SL ít: +${shortRunFee.toLocaleString('vi-VN')}đ`,};} else {// 2. In nhanh gia công (Konica C12000 / C12010S 5 màu - Trang 2 PDF)219 unmodified linesconst ups = Math.max(1, imposition.upsPerPrintSheet);const netSheets = Math.ceil(input.quantity / ups);const printWaste = isDigital ? 4 : (offsetMachine?.defaultWasteSheets ?? 100);const totalSheets = netSheets + printWaste + 10;const cuts = Math.max(1, imposition.cutsPerParentSheet);const parentSheets = Math.ceil(totalSheets / cuts);const pAbove = paperType.priceAbove500 || paperType.pricePerRam;const pBelow = paperType.priceBelow500 || pAbove;const effectiveRamPrice = parentSheets >= 500 ? pAbove : pBelow;let paperCost = Math.round(parentSheets * (effectiveRamPrice / 500));let printCost = 0;if (isDigital) {3 unmodified lineselse if (totalSheets < 100) shortFee = 20000;if (digitalMode === 'with_paper') {const matched = digitalPricingKemGiay.find((kg) =>paperType.code.toUpperCase().includes(kg.paperCode.toUpperCase())) || digitalPricingKemGiay[0];const rate = is2Sides ? matched.price2Side : matched.price1Side;printCost = Math.round(totalSheets * rate) + shortFee;paperCost = 0;215 unmodified lines2162172182192202212222232242252262272282292302312322332342352362372382392402412427 unmodified lines250251252253254255256257258103 unmodified lines3623633643653663673683693703713723733743753763773783793803813823832 unmodified lines38638738838939039139239339439539621 unmodified lines418419420421422423424219 unmodified lines6446456466476486496506516526536546556566576586596606616626633 unmodified lines667668669670671672673674675676677678679680681682683684215 unmodified lines}// Bù hao gia công theo %if (chosenTech === 'offset') {finishingWasteSheets += Math.ceil((netPrintSheets * totalFinishingWastePercent) / 100);} else {// In nhanh KTS: Không tính bù hao gia công vào tờ infinishingWasteSheets = 0;}// 4. Bù hao in ấn & Tổng số tờ inlet printWasteSheets = 0;if (chosenTech === 'offset') {printWasteSheets = offsetMachine?.defaultWasteSheets ?? 100;} else {// In nhanh KTS: KHÔNG BÙ HAO (in bao nhiêu tính tiền bấy nhiêu)printWasteSheets = 0;}const totalPrintSheets = netPrintSheets + printWasteSheets + finishingWasteSheets;const cuts = Math.max(1, imposition.cutsPerParentSheet);const parentSheetsNeeded = (chosenTech === 'digital' && digitalMode === 'with_paper')? totalPrintSheets: Math.ceil(totalPrintSheets / cuts);const ramsNeeded = Math.round((parentSheetsNeeded / 500) * 100) / 100;// Tính kg giấy = Số tờ lớn * Dài (m) * Rộng (m) * (gsm / 1000)7 unmodified lines// Nếu số tờ mẹ >= 500 (trên 1 ram) áp dụng giá sỉ nguyên ram, nếu < 500 tờ áp dụng giá lẻ dưới ramconst isWholesale = parentSheetsNeeded >= 500;const effectiveRamPrice = isWholesale ? priceAbove500 : priceBelow500;let paperCost = (chosenTech === 'digital' && digitalMode === 'with_paper')? 0: Math.round(parentSheetsNeeded * (effectiveRamPrice / 500));// 6. Tiền in ấnlet plateCost = 0;103 unmodified lines? digitalPricingKemGiay: DEFAULT_DIGITAL_KEM_GIAY;// Nhận diện khổ in: nếu tờ in là 325x355 thì tìm mã tương ứng (F180_355 hoặc F230_355)const isSheet355 = imposition.printSheet.widthMm <= 360 || imposition.printSheet.heightMm <= 360;let matchedPricing: DigitalPrintKemGiay | undefined;if (isSheet355) {matchedPricing = kemGiayList.find((kg) =>kg.sheetSize.includes('355') && paperType.code.toUpperCase().includes(kg.paperCode.replace('_355', '').toUpperCase()));}if (!matchedPricing) {matchedPricing = kemGiayList.find((kg) =>!kg.sheetSize.includes('355') && paperType.code.toUpperCase().includes(kg.paperCode.toUpperCase()));}// Nếu không khớp chính xác mã, so khớp theo tiền tố chất liệu (C, I, F) + GSM gần nhấtif (!matchedPricing) {2 unmodified linesif (pName.includes('ivory') || paperType.code.toUpperCase().startsWith('I')) prefix = 'I';else if (pName.includes('fort') || pName.includes('ford') || paperType.code.toUpperCase().startsWith('F')) prefix = 'F';const sameType = kemGiayList.filter((kg) => kg.paperCode.startsWith(prefix) && (isSheet355 ? kg.sheetSize.includes('355') : !kg.sheetSize.includes('355')));const pool = sameType.length > 0 ? sameType : kemGiayList.filter((kg) => kg.paperCode.startsWith(prefix));if (pool.length > 0) {matchedPricing = pool.reduce((prev, curr) =>Math.abs(curr.gsm - paperType.gsm) < Math.abs(prev.gsm - paperType.gsm) ? curr : prev);} else {21 unmodified linessheetSizeName,ratePerSheet,shortRunFee,note: `In Nhanh Kèm Giấy INTC (Đã gồm công in + giấy ${matchedPricing?.paperName || ''}). Không bù hao: ${totalPrintSheets} tờ in. Phí SL ít: +${shortRunFee.toLocaleString('vi-VN')}đ`,};} else {// 2. In nhanh gia công (Konica C12000 / C12010S 5 màu - Trang 2 PDF)219 unmodified linesconst ups = Math.max(1, imposition.upsPerPrintSheet);const netSheets = Math.ceil(input.quantity / ups);const printWaste = isDigital ? 0 : (offsetMachine?.defaultWasteSheets ?? 100);const finishingWaste = isDigital ? 0 : 10;const totalSheets = netSheets + printWaste + finishingWaste;const cuts = Math.max(1, imposition.cutsPerParentSheet);const parentSheets = (isDigital && digitalMode === 'with_paper')? totalSheets: Math.ceil(totalSheets / cuts);const pAbove = paperType.priceAbove500 || paperType.pricePerRam;const pBelow = paperType.priceBelow500 || pAbove;const effectiveRamPrice = parentSheets >= 500 ? pAbove : pBelow;let paperCost = (isDigital && digitalMode === 'with_paper')? 0: Math.round(parentSheets * (effectiveRamPrice / 500));let printCost = 0;if (isDigital) {3 unmodified lineselse if (totalSheets < 100) shortFee = 20000;if (digitalMode === 'with_paper') {const is355 = imposition.printSheet.heightMm <= 360;let matched = digitalPricingKemGiay.find((kg) => {if (is355 && (kg.paperCode === 'F180_355' || kg.paperCode === 'F230_355')) {return paperType.code.toUpperCase().includes(kg.paperCode.toUpperCase());}return kg.paperCode.toUpperCase() === paperType.code.toUpperCase();});if (!matched) {matched = digitalPricingKemGiay.find((kg) =>paperType.code.toUpperCase().includes(kg.paperCode.toUpperCase())) || digitalPricingKemGiay[0];}const rate = is2Sides ? matched.price2Side : matched.price1Side;printCost = Math.round(totalSheets * rate) + shortFee;paperCost = 0;
54 unmodified lines5556575859606162636465666768697071727374757677787980818283848552 unmodified lines13813914014114214314414 unmodified lines15916016116216316416516616716816917017117217317417517617717828 unmodified lines2072082092102112122132142152162172181 unmodified line2202212222232242252262276 unmodified lines2342352362372382394 unmodified lines24424524624724824914 unmodified lines26426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729814 unmodified lines31331431531631731831932032132232354 unmodified linesif (digitalMode === 'with_paper') {// BẢNG GIÁ IN NHANH KÈM GIẤY: Khổ 325 x 430 mm (chính) & 325 x 355 mm (Fort)digitalCandidates = [{ name: 'Khổ in kèm giấy (325 x 430 mm)', w: 430, h: 325, cuts: 4 },{ name: 'Khổ in kèm giấy đứng (325 x 430 mm)', w: 325, h: 430, cuts: 4 },{ name: 'Khổ in kèm giấy (325 x 355 mm)', w: 355, h: 325, cuts: 4 },];} else {// BẢNG GIÁ IN GIA CÔNG KONICA C12000 / C12010S: 5 khổ in máydigitalCandidates = [{ name: 'Khổ Konica A3+ (330 x 483 mm)', w: 483, h: 330, cuts: 4 },{ name: 'Khổ Konica A3 chuẩn (297 x 420 mm)', w: 420, h: 297, cuts: 4 },{ name: 'Khổ Konica 330 x 355 mm', w: 355, h: 330, cuts: 4 },{ name: 'Khổ Konica A4 chuẩn (210 x 297 mm)', w: 297, h: 210, cuts: 8 },{ name: 'Khổ Konica Banner (330 x 1200 mm)', w: 1200, h: 330, cuts: 1 },];}for (const dc of digitalCandidates) {const cuts = calculateCutsFromParent(parentW, parentH, dc.w, dc.h);const cutScheme = determineCutScheme(parentW, parentH, dc.w, dc.h, cuts);candidates.push({name: dc.name,sheetWidthMm: dc.w,sheetHeightMm: dc.h,cutsFromParent: cuts,cutScheme,gripperMarginMm: 4,});}} else {52 unmodified lines});}// 2. Đánh giá tất cả phương án để tìm phương án cho ra tổng số con trên tờ mẹ cao nhấtlet bestCandidateResult: {candidate: EvaluationCandidate;ups: number;14 unmodified linesitemH: heightMm,bleedMm,gripperMarginMm: cand.gripperMarginMm,});const totalUps = layout.ups * cand.cutsFromParent;if (!bestCandidateResult) {bestCandidateResult = { candidate: cand, ...layout };} else {const currentBestTotal = bestCandidateResult.ups * bestCandidateResult.candidate.cutsFromParent;if (totalUps > currentBestTotal) {bestCandidateResult = { candidate: cand, ...layout };} else if (totalUps === currentBestTotal) {// Nếu tổng số con bằng nhau, ưu tiên phương án tờ in nhỏ hơn (chia 4 hoặc chia 2) để tiết kiệm chi phí in máyif (cand.cutsFromParent > bestCandidateResult.candidate.cutsFromParent) {bestCandidateResult = { candidate: cand, ...layout };}}}28 unmodified lines}const { candidate, ups, cols, rows, isRotated, boxes, efficiency, usableW, usableH } = bestCandidateResult;return {parentSheet: {widthCm: paperType.parentWidthCm,heightCm: paperType.parentHeightCm,name: `${paperType.name} (${paperType.parentWidthCm}x${paperType.parentHeightCm}cm)`,},printSheet: {widthMm: candidate.sheetWidthMm,1 unmodified linename: candidate.name,},upsPerPrintSheet: ups,cutsPerParentSheet: candidate.cutsFromParent,totalUpsPerParentSheet: ups * candidate.cutsFromParent,gripperMarginMm: candidate.gripperMarginMm,usableWidthMm: usableW,usableHeightMm: usableH,6 unmodified lines};}// -----------------------------------------------------------------------------------------// THUẬT TOÁN XẾP BÌNH BÀI CHUẨN XÉNG CÔNG NGHIỆP TRÊN TỜ IN MÁY// -----------------------------------------------------------------------------------------4 unmodified linesitemH: number;bleedMm: number;gripperMarginMm: number;}interface LayoutResult {14 unmodified linesitemH,bleedMm,gripperMarginMm,}: LayoutEvalParams): LayoutResult {// Quy ước máy in:// Cạnh dài là cạnh bắt nhíp: width = max(sheetW, sheetH), height = min(sheetW, sheetH)const W = Math.max(sheetW, sheetH);const H = Math.min(sheetW, sheetH);// Lề kẹp nhíp ở cạnh đáy (gripperMarginMm = 10mm)// Lề đuôi (đối diện nhíp): 4mm// Lề 2 bên biên: 4mm mỗi bên (tổng 8mm)const marginSide = 4;const marginTail = 4;const usableW = W - marginSide * 2;const usableH = H - (gripperMarginMm + marginTail);if (usableW < itemW && usableW < itemH) {return { ups: 0, cols: 0, rows: 0, isRotated: false, boxes: [], efficiency: 0, usableW, usableH };}// --- Cách 1: Xếp Thẳng (Không xoay) ---// Chiều ngang chứa C1 cột thành phẩm, có tràn lề 2mm ở 2 mép ngoài cùng// Công thức: C1 * itemW + 2 * bleedMm <= usableWconst cols1 = Math.max(0, Math.floor((usableW - 2 * bleedMm) / itemW));const rows1 = Math.max(0, Math.floor((usableH - 2 * bleedMm) / itemH));const ups1 = cols1 * rows1;// --- Cách 2: Xếp Xoay 90 độ ---// Chiều ngang xếp theo itemH, chiều dọc xếp theo itemWconst cols2 = Math.max(0, Math.floor((usableW - 2 * bleedMm) / itemH));const rows2 = Math.max(0, Math.floor((usableH - 2 * bleedMm) / itemW));const ups2 = cols2 * rows2;// Chọn phương án tốt nhất giữa Xếp Thẳng (ups1) và Xếp Xoay 90° (ups2)14 unmodified linesconst boxW = isRotated ? itemH : itemW;const boxH = isRotated ? itemW : itemH;// Canh giữa cụm con trong vùng in hữu dụngconst blockW = bestCols * boxW + 2 * bleedMm;const blockH = bestRows * boxH + 2 * bleedMm;const startX = marginSide + Math.max(0, Math.floor((usableW - blockW) / 2)) + bleedMm;const startY = marginTail + Math.max(0, Math.floor((usableH - blockH) / 2)) + bleedMm;let idx = 1;for (let r = 0; r < bestRows; r++) {54 unmodified lines55565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610752 unmodified lines16016116216316416516614 unmodified lines18118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523628 unmodified lines2652662672682692702712722732742752762772782791 unmodified line2812822832842852862872886 unmodified lines2952962972982993003013023033043053063073083094 unmodified lines31431531631731831932014 unmodified lines33533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939014 unmodified lines40540640740840941041141241341441541641741841954 unmodified linesif (digitalMode === 'with_paper') {// BẢNG GIÁ IN NHANH KÈM GIẤY: Khổ 325 x 430 mm (chính) & 325 x 355 mm (Fort)digitalCandidates = [{ name: 'Khổ in kèm giấy (325 x 430 mm)', w: 430, h: 325, cuts: 1 },{ name: 'Khổ in kèm giấy (325 x 355 mm)', w: 355, h: 325, cuts: 1 },];} else {// BẢNG GIÁ IN GIA CÔNG KONICA C12000 / C12010S: 5 khổ in máydigitalCandidates = [{ name: 'Khổ Konica A4 chuẩn (210 x 297 mm)', w: 297, h: 210, cuts: 1 },{ name: 'Khổ Konica 330 x 355 mm', w: 355, h: 330, cuts: 1 },{ name: 'Khổ Konica A3 chuẩn (297 x 420 mm)', w: 420, h: 297, cuts: 1 },{ name: 'Khổ Konica A3+ (330 x 483 mm)', w: 483, h: 330, cuts: 1 },{ name: 'Khổ Konica Banner (330 x 1200 mm)', w: 1200, h: 330, cuts: 1 },];}for (const dc of digitalCandidates) {const isWithPaper = digitalMode === 'with_paper';const cutScheme: PaperCutScheme = isWithPaper? {parentWidthMm: dc.w,parentHeightMm: dc.h,cutType: 'chia_1',cutDescription: 'Phôi giấy cắt sẵn khổ chuẩn của xưởng INTC (đã gồm trong đơn giá in, không cần xả từ khổ mẹ)',cutsCount: 1,cutSheetWidthMm: dc.w,cutSheetHeightMm: dc.h,wasteAreaPercent: 0,cutLines: [],blocks: [{index: 1,x: 0,y: 0,w: dc.w,h: dc.h,name: `Phôi in trọn gói (${dc.w} × ${dc.h} mm)`,},],}: determineCutScheme(parentW, parentH, dc.w, dc.h, calculateCutsFromParent(parentW, parentH, dc.w, dc.h));candidates.push({name: dc.name,sheetWidthMm: dc.w,sheetHeightMm: dc.h,cutsFromParent: isWithPaper ? 1 : calculateCutsFromParent(parentW, parentH, dc.w, dc.h),cutScheme,gripperMarginMm: 2.5,});}} else {52 unmodified lines});}// 2. Đánh giá tất cả phương án để tìm phương án tối ưu nhấtlet bestCandidateResult: {candidate: EvaluationCandidate;ups: number;14 unmodified linesitemH: heightMm,bleedMm,gripperMarginMm: cand.gripperMarginMm,isDigital: printTech === 'digital',});if (printTech === 'digital') {if (digitalMode === 'with_paper') {// In nhanh kèm giấy: Chọn khổ phôi có số con (ups) trên tờ in lớn nhất// Nếu số con bằng nhau, ưu tiên 325x430 mm (hoặc 325x355 mm nếu là Fort F180/F230 vì rẻ hơn)if (!bestCandidateResult) {bestCandidateResult = { candidate: cand, ...layout };} else {if (layout.ups > bestCandidateResult.ups) {bestCandidateResult = { candidate: cand, ...layout };} else if (layout.ups === bestCandidateResult.ups && layout.ups > 0) {const isFortSpecial = paperType.code.toUpperCase().includes('F180') || paperType.code.toUpperCase().includes('F230');const isCand355 = cand.name.includes('355');if (isFortSpecial && isCand355) {bestCandidateResult = { candidate: cand, ...layout };}}}} else {// In gia công Konica C12000:// Chọn khổ máy in có layout.ups > 0 và chi phí ước tính trên mỗi con thành phẩm là thấp nhất// (Tránh trường hợp in tờ rơi A4 mà lại chọn nhầm khổ banner 1.2 mét)const approxClick = getApproxKonicaClick(cand.sheetWidthMm, cand.sheetHeightMm);const costPerPiece = layout.ups > 0 ? approxClick / layout.ups : Infinity;if (!bestCandidateResult) {bestCandidateResult = { candidate: cand, ...layout };} else {const prevClick = getApproxKonicaClick(bestCandidateResult.candidate.sheetWidthMm, bestCandidateResult.candidate.sheetHeightMm);const prevCostPerPiece = bestCandidateResult.ups > 0 ? prevClick / bestCandidateResult.ups : Infinity;if (layout.ups > 0 && costPerPiece < prevCostPerPiece) {bestCandidateResult = { candidate: cand, ...layout };}}}} else {// In Offset: Ưu tiên tổng số con sinh ra từ 1 tờ giấy mẹconst totalUps = layout.ups * cand.cutsFromParent;if (!bestCandidateResult) {bestCandidateResult = { candidate: cand, ...layout };} else {const currentBestTotal = bestCandidateResult.ups * bestCandidateResult.candidate.cutsFromParent;if (totalUps > currentBestTotal) {bestCandidateResult = { candidate: cand, ...layout };} else if (totalUps === currentBestTotal) {if (cand.cutsFromParent > bestCandidateResult.candidate.cutsFromParent) {bestCandidateResult = { candidate: cand, ...layout };}}}}28 unmodified lines}const { candidate, ups, cols, rows, isRotated, boxes, efficiency, usableW, usableH } = bestCandidateResult;const isWithPaper = printTech === 'digital' && digitalMode === 'with_paper';return {parentSheet: {widthCm: isWithPaper ? candidate.sheetWidthMm / 10 : paperType.parentWidthCm,heightCm: isWithPaper ? candidate.sheetHeightMm / 10 : paperType.parentHeightCm,name: isWithPaper? `Phôi giấy INTC (${candidate.sheetWidthMm / 10}x${candidate.sheetHeightMm / 10}cm)`: `${paperType.name} (${paperType.parentWidthCm}x${paperType.parentHeightCm}cm)`,},printSheet: {widthMm: candidate.sheetWidthMm,1 unmodified linename: candidate.name,},upsPerPrintSheet: ups,cutsPerParentSheet: isWithPaper ? 1 : candidate.cutsFromParent,totalUpsPerParentSheet: isWithPaper ? ups : ups * candidate.cutsFromParent,gripperMarginMm: candidate.gripperMarginMm,usableWidthMm: usableW,usableHeightMm: usableH,6 unmodified lines};}function getApproxKonicaClick(w: number, h: number): number {const maxDim = Math.max(w, h);if (maxDim <= 300) return 800; // A4if (maxDim <= 360) return 1000; // 330x355if (maxDim <= 425) return 1600; // A3if (maxDim <= 500) return 2500; // 330x483 (A3+)return 7000; // 330x1200 Banner}// -----------------------------------------------------------------------------------------// THUẬT TOÁN XẾP BÌNH BÀI CHUẨN XÉNG CÔNG NGHIỆP TRÊN TỜ IN MÁY// -----------------------------------------------------------------------------------------4 unmodified linesitemH: number;bleedMm: number;gripperMarginMm: number;isDigital?: boolean;}interface LayoutResult {14 unmodified linesitemH,bleedMm,gripperMarginMm,isDigital = false,}: LayoutEvalParams): LayoutResult {// Quy ước máy in:// Cạnh dài: width = max(sheetW, sheetH), Cạnh ngắn: height = min(sheetW, sheetH)const W = Math.max(sheetW, sheetH);const H = Math.min(sheetW, sheetH);let marginSide = 4;let marginTail = 4;let marginGripper = gripperMarginMm;if (isDigital) {// Máy in kỹ thuật số: Không có càng kẹp nhíp cơ học 10mm như offset.// Lề trắng máy in (non-printable margin) chỉ 2.5mm xung quanh 4 mép.marginSide = 2.5;marginTail = 2.5;marginGripper = 2.5;}const usableW = W - marginSide * 2;const usableH = H - (marginGripper + marginTail);if (usableW < itemW && usableW < itemH) {return { ups: 0, cols: 0, rows: 0, isRotated: false, boxes: [], efficiency: 0, usableW, usableH };}// --- Cách 1: Xếp Thẳng (Không xoay) ---let cols1 = 0;let rows1 = 0;if (isDigital) {// In nhanh: Các con xếp sát nhau (cắt 1 nhát chung dao). Tràn lề ăn vào biên giấy ngoài cùng.cols1 = Math.max(0, Math.floor(usableW / itemW));rows1 = Math.max(0, Math.floor(usableH / itemH));} else {// In offset: Chừa lề kẹp nhíp và đường tràn lềcols1 = Math.max(0, Math.floor((usableW - 2 * bleedMm) / itemW));rows1 = Math.max(0, Math.floor((usableH - 2 * bleedMm) / itemH));}const ups1 = cols1 * rows1;// --- Cách 2: Xếp Xoay 90 độ ---let cols2 = 0;let rows2 = 0;if (isDigital) {cols2 = Math.max(0, Math.floor(usableW / itemH));rows2 = Math.max(0, Math.floor(usableH / itemW));} else {cols2 = Math.max(0, Math.floor((usableW - 2 * bleedMm) / itemH));rows2 = Math.max(0, Math.floor((usableH - 2 * bleedMm) / itemW));}const ups2 = cols2 * rows2;// Chọn phương án tốt nhất giữa Xếp Thẳng (ups1) và Xếp Xoay 90° (ups2)14 unmodified linesconst boxW = isRotated ? itemH : itemW;const boxH = isRotated ? itemW : itemH;// Canh giữa cụm con trong tờ inconst blockW = bestCols * boxW;const blockH = bestRows * boxH;const startX = isDigital? Math.max(0, Math.round(((W - blockW) / 2) * 10) / 10): marginSide + Math.max(0, Math.floor((usableW - (blockW + 2 * bleedMm)) / 2)) + bleedMm;const startY = isDigital? Math.max(0, Math.round(((H - blockH) / 2) * 10) / 10): marginTail + Math.max(0, Math.floor((usableH - (blockH + 2 * bleedMm)) / 2)) + bleedMm;let idx = 1;for (let r = 0; r < bestRows; r++) {
src/app/page.tsx+152-42
src/components/CostBreakdownCard.tsx+10-3
src/lib/engine/costCalculator.ts+57-19
src/lib/engine/imposition.ts+141-45