diff --git a/app/Pdf/BillType.php b/app/Pdf/BillType.php new file mode 100644 index 00000000..1520f32e --- /dev/null +++ b/app/Pdf/BillType.php @@ -0,0 +1,34 @@ +pages = $pages; + } + + public function getSubject(): string + { + return 'Rechnung'; + } + + public function setFilename(string $filename): self + { + $this->filename = $filename; + + return $this; + } + + public function getFilename(): string + { + return $this->filename; + } + +} diff --git a/app/Pdf/MemberPdfController.php b/app/Pdf/MemberPdfController.php new file mode 100644 index 00000000..c68a4382 --- /dev/null +++ b/app/Pdf/MemberPdfController.php @@ -0,0 +1,21 @@ +fromSingleRequest($request->type, $member); + + return $repo === null + ? response()->noContent() + : app(PdfGenerator::class)->render($repo); + } + +} diff --git a/app/Pdf/PdfGenerator.php b/app/Pdf/PdfGenerator.php new file mode 100644 index 00000000..d1e6417c --- /dev/null +++ b/app/Pdf/PdfGenerator.php @@ -0,0 +1,31 @@ +make('pdf.pdf', [ + 'data' => $repo, + ]); + + $filename = $repo->getFilename(); + dd($filename); + + Storage::disk('temp')->put($repo->getBasename(), $content); + } + + public function toResponse($request) + { + return response()->file($this->filename); + } + +} + diff --git a/app/Pdf/PdfRepository.php b/app/Pdf/PdfRepository.php new file mode 100644 index 00000000..392c1ee8 --- /dev/null +++ b/app/Pdf/PdfRepository.php @@ -0,0 +1,16 @@ +singleMemberCollection($member); + + if ($members->isEmpty()) { + return null; + } + + $repo = $this->resolve($type, $members); + $firstMember = $members->first()->first(); + + return $repo->setFilename( + Str::slug("{$repo->getSubject()} für {$firstMember->firstname} {$firstMember->lastname}"), + ); + } + + public function singleMemberCollection(Member $member): Collection + { + $members = Member::where($member->only(['firstname', 'lastname', 'address', 'zip', 'location'])) + ->whereHas('payments', fn ($q) => $q->whereNeedsPayment()) + ->get(); + + return $this->toMemberGroup($members); + } + + private function resolve(string $kind, Collection $members): PdfRepository + { + return new $kind($members); + } + + private function toMemberGroup(Collection $members): Collection + { + return $members->groupBy( + fn ($member) => Str::slug( + "{$member->firstname}{$member->lastname}{$member->address}{$member->zip}{$member->location}", + ), + ); + } + +} diff --git a/routes/web.php b/routes/web.php index def18c7b..71494856 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,12 +1,13 @@ - 'App\\Http\\Controllers'], function() { Auth::routes(['register' => false]); @@ -20,5 +21,6 @@ Route::group(['middleware' => 'auth:web'], function () { Route::resource('allpayment', AllpaymentController::class); Route::resource('subscription', SubscriptionController::class); Route::post('/member/{member}/confirm', MemberConfirmController::class); + Route::post('/member/{member}/pdf', MemberPdfController::class)->name('member.singlepdf'); });