@@ -45,7 +41,7 @@
();
@@ -47,7 +49,7 @@
-
+
@@ -66,7 +69,7 @@
class="col-auto"
:class="expense_store.is_showing_create_form ? 'invisible' : ''"
/>
-
+
{{ $t('timesheet.expense.add_expense') }}
@@ -74,8 +77,10 @@
-
-
+
diff --git a/src/modules/timesheets/composables/use-expense-api.ts b/src/modules/timesheets/composables/use-expense-api.ts
index 2165807..a596f0e 100644
--- a/src/modules/timesheets/composables/use-expense-api.ts
+++ b/src/modules/timesheets/composables/use-expense-api.ts
@@ -2,13 +2,13 @@
import { useExpensesStore } from "src/stores/expense-store";
import { useTimesheetStore } from "src/stores/timesheet-store";
import { Expense } from "src/modules/timesheets/models/expense.models";
-import { date } from "quasar";
+import { date, Notify } from "quasar";
export const useExpensesApi = () => {
const expenses_store = useExpensesStore();
const timesheet_store = useTimesheetStore();
- const upsertExpense = async (expense: Expense, employee_email: string, file?: File): Promise => {
+ const upsertExpense = async (expense: Expense, employee_email?: string, file?: File): Promise => {
if (file) {
const attachmentKey = await expenses_store.uploadAttachment(file);
@@ -19,23 +19,24 @@ export const useExpensesApi = () => {
expense.attachment_name = file.name;
}
}
- console.log('employee email provided for expense: ', employee_email)
- const success = await expenses_store.upsertExpense(expense, employee_email);
-
- if (success) {
- expenses_store.current_expense = new Expense(date.formatDate( new Date(), 'YYYY-MM-DD'));
- timesheet_store.getTimesheetsByOptionalEmployeeEmail(employee_email);
- return 'SUCCESS';
- }
- return 'INVALID_EXPENSE';
+ const success = await expenses_store.upsertExpense(expense, employee_email);
+
+ if (success) {
+ expenses_store.current_expense = new Expense(date.formatDate(new Date(), 'YYYY-MM-DD'));
+ await timesheet_store.getTimesheetsByOptionalEmployeeEmail(employee_email);
+
+ return true;
+ }
+
+ return false;
};
const deleteExpenseById = async (expense_id: number, employee_email?: string): Promise => {
const success = await expenses_store.deleteExpenseById(expense_id);
- if (success) {
- timesheet_store.getTimesheetsByOptionalEmployeeEmail(employee_email);
- }
+
+ if (success)
+ await timesheet_store.getTimesheetsByOptionalEmployeeEmail(employee_email);
};
return {
diff --git a/src/stores/expense-store.ts b/src/stores/expense-store.ts
index 64911c9..cbd837c 100644
--- a/src/stores/expense-store.ts
+++ b/src/stores/expense-store.ts
@@ -1,5 +1,5 @@
import { date } from "quasar";
-import { computed, ref } from "vue";
+import { ref } from "vue";
import { defineStore } from "pinia";
import { useTimesheetStore } from "src/stores/timesheet-store";
import { Expense } from "src/modules/timesheets/models/expense.models";
@@ -16,7 +16,6 @@ export const useExpensesStore = defineStore('expenses', () => {
const current_expense = ref(new Expense(date.formatDate(new Date(), 'YYYY-MM-DD')));
const initial_expense = ref(new Expense(date.formatDate(new Date(), 'YYYY-MM-DD')));
const isShowingAttachmentDialog = ref(false);
- const is_save_disabled = computed(() => JSON.stringify(current_expense.value) === JSON.stringify(initial_expense.value))
const open = (): void => {
is_open.value = true;
@@ -103,7 +102,6 @@ export const useExpensesStore = defineStore('expenses', () => {
current_expense,
initial_expense,
isShowingAttachmentDialog,
- is_save_disabled,
attachmentURL,
open,
upsertExpense,
diff --git a/src/stores/timesheet-store.ts b/src/stores/timesheet-store.ts
index 888faa4..aa8d19e 100644
--- a/src/stores/timesheet-store.ts
+++ b/src/stores/timesheet-store.ts
@@ -14,6 +14,7 @@ import type { TimesheetApprovalCSVReportFilters } from 'src/modules/timesheet-ap
import { type FederalHoliday, TARGO_HOLIDAY_NAMES_FR } from 'src/modules/timesheets/models/federal-holidays.models';
import type { RouteNames } from 'src/router/router-constants';
import type { RouteRecordNameGeneric } from 'vue-router';
+import { isBetweenDateStrings } from 'src/utils/date-and-time-utils';
export const useTimesheetStore = defineStore('timesheet', () => {
const { t } = useI18n();
@@ -163,13 +164,6 @@ export const useTimesheetStore = defineStore('timesheet', () => {
try {
const timesheet_ids = timesheets.value.map(timesheet => timesheet.timesheet_id);
- // Backend returns the amount of shifts and expenses successfully updated, could be useful for error handling???
- // const shift_expense_count = timesheets.value.reduce((timesheets_sum, timesheet) => {
- // return timesheets_sum + timesheet.days.reduce((day_sum, day) => {
- // return day_sum + day.shifts.length + day.expenses.length
- // }, 0);
- // }, 0);
-
const response = await timesheetApprovalService.updateTimesheetsApprovalStatus(email, timesheet_ids, approval_status);
return response.success;
} catch (error) {
@@ -227,19 +221,20 @@ export const useTimesheetStore = defineStore('timesheet', () => {
if (pay_period_observer.value === undefined) {
pay_period_observer.value = timesheetApprovalService.subscribeToPayPeriodObservable();
pay_period_observer.value.onmessage = async (event: MessageEvent) => {
- // find employee that modified their timesheets
const pay_period_event: PayPeriodEvent = JSON.parse(event.data);
+
+ // abort notification if event date is not within pay period being currently viewed
+ if (!isBetweenDateStrings(pay_period_event.date, pay_period.value!.period_start, pay_period.value!.period_end))
+ return;
+
const overview = pay_period_overviews.value.find(overview => overview.email === pay_period_event.employee_email);
const employee_name = overview?.employee_first_name + ' ' + overview?.employee_last_name;
- // update overviews
await getTimesheetOverviews();
- // if user is looking at details of employee that generated event, update
if (selected_employee_name.value === employee_name)
await getTimesheetsByOptionalEmployeeEmail(pay_period_event.employee_email);
- // create visual feedback of notification and update
Notify.create({
message: `${employee_name} ${t('timesheet_approvals.event.' + pay_period_event.action)} ${t('timesheet_approvals.event.' + pay_period_event.event_type)}`,
color: 'warning',
diff --git a/src/utils/date-and-time-utils.ts b/src/utils/date-and-time-utils.ts
index b7494b8..e47fcd0 100644
--- a/src/utils/date-and-time-utils.ts
+++ b/src/utils/date-and-time-utils.ts
@@ -28,7 +28,7 @@ export const getHoursMinutesStringFromHoursFloat = (hours: number, minutes?: num
flatHours += 1;
flatMinutes = 0;
}
-
+
return `${flatHours}h${flatMinutes > 1 ? ' ' + flatMinutes : ''}`
}
@@ -39,8 +39,24 @@ export const getHoursMinutesBetweenTwoHHmm = (startTime: string, endTime: string
const [startHours, startMinutes] = startTime.split(':');
const [endHours, endMinutes] = endTime.split(':');
- return {
+ return {
hours: Number(endHours) - Number(startHours),
minutes: Number(endMinutes) - Number(startMinutes),
}
+}
+
+export const isBetweenDateStrings = (evDate: string, start: string, end: string, inclusive: boolean = true) => {
+ const eventDate = date.extractDate(evDate, 'YYYY-MM-DD');
+ const startDate = date.extractDate(start, 'YYYY-MM-DD');
+ const endDate = date.extractDate(end, 'YYYY-MM-DD');
+
+ return date.isBetweenDates(
+ eventDate,
+ startDate,
+ endDate,
+ {
+ inclusiveFrom: inclusive,
+ inclusiveTo: inclusive,
+ onlyDate: true
+ });
}
\ No newline at end of file