admin.js
5 days ago
appointment.js
5 days ago
booking.js
5 days ago
customers.js
5 days ago
event.js
5 days ago
package.js
5 days ago
payment.js
5 days ago
socialAuthOptions.js
5 days ago
status.js
5 days ago
useReactiveCustomize.js
5 days ago
appointment.js
107 lines
| 1 | import { useConvertedUtcToLocalDateTime } from '../common/date' |
| 2 | |
| 3 | function useAppointmentDuration(store, appointment) { |
| 4 | let service = store.getters['entities/getService'](appointment.serviceId) |
| 5 | |
| 6 | let largestBookingDuration = 0 |
| 7 | |
| 8 | let largestBookingExtrasDuration = 0 |
| 9 | |
| 10 | appointment.bookings.forEach((booking) => { |
| 11 | if (['approved', 'pending'].includes(booking.status)) { |
| 12 | let bookingDuration = booking.duration ? booking.duration : service.duration |
| 13 | |
| 14 | if (bookingDuration > largestBookingDuration) { |
| 15 | largestBookingDuration = bookingDuration |
| 16 | } |
| 17 | |
| 18 | let bookingExtrasDuration = 0 |
| 19 | |
| 20 | booking.extras.forEach((bookingExtra) => { |
| 21 | let extra = service.extras.find((i) => i.id === bookingExtra.extraId) |
| 22 | |
| 23 | bookingExtrasDuration += extra.duration * bookingExtra.quantity |
| 24 | }) |
| 25 | |
| 26 | if (bookingExtrasDuration > largestBookingExtrasDuration) { |
| 27 | largestBookingExtrasDuration = bookingExtrasDuration |
| 28 | } |
| 29 | } |
| 30 | }) |
| 31 | |
| 32 | return largestBookingDuration + largestBookingExtrasDuration |
| 33 | } |
| 34 | |
| 35 | function useParsedAppointments(appointments, timeZone, allBookings) { |
| 36 | for (let dateString in appointments) { |
| 37 | appointments[dateString].appointments.forEach((appointment) => { |
| 38 | let appointmentCustomerBookings = {} |
| 39 | |
| 40 | appointment.bookings.forEach((booking) => { |
| 41 | if (!(booking.customerId in appointmentCustomerBookings)) { |
| 42 | appointmentCustomerBookings[booking.customerId] = [] |
| 43 | } |
| 44 | |
| 45 | appointmentCustomerBookings[booking.customerId][booking.id] = booking.status |
| 46 | }) |
| 47 | |
| 48 | let customerBookings = {} |
| 49 | |
| 50 | for (let customerId in appointmentCustomerBookings) { |
| 51 | for (let bookingId in appointmentCustomerBookings[customerId]) { |
| 52 | if ( |
| 53 | !(customerId in customerBookings) || |
| 54 | appointmentCustomerBookings[customerId][bookingId] === 'approved' || |
| 55 | appointmentCustomerBookings[customerId][bookingId] === 'pending' |
| 56 | ) { |
| 57 | customerBookings[customerId] = bookingId |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | appointment.bookings.forEach((booking) => { |
| 63 | if ( |
| 64 | booking.customerId in customerBookings && |
| 65 | parseInt(booking.id) !== parseInt(customerBookings[booking.customerId]) |
| 66 | ) { |
| 67 | return |
| 68 | } |
| 69 | |
| 70 | if (timeZone === '') { |
| 71 | appointment.bookingStart = useConvertedUtcToLocalDateTime(appointment.bookingStart) |
| 72 | appointment.bookingEnd = useConvertedUtcToLocalDateTime(appointment.bookingEnd) |
| 73 | } |
| 74 | |
| 75 | if (!allBookings) { |
| 76 | appointment.bookings = [booking] |
| 77 | } |
| 78 | }) |
| 79 | }) |
| 80 | } |
| 81 | |
| 82 | if (timeZone === '') { |
| 83 | let parsedGroupedAppointments = {} |
| 84 | |
| 85 | for (let dateString in appointments) { |
| 86 | appointments[dateString].appointments.forEach((appointment) => { |
| 87 | let appointmentDateString = appointment.bookingStart.split(' ')[0] |
| 88 | |
| 89 | if (!(appointmentDateString in parsedGroupedAppointments)) { |
| 90 | parsedGroupedAppointments[appointmentDateString] = { |
| 91 | appointments: [appointment], |
| 92 | date: appointmentDateString, |
| 93 | } |
| 94 | } else { |
| 95 | parsedGroupedAppointments[appointmentDateString].appointments.push(appointment) |
| 96 | } |
| 97 | }) |
| 98 | } |
| 99 | |
| 100 | return parsedGroupedAppointments |
| 101 | } |
| 102 | |
| 103 | return appointments |
| 104 | } |
| 105 | |
| 106 | export { useAppointmentDuration, useParsedAppointments } |
| 107 |