Browse Source

Cah Flow Report

add_swagger
MSI\2Fi 11 months ago
parent
commit
1eab253266
4 changed files with 33 additions and 12 deletions
  1. +2
    -0
      src/main/java/com/ffii/tsms/modules/project/entity/ProjectExpenseRepository.kt
  2. +30
    -11
      src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt
  3. +1
    -1
      src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt
  4. BIN
      src/main/resources/templates/report/EX02_Project Cash Flow Report.xlsx

+ 2
- 0
src/main/java/com/ffii/tsms/modules/project/entity/ProjectExpenseRepository.kt View File

@@ -5,4 +5,6 @@ import com.ffii.tsms.modules.project.entity.projections.ProjectExpenseSearchInfo


interface ProjectExpenseRepository : AbstractRepository<ProjectExpense, Long> { interface ProjectExpenseRepository : AbstractRepository<ProjectExpense, Long> {
fun findExpenseSearchInfoByDeletedFalse(): List<ProjectExpenseSearchInfo> fun findExpenseSearchInfoByDeletedFalse(): List<ProjectExpenseSearchInfo>

fun findAllByProjectIdAndDeletedFalse(projectId: Long): List<ProjectExpense>
} }

+ 30
- 11
src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt View File

@@ -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 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)) }?.hourlyRate ?: 0.0) * ((timesheet.normalConsumed ?: 0.0) + (timesheet.otConsumed ?: 0.0))
} }

val sumProjectExpense = projectExpenses.sumOf { it.amount?: 0.0 }

sheet.getRow(rowIndex).apply { sheet.getRow(rowIndex).apply {
createCell(1).apply { createCell(1).apply {
setCellValue(actualExpenditure)
setCellValue(actualExpenditure + sumProjectExpense)
cellStyle.dataFormat = accountingStyle 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) -> // groupedTimesheets.entries.forEach { (key, value) ->
// logger.info("key: $key") // logger.info("key: $key")
// logger.info("value: " + value.sumOf { it }) // logger.info("value: " + value.sumOf { it })
@@ -932,18 +935,23 @@ open class ReportService(
} }


createCell(2).apply { createCell(2).apply {
setCellValue(invoice["paidAmount"] as Double? ?: 0.0)
setCellValue(0.0)
cellStyle.dataFormat = accountingStyle cellStyle.dataFormat = accountingStyle
} }


createCell(3).apply { createCell(3).apply {
setCellValue(invoice["paidAmount"] as Double? ?: 0.0)
cellStyle.dataFormat = accountingStyle
}

createCell(4).apply {
val lastRow = rowIndex - 1 val lastRow = rowIndex - 1
if (lastRow == 16) { if (lastRow == 16) {
cellFormula = cellFormula =
"C{currentRow}-B{currentRow}".replace("{currentRow}", rowIndex.toString()) "C{currentRow}-B{currentRow}".replace("{currentRow}", rowIndex.toString())
} else { } else {
cellFormula = 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}", "{currentRow}",
rowIndex.toString() rowIndex.toString()
).replace("{lastRow}", lastRow.toString()) ).replace("{lastRow}", lastRow.toString())
@@ -951,7 +959,7 @@ open class ReportService(
cellStyle.dataFormat = accountingStyle cellStyle.dataFormat = accountingStyle
} }


createCell(4)?.apply {
createCell(5)?.apply {
setCellValue( setCellValue(
"Invoice Receipt: " + (invoice["invoiceNo"] as String? ?: "N/A").toString() "Invoice Receipt: " + (invoice["invoiceNo"] as String? ?: "N/A").toString()
) )
@@ -971,18 +979,23 @@ open class ReportService(
} }


createCell(2).apply { createCell(2).apply {
setCellValue(groupedInvoices[result]?.sumOf { it["paidAmount"] as Double } ?: 0.0)
setCellValue(0.0)
cellStyle.dataFormat = accountingStyle cellStyle.dataFormat = accountingStyle
} }


createCell(3).apply { createCell(3).apply {
setCellValue(groupedInvoices[result]?.sumOf { it["paidAmount"] as Double } ?: 0.0)
cellStyle.dataFormat = accountingStyle
}

createCell(4).apply {
val lastRow = rowIndex - 1 val lastRow = rowIndex - 1
if (lastRow == 16) { if (lastRow == 16) {
cellFormula = cellFormula =
"C{currentRow}-B{currentRow}".replace("{currentRow}", rowIndex.toString()) "C{currentRow}-B{currentRow}".replace("{currentRow}", rowIndex.toString())
} else { } else {
cellFormula = 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}", "{currentRow}",
rowIndex.toString() rowIndex.toString()
).replace("{lastRow}", lastRow.toString()) ).replace("{lastRow}", lastRow.toString())
@@ -990,7 +1003,7 @@ open class ReportService(
cellStyle.dataFormat = accountingStyle cellStyle.dataFormat = accountingStyle
} }


createCell(4)?.apply {
createCell(5)?.apply {
// setCellValue(invoice["description"].toString()) // setCellValue(invoice["description"].toString())
val invoiceNos = groupedInvoices[result]?.map { it["invoiceNo"] } val invoiceNos = groupedInvoices[result]?.map { it["invoiceNo"] }
if (invoiceNos?.size != null && invoiceNos.size > 1) { if (invoiceNos?.size != null && invoiceNos.size > 1) {
@@ -1023,12 +1036,17 @@ open class ReportService(
} }


createCell(3).apply { createCell(3).apply {
setCellValue(0.0)
cellStyle.dataFormat = accountingStyle
}

createCell(4).apply {
val lastRow = rowIndex - 1 val lastRow = rowIndex - 1
if (lastRow == 16) { if (lastRow == 16) {
cellFormula = "C{currentRow}-B{currentRow}".replace("{currentRow}", rowIndex.toString()) cellFormula = "C{currentRow}-B{currentRow}".replace("{currentRow}", rowIndex.toString())
} else { } else {
cellFormula = 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}", "{currentRow}",
rowIndex.toString() rowIndex.toString()
).replace("{lastRow}", lastRow.toString()) ).replace("{lastRow}", lastRow.toString())
@@ -1036,12 +1054,13 @@ open class ReportService(
cellStyle.dataFormat = accountingStyle cellStyle.dataFormat = accountingStyle
} }


createCell(4).apply {
createCell(5).apply {
setCellValue("Manpower Expenditure") setCellValue("Manpower Expenditure")
} }
} }
} }



} }


conditionalFormattingNegative(sheet) conditionalFormattingNegative(sheet)


+ 1
- 1
src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt View File

@@ -89,7 +89,7 @@ class ReportController(
// val invoices = invoiceService.findAllByProjectAndPaidAmountIsNotNull(project) // val invoices = invoiceService.findAllByProjectAndPaidAmountIsNotNull(project)
val invoices = invoiceRepository.findAllByProjectCodeAndPaidAmountIsNotNullAndDeletedFalse(project.code!!) val invoices = invoiceRepository.findAllByProjectCodeAndPaidAmountIsNotNullAndDeletedFalse(project.code!!)
val timesheets = timesheetRepository.findAllByProjectTaskIn(projectTasks) 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 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) val reportResult: ByteArray = excelReportService.generateProjectCashFlowReport(project, invoices, timesheets, projectExpenses, monthlyStaffSalaryEffective, request.dateType)


BIN
src/main/resources/templates/report/EX02_Project Cash Flow Report.xlsx View File


Loading…
Cancel
Save