actions.js
1 month ago
booking.js
1 day ago
cabinet.js
1 month ago
cart.js
1 day ago
catalog.js
1 day ago
coupon.js
1 month ago
customFields.js
1 month ago
customFontFace.js
1 month ago
eventFormCssVars.js
1 month ago
events.js
1 month ago
facebookPixel.js
1 month ago
ivy.js
1 month ago
package.js
1 day ago
panel.js
1 month ago
public.js
1 month ago
renderActions.js
1 month ago
restore.js
1 day ago
slots.js
1 day ago
stripePaymentIntent.js
1 day ago
translation.js
1 month ago
user.js
1 month ago
package.js
196 lines
| 1 | import { useCartItem } from './cart' |
| 2 | import { usePercentageAmount } from '../common/pricing' |
| 3 | |
| 4 | function useBuildPackage(index, entity) { |
| 5 | let items = [ |
| 6 | { |
| 7 | packageId: entity.id, |
| 8 | serviceId: null, |
| 9 | index: null, |
| 10 | services: {}, |
| 11 | }, |
| 12 | ] |
| 13 | |
| 14 | entity.bookable.forEach((item, i) => { |
| 15 | if (i === 0) { |
| 16 | items[index].serviceId = item.service.id |
| 17 | } |
| 18 | |
| 19 | items[index].index = 0 |
| 20 | |
| 21 | items[index].services[item.service.id] = { |
| 22 | fetched: false, |
| 23 | slots: [], |
| 24 | busyness: {}, |
| 25 | providerId: null, |
| 26 | locationId: null, |
| 27 | serviceId: item.service.id, |
| 28 | quantity: item.quantity, |
| 29 | list: [...new Array(item.minimumScheduled)].map((el, index) => ({ |
| 30 | id: index + ' ' + item.service.id, |
| 31 | providerId: null, |
| 32 | locationId: null, |
| 33 | date: null, |
| 34 | time: null, |
| 35 | persons: 1, |
| 36 | extras: [], |
| 37 | duration: null, |
| 38 | })), |
| 39 | } |
| 40 | }) |
| 41 | |
| 42 | return items |
| 43 | } |
| 44 | |
| 45 | function useFilteredProviders(store) { |
| 46 | let relations = store.getters['entities/getEntitiesRelations'] |
| 47 | |
| 48 | let cartItem = useCartItem(store) |
| 49 | |
| 50 | let serviceId = cartItem.serviceId |
| 51 | |
| 52 | let activeService = cartItem.services[serviceId] |
| 53 | |
| 54 | let packageService = store.getters['entities/getPackage']( |
| 55 | store.getters['booking/getPackageId'], |
| 56 | ).bookable.find((i) => parseInt(i.service.id) === parseInt(serviceId)) |
| 57 | |
| 58 | let preselectedEmployees = store.getters['entities/getPreselected'].employee |
| 59 | |
| 60 | let employees = preselectedEmployees.length |
| 61 | ? store.getters['entities/getUnfilteredEmployees'].filter((a) => |
| 62 | preselectedEmployees.map((id) => parseInt(id)).includes(a.id), |
| 63 | ) |
| 64 | : store.getters['entities/getUnfilteredEmployees'] |
| 65 | |
| 66 | let employeesIds = [] |
| 67 | |
| 68 | if (activeService.locationId) { |
| 69 | for (let employeeId in relations) { |
| 70 | if ( |
| 71 | serviceId in relations[employeeId] && |
| 72 | relations[employeeId][serviceId].indexOf(activeService.locationId) !== -1 |
| 73 | ) { |
| 74 | employeesIds.push(parseInt(employeeId)) |
| 75 | } |
| 76 | } |
| 77 | } else { |
| 78 | let locationsIds = [] |
| 79 | |
| 80 | if (packageService.locations.length) { |
| 81 | locationsIds = packageService.locations.map((item) => item.id) |
| 82 | } else { |
| 83 | for (let employeeId in relations) { |
| 84 | if (serviceId in relations[employeeId]) { |
| 85 | locationsIds = locationsIds.concat(relations[employeeId][serviceId]) |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | for (let employeeId in relations) { |
| 91 | if (serviceId in relations[employeeId]) { |
| 92 | locationsIds.forEach((locationId) => { |
| 93 | if (relations[employeeId][serviceId].indexOf(locationId) !== -1) { |
| 94 | employeesIds.push(parseInt(employeeId)) |
| 95 | } |
| 96 | }) |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | let availableEmployeesIds = packageService.providers.length |
| 102 | ? packageService.providers.map((item) => item.id) |
| 103 | : employees.map((item) => item.id) |
| 104 | |
| 105 | return employees.filter( |
| 106 | (item) => |
| 107 | availableEmployeesIds.indexOf(item.id) !== -1 && |
| 108 | employeesIds.indexOf(item.id) !== -1 && |
| 109 | item.status === 'visible', |
| 110 | ) |
| 111 | } |
| 112 | |
| 113 | function useFilteredLocations(store) { |
| 114 | let cartItem = useCartItem(store) |
| 115 | |
| 116 | let relations = store.getters['entities/getEntitiesRelations'] |
| 117 | |
| 118 | let serviceId = cartItem.serviceId |
| 119 | |
| 120 | let activeService = cartItem.services[serviceId] |
| 121 | |
| 122 | let packageService = store.getters['entities/getPackage']( |
| 123 | store.getters['booking/getPackageId'], |
| 124 | ).bookable.find((i) => parseInt(i.service.id) === parseInt(serviceId)) |
| 125 | |
| 126 | let preselectedLocations = store.getters['entities/getPreselected'].location |
| 127 | |
| 128 | let locations = preselectedLocations.length |
| 129 | ? store.getters['entities/getUnfilteredLocations'].filter((a) => |
| 130 | preselectedLocations.map((id) => parseInt(id)).includes(a.id), |
| 131 | ) |
| 132 | : store.getters['entities/getUnfilteredLocations'] |
| 133 | |
| 134 | let locationsIds = [] |
| 135 | |
| 136 | if (activeService.providerId) { |
| 137 | locationsIds = relations[activeService.providerId][serviceId] |
| 138 | } else { |
| 139 | let employeesIds = [] |
| 140 | |
| 141 | if (packageService.providers.length) { |
| 142 | employeesIds = packageService.providers.map((item) => item.id) |
| 143 | } else { |
| 144 | for (let employeeId in relations) { |
| 145 | if (serviceId in relations[employeeId]) { |
| 146 | employeesIds.push(parseInt(employeeId)) |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | for (let employeeId in relations) { |
| 152 | if (serviceId in relations[employeeId] && employeesIds.indexOf(parseInt(employeeId)) !== -1) { |
| 153 | locationsIds = locationsIds.concat(relations[employeeId][serviceId]) |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | let availableLocationsIds = packageService.locations.length |
| 159 | ? packageService.locations.map((item) => item.id) |
| 160 | : locations.map((item) => item.id) |
| 161 | |
| 162 | return locations.filter( |
| 163 | (item) => |
| 164 | availableLocationsIds.indexOf(item.id) !== -1 && |
| 165 | locationsIds.indexOf(item.id) !== -1 && |
| 166 | item.status === 'visible', |
| 167 | ) |
| 168 | } |
| 169 | |
| 170 | function usePackageAmount(pack) { |
| 171 | return pack.discount && !pack.calculatedPrice |
| 172 | ? pack.price - usePercentageAmount(pack.price, pack.discount) |
| 173 | : pack.price |
| 174 | } |
| 175 | |
| 176 | function usePackageDiscountAmount(pack, coupon) { |
| 177 | return usePercentageAmount(usePackageAmount(pack), coupon.discount) + coupon.deduction |
| 178 | } |
| 179 | |
| 180 | function useCalculateDiscount(pack) { |
| 181 | if (pack.discount && !pack.calculatedPrice) { |
| 182 | return pack.discount |
| 183 | } |
| 184 | |
| 185 | return 0 |
| 186 | } |
| 187 | |
| 188 | export { |
| 189 | useBuildPackage, |
| 190 | useFilteredProviders, |
| 191 | useFilteredLocations, |
| 192 | usePackageAmount, |
| 193 | useCalculateDiscount, |
| 194 | usePackageDiscountAmount, |
| 195 | } |
| 196 |