fix: 연차 저장 및 계산 로직 수정
- calculateUsedAnnualLeave()에서 Seoul 타임존 명시 - FragmentSettingsLab 토스트를 커스텀 토스트로 변경 - 연차 저장 시 남은 연차 자동 계산 로직 개선 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -55,23 +55,23 @@ class FragmentSettingsLab : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupSaveButton() {
|
private fun setupSaveButton() {
|
||||||
binding.btnSaveAnnualLeave.setOnClickListener {
|
binding.btnSaveAnnualLeave.setOnClickListener {
|
||||||
val totalDays = binding.npTotalDays.value.toFloat()
|
val totalDays = binding.npTotalDays.value.toFloat()
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val repo = ShiftRepository(requireContext())
|
val repo = ShiftRepository(requireContext())
|
||||||
|
|
||||||
repo.recalculateAndSaveAnnualLeave(totalDays)
|
repo.recalculateAndSaveAnnualLeave(totalDays)
|
||||||
|
|
||||||
val updated = repo.getAnnualLeave()
|
val updated = repo.getAnnualLeave()
|
||||||
updated?.let {
|
updated?.let {
|
||||||
binding.tvRemainingDays.text = String.format("%.1f", it.remainingDays)
|
binding.tvRemainingDays.text = String.format("%.1f", it.remainingDays)
|
||||||
Toast.makeText(requireContext(), "연차가 저장되었습니다. (남은 연차: ${String.format("%.1f", it.remainingDays)}일)", Toast.LENGTH_SHORT).show()
|
showCustomToast(requireContext(), "연차가 저장되었습니다. (남은 연차: ${String.format("%.1f", it.remainingDays)}일)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
|
|||||||
@@ -58,24 +58,24 @@ class ShiftRepository(private val context: Context) {
|
|||||||
dao.clearCustomAlarms()
|
dao.clearCustomAlarms()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Annual Leave
|
// Annual Leave
|
||||||
suspend fun calculateUsedAnnualLeave(): Float = withContext(Dispatchers.IO) {
|
suspend fun calculateUsedAnnualLeave(): Float = withContext(Dispatchers.IO) {
|
||||||
val currentYear = java.time.Year.now().toString()
|
val currentYear = java.time.Year.now(java.time.ZoneId.of("Asia/Seoul")).toString()
|
||||||
val overrides = dao.getAllOverrides()
|
val overrides = dao.getAllOverrides()
|
||||||
|
|
||||||
var usedDays = 0f
|
var usedDays = 0f
|
||||||
|
|
||||||
for (override in overrides) {
|
for (override in overrides) {
|
||||||
if (override.date.startsWith(currentYear)) {
|
if (override.date.startsWith(currentYear)) {
|
||||||
when (override.shift) {
|
when (override.shift) {
|
||||||
"연차" -> usedDays += 1f
|
"연차" -> usedDays += 1f
|
||||||
"반년" -> usedDays += 0.5f
|
"반년" -> usedDays += 0.5f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
usedDays
|
usedDays
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getAnnualLeave(): AnnualLeave? = withContext(Dispatchers.IO) {
|
suspend fun getAnnualLeave(): AnnualLeave? = withContext(Dispatchers.IO) {
|
||||||
dao.getAnnualLeave()
|
dao.getAnnualLeave()
|
||||||
|
|||||||
Reference in New Issue
Block a user