PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
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 / common / recurring.js
ameliabooking / v3 / src / assets / js / common Last commit date
appointments.js 1 month ago attendees.js 1 month ago colorManipulation.js 1 month ago customer.js 1 month ago date.js 3 weeks ago defaultCustomize.js 3 weeks ago employee.js 6 days ago events.js 1 month ago formFieldsTemplates.js 1 month ago formatting.js 1 month ago helper.js 6 days ago image.js 1 month ago integrationApple.js 1 month ago integrationGoogle.js 1 month ago integrationOutlook.js 1 month ago integrationStripe.js 1 month ago integrationZoom.js 1 month ago licence.js 1 month ago liveAnnouncer.js 3 weeks ago phone.js 3 weeks ago pricing.js 1 month ago recurring.js 6 days ago responsive.js 1 month ago scrollElements.js 1 month ago settings.js 1 month ago translationsElementPlus.js 1 month ago utilHeaderHeight.js 1 month ago
recurring.js
261 lines
1 import moment from 'moment'
2 import { useSortedDateStrings } from './helper'
3
4 function getFutureMonthDate(dateString, interval) {
5 let date = moment(dateString, 'YYYY-MM-DD')
6 let futureMonthDate = moment(date).add(interval, 'M')
7 let futureMonthDateEnd = moment(futureMonthDate).startOf('month')
8
9 if (
10 date.date() !== futureMonthDate.date() &&
11 futureMonthDate.isSame(futureMonthDateEnd.format('YYYY-MM-DD'))
12 ) {
13 futureMonthDate.subtract(1, 'd')
14 }
15
16 return futureMonthDate
17 }
18
19 function getGivenDateOfMonth(date, monthWeek, weekDay) {
20 let firstWeek = moment(date, 'YYYY-MM-DD').startOf('month').day(weekDay)
21
22 if (firstWeek.format('M') !== date.format('M')) {
23 firstWeek.add(7, 'days')
24 }
25
26 let resultDate = firstWeek.add(7 * (monthWeek - 1), 'days')
27
28 if (date.format('M') !== resultDate.format('M')) {
29 resultDate.subtract(7, 'days')
30 }
31
32 return resultDate
33 }
34
35 function useExpectedDates(
36 lastAvailableDate,
37 startDate,
38 endDate,
39 maxDays,
40 type,
41 interval,
42 weekDays,
43 monthRule,
44 ) {
45 let lastDate = endDate ? moment(endDate) : moment().add(maxDays, 'days')
46
47 let selectedDate = moment(startDate, 'YYYY-MM-DD')
48
49 let expectedDates = {}
50
51 let expectedDatesArray = []
52
53 switch (type) {
54 case 'daily':
55 expectedDatesArray.push(moment(startDate, 'YYYY-MM-DD'))
56
57 break
58
59 case 'weekly':
60 let selectedDateIndex = moment(startDate, 'YYYY-MM-DD').isoWeekday()
61
62 weekDays.forEach((item, index) => {
63 if (item.selected) {
64 let dayIndex = index + 1
65
66 let date = moment(startDate, 'YYYY-MM-DD')
67
68 if (selectedDateIndex < dayIndex) {
69 expectedDatesArray.push(date.add(dayIndex - selectedDateIndex, 'days'))
70 } else if (selectedDateIndex === dayIndex) {
71 expectedDatesArray.push(date)
72 } else if (selectedDateIndex > dayIndex) {
73 expectedDatesArray.push(date.subtract(selectedDateIndex - dayIndex, 'days'))
74 }
75
76 let lDate = lastDate ? lastDate : lastAvailableDate
77 if (date.isSameOrBefore(lDate) && date.isAfter(selectedDate)) {
78 expectedDates[date.format('YYYY-MM-DD')] = date
79 }
80 }
81 })
82
83 break
84
85 case 'monthly':
86 expectedDatesArray.push(moment(startDate, 'YYYY-MM-DD'))
87
88 break
89 }
90
91 let isValidExpected = expectedDatesArray.length > 0
92
93 while (isValidExpected) {
94 for (let i = 0; i < expectedDatesArray.length; i++) {
95 switch (type) {
96 case 'daily':
97 expectedDatesArray[i].add(interval, 'days')
98
99 break
100
101 case 'weekly':
102 expectedDatesArray[i].add(interval * 7, 'days')
103
104 break
105
106 case 'monthly':
107 let weekDayIndex = expectedDatesArray[i].isoWeekday()
108 expectedDatesArray[i] =
109 monthRule === 0
110 ? getFutureMonthDate(expectedDatesArray[i].format('YYYY-MM-DD'), interval)
111 : getGivenDateOfMonth(
112 getFutureMonthDate(
113 expectedDatesArray[i].startOf('month').format('YYYY-MM-DD'),
114 interval,
115 ),
116 monthRule,
117 weekDayIndex,
118 )
119
120 break
121 }
122
123 isValidExpected = expectedDatesArray[i].isSameOrBefore(lastDate)
124
125 if (isValidExpected) {
126 expectedDates[moment(expectedDatesArray[i]).format('YYYY-MM-DD')] = moment(
127 expectedDatesArray[i],
128 )
129 }
130 }
131 }
132
133 return expectedDates
134 }
135
136 function useProposedDates(service, slots, expectedDates, startDate, startTime, endDate, count) {
137 let recurringStartDate = moment(startDate, 'YYYY-MM-DD')
138 let recurringEndDate = endDate ? moment(endDate, 'YYYY-MM-DD') : null
139
140 let proposedDates = {}
141 let availableDates = {}
142
143 useSortedDateStrings(Object.keys(slots)).forEach((dateString) => {
144 availableDates[dateString] = moment(dateString + ' 00:00:00')
145 })
146
147 let bookingStartString = moment(startDate, 'YYYY-MM-DD').format('YYYY-MM-DD')
148
149 for (let expectedDateString in expectedDates) {
150 let expectedDate = moment(expectedDateString, 'YYYY-MM-DD')
151
152 let isBefore = recurringEndDate ? expectedDate.isSameOrBefore(recurringEndDate) : true
153
154 if (
155 expectedDateString in slots &&
156 Object.keys(slots[expectedDateString]).length &&
157 !(expectedDateString in proposedDates) &&
158 isBefore
159 ) {
160 let isAvailableTime = startTime in slots[expectedDateString]
161
162 let expectedTime = isAvailableTime ? startTime : Object.keys(slots[expectedDateString])[0]
163
164 proposedDates[expectedDateString] = {
165 isSubstituteDate: false,
166 isSubstituteTime: !isAvailableTime,
167 time: expectedTime,
168 times: Object.keys(slots[expectedDateString]),
169 slot: slots[expectedDateString][expectedTime],
170 }
171 } else if (
172 expectedDateString !== bookingStartString &&
173 !(expectedDateString in proposedDates) &&
174 isBefore
175 ) {
176 let previousDate = null
177 let nextDate = null
178
179 for (let availableDateString in availableDates) {
180 if (
181 (service.recurringSub === 'past' || service.recurringSub === 'both') &&
182 availableDates[availableDateString].isBefore(expectedDates[expectedDateString]) &&
183 availableDates[availableDateString].isAfter(recurringStartDate) &&
184 availableDateString !== expectedDateString &&
185 !(availableDateString in proposedDates)
186 ) {
187 previousDate = availableDates[availableDateString]
188 }
189
190 if (
191 (service.recurringSub === 'future' || service.recurringSub === 'both') &&
192 availableDates[availableDateString].isAfter(expectedDates[expectedDateString]) &&
193 availableDateString !== expectedDateString &&
194 !(availableDateString in proposedDates)
195 ) {
196 nextDate = availableDates[availableDateString]
197
198 break
199 }
200 }
201
202 let previousDateTimeDiff =
203 previousDate !== null
204 ? moment(expectedDates[expectedDateString]).diff(previousDate, 'days')
205 : null
206
207 let nextDateTimeDiff =
208 nextDate !== null ? moment(nextDate).diff(expectedDates[expectedDateString], 'days') : null
209
210 let substituteDate = null
211
212 if (previousDateTimeDiff && nextDateTimeDiff) {
213 substituteDate = previousDateTimeDiff < nextDateTimeDiff ? previousDate : nextDate
214 } else if (previousDateTimeDiff) {
215 substituteDate = previousDate
216 } else if (nextDateTimeDiff) {
217 substituteDate = nextDate
218 }
219
220 if (
221 substituteDate !== null &&
222 (recurringEndDate ? moment(substituteDate).isSameOrBefore(recurringEndDate) : true)
223 ) {
224 let substituteDateString = moment(substituteDate).format('YYYY-MM-DD')
225
226 if (
227 substituteDateString in slots &&
228 !(expectedDateString in proposedDates) &&
229 !(substituteDateString in expectedDates)
230 ) {
231 let isAvailableTime = startTime in slots[substituteDateString]
232
233 let substituteTime = isAvailableTime
234 ? startTime
235 : Object.keys(slots[substituteDateString])[0]
236
237 proposedDates[substituteDateString] = {
238 isSubstituteDate: true,
239 isSubstituteTime: !isAvailableTime,
240 time: substituteTime,
241 times: Object.keys(slots[substituteDateString]),
242 slot: slots[substituteDateString][substituteTime],
243 }
244 }
245 }
246 }
247
248 if (
249 recurringEndDate
250 ? !isBefore
251 : useSortedDateStrings(Object.keys(proposedDates)).length >= count
252 ) {
253 break
254 }
255 }
256
257 return proposedDates
258 }
259
260 export { useProposedDates, useExpectedDates }
261