23-01-2026
This commit is contained in:
parent
a939cd51ef
commit
a8b395e20d
248 changed files with 29342 additions and 4805 deletions
1271
dev/buinessPlan/_bak/BusinessUserItemOptimized.php
Normal file
1271
dev/buinessPlan/_bak/BusinessUserItemOptimized.php
Normal file
File diff suppressed because it is too large
Load diff
399
dev/buinessPlan/_bak/Growth-Bonus.md
Normal file
399
dev/buinessPlan/_bak/Growth-Bonus.md
Normal file
|
|
@ -0,0 +1,399 @@
|
|||
# Funktionsweise: Tiefenbonus (Growth Bonus)
|
||||
|
||||
## ⚠️ WICHTIG: Bug-Fix November 2025
|
||||
|
||||
### Das Problem (vor November 2025)
|
||||
|
||||
Die Payline-Prozentsätze (`pr_line_1` bis `pr_line_6`) in der Datenbank enthielten **bereits den Growth Bonus**.
|
||||
|
||||
**Beispiel Gold Member (falsche Berechnung):**
|
||||
|
||||
| Ebene | Wert in DB (`pr_line_X`) | Was ausgezahlt wurde | Was korrekt gewesen wäre |
|
||||
| ------- | ------------------------ | -------------------- | ------------------------------ |
|
||||
| Ebene 1 | 9% | 9% | 7% Payline + 2% Growth = 9% |
|
||||
| Ebene 2 | 9% | 9% | 7% Payline + 2% Growth = 9% |
|
||||
| Ebene 3 | 9% | 9% | 7% Payline + 2% Growth = 9% |
|
||||
| Ebene 4 | 6% | 6% | 4% Payline + 2% Growth = 6% |
|
||||
| Ebene 5 | 4% | 4% | 2% Payline + 2% Growth = 4% |
|
||||
| Ebene 6 | 4% | 4% | 2% Payline + 2% Growth = 4% |
|
||||
| Ebene 7 | - | 2% (Growth nochmal!) | 2% Growth (nur mit Differenz!) |
|
||||
|
||||
**Problem:** Der Growth Bonus wurde **doppelt gezählt**:
|
||||
|
||||
1. Einmal IN den Payline-Prozentsätzen (pr_line_1 = 9% statt 7%)
|
||||
2. Nochmal SEPARAT auf Ebenen ab 7+ (Legacy-Berechnung)
|
||||
|
||||
### Die Lösung (ab November 2025)
|
||||
|
||||
1. **Payline-Prozentsätze korrigiert:** `pr_line_X` enthält NUR den Payline-Anteil
|
||||
2. **Growth Bonus separat:** Wird mit Differenz-Logik berechnet
|
||||
3. **Einmal pro Bein:** Growth Bonus wird nur EINMAL pro Firstline-Zweig ausgezahlt
|
||||
|
||||
**Beispiel Gold Member (korrekte Berechnung):**
|
||||
|
||||
| Ebene | Payline (`pr_line_X`) | Growth Bonus (separat) | Gesamt |
|
||||
| -------- | --------------------- | ---------------------- | ------ |
|
||||
| Ebene 1 | 7% | +2% (Differenz-Logik) | 9% |
|
||||
| Ebene 2 | 7% | +2% | 9% |
|
||||
| Ebene 3 | 7% | +2% | 9% |
|
||||
| Ebene 4 | 4% | +2% | 6% |
|
||||
| Ebene 5 | 2% | +2% | 4% |
|
||||
| Ebene 6 | 2% | +2% | 4% |
|
||||
| Ebene 7+ | - | +2% (Differenz-Logik) | 2% |
|
||||
|
||||
**Wichtig:** Der Growth Bonus wird NUR ausgezahlt, wenn kein gleichrangiger oder höherer Partner in der Downline ist (Differenz-Berechnung)!
|
||||
|
||||
---
|
||||
|
||||
## Differenz-Logik (ab November 2025)
|
||||
|
||||
Der Tiefenbonus ist ein **Differenz-Bonus**, der **sofort ab der 1. Ebene** beginnt.
|
||||
|
||||
Es gilt das Prinzip: **"Jeder Partner schützt sein eigenes Team-Volumen."**
|
||||
|
||||
### 1. Die Grundregel
|
||||
|
||||
- **Start:** Der Bonus berechnet sich auf Points ab der **1. Ebene** (direkte Downline).
|
||||
- **Anspruch:** Ein Partner erhält seinen Status-Prozentsatz auf alle Points in seiner Linie, **bis** er auf einen Partner trifft, der selbst einen Status-Anspruch hat.
|
||||
- **Blockade:** Sobald ein Partner in der Downline einen Anspruch hat, zieht er diesen von der Upline ab (Differenz-Rechnung).
|
||||
- **⚠️ WICHTIG - Erreichtes Qualifikations-Level:** Die Blockade erfolgt NUR basierend auf dem **in dem Monat tatsächlich erreichten Level** (`qual_user_level`), NICHT auf dem aktuellen Karriere-Level des Partners!
|
||||
|
||||
### 1.1 Erreichte Qualifikation vs. Aktuelles Level
|
||||
|
||||
Ein Partner kann ein bestimmtes Karriere-Level (z.B. Gold) haben, aber in einem Monat die Qualifikationsvoraussetzungen nicht erfüllen. In diesem Fall:
|
||||
|
||||
| Situation | Aktuelles Level | Erreicht in Monat | Blockiert mit |
|
||||
| --------- | --------------- | ----------------- | ------------- |
|
||||
| Fall A | Gold (2%) | Gold qualifiziert | 2% ✅ |
|
||||
| Fall B | Gold (2%) | Team Leader (0%) | 0% ❌ |
|
||||
| Fall C | Team Leader | Silber (1.5%) | 1.5% ✅ |
|
||||
|
||||
**Technische Umsetzung:**
|
||||
|
||||
- Die Methode `getQualifiedGrowthBonus()` in `BusinessUserItemOptimized` gibt den Growth Bonus basierend auf dem **erreichten Qualifikations-Level** (`qual_user_level`) zurück.
|
||||
- Die alte Methode `getActiveGrowthBonus()` gibt den Growth Bonus basierend auf dem **aktuellen Karriere-Level** zurück (NUR für Legacy-Berechnungen!).
|
||||
- Der `GrowthBonusCalculator` verwendet ab November 2025 ausschließlich `getQualifiedGrowthBonus()`.
|
||||
|
||||
---
|
||||
|
||||
### 2. Die Differenz (Der Normalfall)
|
||||
|
||||
Points entstehen irgendwo im Team von **Partner B** (egal ob in B's Ebene 1 oder B's Ebene 50).
|
||||
|
||||
**Die Verteilung:**
|
||||
|
||||
1. **Sicht Partner B (Silber):**
|
||||
|
||||
- Er hat Anspruch auf **1,5 %** auf sein gesamtes Team.
|
||||
- Da unter ihm (Partner C) niemand einen Status hat, der etwas wegnehmen könnte, erhält B die vollen **1,5 %**.
|
||||
- Damit sind 1,5 % des "Kuchens" verteilt.
|
||||
|
||||
2. **Sicht Partner A (Diamant):**
|
||||
- Du hast Anspruch auf **2,5 %**.
|
||||
- Du schaust auf die Linie von Partner B.
|
||||
- Partner B hat den Status Silber und beansprucht damit **1,5 %** für sich und sein ganzes Team.
|
||||
- **Deine Rechnung:** 2,5 % (Dein Anspruch) - 1,5 % (Anspruch B) = **1,0 %**.
|
||||
- **Ergebnis:** Du erhältst auf das gesamte Volumen unter Partner B exakt **1,0 %**.
|
||||
|
||||
---
|
||||
|
||||
### 2. Das "GAP" (Die direkte Ebene)
|
||||
|
||||
Da der Bonus ab Ebene 1 beginnt, entsteht das GAP (die Auszahlung trotz gleichem Rang) immer am **Eigenumsatz des Partners**:
|
||||
|
||||
- **Partner A** (Diamant, 2,5 %) ist Sponsor von **Partner B** (Diamant, 2,5 %).
|
||||
- **Punkte von B (Eigenbestellung/Kunden):**
|
||||
- Partner B erhält darauf _keinen_ Tiefenbonus (man kriegt keinen Tiefenbonus auf sich selbst).
|
||||
- Partner B zieht also **0 %** vom Topf ab.
|
||||
- **Partner A erhält die vollen 2,5 % auf die Punkte von B.**
|
||||
- **Punkte UNTER B (Team von B):**
|
||||
- Partner B greift hier zu (Start ab Ebene 1) und nimmt sich **2,5 %**.
|
||||
- Partner A rechnet: 2,5 % - 2,5 % = **0 %**.
|
||||
- **Partner A ist hier blockiert.**
|
||||
|
||||
> Fazit: Bei gleichem Rang verdient man nur an den direkten Points des Partners (GAP), aber nicht mehr an dessen Team.
|
||||
|
||||
---
|
||||
|
||||
### 3. Das Szenario (A -> B -> F)
|
||||
|
||||
Wir schauen uns deine Struktur mit 3 Diamanten in einer Linie an. Alle haben Anspruch auf **2,5 %**.
|
||||
|
||||
- **Partner A** (Ebene 1)
|
||||
- **Partner B** (Ebene 2, direkt unter A)
|
||||
- ... dazwischen Berater ohne Status ...
|
||||
- **Partner F** (Ebene 6, unter B)
|
||||
- ... Punkte entstehen unter F ...
|
||||
|
||||
### Bereich 1: Punkte von Partner B
|
||||
|
||||
- Das ist für **A** die Ebene 1.
|
||||
- B blockiert nicht (da Eigenumsatz).
|
||||
- **Ergebnis:** **A erhält 2,5 %**.
|
||||
|
||||
### Bereich 2: Punkte ZWISCHEN B und F (Ebene 3 bis 6)
|
||||
|
||||
- Hier entstehen Punkte im Team von B.
|
||||
- **Sicht B:** Er ist qualifiziert (Start ab Ebene 1). Er nimmt sich **2,5 %**.
|
||||
- **Sicht A:** Er hat Anspruch auf 2,5 %. B hat aber schon 2,5 % genommen. Differenz = 0 %.
|
||||
- **Ergebnis:** **B erhält 2,5 %**. A geht leer aus.
|
||||
|
||||
### Bereich 3: Punkte von Partner F
|
||||
|
||||
- Das ist für **B** eine Ebene in seiner Downline.
|
||||
- F blockiert hier noch nicht (Eigenumsatz).
|
||||
- **Ergebnis:** **B erhält 2,5 %** auf die Punkte von F.
|
||||
|
||||
### Bereich 4: Punkte UNTER F (ab Ebene 7)
|
||||
|
||||
- Hier entstehen Punkte im Team von F.
|
||||
- **Sicht F:** Er ist qualifiziert (Start ab Ebene 1). Er nimmt sich **2,5 %**.
|
||||
- **Sicht B:** Anspruch 2,5 %. F hat schon 2,5 % genommen. Differenz = 0 %.
|
||||
- **Sicht A:** Anspruch 2,5 %. B (und F) haben alles genommen. Differenz = 0 %.
|
||||
- **Ergebnis:** **F erhält 2,5 %**. B und A gehen leer aus.
|
||||
|
||||
---
|
||||
|
||||
### 4. Zusammenfassung für die IT-Logik
|
||||
|
||||
1. **Trigger:** Ein Umsatz (Points) entsteht bei User X.
|
||||
2. **Schleife:** Gehe die Upline hoch (Sponsor -> Sponsor...).
|
||||
3. **Prüfung:**
|
||||
- Hat der Upline-Partner einen Status? (z.B. Diamant).
|
||||
- (Keine Prüfung auf Ebene mehr nötig, da Start immer ab Ebene 1).
|
||||
4. **Rechnung:**
|
||||
- Auszahlung = Mein %-Satz - Bereits verteilter %-Satz.
|
||||
- Wenn Auszahlung > 0: Speichern.
|
||||
- Setze `Bereits verteilter %-Satz` auf den neuen Wert (also `Mein %-Satz`).
|
||||
|
||||
---
|
||||
|
||||
## Code-Implementierung
|
||||
|
||||
Diese Implementierung nutzt eine **rekursive Aggregation von Volumen nach "Schutz-Level"**.
|
||||
Anstatt für jede Transaktion die Upline hochzulaufen ("Push"), holt sich der User die aggregierten Volumina seiner Downline gruppiert nach dem bereits beanspruchten Prozentsatz ("Pull").
|
||||
|
||||
### A. Neue Methode `getVolumeByProtectionLevel()`
|
||||
|
||||
Diese Methode liefert ein Array zurück, das das Volumen nach "bereits verteiltem Prozentsatz" gruppiert.
|
||||
Format: `['0.0' => 1000, '1.5' => 5000, ...]`
|
||||
|
||||
```php
|
||||
/**
|
||||
* Liefert das Volumen der Downline gruppiert nach dem "bereits verteilten Prozentsatz" (Protection Level).
|
||||
* Rekursive Funktion, die die "Differenz-Logik" vorbereitet.
|
||||
*
|
||||
* @return array<string, float> Key = Protected Percent, Value = Volume Points
|
||||
*/
|
||||
public function getVolumeByProtectionLevel(): array
|
||||
{
|
||||
$volumes = [];
|
||||
|
||||
// 1. Eigenes Volumen (Unprotected / GAP)
|
||||
// Man selbst schützt seinen eigenen Umsatz NICHT vor der Upline.
|
||||
// Daher Start mit Protection Level 0.0 (oder dem was von unten kommt, aber hier ist es ja Eigenumsatz)
|
||||
|
||||
// WICHTIG: Wir nutzen das Feld, das auch TreeCalcBot für die Punkte nutzt
|
||||
// sales_volume_points_TP_sum scheint in der DB/Model Logik für das relevante Volumen zu stehen
|
||||
$ownVolume = (float) ($this->b_user->sales_volume_points_TP_sum ?? 0);
|
||||
|
||||
if ($ownVolume > 0) {
|
||||
$key = '0.0';
|
||||
if (!isset($volumes[$key])) $volumes[$key] = 0.0;
|
||||
$volumes[$key] += $ownVolume;
|
||||
}
|
||||
|
||||
// 2. Mein Schutz-Level ermitteln
|
||||
// Das ist der Prozentsatz, den ICH auf mein Team beanspruche.
|
||||
// Alles Volumen, das durch MICH hindurch zur Upline fließt, hat mindestens diesen Schutz-Level.
|
||||
$myProtectionPercent = 0.0;
|
||||
if ($this->isQualLevel()) {
|
||||
$qual = $this->b_user->qual_user_level;
|
||||
if (!empty($qual['growth_bonus'])) {
|
||||
$myProtectionPercent = (float) $qual['growth_bonus'];
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Kinder verarbeiten
|
||||
if (!empty($this->businessUserItems)) {
|
||||
foreach ($this->businessUserItems as $childItem) {
|
||||
|
||||
// Rekursion: Hol dir die Volumen-Töpfe aus der Downline
|
||||
// Hinweis: Hier muss sichergestellt sein, dass die Kinder geladen sind.
|
||||
// initBusinesslUserDetail lädt normalerweise die Struktur.
|
||||
|
||||
// Falls Kinder nicht geladen sind, müssten sie hier theoretisch geladen werden.
|
||||
// Wir gehen davon aus, dass die Struktur bereits rekursiv via readParentsBusinessUsers geladen wurde.
|
||||
|
||||
$childVolumes = $childItem->getVolumeByProtectionLevel();
|
||||
|
||||
// 4. Schutz-Level anwenden (Aggregation)
|
||||
foreach ($childVolumes as $protectedPercentStr => $vol) {
|
||||
$incomingProtection = (float) $protectedPercentStr;
|
||||
|
||||
// Das Volumen ist bereits mit $incomingProtection geschützt.
|
||||
// Da es nun durch MICH fließt, erhöht sich der Schutz auf MEINEN Level (falls meiner höher ist).
|
||||
$effectiveProtection = max($incomingProtection, $myProtectionPercent);
|
||||
|
||||
$newKey = (string) $effectiveProtection;
|
||||
|
||||
if (!isset($volumes[$newKey])) $volumes[$newKey] = 0.0;
|
||||
$volumes[$newKey] += $vol;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $volumes;
|
||||
}
|
||||
```
|
||||
|
||||
### B. Neue Methode `calculateGrowthBonusRecursive()`
|
||||
|
||||
Diese Methode ersetzt die bisherige Berechnung und nutzt die oben definierte Aggregation.
|
||||
|
||||
```php
|
||||
/**
|
||||
* Berechnet den Growth Bonus (Tiefenbonus) basierend auf der Differenz-Logik.
|
||||
*/
|
||||
private function calculateGrowthBonusRecursive($qualUserLevel): float
|
||||
{
|
||||
if (empty($qualUserLevel->growth_bonus) || $qualUserLevel->growth_bonus <= 0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
$myGrowthPercent = (float) $qualUserLevel->growth_bonus;
|
||||
$totalGrowthBonus = 0.0;
|
||||
|
||||
// Wir iterieren über alle direkten Beine (Firstlines)
|
||||
foreach ($this->businessUserItems as $childItem) {
|
||||
|
||||
// Volumen-Verteilung aus diesem Bein abrufen
|
||||
// Das Kind liefert uns: "Hier sind 1000 Punkte geschützt mit 0%, 5000 Punkte geschützt mit 1.5%"
|
||||
$volumeDistribution = $childItem->getVolumeByProtectionLevel();
|
||||
|
||||
foreach ($volumeDistribution as $protectedPercentStr => $volume) {
|
||||
$alreadyDistributedPercent = (float) $protectedPercentStr;
|
||||
|
||||
// Differenz berechnen
|
||||
// Mein Anspruch MINUS was schon verteilt wurde
|
||||
$mySharePercent = max(0, $myGrowthPercent - $alreadyDistributedPercent);
|
||||
|
||||
if ($mySharePercent > 0) {
|
||||
$commission = round($volume / 100 * $mySharePercent, 2);
|
||||
$totalGrowthBonus += $commission;
|
||||
|
||||
// Optional Logging
|
||||
// \Log::debug("Growth Bonus: User {$this->b_user->user_id} earns {$mySharePercent}% on {$volume} pts (Protected: {$alreadyDistributedPercent}%) from leg {$childItem->b_user->user_id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $totalGrowthBonus;
|
||||
}
|
||||
```
|
||||
|
||||
### C. Integration in `calculateCommissions`
|
||||
|
||||
```php
|
||||
private function calculateCommissions($qualUserLevel): void
|
||||
{
|
||||
$commission_pp_total = 0;
|
||||
|
||||
// 1. Normale Unilevel Provision (Payline) - NUR pr_line_X Werte
|
||||
for ($i = 1; $i <= $qualUserLevel->paylines; $i++) {
|
||||
if (isset($this->b_user->business_lines[$i])) {
|
||||
$object = $this->b_user->business_lines[$i];
|
||||
$margin = (float) $this->b_user->qual_user_level['pr_line_' . $i];
|
||||
|
||||
$points = is_array($object) ? ((float)($object['points'] ?? 0)) : ((float)($object->points ?? 0));
|
||||
|
||||
$commission = round($points / 100 * $margin, 2);
|
||||
$commission_pp_total += $commission;
|
||||
|
||||
// Rückschreiben
|
||||
if (is_array($object)) {
|
||||
$object['margin'] = $margin;
|
||||
$object['commission'] = $commission;
|
||||
$object['payline'] = true;
|
||||
} else {
|
||||
$object->margin = $margin;
|
||||
$object->commission = $commission;
|
||||
$object->payline = true;
|
||||
}
|
||||
$this->b_user->business_lines[$i] = $object;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Growth Bonus - Unterscheidung Legacy vs. Neu
|
||||
$commission_growth_total = 0;
|
||||
|
||||
if (!empty($qualUserLevel->growth_bonus)) {
|
||||
// Stichtag: 01.11.2025
|
||||
$isLegacy = ($this->date->year < 2025) ||
|
||||
($this->date->year == 2025 && $this->date->month < 11);
|
||||
|
||||
if ($isLegacy) {
|
||||
// ALT: Pauschal ab Ebene paylines+1 (FALSCH - doppelte Auszahlung!)
|
||||
$commission_growth_total = $this->calculateLegacyGrowthBonus($qualUserLevel);
|
||||
} else {
|
||||
// NEU: Differenz-Logik via GrowthBonusCalculator
|
||||
$commission_growth_total = $this->calculateGrowthBonusRecursive($qualUserLevel);
|
||||
}
|
||||
}
|
||||
|
||||
$this->b_user->commission_pp_total = $commission_pp_total;
|
||||
$this->b_user->commission_growth_total = $commission_growth_total;
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Legacy-Berechnung (vor November 2025) - DEPRECATED
|
||||
|
||||
**⚠️ Diese Logik war FALSCH und führte zu doppelter Auszahlung!**
|
||||
|
||||
```php
|
||||
/**
|
||||
* ALT: Pauschal Growth Bonus ab Ebene paylines+1
|
||||
* PROBLEM: Growth Bonus war bereits in pr_line_X enthalten!
|
||||
*/
|
||||
private function calculateLegacyGrowthBonus($qualUserLevel): float
|
||||
{
|
||||
$commission_growth_total = 0;
|
||||
|
||||
// Start ab Ebene paylines+1 (z.B. 7 bei Gold)
|
||||
$payline = (int) ($this->b_user->qual_user_level['paylines'] ?? 0) + 1;
|
||||
$maxlines = count($this->b_user->business_lines ?? []) + 1;
|
||||
$growth_bonus = (float) ($this->b_user->qual_user_level['growth_bonus'] ?? 0);
|
||||
|
||||
// Auf JEDE Ebene ab payline wird der volle Growth Bonus gezahlt
|
||||
// OHNE Differenz-Prüfung = FALSCH!
|
||||
for ($i = $payline; $i <= $maxlines; $i++) {
|
||||
if (isset($this->b_user->business_lines[$i])) {
|
||||
$points = $this->b_user->business_lines[$i]['points'] ?? 0;
|
||||
$commission = round($points / 100 * $growth_bonus, 2);
|
||||
$commission_growth_total += $commission;
|
||||
}
|
||||
}
|
||||
|
||||
return $commission_growth_total;
|
||||
}
|
||||
```
|
||||
|
||||
**Warum war das falsch?**
|
||||
|
||||
1. `pr_line_1` bei Gold = 9% (enthielt bereits 2% Growth Bonus)
|
||||
2. Growth Bonus wurde ab Ebene 7 NOCHMAL mit 2% berechnet
|
||||
3. = **Doppelte Auszahlung** auf tieferen Ebenen
|
||||
|
||||
---
|
||||
|
||||
## Neue Berechnung (ab November 2025) - KORREKT
|
||||
|
||||
Der `GrowthBonusCalculator` verwendet die Differenz-Logik:
|
||||
|
||||
1. **Aggregation:** Sammelt Volumen gruppiert nach "Schutz-Level"
|
||||
2. **Differenz:** Berechnet nur die Differenz (mein Anspruch - bereits verteilt)
|
||||
3. **Einmal pro Bein:** Growth Bonus wird nur einmal pro Firstline-Zweig ausgezahlt
|
||||
|
||||
Siehe `GrowthBonusCalculator.php` für die Implementation.
|
||||
318
dev/buinessPlan/_bak/GrowthBonusCalculator.php
Normal file
318
dev/buinessPlan/_bak/GrowthBonusCalculator.php
Normal file
|
|
@ -0,0 +1,318 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\BusinessPlan;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Service für die Berechnung des Growth Bonus (Tiefenbonus)
|
||||
* Implementiert die Differenz-Bonus-Logik ab Ebene 1
|
||||
*/
|
||||
class GrowthBonusCalculator
|
||||
{
|
||||
/**
|
||||
* Berechnet den Growth Bonus für einen BusinessUserItemOptimized
|
||||
*
|
||||
* @param BusinessUserItemOptimized $userItem Der User, für den der Bonus berechnet wird
|
||||
* @param object $qualUserLevel Das Qualifikations-Level-Objekt des Users
|
||||
* @return float Der berechnete Bonus
|
||||
*/
|
||||
public function calculate(BusinessUserItemOptimized $userItem, $qualUserLevel): float
|
||||
{
|
||||
// Basis-Check: Hat der User überhaupt Anspruch auf Growth Bonus?
|
||||
if (empty($qualUserLevel->growth_bonus) || $qualUserLevel->growth_bonus <= 0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// Falls keine direkte Downline-Struktur geladen ist, kann kein Growth Bonus berechnet werden
|
||||
if (empty($userItem->businessUserItems) && !empty($userItem->business_lines)) {
|
||||
Log::warning("GrowthBonusCalculator: Growth Bonus calculation requires loaded child structure (businessUserItems is empty for user {$userItem->user_id})");
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return $this->calculateRecursive($userItem, $qualUserLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Führt die eigentliche Berechnung basierend auf der Differenz-Logik durch
|
||||
*/
|
||||
private function calculateRecursive(BusinessUserItemOptimized $userItem, $qualUserLevel): float
|
||||
{
|
||||
$myGrowthPercent = (float) $qualUserLevel->growth_bonus;
|
||||
$totalGrowthBonus = 0.0;
|
||||
|
||||
// Iteriere über alle direkten Beine (Firstlines)
|
||||
foreach ($userItem->businessUserItems as $childItem) {
|
||||
|
||||
// Hole die Volumen-Verteilung aus diesem Bein
|
||||
// Array-Format: ['0.0' => 1000, '1.5' => 5000]
|
||||
// Bedeutung: 1000 Punkte sind mit 0% geschützt, 5000 Punkte mit 1.5%
|
||||
$volumeDistribution = $this->getVolumeByProtectionLevel($childItem);
|
||||
|
||||
foreach ($volumeDistribution as $protectedPercentStr => $volume) {
|
||||
$alreadyDistributedPercent = (float) $protectedPercentStr;
|
||||
|
||||
// Differenz berechnen: Mein Anspruch MINUS was schon verteilt wurde
|
||||
$mySharePercent = max(0, $myGrowthPercent - $alreadyDistributedPercent);
|
||||
|
||||
if ($mySharePercent > 0) {
|
||||
$commission = round($volume / 100 * $mySharePercent, 2);
|
||||
$totalGrowthBonus += $commission;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $totalGrowthBonus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert detaillierte Informationen zur Berechnung für die Anzeige
|
||||
*
|
||||
* @return array Detaillierte Aufschlüsselung pro Bein
|
||||
*/
|
||||
public function getCalculationDetails(BusinessUserItemOptimized $userItem, $qualUserLevel): array
|
||||
{
|
||||
$details = [];
|
||||
if (empty($qualUserLevel->growth_bonus) || $qualUserLevel->growth_bonus <= 0) {
|
||||
return $details;
|
||||
}
|
||||
|
||||
$myGrowthPercent = (float) $qualUserLevel->growth_bonus;
|
||||
|
||||
// Iteriere über alle direkten Beine (Firstlines)
|
||||
foreach ($userItem->businessUserItems as $childItem) {
|
||||
$legDetails = [
|
||||
'user_id' => $childItem->user_id,
|
||||
'first_name' => $childItem->first_name,
|
||||
'last_name' => $childItem->last_name,
|
||||
'level_name' => $childItem->user_level_name,
|
||||
'volume_distribution' => [],
|
||||
'total_commission' => 0.0,
|
||||
'total_volume' => 0.0
|
||||
];
|
||||
|
||||
$volumeDistribution = $this->getVolumeByProtectionLevel($childItem);
|
||||
|
||||
foreach ($volumeDistribution as $protectedPercentStr => $volume) {
|
||||
$alreadyDistributedPercent = (float) $protectedPercentStr;
|
||||
$mySharePercent = max(0, $myGrowthPercent - $alreadyDistributedPercent);
|
||||
$commission = 0.0;
|
||||
|
||||
if ($mySharePercent > 0) {
|
||||
$commission = round($volume / 100 * $mySharePercent, 2);
|
||||
}
|
||||
|
||||
$legDetails['volume_distribution'][] = [
|
||||
'protected_percent' => $alreadyDistributedPercent,
|
||||
'volume' => $volume,
|
||||
'my_share_percent' => $mySharePercent,
|
||||
'commission' => $commission
|
||||
];
|
||||
|
||||
$legDetails['total_commission'] += $commission;
|
||||
$legDetails['total_volume'] += $volume;
|
||||
}
|
||||
|
||||
// Sortiere nach Protection Level
|
||||
usort($legDetails['volume_distribution'], function ($a, $b) {
|
||||
return $a['protected_percent'] <=> $b['protected_percent'];
|
||||
});
|
||||
|
||||
if ($legDetails['total_volume'] > 0) {
|
||||
$details[] = $legDetails;
|
||||
}
|
||||
}
|
||||
|
||||
// Sortiere Beine nach höchster Provision
|
||||
usort($details, function ($a, $b) {
|
||||
return $b['total_commission'] <=> $a['total_commission'];
|
||||
});
|
||||
|
||||
return $details;
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert eine Matrix-Sicht für die detaillierte Darstellung
|
||||
* Zeilen = Beine (Legs), Spalten = Ebenen (Levels)
|
||||
*/
|
||||
public function getMatrixDetails(BusinessUserItemOptimized $userItem, $qualUserLevel): array
|
||||
{
|
||||
$details = [];
|
||||
if (empty($qualUserLevel->growth_bonus) || $qualUserLevel->growth_bonus <= 0) {
|
||||
return $details;
|
||||
}
|
||||
|
||||
$myGrowthPercent = (float) $qualUserLevel->growth_bonus;
|
||||
|
||||
foreach ($userItem->businessUserItems as $childItem) {
|
||||
|
||||
$legData = [
|
||||
'user' => [
|
||||
'id' => $childItem->user_id,
|
||||
'name' => $childItem->first_name . ' ' . $childItem->last_name,
|
||||
'level' => $childItem->user_level_name
|
||||
],
|
||||
'levels' => [],
|
||||
'total_commission' => 0.0,
|
||||
'total_volume' => 0.0
|
||||
];
|
||||
|
||||
// Rekursiv die Ebenen dieses Beins einsammeln
|
||||
// Start bei Ebene 1 (das ist das Kind selbst)
|
||||
// Initial Protection ist 0 (vom Upline/Mir kommt kein Schutz, der relevant wäre, da ICH ja der Empfänger bin)
|
||||
$this->collectLegLevels($childItem, 1, 0.0, $myGrowthPercent, $legData);
|
||||
|
||||
if (!empty($legData['levels'])) {
|
||||
// Sortieren nach Ebenen-Index
|
||||
ksort($legData['levels']);
|
||||
$details[] = $legData;
|
||||
}
|
||||
}
|
||||
|
||||
// Sortieren nach Gesamt-Provision
|
||||
usort($details, function ($a, $b) {
|
||||
return $b['total_commission'] <=> $a['total_commission'];
|
||||
});
|
||||
|
||||
return $details;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rekursive Hilfsfunktion für Matrix-Daten
|
||||
*/
|
||||
private function collectLegLevels(BusinessUserItemOptimized $item, int $level, float $incomingProtection, float $myPercent, array &$legData)
|
||||
{
|
||||
// 1. Eigenen Status ermitteln (Schutz für Downline)
|
||||
// WICHTIG: Nutze getQualifiedGrowthBonus() für das ERREICHTE Qualifikations-Level des Monats
|
||||
// Nicht getActiveGrowthBonus() verwenden, da das das aktuelle Karriere-Level wäre!
|
||||
$userProtection = $item->getQualifiedGrowthBonus();
|
||||
$userLevelName = '';
|
||||
|
||||
if ($userProtection > 0) {
|
||||
$qual = $item->getQualUserLevel();
|
||||
$userLevelName = is_array($qual) ? ($qual['name'] ?? '') : ($qual->name ?? '');
|
||||
}
|
||||
|
||||
// Berechnung für diesen User (Ebene)
|
||||
$volume = (float) ($item->sales_volume_points_TP_sum ?? 0);
|
||||
|
||||
// Auch User ohne Volumen in die Matrix aufnehmen, wenn sie einen Status haben (Blocker sichtbar machen)
|
||||
// Aber wir brauchen Volumen für die Relevanz. Wenn Volumen 0, dann ist der Block hier (noch) egal,
|
||||
// wirkt aber auf die Ebenen darunter.
|
||||
|
||||
if ($volume > 0 || $userProtection > 0) {
|
||||
// WICHTIG: Der effektive Schutz ist das MAXIMUM aus:
|
||||
// - Schutz von oben ($incomingProtection)
|
||||
// - Eigener Schutz des Users ($userProtection)
|
||||
// Der User schützt sein EIGENES Volumen mit seinem eigenen Growth Bonus!
|
||||
$effectiveProtection = max($incomingProtection, $userProtection);
|
||||
$diffPercent = max(0, $myPercent - $effectiveProtection);
|
||||
$commission = round($volume / 100 * $diffPercent, 2);
|
||||
|
||||
if (!isset($legData['levels'][$level])) {
|
||||
$legData['levels'][$level] = [
|
||||
'volume' => 0.0,
|
||||
'commission' => 0.0,
|
||||
'details' => [],
|
||||
'has_blocker' => false, // Flag für UI
|
||||
'blocker_name' => ''
|
||||
];
|
||||
}
|
||||
|
||||
$legData['levels'][$level]['volume'] += $volume;
|
||||
$legData['levels'][$level]['commission'] += $commission;
|
||||
|
||||
// Markiere Blocker
|
||||
if ($userProtection > 0) {
|
||||
$legData['levels'][$level]['has_blocker'] = true;
|
||||
$legData['levels'][$level]['blocker_name'] = $userLevelName . ' (' . $userProtection . '%)';
|
||||
}
|
||||
|
||||
// Detail-Information für Hover/Debug
|
||||
$legData['levels'][$level]['details'][] = [
|
||||
'u' => $item->user_id,
|
||||
'n' => $item->first_name . ' ' . $item->last_name, // Name für Tooltip
|
||||
'v' => $volume,
|
||||
'p_in' => $incomingProtection,
|
||||
'p_own' => $userProtection,
|
||||
'pct' => $diffPercent
|
||||
];
|
||||
|
||||
$legData['total_volume'] += $volume;
|
||||
$legData['total_commission'] += $commission;
|
||||
}
|
||||
|
||||
// Protection für nächste Ebene: Maximum aus was von oben kam und was dieser User beansprucht
|
||||
$nextProtection = max($incomingProtection, $userProtection);
|
||||
|
||||
// Rekursion (Begrenzt auf 30 Ebenen für Anzeige)
|
||||
if ($level < 30 && !empty($item->businessUserItems)) {
|
||||
foreach ($item->businessUserItems as $child) {
|
||||
$this->collectLegLevels($child, $level + 1, $nextProtection, $myPercent, $legData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert das Volumen der Downline eines Users gruppiert nach dem "bereits verteilten Prozentsatz" (Protection Level).
|
||||
* Rekursive Funktion, die die "Differenz-Logik" vorbereitet.
|
||||
*
|
||||
* @param BusinessUserItemOptimized $item
|
||||
* @return array<string, float> Key = Protected Percent, Value = Volume Points
|
||||
*/
|
||||
public function getVolumeByProtectionLevel(BusinessUserItemOptimized $item): array
|
||||
{
|
||||
// WICHTIG: Nur calcQualPP aufrufen wenn KEINE gespeicherten Daten vorhanden sind
|
||||
// Bei gespeicherten Daten ist qual_user_level bereits vorhanden, auch wenn qualificationCalculated=false
|
||||
if (!$item->isQualificationCalculated() && !$item->isQualLevel()) {
|
||||
$item->calcQualPP();
|
||||
}
|
||||
|
||||
$volumes = [];
|
||||
|
||||
// 1. Eigenes Volumen (Unprotected / GAP)
|
||||
// Man selbst schützt seinen eigenen Umsatz NICHT vor der Upline.
|
||||
// Daher Start mit Protection Level 0.0
|
||||
$ownVolume = (float) ($item->sales_volume_points_TP_sum ?? 0);
|
||||
|
||||
if ($ownVolume > 0) {
|
||||
$key = '0.0';
|
||||
$volumes[$key] = $ownVolume;
|
||||
}
|
||||
|
||||
// 2. Mein Schutz-Level ermitteln (für das Volumen, das durch mich hindurch fließt)
|
||||
// WICHTIG: Nutze getQualifiedGrowthBonus() für das ERREICHTE Qualifikations-Level des Monats
|
||||
// Nicht getActiveGrowthBonus() verwenden, da das das aktuelle Karriere-Level wäre!
|
||||
$myProtectionPercent = $item->getQualifiedGrowthBonus();
|
||||
|
||||
// Debug-Logging für Troubleshooting
|
||||
Log::debug("GrowthBonusCalculator: User {$item->user_id} - qualifiedGrowthBonus={$myProtectionPercent}%, activeGrowthBonus={$item->getActiveGrowthBonus()}%, isQualLevel=" . ($item->isQualLevel() ? 'true' : 'false'));
|
||||
|
||||
// 3. Rekursive Aggregation der Kinder
|
||||
if (!empty($item->businessUserItems)) {
|
||||
foreach ($item->businessUserItems as $childItem) {
|
||||
|
||||
// Rekursiver Aufruf
|
||||
$childVolumes = $this->getVolumeByProtectionLevel($childItem);
|
||||
|
||||
// 4. Schutz-Level anwenden und aggregieren
|
||||
foreach ($childVolumes as $protectedPercentStr => $vol) {
|
||||
$incomingProtection = (float) $protectedPercentStr;
|
||||
|
||||
// Das Volumen ist bereits mit $incomingProtection geschützt.
|
||||
// Da es nun durch diesen User fließt, erhöht sich der Schutz auf dessen Level (falls höher).
|
||||
$effectiveProtection = max($incomingProtection, $myProtectionPercent);
|
||||
|
||||
$newKey = (string) $effectiveProtection;
|
||||
|
||||
if (!isset($volumes[$newKey])) {
|
||||
$volumes[$newKey] = 0.0;
|
||||
}
|
||||
$volumes[$newKey] += $vol;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $volumes;
|
||||
}
|
||||
}
|
||||
263
dev/buinessPlan/_bak/SalesPointsVolume.php
Normal file
263
dev/buinessPlan/_bak/SalesPointsVolume.php
Normal file
|
|
@ -0,0 +1,263 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\BusinessPlan;
|
||||
|
||||
use App\User;
|
||||
use stdClass;
|
||||
use App\Services\Util;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\UserSalesVolume;
|
||||
use App\Events\BusinessDataChanged;
|
||||
|
||||
class SalesPointsVolume
|
||||
{
|
||||
|
||||
public static function changeSalesPointsVolumeUser(ShoppingOrder $shoppingOrder, $to_user_id)
|
||||
{
|
||||
|
||||
if ($shoppingOrder->user_sales_volume) {
|
||||
$to_user_id = intval($to_user_id);
|
||||
if ($shoppingOrder->user_sales_volume->user_id === $to_user_id) {
|
||||
\Session()->flash('alert-error', 'Keine Änderung: selber Berater');
|
||||
return;
|
||||
}
|
||||
if (!$shoppingOrder->user_sales_volume->isCurrentMonthYear()) {
|
||||
\Session()->flash('alert-error', 'Änderung muss im selben Monat sein');
|
||||
return;
|
||||
}
|
||||
|
||||
$month = $shoppingOrder->user_sales_volume->month;
|
||||
$year = $shoppingOrder->user_sales_volume->year;
|
||||
$form_user_id = $shoppingOrder->user_sales_volume->user_id;
|
||||
|
||||
$to_user = User::find($to_user_id);
|
||||
$form_user = User::find($form_user_id);
|
||||
|
||||
$shoppingOrder->user_sales_volume->user_id = $to_user_id;
|
||||
$shoppingOrder->user_sales_volume->message = 'zugewiesen: ' . date('d.m.Y');
|
||||
|
||||
$syslog = $shoppingOrder->user_sales_volume->syslog;
|
||||
$from_email = $form_user ? $form_user->email : '';
|
||||
$to_email = $to_user ? $to_user->email : '';
|
||||
$syslog[date('d.m.Y-h:i:s')] = 'change form: #' . $form_user_id . ' ' . $from_email . ' to: #' . $to_user_id . ' ' . $to_email;
|
||||
$shoppingOrder->user_sales_volume->syslog = $syslog;
|
||||
|
||||
$shoppingOrder->user_sales_volume->save();
|
||||
|
||||
//recalculate
|
||||
self::reCalculateSalesPointsVolume($to_user_id, $month, $year);
|
||||
self::reCalculateSalesPointsVolume($form_user_id, $month, $year);
|
||||
\Session()->flash('alert-save', true);
|
||||
}
|
||||
}
|
||||
|
||||
private static function add_KP_TP_Points($userSalesVolume, $month_points)
|
||||
{
|
||||
if ($userSalesVolume->status_points === 2) { //KP
|
||||
$month_points->KP += $userSalesVolume->points;
|
||||
} else {
|
||||
// === 1 //TP + KP
|
||||
$month_points->KP += $userSalesVolume->points;
|
||||
$month_points->TP += $userSalesVolume->points;
|
||||
}
|
||||
return $month_points;
|
||||
}
|
||||
|
||||
public static function reCalculateSalesPointsVolume($user_id, $month, $year)
|
||||
{
|
||||
|
||||
$userSalesVolumes = UserSalesVolume::where('user_id', $user_id)->where('month', $month)->where('year', $year)->orderBy('id', 'ASC')->get();
|
||||
$month_points = new stdClass();
|
||||
$month_points->KP = 0;
|
||||
$month_points->TP = 0;
|
||||
$month_total_net = 0;
|
||||
$month_shop_points = 0;
|
||||
$month_shop_total_net = 0;
|
||||
//TDOO Status === 3???
|
||||
|
||||
foreach ($userSalesVolumes as $userSalesVolume) {
|
||||
switch ($userSalesVolume->status) {
|
||||
case 1: //Bestellung Berater
|
||||
$month_points = self::add_KP_TP_Points($userSalesVolume, $month_points);
|
||||
$month_total_net += $userSalesVolume->total_net;
|
||||
break;
|
||||
case 2: //Shop
|
||||
$month_shop_points += $userSalesVolume->points;
|
||||
$month_shop_total_net += $userSalesVolume->total_net;
|
||||
break;
|
||||
case 4: //Gutschrift
|
||||
$month_points = self::add_KP_TP_Points($userSalesVolume, $month_points);
|
||||
|
||||
if ($userSalesVolume->status_turnover === 2) {
|
||||
$month_shop_total_net += $userSalesVolume->total_net;
|
||||
//ggf hier zu den Shop Points zählen wäre aber immer KP + TP kann nicht keine trennung bei month_shop_points
|
||||
} else {
|
||||
$month_total_net += $userSalesVolume->total_net;
|
||||
}
|
||||
|
||||
break;
|
||||
case 5: //Registrierung
|
||||
$month_points = self::add_KP_TP_Points($userSalesVolume, $month_points);
|
||||
$month_total_net += $userSalesVolume->total_net;
|
||||
break;
|
||||
}
|
||||
$userSalesVolume->month_shop_points = $month_shop_points;
|
||||
$userSalesVolume->month_shop_total_net = $month_shop_total_net;
|
||||
$userSalesVolume->month_KP_points = $month_points->KP;
|
||||
$userSalesVolume->month_TP_points = $month_points->TP;
|
||||
$userSalesVolume->month_total_net = $month_total_net;
|
||||
$userSalesVolume->save();
|
||||
}
|
||||
|
||||
// Event für Business-Neuberechnung (Bubble Up zur Upline)
|
||||
if ($user_id) {
|
||||
event(new BusinessDataChanged($user_id, BusinessDataChanged::TYPE_SALES_VOLUME, (int)$month, (int)$year));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function addSalesPointsVolumeUser(ShoppingOrder $shoppingOrder)
|
||||
{
|
||||
|
||||
/*
|
||||
status
|
||||
1 => 'hinzugefügt aus Bestellung',
|
||||
2 => 'hinzugefügt aus Shop',
|
||||
3 => 'hinzugefügt aus Shop / pending',
|
||||
*/
|
||||
|
||||
$status = self::getStatusByOrderPaymentFor($shoppingOrder);
|
||||
$user_id = $shoppingOrder->auth_user_id ? $shoppingOrder->auth_user_id : $shoppingOrder->member_id;
|
||||
//akuteller tag / Monat.
|
||||
$month = date('m');
|
||||
$year = date('Y');
|
||||
$date = date('d.m.Y');
|
||||
|
||||
|
||||
if ($status === 3) { //shop bestellung User pending if is_like
|
||||
$user_id = NULL;
|
||||
}
|
||||
$user_sales_volume = UserSalesVolume::create([
|
||||
'user_id' => $user_id,
|
||||
'shopping_order_id' => $shoppingOrder->id,
|
||||
'month' => $month,
|
||||
'year' => $year,
|
||||
'date' => $date,
|
||||
'points' => $shoppingOrder->points,
|
||||
'total_net' => $shoppingOrder->subtotal,
|
||||
'status_points' => 1, //KP + TP
|
||||
'message' => '',
|
||||
'status' => $status,
|
||||
]);
|
||||
|
||||
if ($status !== 3) {
|
||||
self::reCalculateSalesPointsVolume($user_sales_volume->user_id, $user_sales_volume->month, $user_sales_volume->year);
|
||||
}
|
||||
|
||||
return $user_sales_volume;
|
||||
}
|
||||
|
||||
public static function setToUserAndReCalculate(UserSalesVolume $user_sales_volume, $user_id)
|
||||
{
|
||||
|
||||
//set month year date new, calculate it in the currently month!
|
||||
//If the month has changed, it can no longer be added to the month before
|
||||
$month = date('m');
|
||||
$year = date('Y');
|
||||
$date = date('d.m.Y');
|
||||
|
||||
$user_sales_volume->user_id = $user_id;
|
||||
$user_sales_volume->month = $month;
|
||||
$user_sales_volume->year = $year;
|
||||
$user_sales_volume->date = $date;
|
||||
$user_sales_volume->status = 2; //hinzugefügt aus Shop can only Pending
|
||||
$user_sales_volume->save();
|
||||
|
||||
self::reCalculateSalesPointsVolume($user_id, $month, $year);
|
||||
}
|
||||
|
||||
public static function getStatusByOrderPaymentFor(ShoppingOrder $shoppingOrder)
|
||||
{
|
||||
if ($shoppingOrder->payment_for) {
|
||||
if ($shoppingOrder->payment_for === 6) { //Kunde-Shop
|
||||
if ($shoppingOrder->shopping_user && $shoppingOrder->shopping_user->is_like) {
|
||||
return 3; //shop Kunden, berater zuordnen <- need?
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public static function editSalesPointsVolume($data)
|
||||
{
|
||||
$user_sales_volume = UserSalesVolume::findOrFail($data['id']);
|
||||
if (!$user_sales_volume->isCurrentMonthYear()) {
|
||||
\Session()->flash('alert-error', 'Änderung muss im selben Monat sein');
|
||||
return;
|
||||
}
|
||||
$old_points = $user_sales_volume->points;
|
||||
$old_total_net = $user_sales_volume->total_net;
|
||||
$user_sales_volume->total_net = Util::reFormatNumber($data['total_net']);
|
||||
$user_sales_volume->points = Util::reFormatNumber($data['points']);
|
||||
|
||||
$user_sales_volume->message = 'geändert: ' . date('d.m.Y');
|
||||
$user_sales_volume->info = $data['info'];
|
||||
$user_sales_volume->status_points = $data['status_points'];
|
||||
$user_sales_volume->status_turnover = isset($data['status_turnover']) ? intval($data['status_turnover']) : null;
|
||||
|
||||
$syslog = $user_sales_volume->syslog;
|
||||
$syslog[date('d.m.Y-h:i:s')] = 'edit points: #' . $old_points . ' ' . $user_sales_volume->points . ' total: #' . $old_total_net . ' ' . $user_sales_volume->total_net;
|
||||
$user_sales_volume->syslog = $syslog;
|
||||
|
||||
$user_sales_volume->save();
|
||||
|
||||
self::reCalculateSalesPointsVolume($user_sales_volume->user_id, $user_sales_volume->month, $user_sales_volume->year);
|
||||
|
||||
\Session()->flash('alert-success', "Points geändert");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public static function addSalesPointsVolume($data)
|
||||
{
|
||||
|
||||
if (!isset($data['user_id'])) {
|
||||
\Session()->flash('alert-error', 'Kein Berater ausgewählt');
|
||||
return;
|
||||
}
|
||||
$user = User::findOrFail($data['user_id']);
|
||||
$month = date('m');
|
||||
$year = date('Y');
|
||||
$date = date('d.m.Y');
|
||||
|
||||
$total_net = isset($data['total_net']) ? Util::reFormatNumber($data['total_net']) : 0;
|
||||
$points = isset($data['points']) ? Util::reFormatNumber($data['points']) : 0;
|
||||
$syslog[date('d.m.Y-h:i:s')] = 'add points: #' . $points . ' total: #' . $total_net;
|
||||
$status = isset($data['status']) ? intval($data['status']) : 4;
|
||||
$status_turnover = isset($data['status_turnover']) ? intval($data['status_turnover']) : null;
|
||||
|
||||
$user_sales_volume = UserSalesVolume::create([
|
||||
'user_id' => $user->id,
|
||||
'shopping_order_id' => null,
|
||||
'month' => $month,
|
||||
'year' => $year,
|
||||
'date' => $date,
|
||||
'points' => $points,
|
||||
'status_points' => $data['status_points'],
|
||||
'status_turnover' => $status_turnover,
|
||||
'total_net' => $total_net,
|
||||
'message' => 'hinzugefügt: ' . date('d.m.Y'),
|
||||
'info' => $data['info'],
|
||||
'syslog' => $syslog,
|
||||
'status' => $status,
|
||||
]);
|
||||
|
||||
|
||||
self::reCalculateSalesPointsVolume($user_sales_volume->user_id, $user_sales_volume->month, $user_sales_volume->year);
|
||||
|
||||
\Session()->flash('alert-success', "Points hinzugefügt");
|
||||
}
|
||||
}
|
||||
1080
dev/buinessPlan/_bak/TreeCalcBotOptimized.php
Normal file
1080
dev/buinessPlan/_bak/TreeCalcBotOptimized.php
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue