diff --git a/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt b/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt index 5b27922..748735a 100644 --- a/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt +++ b/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt @@ -107,6 +107,7 @@ open class ReportService( "code" to item.getValue("code"), "description" to item.getValue("description"), "client" to item.getValue("client"), + "subsidiary" to item.getValue("subsidiary"), "teamLead" to item.getValue("teamLead"), "planStart" to item.getValue("planStart"), "planEnd" to item.getValue("planEnd"), @@ -317,8 +318,9 @@ open class ReportService( //Set Column 2, 3, 4 to auto width sheet.setColumnWidth(2, 20 * 256) - sheet.setColumnWidth(3, 45 * 256) - sheet.setColumnWidth(4, 15 * 256) + sheet.setColumnWidth(3, 20 * 256) + sheet.setColumnWidth(4, 45 * 256) + sheet.setColumnWidth(5, 15 * 256) val boldFont = sheet.workbook.createFont() boldFont.bold = true @@ -378,29 +380,35 @@ open class ReportService( } CellUtil.setAlignment(clientCell, HorizontalAlignment.CENTER) - val teamLeadCell = row.createCell(3) + val subsidiaryCell = row.createCell(3) + subsidiaryCell.apply { + setCellValue(if (item["subsidiary"] != null) item.getValue("subsidiary").toString() else "N/A") + } + CellUtil.setAlignment(subsidiaryCell, HorizontalAlignment.CENTER) + + val teamLeadCell = row.createCell(4) teamLeadCell.setCellValue(if (item["teamLead"] != null) item.getValue("teamLead").toString() else "N/A") - val startDateCell = row.createCell(4) + val startDateCell = row.createCell(5) startDateCell.setCellValue(if (item["planStart"] != null) item.getValue("planStart").toString() else "N/A") - val endDateCell = row.createCell(5) + val endDateCell = row.createCell(6) endDateCell.setCellValue(if (item["planEnd"] != null) item.getValue("planEnd").toString() else "N/A") - val totalFeeCell = row.createCell(6) + val totalFeeCell = row.createCell(7) val totalFee = item["expectedTotalFee"]?.let { it as Double } ?: 0.0 totalFeeCell.apply { setCellValue(totalFee) cellStyle.dataFormat = accountingStyle } - val budgetCell = row.createCell(7) + val budgetCell = row.createCell(8) budgetCell.apply { cellFormula = "G${rowNum} * 80%" cellStyle.dataFormat = accountingStyle } - val cumExpenditureCell = row.createCell(8) + val cumExpenditureCell = row.createCell(9) val normalConsumed = item["normalConsumed"]?.let { it as BigDecimal } ?: BigDecimal(0) val otConsumed = item["otConsumed"]?.let { it as BigDecimal } ?: BigDecimal(0) val cumExpenditure = normalConsumed.add(otConsumed) @@ -409,21 +417,21 @@ open class ReportService( cellStyle.dataFormat = accountingStyle } - val budgetVCell = row.createCell(9) + val budgetVCell = row.createCell(10) budgetVCell.apply { cellFormula = "H${rowNum} - I${rowNum}" cellStyle = boldFontCellStyle cellStyle.dataFormat = accountingStyle } - val issuedCell = row.createCell(10) + val issuedCell = row.createCell(11) val issuedAmount = item["issuedAmount"]?.let { it as BigDecimal } ?: BigDecimal(0) issuedCell.apply { setCellValue(issuedAmount.toDouble()) cellStyle.dataFormat = accountingStyle } - val uninvoiceCell = row.createCell(11) + val uninvoiceCell = row.createCell(12) uninvoiceCell.apply { cellFormula = " IF(H${rowNum}<=I${rowNum}, H${rowNum}-K${rowNum}, IF(AND(H${rowNum}>I${rowNum}, I${rowNum}I${rowNum}, I${rowNum}>=K${rowNum}), I${rowNum}-K${rowNum}, 0))) " @@ -431,19 +439,19 @@ open class ReportService( cellStyle.dataFormat = accountingStyle } - val cpiCell = row.createCell(12) + val cpiCell = row.createCell(13) cpiCell.apply { cellFormula = "IF(K${rowNum} = 0, 0, K${rowNum}/I${rowNum})" } - val receivedAmountCell = row.createCell(13) + val receivedAmountCell = row.createCell(14) val paidAmount = item["paidAmount"]?.let { it as BigDecimal } ?: BigDecimal(0) receivedAmountCell.apply { setCellValue(paidAmount.toDouble()) cellStyle.dataFormat = accountingStyle } - val unsettledAmountCell = row.createCell(14) + val unsettledAmountCell = row.createCell(15) unsettledAmountCell.apply { cellFormula = "K${rowNum}-N${rowNum}" cellStyle = boldFontCellStyle @@ -454,13 +462,13 @@ open class ReportService( val lastRowNum = rowNum + 1 val row: Row = sheet.createRow(rowNum) - for (i in 0..4) { + for (i in 0..5) { val cell = row.createCell(i) CellUtil.setCellStyleProperty(cell, "borderTop", BorderStyle.THIN) CellUtil.setCellStyleProperty(cell, "borderBottom", BorderStyle.DOUBLE) } - val subTotalCell = row.createCell(5) + val subTotalCell = row.createCell(6) subTotalCell.apply { setCellValue("Sub-total:") } @@ -468,71 +476,71 @@ open class ReportService( CellUtil.setCellStyleProperty(subTotalCell, "borderBottom", BorderStyle.DOUBLE) - val sumTotalFeeCell = row.createCell(6) + val sumTotalFeeCell = row.createCell(7) sumTotalFeeCell.apply { - cellFormula = "SUM(G15:G${rowNum})" + cellFormula = "SUM(H15:H${rowNum})" cellStyle.dataFormat = accountingStyle } CellUtil.setCellStyleProperty(sumTotalFeeCell, "borderTop", BorderStyle.THIN) CellUtil.setCellStyleProperty(sumTotalFeeCell, "borderBottom", BorderStyle.DOUBLE) - val sumBudgetCell = row.createCell(7) + val sumBudgetCell = row.createCell(8) sumBudgetCell.apply { - cellFormula = "SUM(H15:H${rowNum})" + cellFormula = "SUM(I15:I${rowNum})" cellStyle.dataFormat = accountingStyle } CellUtil.setCellStyleProperty(sumBudgetCell, "borderTop", BorderStyle.THIN) CellUtil.setCellStyleProperty(sumBudgetCell, "borderBottom", BorderStyle.DOUBLE) - val sumCumExpenditureCell = row.createCell(8) + val sumCumExpenditureCell = row.createCell(9) sumCumExpenditureCell.apply { - cellFormula = "SUM(I15:I${rowNum})" + cellFormula = "SUM(J15:J${rowNum})" cellStyle.dataFormat = accountingStyle } CellUtil.setCellStyleProperty(sumCumExpenditureCell, "borderTop", BorderStyle.THIN) CellUtil.setCellStyleProperty(sumCumExpenditureCell, "borderBottom", BorderStyle.DOUBLE) - val sumBudgetVCell = row.createCell(9) + val sumBudgetVCell = row.createCell(10) sumBudgetVCell.apply { - cellFormula = "SUM(J15:J${rowNum})" + cellFormula = "SUM(K15:K${rowNum})" cellStyle = boldFontCellStyle cellStyle.dataFormat = accountingStyle } CellUtil.setCellStyleProperty(sumBudgetVCell, "borderTop", BorderStyle.THIN) CellUtil.setCellStyleProperty(sumBudgetVCell, "borderBottom", BorderStyle.DOUBLE) - val sumIInvoiceCell = row.createCell(10) + val sumIInvoiceCell = row.createCell(11) sumIInvoiceCell.apply { - cellFormula = "SUM(K15:K${rowNum})" + cellFormula = "SUM(L15:L${rowNum})" cellStyle.dataFormat = accountingStyle } CellUtil.setCellStyleProperty(sumIInvoiceCell, "borderTop", BorderStyle.THIN) CellUtil.setCellStyleProperty(sumIInvoiceCell, "borderBottom", BorderStyle.DOUBLE) - val sumUInvoiceCell = row.createCell(11) + val sumUInvoiceCell = row.createCell(12) sumUInvoiceCell.apply { - cellFormula = "SUM(L15:L${rowNum})" + cellFormula = "SUM(M15:M${rowNum})" cellStyle = boldFontCellStyle cellStyle.dataFormat = accountingStyle } CellUtil.setCellStyleProperty(sumUInvoiceCell, "borderTop", BorderStyle.THIN) CellUtil.setCellStyleProperty(sumUInvoiceCell, "borderBottom", BorderStyle.DOUBLE) - val lastCpiCell = row.createCell(12) + val lastCpiCell = row.createCell(13) CellUtil.setCellStyleProperty(lastCpiCell, "borderTop", BorderStyle.THIN) CellUtil.setCellStyleProperty(lastCpiCell, "borderBottom", BorderStyle.DOUBLE) - val sumRAmountCell = row.createCell(13) + val sumRAmountCell = row.createCell(14) sumRAmountCell.apply { - cellFormula = "SUM(N15:N${rowNum})" + cellFormula = "SUM(O15:O${rowNum})" cellStyle.dataFormat = accountingStyle } CellUtil.setCellStyleProperty(sumRAmountCell, "borderTop", BorderStyle.THIN) CellUtil.setCellStyleProperty(sumRAmountCell, "borderBottom", BorderStyle.DOUBLE) - val sumUnSettleCell = row.createCell(14) + val sumUnSettleCell = row.createCell(15) sumUnSettleCell.apply { - cellFormula = "SUM(O15:O${rowNum})" + cellFormula = "SUM(P15:P${rowNum})" cellStyle = boldFontCellStyle cellStyle.dataFormat = accountingStyle } @@ -552,7 +560,7 @@ open class ReportService( row2Cell.setCellValue("All") } else { row2Cell.apply { - cellFormula = "D15" + cellFormula = "E15" } } @@ -565,7 +573,7 @@ open class ReportService( val row5: Row = sheet.getRow(rowNum) val cell1 = row5.createCell(2) cell1.apply { - cellFormula = "H${lastRowNum}" + cellFormula = "I${lastRowNum}" cellStyle.dataFormat = accountingStyle } @@ -573,7 +581,7 @@ open class ReportService( val row6: Row = sheet.getRow(rowNum) val cell2 = row6.createCell(2) cell2.apply { - cellFormula = "I${lastRowNum}" + cellFormula = "J${lastRowNum}" cellStyle.dataFormat = accountingStyle } @@ -581,7 +589,7 @@ open class ReportService( val row7: Row = sheet.getRow(rowNum) val cell3 = row7.createCell(2) cell3.apply { - cellFormula = "J${lastRowNum}" + cellFormula = "K${lastRowNum}" cellStyle.dataFormat = accountingStyle } @@ -589,7 +597,7 @@ open class ReportService( val row8: Row = sheet.getRow(rowNum) val cell4 = row8.createCell(2) cell4.apply { - cellFormula = "K${lastRowNum}" + cellFormula = "L${lastRowNum}" cellStyle.dataFormat = accountingStyle } @@ -597,7 +605,7 @@ open class ReportService( val row9: Row = sheet.getRow(rowNum) val cell5 = row9.createCell(2) cell5.apply { - cellFormula = "L${lastRowNum}" + cellFormula = "N${lastRowNum}" cellStyle.dataFormat = accountingStyle } @@ -605,7 +613,7 @@ open class ReportService( val row10: Row = sheet.getRow(rowNum) val cell6 = row10.createCell(2) cell6.apply { - cellFormula = "N${lastRowNum}" + cellFormula = "O${lastRowNum}" cellStyle.dataFormat = accountingStyle } @@ -613,7 +621,7 @@ open class ReportService( val row11: Row = sheet.getRow(rowNum) val cell7 = row11.createCell(2) cell7.apply { - cellFormula = "O${lastRowNum}" + cellFormula = "P${lastRowNum}" cellStyle.dataFormat = accountingStyle } @@ -1664,12 +1672,14 @@ open class ReportService( + " left join project p on p.code = i.projectCode" + " group by p.code" + " )" - + " select p.code, p.description, c.name as client, concat(t.code, \' - \', t.name) as teamLead, p.planStart , p.planEnd , p.expectedTotalFee," + + " select p.code, p.description, c.name as client, IFNULL(s2.name, \"N/A\") as subsidiary, concat(t.code, \' - \', t.name) as teamLead, p.planStart , p.planEnd , p.expectedTotalFee," + " IFNULL(cte_ts.normalConsumed, 0) as normalConsumed, IFNULL(cte_ts.otConsumed, 0) as otConsumed," + " IFNULL(cte_ts.hourlyRate, 0) as hourlyRate, IFNULL(cte_i.sumIssuedAmount, 0) as sumIssuedAmount, IFNULL(cte_i.sumPaidAmount, 0) as sumPaidAmount" + " from project p" + " left join cte_timesheet cte_ts on p.code = cte_ts.code" + " left join customer c on c.id = p.customerId" + + " left join customer_subsidiary cs on cs.id = p.customerSubsidiaryId" + + " left join subsidiary s2 on s2.id = cs.subsidiaryId " + " left join tsmsdb.team t on t.teamLead = p.teamLead" + " left join cte_invoice cte_i on cte_i.code = p.code" + " where p.status = \'On-going\'" @@ -1877,7 +1887,7 @@ open class ReportService( + " left join project p on p.code = i.projectCode" + " group by p.code" + " )" - + " select p.code, p.description, c.name as client, concat(t.code, \" - \", t.name) as teamLead," + + " select p.code, p.description, c.name as client, IFNULL(s2.name, \"N/A\") as subsidiary, concat(t.code, \" - \", t.name) as teamLead," + " IFNULL(cte_ts.normalConsumed, 0) as normalConsumed, IFNULL(cte_ts.otConsumed, 0) as otConsumed, DATE_FORMAT(cte_ts.recordDate, '%Y-%m') as recordDate, " + " IFNULL(cte_ts.salaryPoint, 0) as salaryPoint, " + " IFNULL(cte_ts.hourlyRate, 0) as hourlyRate, IFNULL(cte_i.sumIssuedAmount, 0) as sumIssuedAmount, IFNULL(cte_i.sumPaidAmount, 0) as sumPaidAmount," @@ -1890,6 +1900,8 @@ open class ReportService( + " left join staff s on s.id = cte_ts.staffId" + " left join grade g on g.id = s.gradeId" + " left join team t2 on t2.id = s.teamId" + + " left join customer_subsidiary cs on cs.id = p.customerSubsidiaryId " + + " left join subsidiary s2 on s2.id = cs.subsidiaryId " + " where p.deleted = false" + " and (DATE_FORMAT(cte_ts.recordDate, \'%Y-%m\') >= :startMonth and DATE_FORMAT(cte_ts.recordDate, \'%Y-%m\') <= :endMonth)" + " and p.id = :projectId" @@ -1941,6 +1953,9 @@ open class ReportService( if (info["code"] == item["code"] && "paidAmount" !in info) { info["paidAmount"] = item.getValue("sumPaidAmount") } + if (info["code"] == item["code"] && "subsidiary" !in info) { + info["subsidiary"] = item.getValue("subsidiary") + } if (info["description"] != item.getValue("description")) { info["description"] = item.getValue("description") } @@ -2040,6 +2055,7 @@ open class ReportService( val accountingStyle = workbook.createDataFormat().getFormat("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)") + val monthFormat = DateTimeFormatter.ofPattern("MMM yyyy", Locale.ENGLISH) val startDate = YearMonth.parse(startMonth, DateTimeFormatter.ofPattern("yyyy-MM")) val convertStartMonth = YearMonth.of(startDate.year, startDate.month) val endDate = YearMonth.parse(endMonth, DateTimeFormatter.ofPattern("yyyy-MM")) @@ -2050,15 +2066,13 @@ open class ReportService( while (!currentDate.isAfter(endDate)) { monthRange.add( mapOf( - "display" to currentDate.month.name.substring(0, 3), + "display" to YearMonth.of(currentDate.year, currentDate.month).format(monthFormat), "date" to currentDate ) ) currentDate = currentDate.plusMonths(1) } - val monthFormat = DateTimeFormatter.ofPattern("MMM yyyy", Locale.ENGLISH) - val info: Map = manhoursSpent.first() { it.containsKey("info") }["info"] as Map val staffInfoList: List> = manhoursSpent.first() { it.containsKey("staffInfoList") }["staffInfoList"] as List> @@ -2129,7 +2143,12 @@ open class ReportService( rowNum = 6 val row6: Row = sheet.getRow(rowNum) val row6Cell = row6.getCell(1) - row6Cell.setCellValue(info.getValue("client").toString()) + val clientSubsidiary = if(info.getValue("subsidiary").toString() != "N/A"){ + info.getValue("subsidiary").toString() + }else{ + info.getValue("client").toString() + } + row6Cell.setCellValue(clientSubsidiary) rowNum = 9 val row9: Row = sheet.getRow(rowNum) diff --git a/src/main/resources/templates/report/AR07_Project P&L Report v02.xlsx b/src/main/resources/templates/report/AR07_Project P&L Report v02.xlsx index 111482b..8acd339 100644 Binary files a/src/main/resources/templates/report/AR07_Project P&L Report v02.xlsx and b/src/main/resources/templates/report/AR07_Project P&L Report v02.xlsx differ diff --git a/src/main/resources/templates/report/EX01_Financial Status Report.xlsx b/src/main/resources/templates/report/EX01_Financial Status Report.xlsx index f864de3..b269cbb 100644 Binary files a/src/main/resources/templates/report/EX01_Financial Status Report.xlsx and b/src/main/resources/templates/report/EX01_Financial Status Report.xlsx differ