adrema/app/Invoice/Actions/InvoiceSendAction.php

55 lines
1.6 KiB
PHP
Raw Normal View History

2023-04-18 22:08:45 +02:00
<?php
namespace App\Invoice\Actions;
2023-12-18 01:15:16 +01:00
use App\Invoice\BillDocument;
2023-12-18 02:17:31 +01:00
use App\Invoice\BillKind;
use App\Invoice\Enums\InvoiceStatus;
2023-12-18 01:15:16 +01:00
use App\Invoice\Mails\BillMail;
2023-12-18 02:17:31 +01:00
use App\Invoice\Mails\RememberMail;
2023-12-18 01:15:16 +01:00
use App\Invoice\Models\Invoice;
2023-12-18 02:17:31 +01:00
use App\Invoice\RememberDocument;
2023-04-18 22:08:45 +02:00
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
{
2023-12-18 02:17:31 +01:00
foreach (Invoice::whereNeedsBill()->where('via', BillKind::EMAIL)->get() as $invoice) {
2023-12-18 01:15:16 +01:00
$document = BillDocument::fromInvoice($invoice);
$path = Storage::disk('temp')->path(Tex::compile($document)->storeIn('', 'temp'));
Mail::to($invoice->getMailRecipient())->send(new BillMail($invoice, $path));
$invoice->sent($document);
2023-04-18 22:08:45 +02:00
}
2023-12-18 02:17:31 +01:00
foreach (Invoice::whereNeedsRemember()->where('via', BillKind::EMAIL)->get() as $invoice) {
$document = RememberDocument::fromInvoice($invoice);
$path = Storage::disk('temp')->path(Tex::compile($document)->storeIn('', 'temp'));
Mail::to($invoice->getMailRecipient())->send(new RememberMail($invoice, $path));
$invoice->sent($document);
}
2023-04-18 22:08:45 +02:00
return 0;
}
}