appointment.js
1 year ago
attendee.js
1 year ago
auth.js
1 year ago
bookableType.js
3 years ago
booking.js
1 year ago
cabinet.js
1 year ago
cabinetFilters.js
1 year ago
coupon.js
2 years ago
customFields.js
2 years ago
customerInfo.js
1 year ago
employee.js
1 year ago
entities.js
1 year ago
event.js
1 year ago
eventBooking.js
3 years ago
eventEntities.js
1 year ago
eventWaitingListOptions.js
1 year ago
pagination.js
3 years ago
params.js
1 year ago
payment.js
2 years ago
persons.js
1 year ago
recurring.js
1 year ago
shortcodeParams.js
2 years ago
tickets.js
1 year ago
entities.js
791 lines
| 1 | import httpClient from "../../plugins/axios.js"; |
| 2 | import { |
| 3 | settings, |
| 4 | shortLocale, |
| 5 | longLocale |
| 6 | } from "../../plugins/settings.js"; |
| 7 | import {useUrlParams, useUrlQueryParams} from "../../assets/js/common/helper"; |
| 8 | import { getBadgeTranslated, useTranslateEntities } from "../../assets/js/public/translation"; |
| 9 | import { useParsedCustomPricing } from "../../assets/js/common/employee"; |
| 10 | |
| 11 | function isEmployeeServiceLocation (relations, employeeId, serviceId, locationId = null) { |
| 12 | if (locationId) { |
| 13 | return employeeId in relations && serviceId in relations[employeeId] && relations[employeeId][serviceId].indexOf(locationId) !== -1 |
| 14 | } |
| 15 | |
| 16 | return employeeId in relations && serviceId in relations[employeeId] |
| 17 | } |
| 18 | |
| 19 | function setLiteService () { |
| 20 | return { |
| 21 | extras: [], |
| 22 | maxCapacity: 1, |
| 23 | minCapacity: 1, |
| 24 | timeAfter: '', |
| 25 | timeBefore: '', |
| 26 | bringingAnyone: false, |
| 27 | aggregatedPrice: true, |
| 28 | settings: null, |
| 29 | recurringCycle: 'disabled', |
| 30 | recurringSub: 'future', |
| 31 | recurringPayment: 0, |
| 32 | deposit: 0, |
| 33 | depositPayment: 'disabled', |
| 34 | depositPerPerson: 1, |
| 35 | fullPayment: false, |
| 36 | translations: null, |
| 37 | minSelectedExtras: null, |
| 38 | mandatoryExtra: false |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | function setStarterService () { |
| 43 | return { |
| 44 | timeAfter: '', |
| 45 | timeBefore: '', |
| 46 | deposit: 0, |
| 47 | depositPayment: 'disabled', |
| 48 | depositPerPerson: 1, |
| 49 | fullPayment: false, |
| 50 | translations: null |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | function useLiteEntities (entities) { |
| 55 | entities.categories.forEach((category, categoryIndex) => { |
| 56 | category.serviceList.forEach((service, serviceIndex) => { |
| 57 | entities.categories[categoryIndex].serviceList[serviceIndex] = Object.assign( |
| 58 | service, |
| 59 | setLiteService() |
| 60 | ) |
| 61 | }) |
| 62 | }) |
| 63 | |
| 64 | entities.employees.forEach((employee, employeeIndex) => { |
| 65 | employee.serviceList.forEach((service, serviceIndex) => { |
| 66 | entities.employees[employeeIndex].serviceList[serviceIndex] = Object.assign( |
| 67 | service, |
| 68 | setLiteService() |
| 69 | ) |
| 70 | }) |
| 71 | }) |
| 72 | |
| 73 | entities.packages = [] |
| 74 | entities.locations = [] |
| 75 | entities.customFields = [] |
| 76 | |
| 77 | return entities |
| 78 | } |
| 79 | |
| 80 | function useStarterEntities (entities) { |
| 81 | entities.categories.forEach((category, categoryIndex) => { |
| 82 | category.serviceList.forEach((service, serviceIndex) => { |
| 83 | entities.categories[categoryIndex].serviceList[serviceIndex] = Object.assign( |
| 84 | service, |
| 85 | setStarterService() |
| 86 | ) |
| 87 | }) |
| 88 | }) |
| 89 | |
| 90 | entities.employees.forEach((employee, employeeIndex) => { |
| 91 | employee.serviceList.forEach((service, serviceIndex) => { |
| 92 | entities.employees[employeeIndex].serviceList[serviceIndex] = Object.assign( |
| 93 | service, |
| 94 | setStarterService() |
| 95 | ) |
| 96 | }) |
| 97 | }) |
| 98 | |
| 99 | entities.packages = [] |
| 100 | entities.locations = [] |
| 101 | entities.customFields = [] |
| 102 | |
| 103 | return entities |
| 104 | } |
| 105 | |
| 106 | function setEntities ({ commit, rootState }, entities, types, licence, showHidden) { |
| 107 | commit('setShowHidden', showHidden) |
| 108 | |
| 109 | let availableTranslationsShort = settings.general.usedLanguages.map( |
| 110 | key => key.length > 2 ? key.slice(0, 2) : key |
| 111 | ) |
| 112 | |
| 113 | if (licence.isLite) { |
| 114 | entities = useLiteEntities(entities) |
| 115 | } |
| 116 | |
| 117 | if (licence.isStarter) { |
| 118 | entities = useStarterEntities(entities) |
| 119 | } |
| 120 | |
| 121 | if (settings.general.usedLanguages.indexOf(longLocale) !== -1 || |
| 122 | availableTranslationsShort.indexOf(shortLocale) !== -1 |
| 123 | ) { |
| 124 | useTranslateEntities(entities) |
| 125 | |
| 126 | rootState.settings.roles.providerBadges.badges.forEach(badge => { |
| 127 | badge.content = getBadgeTranslated(badge) |
| 128 | }) |
| 129 | } |
| 130 | |
| 131 | types.forEach(ent => { |
| 132 | if (!(ent in entities)) { |
| 133 | entities[ent] = [] |
| 134 | } |
| 135 | |
| 136 | if (ent === 'categories') { |
| 137 | if (settings.activation.stash) { |
| 138 | entities[ent].sort((a, b) => a.position - b.position) |
| 139 | } |
| 140 | |
| 141 | entities[ent].forEach((category, categoryIndex) => { |
| 142 | if (settings.activation.stash) { |
| 143 | category.serviceList.sort((a, b) => a.position - b.position) |
| 144 | } |
| 145 | category.serviceList.forEach((service, serviceIndex) => { |
| 146 | entities[ent][categoryIndex].serviceList[serviceIndex].customPricing = useParsedCustomPricing(service) |
| 147 | }) |
| 148 | }) |
| 149 | } |
| 150 | |
| 151 | if (ent === 'employees') { |
| 152 | let arr = [] |
| 153 | entities[ent].forEach((employee, employeeIndex) => { |
| 154 | employee.serviceList.forEach((employeeService, serviceIndex) => { |
| 155 | let service = entities.categories.find( |
| 156 | c => c.serviceList.filter(s => parseInt(s.id) === parseInt(employeeService.id)).length |
| 157 | ).serviceList.find(s => parseInt(s.id) === parseInt(employeeService.id)) |
| 158 | |
| 159 | let employeePrice = entities[ent][employeeIndex].serviceList[serviceIndex].price |
| 160 | let employeeMinCapacity = entities[ent][employeeIndex].serviceList[serviceIndex].minCapacity |
| 161 | let employeeMaxCapacity = entities[ent][employeeIndex].serviceList[serviceIndex].maxCapacity |
| 162 | |
| 163 | entities[ent][employeeIndex].serviceList[serviceIndex] = JSON.parse(JSON.stringify(service)) |
| 164 | |
| 165 | entities[ent][employeeIndex].serviceList[serviceIndex].price = employeePrice |
| 166 | entities[ent][employeeIndex].serviceList[serviceIndex].minCapacity = employeeMinCapacity |
| 167 | entities[ent][employeeIndex].serviceList[serviceIndex].maxCapacity = employeeMaxCapacity |
| 168 | |
| 169 | entities[ent][employeeIndex].serviceList[serviceIndex].customPricing = useParsedCustomPricing( |
| 170 | employeeService.customPricing ? employeeService : service |
| 171 | ) |
| 172 | }) |
| 173 | |
| 174 | if (employee.badgeId) { |
| 175 | employee.badge = rootState.settings.roles.providerBadges.badges.find(badge => badge.id === employee.badgeId) |
| 176 | } else { |
| 177 | employee.badge = null |
| 178 | } |
| 179 | |
| 180 | if (showHidden || employee.status !== 'hidden') { |
| 181 | arr.push(employee) |
| 182 | } |
| 183 | }) |
| 184 | commit('setUnfilteredEmployees', arr) |
| 185 | } |
| 186 | |
| 187 | if (ent === 'locations') { |
| 188 | let arr = [] |
| 189 | entities[ent].forEach((location) => { |
| 190 | if (showHidden || location.status !== 'hidden') { |
| 191 | arr.push(location) |
| 192 | } |
| 193 | }) |
| 194 | commit('setUnfilteredLocations', arr) |
| 195 | } |
| 196 | |
| 197 | commit( |
| 198 | 'set' + ent.charAt(0).toUpperCase() + ent.slice(1), |
| 199 | ent === 'customFields' ? entities['customFields'].sort(function(a, b) { |
| 200 | return ((a['position'] < b['position']) ? -1 : ((a['position'] > b['position']) ? 1 : 0)); |
| 201 | }) : entities[ent] |
| 202 | ) |
| 203 | }) |
| 204 | |
| 205 | commit('setPreselectedFromUrl') |
| 206 | commit('setPreselectedValues') |
| 207 | commit('setReady', true) |
| 208 | } |
| 209 | |
| 210 | function getEntitiesVariableName () { |
| 211 | return 'ameliaAppointmentEntities' in window |
| 212 | ? 'ameliaAppointmentEntities' |
| 213 | : ('ameliaEntities' in window ? 'ameliaEntities' : false) |
| 214 | } |
| 215 | |
| 216 | export default { |
| 217 | namespaced: true, |
| 218 | |
| 219 | state: () => ({ |
| 220 | settings: [], |
| 221 | taxes: [], |
| 222 | categories: [], |
| 223 | services: [], |
| 224 | employees: [], |
| 225 | unfilteredEmployees: [], |
| 226 | locations: [], |
| 227 | unfilteredLocations: [], |
| 228 | packages: [], |
| 229 | entitiesRelations: {}, |
| 230 | customFields: [], |
| 231 | tags: [], |
| 232 | spaces: [], |
| 233 | ready: false, |
| 234 | showHidden: false, |
| 235 | originalPreselected: {}, |
| 236 | preselected: {} |
| 237 | }), |
| 238 | |
| 239 | getters: { |
| 240 | getSettings (state) { |
| 241 | return state.settings |
| 242 | }, |
| 243 | |
| 244 | getSpaces (state) { |
| 245 | return state.spaces |
| 246 | }, |
| 247 | |
| 248 | getEntitiesRelations (state) { |
| 249 | return state.entitiesRelations |
| 250 | }, |
| 251 | |
| 252 | getOriginalPreselected (state) { |
| 253 | return JSON.parse(JSON.stringify(state.originalPreselected)) |
| 254 | }, |
| 255 | |
| 256 | getPreselected (state) { |
| 257 | return state.preselected |
| 258 | }, |
| 259 | |
| 260 | getTaxes (state) { |
| 261 | return state.taxes |
| 262 | }, |
| 263 | |
| 264 | getTax: (state) => (id) => { |
| 265 | return state.taxes.find(i => parseInt(i.id) === parseInt(id)) || null |
| 266 | }, |
| 267 | |
| 268 | getCategories (state) { |
| 269 | return state.categories |
| 270 | }, |
| 271 | |
| 272 | getCategory: (state) => (id) => { |
| 273 | return state.categories.find(i => parseInt(i.id) === parseInt(id)) || null |
| 274 | }, |
| 275 | |
| 276 | getPackages (state) { |
| 277 | return state.packages |
| 278 | }, |
| 279 | |
| 280 | getPackage: (state) => (id) => { |
| 281 | return state.packages.find(i => parseInt(i.id) === parseInt(id)) || null |
| 282 | }, |
| 283 | |
| 284 | getServices (state) { |
| 285 | return state.services |
| 286 | }, |
| 287 | |
| 288 | getService: (state) => (id) => { |
| 289 | return state.services.find(i => parseInt(i.id) === parseInt(id)) || null |
| 290 | }, |
| 291 | |
| 292 | getUnfilteredEmployees (state) { |
| 293 | return state.unfilteredEmployees |
| 294 | }, |
| 295 | |
| 296 | getUnfilteredEmployee: (state) => (id) => { |
| 297 | return state.unfilteredEmployees.find(a => parseInt(a.id) === parseInt(id)) || null |
| 298 | }, |
| 299 | |
| 300 | getEmployees (state) { |
| 301 | return state.employees |
| 302 | }, |
| 303 | |
| 304 | getEmployee: (state) => (id) => { |
| 305 | return state.employees.find(i => parseInt(i.id) === parseInt(id)) || null |
| 306 | }, |
| 307 | |
| 308 | getEmployeeService: (state) => (providerId, serviceId) => { |
| 309 | return state.employees.find( |
| 310 | i => parseInt(i.id) === parseInt(providerId) |
| 311 | ).serviceList.find( |
| 312 | i => parseInt(i.id) === parseInt(serviceId) |
| 313 | ) |
| 314 | }, |
| 315 | |
| 316 | getUnfilteredLocations (state) { |
| 317 | return state.unfilteredLocations |
| 318 | }, |
| 319 | |
| 320 | getUnfilteredLocation: (state) => (id) => { |
| 321 | return state.unfilteredLocations.find(i => parseInt(i.id) === parseInt(id)) || null |
| 322 | }, |
| 323 | |
| 324 | getLocations (state) { |
| 325 | return state.locations |
| 326 | }, |
| 327 | |
| 328 | getLocation: (state) => (id) => { |
| 329 | return state.locations.find(i => parseInt(i.id) === parseInt(id)) || null |
| 330 | }, |
| 331 | |
| 332 | getTags (state) { |
| 333 | return state.tags |
| 334 | }, |
| 335 | |
| 336 | getCustomFields (state) { |
| 337 | return state.customFields |
| 338 | }, |
| 339 | |
| 340 | getCustomField: (state) => (id) => { |
| 341 | return state.customFields.find(i => parseInt(i.id) === parseInt(id)) || null |
| 342 | }, |
| 343 | |
| 344 | filteredCategories: (state, getters) => (data) => { |
| 345 | let categories = [] |
| 346 | |
| 347 | let categoriesIds = getters.filteredServices(data).filter(service => !data.serviceId || service.id === data.serviceId).map(service => service.categoryId) |
| 348 | |
| 349 | state.categories.forEach((category) => { |
| 350 | if (categoriesIds.indexOf(category.id) !== -1) { |
| 351 | let availableCategory = Object.assign( |
| 352 | {}, |
| 353 | category |
| 354 | ) |
| 355 | availableCategory.serviceList = getters.filteredServices(data).filter(service => service.categoryId === category.id) |
| 356 | categories.push(availableCategory) |
| 357 | } |
| 358 | }) |
| 359 | |
| 360 | return categories |
| 361 | }, |
| 362 | |
| 363 | filteredServices: (state, getters) => (data) => { |
| 364 | return state.services.filter(service => |
| 365 | (!data.categoryId ? true : service.categoryId === data.categoryId) && |
| 366 | (!data.providerId ? true : isEmployeeServiceLocation(state.entitiesRelations, data.providerId, service.id)) && |
| 367 | (!data.locationId ? true : |
| 368 | getters.filteredEmployees(data).filter( |
| 369 | employee => isEmployeeServiceLocation(state.entitiesRelations, employee.id, service.id, data.locationId) |
| 370 | ).length > 0 |
| 371 | ) |
| 372 | ) |
| 373 | }, |
| 374 | |
| 375 | filteredPackagesPreselected: (state, getters) => () => { |
| 376 | let preselected = getters.getOriginalPreselected |
| 377 | return state.packages.filter(pack => |
| 378 | (preselected.service.length === 0 ? true : |
| 379 | pack.bookable.filter( |
| 380 | b => preselected.service.map(s => parseInt(s)).includes(b.service.id) |
| 381 | ).length > 0) |
| 382 | && (preselected.employee.length === 0 ? true : |
| 383 | pack.bookable.filter( |
| 384 | b => b.providers.length ? b.providers.find(p => preselected.employee.includes(p.id)) : |
| 385 | preselected.employee.map(e => parseInt(e)).filter(provider => isEmployeeServiceLocation(state.entitiesRelations, provider, b.service.id)).length > 0 |
| 386 | ).length === pack.bookable.length) |
| 387 | && (preselected.category.length === 0 ? true : |
| 388 | pack.bookable.filter( |
| 389 | b => preselected.category.map(c => parseInt(c)).includes(b.service.categoryId) |
| 390 | ).length === pack.bookable.length) |
| 391 | && (preselected.location.length === 0 ? true : |
| 392 | pack.bookable.filter( |
| 393 | b => (b.locations.length ? b.locations.find(l => preselected.location.map(l => parseInt(l)).includes(l.id)) : ( |
| 394 | (b.providers.length > 0 ? b.providers : state.employees).filter( |
| 395 | employee => |
| 396 | preselected.location.map(l => parseInt(l)).filter(l => isEmployeeServiceLocation(state.entitiesRelations, employee.id, b.service.id, l)).length > 0 |
| 397 | ).length > 0 |
| 398 | )) |
| 399 | ).length === pack.bookable.length) |
| 400 | ) |
| 401 | }, |
| 402 | |
| 403 | filteredPackages: (state, getters) => (data) => { |
| 404 | let packagesFiltered = getters.filteredPackagesPreselected() |
| 405 | |
| 406 | return packagesFiltered.filter(pack => |
| 407 | (state.showHidden || pack.status === 'visible') |
| 408 | && pack.bookable.length |
| 409 | && pack.available |
| 410 | && (!data.serviceId ? true : |
| 411 | pack.bookable.filter( |
| 412 | b => b.service.id === data.serviceId |
| 413 | ).length > 0) |
| 414 | && (!data.providerId ? true : |
| 415 | pack.bookable.filter( |
| 416 | b => b.providers.length ? b.providers.find(p => data.providerId === p.id) : isEmployeeServiceLocation(state.entitiesRelations, data.providerId, b.service.id) |
| 417 | ).length === pack.bookable.length) |
| 418 | && (!data.categoryId ? true : |
| 419 | ( |
| 420 | state.originalPreselected.category.length |
| 421 | ? pack.bookable.filter( |
| 422 | b => b.service.categoryId === data.categoryId |
| 423 | ).length === pack.bookable.length |
| 424 | : pack.bookable.filter( |
| 425 | b => b.service.categoryId === data.categoryId |
| 426 | ).length > 0 |
| 427 | ) |
| 428 | ) |
| 429 | && (!data.locationId ? true : |
| 430 | pack.bookable.filter( |
| 431 | b => (b.locations.length ? b.locations.find(l => data.locationId === l.id) : ( |
| 432 | (b.providers.length > 0 ? b.providers : getters.filteredEmployees(data)).filter( |
| 433 | employee => isEmployeeServiceLocation(state.entitiesRelations, employee.id, b.service.id, data.locationId) |
| 434 | ).length > 0 |
| 435 | )) |
| 436 | ).length === pack.bookable.length) |
| 437 | ) |
| 438 | }, |
| 439 | |
| 440 | filteredLocations: (state, getters) => (data) => { |
| 441 | return state.locations.filter(location => |
| 442 | (!data.providerId ? true : |
| 443 | state.employees.length ? state.employees.find(i => i.id === data.providerId).serviceList.filter( |
| 444 | employeeService => { |
| 445 | return (state.showHidden || employeeService.status === 'visible') && |
| 446 | isEmployeeServiceLocation(state.entitiesRelations, data.providerId, employeeService.id, location.id) |
| 447 | }).length > 0 : false |
| 448 | ) && |
| 449 | (!data.serviceId || data.packageId ? true : |
| 450 | getters.filteredEmployees(data).find( |
| 451 | employee => isEmployeeServiceLocation(state.entitiesRelations, employee.id, data.serviceId, location.id) |
| 452 | ) !== undefined |
| 453 | ) && |
| 454 | (!data.packageId ? true : |
| 455 | state.packages.find(i => i.id === data.packageId).bookable.filter((book) => { |
| 456 | return book.locations.length ? book.locations.find(l => l.id === location.id) : |
| 457 | (getters.filteredEmployees(data).filter( |
| 458 | employee => isEmployeeServiceLocation(state.entitiesRelations, employee.id, book.service.id, location.id) |
| 459 | ).length > 0) |
| 460 | }).length > 0 |
| 461 | ) |
| 462 | ) |
| 463 | }, |
| 464 | |
| 465 | filteredEmployees: (state) => (data) => { |
| 466 | return state.employees.filter(employee => |
| 467 | employee.serviceList.find( |
| 468 | service => |
| 469 | (state.showHidden || service.status === 'visible') && |
| 470 | // service.maxCapacity >= data.persons && |
| 471 | (!data.serviceId ? true : isEmployeeServiceLocation(state.entitiesRelations, employee.id, service.id) && service.id === data.serviceId) && |
| 472 | (!data.locationId ? true : isEmployeeServiceLocation(state.entitiesRelations, employee.id, service.id, data.locationId)) |
| 473 | ) !== undefined |
| 474 | ) |
| 475 | }, |
| 476 | |
| 477 | getEmployeeServices: (state, getters) => (data) => { |
| 478 | let employeeServices = [] |
| 479 | |
| 480 | if (data.serviceId) { |
| 481 | let service = getters.getService(data.serviceId) |
| 482 | if (data.providerId) { |
| 483 | let possibleEmployee = state.employees.find(i => i.id === data.providerId) |
| 484 | if (!possibleEmployee) return {} |
| 485 | let employeeService = possibleEmployee.serviceList.filter(service => service.id === data.serviceId) |
| 486 | return employeeService.map(eS => Object.assign(eS, {bringingAnyone: service.bringingAnyone, aggregatedPrice: service.aggregatedPrice, maxExtraPeople: service.maxExtraPeople})) |
| 487 | } |
| 488 | |
| 489 | getters.filteredEmployees(data).forEach((employee) => { |
| 490 | employee.serviceList.forEach((employeeService) => { |
| 491 | if (employeeService.id === data.serviceId) { |
| 492 | employeeServices.push(Object.assign(employeeService, {bringingAnyone: service.bringingAnyone, aggregatedPrice: service.aggregatedPrice, maxExtraPeople: service.maxExtraPeople})) |
| 493 | } |
| 494 | }) |
| 495 | }) |
| 496 | } |
| 497 | |
| 498 | return employeeServices |
| 499 | }, |
| 500 | |
| 501 | getBookableFromBookableEntities: (state) => (data) => { |
| 502 | switch (data.type) { |
| 503 | case ('appointment'): |
| 504 | return state.services.find(i => i.id === data.serviceId) |
| 505 | case ('package'): |
| 506 | return state.packages.find(i => i.id === data.packageId) |
| 507 | } |
| 508 | }, |
| 509 | |
| 510 | getReady (state) { |
| 511 | return state.ready |
| 512 | }, |
| 513 | |
| 514 | getShowHidden (state) { |
| 515 | return state.showHidden |
| 516 | }, |
| 517 | |
| 518 | getPackageEntities: (state, getters) => (packageId) => { |
| 519 | let entities = {services: [], providers: [], locations: [], packages: []} |
| 520 | let pack = getters.getPackage(packageId) |
| 521 | if (pack) { |
| 522 | pack.bookable.forEach(bookable => { |
| 523 | entities.services.push(bookable.service.id) |
| 524 | let employees = [] |
| 525 | if (bookable.providers.length > 0) { |
| 526 | employees = bookable.providers.map(p => p.id) |
| 527 | } else { |
| 528 | employees = state.employees.filter(e => e.serviceList.find(s => s.id === bookable.service.id)).map(e => e.id) |
| 529 | } |
| 530 | entities.providers = entities.providers.concat(employees) |
| 531 | let locations = [] |
| 532 | if (bookable.locations.length > 0) { |
| 533 | locations = bookable.locations.map(p => p.id) |
| 534 | } else { |
| 535 | state.locations.forEach(location => |
| 536 | employees.forEach(e => { |
| 537 | if (isEmployeeServiceLocation(state.entitiesRelations, e, bookable.service.id, location.id)) { |
| 538 | locations.push(location.id) |
| 539 | } |
| 540 | }) |
| 541 | ) |
| 542 | } |
| 543 | entities.locations = entities.locations.concat(locations) |
| 544 | }) |
| 545 | |
| 546 | entities.packages.push(pack.id) |
| 547 | } |
| 548 | return entities |
| 549 | } |
| 550 | }, |
| 551 | |
| 552 | mutations: { |
| 553 | setSettings (state, payload) { |
| 554 | state.settings = payload |
| 555 | }, |
| 556 | |
| 557 | setSpaces (state, payload) { |
| 558 | state.spaces = payload |
| 559 | }, |
| 560 | |
| 561 | setTaxes (state, payload) { |
| 562 | state.taxes = payload |
| 563 | }, |
| 564 | |
| 565 | setCategories (state, payload) { |
| 566 | state.categories = payload |
| 567 | |
| 568 | let services = [] |
| 569 | |
| 570 | state.categories.forEach((category) => { |
| 571 | category.serviceList.forEach((service) => { |
| 572 | services.push(service) |
| 573 | }) |
| 574 | }) |
| 575 | |
| 576 | state.services = services |
| 577 | }, |
| 578 | |
| 579 | setUnfilteredEmployees (state, payload) { |
| 580 | state.unfilteredEmployees = payload |
| 581 | }, |
| 582 | |
| 583 | setUnfilteredLocations (state, payload) { |
| 584 | state.unfilteredLocations = payload |
| 585 | }, |
| 586 | |
| 587 | setEmployees (state, payload) { |
| 588 | state.employees = payload |
| 589 | }, |
| 590 | |
| 591 | setLocations (state, payload) { |
| 592 | state.locations = payload |
| 593 | }, |
| 594 | |
| 595 | setTags (state, payload) { |
| 596 | state.tags = payload |
| 597 | }, |
| 598 | |
| 599 | setPackages (state, payload) { |
| 600 | payload.forEach(pack => { |
| 601 | let isAvailable = true |
| 602 | |
| 603 | pack.bookable.forEach(book => { |
| 604 | if (!book.service.name) { |
| 605 | let service = state.services.find(s => s.id === book.service.id) |
| 606 | if (service) { |
| 607 | book.service = service |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | if (state.showHidden ? false : book.service.status !== 'visible') { |
| 612 | isAvailable = false |
| 613 | } |
| 614 | }) |
| 615 | |
| 616 | if (isAvailable) { |
| 617 | state.packages.push(pack) |
| 618 | } |
| 619 | }) |
| 620 | |
| 621 | state.packages.sort((a, b) => a.position - b.position) |
| 622 | }, |
| 623 | |
| 624 | setCustomFields (state, payload) { |
| 625 | state.customFields = [...Object.values(payload)] |
| 626 | }, |
| 627 | |
| 628 | setEntitiesRelations (state, payload) { |
| 629 | state.entitiesRelations = payload |
| 630 | }, |
| 631 | |
| 632 | setReady (state, payload) { |
| 633 | state.ready = payload |
| 634 | }, |
| 635 | |
| 636 | setShowHidden (state, payload) { |
| 637 | state.showHidden = payload |
| 638 | }, |
| 639 | |
| 640 | setPreselected (state, payload) { |
| 641 | state.preselected = payload |
| 642 | state.preselected = Object.assign({}, state.preselected, |
| 643 | {category: Array.isArray(state.preselected.category) ? state.preselected.category : (state.preselected.category ? state.preselected.category.toString().split(',').map(c=>parseInt(c)) : []), |
| 644 | service: Array.isArray(state.preselected.service) ? state.preselected.service : (state.preselected.service ? state.preselected.service.toString().split(',').map(c=>parseInt(c)) : []), |
| 645 | employee: Array.isArray(state.preselected.employee) ? state.preselected.employee : (state.preselected.employee ? state.preselected.employee.toString().split(',').map(c=>parseInt(c)) : []), |
| 646 | location: Array.isArray(state.preselected.location) ? state.preselected.location : (state.preselected.location ? state.preselected.location.toString().split(',').map(c=>parseInt(c)) : []), |
| 647 | package: Array.isArray(state.preselected.package) ? state.preselected.package : (state.preselected.package ? state.preselected.package.toString().split(',').map(c=>parseInt(c)) : []) |
| 648 | }) |
| 649 | }, |
| 650 | |
| 651 | setPreselectedFromUrl (state) { |
| 652 | let urlParameters = useUrlQueryParams(window.location.href) |
| 653 | if (urlParameters) { |
| 654 | if (urlParameters.ameliaServiceId) { |
| 655 | state.preselected.service = urlParameters.ameliaServiceId.split(',').map(a => parseInt(a)) |
| 656 | } |
| 657 | if (urlParameters.ameliaEmployeeId) { |
| 658 | state.preselected.employee = urlParameters.ameliaEmployeeId.split(',').map(a => parseInt(a)) |
| 659 | } |
| 660 | if (urlParameters.ameliaLocationId) { |
| 661 | state.preselected.location = urlParameters.ameliaLocationId.split(',').map(a => parseInt(a)) |
| 662 | } |
| 663 | if (urlParameters.ameliaCategoryId) { |
| 664 | state.preselected.category = urlParameters.ameliaCategoryId.split(',').map(a => parseInt(a)) |
| 665 | } |
| 666 | } |
| 667 | }, |
| 668 | |
| 669 | setPreselectedValues (state) { |
| 670 | state.originalPreselected = JSON.parse(JSON.stringify(state.preselected)) |
| 671 | |
| 672 | state.employees = state.employees.filter(e => state.showHidden || e.status === 'visible') |
| 673 | state.services = state.services.filter(s => (state.showHidden ? true : s.status === 'visible' && s.show) && state.employees.filter(e => e.serviceList.find(eS => eS.id === s.id)).length) |
| 674 | state.locations = state.locations.filter(l => state.showHidden || l.status === 'visible') |
| 675 | |
| 676 | if ('category' in state.preselected && state.preselected.category.length > 0) { |
| 677 | state.categories = state.categories.filter(c => state.preselected.category.map(id => parseInt(id)).includes(c.id)) |
| 678 | state.services = state.services.filter(s => state.preselected.category.map(id => parseInt(id)).includes(s.categoryId)) |
| 679 | state.employees = state.employees.filter(e => e.serviceList.filter(s => state.preselected.category.map(id => parseInt(id)).includes(s.categoryId)).length > 0) |
| 680 | state.locations = state.locations.filter(l => |
| 681 | state.employees.filter(e => |
| 682 | state.services.filter(s => isEmployeeServiceLocation(state.entitiesRelations, e.id, s.id, l.id) && state.preselected.category.map(id => parseInt(id)).includes(s.categoryId)).length > 0 |
| 683 | ).length > 0 |
| 684 | ) |
| 685 | } |
| 686 | |
| 687 | if ('service' in state.preselected && state.preselected.service.length > 0) { |
| 688 | state.services = state.services.filter(s => state.preselected.service.map(id => parseInt(id)).includes(s.id)) |
| 689 | state.categories = state.categories.filter(c => state.services.map(serv => serv.categoryId).includes(c.id)) |
| 690 | state.employees = state.employees.filter(e => e.serviceList.filter(s => state.preselected.service.map(id => parseInt(id)).includes(s.id)).length > 0) |
| 691 | state.locations = state.locations.filter(l => |
| 692 | state.employees.filter(e => state.preselected.service |
| 693 | .filter(serviceId => |
| 694 | isEmployeeServiceLocation(state.entitiesRelations, e.id, parseInt(serviceId), l.id) |
| 695 | ).length > 0 |
| 696 | ).length > 0 |
| 697 | ) |
| 698 | } |
| 699 | |
| 700 | if ('employee' in state.preselected && state.preselected.employee.length > 0) { |
| 701 | state.employees = state.employees.filter(e => state.preselected.employee.map(id => parseInt(id)).includes(e.id)) |
| 702 | if (state.employees.length > 0) { |
| 703 | state.services = state.services.filter(s => state.employees.filter(e => e.serviceList.filter(serv => serv.id === s.id).length > 0).length > 0) |
| 704 | |
| 705 | state.categories = state.categories.filter(c => state.services.filter(s => s.categoryId === c.id).length > 0) |
| 706 | state.locations = state.locations.filter(l => |
| 707 | state.services.filter(s => state.preselected.employee |
| 708 | .filter(employeeId => |
| 709 | isEmployeeServiceLocation(state.entitiesRelations, parseInt(employeeId), s.id, l.id) |
| 710 | ).length > 0 |
| 711 | ).length > 0 |
| 712 | ) |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | if ('location' in state.preselected && state.preselected.location.length > 0) { |
| 717 | state.locations = state.locations.filter(e => state.preselected.location.map(id => parseInt(id)).includes(e.id)) |
| 718 | state.employees = state.employees.filter(e => e.serviceList.filter( |
| 719 | s => state.preselected.location |
| 720 | .filter(locationId => |
| 721 | isEmployeeServiceLocation(state.entitiesRelations, e.id, s.id, parseInt(locationId)) |
| 722 | ).length > 0 |
| 723 | ).length > 0) |
| 724 | state.services = state.services.filter(s => state.employees.filter(e => e.serviceList.filter(serv => serv.id === s.id).length > 0).length > 0) |
| 725 | state.categories = state.categories.filter(c => state.services.filter(s => s.categoryId === c.id).length > 0) |
| 726 | } |
| 727 | |
| 728 | if ('package' in state.preselected && state.preselected.package.length > 0) { |
| 729 | state.packages = state.packages.filter(p => state.preselected.package.map(id => parseInt(id)).includes(p.id)) |
| 730 | state.preselected.show = 'packages' |
| 731 | state.services = state.services.filter(s => state.packages.filter(p => p.bookable.filter(b => b.service.id === s.id).length > 0).length > 0) |
| 732 | state.categories = state.categories.filter(c => state.services.filter(s => s.categoryId === c.id).length > 0) |
| 733 | } |
| 734 | |
| 735 | if (state.services.length === 1 && state.preselected.show !== 'packages') { |
| 736 | state.preselected = Object.assign({}, state.preselected, {service: [(state.services[0].id).toString()]}) |
| 737 | } |
| 738 | if (state.categories.length === 1 && state.preselected.show !== 'packages') { |
| 739 | state.preselected = Object.assign({}, state.preselected, {category: [(state.categories[0].id).toString()]}) |
| 740 | } |
| 741 | if (state.employees.length === 1 && state.preselected.show !== 'packages') { |
| 742 | state.preselected = Object.assign({}, state.preselected, {employee: [(state.employees[0].id).toString()]}) |
| 743 | } |
| 744 | if (state.locations.length === 1 && state.preselected.show !== 'packages') { |
| 745 | state.preselected = Object.assign({}, state.preselected, {location: [(state.locations[0].id).toString()]}) |
| 746 | } |
| 747 | |
| 748 | |
| 749 | // if all employees have the same price |
| 750 | state.services.forEach(s => { |
| 751 | let services = state.employees.map(e => e.serviceList.filter(service => service.id === s.id)).flat() |
| 752 | let samePrice = services.every(service => service.price === services[0].price) |
| 753 | if (services.length && samePrice) { |
| 754 | s.price = services[0].price |
| 755 | } |
| 756 | }) |
| 757 | }, |
| 758 | }, |
| 759 | |
| 760 | actions: { |
| 761 | getEntities ({ commit, rootState }, payload) { |
| 762 | let types = payload.types |
| 763 | |
| 764 | if (payload.loadEntities && (payload.isPanel || !getEntitiesVariableName())) { |
| 765 | httpClient.get('/entities', { params: useUrlParams({types: types, page: 'booking', lite: true}) }).then(response => { |
| 766 | window.ameliaAppointmentEntities = response.data.data |
| 767 | |
| 768 | let entities = JSON.parse(JSON.stringify(window.ameliaAppointmentEntities)) |
| 769 | |
| 770 | setEntities({ commit, rootState }, entities, types, payload.licence, payload.showHidden) |
| 771 | }) |
| 772 | } else { |
| 773 | let ameliaApiInterval = setInterval( |
| 774 | () => { |
| 775 | let name = getEntitiesVariableName() |
| 776 | |
| 777 | if (name) { |
| 778 | clearInterval(ameliaApiInterval) |
| 779 | |
| 780 | let entities = JSON.parse(JSON.stringify(window[name])) |
| 781 | |
| 782 | setEntities({ commit, rootState }, entities, types, payload.licence, payload.showHidden) |
| 783 | } |
| 784 | }, |
| 785 | 1000 |
| 786 | ) |
| 787 | } |
| 788 | } |
| 789 | }, |
| 790 | } |
| 791 |