From 3c297f1e937303baaa684f57ba7f3ba5ab3f1c43 Mon Sep 17 00:00:00 2001 From: Luiz Amaral Date: Sun, 25 Jun 2023 13:26:03 +0200 Subject: [PATCH] Add :MONTHYEAR keyword to recurring expenses --- app/Factory/RecurringExpenseToExpenseFactory.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/Factory/RecurringExpenseToExpenseFactory.php b/app/Factory/RecurringExpenseToExpenseFactory.php index 98c2a7beee6f..82ea9224f75a 100644 --- a/app/Factory/RecurringExpenseToExpenseFactory.php +++ b/app/Factory/RecurringExpenseToExpenseFactory.php @@ -95,6 +95,11 @@ class RecurringExpenseToExpenseFactory $replacements = [ 'literal' => [ + ':MONTHYEAR' => \sprintf( + '%s %s', + Carbon::createFromDate(now()->year, now()->month)->translatedFormat('F'), + now()->year, + ), ':MONTH' => Carbon::createFromDate(now()->year, now()->month)->translatedFormat('F'), ':YEAR' => now()->year, ':QUARTER' => 'Q'.now()->quarter, @@ -240,6 +245,17 @@ class RecurringExpenseToExpenseFactory $output = \Carbon\Carbon::create()->month($output)->translatedFormat('F'); } + if ($matches->keys()->first() == ':MONTHYEAR') { + + $final_date = now()->addMonths($output-now()->month); + + $output = \sprintf( + '%s %s', + $final_date->translatedFormat('F'), + $final_date->year, + ); + } + $value = preg_replace( $target, $output,