Zahlungszwecke
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace App\Domains\Invoice\Actions\CreateInvoice;
|
||||
|
||||
use App\Enumerations\InvoiceStatus;
|
||||
use App\Enumerations\InvoiceType;
|
||||
use App\Enumerations\TravelReason;
|
||||
use App\Mail\InvoiceMails\InvoiceMailsNewInvoiceMail;
|
||||
use App\Mail\InvoiceMails\InvoiceMailsSubmittedConfirmationMail;
|
||||
use App\Mail\ParticipantParticipationMails\EventSignUpSuccessfullMail;
|
||||
@@ -19,10 +21,19 @@ class CreateInvoiceCommand {
|
||||
public function execute() : CreateInvoiceResponse {
|
||||
$response = new CreateInvoiceResponse();
|
||||
|
||||
$rejection = $this->rejectTravelReason();
|
||||
if ($rejection !== null) {
|
||||
$response->message = $rejection;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
if ($this->request->accountIban === 'undefined') {
|
||||
$this->request->accountIban = null;
|
||||
}
|
||||
|
||||
$travelReason = $this->travelReason();
|
||||
|
||||
$invoice = Invoice::create([
|
||||
'tenant' => currentTenant()->slug,
|
||||
'cost_unit_id' => $this->request->costUnit->id,
|
||||
@@ -30,6 +41,7 @@ class CreateInvoiceCommand {
|
||||
'status' => InvoiceStatus::INVOICE_STATUS_NEW,
|
||||
'type' => $this->request->invoiceType,
|
||||
'type_other' => $this->request->invoiceTypeExtended,
|
||||
'purpose' => $this->purpose($travelReason),
|
||||
'donation' => $this->request->isDonation,
|
||||
'user_id' => $this->request->paymentPurpose === null ? $this->request->userId : null,
|
||||
'contact_name' => $this->request->contactName,
|
||||
@@ -40,9 +52,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,
|
||||
'travel_reason' => $travelReason,
|
||||
'payment_purpose' => $this->request->paymentPurpose,
|
||||
'comment' => $this->request->notices,
|
||||
'document_filename' => $this->request->receiptFile !== null ? $this->request->receiptFile->fullPath : null,
|
||||
@@ -81,6 +91,68 @@ class CreateInvoiceCommand {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Der Zahlungsgrund, einmal beim Anlegen festgehalten.
|
||||
*
|
||||
* Danach ist er eine eigene Angabe: Die Kassenwart*in kann ihn korrigieren, und nichts schreibt ihn
|
||||
* mehr um. Bei Fahrtkosten setzt er sich aus Reisegrund und den gefahrenen Personen zusammen, sonst
|
||||
* trägt ihn "Was wurde eingekauft". Wo nichts erfasst wird -- Beitragserstattungen -- bleibt er leer.
|
||||
*
|
||||
* Steht er schon fest, wird er übernommen: Eine Abrechnungskorrektur kopiert den Beleg, und ein von
|
||||
* Hand gesetzter Grund darf dabei nicht verloren gehen.
|
||||
*/
|
||||
private function purpose(?string $travelReason) : ?string {
|
||||
if (trim((string) $this->request->purpose) !== '') {
|
||||
return $this->request->purpose;
|
||||
}
|
||||
|
||||
$purpose = Invoice::joinPurposeParts(
|
||||
$this->request->invoiceType === InvoiceType::INVOICE_TYPE_TRAVELLING
|
||||
// Der Name des Grundes, nicht sein Schlüssel: In der Belegliste soll "Materialtransport"
|
||||
// stehen, nicht "material_transport".
|
||||
? [TravelReason::text($travelReason), $this->request->travellers]
|
||||
: [$this->request->invoiceTypeExtended]
|
||||
);
|
||||
|
||||
return $purpose === '' ? null : $purpose;
|
||||
}
|
||||
|
||||
/**
|
||||
* Was in `travel_reason` landet: der Schlüssel des gewählten Grundes -- oder, bei "Anderer Grund",
|
||||
* der Text selbst. Der Schlüssel `other` sagt für sich nichts aus, der Text alles.
|
||||
*
|
||||
* Ein unbekannter Wert ist deshalb kein Fehler, sondern genau dieser Fall: So kommen auch
|
||||
* Bestandsbelege und Kopien durch, die ihren Freitext schon mitbringen.
|
||||
*/
|
||||
private function travelReason() : ?string {
|
||||
$reason = TravelReason::find($this->request->travelReason);
|
||||
|
||||
if ($reason === null) {
|
||||
return $this->request->travelReason;
|
||||
}
|
||||
|
||||
return $reason->requires_note
|
||||
? trim((string) $this->request->travelReasonNote)
|
||||
: $reason->slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sicherheitsnetz hinter der Oberfläche: Dort geht es erst weiter, wenn die Erläuterung steht. Über
|
||||
* einen direkten Aufruf ginge das sonst vorbei, und ein "Anderer Grund" ohne Text sagt nichts aus --
|
||||
* gespeichert würde ein leerer Reisegrund.
|
||||
*/
|
||||
private function rejectTravelReason() : ?string {
|
||||
$reason = TravelReason::find($this->request->travelReason);
|
||||
|
||||
if ($reason === null || !$reason->requires_note) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return trim((string) $this->request->travelReasonNote) === ''
|
||||
? 'Bitte gib an, was der Grund für die Reise war.'
|
||||
: null;
|
||||
}
|
||||
|
||||
private function generateInvoiceNumber() : string {
|
||||
$lastInvoiceNumber = Invoice::query()
|
||||
->where('tenant', currentTenant()->slug)
|
||||
|
||||
@@ -16,16 +16,24 @@ class CreateInvoiceRequest {
|
||||
public ?string $invoiceTypeExtended;
|
||||
public ?string $travelRoute;
|
||||
public ?int $distance;
|
||||
public ?int $passengers;
|
||||
public ?int $transportations;
|
||||
public ?InvoiceFile $receiptFile;
|
||||
public float $totalAmount;
|
||||
public bool $isDonation;
|
||||
public ?int $userId;
|
||||
/** Der Slug eines Reisegrundes -- oder ein Freitext, wenn er von einem Bestandsbeleg stammt. */
|
||||
public ?string $travelReason;
|
||||
|
||||
/** Die Erläuterung zu "Anderer Grund"; nur bei einem Grund mit `requires_note` von Belang. */
|
||||
public ?string $travelReasonNote;
|
||||
public ?string $paymentPurpose;
|
||||
public ?string $notices;
|
||||
|
||||
/** Wer gereist ist -- Freitext aus dem Fahrtkosten-Formular, geht in den Zahlungsgrund ein. */
|
||||
public ?string $travellers;
|
||||
|
||||
/** Ein bereits feststehender Zahlungsgrund; gesetzt, gewinnt er über die Ermittlung im Command. */
|
||||
public ?string $purpose;
|
||||
|
||||
|
||||
public function __construct(
|
||||
CostUnit $costUnit,
|
||||
@@ -42,11 +50,12 @@ class CreateInvoiceRequest {
|
||||
?string $invoiceTypeExtended = null,
|
||||
?string $travelRoute = null,
|
||||
?int $distance = null,
|
||||
?int $passengers = null,
|
||||
?int $transportations,
|
||||
?string $travelReason = null,
|
||||
?string $travelReasonNote = null,
|
||||
?string $paymentPurpose = null,
|
||||
?string $notices = null,
|
||||
?string $travellers = null,
|
||||
?string $purpose = null,
|
||||
|
||||
) {
|
||||
$this->costUnit = $costUnit;
|
||||
@@ -55,8 +64,6 @@ class CreateInvoiceRequest {
|
||||
$this->invoiceTypeExtended = $invoiceTypeExtended;
|
||||
$this->travelRoute = $travelRoute;
|
||||
$this->distance = $distance;
|
||||
$this->passengers = $passengers;
|
||||
$this->transportations = $transportations;
|
||||
$this->receiptFile = $receiptFile;
|
||||
$this->contactEmail = $contactEmail;
|
||||
$this->contactPhone = $contactPhone;
|
||||
@@ -66,8 +73,11 @@ class CreateInvoiceRequest {
|
||||
$this->isDonation = $isDonation;
|
||||
$this->userId = $userId;
|
||||
$this->travelReason = $travelReason;
|
||||
$this->travelReasonNote = $travelReasonNote;
|
||||
$this->paymentPurpose = $paymentPurpose;
|
||||
$this->notices = $notices;
|
||||
$this->travellers = $travellers;
|
||||
$this->purpose = $purpose;
|
||||
|
||||
if ($accountIban === 'undefined') {
|
||||
$this->accountIban = null;
|
||||
|
||||
@@ -8,8 +8,12 @@ class CreateInvoiceResponse {
|
||||
public bool $success;
|
||||
public ?Invoice $invoice;
|
||||
|
||||
/** Warum keine Abrechnung entstanden ist -- für die Rückmeldung an die einreichende Person. */
|
||||
public ?string $message;
|
||||
|
||||
public function __construct() {
|
||||
$this->success = false;
|
||||
$this->invoice = null;
|
||||
$this->message = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user