10.April 2026
This commit is contained in:
parent
a00c42e770
commit
f58c709945
208 changed files with 19280 additions and 2914 deletions
|
|
@ -7,6 +7,10 @@ use App\Services\AboHelper;
|
|||
|
||||
class AboRepository extends BaseRepository
|
||||
{
|
||||
private const LOCK_DAYS_CHANGE = 10;
|
||||
|
||||
private const LOCK_DAYS_PAUSE_CANCEL = 3;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// $this->model = $model;
|
||||
|
|
@ -24,9 +28,12 @@ class AboRepository extends BaseRepository
|
|||
if ($this->validate($data)) {
|
||||
$this->updateStatus($data);
|
||||
$this->model->abo_interval = $data['abo_interval'];
|
||||
$this->model->next_date = AboHelper::setNextDate(now(), $data['abo_interval']);
|
||||
$nextDate = $this->calculateNewNextDate($data['abo_interval']);
|
||||
$this->model->next_date = $nextDate;
|
||||
$this->model->save();
|
||||
\Session()->flash('alert-success', 'Einstellungen gespeichert');
|
||||
|
||||
$daysUntilNext = AboHelper::calendarDaysUntil(now(), $nextDate);
|
||||
\Session()->flash('alert-warning', __('abo.warning_next_date_info', ['days' => $daysUntilNext, 'date' => $nextDate->format('d.m.Y')]));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -44,6 +51,16 @@ class AboRepository extends BaseRepository
|
|||
{
|
||||
// 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) {
|
||||
$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]));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Status 4 = abo_cancel (storniert/gekündigt)
|
||||
$this->model->status = 4;
|
||||
$this->model->active = false;
|
||||
|
|
@ -54,6 +71,15 @@ 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) {
|
||||
$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]));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if status is active and active is false, set status to inactive
|
||||
if ($this->model->active && ! $active) {
|
||||
if ($this->model->status == 2) { // okay
|
||||
|
|
@ -63,7 +89,7 @@ class AboRepository extends BaseRepository
|
|||
}
|
||||
}
|
||||
if (! $this->model->active && $active) {
|
||||
if ($this->model->status = 6) { // inactive
|
||||
if ($this->model->status == 6) { // inactive
|
||||
$this->model->status = 2; // okay
|
||||
$this->model->active = true;
|
||||
$this->model->save();
|
||||
|
|
@ -97,23 +123,51 @@ class AboRepository extends BaseRepository
|
|||
}
|
||||
}
|
||||
if (! in_array($data['abo_interval'], \App\Models\UserAbo::$aboDeliveryDays)) {
|
||||
// to check if user is not admin
|
||||
\Session()->flash('alert-error', __('abo.error_abo_interval'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Prüfung: Wenn das Abo diesen Monat noch nicht ausgeführt wurde (oder noch nie),
|
||||
// darf das Abo-Intervall nicht auf einen Tag gesetzt werden, der bereits vergangen ist (oder heute ist),
|
||||
// da setNextDate das nächste Ausführungsdatum sonst auf den nächsten Monat setzt und dieser Monat übersprungen wird.
|
||||
$executedThisMonth = $this->model->last_date && \Carbon\Carbon::parse($this->model->last_date)->isCurrentMonth();
|
||||
// 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);
|
||||
if ($daysUntilExecution >= 0 && $daysUntilExecution < self::LOCK_DAYS_CHANGE) {
|
||||
\Session()->flash('alert-error', __('abo.error_change_locked', ['days' => $daysUntilExecution]));
|
||||
|
||||
if (! $executedThisMonth && $data['abo_interval'] <= now()->day) {
|
||||
\Session()->flash('alert-error', __('abo.error_abo_interval_in_the_past'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Prüfung: Das neue berechnete Ausführungsdatum muss mindestens LOCK_DAYS_CHANGE Tage entfernt sein.
|
||||
// Falls next_date bereits in einem zukünftigen Monat liegt, wird das neue Datum in diesem Monat berechnet.
|
||||
$newNextDate = $this->calculateNewNextDate($data['abo_interval']);
|
||||
$daysUntilNewDate = (int) now()->diffInDays($newNextDate, false);
|
||||
if ($daysUntilNewDate < self::LOCK_DAYS_CHANGE) {
|
||||
\Session()->flash('alert-error', __('abo.error_abo_interval_too_soon', ['days' => $daysUntilNewDate]));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Berechnet das neue Ausführungsdatum unter Berücksichtigung des aktuellen next_date.
|
||||
* Falls next_date bereits in einem zukünftigen Monat liegt, wird der Monatsanfang
|
||||
* dieses Monats als Referenz verwendet, sodass der neue Tag im selben Monat landet.
|
||||
*/
|
||||
private function calculateNewNextDate(int $aboInterval): \Carbon\Carbon
|
||||
{
|
||||
$referenceDate = now();
|
||||
|
||||
if ($this->model->next_date) {
|
||||
$currentNextDate = \Carbon\Carbon::parse($this->model->next_date);
|
||||
|
||||
if ($currentNextDate->format('Y-m') > now()->format('Y-m')) {
|
||||
$referenceDate = $currentNextDate->startOfMonth();
|
||||
}
|
||||
}
|
||||
|
||||
return AboHelper::setNextDate($referenceDate, $aboInterval);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,10 @@ use App\Models\ShoppingOrder;
|
|||
use App\Models\UserInvoice;
|
||||
use App\Models\UserSalesVolume;
|
||||
use App\Services\BusinessPlan\SalesPointsVolume;
|
||||
use App\Services\Incentive\IncentiveTracker;
|
||||
use App\Services\Invoice;
|
||||
use App\Services\UserService;
|
||||
use App\Services\Util;
|
||||
use Storage;
|
||||
|
||||
class InvoiceRepository extends BaseRepository
|
||||
|
|
@ -217,10 +219,15 @@ class InvoiceRepository extends BaseRepository
|
|||
|
||||
public function createAndSalesVolume($request = [])
|
||||
{
|
||||
$this->user_sales_volume = SalesPointsVolume::addSalesPointsVolumeUser($this->model);
|
||||
$user_invoice = $this->create($request);
|
||||
$this->user_sales_volume->user_invoice_id = $user_invoice->id;
|
||||
$this->user_sales_volume->save();
|
||||
$this->user_sales_volume = SalesPointsVolume::User($this->model);
|
||||
if (! Util::isTestSystem(true)) { // rechnung erstellen nur in production
|
||||
$user_invoice = $this->create($request);
|
||||
$this->user_sales_volume->user_invoice_id = $user_invoice->id;
|
||||
$this->user_sales_volume->save();
|
||||
}
|
||||
|
||||
// Incentive: Track sales volume points
|
||||
IncentiveTracker::trackSalesVolume($this->user_sales_volume);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue