diff --git a/src/main/java/com/ffii/tsms/modules/project/entity/ProjectExpenseRepository.kt b/src/main/java/com/ffii/tsms/modules/project/entity/ProjectExpenseRepository.kt index 16829c3..0cd0987 100644 --- a/src/main/java/com/ffii/tsms/modules/project/entity/ProjectExpenseRepository.kt +++ b/src/main/java/com/ffii/tsms/modules/project/entity/ProjectExpenseRepository.kt @@ -5,4 +5,6 @@ import com.ffii.tsms.modules.project.entity.projections.ProjectExpenseSearchInfo interface ProjectExpenseRepository : AbstractRepository { fun findExpenseSearchInfoByDeletedFalse(): List + + fun findAllByProjectIdAndDeletedFalse(projectId: Long): List } \ No newline at end of file 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 528ddb8..377734d 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 @@ -822,9 +822,12 @@ open class ReportService( it.staff.staffId == timesheet.staff?.staffId && it.date.year == timesheet.recordDate?.year && it.date.month == timesheet.recordDate?.month }?.hourlyRate ?: 0.0) * ((timesheet.normalConsumed ?: 0.0) + (timesheet.otConsumed ?: 0.0)) } + + val sumProjectExpense = projectExpenses.sumOf { it.amount?: 0.0 } + sheet.getRow(rowIndex).apply { createCell(1).apply { - setCellValue(actualExpenditure) + setCellValue(actualExpenditure + sumProjectExpense) cellStyle.dataFormat = accountingStyle } @@ -899,8 +902,8 @@ open class ReportService( ) } } - println("grouped Project Expense") - println(groupedProjectExpense) +// println("grouped Project Expense") +// println(groupedProjectExpense) // groupedTimesheets.entries.forEach { (key, value) -> // logger.info("key: $key") // logger.info("value: " + value.sumOf { it }) @@ -932,18 +935,23 @@ open class ReportService( } createCell(2).apply { - setCellValue(invoice["paidAmount"] as Double? ?: 0.0) + setCellValue(0.0) cellStyle.dataFormat = accountingStyle } createCell(3).apply { + setCellValue(invoice["paidAmount"] as Double? ?: 0.0) + cellStyle.dataFormat = accountingStyle + } + + createCell(4).apply { val lastRow = rowIndex - 1 if (lastRow == 16) { cellFormula = "C{currentRow}-B{currentRow}".replace("{currentRow}", rowIndex.toString()) } else { cellFormula = - "IF(B{currentRow}>0,D{lastRow}-B{currentRow},D{lastRow}+C{currentRow})".replace( + "IF(B{currentRow}>0,E{lastRow}-B{currentRow}-C{currentRow},E{lastRow}+D{currentRow}-C{currentRow})".replace( "{currentRow}", rowIndex.toString() ).replace("{lastRow}", lastRow.toString()) @@ -951,7 +959,7 @@ open class ReportService( cellStyle.dataFormat = accountingStyle } - createCell(4)?.apply { + createCell(5)?.apply { setCellValue( "Invoice Receipt: " + (invoice["invoiceNo"] as String? ?: "N/A").toString() ) @@ -971,18 +979,23 @@ open class ReportService( } createCell(2).apply { - setCellValue(groupedInvoices[result]?.sumOf { it["paidAmount"] as Double } ?: 0.0) + setCellValue(0.0) cellStyle.dataFormat = accountingStyle } createCell(3).apply { + setCellValue(groupedInvoices[result]?.sumOf { it["paidAmount"] as Double } ?: 0.0) + cellStyle.dataFormat = accountingStyle + } + + createCell(4).apply { val lastRow = rowIndex - 1 if (lastRow == 16) { cellFormula = "C{currentRow}-B{currentRow}".replace("{currentRow}", rowIndex.toString()) } else { cellFormula = - "IF(B{currentRow}>0,D{lastRow}-B{currentRow},D{lastRow}+C{currentRow})".replace( + "IF(B{currentRow}>0,E{lastRow}-B{currentRow}-C{currentRow},E{lastRow}+D{currentRow}-C{currentRow})".replace( "{currentRow}", rowIndex.toString() ).replace("{lastRow}", lastRow.toString()) @@ -990,7 +1003,7 @@ open class ReportService( cellStyle.dataFormat = accountingStyle } - createCell(4)?.apply { + createCell(5)?.apply { // setCellValue(invoice["description"].toString()) val invoiceNos = groupedInvoices[result]?.map { it["invoiceNo"] } if (invoiceNos?.size != null && invoiceNos.size > 1) { @@ -1023,12 +1036,17 @@ open class ReportService( } createCell(3).apply { + setCellValue(0.0) + cellStyle.dataFormat = accountingStyle + } + + createCell(4).apply { val lastRow = rowIndex - 1 if (lastRow == 16) { cellFormula = "C{currentRow}-B{currentRow}".replace("{currentRow}", rowIndex.toString()) } else { cellFormula = - "IF(B{currentRow}>0,D{lastRow}-B{currentRow},D{lastRow}+C{currentRow})".replace( + "IF(B{currentRow}>0,E{lastRow}-B{currentRow}-C{currentRow},E{lastRow}+D{currentRow}-C{currentRow})".replace( "{currentRow}", rowIndex.toString() ).replace("{lastRow}", lastRow.toString()) @@ -1036,12 +1054,13 @@ open class ReportService( cellStyle.dataFormat = accountingStyle } - createCell(4).apply { + createCell(5).apply { setCellValue("Manpower Expenditure") } } } + } conditionalFormattingNegative(sheet) diff --git a/src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt b/src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt index c12c060..62d0190 100644 --- a/src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt +++ b/src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt @@ -89,7 +89,7 @@ class ReportController( // val invoices = invoiceService.findAllByProjectAndPaidAmountIsNotNull(project) val invoices = invoiceRepository.findAllByProjectCodeAndPaidAmountIsNotNullAndDeletedFalse(project.code!!) val timesheets = timesheetRepository.findAllByProjectTaskIn(projectTasks) - val projectExpenses = projectExpenseRepository.findAll().filter { it.project == project } + val projectExpenses = projectExpenseRepository.findAllByProjectIdAndDeletedFalse(project.id!!) val monthlyStaffSalaryEffective = salaryEffectiveService.getMonthlyStaffSalaryData(timesheets.minByOrNull { it.recordDate!! }?.recordDate ?: LocalDate.parse("2012-01-01"), timesheets.maxByOrNull { it.recordDate!! }?.recordDate ?: LocalDate.now()) val reportResult: ByteArray = excelReportService.generateProjectCashFlowReport(project, invoices, timesheets, projectExpenses, monthlyStaffSalaryEffective, request.dateType) diff --git a/src/main/resources/templates/report/EX02_Project Cash Flow Report.xlsx b/src/main/resources/templates/report/EX02_Project Cash Flow Report.xlsx index 2726f56..d0e60e7 100644 Binary files a/src/main/resources/templates/report/EX02_Project Cash Flow Report.xlsx and b/src/main/resources/templates/report/EX02_Project Cash Flow Report.xlsx differ