Add base gallier document

This commit is contained in:
philipp lang 2024-12-13 00:58:44 +01:00
parent b05c5025c0
commit 1a4a7c3652
5 changed files with 313 additions and 151 deletions

View File

@ -8,6 +8,7 @@ use App\Contribution\Documents\RdpNrwDocument;
use App\Contribution\Documents\CityRemscheidDocument;
use App\Contribution\Documents\CitySolingenDocument;
use App\Contribution\Documents\CityFrankfurtMainDocument;
use App\Contribution\Documents\GallierDocument;
use Illuminate\Support\Collection;
use Illuminate\Validation\Rule;
@ -22,6 +23,7 @@ class ContributionFactory
CityRemscheidDocument::class,
CityFrankfurtMainDocument::class,
BdkjHesse::class,
GallierDocument::class,
];
/**

View File

@ -0,0 +1,142 @@
<?php
namespace App\Contribution\Documents;
use App\Contribution\Data\MemberData;
use App\Country;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Zoomyboy\Tex\Engine;
use Zoomyboy\Tex\Template;
class GallierDocument extends ContributionDocument
{
/**
* @param Collection<int, Collection<int, MemberData>> $members
*/
public function __construct(
public string $dateFrom,
public string $dateUntil,
public string $zipLocation,
public ?Country $country,
public Collection $members,
public ?string $filename = '',
public string $type = 'F',
) {
}
public function dateRange(): string
{
return Carbon::parse($this->dateFrom)->format('d.m.Y')
. ' - '
. Carbon::parse($this->dateUntil)->format('d.m.Y');
}
/**
* {@inheritdoc}
*/
public static function fromRequest(array $request): self
{
return new self(
dateFrom: $request['dateFrom'],
dateUntil: $request['dateUntil'],
zipLocation: $request['zipLocation'],
country: Country::where('id', $request['country'])->firstOrFail(),
members: MemberData::fromModels($request['members'])->chunk(14),
);
}
/**
* {@inheritdoc}
*/
public static function fromApiRequest(array $request): self
{
return new self(
dateFrom: $request['dateFrom'],
dateUntil: $request['dateUntil'],
zipLocation: $request['zipLocation'],
country: Country::where('id', $request['country'])->firstOrFail(),
members: MemberData::fromApi($request['member_data'])->chunk(14),
);
}
public function countryName(): string
{
return $this->country->name;
}
public function memberShort(MemberData $member): string
{
return $member->isLeader ? 'L' : '';
}
public function memberName(MemberData $member): string
{
return $member->separatedName();
}
public function memberAddress(MemberData $member): string
{
return $member->fullAddress();
}
public function memberGender(MemberData $member): string
{
if (!$member->gender) {
return '';
}
return strtolower(substr($member->gender->name, 0, 1));
}
public function memberAge(MemberData $member): string
{
return $member->age();
}
public function basename(): string
{
return 'zuschuesse-gallier';
}
public function view(): string
{
return 'tex.contribution.gallier';
}
public function template(): Template
{
return Template::make('tex.templates.contribution');
}
public function setFilename(string $filename): static
{
$this->filename = $filename;
return $this;
}
public function getEngine(): Engine
{
return Engine::PDFLATEX;
}
public static function getName(): string
{
return 'Für RdP NRW erstellen';
}
/**
* @return array<string, mixed>
*/
public static function rules(): array
{
return [
'dateFrom' => 'required|string|date_format:Y-m-d',
'dateUntil' => 'required|string|date_format:Y-m-d',
'country' => 'required|integer|exists:countries,id',
'zipLocation' => 'required|string',
'eventName' => 'required|string',
];
}
}

View File

@ -0,0 +1,38 @@
\documentclass[a4paper,landscape]{article}
\usepackage[landscape,top=0cm,left=0cm,bottom=0cm,right=0cm]{geometry}
\usepackage{tikz}
\usepackage{background}
\usepackage{blindtext}
\usetikzlibrary{matrix, shapes.misc, calc}
\pagestyle{empty}
\setlength{\parindent}{0cm}
\backgroundsetup{scale = 1, angle = 0, opacity = 1, color=black, contents = {\includegraphics[width = \paperwidth, height = \paperheight] {rdp-nrw.pdf}}}
\begin{document}
\noindent \sffamily
@foreach($members as $chunk)
\begin{tikzpicture}[remember picture,overlay,yscale=-1]
\node[anchor=base west] at (38mm,41.62mm) {\bfseries{\large{<<<!!$dateRange!!>>>}}};
\node[anchor=base west] at (135.2mm,41.62mm) {\bfseries{\large{<<<!!$zipLocation!!>>>}}};
\node[thick, cross out,draw=black,text width=2.4mm, text height=2.4mm, inner sep=0mm] at (17.76mm,47.10mm) {};
@foreach($chunk as $i => $member)
\node[anchor=base, text width=7.75mm, align=center] at ($(16.35mm, 76.6mm + 7mm * <<<$i % 17>>>)$) {<<<$i+1>>>};
\node[anchor=base, text width=18mm, align=center] at ($(32.55mm, 76.6mm + 7mm * <<<$i%17>>>)$) {<<<$memberShort($member)>>>};
\node[anchor=base, text width=70mm, align=center] at ($(80.25mm, 76.6mm + 7mm * <<<$i%17>>>)$) {<<<$memberName($member)>>>};
\node[anchor=base, text width=118mm, align=center] at ($(178.25mm, 76.6mm + 7mm * <<<$i%17>>>)$) {<<<$memberAddress($member)>>>};
\node[anchor=base, text width=16mm, align=center] at ($(249.50mm, 76.6mm + 7mm * <<<$i%17>>>)$) {<<<$memberGender($member)>>>};
\node[anchor=base, text width=16mm, align=center] at ($(269.50mm, 76.6mm + 7mm * <<<$i%17>>>)$) {<<<$memberAge($member)>>>};
@endforeach
\end{tikzpicture}
\pagebreak
@endforeach
\end{document}

Binary file not shown.

View File

@ -14,26 +14,85 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
use Laravel\Passport\Client;
use Laravel\Passport\Passport;
use PHPUnit\Framework\Attributes\DataProvider;
use Spatie\LaravelData\Data;
use Tests\RequestFactories\ContributionMemberApiRequestFactory;
use Tests\RequestFactories\ContributionRequestFactory;
use Tests\TestCase;
use Zoomyboy\Tex\Tex;
class StoreTest extends TestCase
{
use DatabaseTransactions;
uses(DatabaseTransactions::class);
/**
* @testWith ["App\\Contribution\\Documents\\CitySolingenDocument", ["Super tolles Lager", "Max Muster", "Jane Muster", "15.06.1991"]]
* ["App\\Contribution\\Documents\\RdpNrwDocument", ["Muster, Max", "Muster, Jane", "15.06.1991", "42777 SG"]]
* ["App\\Contribution\\Documents\\CityRemscheidDocument", ["Max", "Muster", "Jane"]]
* ["App\\Contribution\\Documents\\CityFrankfurtMainDocument", ["Max", "Muster", "Jane"]]
* ["App\\Contribution\\Documents\\BdkjHesse", ["Max", "Muster", "Jane"]]
*
* @param array<int, string> $bodyChecks
*/
public function testItCompilesContributionDocumentsViaRequest(string $type, array $bodyChecks): void
{
dataset('validation', function () {
return [
[
['type' => 'aaa'],
CitySolingenDocument::class,
'type',
],
[
['type' => ''],
CitySolingenDocument::class,
'type',
],
[
['dateFrom' => ''],
CitySolingenDocument::class,
'dateFrom',
],
[
['dateFrom' => '2022-01'],
CitySolingenDocument::class,
'dateFrom',
],
[
['dateUntil' => ''],
CitySolingenDocument::class,
'dateUntil',
],
[
['dateUntil' => '2022-01'],
CitySolingenDocument::class,
'dateUntil',
],
[
['country' => -1],
RdpNrwDocument::class,
'country',
],
[
['country' => 'AAAA'],
RdpNrwDocument::class,
'country',
],
[
['members' => 'A'],
RdpNrwDocument::class,
'members',
],
[
['members' => [99999]],
RdpNrwDocument::class,
'members.0',
],
[
['members' => ['lalala']],
RdpNrwDocument::class,
'members.0',
],
[
['eventName' => ''],
CitySolingenDocument::class,
'eventName',
],
[
['zipLocation' => ''],
CitySolingenDocument::class,
'zipLocation',
],
];
});
it('compiles documents via api', function (string $type, array $bodyChecks) {
$this->withoutExceptionHandling();
Tex::spy();
$this->login()->loginNami();
@ -54,10 +113,16 @@ class StoreTest extends TestCase
$response->assertSessionDoesntHaveErrors();
$response->assertOk();
Tex::assertCompiled($type, fn ($document) => $document->hasAllContent($bodyChecks));
}
})->with([
["App\\Contribution\\Documents\\CitySolingenDocument", ["Super tolles Lager", "Max Muster", "Jane Muster", "15.06.1991"]],
["App\\Contribution\\Documents\\RdpNrwDocument", ["Muster, Max", "Muster, Jane", "15.06.1991", "42777 SG"]],
["App\\Contribution\\Documents\\CityRemscheidDocument", ["Max", "Muster", "Jane"]],
["App\\Contribution\\Documents\\CityFrankfurtMainDocument", ["Max", "Muster", "Jane"]],
["App\\Contribution\\Documents\\BdkjHesse", ["Max", "Muster", "Jane"]],
["App\\Contribution\\Documents\\GallierDocument", ["Max", "Muster", "Jane", "42777 SG", "15.06.1991", "16.06.1991"]],
]);
public function testItCompilesGroupNameInSolingenDocument(): void
{
it('testItCompilesGroupNameInSolingenDocument', function () {
$this->withoutExceptionHandling()->login()->loginNami();
Tex::spy();
InvoiceSettings::fake(['from_long' => 'Stamm BiPi']);
@ -67,10 +132,9 @@ class StoreTest extends TestCase
]);
Tex::assertCompiled(CitySolingenDocument::class, fn ($document) => $document->hasAllContent(['Stamm BiPi']));
}
});
public function testItCompilesContributionDocumentsViaApi(): void
{
it('testItCompilesContributionDocumentsViaApi', function () {
$this->withoutExceptionHandling();
Tex::spy();
Gender::factory()->female()->create();
@ -96,42 +160,28 @@ class StoreTest extends TestCase
$response->assertSessionDoesntHaveErrors();
$response->assertOk();
Tex::assertCompiled(CitySolingenDocument::class, fn ($document) => $document->hasAllContent(['Super']));
}
});
/**
* @testWith [""]
* ["aaaa"]
* ["YWFhCg=="]
*/
public function testInputShouldBeBase64EncodedJson(string $payload): void
{
it('testInputShouldBeBase64EncodedJson', function (string $payload) {
$this->login()->loginNami();
$this->call('GET', '/contribution-generate', ['payload' => $payload])->assertSessionHasErrors('payload');
}
})->with([
[""],
["aaaa"],
["YWFhCg=="],
]);
/**
* @param array<string, string> $input
* @param class-string<ContributionDocument> $documentClass
*/
#[DataProvider('validationDataProvider')]
public function testItValidatesInput(array $input, string $documentClass, string $errorField): void
{
it('testItValidatesInput', function (array $input, string $documentClass, string $errorField) {
$this->login()->loginNami();
Country::factory()->create();
Member::factory()->defaults()->create();
$this->postJson('/contribution-validate', ContributionRequestFactory::new()->type($documentClass)->state($input)->create())
->assertJsonValidationErrors($errorField);
}
})->with('validation');
/**
* @param array<string, string> $input
* @param class-string<ContributionDocument> $documentClass
*/
#[DataProvider('validationDataProvider')]
public function testItValidatesInputBeforeGeneration(array $input, string $documentClass, string $errorField): void
{
it('testItValidatesInputBeforeGeneration', function (array $input, string $documentClass, string $errorField) {
$this->login()->loginNami();
Country::factory()->create();
Member::factory()->defaults()->create();
@ -139,74 +189,4 @@ class StoreTest extends TestCase
$this->call('GET', '/contribution-generate', [
'payload' => ContributionRequestFactory::new()->type($documentClass)->state($input)->toBase64(),
])->assertSessionHasErrors($errorField);
}
public static function validationDataProvider(): Generator
{
yield [
['type' => 'aaa'],
CitySolingenDocument::class,
'type',
];
yield [
['type' => ''],
CitySolingenDocument::class,
'type',
];
yield [
['dateFrom' => ''],
CitySolingenDocument::class,
'dateFrom',
];
yield [
['dateFrom' => '2022-01'],
CitySolingenDocument::class,
'dateFrom',
];
yield [
['dateUntil' => ''],
CitySolingenDocument::class,
'dateUntil',
];
yield [
['dateUntil' => '2022-01'],
CitySolingenDocument::class,
'dateUntil',
];
yield [
['country' => -1],
RdpNrwDocument::class,
'country',
];
yield [
['country' => 'AAAA'],
RdpNrwDocument::class,
'country',
];
yield [
['members' => 'A'],
RdpNrwDocument::class,
'members',
];
yield [
['members' => [99999]],
RdpNrwDocument::class,
'members.0',
];
yield [
['members' => ['lalala']],
RdpNrwDocument::class,
'members.0',
];
yield [
['eventName' => ''],
CitySolingenDocument::class,
'eventName',
];
yield [
['zipLocation' => ''],
CitySolingenDocument::class,
'zipLocation',
];
}
}
})->with('validation');