|
59 | 59 | max-width: 800px; |
60 | 60 | } |
61 | 61 | </style> |
62 | | - <ia-monthly-giving-circle></ia-monthly-giving-circle> |
| 62 | + <ia-monthly-giving-circle canEdit></ia-monthly-giving-circle> |
63 | 63 | </div> |
64 | 64 |
|
65 | 65 | <script type="module" src="../dist/src/monthly-giving-circle.js"></script> |
|
68 | 68 |
|
69 | 69 | let updateNotices = []; |
70 | 70 |
|
| 71 | + const nextPaymentIn25Days = new Date(); |
| 72 | + nextPaymentIn25Days.setDate(nextPaymentIn25Days.getDate() + 25); |
| 73 | + nextPaymentIn25Days.setMinutes(0); |
| 74 | + nextPaymentIn25Days.setSeconds(0); |
| 75 | + nextPaymentIn25Days.setMilliseconds(0); |
| 76 | + console.log('nextPaymentIn25Days', nextPaymentIn25Days.toISOString()); |
| 77 | + |
| 78 | + const lastPaymentInTheSameMonth = new Date(); |
| 79 | + lastPaymentInTheSameMonth.setMinutes(0); |
| 80 | + lastPaymentInTheSameMonth.setSeconds(0); |
| 81 | + lastPaymentInTheSameMonth.setMilliseconds(0); |
| 82 | + lastPaymentInTheSameMonth.setDate(1); |
| 83 | + console.log('lastPaymentInTheSameMonth', lastPaymentInTheSameMonth.toISOString()); |
| 84 | + |
| 85 | + const nextMonth = new Date(); |
| 86 | + nextMonth.setMonth(nextMonth.getMonth() + 1); |
| 87 | + |
| 88 | + const nextPaymentFirstOfMonth = new Date(nextMonth); |
| 89 | + nextPaymentFirstOfMonth.setMinutes(0); |
| 90 | + nextPaymentFirstOfMonth.setSeconds(0); |
| 91 | + nextPaymentFirstOfMonth.setMilliseconds(0); |
| 92 | + nextPaymentFirstOfMonth.setDate(1); |
| 93 | + console.log('nextPaymentFirstOfMonth', nextPaymentFirstOfMonth.toISOString()); |
| 94 | + |
| 95 | + const today = new Date(); |
| 96 | + today.setHours(0, 0, 0, 0); |
| 97 | + |
| 98 | + const lastMonth = new Date(); |
| 99 | + lastMonth.setHours(0, 0, 0, 0); |
| 100 | + lastMonth.setDate(0); |
| 101 | + |
| 102 | + const lastDayOfCurrentMonth = new Date(); |
| 103 | + lastDayOfCurrentMonth.setHours(0, 0, 0, 0); |
| 104 | + lastDayOfCurrentMonth.setMonth(lastDayOfCurrentMonth.getMonth() + 1); |
| 105 | + lastDayOfCurrentMonth.setDate(0); |
| 106 | + |
71 | 107 | const plans = { |
72 | 108 | "41": { |
73 | 109 | "token": "Acbdcdcadsfdasf.1234alphanumeric.3foobarXyZ", |
|
76 | 112 | "is_test": true, |
77 | 113 | "btdata": { |
78 | 114 | "billingDayOfMonth": 22, |
| 115 | + "lastBillingDate": { |
| 116 | + "date": lastMonth.toISOString(), |
| 117 | + "timezone_type": 3, |
| 118 | + "timezone": "UTC" |
| 119 | + }, |
79 | 120 | "nextBillingDate": { |
80 | | - "date": "2024-08-22 00:00:00.000000", |
| 121 | + "date": lastDayOfCurrentMonth.toISOString(), |
81 | 122 | "timezone_type": 3, |
82 | 123 | "timezone": "UTC" |
83 | 124 | }, |
|
97 | 138 | "is_test": true, |
98 | 139 | "btdata": { |
99 | 140 | "billingDayOfMonth": 9, |
| 141 | + "lastBillingDate": { |
| 142 | + "date": lastPaymentInTheSameMonth.toISOString(), |
| 143 | + "timezone_type": 3, |
| 144 | + "timezone": "UTC" |
| 145 | + }, |
100 | 146 | "nextBillingDate": { |
101 | | - "date": "2024-09-09 00:00:00.000000", |
| 147 | + "date": nextPaymentFirstOfMonth.toISOString(), |
102 | 148 | "timezone_type": 3, |
103 | 149 | "timezone": "UTC" |
104 | 150 | }, |
|
278 | 324 | }, returnTiming); |
279 | 325 | }) |
280 | 326 |
|
| 327 | + mgcComponent.addEventListener('updateDate', (e) => { |
| 328 | + const { newDate, plan } = e.detail; |
| 329 | + |
| 330 | + |
| 331 | + const heads = coinFlip() === 1; |
| 332 | + const successOrFail = heads ? 'success' : 'fail'; |
| 333 | + const returnTiming = heads ? 3000 : 8000; |
| 334 | + |
| 335 | + uxMessageInfoArea.innerText = `Updating next billing date for plan: ${newDate}, plan: ${JSON.stringify(plan.id)} -- Update will return ${successOrFail} in ${returnTiming} ms`; |
| 336 | + const message = successOrFail === 'success' ? 'Date updated' : 'Date failed to update'; |
| 337 | + |
| 338 | + if (heads) { |
| 339 | + plan.setNextBillingDate(newDate); |
| 340 | + } |
| 341 | + |
| 342 | + const update = { |
| 343 | + message, |
| 344 | + status: successOrFail, |
| 345 | + plan, |
| 346 | + donationId: plan.id, |
| 347 | + action: 'dateUpdate' |
| 348 | + }; |
| 349 | + |
| 350 | + updateNotices = [update, ...updateNotices]; |
| 351 | + |
| 352 | + |
| 353 | + setTimeout(() => { |
| 354 | + mgcComponent.updateReceived(update); |
| 355 | + console.log('Amount Update Request --- index.html ----', update); |
| 356 | + uxMessageInfoArea.innerText = ''; |
| 357 | + }, returnTiming); |
| 358 | + }); |
| 359 | + |
281 | 360 | // options hooks |
282 | 361 | document.getElementById('toggle-receipts').addEventListener('click', async () => { |
283 | 362 | if (showReceipts) { |
|
0 commit comments