2. timesheet amendment - staff selection - sort by staffId 3. if the staff is not a teamlead but have authority to edit timesheet amendment, the staff will be not able to view/edit others. 4. update the checking of depart datepull/3/head
@@ -9,7 +9,7 @@ import org.springframework.data.repository.query.Param; | |||||
import com.ffii.core.support.AbstractRepository; | import com.ffii.core.support.AbstractRepository; | ||||
public interface CustomerRepository extends AbstractRepository<Customer, Long> { | public interface CustomerRepository extends AbstractRepository<Customer, Long> { | ||||
List<Customer> findAllByDeletedFalse(); | |||||
List<Customer> findAllByDeletedFalseOrderByNameAsc(); | |||||
Optional<Customer> findByCode(@Param("code") String code); | Optional<Customer> findByCode(@Param("code") String code); | ||||
Optional<Customer> findByName(@Param("name") String name); | Optional<Customer> findByName(@Param("name") String name); | ||||
@@ -28,6 +28,8 @@ public interface StaffRepository extends AbstractRepository<Staff, Long> { | |||||
Optional<List<Staff>> findAllByDeletedFalse(); | Optional<List<Staff>> findAllByDeletedFalse(); | ||||
Optional<List<Staff>> findAllByIdInAndDeletedFalse(List<Long> id); | |||||
Optional<Staff> findIdAndNameByUserIdAndDeletedFalse(Long id); | Optional<Staff> findIdAndNameByUserIdAndDeletedFalse(Long id); | ||||
} | } |
@@ -8,7 +8,7 @@ import java.util.List; | |||||
import java.util.Optional; | import java.util.Optional; | ||||
public interface SubsidiaryRepository extends AbstractRepository<Subsidiary, Long> { | public interface SubsidiaryRepository extends AbstractRepository<Subsidiary, Long> { | ||||
List<Subsidiary> findAllByDeletedFalse(); | |||||
List<Subsidiary> findAllByDeletedFalseOrderByNameAsc(); | |||||
List<Subsidiary> findAllByDeletedFalseAndIdIn(List<Long> id); | List<Subsidiary> findAllByDeletedFalseAndIdIn(List<Long> id); | ||||
@@ -23,7 +23,7 @@ open class CustomerService( | |||||
) : AbstractBaseEntityService<Customer, Long, CustomerRepository>(jdbcDao, customerRepository){ | ) : AbstractBaseEntityService<Customer, Long, CustomerRepository>(jdbcDao, customerRepository){ | ||||
open fun allCustomers(): List<Customer> { | open fun allCustomers(): List<Customer> { | ||||
return customerRepository.findAllByDeletedFalse() | |||||
return customerRepository.findAllByDeletedFalseOrderByNameAsc() | |||||
} | } | ||||
open fun allCustomerTypes(): List<CustomerType> { | open fun allCustomerTypes(): List<CustomerType> { | ||||
@@ -97,8 +97,13 @@ open class StaffsService( | |||||
} | } | ||||
open fun findAll(): Optional<List<Staff>> { | open fun findAll(): Optional<List<Staff>> { | ||||
return staffRepository.findAllByDeletedFalse() | |||||
return staffRepository.findAllByDeletedFalse(); | |||||
} | } | ||||
open fun findAllByIdIn(ids: List<Long>): Optional<List<Staff>> { | |||||
return staffRepository.findAllByIdInAndDeletedFalse(ids); | |||||
} | |||||
open fun getStaff(args: Map<String, Any>): Optional<MutableMap<String, Any>>? { | open fun getStaff(args: Map<String, Any>): Optional<MutableMap<String, Any>>? { | ||||
val sql = StringBuilder("select" | val sql = StringBuilder("select" | ||||
+ " s.id as id," | + " s.id as id," | ||||
@@ -23,7 +23,7 @@ open class SubsidiaryService( | |||||
private val subsidiaryContactService: SubsidiaryContactService, | private val subsidiaryContactService: SubsidiaryContactService, | ||||
) : AbstractBaseEntityService<Subsidiary, Long, SubsidiaryRepository>(jdbcDao, subsidiaryRepository) { | ) : AbstractBaseEntityService<Subsidiary, Long, SubsidiaryRepository>(jdbcDao, subsidiaryRepository) { | ||||
open fun allSubsidiaries(): List<Subsidiary> { | open fun allSubsidiaries(): List<Subsidiary> { | ||||
return subsidiaryRepository.findAllByDeletedFalse() | |||||
return subsidiaryRepository.findAllByDeletedFalseOrderByNameAsc() | |||||
} | } | ||||
open fun allSubsidiaryTypes(): List<SubsidiaryType> { | open fun allSubsidiaryTypes(): List<SubsidiaryType> { | ||||
@@ -129,29 +129,37 @@ open class TimesheetsService( | |||||
open fun getTeamMemberTimesheet(): Map<Long, TeamMemberTimeEntries> { | open fun getTeamMemberTimesheet(): Map<Long, TeamMemberTimeEntries> { | ||||
val authorities = staffsService.currentAuthorities() ?: return emptyMap() | 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() | val currentStaff = staffsService.currentStaff() | ||||
// Get team where current staff is team lead | |||||
val myTeam = if (currentStaff != null) teamService.getMyTeamForStaff(currentStaff) else null | |||||
val teamMembers = if (myTeam != null) { | |||||
staffsService.findAllByTeamId(myTeam.id!!).getOrDefault(emptyList()) | |||||
} else { | |||||
staffsService.findAll().getOrDefault(emptyList()) | |||||
} | |||||
if (currentStaff != null) { | |||||
val isTeamLead = currentStaff.team.staff.id?.equals(currentStaff.id) | |||||
// Get team where current staff is team lead | |||||
val myTeam = teamService.getMyTeamForStaff(currentStaff) | |||||
val teamMembers = if (myTeam != null && isTeamLead == true) { | |||||
staffsService.findAllByTeamId(myTeam.id!!).getOrDefault(emptyList()) | |||||
} else if (isTeamLead != true) { | |||||
staffsService.findAllByIdIn(listOf(currentStaff.id!!)).getOrDefault(emptyList()) | |||||
} else { | |||||
staffsService.findAll().getOrDefault(emptyList()) | |||||
} | |||||
return teamMembers.filter { it.departDate == null }.associate { member -> | |||||
Pair( | |||||
member.id!!, | |||||
TeamMemberTimeEntries( | |||||
staffId = member.staffId, | |||||
name = member.name, | |||||
timeEntries = transformToTimeEntryMap(timesheetRepository.findAllByStaff(member)), | |||||
employType = member.employType | |||||
return teamMembers.filter { it.departDate == null || it.departDate > LocalDate.now() }.sortedBy { it.staffId }.associate { member -> | |||||
Pair( | |||||
member.id!!, | |||||
TeamMemberTimeEntries( | |||||
staffId = member.staffId, | |||||
name = member.name, | |||||
timeEntries = transformToTimeEntryMap(timesheetRepository.findAllByStaff(member)), | |||||
employType = member.employType | |||||
) | |||||
) | ) | ||||
) | |||||
} | |||||
} | } | ||||
} else return emptyMap() | |||||
} | |||||
return emptyMap() | |||||
} | } | ||||
private fun transformToTimeEntryMap(timesheets: List<Timesheet>): Map<String, List<TimeEntry>> { | private fun transformToTimeEntryMap(timesheets: List<Timesheet>): Map<String, List<TimeEntry>> { | ||||