Skip to content

Firefly III: a personal finances manager

Expand view to include weekend responses.

James Colea8e666db342a
diff --git a/app/Http/Controllers/Recurring/EditController.php b/app/Http/Controllers/Recurring/EditController.php
index 1107e93505..e78b8a820f 100644
--- a/app/Http/Controllers/Recurring/EditController.php
+++ b/app/Http/Controllers/Recurring/EditController.php
@@ -88,7 +88,6 @@ class EditController extends Controller
// todo handle old repetition type as well.
-
/** @var RecurrenceRepetition $repetition */
$repetition = $recurrence->recurrenceRepetitions()->first();
$currentRepetitionType = $repetition->repetition_type;
@@ -117,16 +116,27 @@ class EditController extends Controller
$repetitionEnd = 'times';
}
+ // what to do in the weekend?
+ $weekendResponses = [
+ RecurrenceRepetition::WEEKEND_DO_NOTHING => trans('firefly.do_nothing'),
+ RecurrenceRepetition::WEEKEND_SKIP_CREATION => trans('firefly.skip_transaction'),
+ RecurrenceRepetition::WEEKEND_TO_FRIDAY => trans('firefly.jump_to_friday'),
+ RecurrenceRepetition::WEEKEND_TO_MONDAY => trans('firefly.jump_to_monday'),
+ ];
+
// code to handle active-checkboxes
$hasOldInput = null !== $request->old('_token');
- // $hasOldInput = false;
- $preFilled = [
+ // $hasOldInput = false;
+ $preFilled = [
'transaction_type' => strtolower($recurrence->transactionType->type),
'active' => $hasOldInput ? (bool)$request->old('active') : $recurrence->active,
'apply_rules' => $hasOldInput ? (bool)$request->old('apply_rules') : $recurrence->apply_rules,
];
- return view('recurring.edit', compact('recurrence', 'array', 'budgets', 'preFilled', 'currentRepetitionType', 'repetitionEnd', 'repetitionEnds'));
+ return view(
+ 'recurring.edit',
+ compact('recurrence', 'array', 'weekendResponses', 'budgets', 'preFilled', 'currentRepetitionType', 'repetitionEnd', 'repetitionEnds')
+ );
}
/**
diff --git a/app/Jobs/CreateRecurringTransactions.php b/app/Jobs/CreateRecurringTransactions.php
index b358e9bc39..37319dc958 100644
--- a/app/Jobs/CreateRecurringTransactions.php
+++ b/app/Jobs/CreateRecurringTransactions.php
@@ -82,8 +82,6 @@ class CreateRecurringTransactions implements ShouldQueue
Log::debug('Now running report thing.');
// will now send email to users.
foreach ($result as $userId => $journals) {
- //// random bunch to make mail.
- //$journals = TransactionJournal::where('user_id', $userId)->inRandomOrder()->take(1)->get();
event(new RequestedReportOnJournals($userId, $journals));
}
diff --git a/app/Repositories/Recurring/RecurringRepository.php b/app/Repositories/Recurring/RecurringRepository.php
index 6e6c628ef2..8776c8d2de 100644
--- a/app/Repositories/Recurring/RecurringRepository.php
+++ b/app/Repositories/Recurring/RecurringRepository.php
@@ -217,8 +217,6 @@ class RecurringRepository implements RecurringRepositoryInterface
Log::debug('Rep is weekly.');
// monday = 1
// sunday = 7
- $mutator->addDay(); // always assume today has passed. TODO why?
- Log::debug(sprintf('Add a day (not sure why), so mutator is now: %s', $mutator->format('Y-m-d')));
$dayOfWeek = (int)$repetition->repetition_moment;
Log::debug(sprintf('DoW in repetition is %d, in mutator is %d', $dayOfWeek, $mutator->dayOfWeekIso));
if ($mutator->dayOfWeekIso > $dayOfWeek) {
@@ -228,14 +226,18 @@ class RecurringRepository implements RecurringRepositoryInterface
}
// today is wednesday (3), expected is friday (5): add two days.
// today is friday (5), expected is monday (1), subtract four days.
+ Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
$dayDifference = $dayOfWeek - $mutator->dayOfWeekIso;
$mutator->addDays($dayDifference);
+ Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
while ($mutator <= $end) {
if ($attempts % $skipMod === 0 && $start->lte($mutator) && $end->gte($mutator)) {
+ Log::debug('Date is in range of start+end, add to set.');
$return[] = clone $mutator;
}
$attempts++;
$mutator->addWeek();
+ Log::debug(sprintf('Mutator is now (end of loop): %s', $mutator->format('Y-m-d')));
}
break;
case 'monthly':
diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php
index cbe8f38983..2fae93b868 100644
--- a/resources/lang/en_US/firefly.php
+++ b/resources/lang/en_US/firefly.php
@@ -1267,5 +1267,8 @@ return [
'skip_transaction' => 'Skip the occurence',
'jump_to_friday' => 'Create the transaction on the previous Friday instead',
'jump_to_monday' => 'Create the transaction on the next Monday instead',
+ 'will_jump_friday' => 'Will be created on Friday instead of the weekends.',
+ 'will_jump_monday' => 'Will be created on Monday instead of the weekends.',
+ 'except_weekends' => 'Except weekends',
'recurrence_deleted' => 'Recurring transaction ":title" deleted',
];
diff --git a/resources/views/recurring/edit.twig b/resources/views/recurring/edit.twig
index 06267cdafd..cba7f8e113 100644
--- a/resources/views/recurring/edit.twig
+++ b/resources/views/recurring/edit.twig
@@ -21,6 +21,7 @@
{{ ExpandedForm.date('first_date',array.first_date, {helpText: trans('firefly.help_first_date_no_past')}) }}
{{ ExpandedForm.select('repetition_type', [], null, {helpText: trans('firefly.change_date_other_options')}) }}
{{ ExpandedForm.number('skip', array.recurrence_repetitions[0].repetition_skip) }}
+ {{ ExpandedForm.select('weekend', weekendResponses, array.recurrence_repetitions[0].weekend, {helpText: trans('firefly.help_weekend')}) }}
{{ ExpandedForm.select('repetition_end', repetitionEnds, repetitionEnd) }}
{{ ExpandedForm.date('repeat_until',array.repeat_until) }}
{{ ExpandedForm.number('repetitions', array.repetitions) }}
diff --git a/resources/views/recurring/index.twig b/resources/views/recurring/index.twig
index 7b27187baa..a4f39bd1d7 100644
--- a/resources/views/recurring/index.twig
+++ b/resources/views/recurring/index.twig
@@ -87,26 +87,34 @@
{% for rep in rt.recurrence_repetitions %}
<li>{{ rep.description }}
{% if rep.repetition_skip == 1 %}
- ({{ trans('firefly.recurring_skips_one')|lower }})
+ ({{ trans('firefly.recurring_skips_one')|lower }}).
{% endif %}
{% if rep.repetition_skip > 1 %}
- ({{ trans('firefly.recurring_skips_more', {count: rep.repetition_skip})|lower }})
+ ({{ trans('firefly.recurring_skips_more', {count: rep.repetition_skip})|lower }}).
{% endif %}
-
-
+ {% if rep.weekend == 3 %}
+ {{ 'will_jump_friday'|_ }}
+ {% endif %}
+ {% if rep.weekend == 4 %}
+ {{ 'will_jump_monday'|_ }}
+ {% endif %}
+ {% if rep.weekend == 2 %}
+ {{ 'except_weekends'|_ }}
+ {% endif %}
</li>
{% endfor %}
</ul>
<p>
{% if null == rt.repeat_until and rt.repetitions == 0 %}
- {{ 'recurring_repeats_forever'|_ }}
+ {{ 'recurring_repeats_forever'|_ }}.
{% endif %}
{% if null != rt.repeat_until and rt.repetitions == 0 %}
- {{ trans('firefly.recurring_repeats_until', {date: rt.repeat_until.formatLocalized(monthAndDayFormat)}) }}
+ {{ trans('firefly.recurring_repeats_until', {date: rt.repeat_until.formatLocalized(monthAndDayFormat)}) }}.
{% endif %}
{% if null == rt.repeat_until and rt.repetitions != 0 %}
- {{ trans('firefly.recurring_repeats_x_times', {count: rt.repetitions}) }}
+ {{ trans('firefly.recurring_repeats_x_times', {count: rt.repetitions}) }}.
{% endif %}
+
</p>
</td>
</tr>