|
5 | 5 | The actual number of vacation days requested is zero. Please note that the selected days may include weekends or |
6 | 6 | public holidays. |
7 | 7 | </p> |
| 8 | + <p v-else-if="leaveReason?.reason == 'excuse'"> |
| 9 | + The vacation request submitted is for a total of 1 excuse. </p> |
8 | 10 | <p v-else> |
9 | 11 | The vacation request submitted is for a total of {{ vacationDays.state.value }} |
10 | 12 | {{ vacationDays.state.value <= 1 ? 'day' : 'days' }}. </p> |
|
47 | 49 |
|
48 | 50 | <div class="mt-3"> |
49 | 51 | <v-text-field ref="excuseStartField" item-color="info" base-color="info" color="info" variant="outlined" |
50 | | - label="Vacation Start Time" v-model="excuseStart" hide-details="auto" type="time" :rules="[validateTimes]" |
51 | | - :readonly="startDate !== endDate"> |
| 52 | + label="Vacation Start Time" v-model="excuseStart" hide-details="auto" type="time" |
| 53 | + :rules="[validateTimes, validateLeave,]" :readonly="startDate !== endDate"> |
52 | 54 | </v-text-field> |
53 | 55 | </div> |
54 | 56 |
|
55 | 57 | <div class="mt-3"> |
56 | 58 | <v-text-field ref="excuseEndField" item-color="info" base-color="info" color="info" variant="outlined" |
57 | | - label="Vacation End Time" v-model="excuseEnd" hide-details="auto" type="time" :rules="[validateTimes]" |
58 | | - :readonly="startDate !== endDate"> |
| 59 | + label="Vacation End Time" v-model="excuseEnd" hide-details="auto" type="time" |
| 60 | + :rules="[validateTimes, validateLeave,]" :readonly="startDate !== endDate"> |
59 | 61 | </v-text-field> |
60 | 62 | </div> |
61 | 63 | <v-row class="mt-3 pa-4 d-flex justify-end"> |
@@ -222,6 +224,27 @@ export default { |
222 | 224 | return true |
223 | 225 | } |
224 | 226 |
|
| 227 | + watch(leaveReason, () => { |
| 228 | + excuseStartField.value?.validate() |
| 229 | + excuseEndField.value?.validate() |
| 230 | + }) |
| 231 | + const validateLeave = (): string | boolean => { |
| 232 | + let endHour = Number(excuseEnd.value.split(':')[0]) |
| 233 | + let startHour = Number(excuseStart.value.split(':')[0]) |
| 234 | +
|
| 235 | + let endMinute = Number(excuseEnd.value.split(':')[1]) |
| 236 | + let startMinute = Number(excuseStart.value.split(':')[1]) |
| 237 | +
|
| 238 | + let diff = (endHour - startHour) * 60 + (endMinute - startMinute) |
| 239 | + |
| 240 | + if (leaveReason.value && leaveReason.value.reason === 'excuse') { |
| 241 | + if (diff > 120) return 'Excuse time cannot exceed 2 hours in a day.' |
| 242 | + } else { |
| 243 | + if (diff < 180) return 'Vacation duration cannot be less than 0.5 days.' |
| 244 | + } |
| 245 | + return true |
| 246 | + } |
| 247 | +
|
225 | 248 |
|
226 | 249 | onMounted(async () => { |
227 | 250 | startDateField.value.validate() |
@@ -301,6 +324,7 @@ export default { |
301 | 324 | createLeave, |
302 | 325 | validateDates, |
303 | 326 | validateTimes, |
| 327 | + validateLeave, |
304 | 328 | useOldBalance, |
305 | 329 | balance, |
306 | 330 | couldApplyUsingOldBalance, |
|
0 commit comments