Add mail for bill

This commit is contained in:
philipp lang 2021-07-18 21:38:00 +02:00
parent d1c3287e65
commit e657b09872
27 changed files with 625 additions and 12 deletions

View File

@ -2,6 +2,7 @@
namespace App\Console;
use App\Payment\PaymentSendCommand;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@ -12,8 +13,8 @@ class Kernel extends ConsoleKernel
*
* @var array
*/
protected $commands = [
//
protected $commands = [
PaymentSendCommand::class,
];
/**

View File

@ -0,0 +1,41 @@
<?php
namespace App\Payment;
use App\Pdf\PdfRepository;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class PaymentMail extends Mailable
{
use Queueable, SerializesModels;
public PdfRepository $repo;
public string $filename;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(PdfRepository $repo, string $filename)
{
$this->filename = $filename;
$this->repo = $repo;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->markdown('mail.payment.payment')
->attach($this->filename)
->replyTo('kasse@stamm-silva.de')
->subject('Jahresrechnung | DPSG Stamm Silva');
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace App\Payment;
use App\Pdf\BillType;
use App\Pdf\PdfGenerator;
use App\Pdf\PdfRepositoryFactory;
use Illuminate\Console\Command;
use Mail;
class PaymentSendCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'payment:send';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Sends Bills';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$repos = app(PdfRepositoryFactory::class)->repoCollection(BillType::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);
}
return 0;
}
}

View File

@ -24,10 +24,10 @@ class SendpaymentController extends Controller
public function send(Request $request)
{
$repo = app(PdfRepositoryFactory::class)->forAll($request->type);
$repo = app(PdfRepositoryFactory::class)->forAll($request->type, 'Post');
$pdfFile = app(PdfGenerator::class)->setRepository($repo)->render();
app(PdfRepositoryFactory::class)->afterAll($request->type);
app(PdfRepositoryFactory::class)->afterAll($request->type, 'Post');
return $repo === null
? response()->noContent()

View File

@ -82,6 +82,11 @@ class BillType extends Repository implements PdfRepository
return $page->first()->zip;
}
public function getEmail(Collection $page): string
{
return $page->first()->email_parents ?: $page->first()->email;
}
public function getLocation(Collection $page): string
{
return $page->first()->location;

View File

@ -41,4 +41,6 @@ interface PdfRepository
public function allLabel(): string;
public function getEmail(Collection $page): string;
}

View File

@ -35,9 +35,9 @@ class PdfRepositoryFactory
);
}
public function forAll(string $type): ?PdfRepository
public function forAll(string $type, string $billKind): ?PdfRepository
{
$members = $this->toMemberGroup($this->allMemberCollection($type));
$members = $this->toMemberGroup($this->allMemberCollection($type, $billKind));
if ($members->isEmpty()) {
return null;
@ -46,16 +46,32 @@ class PdfRepositoryFactory
return $this->resolve($type, $members)->setFilename('alle-rechnungen');
}
public function afterAll(string $type): void
public function repoCollection(string $type, string $billKind): Collection
{
$members = $this->allMemberCollection($type);
$repo = $this->resolve($type, $this->toMemberGroup($this->allMemberCollection($type)));
$members = $this->toMemberGroup($this->allMemberCollection($type, $billKind));
return $members->map(function (Collection $members) use ($type) {
$repo = $this->resolve($type, collect([$members]));
return $repo->setFilename(Str::slug("{$repo->getSubject()} für {$members->first()->lastname}"));
});
}
public function afterSingle(PdfRepository $repo): void
{
foreach ($repo->allPayments() as $payment) {
$payment->update(['status_id' => 2]);
}
}
public function afterAll(string $type, string $billKind): void
{
$members = $this->allMemberCollection($type, $billKind);
$repo = $this->resolve($type, $this->toMemberGroup($members));
$this->afterSingle($repo);
}
public function singleMemberCollection(Member $member, string $type): Collection
{
$members = Member::where($member->only(['lastname', 'address', 'zip', 'location']))
@ -65,9 +81,9 @@ class PdfRepositoryFactory
return $this->toMemberGroup($members);
}
public function allMemberCollection(string $type): Collection
private function allMemberCollection(string $type, string $billKind): Collection
{
return Member::whereHas('billKind', fn (Builder $q) => $q->where('name', 'Post'))
return Member::whereHas('billKind', fn (Builder $q) => $q->where('name', $billKind))
->get()
->filter(fn (Member $member) => app($type)->createable($member));
}

@ -1 +1 @@
Subproject commit 63fb0c9daed5648bc2bf06a0361d95cd586db17f
Subproject commit cd9837290db78de9ec3fb08d553ecf6834da34f0

BIN
resources/img/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

View File

@ -0,0 +1,13 @@
@component('mail::message')
# Liebe Familie {{ $repo->getFamilyName($repo->pages->first()) }},
Im Anhang findet ihr die aktuelle Rechnung des Stammes Silva für das laufende Jahr. Bitte begleicht diese bis zum angegebenen Datum.
@component('mail::subcopy')
Herzliche Grüße und gut Pfad
Der Stammesvorstand
@endcomponent
@endcomponent

View File

@ -0,0 +1,19 @@
<table class="action" align="center" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td align="center">
<table width="100%" border="0" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td align="center">
<table border="0" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td>
<a href="{{ $url }}" class="button button-{{ $color ?? 'primary' }}" target="_blank" rel="noopener">{{ $slot }}</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>

View File

@ -0,0 +1,11 @@
<tr>
<td>
<table class="footer" align="center" width="570" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td class="content-cell" align="center">
{{ Illuminate\Mail\Markdown::parse($slot) }}
</td>
</tr>
</table>
</td>
</tr>

View File

@ -0,0 +1,7 @@
<tr>
<td class="header">
<a href="{{ $url }}" style="display: inline-block;">
<img src="{{ url('/img/logo.png') }}" class="logo" alt="Stamm Silva Logo">
</a>
</td>
</tr>

View File

@ -0,0 +1,56 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="color-scheme" content="light">
<meta name="supported-color-schemes" content="light">
<style>
@media only screen and (max-width: 600px) {
.inner-body {
width: 100% !important;
}
.footer {
width: 100% !important;
}
}
@media only screen and (max-width: 500px) {
.button {
width: 100% !important;
}
}
</style>
</head>
<body>
<table class="wrapper" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td align="center">
<table class="content" width="100%" cellpadding="0" cellspacing="0" role="presentation">
{{ $header ?? '' }}
<!-- Email Body -->
<tr>
<td class="body" width="100%" cellpadding="0" cellspacing="0">
<table class="inner-body" align="center" width="570" cellpadding="0" cellspacing="0" role="presentation">
<!-- Body content -->
<tr>
<td class="content-cell">
{{ Illuminate\Mail\Markdown::parse($slot) }}
{{ $subcopy ?? '' }}
</td>
</tr>
</table>
</td>
</tr>
{{ $footer ?? '' }}
</table>
</td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1,27 @@
@component('mail::layout')
{{-- Header --}}
@slot('header')
@component('mail::header', ['url' => 'https://stamm-silva.de'])
{{ config('app.name') }}
@endcomponent
@endslot
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
@isset($subcopy)
@slot('subcopy')
@component('mail::subcopy')
{{ $subcopy }}
@endcomponent
@endslot
@endisset
{{-- Footer --}}
@slot('footer')
@component('mail::footer')
© {{ date('Y') }} Stamm Silva.
@endcomponent
@endslot
@endcomponent

View File

@ -0,0 +1,14 @@
<table class="panel" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td class="panel-content">
<table width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td class="panel-item">
{{ Illuminate\Mail\Markdown::parse($slot) }}
</td>
</tr>
</table>
</td>
</tr>
</table>

View File

@ -0,0 +1,7 @@
<table class="subcopy" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td>
{{ Illuminate\Mail\Markdown::parse($slot) }}
</td>
</tr>
</table>

View File

@ -0,0 +1,3 @@
<div class="table">
{{ Illuminate\Mail\Markdown::parse($slot) }}
</div>

View File

@ -0,0 +1,290 @@
/* Base */
body,
body *:not(html):not(style):not(br):not(tr):not(code) {
box-sizing: border-box;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif,
'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
position: relative;
}
body {
-webkit-text-size-adjust: none;
background-color: #ffffff;
color: #718096;
height: 100%;
line-height: 1.4;
margin: 0;
padding: 0;
width: 100% !important;
}
p,
ul,
ol,
blockquote {
line-height: 1.4;
text-align: left;
}
a {
color: #3869d4;
}
a img {
border: none;
}
/* Typography */
h1 {
color: #3d4852;
font-size: 18px;
font-weight: bold;
margin-top: 0;
text-align: left;
}
h2 {
font-size: 16px;
font-weight: bold;
margin-top: 0;
text-align: left;
}
h3 {
font-size: 14px;
font-weight: bold;
margin-top: 0;
text-align: left;
}
p {
font-size: 16px;
line-height: 1.5em;
margin-top: 0;
text-align: left;
}
p.sub {
font-size: 12px;
}
img {
max-width: 100%;
}
/* Layout */
.wrapper {
-premailer-cellpadding: 0;
-premailer-cellspacing: 0;
-premailer-width: 100%;
background-color: #edf2f7;
margin: 0;
padding: 0;
width: 100%;
}
.content {
-premailer-cellpadding: 0;
-premailer-cellspacing: 0;
-premailer-width: 100%;
margin: 0;
padding: 0;
width: 100%;
}
/* Header */
.header {
padding: 25px 0;
text-align: center;
}
.header a {
color: #3d4852;
font-size: 19px;
font-weight: bold;
text-decoration: none;
}
/* Logo */
.logo {
height: 75px;
max-height: 75px;
width: 75px;
}
/* Body */
.body {
-premailer-cellpadding: 0;
-premailer-cellspacing: 0;
-premailer-width: 100%;
background-color: #edf2f7;
border-bottom: 1px solid #edf2f7;
border-top: 1px solid #edf2f7;
margin: 0;
padding: 0;
width: 100%;
}
.inner-body {
-premailer-cellpadding: 0;
-premailer-cellspacing: 0;
-premailer-width: 570px;
background-color: #ffffff;
border-color: #e8e5ef;
border-radius: 2px;
border-width: 1px;
box-shadow: 0 2px 0 rgba(0, 0, 150, 0.025), 2px 4px 0 rgba(0, 0, 150, 0.015);
margin: 0 auto;
padding: 0;
width: 570px;
}
/* Subcopy */
.subcopy {
border-top: 1px solid #e8e5ef;
margin-top: 25px;
padding-top: 25px;
}
.subcopy p {
font-size: 14px;
}
/* Footer */
.footer {
-premailer-cellpadding: 0;
-premailer-cellspacing: 0;
-premailer-width: 570px;
margin: 0 auto;
padding: 0;
text-align: center;
width: 570px;
}
.footer p {
color: #b0adc5;
font-size: 12px;
text-align: center;
}
.footer a {
color: #b0adc5;
text-decoration: underline;
}
/* Tables */
.table table {
-premailer-cellpadding: 0;
-premailer-cellspacing: 0;
-premailer-width: 100%;
margin: 30px auto;
width: 100%;
}
.table th {
border-bottom: 1px solid #edeff2;
margin: 0;
padding-bottom: 8px;
}
.table td {
color: #74787e;
font-size: 15px;
line-height: 18px;
margin: 0;
padding: 10px 0;
}
.content-cell {
max-width: 100vw;
padding: 32px;
}
/* Buttons */
.action {
-premailer-cellpadding: 0;
-premailer-cellspacing: 0;
-premailer-width: 100%;
margin: 30px auto;
padding: 0;
text-align: center;
width: 100%;
}
.button {
-webkit-text-size-adjust: none;
border-radius: 4px;
color: #fff;
display: inline-block;
overflow: hidden;
text-decoration: none;
}
.button-blue,
.button-primary {
background-color: #2d3748;
border-bottom: 8px solid #2d3748;
border-left: 18px solid #2d3748;
border-right: 18px solid #2d3748;
border-top: 8px solid #2d3748;
}
.button-green,
.button-success {
background-color: #48bb78;
border-bottom: 8px solid #48bb78;
border-left: 18px solid #48bb78;
border-right: 18px solid #48bb78;
border-top: 8px solid #48bb78;
}
.button-red,
.button-error {
background-color: #e53e3e;
border-bottom: 8px solid #e53e3e;
border-left: 18px solid #e53e3e;
border-right: 18px solid #e53e3e;
border-top: 8px solid #e53e3e;
}
/* Panels */
.panel {
border-left: #2d3748 solid 4px;
margin: 21px 0;
}
.panel-content {
background-color: #edf2f7;
color: #718096;
padding: 16px;
}
.panel-content p {
color: #718096;
}
.panel-item {
padding: 0;
}
.panel-item p:last-of-type {
margin-bottom: 0;
padding-bottom: 0;
}
/* Utilities */
.break-all {
word-break: break-all;
}

View File

@ -0,0 +1 @@
{{ $slot }}: {{ $url }}

View File

@ -0,0 +1 @@
{{ $slot }}

View File

@ -0,0 +1 @@
[{{ $slot }}]({{ $url }})

View File

@ -0,0 +1,9 @@
{!! strip_tags($header) !!}
{!! strip_tags($slot) !!}
@isset($subcopy)
{!! strip_tags($subcopy) !!}
@endisset
{!! strip_tags($footer) !!}

View File

@ -0,0 +1,27 @@
@component('mail::layout')
{{-- Header --}}
@slot('header')
@component('mail::header', ['url' => config('app.url')])
{{ config('app.name') }}
@endcomponent
@endslot
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
@isset($subcopy)
@slot('subcopy')
@component('mail::subcopy')
{{ $subcopy }}
@endcomponent
@endslot
@endisset
{{-- Footer --}}
@slot('footer')
@component('mail::footer')
© {{ date('Y') }} {{ config('app.name') }}. @lang('All rights reserved.')
@endcomponent
@endslot
@endcomponent

View File

@ -0,0 +1 @@
{{ $slot }}

View File

@ -0,0 +1 @@
{{ $slot }}

View File

@ -0,0 +1 @@
{{ $slot }}