PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 / admin / event.js
ameliabooking / v3 / src / assets / js / admin Last commit date
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
event.js
226 lines
1 import moment from 'moment'
2 import { useConvertedUtcToLocalDateTime } from '../common/date'
3 import { getNameTranslated, getTicketTranslated } from '../public/translation'
4 import { useAmount } from '../common/pricing'
5
6 function useParsedEvents(events, timeZone, store) {
7 let eventsDay = {}
8
9 events.forEach((event) => {
10 if (timeZone === '') {
11 event.periods.forEach((period) => {
12 period.periodStart = useConvertedUtcToLocalDateTime(period.periodStart)
13 period.periodEnd = useConvertedUtcToLocalDateTime(period.periodEnd)
14 })
15 }
16
17 let startDate = moment(event.periods[0].periodStart, 'YYYY-MM-DD HH:mm:ss')
18 let dateString = startDate.format('YYYY-MM-DD')
19
20 let availableTranslationsShort = store.getters['getSettings'].general.usedLanguages.map((key) =>
21 key.length > 2 ? key.slice(0, 2) : key,
22 )
23
24 let useTranslations =
25 store.getters['getSettings'].general.usedLanguages.indexOf(
26 store.getters['getLocalLanguage'],
27 ) !== -1 ||
28 availableTranslationsShort.indexOf(store.getters['getLocalLanguage'].split('_')[0]) !== -1
29
30 if (useTranslations) {
31 event.name = getNameTranslated(event)
32
33 event.customTickets.forEach((ticket) => {
34 ticket.name = getTicketTranslated(ticket)
35 })
36 }
37
38 if (event.recurring && event.recurring.until) {
39 event.recurring.until = event.recurring.until.split(' ')[0]
40 }
41
42 if (!(dateString in eventsDay)) {
43 eventsDay[dateString] = {
44 date: dateString,
45 events: [],
46 }
47 }
48
49 let isWaiting = event.bookings.some((booking) => booking.status === 'waiting')
50
51 if (event.full && event.status === 'approved') {
52 event.status = 'full'
53 } else if (event.upcoming && event.status === 'approved') {
54 event.status = 'upcoming'
55 }
56
57 if (isWaiting) {
58 event.status = 'waiting'
59 }
60
61 if (store.getters['auth/getProfile'].type === 'provider') {
62 let clonedEvent = JSON.parse(JSON.stringify(event))
63
64 eventsDay[dateString].events.push(clonedEvent)
65 } else {
66 event.bookings.forEach((booking) => {
67 let clonedEvent = JSON.parse(JSON.stringify(event))
68
69 clonedEvent.bookings = [booking]
70
71 eventsDay[dateString].events.push(clonedEvent)
72 })
73 }
74 })
75
76 return eventsDay
77 }
78
79 function useEventBookingsPrice(event) {
80 let price = 0
81
82 event.bookings.forEach((booking) => {
83 if (['approved', 'pending'].includes(booking.status)) {
84 let subTotal = 0
85
86 if (booking.ticketsData.length > 0) {
87 for (let i = 0; i < booking.ticketsData.length; i++) {
88 subTotal += booking.ticketsData[i].persons * booking.ticketsData[i].price
89 }
90 } else {
91 subTotal += event.price * booking.persons
92 }
93
94 let amountData = useAmount(
95 event,
96 booking.coupon,
97 booking.tax ? booking.tax[0] : null,
98 subTotal,
99 false,
100 )
101
102 price += amountData.price - amountData.discount + amountData.tax
103 }
104 })
105
106 return price >= 0 ? price : 0
107 }
108
109 function usePeriodsData(connectedPeriods) {
110 let result = []
111
112 connectedPeriods.forEach((period) => {
113 let startDate = moment(period.periodStart.split(' ')[0], 'YYYY-MM-DD')
114 let endDate = moment(period.periodEnd.split(' ')[0], 'YYYY-MM-DD')
115
116 let startTime = period.periodStart.split(' ')[1].slice(0, 5)
117 let endTime = period.periodEnd.split(' ')[1].slice(0, 5)
118
119 if (endTime === '00:00') {
120 endTime = '24:00'
121 endDate.subtract(1, 'days')
122 }
123
124 let periodDates = []
125
126 while (startDate.isSameOrBefore(endDate)) {
127 periodDates.push(startDate.format('YYYY-MM-DD'))
128
129 startDate.add(1, 'days')
130 }
131
132 periodDates.forEach((dateString) => {
133 result.push({
134 date: dateString,
135 startTime: startTime,
136 endTime: endTime,
137 periodStart: dateString + ' ' + startTime,
138 periodEnd: dateString + ' ' + endTime,
139 zoomLink:
140 connectedPeriods.length > 1 && period.zoomMeeting ? period.zoomMeeting.joinUrl : '',
141 lessonSpaceLink:
142 connectedPeriods.length > 1 && period.lessonSpace ? period.lessonSpace : '',
143 googleMeetLink:
144 connectedPeriods.length > 1 && period.googleMeetUrl ? period.googleMeetUrl : '',
145 microsoftTeamsLink:
146 connectedPeriods.length > 1 && period.microsoftTeamsUrl ? period.microsoftTeamsUrl : '',
147 })
148 })
149 })
150
151 return result
152 }
153
154 function useTicketsData(event) {
155 let result = {}
156
157 event.bookings.forEach((booking) => {
158 if (
159 ['approved', 'pending'].includes(booking.status) &&
160 booking.ticketsData &&
161 booking.ticketsData.length
162 ) {
163 booking.ticketsData.forEach((ticketData) => {
164 if (!(ticketData.eventTicketId in result)) {
165 result[ticketData.eventTicketId] = {
166 persons: 0,
167 price: ticketData.price,
168 name: event.customTickets.find((i) => i.id === ticketData.eventTicketId).name,
169 }
170 }
171
172 result[ticketData.eventTicketId].persons =
173 result[ticketData.eventTicketId].persons + ticketData.persons
174 })
175 }
176 })
177
178 return result
179 }
180
181 function useEventLocation(store, event) {
182 let locations = store.getters['entities/getLocations']
183
184 if (event.locationId && locations.length) {
185 let location = locations.find((location) => location.id === event.locationId)
186 return typeof location !== 'undefined' ? location : null
187 } else if (event.customLocation) {
188 return {
189 address: '',
190 name: event.customLocation,
191 }
192 }
193
194 return null
195 }
196
197 function useEventQrCodes(event) {
198 let qrCodesArr = []
199
200 event.bookings.forEach((booking) => {
201 if (['approved', 'pending'].includes(booking.status) && booking.qrCodes) {
202 let arr = JSON.parse(booking.qrCodes)
203 arr = arr.map((qr) => {
204 return {
205 ...qr,
206 bookingId: booking.id,
207 eventId: event.id,
208 }
209 })
210
211 qrCodesArr = qrCodesArr.concat(arr)
212 }
213 })
214
215 return qrCodesArr
216 }
217
218 export {
219 useParsedEvents,
220 useEventBookingsPrice,
221 usePeriodsData,
222 useTicketsData,
223 useEventLocation,
224 useEventQrCodes,
225 }
226