adrema/app/Letter/Actions/LetterSendAction.php

48 lines
1.1 KiB
PHP
Raw Normal View History

2022-11-07 16:18:11 +01:00
<?php
namespace App\Letter\Actions;
use App\Letter\DocumentFactory;
use App\Payment\PaymentMail;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use Lorisleiva\Actions\Concerns\AsAction;
use Mail;
use Zoomyboy\Tex\Tex;
class LetterSendAction
{
use AsAction;
/**
* The name and signature of the console command.
*/
2022-11-09 01:33:31 +01:00
public string $commandSignature = 'letter:send';
2022-11-07 16:18:11 +01:00
/**
* The console command description.
*
* @var string
*/
protected $description = 'Sends Bills';
/**
* Execute the console command.
*/
2022-11-07 16:26:55 +01:00
public function handle(): int
2022-11-07 16:18:11 +01:00
{
foreach (app(DocumentFactory::class)->types as $type) {
$letters = app(DocumentFactory::class)->repoCollection($type, 'E-Mail');
foreach ($letters as $letter) {
$letterPath = Storage::path(Tex::compile($letter)->storeIn('/tmp', 'local'));
Mail::to($letter->getRecipient())
->send(new PaymentMail($letter, $letterPath));
app(DocumentFactory::class)->afterSingle($letter);
}
}
return 0;
}
}