Statistik: uebrige Audit-Korrekturen (Abo-Regeln, Prognose, Sortierung)

A01 — Abo-Regeln waren ueber das Aktiv-Feld umgehbar. Das
Selbstbedienungsformular hat gar keinen Aktiv-Schalter, es spiegelt den Zustand
nur in einem versteckten Feld zurueck; `updateStatus()` hat den Wert trotzdem
uebernommen. Wer den Request manipulierte, konnte sein eigenes Abo dauerhaft
deaktivieren und so die Mindestlaufzeit umgehen, am Pausenpfad mit seinen
Sperren vorbei. Das Feld wirkt jetzt nur noch im Admin-Pfad.

A16 — Statuswechsel wurden nur aus dem Formular protokolliert. Recovery-Zahlung,
Retry, externe Erledigung und die DSGVO-Anonymisierung schreiben `active` direkt
auf das Modell. Das ist heikel, weil die historische Bestandsrueckrechnung ein
Abo verwirft, solange eine protokollierte Deaktivierung nicht durch eine
spaetere protokollierte Reaktivierung aufgehoben ist — ein stiller
`active = true` nimmt es dauerhaft aus allen Folgemonaten.

Der Eintrag liegt deshalb jetzt am Model (`UserAbo::logStatusTransition()`) und
nicht in den einzelnen Diensten: so kann ihn ein kuenftiger Schreibpfad nicht
vergessen, und er entsteht in derselben Transaktion wie die Statusaenderung.
Nebeneffekt: Die DSGVO-Anonymisierung setzt `active = false` ohne `cancel_date`
— bisher fiel ein so abgeschaltetes Abo rueckwirkend aus allen vergangenen
Monaten, jetzt bleibt die Historie korrekt.

A13 — Ein heute faelliges Abo galt ab Mitternacht als erledigt, der
Ausfuehrungsjob laeuft aber erst um 04:00. In diesem Fenster fehlten die Punkte
in der Prognose UND im Ist. Der neue Scope `UserAbo::scopeOpenExecutionUntil()`
zaehlt den heutigen Liefertag mit, solange keine Ausfuehrung angelegt ist —
genau diese Bedingung verhindert die Doppelzaehlung. Alle drei Prognosen nutzen
jetzt denselben Scope statt je einer eigenen Kopie der Datumsregel.

A11 — Der Namens-Tiebreak der Top 3 lief nach dem Abschneiden auf 25
Kandidaten, bei Gleichstand entschied also die Reihenfolge der Abfrage. Die
Auswahlgrenze wird jetzt um alle Gleichstaende an dieser Grenze erweitert, und
Kandidaten ohne Account fallen vorher weg statt die Plaetze zu blockieren. Als
letzte Regel entscheidet die user_id, damit eine gecachte Rangliste
reproduzierbar bleibt.

A14 — Sortiert wurde ueber den angezeigten Zellentext. Unter `en` liefert die
Anwendung `Y-m-d` und `1,000.00`, damit ergab jedes Datum 0 und `1,000.00` wurde
zur 1. Die Zellen tragen jetzt `data-sort-value` mit dem unformatierten Wert;
ohne Attribut gilt weiter der Textweg. Dabei mitgenommen: Umlaute landeten hinter
dem Z (jetzt localeCompare), leere Werte lagen als 0 zwischen den negativen
Stornowerten, und `next_date` wurde doppelt formatiert.

Ausserdem A08 (Prognose auch ohne erreichte Qualifikationsstufe), A09
(Summenzeile im Neupartner-CSV), A10 (Lieferungszahl vorgeladen), A17
(Faelligkeitsgruppen ohne Monatsueberlauf), A18 (Formelinhalte im CSV als Text)
und A19 (fehlgeschlagene Provisionsberechnung ist als solche erkennbar statt
0,00 EUR).

Audit-Befunde A01, A08, A09, A10, A11, A13, A14, A16, A17, A18, A19.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kevin 2026-09-10 11:19:38 +00:00
parent 92344f7080
commit 5a38f4ac3e
31 changed files with 1931 additions and 241 deletions

View file

@ -100,9 +100,10 @@
<th class="text-right" data-sortable="true" data-sort-type="number" style="background-color:#d4edda;"><span class="sortable-label justify-content-end">Kundenpunkte <i class="ion ion-ios-swap sort-icon"></i></span></th>
<th class="text-right" data-sortable="true" data-sort-type="number"><span class="sortable-label justify-content-end">Gesamtpunkte <i class="ion ion-ios-swap sort-icon"></i></span></th>
@elseif ($details['metric'] === 'new_partners')
<th data-sortable="true"><span class="sortable-label">Telefon <i class="ion ion-ios-swap sort-icon"></i></span></th>
<th data-sortable="true"><span class="sortable-label">Sponsor <i class="ion ion-ios-swap sort-icon"></i></span></th>
<th class="text-right" data-sortable="true" data-sort-type="number"><span class="sortable-label justify-content-end">Kundenpunkte <i class="ion ion-ios-swap sort-icon"></i></span></th>
<th class="text-right" data-sortable="true" data-sort-type="number" title="Eigen- und Kundenpunkte des Monats zusammen — inkl. Starterpaket"><span class="sortable-label justify-content-end">Punkte gesamt <i class="ion ion-ios-swap sort-icon"></i></span></th>
<th class="text-right" data-sortable="true" data-sort-type="number" title="Punkte aus den Bestellungen SEINER Kunden (Shop und Abo) — ohne seine eigenen Bestellungen."><span class="sortable-label justify-content-end">Punkte seiner Kunden <i class="ion ion-ios-swap sort-icon"></i></span></th>
<th class="text-right" data-sortable="true" data-sort-type="number" title="Punkte seiner Kunden PLUS seine eigenen Bestellungen — hier steckt vor allem das Starterpaket drin."><span class="sortable-label justify-content-end">Gesamt (inkl. Eigenbestellung) <i class="ion ion-ios-swap sort-icon"></i></span></th>
<th data-sortable="true" data-sort-type="date"><span class="sortable-label">Aktiv seit <i class="ion ion-ios-swap sort-icon"></i></span></th>
<th data-sortable="true" data-sort-type="date"><span class="sortable-label">Account gültig bis <i class="ion ion-ios-swap sort-icon"></i></span></th>
@else
@ -119,8 +120,8 @@
<td>{{ $row['email'] ?? '-' }}</td>
<td>{{ $row['career_level'] ?? '-' }}</td>
@if ($details['metric'] === 'team_customer_abos')
<td class="text-right">{{ number_format($row['abo_count'], 0, ',', '.') }}</td>
<td class="text-right">
<td class="text-right" data-sort-value="{{ $row['abo_count'] }}">{{ number_format($row['abo_count'], 0, ',', '.') }}</td>
<td class="text-right" data-sort-value="{{ $row['points'] }}">
<span class="font-weight-bold">{{ \App\Services\Util::formatNumber($row['points']) }}</span>
@if (! empty($row['abos']))
<a class="d-block small" data-toggle="collapse"
@ -145,37 +146,38 @@
</td>
@elseif ($details['metric'] === 'team_partner_abos')
<td>{{ $row['consultant_name'] ?? $row['name'] }}</td>
<td class="text-right">{{ \App\Services\Util::formatNumber($row['points']) }}</td>
<td>
<td class="text-right" data-sort-value="{{ $row['points'] }}">{{ \App\Services\Util::formatNumber($row['points']) }}</td>
<td data-sort-value="{{ $row['status_label'] ?? '' }}">
{!! $row['status_badge'] ?? '' !!}
@if (! empty($row['status_reason']))
<div class="small text-muted mt-1">{{ $row['status_reason'] }}</div>
@endif
</td>
<td>
<td data-sort-value="{{ $row['start_date_sort'] ?? '' }}">
{{ $row['start_date'] ?? '-' }}
@if (! empty($row['is_new_this_month']))
<span class="badge badge-success ml-1">Neu</span>
@endif
</td>
<td>{{ $row['next_date'] ?? '-' }}</td>
<td class="text-right">{{ number_format($row['deliveries'], 0, ',', '.') }}</td>
<td data-sort-value="{{ $row['next_date_sort'] ?? '' }}">{{ $row['next_date'] ?? '-' }}</td>
<td class="text-right" data-sort-value="{{ $row['deliveries'] }}">{{ number_format($row['deliveries'], 0, ',', '.') }}</td>
@elseif (in_array($details['metric'], ['own_points', 'external_points', 'customer_abo_points', 'customer_single_order_points', 'customer_other_points', 'total_points', 'shop_1000'], true))
<td class="text-right"><span class="badge" style="background-color:#d4edda;color:#155724;font-size:90%;">{{ \App\Services\Util::formatNumber($row['own_points']) }}</span></td>
<td class="text-right">{{ \App\Services\Util::formatNumber($row['customer_single_order_points']) }}</td>
<td class="text-right">{{ \App\Services\Util::formatNumber($row['customer_abo_points']) }}</td>
<td class="text-right">{{ \App\Services\Util::formatNumber($row['customer_other_points']) }}</td>
<td class="text-right font-weight-bold"><span class="badge" style="background-color:#d4edda;color:#155724;font-size:90%;">{{ \App\Services\Util::formatNumber($row['external_points']) }}</span></td>
<td class="text-right font-weight-bold">{{ \App\Services\Util::formatNumber($row['total_points']) }}</td>
<td class="text-right" data-sort-value="{{ $row['own_points'] }}"><span class="badge" style="background-color:#d4edda;color:#155724;font-size:90%;">{{ \App\Services\Util::formatNumber($row['own_points']) }}</span></td>
<td class="text-right" data-sort-value="{{ $row['customer_single_order_points'] }}">{{ \App\Services\Util::formatNumber($row['customer_single_order_points']) }}</td>
<td class="text-right" data-sort-value="{{ $row['customer_abo_points'] }}">{{ \App\Services\Util::formatNumber($row['customer_abo_points']) }}</td>
<td class="text-right" data-sort-value="{{ $row['customer_other_points'] }}">{{ \App\Services\Util::formatNumber($row['customer_other_points']) }}</td>
<td class="text-right font-weight-bold" data-sort-value="{{ $row['external_points'] }}"><span class="badge" style="background-color:#d4edda;color:#155724;font-size:90%;">{{ \App\Services\Util::formatNumber($row['external_points']) }}</span></td>
<td class="text-right font-weight-bold" data-sort-value="{{ $row['total_points'] }}">{{ \App\Services\Util::formatNumber($row['total_points']) }}</td>
@elseif ($details['metric'] === 'new_partners')
<td>{{ ($row['phone'] ?? '') !== '' ? $row['phone'] : '-' }}</td>
<td>{{ $row['sponsor'] ?? '-' }}</td>
<td class="text-right font-weight-bold">{{ \App\Services\Util::formatNumber($row['customer_points'] ?? 0) }}</td>
<td class="text-right font-weight-bold">{{ \App\Services\Util::formatNumber($row['total_points'] ?? 0) }}</td>
<td>{{ $row['active_date'] ?? '-' }}</td>
<td>{{ $row['payment_account'] ?? '-' }}</td>
<td class="text-right font-weight-bold" data-sort-value="{{ $row['customer_points'] ?? 0 }}">{{ \App\Services\Util::formatNumber($row['customer_points'] ?? 0) }}</td>
<td class="text-right font-weight-bold" data-sort-value="{{ $row['total_points'] ?? 0 }}">{{ \App\Services\Util::formatNumber($row['total_points'] ?? 0) }}</td>
<td data-sort-value="{{ $row['active_date_sort'] ?? '' }}">{{ $row['active_date'] ?? '-' }}</td>
<td data-sort-value="{{ $row['payment_account_sort'] ?? '' }}">{{ $row['payment_account'] ?? '-' }}</td>
@else
<td>{{ $row['active_date'] ?? '-' }}</td>
<td>
<td data-sort-value="{{ $row['active_date_sort'] ?? '' }}">{{ $row['active_date'] ?? '-' }}</td>
<td data-sort-value="{{ $row['payment_account_sort'] ?? '' }}">
{{ $row['payment_account'] ?? '-' }}
@if (isset($row['is_account_active']))
<span
@ -211,6 +213,7 @@
<td class="text-right" style="background-color:#d4edda;">{{ \App\Services\Util::formatNumber($details['summary']['external_points']) }}</td>
<td class="text-right">{{ \App\Services\Util::formatNumber($details['summary']['total_points']) }}</td>
@elseif ($details['metric'] === 'new_partners')
<td></td>
<td></td>
<td class="text-right">{{ \App\Services\Util::formatNumber($details['summary']['customer_points'] ?? 0) }}</td>
<td class="text-right">{{ \App\Services\Util::formatNumber($details['summary']['total_points'] ?? 0) }}</td>
@ -229,104 +232,9 @@
</div>
@if ($details['rows'] !== [])
<style>
#backoffice-statistics-detail-table {
min-width: 980px;
}
#backoffice-statistics-detail-table th,
#backoffice-statistics-detail-table td {
vertical-align: middle;
}
#backoffice-statistics-detail-table th[data-sortable="true"] {
white-space: nowrap;
}
#backoffice-statistics-detail-table .sortable-label {
align-items: center;
display: inline-flex;
gap: .25rem;
white-space: nowrap;
width: 100%;
}
#backoffice-statistics-detail-table .sort-icon {
color: #adb5bd;
flex: 0 0 auto;
font-size: .875rem;
line-height: 1;
}
#backoffice-statistics-detail-table th[data-sort-direction="asc"] .sort-icon,
#backoffice-statistics-detail-table th[data-sort-direction="desc"] .sort-icon {
color: #4e73df;
}
</style>
<script>
$(document).ready(function() {
$('#backoffice-statistics-detail-search').on('keyup search', function() {
var search = $(this).val().toLowerCase();
$('#backoffice-statistics-detail-table tbody tr').each(function() {
var rowText = $(this).text().toLowerCase();
$(this).toggle(rowText.indexOf(search) !== -1);
});
});
$('#backoffice-statistics-detail-table th[data-sortable="true"]').css('cursor', 'pointer').on('click',
function() {
var $header = $(this);
var columnIndex = $header.index();
var sortType = $header.data('sort-type') || 'text';
var direction = $header.data('sort-direction') === 'asc' ? 'desc' : 'asc';
var rows = $('#backoffice-statistics-detail-table tbody tr').get();
rows.sort(function(a, b) {
var aValue = getSortValue($(a).children('td').eq(columnIndex).text(), sortType);
var bValue = getSortValue($(b).children('td').eq(columnIndex).text(), sortType);
if (aValue < bValue) {
return direction === 'asc' ? -1 : 1;
}
if (aValue > bValue) {
return direction === 'asc' ? 1 : -1;
}
return 0;
});
$('#backoffice-statistics-detail-table th[data-sortable="true"]')
.removeData('sort-direction')
.removeAttr('data-sort-direction');
$header.data('sort-direction', direction).attr('data-sort-direction', direction);
$.each(rows, function(index, row) {
$('#backoffice-statistics-detail-table tbody').append(row);
});
});
function getSortValue(value, sortType) {
value = $.trim(value);
if (sortType === 'number') {
return parseFloat(value.replace(/\./g, '').replace(',', '.').replace(/[^\d.-]/g, '')) || 0;
}
if (sortType === 'date') {
var parts = value.match(/(\d{2})\.(\d{2})\.(\d{4})/);
if (!parts) {
return 0;
}
return new Date(parts[3], parts[2] - 1, parts[1]).getTime();
}
return value.toLowerCase();
}
});
</script>
@include('components._sortable_table', [
'tableId' => 'backoffice-statistics-detail-table',
'searchId' => 'backoffice-statistics-detail-search',
])
@endif
@endsection