mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Update some things for recurring transactions.
This commit is contained in:
@@ -25,9 +25,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Console;
|
namespace FireflyIII\Console;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Events\AdminRequestedTestMessage;
|
|
||||||
use FireflyIII\Jobs\CreateRecurringTransactions;
|
use FireflyIII\Jobs\CreateRecurringTransactions;
|
||||||
use FireflyIII\User;
|
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
|
|
||||||
@@ -62,7 +60,6 @@ class Kernel extends ConsoleKernel
|
|||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule): void
|
protected function schedule(Schedule $schedule): void
|
||||||
{
|
{
|
||||||
// create recurring transactions.
|
|
||||||
$schedule->job(new CreateRecurringTransactions(new Carbon))->daily();
|
$schedule->job(new CreateRecurringTransactions(new Carbon))->daily();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,8 @@ class RequestedReportOnJournals
|
|||||||
/**
|
/**
|
||||||
* Create a new event instance.
|
* Create a new event instance.
|
||||||
*
|
*
|
||||||
* @return void
|
* @param int $userId
|
||||||
|
* @param Collection $journals
|
||||||
*/
|
*/
|
||||||
public function __construct(int $userId, Collection $journals)
|
public function __construct(int $userId, Collection $journals)
|
||||||
{
|
{
|
||||||
|
@@ -51,7 +51,7 @@ class CreateRecurringTransactions implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
Log::debug('Now at start of CreateRecurringTransactions() job.');
|
Log::debug(sprintf('Now at start of CreateRecurringTransactions() job for %s.', $this->date->format('D d M Y')));
|
||||||
$recurrences = $this->repository->getAll();
|
$recurrences = $this->repository->getAll();
|
||||||
Log::debug(sprintf('Count of collection is %d', $recurrences->count()));
|
Log::debug(sprintf('Count of collection is %d', $recurrences->count()));
|
||||||
|
|
||||||
@@ -125,9 +125,6 @@ class CreateRecurringTransactions implements ShouldQueue
|
|||||||
$startDate = clone $recurrence->first_date;
|
$startDate = clone $recurrence->first_date;
|
||||||
if (null !== $recurrence->latest_date && $recurrence->latest_date->gte($startDate)) {
|
if (null !== $recurrence->latest_date && $recurrence->latest_date->gte($startDate)) {
|
||||||
$startDate = clone $recurrence->latest_date;
|
$startDate = clone $recurrence->latest_date;
|
||||||
// jump to a day later.
|
|
||||||
$startDate->addDay();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $startDate;
|
return $startDate;
|
||||||
@@ -250,12 +247,19 @@ class CreateRecurringTransactions implements ShouldQueue
|
|||||||
);
|
);
|
||||||
|
|
||||||
// start looping from $startDate to today perhaps we have a hit?
|
// start looping from $startDate to today perhaps we have a hit?
|
||||||
$occurrences = $this->repository->getOccurrencesInRange($repetition, $recurrence->first_date, $this->date);
|
// 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);
|
||||||
Log::debug(
|
Log::debug(
|
||||||
sprintf(
|
sprintf(
|
||||||
'Calculated %d occurrences between %s and %s', \count($occurrences), $recurrence->first_date->format('Y-m-d'), $this->date->format('Y-m-d')
|
'Calculated %d occurrences between %s and %s',
|
||||||
|
\count($occurrences),
|
||||||
|
$recurrence->first_date->format('Y-m-d'),
|
||||||
|
$includeWeekend->format('Y-m-d')
|
||||||
), $this->debugArray($occurrences)
|
), $this->debugArray($occurrences)
|
||||||
);
|
);
|
||||||
|
unset($includeWeekend);
|
||||||
|
|
||||||
$result = $this->handleOccurrences($recurrence, $occurrences);
|
$result = $this->handleOccurrences($recurrence, $occurrences);
|
||||||
$collection = $collection->merge($result);
|
$collection = $collection->merge($result);
|
||||||
|
@@ -65,7 +65,13 @@ class ReportNewJournalsMail extends Mailable
|
|||||||
*/
|
*/
|
||||||
public function build(): self
|
public function build(): self
|
||||||
{
|
{
|
||||||
|
$subject = $this->journals->count() === 1
|
||||||
|
? 'Firefly III has created a new transaction'
|
||||||
|
: sprintf(
|
||||||
|
'Firefly III has created new %d transactions', $this->journals->count()
|
||||||
|
);
|
||||||
|
|
||||||
return $this->view('emails.report-new-journals-html')->text('emails.report-new-journals-text')
|
return $this->view('emails.report-new-journals-html')->text('emails.report-new-journals-text')
|
||||||
->subject('Firefly III has created new transactions');
|
->subject($subject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -547,6 +547,8 @@ class RecurringRepository implements RecurringRepositoryInterface
|
|||||||
protected function filterWeekends(RecurrenceRepetition $repetition, array $dates): array
|
protected function filterWeekends(RecurrenceRepetition $repetition, array $dates): array
|
||||||
{
|
{
|
||||||
if ($repetition->weekend === RecurrenceRepetition::WEEKEND_DO_NOTHING) {
|
if ($repetition->weekend === RecurrenceRepetition::WEEKEND_DO_NOTHING) {
|
||||||
|
Log::debug('Repetition will not be filtered on weekend days.');
|
||||||
|
|
||||||
return $dates;
|
return $dates;
|
||||||
}
|
}
|
||||||
$return = [];
|
$return = [];
|
||||||
@@ -555,29 +557,42 @@ class RecurringRepository implements RecurringRepositoryInterface
|
|||||||
$isWeekend = $date->isWeekend();
|
$isWeekend = $date->isWeekend();
|
||||||
if (!$isWeekend) {
|
if (!$isWeekend) {
|
||||||
$return[] = clone $date;
|
$return[] = clone $date;
|
||||||
|
Log::debug(sprintf('Date is %s, not a weekend date.', $date->format('D d M Y')));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// is weekend and must set back to Friday?
|
// is weekend and must set back to Friday?
|
||||||
if ($isWeekend && $repetition->weekend === RecurrenceRepetition::WEEKEND_TO_FRIDAY) {
|
if ($repetition->weekend === RecurrenceRepetition::WEEKEND_TO_FRIDAY) {
|
||||||
$clone = clone $date;
|
$clone = clone $date;
|
||||||
$clone->addDays(5 - $date->dayOfWeekIso);
|
$clone->addDays(5 - $date->dayOfWeekIso);
|
||||||
|
Log::debug(
|
||||||
|
sprintf('Date is %s, and this is in the weekend, so corrected to %s (Friday).', $date->format('D d M Y'), $clone->format('D d M Y'))
|
||||||
|
);
|
||||||
$return[] = clone $clone;
|
$return[] = clone $clone;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// postpone to Monday?
|
// postpone to Monday?
|
||||||
if ($isWeekend && $repetition->weekend === RecurrenceRepetition::WEEKEND_TO_MONDAY) {
|
if ($repetition->weekend === RecurrenceRepetition::WEEKEND_TO_MONDAY) {
|
||||||
$clone = clone $date;
|
$clone = clone $date;
|
||||||
$clone->addDays(8 - $date->dayOfWeekIso);
|
$clone->addDays(8 - $date->dayOfWeekIso);
|
||||||
|
Log::debug(
|
||||||
|
sprintf('Date is %s, and this is in the weekend, so corrected to %s (Monday).', $date->format('D d M Y'), $clone->format('D d M Y'))
|
||||||
|
);
|
||||||
$return[] = $clone;
|
$return[] = $clone;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
Log::debug(sprintf('Date is %s, removed from final result', $date->format('D d M Y')));
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter unique dates
|
// filter unique dates
|
||||||
|
Log::debug(sprintf('Count before filtering: %d', \count($dates)));
|
||||||
$collection = new Collection($return);
|
$collection = new Collection($return);
|
||||||
$filtered = $collection->unique();
|
$filtered = $collection->unique();
|
||||||
$return = $filtered->toArray();
|
$return = $filtered->toArray();
|
||||||
|
|
||||||
|
Log::debug(sprintf('Count after filtering: %d', \count($return)));
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user