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
booking.js
75 lines
| 1 | function useParams(store, cabinetType) { |
| 2 | return { |
| 3 | source: 'cabinet-' + cabinetType.value, |
| 4 | timeZone: store.getters['cabinet/getTimeZone'], |
| 5 | } |
| 6 | } |
| 7 | |
| 8 | function useCustomFieldsData(bookings, userType) { |
| 9 | let result = [] |
| 10 | |
| 11 | bookings.forEach((booking) => { |
| 12 | if (['approved', 'pending'].includes(booking.status) && booking.customFields) { |
| 13 | let customFields = JSON.parse(booking.customFields) |
| 14 | |
| 15 | Object.keys(customFields).forEach((customFieldId) => { |
| 16 | if (customFields[customFieldId]) { |
| 17 | let value = |
| 18 | customFields[customFieldId].type === 'file' |
| 19 | ? customFields[customFieldId]?.value |
| 20 | ? customFields[customFieldId].value |
| 21 | : '' |
| 22 | : customFields[customFieldId].value |
| 23 | |
| 24 | if (Array.isArray(value) ? value.length : value) { |
| 25 | result.push({ |
| 26 | label: customFields[customFieldId].label, |
| 27 | value: value, |
| 28 | }) |
| 29 | } |
| 30 | } |
| 31 | }) |
| 32 | } |
| 33 | }) |
| 34 | |
| 35 | if (userType === 'customer') { |
| 36 | return result |
| 37 | } |
| 38 | |
| 39 | // For employee view, keep unique custom fields with their values |
| 40 | const uniqueFields = new Map() |
| 41 | result |
| 42 | .filter((i) => i.value) |
| 43 | .forEach((item) => { |
| 44 | if (!uniqueFields.has(item.label)) { |
| 45 | uniqueFields.set(item.label, item) |
| 46 | } |
| 47 | }) |
| 48 | return Array.from(uniqueFields.values()) |
| 49 | } |
| 50 | |
| 51 | function useExtrasData(bookings, bookable) { |
| 52 | let result = {} |
| 53 | |
| 54 | bookings.forEach((booking) => { |
| 55 | if (['approved', 'pending'].includes(booking.status)) { |
| 56 | booking.extras.forEach((bookingExtra) => { |
| 57 | if (!(bookingExtra.extraId in result)) { |
| 58 | result[bookingExtra.extraId] = { |
| 59 | quantity: 0, |
| 60 | price: bookingExtra.price, |
| 61 | name: bookable.extras.find((i) => i.id === bookingExtra.extraId).name, |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | result[bookingExtra.extraId].quantity = |
| 66 | result[bookingExtra.extraId].quantity + bookingExtra.quantity |
| 67 | }) |
| 68 | } |
| 69 | }) |
| 70 | |
| 71 | return result |
| 72 | } |
| 73 | |
| 74 | export { useParams, useCustomFieldsData, useExtrasData } |
| 75 |