Expand view to include weekend responses.

This commit is contained in:
James Cole 2018-06-27 18:30:53 +02:00
parent 7b46339a5d
commit a8e666db34
6 changed files with 37 additions and 15 deletions

View File

@ -88,7 +88,6 @@ class EditController extends Controller
// todo handle old repetition type as well. // todo handle old repetition type as well.
/** @var RecurrenceRepetition $repetition */ /** @var RecurrenceRepetition $repetition */
$repetition = $recurrence->recurrenceRepetitions()->first(); $repetition = $recurrence->recurrenceRepetitions()->first();
$currentRepetitionType = $repetition->repetition_type; $currentRepetitionType = $repetition->repetition_type;
@ -117,6 +116,14 @@ class EditController extends Controller
$repetitionEnd = 'times'; $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 // code to handle active-checkboxes
$hasOldInput = null !== $request->old('_token'); $hasOldInput = null !== $request->old('_token');
// $hasOldInput = false; // $hasOldInput = false;
@ -126,7 +133,10 @@ class EditController extends Controller
'apply_rules' => $hasOldInput ? (bool)$request->old('apply_rules') : $recurrence->apply_rules, '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')
);
} }
/** /**

View File

@ -82,8 +82,6 @@ class CreateRecurringTransactions implements ShouldQueue
Log::debug('Now running report thing.'); Log::debug('Now running report thing.');
// will now send email to users. // will now send email to users.
foreach ($result as $userId => $journals) { 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)); event(new RequestedReportOnJournals($userId, $journals));
} }

View File

@ -217,8 +217,6 @@ class RecurringRepository implements RecurringRepositoryInterface
Log::debug('Rep is weekly.'); Log::debug('Rep is weekly.');
// monday = 1 // monday = 1
// sunday = 7 // 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; $dayOfWeek = (int)$repetition->repetition_moment;
Log::debug(sprintf('DoW in repetition is %d, in mutator is %d', $dayOfWeek, $mutator->dayOfWeekIso)); Log::debug(sprintf('DoW in repetition is %d, in mutator is %d', $dayOfWeek, $mutator->dayOfWeekIso));
if ($mutator->dayOfWeekIso > $dayOfWeek) { 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 wednesday (3), expected is friday (5): add two days.
// today is friday (5), expected is monday (1), subtract four 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; $dayDifference = $dayOfWeek - $mutator->dayOfWeekIso;
$mutator->addDays($dayDifference); $mutator->addDays($dayDifference);
Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
while ($mutator <= $end) { while ($mutator <= $end) {
if ($attempts % $skipMod === 0 && $start->lte($mutator) && $end->gte($mutator)) { 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; $return[] = clone $mutator;
} }
$attempts++; $attempts++;
$mutator->addWeek(); $mutator->addWeek();
Log::debug(sprintf('Mutator is now (end of loop): %s', $mutator->format('Y-m-d')));
} }
break; break;
case 'monthly': case 'monthly':

View File

@ -1267,5 +1267,8 @@ return [
'skip_transaction' => 'Skip the occurence', 'skip_transaction' => 'Skip the occurence',
'jump_to_friday' => 'Create the transaction on the previous Friday instead', 'jump_to_friday' => 'Create the transaction on the previous Friday instead',
'jump_to_monday' => 'Create the transaction on the next Monday 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', 'recurrence_deleted' => 'Recurring transaction ":title" deleted',
]; ];

View File

@ -21,6 +21,7 @@
{{ ExpandedForm.date('first_date',array.first_date, {helpText: trans('firefly.help_first_date_no_past')}) }} {{ 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.select('repetition_type', [], null, {helpText: trans('firefly.change_date_other_options')}) }}
{{ ExpandedForm.number('skip', array.recurrence_repetitions[0].repetition_skip) }} {{ 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.select('repetition_end', repetitionEnds, repetitionEnd) }}
{{ ExpandedForm.date('repeat_until',array.repeat_until) }} {{ ExpandedForm.date('repeat_until',array.repeat_until) }}
{{ ExpandedForm.number('repetitions', array.repetitions) }} {{ ExpandedForm.number('repetitions', array.repetitions) }}

View File

@ -87,26 +87,34 @@
{% for rep in rt.recurrence_repetitions %} {% for rep in rt.recurrence_repetitions %}
<li>{{ rep.description }} <li>{{ rep.description }}
{% if rep.repetition_skip == 1 %} {% if rep.repetition_skip == 1 %}
({{ trans('firefly.recurring_skips_one')|lower }}) ({{ trans('firefly.recurring_skips_one')|lower }}).
{% endif %} {% endif %}
{% if rep.repetition_skip > 1 %} {% 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 %} {% endif %}
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
<p> <p>
{% if null == rt.repeat_until and rt.repetitions == 0 %} {% if null == rt.repeat_until and rt.repetitions == 0 %}
{{ 'recurring_repeats_forever'|_ }} {{ 'recurring_repeats_forever'|_ }}.
{% endif %} {% endif %}
{% if null != rt.repeat_until and rt.repetitions == 0 %} {% 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 %} {% endif %}
{% if null == rt.repeat_until and rt.repetitions != 0 %} {% 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 %} {% endif %}
</p> </p>
</td> </td>
</tr> </tr>