adrema/app/Payment/PaymentSendCommand.php

80 lines
2.0 KiB
PHP
Raw Normal View History

2021-07-18 21:38:00 +02:00
<?php
namespace App\Payment;
use App\Pdf\BillType;
use App\Pdf\PdfGenerator;
use App\Pdf\PdfRepositoryFactory;
2021-10-29 22:02:21 +02:00
use App\Pdf\RememberType;
2021-07-18 21:38:00 +02:00
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()
2021-10-29 22:02:21 +02:00
{
$this->sendBills();
$this->sendRemembers();
}
private function sendBills(): void
2021-07-18 21:38:00 +02:00
{
$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);
}
2021-10-29 22:02:21 +02:00
}
2021-07-18 21:38:00 +02:00
2021-10-29 22:02:21 +02:00
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);
}
2021-07-18 21:38:00 +02:00
}
}