adrema/app/Pdf/BillType.php

90 lines
1.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;
2021-07-17 15:16:29 +02:00
class BillType extends Repository implements PdfRepository
2021-07-15 21:17:48 +02:00
{
public string $filename;
2021-07-17 15:16:29 +02:00
public Collection $pages;
2021-07-15 21:17:48 +02:00
public function __construct(Collection $pages)
{
$this->pages = $pages;
}
2021-07-17 16:57:37 +02:00
public function createable(Member $member): bool
{
return $member->payments()->whereNeedsBill()->count() !== 0;
}
public function linkLabel(): string
{
return 'Rechnung erstellen';
}
2021-07-15 21:17:48 +02:00
public function getSubject(): string
{
return 'Rechnung';
}
public function setFilename(string $filename): self
{
$this->filename = $filename;
return $this;
}
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();
$payments = Payment::whereIn('member_id', $memberIds)->whereNeedsBill()->get();
return $payments->mapWithKeys(function (Payment $payment) {
$key = "Beitrag für {$payment->nr} ({$payment->subscription->name})";
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;
}
public function getLocation(Collection $page): string
{
return $page->first()->location;
}
2021-07-15 21:17:48 +02:00
}