Browse Source

Add Download Invoice

tags/Baseline_30082024_BACKEND_UAT
MSI\2Fi 1 year ago
parent
commit
cfc9aa7d95
4 changed files with 93 additions and 52 deletions
  1. +6
    -4
      src/main/java/com/ffii/tsms/modules/project/entity/projections/InvoicePDFReq.kt
  2. +22
    -18
      src/main/java/com/ffii/tsms/modules/project/service/InvoiceService.kt
  3. +2
    -1
      src/main/java/com/ffii/tsms/modules/project/web/InvoiceController.kt
  4. +63
    -29
      src/main/resources/pdf/invoicePDF.jrxml

+ 6
- 4
src/main/java/com/ffii/tsms/modules/project/entity/projections/InvoicePDFReq.kt View File

@@ -1,6 +1,8 @@
package com.ffii.tsms.modules.project.entity.projections

class InvoicePDFReq {
val amount: Int = 0
val client: String = ""
}
data class InvoicePDFReq(
val id: Long,
val amount: Int,
val invoiceDate: String,
val dueDate: String
)

+ 22
- 18
src/main/java/com/ffii/tsms/modules/project/service/InvoiceService.kt View File

@@ -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<Map<String, Any>> = ArrayList()
val fieldValue1: Map<String, Any> = mapOf(
"unitPrice" to BigDecimal(1),
"qty" to BigDecimal(2),
"paymentMilestone" to "1 - Completion of stage 1: Design and Cost Planning",
)
val fieldValue2: Map<String, Any> = 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<String, Any> = 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),


+ 2
- 1
src/main/java/com/ffii/tsms/modules/project/web/InvoiceController.kt View File

@@ -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"



+ 63
- 29
src/main/resources/pdf/invoicePDF.jrxml View File

@@ -18,6 +18,7 @@
<parameter name="projectRefNo" class="java.lang.String"/>
<parameter name="curDate" class="java.lang.String"/>
<parameter name="dueDate" class="java.lang.String"/>
<parameter name="stage" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
@@ -38,12 +39,17 @@
<textFieldExpression><![CDATA[$P{Client}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="280" y="0" width="100" height="20" uuid="556e2b38-0b69-4a2c-8d56-1a28a5215fb3"/>
<reportElement x="300" y="0" width="100" height="20" uuid="556e2b38-0b69-4a2c-8d56-1a28a5215fb3">
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<box topPadding="0" bottomPadding="0"/>
<text><![CDATA[Invoice No:]]></text>
</staticText>
<textField>
<reportElement x="380" y="0" width="164" height="20" uuid="839b2264-6b33-46e7-b26a-e01bd9d79066"/>
<reportElement x="400" y="0" width="140" height="20" uuid="839b2264-6b33-46e7-b26a-e01bd9d79066">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<box topPadding="0" bottomPadding="0"/>
<textFieldExpression><![CDATA[$P{invoiceNo}]]></textFieldExpression>
</textField>
@@ -77,15 +83,18 @@
<text><![CDATA[Address:]]></text>
</staticText>
<textField>
<reportElement x="380" y="0" width="164" height="20" uuid="b153149a-579b-4619-aa91-327f09dc1606">
<reportElement x="400" y="0" width="140" height="20" uuid="b153149a-579b-4619-aa91-327f09dc1606">
<property name="com.jaspersoft.studio.unit.y" value="px"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<box topPadding="0" bottomPadding="0"/>
<textFieldExpression><![CDATA[$P{projectRefNo}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="280" y="0" width="100" height="20" uuid="a091861e-e24a-4b93-949a-4e1a9d68a870">
<reportElement x="300" y="0" width="100" height="20" uuid="a091861e-e24a-4b93-949a-4e1a9d68a870">
<property name="com.jaspersoft.studio.unit.y" value="px"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<box topPadding="0" bottomPadding="0"/>
<text><![CDATA[Project Ref. No:]]></text>
@@ -95,7 +104,7 @@
</group>
<group name="Signature">
<groupFooter>
<band height="80">
<band height="81">
<staticText>
<reportElement x="20" y="10" width="201" height="70" uuid="a8f7e495-37a7-4a4f-86ac-a4b0cd4c7957"/>
<textElement>
@@ -121,7 +130,7 @@ Beria Consultants Limited]]></text>
<text><![CDATA[Authorized Signature]]></text>
</staticText>
<line>
<reportElement x="320" y="69" width="140" height="1" uuid="1aab4154-48c9-4ab7-8228-be3e69526457">
<reportElement x="320" y="80" width="140" height="1" uuid="1aab4154-48c9-4ab7-8228-be3e69526457">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
@@ -132,11 +141,11 @@ Beria Consultants Limited]]></text>
<group name="Total Amount">
<groupFooter>
<band height="20">
<textField pattern="#,##0.00" isBlankWhenNull="false">
<textField pattern="$#,##0.00;-$#,##0.00" isBlankWhenNull="false">
<reportElement x="440" y="0" width="110" height="20" uuid="03e0b533-986b-421e-b270-52d1bb2015cd">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textElement textAlignment="Right"/>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{totalAmount}]]></textFieldExpression>
</textField>
<line>
@@ -146,7 +155,7 @@ Beria Consultants Limited]]></text>
</reportElement>
</line>
<staticText>
<reportElement x="321" y="0" width="119" height="20" uuid="cea68cad-ad0f-4730-bda2-e3dd43a95b4c">
<reportElement x="330" y="0" width="110" height="20" uuid="cea68cad-ad0f-4730-bda2-e3dd43a95b4c">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<textElement textAlignment="Justified" verticalAlignment="Middle">
@@ -189,33 +198,39 @@ Beria Consultants Limited]]></text>
<textFieldExpression><![CDATA[$P{Attention}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="380" y="0" width="164" height="20" uuid="a32bd1bf-7334-4923-8c20-f9a1b9fc1254">
<reportElement x="400" y="0" width="140" height="20" uuid="a32bd1bf-7334-4923-8c20-f9a1b9fc1254">
<property name="com.jaspersoft.studio.unit.y" value="px"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<box topPadding="0" bottomPadding="0"/>
<textFieldExpression><![CDATA[$P{curDate}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="280" y="0" width="100" height="20" uuid="d15659cd-045c-4f33-beb0-6b52e595ebbc">
<reportElement x="300" y="0" width="100" height="20" uuid="d15659cd-045c-4f33-beb0-6b52e595ebbc">
<property name="com.jaspersoft.studio.unit.y" value="px"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<box topPadding="0" bottomPadding="0"/>
<text><![CDATA[Date:]]></text>
</staticText>
<staticText>
<reportElement x="280" y="25" width="100" height="20" uuid="d70d883a-2779-4894-be69-a7b2216bc1ea">
<reportElement x="300" y="25" width="100" height="20" uuid="d70d883a-2779-4894-be69-a7b2216bc1ea">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<box topPadding="0" bottomPadding="0"/>
<text><![CDATA[Payment Due Date:]]></text>
</staticText>
<textField>
<reportElement x="380" y="25" width="164" height="20" uuid="93e3fb31-d6bd-4a84-beb9-ac17976665d9">
<reportElement x="400" y="25" width="140" height="20" uuid="93e3fb31-d6bd-4a84-beb9-ac17976665d9">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<box topPadding="0" bottomPadding="0"/>
<textFieldExpression><![CDATA[$P{dueDate}]]></textFieldExpression>
@@ -231,7 +246,8 @@ Beria Consultants Limited]]></text>
</group>
<group name="Column Header">
<groupHeader>
<band height="41">
<band height="70">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<staticText>
<reportElement x="260" y="0" width="60" height="40" uuid="057f3605-56be-440f-b783-ec401036c4dd"/>
<textElement textAlignment="Center" verticalAlignment="Bottom">
@@ -241,7 +257,7 @@ Beria Consultants Limited]]></text>
]]></text>
</staticText>
<staticText>
<reportElement x="17" y="1" width="243" height="40" uuid="96dfd897-5af3-4ae6-8231-1f96643e013e"/>
<reportElement stretchType="ContainerHeight" x="17" y="1" width="243" height="40" uuid="96dfd897-5af3-4ae6-8231-1f96643e013e"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
@@ -262,18 +278,21 @@ Beria Consultants Limited]]></text>
<text><![CDATA[Unit Price]]></text>
</staticText>
<line>
<reportElement x="260" y="0" width="1" height="41" uuid="3cefc23f-32b5-41eb-804a-65dca704f5c9">
<reportElement stretchType="ElementGroupHeight" x="260" y="0" width="1" height="70" uuid="3cefc23f-32b5-41eb-804a-65dca704f5c9">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
</line>
<line>
<reportElement x="320" y="0" width="1" height="41" uuid="e80e9429-abb8-4d7b-a399-1dad66108e84">
<reportElement stretchType="ContainerHeight" x="320" y="0" width="1" height="70" uuid="e80e9429-abb8-4d7b-a399-1dad66108e84">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
</line>
<line>
<reportElement x="440" y="0" width="1" height="40" uuid="c55f3275-fae9-4d3f-aba0-2b135acee5df">
<reportElement stretchType="ContainerHeight" x="440" y="0" width="1" height="70" uuid="c55f3275-fae9-4d3f-aba0-2b135acee5df">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
</line>
<line>
@@ -287,6 +306,15 @@ Beria Consultants Limited]]></text>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
</line>
<textField textAdjust="StretchHeight">
<reportElement x="17" y="40" width="242" height="30" isPrintWhenDetailOverflows="true" uuid="66129353-13d6-4bd5-9ff8-e19ebcee9814">
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
<textElement>
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{stage}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
@@ -305,51 +333,57 @@ Beria Consultants Limited]]></text>
</band>
</pageHeader>
<detail>
<band height="20" splitType="Stretch">
<band height="30" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<textField isBlankWhenNull="false">
<reportElement x="17" y="0" width="244" height="20" uuid="ee29910e-c4a8-4749-9d3f-f5402db35d4a"/>
<reportElement x="27" y="0" width="232" height="30" uuid="ee29910e-c4a8-4749-9d3f-f5402db35d4a">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
<textElement>
<font isBold="true"/>
<font isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{paymentMilestone}]]></textFieldExpression>
</textField>
<textField pattern="#,##0.00" isBlankWhenNull="false">
<reportElement x="321" y="0" width="120" height="20" uuid="f1a30fbb-a957-41d5-93b8-ada8db80cda0">
<textField pattern="$#,##0.00;$-#,##0.00" isBlankWhenNull="false">
<reportElement x="320" y="0" width="120" height="30" uuid="f1a30fbb-a957-41d5-93b8-ada8db80cda0">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
<box rightPadding="3"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{unitPrice}]]></textFieldExpression>
</textField>
<line>
<reportElement x="260" y="0" width="1" height="20" uuid="f0bda4f5-9e0f-4dde-9446-b4fef2396b03">
<reportElement x="260" y="0" width="1" height="30" uuid="f0bda4f5-9e0f-4dde-9446-b4fef2396b03">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
</line>
<line>
<reportElement x="320" y="0" width="1" height="20" uuid="220039eb-de38-4db8-a2ab-bca2879ad100">
<reportElement x="320" y="0" width="1" height="30" uuid="220039eb-de38-4db8-a2ab-bca2879ad100">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
</line>
<line>
<reportElement x="440" y="0" width="1" height="20" uuid="8b718f3b-39d5-4136-b1eb-49cfce304b0b">
<reportElement x="440" y="0" width="1" height="30" uuid="8b718f3b-39d5-4136-b1eb-49cfce304b0b">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
</line>
<textField pattern="#,##0.00" isBlankWhenNull="false">
<reportElement x="439" y="0" width="110" height="20" uuid="aa36d257-7e07-4a10-869d-12af3a1d3018">
<textField pattern="$#,##0.00;-$#,##0.00" isBlankWhenNull="false">
<reportElement x="440" y="0" width="110" height="30" uuid="aa36d257-7e07-4a10-869d-12af3a1d3018">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{unitPrice}.multiply( $F{qty})]]></textFieldExpression>
</textField>
<textField pattern="#,##0.00" isBlankWhenNull="false">
<reportElement x="260" y="0" width="60" height="20" uuid="0cc30128-9eca-42d1-8feb-08a296c75235">
<reportElement x="260" y="0" width="60" height="30" uuid="0cc30128-9eca-42d1-8feb-08a296c75235">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
<box topPadding="0" leftPadding="0" bottomPadding="0" rightPadding="3"/>
<textElement textAlignment="Right"/>


Loading…
Cancel
Save