From ce5c21f4fa893e834f08a20b481a81fa7bb8fa3d Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 3 Feb 2025 16:20:16 +0100 Subject: [PATCH 1/2] fix: refs #8370 change param rely on month --- src/pages/Worker/Card/WorkerTimeControl.vue | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/pages/Worker/Card/WorkerTimeControl.vue b/src/pages/Worker/Card/WorkerTimeControl.vue index c580e5202..d181c70af 100644 --- a/src/pages/Worker/Card/WorkerTimeControl.vue +++ b/src/pages/Worker/Card/WorkerTimeControl.vue @@ -345,17 +345,35 @@ const getMailStates = async (date) => { const url = `WorkerTimeControls/${route.params.id}/getMailStates`; const month = date.getMonth() + 1; const prevMonth = month == 1 ? 12 : month - 1; + const postMonth = month == 12 ? 1 : month + 1; const params = { month, year: date.getFullYear(), }; const curMonthStates = (await axios.get(url, { params })).data; + + if (prevMonth == 12) { + params.year = params.year - 1; + } const prevMonthStates = ( await axios.get(url, { params: { ...params, month: prevMonth } }) ).data; - workerTimeControlMails.value = curMonthStates.concat(prevMonthStates); + if (postMonth == 1) { + params.year = date.getFullYear() + 1; + } + + const postMonthStates = ( + await axios.get(url, { + params: { ...params, month: postMonth }, + }) + ).data; + + workerTimeControlMails.value = curMonthStates.concat( + prevMonthStates, + postMonthStates + ); }; const showWorkerTimeForm = (propValue, formType) => { From 4e5a698e943650e613a7d3210c8814297db7da4b Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 4 Mar 2025 11:21:42 +0100 Subject: [PATCH 2/2] refactor: refs #8370 modified function to get the correct date --- src/pages/Worker/Card/WorkerTimeControl.vue | 56 +++++++++------------ 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/src/pages/Worker/Card/WorkerTimeControl.vue b/src/pages/Worker/Card/WorkerTimeControl.vue index d181c70af..989fd602e 100644 --- a/src/pages/Worker/Card/WorkerTimeControl.vue +++ b/src/pages/Worker/Card/WorkerTimeControl.vue @@ -69,12 +69,12 @@ const acl = useAcl(); const selectedDateYear = computed(() => moment(selectedDate.value).isoWeekYear()); const worker = computed(() => arrayData.store?.data); const canSend = computed(() => - acl.hasAny([{ model: 'WorkerTimeControl', props: 'sendMail', accessType: 'WRITE' }]) + acl.hasAny([{ model: 'WorkerTimeControl', props: 'sendMail', accessType: 'WRITE' }]), ); const canUpdate = computed(() => acl.hasAny([ { model: 'WorkerTimeControl', props: 'updateMailState', accessType: 'WRITE' }, - ]) + ]), ); const isHimself = computed(() => user.value.id === Number(route.params.id)); @@ -100,7 +100,7 @@ const getHeaderFormattedDate = (date) => { }; const formattedWeekTotalHours = computed(() => - secondsToHoursMinutes(weekTotalHours.value) + secondsToHoursMinutes(weekTotalHours.value), ); const onInputChange = async (date) => { @@ -320,7 +320,7 @@ const getFinishTime = () => { today.setHours(0, 0, 0, 0); let todayInWeek = weekDays.value.find( - (day) => day.dated.getTime() === today.getTime() + (day) => day.dated.getTime() === today.getTime(), ); if (todayInWeek && todayInWeek.hours && todayInWeek.hours.length) { @@ -343,37 +343,29 @@ const updateData = async () => { const getMailStates = async (date) => { const url = `WorkerTimeControls/${route.params.id}/getMailStates`; + const year = date.getFullYear(); const month = date.getMonth() + 1; - const prevMonth = month == 1 ? 12 : month - 1; - const postMonth = month == 12 ? 1 : month + 1; - const params = { - month, - year: date.getFullYear(), + + const getMonthStates = async (month, year) => { + return (await axios.get(url, { params: { month, year } })).data; }; - const curMonthStates = (await axios.get(url, { params })).data; + const curMonthStates = await getMonthStates(month, year); - if (prevMonth == 12) { - params.year = params.year - 1; - } - const prevMonthStates = ( - await axios.get(url, { params: { ...params, month: prevMonth } }) - ).data; - - if (postMonth == 1) { - params.year = date.getFullYear() + 1; - } - - const postMonthStates = ( - await axios.get(url, { - params: { ...params, month: postMonth }, - }) - ).data; - - workerTimeControlMails.value = curMonthStates.concat( - prevMonthStates, - postMonthStates + const prevMonthStates = await getMonthStates( + month === 1 ? 12 : month - 1, + month === 1 ? year - 1 : year, ); + + const postMonthStates = await getMonthStates( + month === 12 ? 1 : month + 1, + month === 12 ? year + 1 : year, + ); + workerTimeControlMails.value = [ + ...curMonthStates, + ...prevMonthStates, + ...postMonthStates, + ]; }; const showWorkerTimeForm = (propValue, formType) => { @@ -490,7 +482,7 @@ onMounted(async () => { openConfirmationModal( t('Send time control email'), t('Are you sure you want to send it?'), - resendEmail + resendEmail, ) " > @@ -579,7 +571,7 @@ onMounted(async () => { @show-worker-time-form=" showWorkerTimeForm( { id: hour.id, entryCode: hour.direction }, - 'edit' + 'edit', ) " class="hour-chip"