From 14a478785ece00a6980bdf2edcc98212446c494d Mon Sep 17 00:00:00 2001 From: philipp lang Date: Fri, 29 Oct 2021 22:02:21 +0200 Subject: [PATCH] Add remember via email --- app/Payment/PaymentMail.php | 6 +++-- app/Payment/PaymentSendCommand.php | 22 ++++++++++++++++++- app/Pdf/BillType.php | 5 +++++ app/Pdf/PdfRepository.php | 2 ++ app/Pdf/RememberType.php | 7 +++++- ...{payment.blade.php => bill_type.blade.php} | 0 .../mail/payment/remember_type.blade.php | 13 +++++++++++ 7 files changed, 51 insertions(+), 4 deletions(-) rename resources/views/mail/payment/{payment.blade.php => bill_type.blade.php} (100%) create mode 100644 resources/views/mail/payment/remember_type.blade.php diff --git a/app/Payment/PaymentMail.php b/app/Payment/PaymentMail.php index 6f93f750..e8c24664 100644 --- a/app/Payment/PaymentMail.php +++ b/app/Payment/PaymentMail.php @@ -7,6 +7,7 @@ use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Str; class PaymentMail extends Mailable { @@ -33,9 +34,10 @@ class PaymentMail extends Mailable */ public function build() { - return $this->markdown('mail.payment.payment') + $template = Str::snake(class_basename($this->repo)); + return $this->markdown('mail.payment.'.$template) ->attach($this->filename) ->replyTo('kasse@stamm-silva.de') - ->subject('Jahresrechnung | DPSG Stamm Silva'); + ->subject($this->repo->getMailSubject().' | DPSG Stamm Silva'); } } diff --git a/app/Payment/PaymentSendCommand.php b/app/Payment/PaymentSendCommand.php index 81f14a90..2b67fb32 100644 --- a/app/Payment/PaymentSendCommand.php +++ b/app/Payment/PaymentSendCommand.php @@ -5,6 +5,7 @@ namespace App\Payment; use App\Pdf\BillType; use App\Pdf\PdfGenerator; use App\Pdf\PdfRepositoryFactory; +use App\Pdf\RememberType; use Illuminate\Console\Command; use Mail; @@ -40,6 +41,12 @@ class PaymentSendCommand extends Command * @return int */ public function handle() + { + $this->sendBills(); + $this->sendRemembers(); + } + + private function sendBills(): void { $repos = app(PdfRepositoryFactory::class)->repoCollection(BillType::class, 'E-Mail'); @@ -52,8 +59,21 @@ class PaymentSendCommand extends Command Mail::to($to)->send(new PaymentMail($repo, $generator->getCompiledFilename())); app(PdfRepositoryFactory::class)->afterSingle($repo); } + } - return 0; + private function sendRemembers(): void + { + $repos = app(PdfRepositoryFactory::class)->repoCollection(RememberType::class, 'E-Mail'); + + foreach ($repos as $repo) { + $generator = app(PdfGenerator::class)->setRepository($repo)->render(); + $to = (object) [ + 'email' => $repo->getEmail($repo->pages->first()), + 'name' => $repo->getFamilyName($repo->pages->first()), + ]; + Mail::to($to)->send(new PaymentMail($repo, $generator->getCompiledFilename())); + app(PdfRepositoryFactory::class)->afterSingle($repo); + } } } diff --git a/app/Pdf/BillType.php b/app/Pdf/BillType.php index c5302c50..8c7c03ab 100644 --- a/app/Pdf/BillType.php +++ b/app/Pdf/BillType.php @@ -120,4 +120,9 @@ class BillType extends Repository implements PdfRepository $payment->update(['status_id' => 2]); } + public function getMailSubject(): string + { + return 'Jahresrechnung'; + } + } diff --git a/app/Pdf/PdfRepository.php b/app/Pdf/PdfRepository.php index d9134db8..5426c3a6 100644 --- a/app/Pdf/PdfRepository.php +++ b/app/Pdf/PdfRepository.php @@ -48,4 +48,6 @@ interface PdfRepository public function afterSingle(Payment $payment): void; + public function getMailSubject(): string; + } diff --git a/app/Pdf/RememberType.php b/app/Pdf/RememberType.php index 2bca69b1..e5662090 100644 --- a/app/Pdf/RememberType.php +++ b/app/Pdf/RememberType.php @@ -97,7 +97,7 @@ class RememberType extends Repository implements PdfRepository return "Mitgliedsbeitrag für {$this->getFamilyName($page)}"; } - public function allLabel(): string + public function allLabel(): string { return 'Erinnerungen versenden'; } @@ -120,4 +120,9 @@ class RememberType extends Repository implements PdfRepository $payment->update(['last_remembered_at' => now()]); } + public function getMailSubject(): string + { + return 'Zahlungserinnerung'; + } + } diff --git a/resources/views/mail/payment/payment.blade.php b/resources/views/mail/payment/bill_type.blade.php similarity index 100% rename from resources/views/mail/payment/payment.blade.php rename to resources/views/mail/payment/bill_type.blade.php diff --git a/resources/views/mail/payment/remember_type.blade.php b/resources/views/mail/payment/remember_type.blade.php new file mode 100644 index 00000000..fd14a79a --- /dev/null +++ b/resources/views/mail/payment/remember_type.blade.php @@ -0,0 +1,13 @@ +@component('mail::message') +# Liebe Familie {{ $repo->getFamilyName($repo->pages->first()) }}, + +Hiermit möchten wir euch an die noch ausstehenden Mitgliedsbeiträge des Stammes Silva für das laufende Jahr erinnern. Bitte begleicht diese bis zum angegebenen Datum. + +@component('mail::subcopy') + +Herzliche Grüße und gut Pfad + +Der Stammesvorstand +@endcomponent + +@endcomponent