PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / v3 / src / assets / js / public / catalog.js
ameliabooking / v3 / src / assets / js / public Last commit date
actions.js 1 month ago booking.js 2 days ago cabinet.js 1 month ago cart.js 2 days ago catalog.js 2 days 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 2 days ago panel.js 1 month ago public.js 1 month ago renderActions.js 1 month ago restore.js 2 days ago slots.js 2 days ago stripePaymentIntent.js 2 days ago translation.js 1 month ago user.js 1 month ago
catalog.js
479 lines
1 // * Imported from Vue
2 import { reactive, ref } from 'vue'
3
4 import { useFormattedPrice } from '../common/formatting.js'
5
6 const globalSettings = reactive(window.wpAmeliaSettings)
7 const globalLabels = reactive(window.wpAmeliaLabels)
8
9 function useAvailableServiceIdsInCategory(
10 shortcodeData,
11 category,
12 entities,
13 employeeId = null,
14 locationId = null,
15 ) {
16 let serviceIdInCategory = []
17 let preselectedServices =
18 shortcodeData && shortcodeData.service
19 ? shortcodeData.service.split(',').map((s) => parseInt(s))
20 : null
21 if (category) {
22 category.serviceList.forEach((service) => {
23 if (employeeId) {
24 if (
25 employeeId in entities.entitiesRelations &&
26 service.id in entities.entitiesRelations[employeeId] &&
27 (locationId
28 ? entities.entitiesRelations[employeeId][service.id].find((a) => a === locationId)
29 : true) &&
30 service.status === 'visible' &&
31 service.show &&
32 !serviceIdInCategory.filter((el) => el === service.id).length &&
33 (!preselectedServices || preselectedServices.includes(service.id))
34 ) {
35 serviceIdInCategory.push(service.id)
36 }
37 } else {
38 entities.employees.forEach((employee) => {
39 if (
40 employee.id in entities.entitiesRelations &&
41 employee.show &&
42 service.id in entities.entitiesRelations[employee.id] &&
43 (locationId
44 ? entities.entitiesRelations[employee.id][service.id].find((a) => a === locationId)
45 : true) &&
46 service.status === 'visible' &&
47 service.show &&
48 !serviceIdInCategory.filter((el) => el === service.id).length &&
49 (!preselectedServices || preselectedServices.includes(service.id))
50 ) {
51 serviceIdInCategory.push(service.id)
52 }
53 })
54 }
55 })
56 }
57
58 return serviceIdInCategory
59 }
60
61 function useEmployeesServiceCapacity(entities, serviceId) {
62 let arrMax = []
63 let arrMin = []
64
65 entities.employees.forEach((employee) => {
66 if (
67 employee.id in entities.entitiesRelations &&
68 serviceId in entities.entitiesRelations[employee.id]
69 ) {
70 let employeeService = employee.serviceList.find((service) => service.id === serviceId)
71 arrMax.push(employeeService.maxCapacity)
72 arrMin.push(employeeService.minCapacity)
73 }
74 })
75
76 let serviceMinCapacity = arrMin.reduce((prev, curr) => {
77 return curr < prev ? curr : prev
78 }, arrMin[0])
79
80 let serviceMaxCapacity = arrMax.reduce((prev, curr) => {
81 return curr > prev ? curr : prev
82 }, arrMax[0])
83
84 if (serviceMinCapacity !== serviceMaxCapacity) {
85 return `${serviceMinCapacity}/${serviceMaxCapacity}`
86 }
87
88 return serviceMinCapacity
89 }
90
91 function useServiceDuration(seconds) {
92 let hours = Math.floor(seconds / 3600)
93 let minutes = (seconds / 60) % 60
94
95 return (
96 (hours ? hours + globalLabels.h + ' ' : '') + ' ' + (minutes ? minutes + globalLabels.min : '')
97 )
98 }
99
100 function useServicePrice(entities, serviceId) {
101 let arrPrice = []
102
103 let service = entities.services.find((service) => service.id === serviceId)
104
105 if (service) {
106 arrPrice.push(...getServicePrices(service))
107 }
108
109 entities.employees.forEach((employee) => {
110 if (
111 employee.id in entities.entitiesRelations &&
112 serviceId in entities.entitiesRelations[employee.id]
113 ) {
114 let employeeService = employee.serviceList.find((service) => service.id === serviceId)
115 if (employeeService) {
116 arrPrice.push(...getServicePrices(employeeService))
117 }
118 }
119 })
120
121 let serviceMinPrice = arrPrice.reduce((prev, curr) => {
122 return curr < prev ? curr : prev
123 }, arrPrice[0])
124
125 let serviceMaxPrice = arrPrice.reduce((prev, curr) => {
126 return curr > prev ? curr : prev
127 }, arrPrice[0])
128
129 if (serviceMinPrice !== serviceMaxPrice) {
130 return {
131 price: `${useFormattedPrice(serviceMinPrice, !globalSettings.payments.hideCurrencySymbolFrontend)} - ${useFormattedPrice(serviceMaxPrice, !globalSettings.payments.hideCurrencySymbolFrontend)}`,
132 min: serviceMinPrice,
133 max: serviceMaxPrice,
134 }
135 }
136
137 return {
138 price: useFormattedPrice(serviceMinPrice, globalSettings.payments.hideCurrencySymbolFrontend),
139 min: serviceMinPrice,
140 max: serviceMaxPrice,
141 }
142 }
143
144 function getServicePrices(service) {
145 let arrPrice = []
146
147 // Base price
148 arrPrice.push(service.price)
149
150 // Custom Pricing enabled
151 if (service.customPricing.enabled) {
152 // Duration pricing
153 if (service.customPricing.enabled === 'duration') {
154 let durations = Object.keys(service.customPricing.durations)
155 durations.forEach((duration) => {
156 arrPrice.push(service.customPricing.durations[duration].price)
157 })
158 }
159
160 // Period pricing
161 if (service.customPricing.enabled === 'period') {
162 service.customPricing.periods.custom.forEach((period) => {
163 period.ranges.forEach((range) => {
164 arrPrice.push(range.price)
165 })
166 })
167
168 service.customPricing.periods.default.forEach((period) => {
169 period.ranges.forEach((range) => {
170 arrPrice.push(range.price)
171 })
172 })
173 }
174
175 // Person pricing
176 if (service.customPricing.enabled === 'person') {
177 Object.keys(service.customPricing.persons).forEach((person) => {
178 arrPrice.push(service.customPricing.persons[person].price)
179 })
180 }
181 }
182
183 return arrPrice
184 }
185
186 function useServiceLocation(entities, serviceId) {
187 let arr = []
188
189 entities.employees.forEach((employee) => {
190 if (
191 employee.id in entities.entitiesRelations &&
192 serviceId in entities.entitiesRelations[employee.id] &&
193 entities.entitiesRelations[employee.id][serviceId].length
194 ) {
195 entities.locations.forEach((a) => {
196 if (
197 entities.entitiesRelations[employee.id][serviceId].some((b) => b === a.id) &&
198 !arr.find((b) => b === a.id)
199 ) {
200 arr.push(a)
201 }
202 })
203 }
204 })
205
206 return arr
207 }
208
209 function useDisabledPackageService(entities, pack) {
210 let detector = []
211 let employeesIds = Object.keys(entities.entitiesRelations)
212
213 pack.bookable.forEach((item) => {
214 let serviceEmployees = []
215 employeesIds.forEach((employeeId) => {
216 if (
217 entities.entitiesRelations[employeeId] &&
218 entities.entitiesRelations[employeeId][item.service.id] &&
219 !serviceEmployees.find((a) => (a ? a.id === parseInt(employeeId) : true))
220 ) {
221 serviceEmployees.push(entities.employees.find((a) => a.id === parseInt(employeeId)))
222 }
223 })
224
225 if (!serviceEmployees.length) {
226 detector.push(false)
227 }
228 })
229
230 return detector.filter((a) => a === false).length
231 }
232
233 function usePackageAvailabilityByEmployeeAndLocation(entities, pack, shortcodeData) {
234 let displayPack = []
235 let employeesIds = Object.keys(entities.entitiesRelations)
236 let preselectedEmployees =
237 shortcodeData && shortcodeData.employee
238 ? shortcodeData.employee.split(',').map((s) => parseInt(s))
239 : null
240 let unfilteredEmployees = ref(
241 preselectedEmployees
242 ? entities.unfilteredEmployees.filter((a) =>
243 preselectedEmployees.map((id) => parseInt(id)).includes(a.id),
244 )
245 : entities.unfilteredEmployees,
246 )
247
248 pack.bookable.forEach((item) => {
249 let arr = []
250
251 if (item.providers.length) {
252 item.providers.forEach((p) => {
253 if (item.locations.length) {
254 item.locations.forEach((l) => {
255 if (
256 unfilteredEmployees.value.find((a) => a.id === p.id) &&
257 entities.entitiesRelations[p.id] &&
258 entities.entitiesRelations[p.id][item.service.id] &&
259 entities.entitiesRelations[p.id][item.service.id].indexOf(l.id) !== -1 &&
260 !arr.find((a) => a.id === p.id)
261 ) {
262 arr.push(unfilteredEmployees.value.find((a) => a.id === p.id))
263 }
264 })
265 } else {
266 if (
267 unfilteredEmployees.value.find((a) => a.id === p.id) &&
268 !arr.find((a) => a.id === p.id)
269 ) {
270 arr.push(unfilteredEmployees.value.find((a) => a.id === p.id))
271 }
272 }
273 })
274 } else {
275 employeesIds.forEach((employeeId) => {
276 if (item.locations.length) {
277 item.locations.forEach((l) => {
278 if (
279 entities.entitiesRelations[employeeId] &&
280 entities.entitiesRelations[employeeId][item.service.id] &&
281 entities.entitiesRelations[employeeId][item.service.id].indexOf(l.id) !== -1 &&
282 unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)) &&
283 !arr.find((a) => a.id === parseInt(employeeId))
284 ) {
285 arr.push(unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)))
286 }
287 })
288 } else {
289 if (
290 entities.entitiesRelations[employeeId] &&
291 entities.entitiesRelations[employeeId][item.service.id] &&
292 unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)) &&
293 !arr.find((a) => a.id === parseInt(employeeId))
294 ) {
295 arr.push(unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)))
296 }
297 }
298 })
299 }
300
301 displayPack.push(!!arr.length)
302 })
303
304 return !displayPack.filter((a) => a === false).length
305 }
306
307 function usePackageEmployees(entities, pack, shortcodeData) {
308 let arr = []
309 let employeesIds = Object.keys(entities.entitiesRelations)
310 let preselectedEmployees =
311 shortcodeData && shortcodeData.employee
312 ? shortcodeData.employee.split(',').map((s) => parseInt(s))
313 : null
314 let unfilteredEmployees = ref(
315 preselectedEmployees
316 ? entities.unfilteredEmployees.filter((a) =>
317 preselectedEmployees.map((id) => parseInt(id)).includes(a.id),
318 )
319 : entities.unfilteredEmployees,
320 )
321
322 pack.bookable.forEach((item) => {
323 if (item.providers.length) {
324 item.providers.forEach((p) => {
325 if (item.locations.length) {
326 item.locations.forEach((l) => {
327 if (
328 unfilteredEmployees.value.find((a) => a.id === p.id) &&
329 entities.entitiesRelations[p.id] &&
330 entities.entitiesRelations[p.id][item.service.id] &&
331 entities.entitiesRelations[p.id][item.service.id].indexOf(l.id) !== -1 &&
332 !arr.find((a) => a.id === p.id)
333 ) {
334 arr.push(unfilteredEmployees.value.find((a) => a.id === p.id))
335 }
336 })
337 } else {
338 if (
339 unfilteredEmployees.value.find((a) => a.id === p.id) &&
340 !arr.find((a) => a.id === p.id)
341 ) {
342 arr.push(unfilteredEmployees.value.find((a) => a.id === p.id))
343 }
344 }
345 })
346 } else {
347 employeesIds.forEach((employeeId) => {
348 if (item.locations.length) {
349 item.locations.forEach((l) => {
350 if (
351 entities.entitiesRelations[employeeId] &&
352 entities.entitiesRelations[employeeId][item.service.id] &&
353 entities.entitiesRelations[employeeId][item.service.id].indexOf(l.id) !== -1 &&
354 unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)) &&
355 !arr.find((a) => a.id === parseInt(employeeId))
356 ) {
357 arr.push(unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)))
358 }
359 })
360 } else {
361 if (
362 entities.entitiesRelations[employeeId] &&
363 entities.entitiesRelations[employeeId][item.service.id] &&
364 unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)) &&
365 !arr.find((a) => a.id === parseInt(employeeId))
366 ) {
367 arr.push(unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)))
368 }
369 }
370 })
371 }
372 })
373
374 return arr
375 }
376
377 function usePackageLocations(entities, pack, shortcodeData) {
378 let arr = []
379
380 let employeesIds = Object.keys(entities.entitiesRelations)
381 let preselectedLocations =
382 shortcodeData && shortcodeData.location
383 ? shortcodeData.location.split(',').map((s) => parseInt(s))
384 : null
385 let unfilteredLocations = ref(
386 preselectedLocations
387 ? entities.unfilteredLocations.filter((a) =>
388 preselectedLocations.map((id) => parseInt(id)).includes(a.id),
389 )
390 : entities.unfilteredLocations,
391 )
392
393 pack.bookable.forEach((b) => {
394 if (b.locations.length) {
395 b.locations.forEach((l) => {
396 if (
397 unfilteredLocations.value.find((a) => a.id === l.id) &&
398 !arr.find((a) => a.id === l.id)
399 ) {
400 arr.push(unfilteredLocations.value.find((a) => a.id === l.id))
401 }
402 })
403 } else {
404 employeesIds.forEach((e) => {
405 unfilteredLocations.value.forEach((l) => {
406 if (
407 e in entities.entitiesRelations &&
408 b.service.id in entities.entitiesRelations[e] &&
409 entities.entitiesRelations[e][b.service.id].indexOf(l.id) !== -1 &&
410 unfilteredLocations.value.find((a) => a.id === l.id) &&
411 !arr.find((a) => a.id === parseInt(l.id))
412 ) {
413 arr.push(unfilteredLocations.value.find((a) => a.id === l.id))
414 }
415 })
416 })
417 }
418 })
419
420 return arr
421 }
422
423 function useAvailableCategories(entities, shortcodeData, employeeId = null, locationId = null) {
424 let arr = []
425 entities.categories.forEach((category) => {
426 let serviceIdsInCategory = useAvailableServiceIdsInCategory(
427 shortcodeData,
428 category,
429 entities,
430 employeeId,
431 locationId,
432 )
433 /* Service ids in category */
434 category.serviceIdList = serviceIdsInCategory
435
436 /* Packages in category */
437 category.packageList = []
438 entities.packages.forEach((pack) => {
439 serviceIdsInCategory.forEach((service) => {
440 if (
441 pack.bookable.filter((a) => a.service.id === service).length &&
442 !category.packageList.filter((b) => b === pack.id).length &&
443 pack.available &&
444 pack.status === 'visible' &&
445 !useDisabledPackageService(entities, pack) &&
446 usePackageAvailabilityByEmployeeAndLocation(entities, pack, shortcodeData)
447 ) {
448 category.packageList.push(pack.id)
449 }
450 })
451 })
452
453 if (
454 category.status === 'visible' &&
455 category.serviceList.length &&
456 !!serviceIdsInCategory.length &&
457 (shortcodeData.show === 'packages' ? !!category.packageList.length : true)
458 ) {
459 arr.push(category)
460 }
461 })
462
463 return arr
464 }
465
466 export {
467 useAvailableServiceIdsInCategory,
468 useEmployeesServiceCapacity,
469 useServiceDuration,
470 useServicePrice,
471 useServiceLocation,
472 useDisabledPackageService,
473 usePackageAvailabilityByEmployeeAndLocation,
474 usePackageEmployees,
475 usePackageLocations,
476 useAvailableCategories,
477 getServicePrices,
478 }
479