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 / pricing.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
pricing.js
145 lines
1 function useAmount(entity, coupon, entityTax, subTotal, includedTaxInTotal) {
2 let excludedTax = entityTax ? entityTax.excluded : false
3
4 let discount = 0
5
6 if (coupon && coupon.limit) {
7 discount =
8 entityTax && !excludedTax
9 ? usePercentageAmount(useTaxedAmount(subTotal, entityTax), coupon.discount) +
10 coupon.deduction
11 : usePercentageAmount(subTotal, coupon.discount) + coupon.deduction
12
13 if (discount >= subTotal) {
14 discount = subTotal
15 }
16 }
17
18 let tax = 0
19
20 if (entityTax && excludedTax) {
21 tax = useTaxAmount(entityTax, subTotal - discount)
22 } else if (entityTax && !excludedTax) {
23 let baseAmount = useTaxedAmount(subTotal, entityTax)
24
25 tax = useTaxAmount(entityTax, baseAmount - discount)
26
27 if (includedTaxInTotal) {
28 subTotal = baseAmount + tax
29
30 tax = 0
31 } else {
32 subTotal = baseAmount
33 }
34 }
35
36 return {
37 price: subTotal,
38 discount: discount,
39 tax: tax,
40 deposit: entity ? useDepositAmount(subTotal - discount + tax, entity) : 0,
41 }
42 }
43
44 function getAllColumn(type) {
45 switch (type) {
46 case 'service':
47 return 'allServices'
48
49 case 'extra':
50 return 'allExtras'
51
52 case 'event':
53 return 'allEvents'
54
55 case 'package':
56 return 'allPackages'
57 }
58 }
59
60 function useTaxVisibility(store, id, type) {
61 let allColumn = getAllColumn(type)
62
63 let amSettings = store.getters['getSettings']
64
65 let tax = useEntityTax(store, id, type)
66
67 if (!amSettings.payments.taxes.enabled) {
68 return false
69 }
70
71 return (tax && tax[allColumn]) || !!tax?.[`${type}List`].length
72 }
73
74 function useEntityTax(store, entityId, entityType) {
75 let allColumn = getAllColumn(entityType)
76
77 let tax = store.getters[
78 entityType !== 'event' ? 'entities/getTaxes' : 'eventEntities/getTaxes'
79 ].find((t) => t[allColumn] || t[entityType + 'List'].find((s) => s.id === entityId))
80
81 return tax && typeof tax !== 'undefined' && ('status' in tax ? tax.status === 'visible' : true)
82 ? tax
83 : null
84 }
85
86 function useTaxAmount(tax, amount) {
87 switch (tax.type) {
88 case 'percentage':
89 return usePercentageAmount(amount, tax.amount)
90 case 'fixed':
91 return amount > 0 ? tax.amount : 0
92 }
93 }
94
95 function useTaxedAmount(value, tax) {
96 switch (tax.type) {
97 case 'percentage':
98 return value / (1 + tax.amount / 100)
99 case 'fixed':
100 return value - tax.amount
101 }
102 }
103
104 function useDepositAmount(totalAmount, entity) {
105 let depositAmount = 0
106
107 if (entity.depositPayment !== 'disabled') {
108 switch (entity.depositPayment) {
109 case 'fixed':
110 depositAmount =
111 (entity.depositPerPerson && entity.aggregatedPrice && entity.persons
112 ? entity.persons
113 : 1) * entity.deposit
114
115 break
116
117 case 'percentage':
118 depositAmount = usePercentageAmount(totalAmount, entity.deposit)
119
120 break
121 }
122 }
123
124 return useRoundAmount(totalAmount > depositAmount ? depositAmount : 0)
125 }
126
127 function usePercentageAmount(amount, percentage) {
128 return (amount * percentage) / 100
129 }
130
131 function useRoundAmount(amount) {
132 return Math.round(amount * 100) / 100
133 }
134
135 export {
136 useAmount,
137 useDepositAmount,
138 useTaxVisibility,
139 useEntityTax,
140 usePercentageAmount,
141 useRoundAmount,
142 useTaxAmount,
143 useTaxedAmount,
144 }
145