adrema/app/Invoice/Actions/InvoiceSendAction.php

50 lines
1.3 KiB
PHP
Raw Normal View History

2023-04-18 22:08:45 +02:00
<?php
namespace App\Invoice\Actions;
use App\Invoice\BillKind;
use App\Invoice\DocumentFactory;
use App\Invoice\Queries\BillKindQuery;
2023-11-30 23:54:16 +01:00
use App\Payment\Payment;
2023-04-18 22:08:45 +02:00
use App\Payment\PaymentMail;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;
use Lorisleiva\Actions\Concerns\AsAction;
use Zoomyboy\Tex\Tex;
class InvoiceSendAction
{
use AsAction;
/**
* The name and signature of the console command.
*/
public string $commandSignature = 'invoice:send';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Sends Bills';
/**
* Execute the console command.
*/
public function handle(): int
{
foreach (app(DocumentFactory::class)->getTypes() as $type) {
2023-11-30 23:54:16 +01:00
$memberCollection = (new BillKindQuery(BillKind::EMAIL))->type($type)->getMembers();
2023-04-18 22:08:45 +02:00
2023-11-30 23:54:16 +01:00
foreach ($memberCollection as $members) {
$invoice = $type::fromMembers($members);
2023-04-18 22:08:45 +02:00
$invoicePath = Storage::disk('temp')->path(Tex::compile($invoice)->storeIn('', 'temp'));
2023-11-30 23:54:16 +01:00
Mail::to($invoice->getRecipient())->send(new PaymentMail($invoice, $invoicePath));
app(DocumentFactory::class)->afterSingle($invoice, $members);
2023-04-18 22:08:45 +02:00
}
}
return 0;
}
}