nodebb-plugin-equipment-calendar 0.9.0 → 0.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/library.js CHANGED
@@ -129,9 +129,11 @@ async function createHelloAssoCheckoutIntent(settings,
129
129
  items.forEach(i => { byId[i.id] = i; });
130
130
 
131
131
  const names = reservations.map(r => (byId[r.itemId] && byId[r.itemId].name) || r.itemId);
132
+ const days = reservations.length ? Math.max(1, Math.round((reservations[0].endMs - reservations[0].startMs) / (24*60*60*1000))) : 1;
132
133
  const totalAmount = reservations.reduce((sum, r) => {
133
- const price = (byId[r.itemId] && parseInt(byId[r.itemId].price, 10)) || 0;
134
- return sum + (Number.isFinite(price) ? price : 0);
134
+ const priceEuro = (byId[r.itemId] && parseFloat(byId[r.itemId].price)) || 0;
135
+ const priceCents = Math.round((Number.isFinite(priceEuro) ? priceEuro : 0) * 100);
136
+ return sum + (priceCents * days);
135
137
  }, 0);
136
138
 
137
139
  if (!totalAmount || totalAmount <= 0) {
@@ -296,11 +298,11 @@ async function getActiveItems(settings) {
296
298
  const id = String(it.id || it.itemId || it.reference || it.slug || it.name || '').trim();
297
299
  const name = String(it.name || it.label || it.title || id).trim();
298
300
  // Price handling is not displayed in the public calendar, keep a field if you want later
299
- const price =
301
+ const priceRaw =
300
302
  (it.price && (it.price.value || it.price.amount)) ||
301
303
  (it.amount && (it.amount.value || it.amount)) ||
302
304
  it.price;
303
- const price = typeof price === 'number' ? price : 0;
305
+ const price = (typeof priceRaw === 'number' ? priceRaw : parseInt(priceRaw, 10)) || 0;
304
306
 
305
307
  return {
306
308
  id: id || name,
@@ -837,7 +839,7 @@ async function handleHelloAssoTest(req, res) {
837
839
  // force=1 skips in-memory cache and refresh_token; clear=1 wipes stored refresh token
838
840
  haTokenCache = null;
839
841
  await getHelloAssoAccessToken(settings,
840
- saved, { force, clearStored: clear });
842
+ { force, clearStored: clear });
841
843
  const items = await fetchHelloAssoItems(settings);
842
844
  const list = Array.isArray(items) ? items : (Array.isArray(items.data) ? items.data : []);
843
845
  count = list.length;
@@ -860,8 +862,7 @@ async function handleHelloAssoTest(req, res) {
860
862
  message,
861
863
  count,
862
864
  settings,
863
- saved,
864
- sampleItems,
865
+ sampleItems,
865
866
  hasSampleItems,
866
867
  hasSampleItems: sampleItems && sampleItems.length > 0,
867
868
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-equipment-calendar",
3
- "version": "0.9.0",
3
+ "version": "0.9.8",
4
4
  "description": "Equipment reservation calendar for NodeBB (FullCalendar, approvals, HelloAsso payments)",
5
5
  "main": "library.js",
6
6
  "scripts": {
package/plugin.json CHANGED
@@ -25,6 +25,6 @@
25
25
  "scripts": [
26
26
  "public/js/client.js"
27
27
  ],
28
- "version": "0.5.2",
28
+ "version": "0.5.7",
29
29
  "minver": "4.7.1"
30
30
  }
@@ -1,3 +1,29 @@
1
+
2
+ function updateTotalPrice() {
3
+ try {
4
+ const sel = document.getElementById('ec-item-ids');
5
+ const out = document.getElementById('ec-total-price');
6
+ const daysEl = document.getElementById('ec-total-days');
7
+ if (!sel || !out) return;
8
+ let total = 0;
9
+ Array.from(sel.selectedOptions || []).forEach(opt => {
10
+ const p = parseFloat(opt.getAttribute('data-price') || '0');
11
+ if (!Number.isNaN(p)) total += p;
12
+ });
13
+ const days = getReservationDays();
14
+ const finalTotal = total * days;
15
+ if (daysEl) {
16
+ daysEl.textContent = days + (days > 1 ? ' jours' : ' jour');
17
+ }
18
+ const txt = Number.isInteger(finalTotal) ? String(finalTotal) : finalTotal.toFixed(2);
19
+ out.textContent = txt + ' €';
20
+ } catch (e) {}
21
+ });
22
+ const txt = Number.isInteger(total) ? String(total) : total.toFixed(2);
23
+ out.textContent = txt + ' €';
24
+ } catch (e) {}
25
+ }
26
+
1
27
  'use strict';
2
28
  /* global window, document, FullCalendar, bootbox */
3
29
 
@@ -174,3 +200,14 @@
174
200
  initCalendar();
175
201
  }
176
202
  }());
203
+
204
+ const ecItemSel = document.getElementById('ec-item-ids');
205
+ if (ecItemSel) { ecItemSel.addEventListener('change', updateTotalPrice); updateTotalPrice(); }
206
+
207
+ function getReservationDays() {
208
+ const startMs = parseInt(document.getElementById('ec-start-ms')?.value || '0', 10);
209
+ const endMs = parseInt(document.getElementById('ec-end-ms')?.value || '0', 10);
210
+ if (!startMs || !endMs || endMs <= startMs) return 1;
211
+ const days = Math.round((endMs - startMs) / (24*60*60*1000));
212
+ return days > 0 ? days : 1;
213
+ }