diff --git a/src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt b/src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt index 2c2ec8f..e5461d0 100644 --- a/src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt +++ b/src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt @@ -4,16 +4,21 @@ import com.ffii.core.exception.UnprocessableEntityException import com.ffii.core.support.AbstractBaseEntityService import com.ffii.core.support.JdbcDao import com.ffii.tsms.modules.common.SecurityUtils +import com.ffii.tsms.modules.common.SettingNames +import com.ffii.tsms.modules.common.mail.pojo.MailRequest import com.ffii.tsms.modules.data.entity.* import com.ffii.tsms.modules.data.entity.projections.StaffSearchInfo import com.ffii.tsms.modules.data.web.models.NewStaffRequest import com.ffii.tsms.modules.data.web.models.SalaryEffectiveInfo import com.ffii.tsms.modules.user.entity.User import com.ffii.tsms.modules.user.entity.UserRepository +import jakarta.mail.internet.InternetAddress +import org.springframework.scheduling.annotation.Scheduled import org.springframework.security.core.GrantedAuthority import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional +import java.time.LocalDate import java.util.* import kotlin.jvm.optionals.getOrNull @@ -138,6 +143,7 @@ open class StaffsService( name = req.name phone1 = req.phone1 email = req.email ?: null + locked = LocalDate.now().isAfter(req.departDate) } ) @@ -226,6 +232,14 @@ open class StaffsService( this.department = department } + if (req.departDate != null) { + val user = userRepository.findByUsernameAndDeletedFalse(req.staffId).orElseThrow() + user.apply { + locked = LocalDate.now().isAfter(req.departDate) + } + + userRepository.save(user) + } // salaryEffectiveService.saveSalaryEffective(staff.id!!, salary.salaryPoint.toLong()) salaryEffectiveService.updateSalaryEffective(staff.id!!, req.salaryEffectiveInfo?.sortedBy { it.date }, req.delSalaryEffectiveInfo) @@ -267,4 +281,23 @@ open class StaffsService( val latestSalaryPoint = salaryEffectInfo?.maxByOrNull { it.date }?.salaryPoint return latestSalaryPoint } + + @Scheduled(cron = "0 0 0 * * ?") // Runs at 00:00 AM every day + open fun checkDepartStaffs() { + val staffs = staffRepository.findAll() + + val users = mutableListOf() + + staffs.forEach { staff -> + val user = userRepository.findByUsernameAndDeletedFalse(staff.staffId).orElseThrow() + + user.apply { + locked = LocalDate.now().isAfter(staff.departDate) + } + + users += user + } + + userRepository.saveAll(users) + } } \ 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 88ab1ca..ab4fb78 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 @@ -777,7 +777,7 @@ open class ReportService( } createCell(2).apply { - setCellValue((project.expectedTotalFee ?: 0.0) - (project.subContractFee ?: 0.0)) + setCellValue(project.expectedTotalFee ?: 0.0) cellStyle.dataFormat = accountingStyle } } diff --git a/src/main/java/com/ffii/tsms/modules/timesheet/service/TimesheetsService.kt b/src/main/java/com/ffii/tsms/modules/timesheet/service/TimesheetsService.kt index d93c531..b862ab1 100644 --- a/src/main/java/com/ffii/tsms/modules/timesheet/service/TimesheetsService.kt +++ b/src/main/java/com/ffii/tsms/modules/timesheet/service/TimesheetsService.kt @@ -288,7 +288,7 @@ open class TimesheetsService( logger.info("---------project task-------") val projectTask = null - val nonBillableTask = taskRepository.findById(44).orElseThrow() + val nonBillableTask = taskRepository.findById(42).orElseThrow() // process record date logger.info("---------record date-------") val formatter = DateTimeFormatter.ofPattern("dd-MMM-yyyy") diff --git a/src/main/resources/db/changelog/changes/20240814_01_cyril/01_update_timesheet_and_task.sql b/src/main/resources/db/changelog/changes/20240814_01_cyril/01_update_timesheet_and_task.sql new file mode 100644 index 0000000..08b15d0 --- /dev/null +++ b/src/main/resources/db/changelog/changes/20240814_01_cyril/01_update_timesheet_and_task.sql @@ -0,0 +1,24 @@ +-- liquibase formatted sql +-- changeset cyril:timesheet,project_task,task_template_tasks,task + +UPDATE timesheet t, project_task pt1, project_task pt2 +SET t.projectTaskId = pt2.id +WHERE t.projectTaskId = pt1.id and t.projectId = pt2.project_id and pt2.task_id = 44 and (pt1.task_id = 42 or pt1.task_id = 43); + +UPDATE timesheet SET nonBillableTaskId = 42 where nonBillableTaskId in (43, 44); + +DELETE FROM project_task WHERE task_id in (42, 43); + +UPDATE project_task SET task_id = 42 WHERE task_id = 44; + +DELETE FROM task_template_tasks WHERE tasksId in (42, 43); + +UPDATE task_template_tasks SET tasksId = 42 WHERE tasksId = 44; + +DELETE FROM task +WHERE id=43; +DELETE FROM task +WHERE id=44; +UPDATE task +SET name='5.9 Others and remain fast time input' +WHERE id=42; \ No newline at end of file