forked from firefly-iii/firefly-iii
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirefly_src.patch
More file actions
690 lines (662 loc) · 31.9 KB
/
firefly_src.patch
File metadata and controls
690 lines (662 loc) · 31.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
diff -Naur ../official/public/v1/js/ff/accounts/reconcile.js ./public/v1/js/ff/accounts/reconcile.js
--- ../official/public/v1/js/ff/accounts/reconcile.js 2022-05-06 16:20:55.829339578 +0200
+++ ./public/v1/js/ff/accounts/reconcile.js 2024-04-01 17:50:06.097596790 +0200
@@ -21,6 +21,7 @@
var balanceDifference = 0;
var difference = 0;
var selectedAmount = 0;
+var initialSelectedAmount = 0;
var reconcileStarted = false;
var changedBalances = false;
@@ -41,6 +42,9 @@
difference = balanceDifference - selectedAmount;
updateDifference();
+ trigger_smart_reconcile();
+ difference = balanceDifference - selectedAmount;
+ updateDifference();
}
changedBalances = true;
});
@@ -69,6 +73,107 @@
});
+function smart_reconcile(amounts, target_sum) {
+ let d_size = amounts.length;
+ let max_sum = amounts.reduce((a, b) => a + b);
+ // Define number of maximum items to exclude in order to keep short computing time
+ // Here are some pre-computed values ensuring less than 1e7 combinations to explore
+ // 10 -> 10, 20 -> 20, 22 -> 22, 24 -> 12, 26 -> 9, 30 -> 8, 40 -> 6, 50 -> 5, 100 -> 4
+ // next line is a magic formula fitting these values
+ let max_nb_unchecked_items = (d_size <= 22) ? d_size : Math.floor( 13*(d_size-22)**-0.3 );
+ console.log('debug smart_reconcile:', target_sum, max_sum, max_nb_unchecked_items);
+ // Result will be list of items to EXCLUDE from reconcile
+ let result = solve_knapsack(amounts, amounts.length, max_nb_unchecked_items, 0, max_sum-target_sum);
+ return result;
+}
+
+// Find combination of transactions whose sum equals to target, with a preference
+// to pick minimum number of transactions and new transactions first. (remember
+// that pick = exclude some reconcile).
+// Tree exploration through recursive function:
+// Add transactions from index-1 to 0 to achieve target_sum without picking more
+// than remain_to_take items
+// Returns null if not possible, else boolean array listing which transactions to pick
+function solve_knapsack(amounts, index, remain_to_take, current_sum, target_sum) {
+ // Stop if no more transactions can be checked
+ if (Math.abs(current_sum - target_sum) < 0.001) return Array(index).fill(false);
+ if (remain_to_take == 0 || index == 0) return null;
+
+ // Try not to pick current transaction
+ let result = solve_knapsack(amounts, index-1, remain_to_take, current_sum, target_sum);
+ if (result) {
+ result.push(false);
+ return result;
+ }
+
+ // Try picking current transaction
+ let new_amount = amounts[index-1];
+ let new_sum = current_sum + new_amount;
+ if (Math.abs(new_sum - target_sum) < 0.001) return Array(index-1).fill(false).concat([true]);
+ result = solve_knapsack(amounts, index-1, remain_to_take-1, new_sum, target_sum);
+ if (result) {
+ result.push(true);
+ return result;
+ }
+
+ // No solution
+ return null;
+}
+
+function trigger_smart_reconcile() {
+ // Gather all data
+ let amounts = [];
+ $('.reconcile_checkbox').each(function (i, v) {
+ var check = $(v);
+ amounts.push(parseFloat(check.val()));
+ });
+
+ // Call core function, better to serch for items to uncheck than the ones to check
+ var items_to_uncheck = smart_reconcile(amounts, initialSelectedAmount - balanceDifference);
+ if (items_to_uncheck) {
+ // Set checkboxes
+ $('.reconcile_checkbox').each(function (i, v) {
+ var check = $(v);
+ changeReconciledBoxAndUpdate(check, !items_to_uncheck[i]);
+ });
+ } else {
+ console.log('Cant find a solution for smart reconcile');
+ }
+}
+
+// Change status of el to targetState and update all variables
+// If targetState is null, then assumes that state is alreay changed and only update variables
+function changeReconciledBoxAndUpdate(el, targetState) {
+ var amount = parseFloat(el.val());
+ var journalId = parseInt(el.data('id'));
+ var identifier = 'checked_' + journalId;
+ console.log('in changeReconciledBoxAndUpdate(' + journalId + ') with amount ' + amount + ' selected amount ' + selectedAmount + ' and targetState=' + targetState);
+
+ if (targetState != null) {
+ // do nothing if line is already in target state
+ if (el.prop('checked') === targetState) {
+ return;
+ }
+ el.prop('checked', targetState);
+ }
+
+ // if checked, add to selected amount
+ if (el.prop('checked') === true && el.data('younger') === false) {
+ selectedAmount = selectedAmount - amount;
+ //console.log('checked = true and younger = false so selected amount = ' + selectedAmount);
+ localStorage.setItem(identifier, 'true');
+ }
+ // if unchecked, substract from selected amount
+ if (el.prop('checked') === false && el.data('younger') === false) {
+ selectedAmount = selectedAmount + amount;
+ //console.log('checked = false and younger = false so selected amount = ' + selectedAmount);
+ localStorage.setItem(identifier, 'false');
+ }
+ difference = balanceDifference - selectedAmount;
+ //console.log('Difference is now ' + difference);
+ updateDifference();
+}
+
function selectAllReconcile(e) {
// loop all, check.
var el = $(e.target);
@@ -83,29 +188,7 @@
$('.reconcile_checkbox').each(function (i, v) {
var check = $(v);
- var amount = parseFloat(check.val());
- var journalId = parseInt(check.data('id'));
- var identifier = 'checked_' + journalId;
- console.log('in selectAllReconcile(' + journalId + ') with amount ' + amount + ' and selected amount ' + selectedAmount);
-
- // do nothing if line is already in target state
- if (check.prop('checked') === doCheck )
- return;
-
- check.prop('checked', doCheck);
- // if checked, add to selected amount
- if (doCheck === true && check.data('younger') === false) {
- selectedAmount = selectedAmount - amount;
- //console.log('checked = true and younger = false so selected amount = ' + selectedAmount);
- localStorage.setItem(identifier, 'true');
- }
- if (doCheck === false && check.data('younger') === false) {
- selectedAmount = selectedAmount + amount;
- //console.log('checked = false and younger = false so selected amount = ' + selectedAmount);
- localStorage.setItem(identifier, 'false');
- }
- difference = balanceDifference - selectedAmount;
- //console.log('Difference is now ' + difference);
+ changeReconciledBoxAndUpdate(check, doCheck);
});
updateDifference();
@@ -153,26 +236,7 @@
* @param e
*/
function checkReconciledBox(e) {
-
- var el = $(e.target);
- var amount = parseFloat(el.val());
- var journalId = parseInt(el.data('id'));
- var identifier = 'checked_' + journalId;
- //console.log('in checkReconciledBox(' + journalId + ') with amount ' + amount + ' and selected amount ' + selectedAmount);
- // if checked, add to selected amount
- if (el.prop('checked') === true && el.data('younger') === false) {
- selectedAmount = selectedAmount - amount;
- //console.log('checked = true and younger = false so selected amount = ' + selectedAmount);
- localStorage.setItem(identifier, 'true');
- }
- if (el.prop('checked') === false && el.data('younger') === false) {
- selectedAmount = selectedAmount + amount;
- //console.log('checked = false and younger = false so selected amount = ' + selectedAmount);
- localStorage.setItem(identifier, 'false');
- }
- difference = balanceDifference - selectedAmount;
- //console.log('Difference is now ' + difference);
- updateDifference();
+ changeReconciledBoxAndUpdate($(e.target), null);
}
@@ -266,6 +330,7 @@
difference = balanceDifference - selectedAmount;
updateDifference();
+ initialSelectedAmount = selectedAmount;
// loop al placed checkboxes and check them if necessary.
restoreFromLocalStorage();
@@ -331,12 +396,12 @@
}
function updateDifference() {
- console.log('in updateDifference()');
+ //console.log('in updateDifference()');
var addClass = 'text-info';
- if (difference > 0) {
+ if (difference > 0.01) {
addClass = 'text-success';
}
- if (difference < 0) {
+ if (difference < -0.01) {
addClass = 'text-danger';
}
$('#difference').addClass(addClass).text(accounting.formatMoney(difference));
diff -Naur ../official/resources/assets/v1/src/components/transactions/CreateTransaction.vue ./resources/assets/v1/src/components/transactions/CreateTransaction.vue
--- ../official/resources/assets/v1/src/components/transactions/CreateTransaction.vue 2024-09-30 18:10:03.237771486 +0200
+++ ./resources/assets/v1/src/components/transactions/CreateTransaction.vue 2024-09-30 18:10:06.149784871 +0200
@@ -147,31 +147,6 @@
:no_budget="$t('firefly.none_in_select_list')"
:transactionType="transactionType"
></budget>
- <category
- v-model="transaction.category"
- :error="transaction.errors.category"
- :transactionType="transactionType"
- ></category>
- <piggy-bank
- v-model="transaction.piggy_bank"
- :error="transaction.errors.piggy_bank"
- :no_piggy_bank="$t('firefly.no_piggy_bank')"
- :transactionType="transactionType"
- ></piggy-bank>
- <tags
- v-model="transaction.tags"
- :error="transaction.errors.tags"
- ></tags>
- <bill
- v-model="transaction.bill"
- :error="transaction.errors.bill_id"
- :no_bill="$t('firefly.none_in_select_list')"
- :transactionType="transactionType"
- ></bill>
- <custom-transaction-fields
- v-model="transaction.custom_fields"
- :error="transaction.errors.custom_errors"
- ></custom-transaction-fields>
</div>
</div>
</div>
diff -Naur ../official/resources/assets/v1/webpack.mix.js ./resources/assets/v1/webpack.mix.js
--- ../official/resources/assets/v1/webpack.mix.js 2024-06-15 16:46:04.215688753 +0200
+++ ./resources/assets/v1/webpack.mix.js 2024-09-30 18:10:06.161784929 +0200
@@ -35,6 +35,19 @@
}
});
+<<<<<<< HEAD:webpack.mix.js
+mix.js('resources/assets/js/app.js', 'public/v1/js');
+mix.js('resources/assets/js/app_vue.js', 'public/v1/js').vue({version: 2});
+mix.js('resources/assets/js/create_transaction.js', 'public/v1/js').vue({version: 2});
+mix.js('resources/assets/js/edit_transaction.js', 'public/v1/js').vue({version: 2});
+mix.js('resources/assets/js/profile.js', 'public/v1/js').vue({version: 2});
+
+// webhooks
+//mix.js('resources/assets/js/webhooks/index.js', 'public/v1/js/webhooks').vue({version: 2});
+//mix.js('resources/assets/js/webhooks/create.js', 'public/v1/js/webhooks').vue({version: 2});
+//mix.js('resources/assets/js/webhooks/edit.js', 'public/v1/js/webhooks').vue({version: 2});
+//mix.js('resources/assets/js/webhooks/show.js', 'public/v1/js/webhooks').vue({version: 2});
+=======
mix.js('src/app.js', 'build');
mix.js('src/app_vue.js', 'build').vue({version: 2});
mix.js('src/create_transaction.js', 'build').vue({version: 2});
@@ -46,3 +59,4 @@
mix.js('src/webhooks/create.js', 'build/webhooks').vue({version: 2});
mix.js('src/webhooks/edit.js', 'build/webhooks').vue({version: 2});
mix.js('src/webhooks/show.js', 'build/webhooks').vue({version: 2}).copy('build','../../../public/v1/js')
+>>>>>>> abcddb09bf735604e8f2fbe17be69f440b5b6496:resources/assets/v1/webpack.mix.js
diff -Naur ../official/resources/lang/en_US/firefly.php ./resources/lang/en_US/firefly.php
--- ../official/resources/lang/en_US/firefly.php 2024-06-15 16:46:04.231689347 +0200
+++ ./resources/lang/en_US/firefly.php 2024-09-30 18:10:06.185785043 +0200
@@ -1300,6 +1300,7 @@
'pref_view_range_help' => 'Some charts are automatically grouped in periods. Your budgets will also be grouped in periods. What period would you prefer?',
'pref_1D' => 'One day',
'pref_1W' => 'One week',
+ 'pref_3W' => 'Three weeks centered',
'pref_1M' => 'One month',
'pref_3M' => 'Three months (quarter)',
'pref_6M' => 'Six months',
diff -Naur ../official/resources/views/accounts/reconcile/index.twig ./resources/views/accounts/reconcile/index.twig
--- ../official/resources/views/accounts/reconcile/index.twig 2022-12-29 16:01:27.132300233 +0100
+++ ./resources/views/accounts/reconcile/index.twig 2022-12-29 16:01:29.804338669 +0100
@@ -134,4 +134,7 @@
var selectRangeAndBalance = '{{ 'select_range_and_balance'|_|escape('js') }}';
</script>
<script src="v1/js/ff/accounts/reconcile.js?v={{ FF_VERSION }}" type="text/javascript" nonce="{{ JS_NONCE }}"></script>
+ <script type="text/javascript" nonce="{{ JS_NONCE }}">
+ document.addEventListener('DOMContentLoaded', startReconcile, false);
+ </script>
{% endblock %}
diff -Naur ../official/resources/views/index.twig ./resources/views/index.twig
--- ../official/resources/views/index.twig 2024-09-30 18:10:03.237771486 +0200
+++ ./resources/views/index.twig 2024-09-30 18:30:48.510575636 +0200
@@ -4,7 +4,6 @@
{{ Breadcrumbs.render }}
{% endblock %}
{% block content %}
- {% include 'partials.boxes' %}
<div class="row">
<div class="col-lg-8 col-md-12 col-sm-12">
{# ACCOUNTS #}
@@ -38,23 +37,6 @@
</a>
</div>
</div>
- {# CATEGORIES #}
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title"><a href="{{ route('categories.index') }}"
- title="{{ 'categories'|_ }}">{{ 'categories'|_ }}</a></h3>
-
- </div>
- <div class="box-body">
- <canvas id="categories-chart" style="width:100%;height:400px;" height="400" width="100%"></canvas>
- </div>
- <div class="box-footer">
- <a href="{{ route('categories.index') }}" class="btn btn-default button-sm">
- <span class="fa fa-bookmark"></span>
- <span>{{ 'go_to_categories'|_ }}</span>
- </a>
- </div>
- </div>
</div>
<div class="col-lg-4 col-md-6 col-sm-12">
@@ -127,67 +109,6 @@
</div>
{% endfor %}
</div>
-
- {% if billCount > 0 %}
- {# BILLS #}
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title"><a href="{{ route('bills.index') }}"
- title="{{ 'bills'|_ }}">{{ 'bills'|_ }}</a></h3>
-
- </div>
- <div class="box-body">
- <div style="width:100%;margin:0 auto;">
- <canvas id="bills-chart" style="width:100%;height:200px;" height="200"></canvas>
- </div>
- </div>
- <div class="box-footer">
- <a href="{{ route('bills.index') }}" class="btn btn-default button-sm"><span
- class="fa fa-calendar"></span> {{ 'go_to_bills'|_ }}</a>
- </div>
- </div>
- {% endif %}
-
- {# box for piggy bank data (JSON) #}
- <div id="piggy_bank_overview">
-
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-lg-12 col-md-12 col-sm-12">
- {# EXPENSE ACCOUNTS #}
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title"><a href="{{ route('accounts.index',['expense']) }}"
- title="{{ 'expense_accounts'|_ }}">{{ 'expense_accounts'|_ }}</a>
- </h3>
- </div>
- <div class="box-body">
- <canvas id="expense-accounts-chart" style="width:100%;height:400px;" height="400"
- width="100%"></canvas>
- </div>
- <div class="box-footer">
- <a href="{{ route('accounts.index', ['expense']) }}" class="btn btn-default button-sm"><span
- class="fa fa-shopping-cart"></span> {{ 'go_to_expense_accounts'|_ }}</a>
- </div>
- </div>
- {# OPTIONAL REVENUE ACCOUNTS #}
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title"><a href="{{ route('accounts.index',['revenue']) }}"
- title="{{ 'revenue_accounts'|_ }}">{{ 'revenue_accounts'|_ }}</a></h3>
-
- </div>
- <div class="box-body">
- <canvas id="revenue-accounts-chart" style="width:100%;height:400px;" height="400"
- width="100%"></canvas>
- </div>
- <div class="box-footer">
- <a href="{{ route('accounts.index', ['revenue']) }}" class="btn btn-default button-sm"><span
- class="fa fa-download"></span> {{ 'go_to_revenue_accounts'|_ }}</a>
- </div>
- </div>
</div>
</div>
{% endblock %}
diff -Naur ../official/resources/views/layout/default.twig ./resources/views/layout/default.twig
--- ../official/resources/views/layout/default.twig 2024-06-15 16:46:04.243689793 +0200
+++ ./resources/views/layout/default.twig 2024-09-30 18:10:06.209785158 +0200
@@ -126,11 +126,22 @@
</span>
</li>
- <li class="dropdown user user-menu">
- <span style="cursor:default;color:#fff;padding: 15px;display: block;line-height: 20px;">
- <span class="hidden-xs">{{ Auth.user.email }}</span>
- </span>
+ <li>
+ <a href="{{ route('transactions.create', 'withdrawal') }}">
+ <span class="fa fa-long-arrow-left bg-red" style="font-size:20px;border-radius:50%"></span>
+ </a>
</li>
+ <li>
+ <a href="{{ route('transactions.create', 'deposit') }}">
+ <span class="fa fa-long-arrow-right bg-green" style="font-size:20px;border-radius:50%"></span>
+ </a>
+ </li>
+ <li>
+ <a href="{{ route('transactions.create', 'transfer') }}">
+ <span class="fa fa-exchange bg-blue" style="font-size:20px;border-radius:50%"></span>
+ </a>
+ </li>
+
<li id="sidebar-toggle">
<a href="#" data-toggle="control-sidebar"><span class="fa fa-plus-circle"></span></a>
</li>
diff -Naur ../official/resources/views/preferences/index.twig ./resources/views/preferences/index.twig
--- ../official/resources/views/preferences/index.twig 2024-06-15 16:46:04.243689793 +0200
+++ ./resources/views/preferences/index.twig 2024-09-30 18:10:06.209785158 +0200
@@ -196,30 +196,24 @@
<div class="radio">
<label>
<input type="radio" name="viewRange"
- value="last7" {% if viewRange == 'last7' %} checked {% endif %}>
- {{ 'pref_last7'|_ }}
+ value="3W" {% if viewRange == '3W' %} checked {% endif %}>
+ {{ 'pref_3W'|_ }}
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="viewRange"
- value="1M" {% if viewRange == '1M' %} checked {% endif %}>
- {{ 'pref_1M'|_ }}
- </label>
- </div>
- <div class="radio">
- <label>
- <input type="radio" name="viewRange"
- value="last30" {% if viewRange == 'last30' %} checked {% endif %}>
- {{ 'pref_last30'|_ }}
+ value="last7" {% if viewRange == 'last7' %} checked {% endif %}>
+ {{ 'pref_last7'|_ }}
</label>
</div>
+
<div class="radio">
<label>
<input type="radio" name="viewRange"
- value="MTD" {% if viewRange == 'MTD' %} checked {% endif %}>
- {{ 'pref_MTD'|_ }}
+ value="1M" {% if viewRange == '1M' %} checked {% endif %}>
+ {{ 'pref_1M'|_ }}
</label>
</div>
diff -Naur ../official/app/Http/Controllers/Bill/IndexController.php ./app/Http/Controllers/Bill/IndexController.php
--- ../official/app/Http/Controllers/Bill/IndexController.php 2024-03-29 20:30:45.775713179 +0100
+++ ./app/Http/Controllers/Bill/IndexController.php 2024-03-29 20:30:49.435771450 +0100
@@ -201,6 +201,7 @@
'3M' => '4',
'1M' => '12',
'1W' => '52.16',
+ '3W' => '156.48',
'1D' => '365.24',
'YTD' => '1',
'QTD' => '4',
diff -Naur ../official/app/Jobs/CreateRecurringTransactions.php ./app/Jobs/CreateRecurringTransactions.php
--- ../official/app/Jobs/CreateRecurringTransactions.php 2024-09-30 18:10:03.229771449 +0200
+++ ./app/Jobs/CreateRecurringTransactions.php 2024-09-30 18:10:06.129784773 +0200
@@ -87,6 +87,8 @@
$this->created = 0;
$this->recurrences = new Collection();
$this->groups = new Collection();
+ $this->days_max_early = 8;
+ $this->days_max_late = 8;
app('log')->debug(sprintf('Created new CreateRecurringTransactions("%s")', $this->date->format('Y-m-d')));
}
@@ -293,10 +295,10 @@
);
// start looping from $startDate to today perhaps we have a hit?
- // add two days to $this->date, so we always include the weekend.
- $includeWeekend = clone $this->date;
- $includeWeekend->addDays(2);
- $occurrences = $this->repository->getOccurrencesInRange($repetition, $recurrence->first_date, $includeWeekend);
+ // add few days to anticipate next occurrences
+ $endDate = clone $this->date;
+ $endDate->addDays($this->days_max_early);
+ $occurrences = $this->repository->getOccurrencesInRange($repetition, $recurrence->first_date, $endDate);
unset($includeWeekend);
@@ -335,10 +337,18 @@
private function handleOccurrence(Recurrence $recurrence, RecurrenceRepetition $repetition, Carbon $date): ?TransactionGroup
{
$date->startOfDay();
- if ($date->ne($this->date)) {
+
+ // allow some margin in the future (to anticipate) and in the past (in case cron was not executed)
+ $datediff = $date->diffInDays($this->date);
+ if ($datediff > $this->days_max_early) {
+ //print "date too much in the future\n";
+ return null;
+ }
+ if ($datediff < -$this->days_max_late) {
+ //print "date too much in the past\n";
return null;
}
- app('log')->debug(sprintf('%s IS today (%s)', $date->format('Y-m-d'), $this->date->format('Y-m-d')));
+ app('log')->debug(sprintf('%s IS close to today (%s)', $date->format('Y-m-d'), $this->date->format('Y-m-d')));
// count created journals on THIS day.
$journalCount = $this->repository->getJournalCount($recurrence, $date, $date);
diff -Naur ../official/app/Support/Calendar/Periodicity/ThreeWeekly.php ./app/Support/Calendar/Periodicity/ThreeWeekly.php
--- ../official/app/Support/Calendar/Periodicity/ThreeWeekly.php 1970-01-01 01:00:00.000000000 +0100
+++ ./app/Support/Calendar/Periodicity/ThreeWeekly.php 2023-12-28 18:44:14.187521306 +0100
@@ -0,0 +1,10 @@
+<?php
+
+declare(strict_types=1);
+
+namespace FireflyIII\Support\Calendar\Periodicity;
+
+final class ThreeWeekly extends Weekly
+{
+ public const int INTERVAL = 3;
+}
diff -Naur ../official/app/Support/Calendar/Periodicity.php ./app/Support/Calendar/Periodicity.php
--- ../official/app/Support/Calendar/Periodicity.php 2023-12-27 17:56:43.166457746 +0100
+++ ./app/Support/Calendar/Periodicity.php 2023-12-27 18:23:56.957621643 +0100
@@ -31,6 +31,7 @@
{
case Daily;
case Weekly;
+ case ThreeWeekly;
case Fortnightly;
case Monthly;
case Bimonthly;
diff -Naur ../official/app/Support/Http/Controllers/GetConfigurationData.php ./app/Support/Http/Controllers/GetConfigurationData.php
--- ../official/app/Support/Http/Controllers/GetConfigurationData.php 2024-09-30 18:10:03.233771466 +0200
+++ ./app/Support/Http/Controllers/GetConfigurationData.php 2024-09-30 18:11:42.770591159 +0200
@@ -125,12 +125,15 @@
}
// today:
- /** @var Carbon $todayStart */
- $todayStart = app('navigation')->startOfPeriod($today, $viewRange);
-
- /** @var Carbon $todayEnd */
- $todayEnd = app('navigation')->endOfPeriod($todayStart, $viewRange);
-
+ if ('3W' === $viewRange) {
+ $todayStart = Carbon::now()->subDays(14);
+ $todayEnd = Carbon::now()->addDays(7);
+ } else {
+ /** @var Carbon $todayStart */
+ $todayStart = app('navigation')->startOfPeriod($today, $viewRange);
+ /** @var Carbon $todayEnd */
+ $todayEnd = app('navigation')->endOfPeriod($todayStart, $viewRange);
+ }
if ($todayStart->ne($start) || $todayEnd->ne($end)) {
$ranges[ucfirst((string)trans('firefly.today'))] = [$todayStart, $todayEnd];
}
diff -Naur ../official/app/Support/Navigation.php ./app/Support/Navigation.php
--- ../official/app/Support/Navigation.php 2024-09-30 18:10:03.233771466 +0200
+++ ./app/Support/Navigation.php 2024-09-30 18:13:59.197971540 +0200
@@ -52,6 +52,7 @@
'1W' => Periodicity::Weekly,
'weekly' => Periodicity::Weekly,
'week' => Periodicity::Weekly,
+ '3W' => Periodicity::ThreeWeekly,
'1M' => Periodicity::Monthly,
'month' => Periodicity::Monthly,
'monthly' => Periodicity::Monthly,
@@ -162,6 +163,7 @@
{
$date = clone $theDate;
Log::debug(sprintf('Now in startOfPeriod("%s", "%s")', $date->toIso8601String(), $repeatFreq));
+ // No need to change anything for 3W
$functionMap = [
'1D' => 'startOfDay',
'daily' => 'startOfDay',
@@ -225,7 +227,7 @@
return $result;
}
- if ('custom' === $repeatFreq) {
+ if ('3W' === $repeatFreq || 'custom' === $repeatFreq) {
Log::debug(sprintf('Custom, result is "%s"', $date->toIso8601String()));
return $date; // the date is already at the start.
@@ -246,6 +248,7 @@
'1W' => 'addWeek',
'week' => 'addWeek',
'weekly' => 'addWeek',
+ '3W' => 'addWeeks',
'1M' => 'addMonth',
'month' => 'addMonth',
'monthly' => 'addMonth',
@@ -259,7 +262,7 @@
'yearly' => 'addYear',
'1Y' => 'addYear',
];
- $modifierMap = ['half-year' => 6, 'half_year' => 6, '6M' => 6];
+ $modifierMap = ['3W' => 3, 'half-year' => 6, 'half_year' => 6, '6M' => 6];
$subDay = ['week', 'weekly', '1W', 'month', 'monthly', '1M', '3M', 'quarter', 'quarterly', '6M', 'half-year', 'half_year', '1Y', 'year', 'yearly'];
if ('custom' === $repeatFreq) {
@@ -396,6 +399,7 @@
public function endOfX(Carbon $theCurrentEnd, string $repeatFreq, ?Carbon $maxDate): Carbon
{
+ // No need to change anything for 3W
$functionMap = [
'1D' => 'endOfDay',
'daily' => 'endOfDay',
@@ -529,6 +533,7 @@
'1W' => (string) trans('config.week_in_year_js'),
'week' => (string) trans('config.week_in_year_js'),
'weekly' => (string) trans('config.week_in_year_js'),
+ '3W' => (string) trans('config.month_js'),
'1M' => (string) trans('config.month_js'),
'month' => (string) trans('config.month_js'),
'monthly' => (string) trans('config.month_js'),
@@ -562,6 +567,7 @@
default => 'Y-m-d',
// '1D' => 'Y-m-d',
'1W' => '\WW,Y',
+ '3W' => 'Y-m',
'1M' => 'Y-m',
'3M', '6M' => '\QQ,Y',
'1Y' => 'Y',
@@ -656,6 +662,7 @@
'week' => 'subWeeks',
'1W' => 'subWeeks',
'weekly' => 'subWeeks',
+ '3W' => 'subDays',
'month' => 'subMonths',
'1M' => 'subMonths',
'monthly' => 'subMonths',
@@ -664,6 +671,7 @@
'yearly' => 'subYears',
];
$modifierMap = [
+ '3W' => 21,
'quarter' => 3,
'3M' => 3,
'quarterly' => 3,
@@ -774,6 +782,11 @@
return $end;
}
+ if ('3W' === $range) {
+ $end->addDays(21);
+ return $end;
+ }
+
// make sure 1Y takes the fiscal year into account.
if ('1Y' === $range) {
/** @var FiscalHelperInterface $fiscalHelper */
@@ -821,6 +834,12 @@
return $start;
}
+
+ if ('3W' === $range) {
+ $start->subDays(14);
+ return $start;
+ }
+
if ('6M' === $range) {
if ($start->month >= 7) {
$start->startOfYear()->addMonths(6);