Improved handling for new invoices
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
namespace App\Domains\Invoice\Actions\CreateInvoice;
|
||||
|
||||
use App\Enumerations\InvoiceStatus;
|
||||
use App\Mail\InvoiceMails\InvoiceMailsNewInvoiceMail;
|
||||
use App\Mail\ParticipantParticipationMails\EventSignUpSuccessfullMail;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class CreateInvoiceCommand {
|
||||
private CreateInvoiceRequest $request;
|
||||
@@ -36,6 +39,7 @@ class CreateInvoiceCommand {
|
||||
'amount' => $this->request->totalAmount,
|
||||
'distance' => $this->request->distance,
|
||||
'travel_direction' => $this->request->travelRoute,
|
||||
'travel_reason' => $this->request->travelReason,
|
||||
'passengers' => $this->request->passengers,
|
||||
'transportation' => $this->request->transportations,
|
||||
'document_filename' => $this->request->receiptFile !== null ? $this->request->receiptFile->fullPath : null,
|
||||
@@ -46,6 +50,23 @@ class CreateInvoiceCommand {
|
||||
$response->invoice = $invoice;
|
||||
}
|
||||
|
||||
if ($this->request->costUnit->mail_on_new) {
|
||||
$recipients = [app('tenant')->email_finance];
|
||||
|
||||
foreach ($this->request->costUnit->treasurers()->get() as $treasurer) {
|
||||
if (!in_array($treasurer->email, $recipients)) {
|
||||
$recipients[] = $treasurer->email;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($recipients as $recipient) {
|
||||
Mail::to($recipient)->send(new InvoiceMailsNewInvoiceMail(
|
||||
invoice: $invoice,
|
||||
costUnit: $this->request->costUnit,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ class CreateInvoiceRequest {
|
||||
public float $totalAmount;
|
||||
public bool $isDonation;
|
||||
public ?int $userId;
|
||||
public ?string $travelReason;
|
||||
|
||||
|
||||
public function __construct(
|
||||
@@ -41,6 +42,7 @@ class CreateInvoiceRequest {
|
||||
?int $distance = null,
|
||||
?int $passengers = null,
|
||||
?int $transportations,
|
||||
?string $travelReason = null,
|
||||
|
||||
) {
|
||||
$this->costUnit = $costUnit;
|
||||
@@ -59,6 +61,7 @@ class CreateInvoiceRequest {
|
||||
$this->totalAmount = $totalAmount;
|
||||
$this->isDonation = $isDonation;
|
||||
$this->userId = $userId;
|
||||
$this->travelReason = $travelReason;
|
||||
|
||||
if ($accountIban === 'undefined') {
|
||||
$this->accountIban = null;
|
||||
|
||||
@@ -84,6 +84,7 @@ class CreateInvoiceReceiptCommand {
|
||||
|
||||
$travelPartTemplate = <<<HTML
|
||||
<tr><td>Reiseweg:</td><td>%1\$s</td></tr>
|
||||
<tr><td>Grund der Reise:</td><td>%6\$s</td></tr>
|
||||
<tr><td>Gesamtlänge der Strecke:</td><td>%2\$s km x %3\$s / km</td></tr>
|
||||
<tr><td>Materialtransport:</td><td>%4\$s</td></tr>
|
||||
<tr><td>Mitfahrende im PKW:</td><td>%5\$s</td></tr>
|
||||
@@ -95,7 +96,8 @@ HTML;
|
||||
$invoiceReadable['distance'],
|
||||
$invoiceReadable['distanceAllowance'],
|
||||
$invoiceReadable['transportation'],
|
||||
$invoiceReadable['passengers']
|
||||
$invoiceReadable['passengers'],
|
||||
$invoiceReadable['travelReason'] ,
|
||||
);
|
||||
|
||||
$invoiceTravelPart = '<tr><td>Kosten für ÖPNV:</td><td>' . $invoiceReadable['amount'] . '</td></tr>';;
|
||||
|
||||
Reference in New Issue
Block a user