diff --git a/src/components/FormPopup.vue b/src/components/FormPopup.vue new file mode 100644 index 000000000..b6eff5d80 --- /dev/null +++ b/src/components/FormPopup.vue @@ -0,0 +1,96 @@ + + + + + diff --git a/src/components/WorkerTimeReasonForm.vue b/src/components/WorkerTimeReasonForm.vue new file mode 100644 index 000000000..2f151dbc8 --- /dev/null +++ b/src/components/WorkerTimeReasonForm.vue @@ -0,0 +1,47 @@ + + + + + +es: + Reason: Motivo + diff --git a/src/i18n/en/index.js b/src/i18n/en/index.js index 558709513..17b042923 100644 --- a/src/i18n/en/index.js +++ b/src/i18n/en/index.js @@ -84,6 +84,7 @@ export default { selectFile: 'Select a file', copyClipboard: 'Copy on clipboard', salesPerson: 'SalesPerson', + send: 'Send', }, errors: { statusUnauthorized: 'Access denied', diff --git a/src/i18n/es/index.js b/src/i18n/es/index.js index 0a81b7ec5..7f46ed3b2 100644 --- a/src/i18n/es/index.js +++ b/src/i18n/es/index.js @@ -84,6 +84,7 @@ export default { selectFile: 'Seleccione un fichero', copyClipboard: 'Copiar en portapapeles', salesPerson: 'Comercial', + send: 'Enviar', }, errors: { statusUnauthorized: 'Acceso denegado', diff --git a/src/pages/Worker/Card/WorkerTimeControl.vue b/src/pages/Worker/Card/WorkerTimeControl.vue index e5eaba648..894f6ccc6 100644 --- a/src/pages/Worker/Card/WorkerTimeControl.vue +++ b/src/pages/Worker/Card/WorkerTimeControl.vue @@ -6,6 +6,7 @@ import { onMounted, ref, computed, onBeforeMount, nextTick, reactive } from 'vue import FetchData from 'components/FetchData.vue'; import WorkerTimeHourChip from 'components/WorkerTimeHourChip.vue'; import WorkerTimeForm from 'components/WorkerTimeForm.vue'; +import WorkerTimeReasonForm from 'components/WorkerTimeReasonForm.vue'; import useNotify from 'src/composables/useNotify.js'; import axios from 'axios'; @@ -14,6 +15,8 @@ import { useWeekdayStore } from 'src/stores/useWeekdayStore'; import { useStateStore } from 'stores/useStateStore'; import { useState } from 'src/composables/useState'; import { dashIfEmpty } from 'src/filters'; +import { useVnConfirm } from 'composables/useVnConfirm'; +import { useArrayData } from 'composables/useArrayData'; const route = useRoute(); const { t } = useI18n(); @@ -24,26 +27,10 @@ const user = _state.getUser(); const stateStore = useStateStore(); const weekdayStore = useWeekdayStore(); const weekDays = ref([]); - -const isHr = computed(() => hasAny(['hr'])); - -const isHimSelf = computed(() => user.value.id === route.params.id); - -const columns = computed(() => { - return weekdayStore.localeWeekdays?.map((day, index) => { - const obj = { - label: day.locale, - formattedDate: getHeaderFormattedDate(weekDays.value[index]?.dated), - name: day.name, - align: 'left', - colIndex: index, - dayData: weekDays.value[index], - }; - return obj; - }); -}); +const { openConfirmationModal } = useVnConfirm(); const workerTimeFormDialogRef = ref(null); +const workerTimeReasonFormDialogRef = ref(null); const workerHoursRef = ref(null); const calendarRef = ref(null); const selectedDate = ref(null); @@ -62,7 +49,27 @@ const workerTimeFormProps = reactive({ formType: null, }); -onMounted(() => setDate(Date.vnNew())); +const arrayData = useArrayData('workerData'); + +const worker = computed(() => arrayData.store?.data); + +const isHr = computed(() => hasAny(['hr'])); + +const isHimSelf = computed(() => user.value.id === route.params.id); + +const columns = computed(() => { + return weekdayStore.localeWeekdays?.map((day, index) => { + const obj = { + label: day.locale, + formattedDate: getHeaderFormattedDate(weekDays.value[index]?.dated), + name: day.name, + align: 'left', + colIndex: index, + dayData: weekDays.value[index], + }; + return obj; + }); +}); const getHeaderFormattedDate = (date) => { //TODO:: Ver si se puede hacer una funcion reutilizable o complementar a utils de dates @@ -307,7 +314,7 @@ const fetchWeekData = async () => { } else { const [mail] = data; state.value = mail.state; - reason.value.value = mail.reason; + reason.value = mail.reason; } await canBeResend(); @@ -403,13 +410,67 @@ const showWorkerTimeForm = (propValue, formType) => { workerTimeFormDialogRef.value.show(); }; +const showReasonForm = () => { + workerTimeReasonFormDialogRef.value.show(); +}; + +const updateWorkerTimeControlMail = async (state, reason) => { + try { + const params = { + workerId: Number(route.params.id), + year: selectedDate.value.getFullYear(), + week: selectedWeekNumber.value, + state, + }; + + if (reason) params.reason = reason; + + await axios.post('WorkerTimeControls/updateWorkerTimeControlMail', params); + await getMailStates(selectedDate.value); + await fetchWeekData(); + notify(t('globals.dataSaved'), 'positive'); + } catch (err) { + console.error('Error updating worker time control mail'); + } +}; + +const isSatisfied = async () => { + await updateWorkerTimeControlMail('CONFIRMED'); +}; + +const isUnsatisfied = async (reason) => { + console.log('unsatiesfied reason:: ', reason); + if (!reason) return; // TODO: Mostrar notify de 'debe haber una razon' + updateWorkerTimeControlMail('REVISE', reason); +}; + +const resendEmail = async () => { + try { + const params = { + recipient: worker.value?.user?.email, + week: selectedWeekNumber.value, + year: selectedDate.value.getFullYear(), + workerId: Number(route.params.id), + state: 'SENDED', + }; + await axios.post('WorkerTimeControls/weekly-hour-hecord-email', params); + await getMailStates(selectedDate.value); + notify(t('Email sended'), 'positive'); + } catch (err) { + console.error('Error sending email'); + } +}; + onBeforeMount(() => { weekdayStore.initStore(); console.log('asdasdasd:: ', weekdayStore); }); onMounted(async () => { + setDate(Date.vnNew()); stateStore.rightDrawer = true; + const test = useArrayData('workerData').store.data; + console.log('test:: ', test); }); @@ -423,6 +484,53 @@ onMounted(async () => { }" @on-fetch="(data) => setHours(data)" /> + +
+ + + + + + {{ state ? t('Resend') : t('globals.send') }} + {{ t('email of this week to the user') }} + + +
+
@@ -520,6 +628,9 @@ onMounted(async () => { + + +
{{ columns }}
@@ -559,4 +670,12 @@ es: Total semana: Total semana Termina a las: Termina a las Add time: Añadir hora + Reason: Motivo + Not satisfied: No conforme + Satisfied: Conforme + Resend: Reenviar + email of this week to the user: email de esta semana al usuario + Email sended: Email enviado + Send time control email: Enviar email control horario + Are you sure you want to send it?: ¿Seguro que quieres enviarlo?