| @@ -194,28 +194,21 @@ open class TimesheetsService( | |||||
| val row = sheet.getRow(i) | val row = sheet.getRow(i) | ||||
| // Necessary Cell Value | // Necessary Cell Value | ||||
| val mtsid = row.getCell(0).numericCellValue.toInt() | |||||
| val staffId = row.getCell(1).stringCellValue | |||||
| var projectCode = when (row.getCell(4).stringCellValue.isNullOrBlank()) { | |||||
| val staffId = when (row.getCell(1) == null || row.getCell(1).stringCellValue.isNullOrBlank()) { | |||||
| true -> "" | true -> "" | ||||
| false -> StringBuilder(row.getCell(4).stringCellValue).insert(1, '-').toString() | |||||
| } | |||||
| val projectSubCode = when (row.getCell(5)?.cellType) { | |||||
| CellType.STRING -> row.getCell(5).stringCellValue.padStart(3, '0') | |||||
| CellType.NUMERIC -> row.getCell(5).numericCellValue.toString().padStart(3, '0') | |||||
| else -> "" | |||||
| false -> row.getCell(1).stringCellValue | |||||
| } | } | ||||
| val recordDate = when (row.getCell(7).toString().isBlank()) { | |||||
| true -> null | |||||
| false -> LocalDate.parse(row.getCell(7).toString(), formatter); | |||||
| var projectCode = when (row.getCell(4) == null || row.getCell(4).stringCellValue.isNullOrBlank()) { | |||||
| true -> "" | |||||
| false -> StringBuilder(row.getCell(4).stringCellValue).insert(1, '-').toString() | |||||
| } | } | ||||
| val hours: Double = row.getCell(8).numericCellValue | |||||
| // Start Process | // Start Process | ||||
| if (!staffId.isNullOrBlank() && projectCode.isNotBlank()) { | if (!staffId.isNullOrBlank() && projectCode.isNotBlank()) { | ||||
| logger.info("row :$i | lastCellNum" + row.lastCellNum) | logger.info("row :$i | lastCellNum" + row.lastCellNum) | ||||
| // process staff | // process staff | ||||
| val mtsid = row.getCell(0).numericCellValue.toInt() | |||||
| logger.info("---------staff-------") | logger.info("---------staff-------") | ||||
| logger.info("mtsid: $mtsid") | logger.info("mtsid: $mtsid") | ||||
| logger.info("Staff ID: $staffId") | logger.info("Staff ID: $staffId") | ||||
| @@ -230,7 +223,11 @@ open class TimesheetsService( | |||||
| // process project | // process project | ||||
| logger.info("---------project-------") | logger.info("---------project-------") | ||||
| val projectSubCode = when (row.getCell(5)?.cellType) { | |||||
| CellType.STRING -> row.getCell(5).stringCellValue.padStart(3, '0') | |||||
| CellType.NUMERIC -> row.getCell(5).numericCellValue.toInt().toString().padStart(3, '0') | |||||
| else -> "" | |||||
| } | |||||
| if (projectSubCode.isNotBlank()) { | if (projectSubCode.isNotBlank()) { | ||||
| val splitMainProjectCode = projectCode.split('-') | val splitMainProjectCode = projectCode.split('-') | ||||
| projectCode = splitMainProjectCode[0] + '-' + String.format( | projectCode = splitMainProjectCode[0] + '-' + String.format( | ||||
| @@ -247,16 +244,21 @@ open class TimesheetsService( | |||||
| // process project task | // process project task | ||||
| logger.info("---------project task-------") | logger.info("---------project task-------") | ||||
| val task = taskRepository.findById(41).getOrNull() | |||||
| val task = taskRepository.findById(42).getOrNull() | |||||
| val projectTask = | val projectTask = | ||||
| project?.let { p -> task?.let { t -> projectTaskRepository.findByProjectAndTask(p, t) } } | project?.let { p -> task?.let { t -> projectTaskRepository.findByProjectAndTask(p, t) } } | ||||
| // process record date | // process record date | ||||
| logger.info("---------record date-------") | logger.info("---------record date-------") | ||||
| val recordDate = when (row.getCell(7).toString().isBlank()) { | |||||
| true -> null | |||||
| false -> LocalDate.parse(row.getCell(7).toString(), formatter); | |||||
| } | |||||
| logger.info("Recode Date: $recordDate") | logger.info("Recode Date: $recordDate") | ||||
| // normal hour + ot hour | // normal hour + ot hour | ||||
| logger.info("---------normal hour + ot hour-------") | logger.info("---------normal hour + ot hour-------") | ||||
| val hours: Double = row.getCell(8).numericCellValue | |||||
| val normalHours = if (hours > 8.0) 8.0 else hours | val normalHours = if (hours > 8.0) 8.0 else hours | ||||
| val otHours = if (hours > 8.0) hours - 8.0 else 0.0 | val otHours = if (hours > 8.0) hours - 8.0 else 0.0 | ||||
| logger.info("Normal Hours: $normalHours | OT Hours: $otHours") | logger.info("Normal Hours: $normalHours | OT Hours: $otHours") | ||||
| @@ -317,19 +319,17 @@ open class TimesheetsService( | |||||
| for (i in 1..<sheet.lastRowNum) { | for (i in 1..<sheet.lastRowNum) { | ||||
| val row = sheet.getRow(i) | val row = sheet.getRow(i) | ||||
| val mtsid = row.getCell(0).numericCellValue.toInt() | |||||
| val staffId = row.getCell(1).stringCellValue | |||||
| val recordDate = when (row.getCell(7).toString().isBlank()) { | |||||
| true -> null | |||||
| false -> LocalDate.parse(row.getCell(7).toString(), formatter); | |||||
| val staffId = when (row.getCell(1) == null || row.getCell(1).stringCellValue.isNullOrBlank()) { | |||||
| true -> "" | |||||
| false -> row.getCell(1).stringCellValue | |||||
| } | } | ||||
| val hours: Double = row.getCell(8).numericCellValue | |||||
| if (!staffId.isNullOrBlank()) { | if (!staffId.isNullOrBlank()) { | ||||
| logger.info("row :$i | lastCellNum" + row.lastCellNum) | logger.info("row :$i | lastCellNum" + row.lastCellNum) | ||||
| // process staff | // process staff | ||||
| logger.info("---------staff-------") | logger.info("---------staff-------") | ||||
| val mtsid = row.getCell(0).numericCellValue.toInt() | |||||
| var staff = staffRepository.findByStaffId(staffId).getOrNull() | var staff = staffRepository.findByStaffId(staffId).getOrNull() | ||||
| if (staff == null) { | if (staff == null) { | ||||
| staff = staffRepository.findByStaffId("B000").orElseThrow() | staff = staffRepository.findByStaffId("B000").orElseThrow() | ||||
| @@ -352,9 +352,15 @@ open class TimesheetsService( | |||||
| // process record date | // process record date | ||||
| logger.info("---------record date-------") | logger.info("---------record date-------") | ||||
| val recordDate = when (row.getCell(7).toString().isBlank()) { | |||||
| true -> null | |||||
| false -> LocalDate.parse(row.getCell(7).toString(), formatter); | |||||
| } | |||||
| logger.info("Recode Date: $recordDate") | |||||
| // normal hour + ot hour | // normal hour + ot hour | ||||
| logger.info("---------normal hour + ot hour-------") | logger.info("---------normal hour + ot hour-------") | ||||
| val hours: Double = row.getCell(8).numericCellValue | |||||
| val normalHours = if (hours > 8.0) 8.0 else hours | val normalHours = if (hours > 8.0) 8.0 else hours | ||||
| val otHours = if (hours > 8.0) hours - 8.0 else 0.0 | val otHours = if (hours > 8.0) hours - 8.0 else 0.0 | ||||