60 lines
1.3 KiB
PHP
60 lines
1.3 KiB
PHP
<?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;
|
|
}
|
|
|
|
}
|