Просмотр исходного кода

update

tags/Baseline_30082024_BACKEND_UAT
cyril.tsui 1 год назад
Родитель
Сommit
b0eea4b574
4 измененных файлов: 67 добавлений и 45 удалений
  1. +4
    -4
      src/main/java/com/ffii/tsms/modules/project/service/InvoiceService.kt
  2. +3
    -4
      src/main/java/com/ffii/tsms/modules/project/service/ProjectsService.kt
  3. +2
    -2
      src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt
  4. +58
    -35
      src/main/java/com/ffii/tsms/modules/timesheet/service/TimesheetsService.kt

+ 4
- 4
src/main/java/com/ffii/tsms/modules/project/service/InvoiceService.kt Просмотреть файл

@@ -362,7 +362,7 @@ open class InvoiceService(

// Check the import invoice with the data in DB
for (i in 2..sheet.lastRowNum){
val sheetInvoice = ExcelUtils.getCell(sheet, i, 0).stringCellValue
val sheetInvoice = ExcelUtils.getCell(sheet, i, 0).toString()
val sheetProjectCode = ExcelUtils.getCell(sheet, i, 1).stringCellValue
checkInvoiceNo(sheetInvoice, invoices, invoicesResult, true)
checkProjectCode(sheetProjectCode, projects, newProjectCodes)
@@ -398,7 +398,7 @@ open class InvoiceService(
// val paymentMilestoneId = getMilestonePaymentId(ExcelUtils.getCell(sheet, i, 1).stringCellValue, ExcelUtils.getCell(sheet, i, 5).stringCellValue)
// val milestonePayment = milestonePaymentRepository.findById(paymentMilestoneId).orElseThrow()
val invoice = Invoice().apply {
invoiceNo = ExcelUtils.getCell(sheet, i, 0).stringCellValue
invoiceNo = ExcelUtils.getCell(sheet, i, 0).toString()
projectCode = ExcelUtils.getCell(sheet, i, 1).stringCellValue
projectName = ExcelUtils.getCell(sheet, i, 2).stringCellValue
team = ExcelUtils.getCell(sheet, i, 3).stringCellValue
@@ -447,7 +447,7 @@ open class InvoiceService(
val duplicateItemsInInvoice = checkDuplicateItemInImportedInvoice(sheet,2,0)

for (i in 2..sheet.lastRowNum){
val sheetInvoice = ExcelUtils.getCell(sheet, i, 0).stringCellValue
val sheetInvoice = ExcelUtils.getCell(sheet, i, 0).toString()
val sheetProjectCode = ExcelUtils.getCell(sheet, i, 1).stringCellValue
checkInvoiceNo(sheetInvoice, invoices, invoicesResult, false)
checkProjectCode(sheetProjectCode, projects, newProjectCodes)
@@ -489,7 +489,7 @@ open class InvoiceService(
}

for (i in 2..sheet.lastRowNum){
val invoice = getInvoiceByInvoiceNo(ExcelUtils.getCell(sheet, i, 0).stringCellValue)
val invoice = getInvoiceByInvoiceNo(ExcelUtils.getCell(sheet, i, 0).toString())
invoice.paidAmount = ExcelUtils.getCell(sheet, i, 5).numericCellValue.toBigDecimal()
invoice.receiptDate = ExcelUtils.getCell(sheet, i, 4).dateCellValue.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()
saveAndFlush(invoice)


+ 3
- 4
src/main/java/com/ffii/tsms/modules/project/service/ProjectsService.kt Просмотреть файл

@@ -200,11 +200,10 @@ open class ProjectsService(
totalManhour = request.totalManhour
actualStart = request.projectActualStart
actualEnd = request.projectActualEnd
status = request.projectStatus
?: if (this.status == "Deleted" || this.deleted == true) "Deleted"
status = if (this.status == "Deleted" || this.deleted == true) "Deleted"
else if (this.actualStart != null && this.actualEnd != null) "Completed"
else if (this.actualStart != null) "On-going"
else "Pending To Start"
else request.projectStatus ?: "Pending To Start"
isClpProject = request.isClpProject
this.mainProject = mainProject

@@ -526,7 +525,7 @@ open class ProjectsService(
Project().apply {
name = row.getCell(1).stringCellValue
description = row.getCell(1).stringCellValue
code = splitProjectCode[0]
code = splitMainProjectCode[0] + '-' + String.format("%04d", splitMainProjectCode[1].toInt())
status = "Completed"
projectCategory = projectCategoryRepository.findById(1).orElseThrow()
customer = currentClient


+ 2
- 2
src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt Просмотреть файл

@@ -691,12 +691,12 @@ open class ReportService(
rowIndex = 10
sheet.getRow(rowIndex).apply {
createCell(1).apply {
setCellValue(project.expectedTotalFee!! * 0.8)
setCellValue(if (project.expectedTotalFee != null) project.expectedTotalFee!! * 0.8 else 0.0)
cellStyle.dataFormat = accountingStyle
}

createCell(2).apply {
setCellValue(project.expectedTotalFee!!)
setCellValue(project.expectedTotalFee ?: 0.0)
cellStyle.dataFormat = accountingStyle
}
}


+ 58
- 35
src/main/java/com/ffii/tsms/modules/timesheet/service/TimesheetsService.kt Просмотреть файл

@@ -45,14 +45,15 @@ open class TimesheetsService(
mergeTimeEntriesByProjectAndTask(timeEntries).map { timeEntry ->
val task = timeEntry.taskId?.let { taskRepository.findById(it).getOrNull() }
val project = timeEntry.projectId?.let { projectRepository.findById(it).getOrNull() }
val projectTask = project?.let { p -> task?.let { t -> projectTaskRepository.findByProjectAndTask(p, t) } }
val projectTask =
project?.let { p -> task?.let { t -> projectTaskRepository.findByProjectAndTask(p, t) } }

Timesheet().apply {
this.staff = currentStaff
this.recordDate = entryDate
this.normalConsumed = timeEntry.inputHours
this.otConsumed = timeEntry.otHours
this.projectTask = projectTask
this.projectTask = projectTask
this.project = project
this.remark = timeEntry.remark
}
@@ -65,7 +66,11 @@ open class TimesheetsService(
}

@Transactional
open fun saveMemberTimeEntry(staffId: Long, entry: TimeEntry, recordDate: LocalDate?): Map<String, List<TimeEntry>> {
open fun saveMemberTimeEntry(
staffId: Long,
entry: TimeEntry,
recordDate: LocalDate?
): Map<String, List<TimeEntry>> {
val authorities = staffsService.currentAuthorities() ?: throw BadRequestException()

if (!authorities.stream().anyMatch { it.authority.equals("MAINTAIN_TIMESHEET") }) {
@@ -80,11 +85,11 @@ open class TimesheetsService(
val timesheet = timesheetRepository.findById(entry.id).getOrDefault(Timesheet()).apply {
val task = entry.taskId?.let { taskRepository.findById(it).getOrNull() }
val project = entry.projectId?.let { projectRepository.findById(it).getOrNull() }
val projectTask = project?.let { p -> task?.let { t -> projectTaskRepository.findByProjectAndTask(p, t) } }
val projectTask = project?.let { p -> task?.let { t -> projectTaskRepository.findByProjectAndTask(p, t) } }

this.normalConsumed = entry.inputHours
this.otConsumed = entry.otHours
this.projectTask = projectTask
this.projectTask = projectTask
this.project = project
this.remark = entry.remark
this.recordDate = this.recordDate ?: recordDate
@@ -114,7 +119,7 @@ open class TimesheetsService(

open fun getTeamMemberTimesheet(): Map<Long, TeamMemberTimeEntries> {
val authorities = staffsService.currentAuthorities() ?: return emptyMap()
if (authorities.stream().anyMatch { it.authority.equals("MAINTAIN_TIMESHEET")}) {
if (authorities.stream().anyMatch { it.authority.equals("MAINTAIN_TIMESHEET") }) {
val currentStaff = staffsService.currentStaff()
// Get team where current staff is team lead

@@ -141,27 +146,31 @@ open class TimesheetsService(
private fun transformToTimeEntryMap(timesheets: List<Timesheet>): Map<String, List<TimeEntry>> {
return timesheets
.groupBy { timesheet -> timesheet.recordDate!!.format(DateTimeFormatter.ISO_LOCAL_DATE) }
.mapValues { (_, timesheets) -> timesheets.map { timesheet ->
TimeEntry(
id = timesheet.id!!,
projectId = timesheet.projectTask?.project?.id ?: timesheet.project?.id,
taskId = timesheet.projectTask?.task?.id,
taskGroupId = timesheet.projectTask?.task?.taskGroup?.id,
inputHours = timesheet.normalConsumed ?: 0.0,
otHours = timesheet.otConsumed ?: 0.0,
remark = timesheet.remark
)
} }
.mapValues { (_, timesheets) ->
timesheets.map { timesheet ->
TimeEntry(
id = timesheet.id!!,
projectId = timesheet.projectTask?.project?.id ?: timesheet.project?.id,
taskId = timesheet.projectTask?.task?.id,
taskGroupId = timesheet.projectTask?.task?.taskGroup?.id,
inputHours = timesheet.normalConsumed ?: 0.0,
otHours = timesheet.otConsumed ?: 0.0,
remark = timesheet.remark
)
}
}
}

private fun mergeTimeEntriesByProjectAndTask(entries: List<TimeEntry>): List<TimeEntry> {
return entries
.groupBy { timeEntry -> Pair(timeEntry.projectId, timeEntry.taskId) }
.values.map { timeEntries ->
timeEntries.reduce { acc, timeEntry -> acc.copy(
inputHours = (acc.inputHours ?: 0.0) + (timeEntry.inputHours ?: 0.0),
otHours = (acc.otHours ?: 0.0) + (timeEntry.otHours ?: 0.0)
) }
timeEntries.reduce { acc, timeEntry ->
acc.copy(
inputHours = (acc.inputHours ?: 0.0) + (timeEntry.inputHours ?: 0.0),
otHours = (acc.otHours ?: 0.0) + (timeEntry.otHours ?: 0.0)
)
}
}
}

@@ -173,13 +182,18 @@ open class TimesheetsService(
return "No Excel import" // if workbook is null
}

val notExistProjectList = mutableListOf<String>()
val sheet: Sheet = workbook.getSheetAt(0)

logger.info("---------Start Import Timesheets-------")
val timesheetList = mutableListOf<Timesheet>().toMutableList();
for (i in 1..<sheet.lastRowNum) {
val row = sheet.getRow(i)

if (row?.getCell(0) != null && !row.getCell(0).stringCellValue.isNullOrBlank() && row.getCell(3) != null && !row.getCell(3).stringCellValue.isNullOrBlank()) {
if (row?.getCell(0) != null && !row.getCell(0).stringCellValue.isNullOrBlank() && row.getCell(3) != null && !row.getCell(
3
).stringCellValue.isNullOrBlank()
) {
logger.info("row :$i | lastCellNum" + row.lastCellNum)

// process staff
@@ -193,10 +207,13 @@ open class TimesheetsService(
logger.info("---------project-------")
var projectCode = StringBuilder(row.getCell(3).stringCellValue).insert(1, '-').toString()

if (projectCode.contains('(')) {
val splitProjectCode = projectCode.split('(')
val splitMainProjectCode = splitProjectCode[0].split('-')
projectCode = splitMainProjectCode[0] + '-' + String.format("%04d", splitMainProjectCode[1].toInt()) + '-' + String.format("%03d", splitProjectCode[1].split(')')[0].toInt())
if (row.getCell(4) != null && row.getCell(4).toString().isNotBlank()) {
val subCode = row.getCell(4).numericCellValue
val splitMainProjectCode = projectCode.split('-')
projectCode = splitMainProjectCode[0] + '-' + String.format(
"%04d",
splitMainProjectCode[1].toInt()
) + '-' + String.format("%03d", subCode.toInt())
} else {
val splitProjectCode = projectCode.split('-')
projectCode = splitProjectCode[0] + '-' + String.format("%04d", splitProjectCode[1].toInt())
@@ -208,7 +225,8 @@ open class TimesheetsService(
// process project task
logger.info("---------project task-------")
val task = taskRepository.findById(41).getOrNull()
val projectTask = project?.let { p -> task?.let { t -> projectTaskRepository.findByProjectAndTask(p, t) } }
val projectTask =
project?.let { p -> task?.let { t -> projectTaskRepository.findByProjectAndTask(p, t) } }

// process record date
logger.info("---------record date-------")
@@ -221,20 +239,25 @@ open class TimesheetsService(
val normalHours = if (hours > 8.0) 8.0 else hours
val otHours = if (hours > 8.0) hours - 8.0 else 0.0

timesheetList += Timesheet().apply {
this.staff = staff
this.recordDate = recordDate
this.normalConsumed = normalHours
this.otConsumed = otHours
this.projectTask = projectTask
this.project = project
if (project != null) {
timesheetList += Timesheet().apply {
this.staff = staff
this.recordDate = recordDate
this.normalConsumed = normalHours
this.otConsumed = otHours
this.projectTask = projectTask
this.project = project
}
} else {
notExistProjectList += projectCode
}
}
}

timesheetRepository.saveAll(timesheetList)
logger.info("---------end-------")
logger.info("Not Exist Project List: "+ notExistProjectList.joinToString(", "))

return if (sheet.lastRowNum > 0) "Import Excel success" else "Import Excel failure"
return if (sheet.lastRowNum > 0) "Import Excel success btw " + notExistProjectList.joinToString(", ") else "Import Excel failure"
}
}

Загрузка…
Отмена
Сохранить