diff --git a/app/Invoice/Actions/InvoiceSendAction.php b/app/Invoice/Actions/InvoiceSendAction.php index 9fb3cc66..e66d8b5b 100644 --- a/app/Invoice/Actions/InvoiceSendAction.php +++ b/app/Invoice/Actions/InvoiceSendAction.php @@ -4,7 +4,6 @@ namespace App\Invoice\Actions; use App\Invoice\BillDocument; use App\Invoice\BillKind; -use App\Invoice\Enums\InvoiceStatus; use App\Invoice\Mails\BillMail; use App\Invoice\Mails\RememberMail; use App\Invoice\Models\Invoice; diff --git a/app/Invoice/InvoiceSettings.php b/app/Invoice/InvoiceSettings.php index a29264de..e842d37f 100644 --- a/app/Invoice/InvoiceSettings.php +++ b/app/Invoice/InvoiceSettings.php @@ -28,6 +28,8 @@ class InvoiceSettings extends LocalSettings implements Indexable, Storeable public string $bic; + public int $rememberWeeks; + public static function group(): string { return 'bill'; diff --git a/app/Invoice/Models/Invoice.php b/app/Invoice/Models/Invoice.php index a0678852..733125d9 100644 --- a/app/Invoice/Models/Invoice.php +++ b/app/Invoice/Models/Invoice.php @@ -6,6 +6,7 @@ use App\Invoice\BillDocument; use App\Invoice\BillKind; use App\Invoice\Enums\InvoiceStatus; use App\Invoice\InvoiceDocument; +use App\Invoice\InvoiceSettings; use App\Invoice\RememberDocument; use App\Invoice\Scopes\InvoiceFilterScope; use App\Member\Member; @@ -111,13 +112,14 @@ class Invoice extends Model * * @return Builder */ - public function scopeWhereNeedsRemember(Builder $query): Builder + public function scopeWhereNeedsRemember(Builder $query, ?int $weeks = null): Builder { + $weeks = $weeks ?: app(InvoiceSettings::class)->rememberWeeks; return $query ->where('status', InvoiceStatus::SENT) ->whereNotNull('sent_at') ->whereNotNull('last_remembered_at') - ->where('last_remembered_at', '<=', now()->subMonths(3)); + ->where('last_remembered_at', '<=', now()->subWeeks($weeks)); } /** diff --git a/app/Invoice/SettingIndexAction.php b/app/Invoice/SettingIndexAction.php index 6a8f13cd..11341622 100644 --- a/app/Invoice/SettingIndexAction.php +++ b/app/Invoice/SettingIndexAction.php @@ -26,6 +26,7 @@ class SettingIndexAction 'zip' => $settings->zip, 'iban' => $settings->iban, 'bic' => $settings->bic, + 'remember_weeks' => $settings->rememberWeeks, ]; } diff --git a/app/Invoice/SettingSaveAction.php b/app/Invoice/SettingSaveAction.php index 539620da..38b0ec0f 100644 --- a/app/Invoice/SettingSaveAction.php +++ b/app/Invoice/SettingSaveAction.php @@ -28,6 +28,7 @@ class SettingSaveAction 'zip' => $input['zip'] ?? '', 'iban' => $input['iban'] ?? '', 'bic' => $input['bic'] ?? '', + 'rememberWeeks' => $input['remember_weeks'] ?? 1, ]); $settings->save(); diff --git a/database/settings/2024_07_31_211952_create_invoice_remember_weeks_setting.php b/database/settings/2024_07_31_211952_create_invoice_remember_weeks_setting.php new file mode 100644 index 00000000..d1b0fe96 --- /dev/null +++ b/database/settings/2024_07_31_211952_create_invoice_remember_weeks_setting.php @@ -0,0 +1,11 @@ +migrator->add('bill.rememberWeeks', 12); + } +}; diff --git a/resources/js/views/setting/Bill.vue b/resources/js/views/setting/Bill.vue index 0671eb91..76193419 100644 --- a/resources/js/views/setting/Bill.vue +++ b/resources/js/views/setting/Bill.vue @@ -17,6 +17,7 @@ + diff --git a/tests/Feature/Invoice/InvoiceSendActionTest.php b/tests/Feature/Invoice/InvoiceSendActionTest.php index 807d021a..83b8dc66 100644 --- a/tests/Feature/Invoice/InvoiceSendActionTest.php +++ b/tests/Feature/Invoice/InvoiceSendActionTest.php @@ -6,6 +6,7 @@ use App\Invoice\Actions\InvoiceSendAction; use App\Invoice\BillDocument; use App\Invoice\BillKind; use App\Invoice\Enums\InvoiceStatus; +use App\Invoice\InvoiceSettings; use App\Invoice\Mails\BillMail; use App\Invoice\Mails\RememberMail; use App\Invoice\Models\Invoice; @@ -76,6 +77,25 @@ class InvoiceSendActionTest extends TestCase Mail::assertNotSent(RememberMail::class); } + public function testItRemembersWhenWeeksSettingIsReached(): void + { + Mail::fake(); + $this->withoutExceptionHandling()->login()->loginNami(); + Invoice::factory() + ->has(InvoicePosition::factory()->withMember(), 'positions') + ->via(BillKind::EMAIL) + ->status(InvoiceStatus::SENT) + ->create(['sent_at' => now()->subYear(), 'last_remembered_at' => now()->subWeeks(5)->subDay()]); + + app(InvoiceSettings::class)->fill(['rememberWeeks' => 6])->save(); + InvoiceSendAction::run(); + Mail::assertNotSent(RememberMail::class); + + app(InvoiceSettings::class)->fill(['rememberWeeks' => 5])->save(); + InvoiceSendAction::run(); + Mail::assertSent(RememberMail::class); + } + public function testItDoesntSendPostInvoices(): void { Mail::fake(); diff --git a/tests/Feature/Invoice/SettingTest.php b/tests/Feature/Invoice/SettingTest.php index c4c4f16b..3e451023 100644 --- a/tests/Feature/Invoice/SettingTest.php +++ b/tests/Feature/Invoice/SettingTest.php @@ -24,6 +24,7 @@ class SettingTest extends TestCase 'zip' => '12345', 'iban' => 'DE05', 'bic' => 'SOLSDE', + 'rememberWeeks' => 6 ]); $response = $this->get('/setting/bill'); @@ -40,6 +41,7 @@ class SettingTest extends TestCase 'zip' => '12345', 'iban' => 'DE05', 'bic' => 'SOLSDE', + 'remember_weeks' => 6 ], $response, 'data'); } @@ -77,6 +79,7 @@ class SettingTest extends TestCase 'zip' => '12345', 'iban' => 'DE05', 'bic' => 'SOLSDE', + 'remember_weeks' => 10 ]); $response->assertRedirect('/setting/bill'); @@ -84,5 +87,6 @@ class SettingTest extends TestCase $this->assertEquals('DPSG Stamm Muster', $settings->from_long); $this->assertEquals('DE05', $settings->iban); $this->assertEquals('SOLSDE', $settings->bic); + $this->assertEquals(10, $settings->rememberWeeks); } }