From 656dec663bc79572ffd1b0157e77f0d51bab55bd Mon Sep 17 00:00:00 2001 From: "MSI\\2Fi" Date: Thu, 22 Aug 2024 13:41:58 +0800 Subject: [PATCH] Update 1. CashReport - filter deleted Invoice 2. Invoice - add delete and filter deleted Invoice --- .../project/entity/InvoiceRepository.kt | 2 +- .../modules/project/service/InvoiceService.kt | 21 ++++++++++++------- .../modules/project/web/InvoiceController.kt | 15 ++++++------- .../modules/report/service/ReportService.kt | 21 ++++++++++++++++--- .../modules/report/web/ReportController.kt | 2 +- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/ffii/tsms/modules/project/entity/InvoiceRepository.kt b/src/main/java/com/ffii/tsms/modules/project/entity/InvoiceRepository.kt index a08be63..d42227f 100644 --- a/src/main/java/com/ffii/tsms/modules/project/entity/InvoiceRepository.kt +++ b/src/main/java/com/ffii/tsms/modules/project/entity/InvoiceRepository.kt @@ -16,5 +16,5 @@ interface InvoiceRepository : AbstractRepository { fun findByInvoiceNo(invoiceNo: String): Invoice - fun findAllByProjectCodeAndPaidAmountIsNotNull(projectCode: String): List + fun findAllByProjectCodeAndPaidAmountIsNotNullAndDeletedFalse(projectCode: String): List } \ No newline at end of file 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 b3cc448..36b1e31 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 @@ -334,14 +334,15 @@ open class InvoiceService( open fun allInvoiceV3(): List>{ val sql = StringBuilder( - "select i.id, i.invoiceNo, i.projectCode, " + - "p.name as projectName, t.code as team, i.invoiceDate, " + + " select i.id, i.invoiceNo, i.projectCode, " + + " p.name as projectName, t.code as team, i.invoiceDate, " + " concat(t.code, ' - ', t.name) as teamCodeName, " + - "i.receiptDate, i.issueAmount , i.paidAmount " + - "from invoice i " + - "left join project p on i.projectCode = p.code " + - "left join team t on t.id = p.teamLead " + - "order by i.invoiceDate " + " i.receiptDate, i.issueAmount , i.paidAmount " + + " from invoice i " + + " left join project p on i.projectCode = p.code " + + " left join team t on t.id = p.teamLead " + + " where i.deleted = false " + + " order by i.invoiceDate " ) return jdbcDao.queryForList(sql.toString()); } @@ -721,4 +722,10 @@ open class InvoiceService( } } + open fun markDeleted(id: Long) { + invoiceRepository.save(invoiceRepository.findById(id).orElseThrow().apply { + deleted = true + }) + } + } 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 666c5cc..62ef65b 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 @@ -15,14 +15,9 @@ import net.sf.jasperreports.engine.JasperExportManager import net.sf.jasperreports.engine.JasperPrint import org.apache.poi.ss.usermodel.Workbook import org.apache.poi.xssf.usermodel.XSSFWorkbook +import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity -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 +import org.springframework.web.bind.annotation.* import org.springframework.web.multipart.MultipartHttpServletRequest import java.io.OutputStream @@ -145,4 +140,10 @@ class InvoiceController( fun updateInvoiceDetail(@RequestBody req: EditInvoiceRequest): EditInvoiceResponse { return invoiceService.updateInvoiceDetail(req) } + + @DeleteMapping("/{id}") + @ResponseStatus(HttpStatus.NO_CONTENT) + fun deleteProject(@PathVariable id: Long) { + invoiceService.markDeleted(id) + } } \ 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 a4b958a..d1f06e2 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 @@ -3903,6 +3903,7 @@ open class ReportService( return workbook } // Use to Calculate cummunlative expenditure +// TO DO: Add isCrossTeam data class TimesheetData( val normalConsumed: Double, val otConsumed: Double, @@ -3913,6 +3914,7 @@ open class ReportService( val projectCode: String, val planStart: LocalDate, val planEnd: LocalDate + // val isCrossTeam: Boolean ) data class SalaryEffectiveInfo( @@ -3947,6 +3949,12 @@ open class ReportService( fun getManHoursSpentByTeam(teamLeadId: Long?): List{ val sql = StringBuilder( "select coalesce(t.normalConsumed, 0) as normalConsumed, coalesce(t.otConsumed, 0) as otConsumed, t.recordDate, t.staffId, s2.hourlyRate, s2.salaryPoint, p.code, p.planStart, p.planEnd" +// For later calculating cross team charge +// + ",CASE" +// + " when s.teamId is NUll then null" +// + " when s.teamId = p.teamLead then 1" +// + " else 0" +// + " END as IsCrossTeam" + " from timesheet t" + " left join project p on t.projectId = p.id" + " left join staff s on t.staffId = s.id" @@ -4070,6 +4078,9 @@ open class ReportService( // } fun calculateProjectExpenditures(timesheetDataList: List): Map { val otFactor = BigDecimal(1.0) +// For cross Team Calculation +// val crossTeamCharge = BigDecimal(1.15) +// If isCrossTeam is true, normal an ot expenditure will times the cross team charge return timesheetDataList .groupBy { it.projectCode } .mapValues { (_, projectTimesheets) -> @@ -4084,6 +4095,7 @@ open class ReportService( // Update timesheet data with salary effective data, then group by project code, group by staff Id and group by Year Month + // Used for checking data // Data foramt: // "M-0976": { // "184": { @@ -4108,13 +4120,16 @@ open class ReportService( fun sumTimesheetDataByMonth(timesheetDataList: List): Map { return timesheetDataList - .groupBy { it.projectCode } + .groupBy { it.projectCode } // Group timesheet data by project code .mapValues { (_, projectTimesheets) -> - val staffData = projectTimesheets.groupBy { it.staffId } + // Process each project's timesheet data + val staffData = projectTimesheets.groupBy { it.staffId } // Group by staff ID .mapValues { (_, staffTimesheets) -> + // Process each staff member's timesheet data val monthlyData = staffTimesheets.groupBy { timesheet -> - YearMonth.from(timesheet.recordDate) + YearMonth.from(timesheet.recordDate) // Group by month }.mapValues { (_, monthTimesheets) -> + // Calculate monthly summary for each staff member MonthSummary( hourlyRate = monthTimesheets.maxByOrNull { it.recordDate }?.hourlyRate ?: BigDecimal.ZERO, salaryPoint = monthTimesheets.maxByOrNull { it.recordDate }?.salaryPoint ?: 0, 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 0c915be..096fb28 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 @@ -86,7 +86,7 @@ class ReportController( val project = projectRepository.findById(request.projectId).orElseThrow() val projectTasks = projectTaskRepository.findAllByProject(project) // val invoices = invoiceService.findAllByProjectAndPaidAmountIsNotNull(project) - val invoices = invoiceRepository.findAllByProjectCodeAndPaidAmountIsNotNull(project.code!!) + val invoices = invoiceRepository.findAllByProjectCodeAndPaidAmountIsNotNullAndDeletedFalse(project.code!!) val timesheets = timesheetRepository.findAllByProjectTaskIn(projectTasks) val monthlyStaffSalaryEffective = salaryEffectiveService.getMonthlyStaffSalaryData(timesheets.minByOrNull { it.recordDate!! }?.recordDate ?: LocalDate.parse("2012-01-01"), timesheets.maxByOrNull { it.recordDate!! }?.recordDate ?: LocalDate.now())