Notification after invoice state
This commit is contained in:
@@ -3,6 +3,11 @@
|
||||
namespace App\Domains\Invoice\Actions\ChangeStatus;
|
||||
|
||||
use App\Enumerations\InvoiceStatus;
|
||||
use App\Mail\InvoiceMails\InvoiceMailsApprovedInvoiceMail;
|
||||
use App\Mail\InvoiceMails\InvoiceMailsDeniedInvoiceMail;
|
||||
use App\Mail\InvoiceMails\InvoiceMailsReopenedInvoiceMail;
|
||||
use App\Mail\ParticipantCocMails\ParticipantCocCompleteMail;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class ChangeStatusCommand {
|
||||
private ChangeStatusRequest $request;
|
||||
@@ -19,6 +24,13 @@ class ChangeStatusCommand {
|
||||
$this->request->invoice->status = InvoiceStatus::INVOICE_STATUS_APPROVED;
|
||||
$this->request->invoice->approved_by = auth()->user()->id;
|
||||
$this->request->invoice->approved_at = now();
|
||||
|
||||
if ($this->request->invoice->contact_email !== null) {
|
||||
Mail::to($this->request->invoice->contact_email)->send(new InvoiceMailsApprovedInvoiceMail(
|
||||
invoice: $this->request->invoice,
|
||||
costUnit: $this->request->invoice->costUnit()->first(),
|
||||
));
|
||||
}
|
||||
break;
|
||||
|
||||
case InvoiceStatus::INVOICE_STATUS_DENIED:
|
||||
@@ -26,6 +38,12 @@ class ChangeStatusCommand {
|
||||
$this->request->invoice->denied_by = auth()->user()->id;
|
||||
$this->request->invoice->denied_at = now();
|
||||
$this->request->invoice->denied_reason = $this->request->comment;
|
||||
if ($this->request->invoice->contact_email !== null) {
|
||||
Mail::to($this->request->invoice->contact_email)->send(new InvoiceMailsDeniedInvoiceMail(
|
||||
invoice: $this->request->invoice,
|
||||
costUnit: $this->request->invoice->costUnit()->first(),
|
||||
));
|
||||
}
|
||||
break;
|
||||
case InvoiceStatus::INVOICE_STATUS_NEW:
|
||||
$this->request->invoice->status = InvoiceStatus::INVOICE_STATUS_NEW;
|
||||
@@ -35,6 +53,12 @@ class ChangeStatusCommand {
|
||||
$this->request->invoice->denied_at = null;
|
||||
$this->request->invoice->comment = $this->request->invoice->denied_reason;
|
||||
$this->request->invoice->denied_reason = null;
|
||||
if ($this->request->invoice->contact_email !== null) {
|
||||
Mail::to($this->request->invoice->contact_email)->send(new InvoiceMailsReopenedInvoiceMail(
|
||||
invoice: $this->request->invoice,
|
||||
costUnit: $this->request->invoice->costUnit()->first(),
|
||||
));
|
||||
}
|
||||
break;
|
||||
case InvoiceStatus::INVOICE_STATUS_DELETED:
|
||||
$this->request->invoice->status = InvoiceStatus::INVOICE_STATUS_DELETED;
|
||||
@@ -49,7 +73,6 @@ class ChangeStatusCommand {
|
||||
$response->success = true;
|
||||
}
|
||||
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ async function reopenInvoice() {
|
||||
<Modal title="Abrechnung ablehnen" :show="denyInvoiceDialog" @close="denyInvoiceDialog = false" >
|
||||
Begründung:
|
||||
<textarea class="mareike-textarea" style="width: 100%; height: 100px; margin-top: 10px;" id="deny_invoice_reason" />
|
||||
<input type="button" class="mareike-button mareike-deny-invoice-button" value="Abrechnung ablehnen" @click="denyInvoice" />
|
||||
<input type="button" class="mareike-button mareike-deny-invoice-button" style="width: 250px !important;" value="Abrechnung ablehnen" @click="denyInvoice" />
|
||||
</Modal>
|
||||
|
||||
</template>
|
||||
|
||||
@@ -102,25 +102,27 @@ async function sendData() {
|
||||
name="contact_name" v-model="userName"
|
||||
style="font-size: 14pt; width: 550px;" /><br /><br />
|
||||
|
||||
<label>
|
||||
<label v-if="userName !== ''">
|
||||
<strong>E-Mail-Adresse (Für Rückfragen):</strong>
|
||||
</label><br />
|
||||
<input
|
||||
v-if="userName !== ''"
|
||||
type="email"
|
||||
name="contact_email"
|
||||
v-model="userEmail"
|
||||
style="font-size: 14pt; width: 550px;" /><br /><br />
|
||||
|
||||
<label>
|
||||
<label v-if="userName !== ''">
|
||||
<strong>Telefonnummer (für Rückfragen):</strong>
|
||||
</label><br />
|
||||
<input
|
||||
v-if="userName !== ''"
|
||||
type="text"
|
||||
id="contact_telephone"
|
||||
name="contact_telephone" v-model="userTelephone"
|
||||
style="font-size: 14pt; width: 550px;" /><br /><br />
|
||||
|
||||
<span id="decision" v-if="userName !== '' && decision === ''">
|
||||
<span id="decision" v-if="userEmail !== '' && decision === ''">
|
||||
<label><br />
|
||||
<strong>Möchtest du den Betrag spenden?</strong>
|
||||
</label><br />
|
||||
|
||||
79
app/Mail/InvoiceMails/InvoiceMailsApprovedInvoiceMail.php
Normal file
79
app/Mail/InvoiceMails/InvoiceMailsApprovedInvoiceMail.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail\InvoiceMails;
|
||||
|
||||
use App\Enumerations\InvoiceStatus;
|
||||
use App\Enumerations\InvoiceType;
|
||||
use App\Models\CostUnit;
|
||||
use App\Models\Invoice;
|
||||
use App\Resources\CostUnitResource;
|
||||
use App\Resources\InvoiceResource;
|
||||
use App\ValueObjects\Amount;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Attachment;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
|
||||
class InvoiceMailsApprovedInvoiceMail extends Mailable {
|
||||
public function __construct(
|
||||
private Invoice $invoice,
|
||||
private CostUnit $costUnit,
|
||||
)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Deine Abrechnung wurde zur Auszahlung freigegeben',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
$costUnit = new CostUnitResource($this->costUnit)->toArray(new Request());
|
||||
$invoice = new InvoiceResource($this->invoice)->toArray(new Request());
|
||||
|
||||
$invoiceStatus = match($invoice['status']) {
|
||||
InvoiceStatus::INVOICE_STATUS_APPROVED => 'Zur Auszahlung freigegeben',
|
||||
InvoiceStatus::INVOICE_STATUS_DENIED => 'Nicht auszahlbar und zurückgewiesen',
|
||||
InvoiceStatus::INVOICE_STATUS_NEW => 'Erneut zur Prüfung geöffnet',
|
||||
default => 'Unbekannt',
|
||||
};
|
||||
|
||||
$invoiceType = match($invoice['internalType']) {
|
||||
InvoiceType::INVOICE_TYPE_TRAVELLING => sprintf( 'Reisekosten [%1$s]', $invoice['travelReason']),
|
||||
default => $invoice['invoiceType'],
|
||||
};
|
||||
|
||||
return new Content(
|
||||
view: 'emails.invoices.changed_invoice_state',
|
||||
with: [
|
||||
'costUnitContactMail' => $this->costUnit->tenant()->first()->email_finance,
|
||||
'invoiceStatus' => $invoiceStatus,
|
||||
'costUnit' => $costUnit,
|
||||
'invoice' => $invoice,
|
||||
'invoiceType' => $invoiceType,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
81
app/Mail/InvoiceMails/InvoiceMailsDeniedInvoiceMail.php
Normal file
81
app/Mail/InvoiceMails/InvoiceMailsDeniedInvoiceMail.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail\InvoiceMails;
|
||||
|
||||
use App\Enumerations\InvoiceStatus;
|
||||
use App\Enumerations\InvoiceType;
|
||||
use App\Models\CostUnit;
|
||||
use App\Models\Event;
|
||||
use App\Models\EventParticipant;
|
||||
use App\Models\Invoice;
|
||||
use App\Resources\CostUnitResource;
|
||||
use App\Resources\InvoiceResource;
|
||||
use App\ValueObjects\Amount;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Attachment;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
|
||||
class InvoiceMailsDeniedInvoiceMail extends Mailable {
|
||||
public function __construct(
|
||||
private Invoice $invoice,
|
||||
private CostUnit $costUnit,
|
||||
)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Deine Abrechnung wurde zurückgewiesen',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
$costUnit = new CostUnitResource($this->costUnit)->toArray(new Request());
|
||||
$invoice = new InvoiceResource($this->invoice)->toArray(new Request());
|
||||
|
||||
$invoiceStatus = match($invoice['status']) {
|
||||
InvoiceStatus::INVOICE_STATUS_APPROVED => 'Zur Auszahlung freigegeben',
|
||||
InvoiceStatus::INVOICE_STATUS_DENIED => 'Nicht auszahlbar und zurückgewiesen',
|
||||
InvoiceStatus::INVOICE_STATUS_NEW => 'Erneut zur Prüfung geöffnet',
|
||||
default => 'Unbekannt',
|
||||
};
|
||||
|
||||
$invoiceType = match($invoice['internalType']) {
|
||||
InvoiceType::INVOICE_TYPE_TRAVELLING => sprintf( 'Reisekosten [%1$s]', $invoice['travelReason']),
|
||||
default => $invoice['invoiceType'],
|
||||
};
|
||||
|
||||
return new Content(
|
||||
view: 'emails.invoices.changed_invoice_state',
|
||||
with: [
|
||||
'costUnitContactMail' => $this->costUnit->tenant()->first()->email_finance,
|
||||
'invoiceStatus' => $invoiceStatus,
|
||||
'costUnit' => $costUnit,
|
||||
'invoice' => $invoice,
|
||||
'invoiceType' => $invoiceType,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
81
app/Mail/InvoiceMails/InvoiceMailsReopenedInvoiceMail.php
Normal file
81
app/Mail/InvoiceMails/InvoiceMailsReopenedInvoiceMail.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail\InvoiceMails;
|
||||
|
||||
use App\Enumerations\InvoiceStatus;
|
||||
use App\Enumerations\InvoiceType;
|
||||
use App\Models\CostUnit;
|
||||
use App\Models\Event;
|
||||
use App\Models\EventParticipant;
|
||||
use App\Models\Invoice;
|
||||
use App\Resources\CostUnitResource;
|
||||
use App\Resources\InvoiceResource;
|
||||
use App\ValueObjects\Amount;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Attachment;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
|
||||
class InvoiceMailsReopenedInvoiceMail extends Mailable {
|
||||
public function __construct(
|
||||
private Invoice $invoice,
|
||||
private CostUnit $costUnit,
|
||||
)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Deine Abrechnung wird erneut geprüft',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
$costUnit = new CostUnitResource($this->costUnit)->toArray(new Request());
|
||||
$invoice = new InvoiceResource($this->invoice)->toArray(new Request());
|
||||
|
||||
$invoiceStatus = match($invoice['status']) {
|
||||
InvoiceStatus::INVOICE_STATUS_APPROVED => 'Zur Auszahlung freigegeben',
|
||||
InvoiceStatus::INVOICE_STATUS_DENIED => 'Nicht auszahlbar und zurückgewiesen',
|
||||
InvoiceStatus::INVOICE_STATUS_NEW => 'Erneut zur Prüfung geöffnet',
|
||||
default => 'Unbekannt',
|
||||
};
|
||||
|
||||
$invoiceType = match($invoice['internalType']) {
|
||||
InvoiceType::INVOICE_TYPE_TRAVELLING => sprintf( 'Reisekosten [%1$s]', $invoice['travelReason']),
|
||||
default => $invoice['invoiceType'],
|
||||
};
|
||||
|
||||
return new Content(
|
||||
view: 'emails.invoices.changed_invoice_state',
|
||||
with: [
|
||||
'costUnitContactMail' => $this->costUnit->tenant()->first()->email_finance,
|
||||
'invoiceStatus' => $invoiceStatus,
|
||||
'costUnit' => $costUnit,
|
||||
'invoice' => $invoice,
|
||||
'invoiceType' => $invoiceType,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Scopes\InstancedModel;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
@@ -42,4 +43,8 @@ class CostUnit extends InstancedModel
|
||||
public function invoices() : hasMany {
|
||||
return $this->hasMany(Invoice::class);
|
||||
}
|
||||
|
||||
public function tenant() : BelongsTo {
|
||||
return $this->belongsTo(Tenant::class, 'tenant', 'slug');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class InvoiceResource {
|
||||
$returnData['deniedReason'] = $this->invoice->denied_reason ?? '--';
|
||||
$returnData['travelDirection'] = $this->invoice->travel_direction ?? '--';
|
||||
$returnData['travelReason'] = $this->invoice->travel_reason ?? '--';
|
||||
$returnData['distance'] = $this->invoice->distance;
|
||||
$returnData['distance'] = $this->invoice->distance ?? '--';
|
||||
$returnData['distanceAllowance'] = new Amount($this->invoice->costUnit()->first()->distance_allowance, '')->toString();
|
||||
$returnData['passengers'] = $this->invoice->passengers ? 'Ja' : 'Nein';
|
||||
$returnData['transportation'] = $this->invoice->transportation ? 'Ja' : 'Nein';
|
||||
|
||||
Reference in New Issue
Block a user