diff --git a/src/main/java/com/ffii/fpsms/modules/deliveryOrder/service/DeliveryOrderService.kt b/src/main/java/com/ffii/fpsms/modules/deliveryOrder/service/DeliveryOrderService.kt index e506b4f..51da506 100644 --- a/src/main/java/com/ffii/fpsms/modules/deliveryOrder/service/DeliveryOrderService.kt +++ b/src/main/java/com/ffii/fpsms/modules/deliveryOrder/service/DeliveryOrderService.kt @@ -963,52 +963,58 @@ open class DeliveryOrderService( } - //Carton Labels - open fun exportDNLabels(request: ExportDNLabelsRequest): Map { - val DNLABELS_PDF = "DeliveryNote/DeliveryNoteCartonLabelsPDF.jrxml" - val resource = ClassPathResource(DNLABELS_PDF) - if (!resource.exists()) { - throw FileNotFoundException("Label file not found: $DNLABELS_PDF") - } + //Carton Labels + open fun exportDNLabels(request: ExportDNLabelsRequest): Map { + val DNLABELS_PDF = "DeliveryNote/DeliveryNoteCartonLabelsPDF.jrxml" + val resource = ClassPathResource(DNLABELS_PDF) + if (!resource.exists()) { + throw FileNotFoundException("Label file not found: $DNLABELS_PDF") + } - val doPickOrder = doPickOrderRepository.findById(request.doPickOrderId).orElseThrow { - NoSuchElementException("DoPickOrder not found with ID: ${request.doPickOrderId}") - } + val doPickOrderRecord = doPickOrderRecordRepository.findById(request.doPickOrderId).orElseThrow { + NoSuchElementException("DoPickOrderRecord not found with ID: ${request.doPickOrderId}") + } + val doPickOrderLineRecords = doPickOrderLineRecordRepository.findByDoPickOrderIdAndDeletedFalse(request.doPickOrderId) - val deliveryOrderId = doPickOrder.doOrderId - ?: throw IllegalStateException("DoPickOrder has no associated delivery order") + val deliveryOrderIds = doPickOrderLineRecords.mapNotNull { it.doOrderId }.distinct() + if(deliveryOrderIds.isEmpty()){ + throw IllegalStateException("DoPickOrderRecord ${request.doPickOrderId} has no associated delivery orders") + } + + val inputStream = resource.inputStream + val cartonLabel = JasperCompileManager.compileReport(inputStream) + val cartonLabelInfo = deliveryOrderIds.flatMap { deliveryOrderId -> + deliveryOrderRepository.findDeliveryOrderInfoById(deliveryOrderId) + }.toMutableList() - val inputStream = resource.inputStream - val cartonLabel = JasperCompileManager.compileReport(inputStream) - val cartonLabelInfo = - deliveryOrderRepository.findDeliveryOrderInfoById(request.doPickOrderId).toMutableList() + val params = mutableMapOf() + val fields = mutableListOf>() - val params = mutableMapOf() - val fields = mutableListOf>() + for (info in cartonLabelInfo) { + val field = mutableMapOf() + } - for (info in cartonLabelInfo) { - val field = mutableMapOf() - } - if(cartonLabelInfo.size > 1){ + if(cartonLabelInfo.size > 1){ - } - params["shopPurchaseOrderNo"] = doPickOrder.deliveryOrderCode ?: cartonLabelInfo[0].code - params["deliveryNoteCode"] = "GEN FROM CODE GENERATOR (NEED FIND TIMING)" - params["shopAddress"] = cartonLabelInfo[0].shopAddress ?: "" - params["shopName"] = doPickOrder.shopName ?: cartonLabelInfo[0].shopName ?: "" - - for (cartonNumber in 1..request.numOfCarton) { - val field = mutableMapOf() - fields.add(field) - } + } - return mapOf( - "report" to PdfUtils.fillReport(cartonLabel, fields, params), - "filename" to "${cartonLabelInfo[0].code}_carton_labels" - ) + params["shopPurchaseOrderNo"] = doPickOrderRecord.deliveryOrderCode ?: cartonLabelInfo[0].code + params["deliveryNoteCode"] = doPickOrderRecord.deliveryNoteCode ?: "" + params["shopAddress"] = cartonLabelInfo[0].shopAddress ?: "" + params["shopName"] = doPickOrderRecord.shopName ?: cartonLabelInfo[0].shopName ?: "" + params["truckNo"] = doPickOrderRecord.truckLanceCode ?: "" + for (cartonNumber in 1..request.numOfCarton) { + val field = mutableMapOf() + fields.add(field) } + return mapOf( + "report" to PdfUtils.fillReport(cartonLabel, fields, params), + "filename" to "${cartonLabelInfo[0].code}_carton_labels" + ) + } + //Print Carton Labels @Transactional diff --git a/src/main/java/com/ffii/fpsms/modules/jobOrder/service/JobOrderService.kt b/src/main/java/com/ffii/fpsms/modules/jobOrder/service/JobOrderService.kt index 31d54ab..89daab1 100644 --- a/src/main/java/com/ffii/fpsms/modules/jobOrder/service/JobOrderService.kt +++ b/src/main/java/com/ffii/fpsms/modules/jobOrder/service/JobOrderService.kt @@ -4,6 +4,8 @@ import com.ffii.core.exception.BadRequestException import com.ffii.core.response.RecordsRes import com.ffii.core.utils.GsonUtils import com.ffii.core.utils.PdfUtils +import com.ffii.core.utils.QrCodeUtil +import com.ffii.core.utils.ZebraPrinterUtil import com.ffii.fpsms.modules.common.SecurityUtils import com.ffii.fpsms.modules.jobOrder.entity.JobOrder import com.ffii.fpsms.modules.jobOrder.entity.JobOrderRepository @@ -402,12 +404,12 @@ open class JobOrderService( val unit = pickRecordInfo.firstOrNull()?.get("unit") as? String println("Debug - UOM Info:") - println(" bomItemId: $bomItemId") - println(" bomItemUomId: $bomItemUomIdRaw") - println(" uomCode: $uomCode") - println(" uomDesc: $uomDesc") - println(" uomShortDesc: $uomShortDesc") - println(" unit (from BOM): $unit")*/ + println("bomItemId: $bomItemId") + println("bomItemUomId: $bomItemUomIdRaw") + println("uomCode: $uomCode") + println("uomDesc: $uomDesc") + println("uomShortDesc: $uomShortDesc") + println("unit (from BOM): $unit")*/ params["unit"] = pickRecordInfo.firstOrNull()?.get("uomConversionDesc") as? String ?: "N/A" @@ -436,7 +438,86 @@ open class JobOrderService( JasperExportManager.exportReportToPdfFile(jasperPrint,tempPdfFile.absolutePath) } finally { - //tempPdfFile.delete*9 + //tempPdfFile.delete } } + + //FG Pick Record Label + @Throws(IOException::class) + @Transactional + // Hardcoded Request + open fun exportFGPickRecordLabel(request: ExportPickRecordRequest): Map { + val FG_PICKRECORD_LABEL_PDF = "PickRecord/FinishedGoodPickRecordLabelPDF.jrxml" + val resource = ClassPathResource(FG_PICKRECORD_LABEL_PDF) + if(!resource.exists()){ + throw FileNotFoundException("Report file not found: $FG_PICKRECORD_LABEL_PDF") + } + val inputStream = resource.inputStream + val fgPickRecordLabel = JasperCompileManager.compileReport(inputStream) + + val params = mutableMapOf() + + // Hardcoded for demo on 6/11/2025 + params["jobOrderCode"] = "JO-20251106-0001" + params["finishedGoodItemCode"] = "PP2061" + params["finishedGoodItemName"] = "炒芝麻" + params["finishedGoodLotNo"] = "LT-20251106-0006A" + params["productionQty"] = "25.0" + params["productionDate"] = "2025-11-06" + params["expiryDate"] = "2026-02-06" + params["uom"] = "一包一磅" + params["shortName"] = "包" + + // Hardcoded QR code for demo on 6/11/2025 + val qrCodeContent = "JO-20241201-001|FG-001|LOT-20241201-001" + val qrCodeImage = QrCodeUtil.generateQRCodeImage(qrCodeContent) + params["qrCode"] = qrCodeImage + + val fields = mutableListOf>() + + val filename = params["jobOrderCode"] as String + return mapOf( + "report" to PdfUtils.fillReport(fgPickRecordLabel, fields, params), + "filename" to filename + ) + } + + + @Transactional + open fun printFGPickRecordLabel(request: PrintPickRecordRequest){ + val printer = printerService.findById(request.printerId) ?: throw java.util.NoSuchElementException("No such printer") + + val pdf = exportFGPickRecordLabel( + ExportPickRecordRequest( + pickOrderIds = request.pickOrderId + ) + ) + + val jasperPrint = pdf["report"] as JasperPrint + + val tempPdfFile = File.createTempFile("print_job_",".pdf") + + try{ + JasperExportManager.exportReportToPdfFile(jasperPrint,tempPdfFile.absolutePath) + val printQty = if (request.printQty == null || request.printQty <= 0) 1 else request.printQty + printer.ip?.let { ip -> + printer.port?.let { port -> + ZebraPrinterUtil.printPdfToZebra( + tempPdfFile, + ip, + port, + printQty, + ZebraPrinterUtil.PrintDirection.ROTATED + ) + } + } + + println("Test PDF saved to: ${tempPdfFile.absolutePath}") + + } finally { + //tempPdfFile.delete + } + } + + } \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/jobOrder/web/JobOrderController.kt b/src/main/java/com/ffii/fpsms/modules/jobOrder/web/JobOrderController.kt index 189cf8e..9536c92 100644 --- a/src/main/java/com/ffii/fpsms/modules/jobOrder/web/JobOrderController.kt +++ b/src/main/java/com/ffii/fpsms/modules/jobOrder/web/JobOrderController.kt @@ -190,6 +190,24 @@ fun recordSecondScanIssue( jobOrderService.printPickRecord(request) } + @PostMapping("/FGPickRecordLabel") + @Throws(UnsupportedEncodingException::class, NoSuchMessageException::class, ParseException::class, Exception::class) + fun exportFGPickRecordLabel(@Valid @RequestBody request: ExportPickRecordRequest, response: HttpServletResponse){ + response.characterEncoding = "utf-8" + response.contentType = "application/pdf" + val out: OutputStream = response.outputStream + val pdf = jobOrderService.exportFGPickRecordLabel(request) + val jasperPrint = pdf["report"] as JasperPrint + response.addHeader("filename", "${pdf["filename"]}.pdf") + out.write(JasperExportManager.exportReportToPdf(jasperPrint)) + } + + @GetMapping("/print-FGPickRecordLabel") + fun printFGPickRecordLabel(@ModelAttribute request: PrintPickRecordRequest){ + jobOrderService.printFGPickRecordLabel(request) + } + + @GetMapping("/completed-job-order-pick-orders-only/{userId}") fun getCompletedJobOrderPickOrders(@PathVariable userId: Long): List> { return joPickOrderService.getCompletedJobOrderPickOrders(userId) diff --git a/src/main/resources/DeliveryNote/DeliveryNoteCartonLabelsPDF.jrxml b/src/main/resources/DeliveryNote/DeliveryNoteCartonLabelsPDF.jrxml index 392fe29..bd6161c 100644 --- a/src/main/resources/DeliveryNote/DeliveryNoteCartonLabelsPDF.jrxml +++ b/src/main/resources/DeliveryNote/DeliveryNoteCartonLabelsPDF.jrxml @@ -1,159 +1,166 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/DeliveryNote/DeliveryNotePDF.jrxml b/src/main/resources/DeliveryNote/DeliveryNotePDF.jrxml index 42288ce..fb33a40 100644 --- a/src/main/resources/DeliveryNote/DeliveryNotePDF.jrxml +++ b/src/main/resources/DeliveryNote/DeliveryNotePDF.jrxml @@ -1,5 +1,5 @@ - + diff --git a/src/main/resources/PickRecord/FinishedGoodPickRecordLabelPDF.jrxml b/src/main/resources/PickRecord/FinishedGoodPickRecordLabelPDF.jrxml new file mode 100644 index 0000000..2566591 --- /dev/null +++ b/src/main/resources/PickRecord/FinishedGoodPickRecordLabelPDF.jrxml @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/PickRecord/PickRecordPDF.jrxml b/src/main/resources/PickRecord/PickRecordPDF.jrxml new file mode 100644 index 0000000..d0fb600 --- /dev/null +++ b/src/main/resources/PickRecord/PickRecordPDF.jrxml @@ -0,0 +1,332 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + <band splitType="Stretch"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +