Change state after allPAyment
This commit is contained in:
parent
78a05ec82a
commit
3c936a9327
|
@ -26,9 +26,12 @@ class SendpaymentController extends Controller
|
|||
{
|
||||
$repo = app(PdfRepositoryFactory::class)->forAll($request->type);
|
||||
|
||||
$pdfFile = app(PdfGenerator::class)->setRepository($repo)->render();
|
||||
app(PdfRepositoryFactory::class)->afterAll($request->type);
|
||||
|
||||
return $repo === null
|
||||
? response()->noContent()
|
||||
: app(PdfGenerator::class)->setRepository($repo)->render();
|
||||
: $pdfFile;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ class BillType extends Repository implements PdfRepository
|
|||
$this->pages = $pages;
|
||||
}
|
||||
|
||||
public function createable(Member $member): bool
|
||||
public function getPayments(Member $member): Collection
|
||||
{
|
||||
return $member->payments()->whereNeedsBill()->count() !== 0;
|
||||
return $member->payments()->whereNeedsBill()->get();
|
||||
}
|
||||
|
||||
public function linkLabel(): string
|
||||
|
|
|
@ -31,6 +31,8 @@ interface PdfRepository
|
|||
|
||||
public function createable(Member $member): bool;
|
||||
|
||||
public function getPayments(Member $member): Collection;
|
||||
|
||||
public function linkLabel(): string;
|
||||
|
||||
public function getUntil(): Carbon;
|
||||
|
|
|
@ -37,7 +37,7 @@ class PdfRepositoryFactory
|
|||
|
||||
public function forAll(string $type): ?PdfRepository
|
||||
{
|
||||
$members = $this->allMemberCollection($type);
|
||||
$members = $this->toMemberGroup($this->allMemberCollection($type));
|
||||
|
||||
if ($members->isEmpty()) {
|
||||
return null;
|
||||
|
@ -46,6 +46,16 @@ class PdfRepositoryFactory
|
|||
return $this->resolve($type, $members)->setFilename('alle-rechnungen');
|
||||
}
|
||||
|
||||
public function afterAll(string $type): void
|
||||
{
|
||||
$members = $this->allMemberCollection($type);
|
||||
$repo = $this->resolve($type, $this->toMemberGroup($this->allMemberCollection($type)));
|
||||
|
||||
foreach ($repo->allPayments() as $payment) {
|
||||
$payment->update(['status_id' => 2]);
|
||||
}
|
||||
}
|
||||
|
||||
public function singleMemberCollection(Member $member, string $type): Collection
|
||||
{
|
||||
$members = Member::where($member->only(['lastname', 'address', 'zip', 'location']))
|
||||
|
@ -57,11 +67,9 @@ class PdfRepositoryFactory
|
|||
|
||||
public function allMemberCollection(string $type): Collection
|
||||
{
|
||||
$members = Member::whereHas('billKind', fn (Builder $q) => $q->where('name', 'Post'))
|
||||
return Member::whereHas('billKind', fn (Builder $q) => $q->where('name', 'Post'))
|
||||
->get()
|
||||
->filter(fn (Member $member) => app($type)->createable($member));
|
||||
|
||||
return $this->toMemberGroup($members);
|
||||
}
|
||||
|
||||
private function resolve(string $kind, Collection $members): PdfRepository
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace App\Pdf;
|
||||
|
||||
use App\Member\Member;
|
||||
use Carbon\Carbon;
|
||||
use Generator;
|
||||
|
||||
abstract class Repository
|
||||
{
|
||||
|
@ -17,4 +19,20 @@ abstract class Repository
|
|||
return now()->addWeeks(2);
|
||||
}
|
||||
|
||||
public function createable(Member $member): bool
|
||||
{
|
||||
return $this->getPayments($member)->count() !== 0;
|
||||
}
|
||||
|
||||
public function allPayments(): Generator
|
||||
{
|
||||
foreach ($this->pages as $page) {
|
||||
foreach ($page as $member) {
|
||||
foreach ($this->getPayments($member) as $payment) {
|
||||
yield $payment;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue