From 874bfa8c8e63f4f025d25be558be35aa36f5c73b Mon Sep 17 00:00:00 2001 From: "MSI\\2Fi" Date: Fri, 16 Aug 2024 16:40:09 +0800 Subject: [PATCH] Update Pnl, Cost and Expense and Financial Status Report, the time range is the first timesheet entry to today --- .../modules/report/service/ReportService.kt | 33 ++++++++++++------- .../timesheet/entity/TimesheetRepository.kt | 4 +++ 2 files changed, 26 insertions(+), 11 deletions(-) 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 88ab1ca..209a1d4 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 @@ -10,6 +10,7 @@ import com.ffii.tsms.modules.project.entity.Project import com.ffii.tsms.modules.project.entity.ProjectRepository import com.ffii.tsms.modules.report.web.model.costAndExpenseRequest import com.ffii.tsms.modules.timesheet.entity.Timesheet +import com.ffii.tsms.modules.timesheet.entity.TimesheetRepository import org.apache.commons.logging.Log import org.apache.commons.logging.LogFactory import org.apache.poi.ss.usermodel.* @@ -45,7 +46,7 @@ data class DayInfo(val date: String?, val weekday: String?) open class ReportService( private val jdbcDao: JdbcDao, private val projectRepository: ProjectRepository, - private val salaryEffectiveService: SalaryEffectiveService, private val salaryRepository: SalaryRepository + private val salaryEffectiveService: SalaryEffectiveService, private val salaryRepository: SalaryRepository, private val timesheetRepository: TimesheetRepository ) { private val logger: Log = LogFactory.getLog(javaClass) private val DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd") @@ -2304,14 +2305,18 @@ open class ReportService( + " order by g.code, s.name, cte_ts.recordDate" ) val projectPlanStartEndMonth = projectRepository.findProjectPlanStartEndByIdAndDeletedFalse(projectId) + val minStartMonthInTimesheetByProject = timesheetRepository.findMinRecordDateByProjectId(projectId) val compareStartMonth = YearMonth.parse(startMonth) val compareEndMonth = YearMonth.parse(endMonth) val actualStartMonth: YearMonth - (if (projectPlanStartEndMonth.actualStart == null) { + (if (minStartMonthInTimesheetByProject == null) { YearMonth.now().plusMonths(1) } else { - YearMonth.from(projectPlanStartEndMonth.actualStart) - }).also { actualStartMonth = it } + YearMonth.from(minStartMonthInTimesheetByProject) + }).also { + actualStartMonth = it + println("============= Actual Start Month $actualStartMonth ===============") + } val queryStartMonth = if (compareStartMonth.isAfter(actualStartMonth)) compareStartMonth else actualStartMonth val queryEndMonth = if (compareEndMonth.isAfter(YearMonth.now())) YearMonth.now() else compareEndMonth @@ -2495,7 +2500,7 @@ open class ReportService( val previousHourlyRate = findPreviousValue(salaryDataList, financialYear.start) { it.hourlyRate } val previousSalaryPoint = findPreviousValue(salaryDataList, financialYear.start) { it.salaryPoint } - println("====================== staffInfo: $staffInfo ===============================") +// println("====================== staffInfo: $staffInfo ===============================") return financialYear.copy( hourlyRate = previousHourlyRate?.toDouble() ?: (staffInfo["hourlyRate"] as BigDecimal).toDouble(), salaryPoint = previousSalaryPoint ?: (staffInfo["salaryPoint"] as Long).toInt() @@ -2658,14 +2663,18 @@ open class ReportService( val accountingStyle = workbook.createDataFormat().getFormat("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)") val projectPlanStartEndMonth = projectRepository.findProjectPlanStartEndByIdAndDeletedFalse(projectId) + val minStartMonthInTimesheetByProject = timesheetRepository.findMinRecordDateByProjectId(projectId) val compareStartMonth = YearMonth.parse(startMonth) val compareEndMonth = YearMonth.parse(endMonth) val actualStartMonth: YearMonth - (if (projectPlanStartEndMonth.actualStart == null) { + (if (minStartMonthInTimesheetByProject == null) { YearMonth.now().plusMonths(1) } else { - YearMonth.from(projectPlanStartEndMonth.actualStart) - }).also { actualStartMonth = it } + YearMonth.from(minStartMonthInTimesheetByProject) + }).also { + actualStartMonth = it + println("============= Actual Start Month $actualStartMonth ===============") + } val queryStartMonth = if (compareStartMonth.isAfter(actualStartMonth)) compareStartMonth else actualStartMonth val queryEndMonth = if (compareEndMonth.isAfter(YearMonth.now())) YearMonth.now() else compareEndMonth @@ -2676,6 +2685,8 @@ open class ReportService( val endDate = YearMonth.parse(queryEndMonth.toString(), DateTimeFormatter.ofPattern("yyyy-MM")) val convertEndMonth = YearMonth.of(endDate.year, endDate.month) + + val monthRange: MutableList> = ArrayList() val financialYears = getHalfYearFinancialPeriods(queryStartMonth, queryEndMonth, 1) @@ -2913,7 +2924,7 @@ open class ReportService( // Manhour Spent LOOP - println("monthRange--------------- ${monthRange}\n") +// println("monthRange--------------- ${monthRange}\n") rowNum += 1 for (staff in staffInfoList) { val row: Row = sheet.getRow(rowNum) ?: sheet.createRow(rowNum) @@ -3940,8 +3951,8 @@ open class ReportService( if (teamLeadId != null && teamLeadId > 0){ sql.append( "and p.teamLead = :teamLeadId " ) } - sql.append(" ) and t.recordDate >= p.actualStart ") - sql.append(" order by code, recordDate, staffId; ") +// sql.append("and t.recordDate >= p.actualStart ") + sql.append(") order by code, recordDate, staffId; ") val results = jdbcDao.queryForList(sql.toString(), mapOf("teamLeadId" to teamLeadId)).map { diff --git a/src/main/java/com/ffii/tsms/modules/timesheet/entity/TimesheetRepository.kt b/src/main/java/com/ffii/tsms/modules/timesheet/entity/TimesheetRepository.kt index d1ef25e..1ddfe22 100644 --- a/src/main/java/com/ffii/tsms/modules/timesheet/entity/TimesheetRepository.kt +++ b/src/main/java/com/ffii/tsms/modules/timesheet/entity/TimesheetRepository.kt @@ -27,4 +27,8 @@ interface TimesheetRepository : AbstractRepository { fun findByStaffAndRecordDateBetweenOrderByRecordDate(staff: Staff, start: LocalDate, end: LocalDate): List fun findDistinctProjectTaskByStaffAndRecordDateBetweenOrderByRecordDate(staff: Staff, start: LocalDate, end: LocalDate): List + + @Query("SELECT MIN(t.recordDate) AS recordDate FROM Timesheet t WHERE t.project.id = ?1") + fun findMinRecordDateByProjectId(projectId: Long): LocalDate? + } \ No newline at end of file