Add RememberWeeks setting for remembering invoices
continuous-integration/drone/push Build is passing Details

This commit is contained in:
philipp lang 2024-07-31 21:37:18 +02:00
parent fe258198f4
commit 343b0d418d
9 changed files with 44 additions and 3 deletions

View File

@ -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;

View File

@ -28,6 +28,8 @@ class InvoiceSettings extends LocalSettings implements Indexable, Storeable
public string $bic;
public int $rememberWeeks;
public static function group(): string
{
return 'bill';

View File

@ -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<self>
*/
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));
}
/**

View File

@ -26,6 +26,7 @@ class SettingIndexAction
'zip' => $settings->zip,
'iban' => $settings->iban,
'bic' => $settings->bic,
'remember_weeks' => $settings->rememberWeeks,
];
}

View File

@ -28,6 +28,7 @@ class SettingSaveAction
'zip' => $input['zip'] ?? '',
'iban' => $input['iban'] ?? '',
'bic' => $input['bic'] ?? '',
'rememberWeeks' => $input['remember_weeks'] ?? 1,
]);
$settings->save();

View File

@ -0,0 +1,11 @@
<?php
use Spatie\LaravelSettings\Migrations\SettingsMigration;
return new class extends SettingsMigration
{
public function up(): void
{
$this->migrator->add('bill.rememberWeeks', 12);
}
};

View File

@ -17,6 +17,7 @@
<f-text id="website" v-model="inner.website" label="Webseite"></f-text>
<f-text id="iban" v-model="inner.iban" label="IBAN"></f-text>
<f-text id="bic" v-model="inner.bic" label="BIC"></f-text>
<f-text id="remember_weeks" v-model="inner.remember_weeks" type="number" label="Erinnerung alle X Wochen versenden"></f-text>
</form>
</setting-layout>
</page-layout>

View File

@ -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();

View File

@ -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);
}
}