From cfc9aa7d95450e50bbcc131933331a0a9a2a272c Mon Sep 17 00:00:00 2001 From: "MSI\\2Fi" Date: Thu, 25 Apr 2024 18:12:51 +0800 Subject: [PATCH] Add Download Invoice --- .../entity/projections/InvoicePDFReq.kt | 10 +- .../modules/project/service/InvoiceService.kt | 40 ++++---- .../modules/project/web/InvoiceController.kt | 3 +- src/main/resources/pdf/invoicePDF.jrxml | 92 +++++++++++++------ 4 files changed, 93 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/ffii/tsms/modules/project/entity/projections/InvoicePDFReq.kt b/src/main/java/com/ffii/tsms/modules/project/entity/projections/InvoicePDFReq.kt index 25ea368..f76e2b6 100644 --- a/src/main/java/com/ffii/tsms/modules/project/entity/projections/InvoicePDFReq.kt +++ b/src/main/java/com/ffii/tsms/modules/project/entity/projections/InvoicePDFReq.kt @@ -1,6 +1,8 @@ package com.ffii.tsms.modules.project.entity.projections -class InvoicePDFReq { - val amount: Int = 0 - val client: String = "" -} \ No newline at end of file +data class InvoicePDFReq( + val id: Long, + val amount: Int, + val invoiceDate: String, + val dueDate: String +) diff --git a/src/main/java/com/ffii/tsms/modules/project/service/InvoiceService.kt b/src/main/java/com/ffii/tsms/modules/project/service/InvoiceService.kt index d5fa798..1d3700a 100644 --- a/src/main/java/com/ffii/tsms/modules/project/service/InvoiceService.kt +++ b/src/main/java/com/ffii/tsms/modules/project/service/InvoiceService.kt @@ -28,12 +28,14 @@ open class InvoiceService( val sql = StringBuilder(" select " + " mp.id, " + " mp.date as paymentMilestoneDate, mp.amount, mp.description as comingPaymentMileStone, " - + " m.startDate, m.endDate, m.name, m.description as milestoneDescription, " + + " m.startDate, m.endDate, m.name, m.description as milestoneDescription, tg.name as stage, " + " p.code as projectCode, p.name as projectName " + " from milestone_payment mp " + " left join milestone m on m.id = mp.milestoneId " + " left join project p on p.id = m.projectId " + + " left join task_group tg on tg.id = m.taskGroupId " + " where p.deleted = false " + + " order by mp.date ASC" ) return jdbcDao.queryForList(sql.toString()) } @@ -42,11 +44,12 @@ open class InvoiceService( val sql = StringBuilder(" select " + " mp.id, " + " mp.date as paymentMilestoneDate, mp.amount, mp.description as comingPaymentMileStone, " - + " m.startDate, m.endDate, m.name, m.description as milestoneDescription, " + + " m.startDate, m.endDate, m.name, m.description as milestoneDescription, tg.name as stage, " + " p.code as projectCode, p.name as projectName " + " from milestone_payment mp " + " left join milestone m on m.id = mp.milestoneId " + " left join project p on p.id = m.projectId " + + " left join task_group tg on tg.id = m.taskGroupId " + " where p.deleted = false " + " and mp.id = :id " ) @@ -84,29 +87,30 @@ open class InvoiceService( val invoicePDF: JasperReport = JasperCompileManager.compileReport(inputStream) + val projectDetailList = getProjectDetailsByMilestonePaymentId(req.id) + val projectDetail = projectDetailList.get(0) + val fields: MutableList> = ArrayList() val fieldValue1: Map = mapOf( - "unitPrice" to BigDecimal(1), - "qty" to BigDecimal(2), - "paymentMilestone" to "1 - Completion of stage 1: Design and Cost Planning", - ) - val fieldValue2: Map = mapOf( - "unitPrice" to BigDecimal(200), - "qty" to BigDecimal(3), - "paymentMilestone" to "1 - Completion of stage 1: Design and Cost Planning", + "unitPrice" to BigDecimal(req.amount), + "qty" to BigDecimal(1), + "paymentMilestone" to projectDetail.getValue("comingPaymentMileStone"), ) + fields.add(fieldValue1) - fields.add(fieldValue2) - val currentDate: LocalDate = LocalDate.now() + + val invoiceInfoList = getInvoiceInfoByMilestonePaymentId(req.id) + val invoiceInfo = invoiceInfoList.get(0) val params: MutableMap = HashMap() - params["Client"] = "CLIENT WONG" - params["Address"] = "Shop No. 17, B1/F, Airside, 2 Concorde Road, Kai Tak, Kowloon" - params["Attention"] = "002 Lee" - params["invoiceNo"] = "INV-20240424" + params["Client"] = invoiceInfo.getValue("client") + params["Address"] = invoiceInfo.getValue("address") + params["Attention"] = invoiceInfo.getValue("attention") + params["invoiceNo"] = req.invoiceDate.toString() + req.id params["projectRefNo"] = "XXX" - params["curDate"] = currentDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) - params["dueDate"] = "2024-05-01" + params["curDate"] = req.invoiceDate.toString() + params["dueDate"] = req.dueDate.toString() + params["stage"] = projectDetail.getValue("stage") return mapOf( "report" to PdfUtils.fillReport(invoicePDF, fields, params), diff --git a/src/main/java/com/ffii/tsms/modules/project/web/InvoiceController.kt b/src/main/java/com/ffii/tsms/modules/project/web/InvoiceController.kt index 9e7e911..6225c29 100644 --- a/src/main/java/com/ffii/tsms/modules/project/web/InvoiceController.kt +++ b/src/main/java/com/ffii/tsms/modules/project/web/InvoiceController.kt @@ -11,6 +11,7 @@ import net.sf.jasperreports.engine.JasperPrint import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController @@ -40,7 +41,7 @@ class InvoiceController( } @PostMapping("/pdf") - fun generatePDF(req: InvoicePDFReq, response: HttpServletResponse) { + fun generatePDF(@RequestBody req: InvoicePDFReq, response: HttpServletResponse) { response.characterEncoding = "utf-8" response.contentType = "application/pdf" diff --git a/src/main/resources/pdf/invoicePDF.jrxml b/src/main/resources/pdf/invoicePDF.jrxml index 2eb703e..c576184 100644 --- a/src/main/resources/pdf/invoicePDF.jrxml +++ b/src/main/resources/pdf/invoicePDF.jrxml @@ -18,6 +18,7 @@ + @@ -38,12 +39,17 @@ - + + + - + + + + @@ -77,15 +83,18 @@ - + + + - + + @@ -95,7 +104,7 @@ - + @@ -121,7 +130,7 @@ Beria Consultants Limited]]> - + @@ -132,11 +141,11 @@ Beria Consultants Limited]]> - + - + @@ -146,7 +155,7 @@ Beria Consultants Limited]]> - + @@ -189,33 +198,39 @@ Beria Consultants Limited]]> - + + + - + + - + + - + + + @@ -231,7 +246,8 @@ Beria Consultants Limited]]> - + + @@ -241,7 +257,7 @@ Beria Consultants Limited]]> ]]> - + @@ -262,18 +278,21 @@ Beria Consultants Limited]]> - + + - + + - + + @@ -287,6 +306,15 @@ Beria Consultants Limited]]> + + + + + + + + + @@ -305,51 +333,57 @@ Beria Consultants Limited]]> - + - + + + + - + - - + + + - + - + - + - - + + + - + +