adrema/app/Pdf/BillType.php

126 lines
2.9 KiB
PHP
Raw Normal View History

2021-07-15 21:17:48 +02:00
<?php
namespace App\Pdf;
2021-07-17 16:57:37 +02:00
use App\Member\Member;
2021-07-17 15:16:29 +02:00
use App\Payment\Payment;
2021-07-15 21:17:48 +02:00
use Illuminate\Support\Collection;
2022-03-20 16:33:56 +01:00
class BillType extends Repository implements LetterRepository
2021-07-15 21:17:48 +02:00
{
public string $filename;
2021-07-17 19:21:27 +02:00
public function getPayments(Member $member): Collection
2021-07-17 16:57:37 +02:00
{
2021-07-17 19:21:27 +02:00
return $member->payments()->whereNeedsBill()->get();
2021-07-17 16:57:37 +02:00
}
public function linkLabel(): string
{
return 'Rechnung erstellen';
}
2021-07-15 21:17:48 +02:00
public function getSubject(): string
{
return 'Rechnung';
}
2022-03-20 16:33:56 +01:00
public function setFilename(string $filename): static
2021-07-15 21:17:48 +02:00
{
$this->filename = $filename;
return $this;
}
2022-03-20 16:33:56 +01:00
public function getScript(): EnvType
{
return EnvType::XELATEX;
}
2021-07-15 21:17:48 +02:00
public function getFilename(): string
{
return $this->filename;
}
2021-07-16 00:12:19 +02:00
public function getView(): string
{
return 'tex.bill';
}
public function getTemplate(): string
{
return 'default';
}
2021-07-17 15:16:29 +02:00
public function getPositions(Collection $page): array
{
$memberIds = $page->pluck('id')->toArray();
2021-07-17 17:00:27 +02:00
$payments = Payment::whereIn('member_id', $memberIds)
->orderByRaw('nr, member_id')->whereNeedsBill()->get();
2021-07-17 15:16:29 +02:00
return $payments->mapWithKeys(function (Payment $payment) {
2021-07-17 17:21:30 +02:00
$key = "Beitrag {$payment->nr} für {$payment->member->firstname} {$payment->member->lastname} ({$payment->subscription->name})";
2021-07-17 15:16:29 +02:00
return [$key => $this->number($payment->subscription->amount)];
})->toArray();
}
public function getFamilyName(Collection $page): string
{
return $page->first()->lastname;
}
public function getAddress(Collection $page): string
{
return $page->first()->address;
}
public function getZip(Collection $page): string
{
return $page->first()->zip;
}
2021-07-18 21:38:00 +02:00
public function getEmail(Collection $page): string
{
return $page->first()->email_parents ?: $page->first()->email;
}
2021-07-17 15:16:29 +02:00
public function getLocation(Collection $page): string
{
return $page->first()->location;
}
2021-07-17 17:29:59 +02:00
public function getUsage(Collection $page): string
{
return "Mitgliedsbeitrag für {$this->getFamilyName($page)}";
}
2022-01-02 12:32:57 +01:00
public function allLabel(): string
2021-07-17 18:46:02 +02:00
{
return 'Rechnungen versenden';
}
2021-10-29 21:44:23 +02:00
/**
2022-03-11 20:19:17 +01:00
* Get Descriptions for sendpayment page.
2021-10-29 21:44:23 +02:00
*
* @return array<int, string>
*/
2022-01-02 12:32:57 +01:00
public function getDescription(): array
2021-10-29 21:44:23 +02:00
{
return [
'Diese Funktion erstellt ein PDF mit allen noch nicht versendenden Rechnungen bei den Mitgliedern die Post als Versandweg haben.',
'Die Rechnungen werden automatisch auf "Rechnung gestellt" aktualisiert.',
];
}
public function afterSingle(Payment $payment): void
{
$payment->update(['status_id' => 2]);
}
2021-10-29 22:02:21 +02:00
public function getMailSubject(): string
{
return 'Jahresrechnung';
}
2021-07-15 21:17:48 +02:00
}