From 4b6038d1d2db4c90b141f4ce50b6c9ffb3a06660 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Sat, 6 Apr 2024 14:10:08 -0300 Subject: [PATCH] Last changes --- src/pages/Worker/Card/WorkerCalendar.vue | 42 ++++++--- .../Worker/Card/WorkerCalendarFilter.vue | 93 +++++++++++-------- src/pages/Worker/Card/WorkerCalendarItem.vue | 78 ++++++++++++---- src/pages/Worker/Card/WorkerDateLabel.vue | 3 +- 4 files changed, 147 insertions(+), 69 deletions(-) diff --git a/src/pages/Worker/Card/WorkerCalendar.vue b/src/pages/Worker/Card/WorkerCalendar.vue index 379ba334f..06cb69f5c 100644 --- a/src/pages/Worker/Card/WorkerCalendar.vue +++ b/src/pages/Worker/Card/WorkerCalendar.vue @@ -23,7 +23,8 @@ const businessFk = ref(null); const year = ref(Date.vnNew().getFullYear()); const contractHolidays = ref(null); const yearHolidays = ref(null); -const events = ref({}); +const eventsMap = ref({}); +const festiveEventsMap = ref({}); const onFetchActiveContract = (data) => { if (!data) return; @@ -31,21 +32,27 @@ const onFetchActiveContract = (data) => { hasWorkCenter.value = Boolean(data?.workCenterFk); }; -const addEvent = (day, newEvent) => { +const addEvent = (day, newEvent, isFestive = false) => { const timestamp = new Date(day).getTime(); - let event = events.value[timestamp]; + let event = eventsMap.value[timestamp]; - if (event) { + if (!event) { + eventsMap.value[timestamp] = newEvent; + if (isFestive) + festiveEventsMap.value[timestamp] = JSON.parse(JSON.stringify(newEvent)); + } else { const oldName = event.name; + const oldEventWasFestive = event.isFestive; Object.assign(event, newEvent); + event.isFestive = oldEventWasFestive; event.name = `${oldName}, ${event.name}`; - } else events.value[timestamp] = newEvent; + } }; const onFetchAbsences = (data) => { if (!data) return; - events.value = {}; + eventsMap.value = {}; if (data.holidays) { data.holidays.forEach((holiday) => { @@ -53,10 +60,14 @@ const onFetchAbsences = (data) => { const holidayType = holiday.type && holiday.type.name; const holidayName = holidayDetail || holidayType; - addEvent(holiday.dated, { - name: holidayName, - className: 'festive', - }); + addEvent( + holiday.dated, + { + name: holidayName, + isFestive: true, + }, + true + ); }); } if (data.absences) { @@ -67,10 +78,10 @@ const onFetchAbsences = (data) => { color: type.rgb, type: type.code, absenceId: absence.id, + isFestive: false, }); }); } - console.log('events:: ', events.value); }; const getAbsences = async () => { @@ -120,7 +131,10 @@ const refreshData = () => { }; const onDeletedEvent = (timestamp) => { - delete events.value[timestamp]; + delete eventsMap.value[timestamp]; + // Si el evento que eliminamos se encontraba dentro de un dia festivo, volvemos a agregar el evento festivo + if (festiveEventsMap.value[timestamp]) + eventsMap.value[timestamp] = festiveEventsMap.value[timestamp]; }; watch([year, businessFk], () => refreshData()); @@ -161,6 +175,8 @@ watch([year, businessFk], () => refreshData()); v-model:business-fk="businessFk" v-model:year="year" v-model:absence-type="absenceType" + :contract-holidays="contractHolidays" + :year-holidays="yearHolidays" /> @@ -195,7 +211,7 @@ watch([year, businessFk], () => refreshData()); :month="month" :absence-type="absenceType" :business-fk="businessFk" - :events="events" + :events="eventsMap" @refresh="refreshData" @on-deleted-event="onDeletedEvent" /> diff --git a/src/pages/Worker/Card/WorkerCalendarFilter.vue b/src/pages/Worker/Card/WorkerCalendarFilter.vue index c3fe65e19..db6b803d2 100644 --- a/src/pages/Worker/Card/WorkerCalendarFilter.vue +++ b/src/pages/Worker/Card/WorkerCalendarFilter.vue @@ -20,7 +20,15 @@ const props = defineProps({ default: null, }, absenceType: { - type: Number, + type: Object, + default: null, + }, + contractHolidays: { + type: Object, + default: null, + }, + yearHolidays: { + type: Object, default: null, }, }); @@ -29,10 +37,7 @@ const emit = defineEmits(['update:businessFk', 'update:year', 'update:absenceTyp const selectedBusinessFk = computed({ get: () => props.businessFk, - set: (value) => { - console.log('businessFk', value); - emit('update:businessFk', value); - }, + set: (value) => emit('update:businessFk', value), }); const selectedYear = computed({ @@ -76,42 +81,61 @@ const yearList = ref(generateYears()); @on-fetch="(data) => (contractList = data)" auto-load /> - - -

+ +

+ + {{ t('Contract') }} #{{ selectedBusinessFk }} -

-
+ + + + {{ t('Used') }} {{ contractHolidays.holidaysEnjoyed || 0 }} {{ t('of') }} {{ contractHolidays.totalHolidays || 0 }} {{ t('days') }} -
-
+ + + + {{ t('Spent') }} {{ contractHolidays.hoursEnjoyed || 0 }} {{ t('of') }} {{ contractHolidays.totalHours || 0 }} {{ t('hours') }} -
-
+ + + + {{ t('Paid holidays') }} {{ contractHolidays.payedHolidays || 0 }} {{ t('days') }} -
- - - - - -

{{ t('Year') }} {{ selectedYear }}

-
+ + +
+
+ + + {{ t('Year') }} {{ selectedYear }} + + + + {{ t('Used') }} {{ yearHolidays.holidaysEnjoyed || 0 }} {{ t('of') }} {{ yearHolidays.totalHolidays || 0 }} {{ t('days') }} -
-
+ + + + {{ t('Spent') }} {{ yearHolidays.hoursEnjoyed || 0 }} {{ t('of') }} {{ yearHolidays.totalHours || 0 }} {{ t('hours') }} -
-
-
- +
+
+
@@ -172,17 +196,18 @@ const yearList = ref(generateYears()); - + - Festive + {{ t('Festive') }} - Current day + {{ t('Current day') }} + - es: diff --git a/src/pages/Worker/Card/WorkerCalendarItem.vue b/src/pages/Worker/Card/WorkerCalendarItem.vue index 92fd3f47b..cac455822 100644 --- a/src/pages/Worker/Card/WorkerCalendarItem.vue +++ b/src/pages/Worker/Card/WorkerCalendarItem.vue @@ -1,5 +1,5 @@ @@ -173,16 +197,20 @@ watch(props.year, (newValue) => { > @@ -190,6 +218,11 @@ watch(props.year, (newValue) => {