Add display remember pdf

This commit is contained in:
Philipp Lang 2023-12-18 00:16:58 +01:00
parent f5ad0d46fd
commit 68a654494d
11 changed files with 125 additions and 134 deletions

View File

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

View File

@ -0,0 +1,20 @@
<?php
namespace App\Invoice\Actions;
use App\Invoice\Models\Invoice;
use App\Invoice\RememberDocument;
use Illuminate\Http\Response;
use Lorisleiva\Actions\Concerns\AsAction;
use Zoomyboy\Tex\BaseCompiler;
use Zoomyboy\Tex\Tex;
class DisplayRememberpdfAction
{
use AsAction;
public function handle(Invoice $invoice): BaseCompiler|Response
{
return Tex::compile(RememberDocument::fromInvoice($invoice));
}
}

View File

@ -5,7 +5,7 @@ namespace App\Invoice;
use App\Payment\Payment;
use Illuminate\Database\Eloquent\Relations\HasMany;
class RememberDocument extends Invoice
class RememberDocument extends InvoiceDocument
{
public function linkLabel(): string
{

View File

@ -37,6 +37,7 @@ class InvoiceResource extends JsonResource
'usage' => $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()]),
]

View File

@ -96,6 +96,8 @@
<td>
<a v-tooltip="`Anschauen`" :href="invoice.links.pdf" target="_BLANK"
class="inline-flex btn btn-info btn-sm"><ui-sprite src="eye"></ui-sprite></a>
<a v-tooltip="`Erinnerung anschauen`" :href="invoice.links.rememberpdf" target="_BLANK"
class="ml-2 inline-flex btn btn-info btn-sm"><ui-sprite src="document"></ui-sprite></a>
<a v-tooltip="`Bearbeiten`" href="#" class="ml-2 inline-flex btn btn-warning btn-sm"
@click.prevent="edit(invoice)"><ui-sprite src="pencil"></ui-sprite></a>
<a v-tooltip="`Löschen`" href="#" class="ml-2 inline-flex btn btn-danger btn-sm"

View File

@ -11,10 +11,10 @@
\setkomavar{fromlogo}{\includegraphics[width=2cm]{logo.png}} % stammeslogo
\begin{document}
\begin{letter}{Familie <<< $familyName >>>\\<<< $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:

View File

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

View File

@ -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<Invoice> $type
*/

View File

@ -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'))

View File

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

View File

@ -0,0 +1,64 @@
<?php
namespace Tests\Feature\Invoice;
use App\Invoice\BillKind;
use App\Invoice\InvoiceSettings;
use App\Invoice\Models\Invoice;
use App\Invoice\Models\InvoicePosition;
use App\Invoice\RememberDocument;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
use Zoomyboy\Tex\Tex;
class ShowRememberpdfTest extends TestCase
{
use DatabaseTransactions;
public function testItShowsRememberAsPdf(): 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()->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',
]));
}
}