diff --git a/app/Invoice/Actions/DisplayPdfAction.php b/app/Invoice/Actions/DisplayPdfAction.php index 76aac191..8fefb91d 100644 --- a/app/Invoice/Actions/DisplayPdfAction.php +++ b/app/Invoice/Actions/DisplayPdfAction.php @@ -4,7 +4,6 @@ namespace App\Invoice\Actions; use App\Invoice\BillDocument; use App\Invoice\Models\Invoice; -use App\Payment\Payment; use Illuminate\Http\Response; use Lorisleiva\Actions\Concerns\AsAction; use Zoomyboy\Tex\BaseCompiler; diff --git a/app/Invoice/Actions/DisplayRememberpdfAction.php b/app/Invoice/Actions/DisplayRememberpdfAction.php new file mode 100644 index 00000000..358172c6 --- /dev/null +++ b/app/Invoice/Actions/DisplayRememberpdfAction.php @@ -0,0 +1,20 @@ + $this->usage, 'links' => [ 'pdf' => route('invoice.pdf', ['invoice' => $this->getModel()]), + 'rememberpdf' => route('invoice.rememberpdf', ['invoice' => $this->getModel()]), 'update' => route('invoice.update', ['invoice' => $this->getModel()]), 'destroy' => route('invoice.destroy', ['invoice' => $this->getModel()]), ] diff --git a/resources/js/views/invoice/Index.vue b/resources/js/views/invoice/Index.vue index cf8d89fe..c23551d6 100644 --- a/resources/js/views/invoice/Index.vue +++ b/resources/js/views/invoice/Index.vue @@ -96,6 +96,8 @@ + >>\\<<< $address >>>\\<<< $zip >>> <<< $location >>>} +\begin{letter}{<<< $toName >>>\\<<< $toAddress >>>\\<<< $toZip >>> <<< $toLocation >>>} \sffamily \gdef\TotalHT{0} - \opening{Liebe Familie <<< $familyName >>>,} + \opening{<<< $greeting >>>,} Ihr Mitgliedbeitrag ist noch ausstehend. Dieser setzt sich wie folgt zusammen: diff --git a/routes/web.php b/routes/web.php index 145a621c..36e65c88 100644 --- a/routes/web.php +++ b/routes/web.php @@ -26,6 +26,7 @@ use App\Initialize\Actions\NamiGetSearchLayerAction; use App\Initialize\Actions\NamiLoginCheckAction; use App\Initialize\Actions\NamiSearchAction; use App\Invoice\Actions\DisplayPdfAction; +use App\Invoice\Actions\DisplayRememberpdfAction; use App\Invoice\Actions\InvoiceDestroyAction; use App\Invoice\Actions\InvoiceIndexAction; use App\Invoice\Actions\InvoiceUpdateAction; @@ -112,6 +113,7 @@ Route::group(['middleware' => 'auth:web'], function (): void { Route::patch('/invoice/{invoice}', InvoiceUpdateAction::class)->name('invoice.update'); Route::delete('/invoice/{invoice}', InvoiceDestroyAction::class)->name('invoice.destroy'); Route::get('/invoice/{invoice}/pdf', DisplayPdfAction::class)->name('invoice.pdf'); + Route::get('/invoice/{invoice}/rememberpdf', DisplayRememberpdfAction::class)->name('invoice.rememberpdf'); // ----------------------------- invoice-position ------------------------------ diff --git a/tests/Feature/Invoice/BillRememberDocumentTest.php b/tests/Feature/Invoice/BillRememberDocumentTest.php index 9bfeea5b..8a605c09 100644 --- a/tests/Feature/Invoice/BillRememberDocumentTest.php +++ b/tests/Feature/Invoice/BillRememberDocumentTest.php @@ -5,104 +5,17 @@ namespace Tests\Feature\Invoice; use App\Invoice\BillDocument; use App\Invoice\BillKind; use App\Invoice\Invoice; -use App\Invoice\InvoiceSettings; use App\Invoice\Queries\BillKindQuery; use App\Invoice\Queries\InvoiceMemberQuery; -use App\Invoice\RememberDocument; use App\Member\Member; use App\Payment\Payment; use Illuminate\Foundation\Testing\DatabaseTransactions; -use Tests\RequestFactories\Child; use Tests\TestCase; class BillRememberDocumentTest extends TestCase { use DatabaseTransactions; - public function testItDisplaysMemberInformation(): void - { - $member = Member::factory() - ->defaults() - ->state([ - 'firstname' => '::firstname::', - 'lastname' => '::lastname::', - 'address' => '::street::', - 'zip' => '::zip::', - 'location' => '::location::', - ]) - ->postBillKind() - ->has(Payment::factory()->notPaid()->nr('1995')->subscription('::subName::', [ - new Child('a', 1000), - new Child('a', 500), - ])) - ->create(); - - $invoice = BillDocument::fromMembers($this->query(BillDocument::class)->getMembers()->first()); - - $invoice->assertHasAllContent([ - 'Rechnung', - '15.00', - '::subName:: 1995 für ::firstname:: ::lastname::', - 'Mitgliedsbeitrag für ::lastname::', - 'Familie ::lastname::\\\\::street::\\\\::zip:: ::location::', - ]); - } - - public function testItDisplaysSplitPayments(): void - { - $member = Member::factory() - ->defaults() - ->postBillKind() - ->state([ - 'firstname' => '::firstname::', - 'lastname' => '::lastname::', - ]) - ->has(Payment::factory()->notPaid()->nr('1995')->subscription('::subName::', [ - new Child('a', 1000), - new Child('b', 500), - ], ['split' => true])) - ->create(); - - $invoice = BillDocument::fromMembers($this->query(BillDocument::class)->getMembers()->first()); - - $invoice->assertHasAllContent([ - 'Rechnung', - '10.00', - '5.00', - '::subName:: (a) 1995 für ::firstname:: ::lastname::', - '::subName:: (b) 1995 für ::firstname:: ::lastname::', - 'Mitgliedsbeitrag für ::lastname::', - ]); - } - - public function testBillSetsFilename(): void - { - Member::factory() - ->defaults() - ->postBillKind() - ->state(['lastname' => '::lastname::']) - ->has(Payment::factory()->notPaid()->nr('1995')) - ->create(); - - $invoice = BillDocument::fromMembers($this->query(BillDocument::class)->getMembers()->first()); - - $this->assertEquals('rechnung-fur-lastname.pdf', $invoice->compiledFilename()); - } - - public function testRememberSetsFilename(): void - { - Member::factory() - ->postBillKind() - ->defaults() - ->state(['lastname' => '::lastname::']) - ->has(Payment::factory()->notPaid()->state(['last_remembered_at' => now()->subMonths(6)])) - ->create(); - - $invoice = RememberDocument::fromMembers($this->query(RememberDocument::class)->getMembers()->first()); - - $this->assertEquals('zahlungserinnerung-fur-lastname.pdf', $invoice->compiledFilename()); - } - public function testItCreatesOneFileForFamilyMembers(): void { Member::factory() @@ -121,46 +34,6 @@ class BillRememberDocumentTest extends TestCase $this->assertCount(2, $this->query(BillDocument::class)->getMembers()->first()); } - /** - * @testWith ["App\\Invoice\\BillDocument"] - * ["App\\Invoice\\RememberDocument"] - */ - public function testItDisplaysSettings(string $type): void - { - InvoiceSettings::fake([ - 'from_long' => 'langer Stammesname', - 'from' => 'Stammeskurz', - 'mobile' => '+49 176 55555', - 'email' => 'max@muster.de', - 'website' => 'https://example.com', - 'address' => 'Musterstr 4', - 'place' => 'Münster', - 'zip' => '12345', - 'iban' => 'DE444', - 'bic' => 'SOLSSSSS', - ]); - Member::factory() - ->defaults() - ->postBillKind() - ->has(Payment::factory()->notPaid()->nr('nr2')->state(['last_remembered_at' => now()->subYear()])) - ->create(); - - $invoice = BillDocument::fromMembers($this->query(BillDocument::class)->getMembers()->first()); - - $invoice->assertHasAllContent([ - 'langer Stammesname', - 'Stammeskurz', - '+49 176 55555', - 'max@muster.de', - 'https://example.com', - 'Musterstr 4', - 'Münster', - '12345', - 'DE444', - 'SOLSSSSS', - ]); - } - /** * @param class-string $type */ diff --git a/tests/Feature/Invoice/InvoiceIndexActionTest.php b/tests/Feature/Invoice/InvoiceIndexActionTest.php index 7717ece8..9b45f020 100644 --- a/tests/Feature/Invoice/InvoiceIndexActionTest.php +++ b/tests/Feature/Invoice/InvoiceIndexActionTest.php @@ -42,6 +42,7 @@ class InvoiceIndexActionTest extends TestCase ->assertInertiaPath('data.data.0.positions.0.description', 'lala') ->assertInertiaPath('data.data.0.positions.0.id', $invoice->positions->first()->id) ->assertInertiaPath('data.data.0.links.pdf', route('invoice.pdf', ['invoice' => $invoice])) + ->assertInertiaPath('data.data.0.links.rememberpdf', route('invoice.rememberpdf', ['invoice' => $invoice])) ->assertInertiaPath('data.data.0.links.update', route('invoice.update', ['invoice' => $invoice])) ->assertInertiaPath('data.data.0.links.destroy', route('invoice.destroy', ['invoice' => $invoice])) ->assertInertiaPath('data.meta.links.mass-store', route('invoice.mass-store')) diff --git a/tests/Feature/Invoice/ShowPdfTest.php b/tests/Feature/Invoice/ShowPdfTest.php index 65391a63..0158354a 100644 --- a/tests/Feature/Invoice/ShowPdfTest.php +++ b/tests/Feature/Invoice/ShowPdfTest.php @@ -4,6 +4,7 @@ namespace Tests\Feature\Invoice; use App\Invoice\BillDocument; use App\Invoice\BillKind; +use App\Invoice\InvoiceSettings; use App\Invoice\Models\Invoice; use App\Invoice\Models\InvoicePosition; use Illuminate\Foundation\Testing\DatabaseTransactions; @@ -18,18 +19,46 @@ class ShowPdfTest extends TestCase public function testItShowsAnInvoiceAsPdf(): void { Tex::spy(); + InvoiceSettings::fake([ + 'from_long' => 'langer Stammesname', + 'from' => 'Stammeskurz', + 'mobile' => '+49 176 55555', + 'email' => 'max@muster.de', + 'website' => 'https://example.com', + 'address' => 'Musterstr 4', + 'place' => 'Münster', + 'zip' => '12345', + 'iban' => 'DE444', + 'bic' => 'SOLSSSSS', + ]); $this->login()->loginNami(); $invoice = Invoice::factory() ->to(ReceiverRequestFactory::new()->name('Familie Lala')) - ->has(InvoicePosition::factory()->withMember()->description('Beitrag12'), 'positions') + ->has(InvoicePosition::factory()->withMember()->price(1500)->description('Beitrag12'), 'positions') ->via(BillKind::EMAIL) - ->create(); + ->create(['usage' => 'Usa']); $this->get(route('invoice.pdf', ['invoice' => $invoice])) ->assertOk() ->assertPdfPageCount(1) ->assertPdfName('rechnung-fur-familie-lala.pdf'); - Tex::assertCompiled(BillDocument::class, fn ($document) => $document->hasAllContent(['Beitrag12', 'Familie Lala'])); + Tex::assertCompiled(BillDocument::class, fn ($document) => $document->hasAllContent([ + 'Beitrag12', + 'Familie Lala', + 'Rechnung', + '15.00', + 'Usa', + 'langer Stammesname', + 'Stammeskurz', + '+49 176 55555', + 'max@muster.de', + 'https://example.com', + 'Musterstr 4', + 'Münster', + '12345', + 'DE444', + 'SOLSSSSS', + ])); } } diff --git a/tests/Feature/Invoice/ShowRememberpdfTest.php b/tests/Feature/Invoice/ShowRememberpdfTest.php new file mode 100644 index 00000000..bf198126 --- /dev/null +++ b/tests/Feature/Invoice/ShowRememberpdfTest.php @@ -0,0 +1,64 @@ + 'langer Stammesname', + 'from' => 'Stammeskurz', + 'mobile' => '+49 176 55555', + 'email' => 'max@muster.de', + 'website' => 'https://example.com', + 'address' => 'Musterstr 4', + 'place' => 'Münster', + 'zip' => '12345', + 'iban' => 'DE444', + 'bic' => 'SOLSSSSS', + ]); + $this->login()->loginNami(); + $invoice = Invoice::factory() + ->to(ReceiverRequestFactory::new()->name('Familie Lala')) + ->has(InvoicePosition::factory()->withMember()->price(1500)->description('Beitrag12'), 'positions') + ->via(BillKind::EMAIL) + ->create(['usage' => 'Usa']); + + $this->get(route('invoice.rememberpdf', ['invoice' => $invoice])) + ->assertOk() + ->assertPdfPageCount(1) + ->assertPdfName('zahlungserinnerung-fur-familie-lala.pdf'); + + Tex::assertCompiled(RememberDocument::class, fn ($document) => $document->hasAllContent([ + 'Beitrag12', + 'Familie Lala', + 'Zahlungserinnerung', + '15.00', + 'Usa', + 'langer Stammesname', + 'Stammeskurz', + '+49 176 55555', + 'max@muster.de', + 'https://example.com', + 'Musterstr 4', + 'Münster', + '12345', + 'DE444', + 'SOLSSSSS', + ])); + } +}