Steuerberater Modul tax

This commit is contained in:
Kevin Adametz 2026-05-08 15:34:57 +02:00
parent 0f82fea88a
commit 245c281541
22 changed files with 1489 additions and 139 deletions

View file

@ -4,6 +4,7 @@ namespace App\Repositories;
use App\Models\UserAbo;
use App\Services\AboHelper;
use Carbon\Carbon;
class AboRepository extends BaseRepository
{
@ -27,8 +28,10 @@ class AboRepository extends BaseRepository
if ($data['action'] === 'abo_update_settings') {
if ($this->validate($data)) {
$this->updateStatus($data);
$this->model->abo_interval = $data['abo_interval'];
$nextDate = $this->calculateNewNextDate($data['abo_interval']);
$this->model->abo_interval = (int) $data['abo_interval'];
$nextDate = $this->isAdminUpdate($data)
? $this->calculateAdminNextDate($data)
: $this->calculateNewNextDate((int) $data['abo_interval']);
$this->model->next_date = $nextDate;
$this->model->save();
@ -49,10 +52,12 @@ class AboRepository extends BaseRepository
private function updateStatus($data)
{
$isAdminUpdate = $this->isAdminUpdate($data);
// Handle cancellation
if (isset($data['abo_cancel']) && $data['abo_cancel'] == 'true') {
// Sperre: 3 Tage vor Ausführung kann nicht mehr pausiert/gekündigt werden
if ($this->model->next_date) {
if (! $isAdminUpdate && $this->model->next_date) {
$daysUntil = (int) now()->diffInDays(\Carbon\Carbon::parse($this->model->next_date), false);
if ($daysUntil >= 0 && $daysUntil < self::LOCK_DAYS_PAUSE_CANCEL) {
\Session()->flash('alert-error', __('abo.error_cancel_locked', ['days' => $daysUntil]));
@ -72,7 +77,7 @@ class AboRepository extends BaseRepository
$active = (isset($data['abo_is_active']) && $data['abo_is_active']) ? true : false;
// Sperre: 3 Tage vor Ausführung kann nicht mehr pausiert werden
if ($this->model->active && ! $active && $this->model->next_date) {
if (! $isAdminUpdate && $this->model->active && ! $active && $this->model->next_date) {
$daysUntil = (int) now()->diffInDays(\Carbon\Carbon::parse($this->model->next_date), false);
if ($daysUntil >= 0 && $daysUntil < self::LOCK_DAYS_PAUSE_CANCEL) {
\Session()->flash('alert-error', __('abo.error_pause_locked', ['days' => $daysUntil]));
@ -122,12 +127,28 @@ class AboRepository extends BaseRepository
return false;
}
}
if (! in_array($data['abo_interval'], \App\Models\UserAbo::$aboDeliveryDays)) {
if (! isset($data['abo_interval']) || ! in_array((int) $data['abo_interval'], \App\Models\UserAbo::$aboDeliveryDays, true)) {
\Session()->flash('alert-error', __('abo.error_abo_interval'));
return false;
}
if ($this->isAdminUpdate($data)) {
if (! isset($data['abo_next_month']) || ! in_array($data['abo_next_month'], $this->getAdminExecutionMonths(), true)) {
\Session()->flash('alert-error', __('abo.error_next_date'));
return false;
}
if ($this->calculateAdminNextDate($data)->startOfDay()->lt(now()->startOfDay())) {
\Session()->flash('alert-error', __('abo.error_next_date'));
return false;
}
return true;
}
// Sperre: 10 Tage vor nächster Ausführung keine Änderungen mehr (Pakete werden vorgepackt)
if ($this->model->next_date) {
$daysUntilExecution = (int) now()->diffInDays(\Carbon\Carbon::parse($this->model->next_date), false);
@ -170,4 +191,26 @@ class AboRepository extends BaseRepository
return AboHelper::setNextDate($referenceDate, $aboInterval);
}
private function calculateAdminNextDate(array $data): Carbon
{
return Carbon::createFromFormat('Y-m-d', $data['abo_next_month'].'-01')
->startOfMonth()
->addDays(((int) $data['abo_interval']) - 1);
}
/**
* @return array<int, string>
*/
private function getAdminExecutionMonths(): array
{
return collect(range(0, 3))
->map(fn (int $offset): string => now()->copy()->startOfMonth()->addMonths($offset)->format('Y-m'))
->all();
}
private function isAdminUpdate(array $data): bool
{
return ($data['view'] ?? null) === 'admin';
}
}

View file

@ -74,6 +74,7 @@ class CheckoutRepository extends BaseRepository
'subtotal_ws' => $ShoppingCollectOrder->price_total_net,
'tax' => $ShoppingCollectOrder->tax_total,
'tax_split' => $ShoppingCollectOrder->tax_split,
'net_split' => $ShoppingCollectOrder->net_split,
'total_shipping' => Yard::instance($this->instance)->totalWithShipping(2, '.', ''),
'points' => round($ShoppingCollectOrder->points, 2),
'weight' => 0,