PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.4
Booking for Appointments and Events Calendar – Amelia v2.4.4
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 5 days ago booking.js 5 days ago cabinet.js 5 days ago cart.js 5 days ago catalog.js 5 days ago coupon.js 5 days ago customFields.js 5 days ago events.js 5 days ago facebookPixel.js 5 days ago ivy.js 5 days ago package.js 5 days ago panel.js 5 days ago public.js 5 days ago renderActions.js 5 days ago restore.js 5 days ago slots.js 5 days ago translation.js 5 days ago user.js 5 days ago
catalog.js
428 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 entities.employees.forEach((employee) => {
104 if (
105 employee.id in entities.entitiesRelations &&
106 serviceId in entities.entitiesRelations[employee.id]
107 ) {
108 let employeeService = employee.serviceList.find((service) => service.id === serviceId)
109 arrPrice.push(employeeService.price)
110 }
111 })
112
113 let serviceMinPrice = arrPrice.reduce((prev, curr) => {
114 return curr < prev ? curr : prev
115 }, arrPrice[0])
116
117 let serviceMaxPrice = arrPrice.reduce((prev, curr) => {
118 return curr > prev ? curr : prev
119 }, arrPrice[0])
120
121 if (serviceMinPrice !== serviceMaxPrice) {
122 return {
123 price: `${useFormattedPrice(serviceMinPrice, !globalSettings.payments.hideCurrencySymbolFrontend)} - ${useFormattedPrice(serviceMaxPrice, !globalSettings.payments.hideCurrencySymbolFrontend)}`,
124 min: serviceMinPrice,
125 max: serviceMaxPrice,
126 }
127 }
128
129 return {
130 price: useFormattedPrice(serviceMinPrice, globalSettings.payments.hideCurrencySymbolFrontend),
131 min: serviceMinPrice,
132 max: serviceMaxPrice,
133 }
134 }
135
136 function useServiceLocation(entities, serviceId) {
137 let arr = []
138
139 entities.employees.forEach((employee) => {
140 if (
141 employee.id in entities.entitiesRelations &&
142 serviceId in entities.entitiesRelations[employee.id] &&
143 entities.entitiesRelations[employee.id][serviceId].length
144 ) {
145 entities.locations.forEach((a) => {
146 if (
147 entities.entitiesRelations[employee.id][serviceId].some((b) => b === a.id) &&
148 !arr.find((b) => b === a.id)
149 ) {
150 arr.push(a)
151 }
152 })
153 }
154 })
155
156 return arr
157 }
158
159 function useDisabledPackageService(entities, pack) {
160 let detector = []
161 let employeesIds = Object.keys(entities.entitiesRelations)
162
163 pack.bookable.forEach((item) => {
164 let serviceEmployees = []
165 employeesIds.forEach((employeeId) => {
166 if (
167 entities.entitiesRelations[employeeId] &&
168 entities.entitiesRelations[employeeId][item.service.id] &&
169 !serviceEmployees.find((a) => (a ? a.id === parseInt(employeeId) : true))
170 ) {
171 serviceEmployees.push(entities.employees.find((a) => a.id === parseInt(employeeId)))
172 }
173 })
174
175 if (!serviceEmployees.length) {
176 detector.push(false)
177 }
178 })
179
180 return detector.filter((a) => a === false).length
181 }
182
183 function usePackageAvailabilityByEmployeeAndLocation(entities, pack, shortcodeData) {
184 let displayPack = []
185 let employeesIds = Object.keys(entities.entitiesRelations)
186 let preselectedEmployees =
187 shortcodeData && shortcodeData.employee
188 ? shortcodeData.employee.split(',').map((s) => parseInt(s))
189 : null
190 let unfilteredEmployees = ref(
191 preselectedEmployees
192 ? entities.unfilteredEmployees.filter((a) =>
193 preselectedEmployees.map((id) => parseInt(id)).includes(a.id),
194 )
195 : entities.unfilteredEmployees,
196 )
197
198 pack.bookable.forEach((item) => {
199 let arr = []
200
201 if (item.providers.length) {
202 item.providers.forEach((p) => {
203 if (item.locations.length) {
204 item.locations.forEach((l) => {
205 if (
206 unfilteredEmployees.value.find((a) => a.id === p.id) &&
207 entities.entitiesRelations[p.id] &&
208 entities.entitiesRelations[p.id][item.service.id] &&
209 entities.entitiesRelations[p.id][item.service.id].indexOf(l.id) !== -1 &&
210 !arr.find((a) => a.id === p.id)
211 ) {
212 arr.push(unfilteredEmployees.value.find((a) => a.id === p.id))
213 }
214 })
215 } else {
216 if (
217 unfilteredEmployees.value.find((a) => a.id === p.id) &&
218 !arr.find((a) => a.id === p.id)
219 ) {
220 arr.push(unfilteredEmployees.value.find((a) => a.id === p.id))
221 }
222 }
223 })
224 } else {
225 employeesIds.forEach((employeeId) => {
226 if (item.locations.length) {
227 item.locations.forEach((l) => {
228 if (
229 entities.entitiesRelations[employeeId] &&
230 entities.entitiesRelations[employeeId][item.service.id] &&
231 entities.entitiesRelations[employeeId][item.service.id].indexOf(l.id) !== -1 &&
232 unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)) &&
233 !arr.find((a) => a.id === parseInt(employeeId))
234 ) {
235 arr.push(unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)))
236 }
237 })
238 } else {
239 if (
240 entities.entitiesRelations[employeeId] &&
241 entities.entitiesRelations[employeeId][item.service.id] &&
242 unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)) &&
243 !arr.find((a) => a.id === parseInt(employeeId))
244 ) {
245 arr.push(unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)))
246 }
247 }
248 })
249 }
250
251 displayPack.push(!!arr.length)
252 })
253
254 return !displayPack.filter((a) => a === false).length
255 }
256
257 function usePackageEmployees(entities, pack, shortcodeData) {
258 let arr = []
259 let employeesIds = Object.keys(entities.entitiesRelations)
260 let preselectedEmployees =
261 shortcodeData && shortcodeData.employee
262 ? shortcodeData.employee.split(',').map((s) => parseInt(s))
263 : null
264 let unfilteredEmployees = ref(
265 preselectedEmployees
266 ? entities.unfilteredEmployees.filter((a) =>
267 preselectedEmployees.map((id) => parseInt(id)).includes(a.id),
268 )
269 : entities.unfilteredEmployees,
270 )
271
272 pack.bookable.forEach((item) => {
273 if (item.providers.length) {
274 item.providers.forEach((p) => {
275 if (item.locations.length) {
276 item.locations.forEach((l) => {
277 if (
278 unfilteredEmployees.value.find((a) => a.id === p.id) &&
279 entities.entitiesRelations[p.id] &&
280 entities.entitiesRelations[p.id][item.service.id] &&
281 entities.entitiesRelations[p.id][item.service.id].indexOf(l.id) !== -1 &&
282 !arr.find((a) => a.id === p.id)
283 ) {
284 arr.push(unfilteredEmployees.value.find((a) => a.id === p.id))
285 }
286 })
287 } else {
288 if (
289 unfilteredEmployees.value.find((a) => a.id === p.id) &&
290 !arr.find((a) => a.id === p.id)
291 ) {
292 arr.push(unfilteredEmployees.value.find((a) => a.id === p.id))
293 }
294 }
295 })
296 } else {
297 employeesIds.forEach((employeeId) => {
298 if (item.locations.length) {
299 item.locations.forEach((l) => {
300 if (
301 entities.entitiesRelations[employeeId] &&
302 entities.entitiesRelations[employeeId][item.service.id] &&
303 entities.entitiesRelations[employeeId][item.service.id].indexOf(l.id) !== -1 &&
304 unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)) &&
305 !arr.find((a) => a.id === parseInt(employeeId))
306 ) {
307 arr.push(unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)))
308 }
309 })
310 } else {
311 if (
312 entities.entitiesRelations[employeeId] &&
313 entities.entitiesRelations[employeeId][item.service.id] &&
314 unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)) &&
315 !arr.find((a) => a.id === parseInt(employeeId))
316 ) {
317 arr.push(unfilteredEmployees.value.find((a) => a.id === parseInt(employeeId)))
318 }
319 }
320 })
321 }
322 })
323
324 return arr
325 }
326
327 function usePackageLocations(entities, pack, shortcodeData) {
328 let arr = []
329
330 let employeesIds = Object.keys(entities.entitiesRelations)
331 let preselectedLocations =
332 shortcodeData && shortcodeData.location
333 ? shortcodeData.location.split(',').map((s) => parseInt(s))
334 : null
335 let unfilteredLocations = ref(
336 preselectedLocations
337 ? entities.unfilteredLocations.filter((a) =>
338 preselectedLocations.map((id) => parseInt(id)).includes(a.id),
339 )
340 : entities.unfilteredLocations,
341 )
342
343 pack.bookable.forEach((b) => {
344 if (b.locations.length) {
345 b.locations.forEach((l) => {
346 if (
347 unfilteredLocations.value.find((a) => a.id === l.id) &&
348 !arr.find((a) => a.id === l.id)
349 ) {
350 arr.push(unfilteredLocations.value.find((a) => a.id === l.id))
351 }
352 })
353 } else {
354 employeesIds.forEach((e) => {
355 unfilteredLocations.value.forEach((l) => {
356 if (
357 e in entities.entitiesRelations &&
358 b.service.id in entities.entitiesRelations[e] &&
359 entities.entitiesRelations[e][b.service.id].indexOf(l.id) !== -1 &&
360 unfilteredLocations.value.find((a) => a.id === l.id) &&
361 !arr.find((a) => a.id === parseInt(l.id))
362 ) {
363 arr.push(unfilteredLocations.value.find((a) => a.id === l.id))
364 }
365 })
366 })
367 }
368 })
369
370 return arr
371 }
372
373 function useAvailableCategories(entities, shortcodeData, employeeId = null, locationId = null) {
374 let arr = []
375 entities.categories.forEach((category) => {
376 let serviceIdsInCategory = useAvailableServiceIdsInCategory(
377 shortcodeData,
378 category,
379 entities,
380 employeeId,
381 locationId,
382 )
383 /* Service ids in category */
384 category.serviceIdList = serviceIdsInCategory
385
386 /* Packages in category */
387 category.packageList = []
388 entities.packages.forEach((pack) => {
389 serviceIdsInCategory.forEach((service) => {
390 if (
391 pack.bookable.filter((a) => a.service.id === service).length &&
392 !category.packageList.filter((b) => b === pack.id).length &&
393 pack.available &&
394 pack.status === 'visible' &&
395 !useDisabledPackageService(entities, pack) &&
396 usePackageAvailabilityByEmployeeAndLocation(entities, pack, shortcodeData)
397 ) {
398 category.packageList.push(pack.id)
399 }
400 })
401 })
402
403 if (
404 category.status === 'visible' &&
405 category.serviceList.length &&
406 !!serviceIdsInCategory.length &&
407 (shortcodeData.show === 'packages' ? !!category.packageList.length : true)
408 ) {
409 arr.push(category)
410 }
411 })
412
413 return arr
414 }
415
416 export {
417 useAvailableServiceIdsInCategory,
418 useEmployeesServiceCapacity,
419 useServiceDuration,
420 useServicePrice,
421 useServiceLocation,
422 useDisabledPackageService,
423 usePackageAvailabilityByEmployeeAndLocation,
424 usePackageEmployees,
425 usePackageLocations,
426 useAvailableCategories,
427 }
428