Teilnahmerechnungen erstellen
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace App\Domains\Admin\Actions\UpdateTenantTax;
|
||||
|
||||
use App\Enumerations\VatPricingMode;
|
||||
use App\Models\Tenant;
|
||||
use App\Support\Text;
|
||||
|
||||
class UpdateTenantTaxAction
|
||||
{
|
||||
@@ -14,14 +16,23 @@ class UpdateTenantTaxAction
|
||||
{
|
||||
$response = new UpdateTenantTaxResponse();
|
||||
|
||||
// Präfixe sind großgeschrieben; null heißt "nicht mitgeschickt" und damit "unverändert".
|
||||
$prefix = Text::nullIfBlank(strtoupper((string) $this->request->invoicePrefix));
|
||||
|
||||
if ($prefix !== null && $this->prefixTakenByAnotherTenant($prefix)) {
|
||||
$response->message = sprintf('Das Rechnungs-Präfix "%s" wird bereits von einem anderen Mandanten genutzt.', $prefix);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
if ($this->request->taxLiable) {
|
||||
$this->request->tenant->update([
|
||||
$this->request->tenant->update($this->withInvoiceDetails([
|
||||
'tax_liable' => true,
|
||||
'vat_rate' => $this->clampVatRate($this->request->vatRate),
|
||||
'vat_pricing_mode' => $this->request->vatPricingMode->value,
|
||||
'tax_exemption_reason' => null,
|
||||
'tax_exemption_note' => null,
|
||||
]);
|
||||
], $prefix));
|
||||
|
||||
$response->success = true;
|
||||
$response->message = 'Steuerinformationen wurden gespeichert.';
|
||||
@@ -45,13 +56,13 @@ class UpdateTenantTaxAction
|
||||
return $response;
|
||||
}
|
||||
|
||||
$this->request->tenant->update([
|
||||
$this->request->tenant->update($this->withInvoiceDetails([
|
||||
'tax_liable' => false,
|
||||
'vat_rate' => 0,
|
||||
'vat_pricing_mode' => VatPricingMode::Inclusive->value,
|
||||
'tax_exemption_reason' => $reason->slug,
|
||||
'tax_exemption_note' => $reason->requires_note ? $note : null,
|
||||
]);
|
||||
], $prefix));
|
||||
|
||||
$response->success = true;
|
||||
$response->message = 'Steuerinformationen wurden gespeichert.';
|
||||
@@ -63,4 +74,31 @@ class UpdateTenantTaxAction
|
||||
{
|
||||
return max(0, min(100, $vatRate));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ergänzt die Rechnungsstellerangaben. Sie gelten unabhängig davon, ob Steuerpflicht besteht -- eine
|
||||
* Steuernummer gehört auch auf eine steuerfreie Rechnung.
|
||||
*
|
||||
* @param array<string, mixed> $attributes
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function withInvoiceDetails(array $attributes, ?string $prefix): array
|
||||
{
|
||||
$attributes['tax_number'] = Text::nullIfBlank($this->request->taxNumber);
|
||||
$attributes['vat_id'] = Text::nullIfBlank($this->request->vatId);
|
||||
|
||||
// Nicht mitgeschickt heißt "unverändert", nicht "leeren".
|
||||
if ($prefix !== null) {
|
||||
$attributes['invoice_prefix'] = $prefix;
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
private function prefixTakenByAnotherTenant(string $prefix): bool
|
||||
{
|
||||
return Tenant::where('invoice_prefix', $prefix)
|
||||
->where('id', '!=', $this->request->tenant->id)
|
||||
->exists();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user