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) {
|
2022-12-06 22:16:37 +01:00
|
|
|
$letters = app(DocumentFactory::class)->letterCollection($type, 'E-Mail');
|
2022-11-07 16:18:11 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|