Überarbeitung landing und index
This commit is contained in:
@@ -38,11 +38,25 @@ if (!$hasAccess && checkKaffeelisteAccess($conn, $mailadress)) {
|
||||
}
|
||||
|
||||
$participant = null;
|
||||
if ($hasAccess && $emailNorm !== '') {
|
||||
$summaries = ledger_fetch_participant_summaries($pdo, $tenantId, [
|
||||
'email_norms' => [$emailNorm],
|
||||
]);
|
||||
$participant = $summaries[0] ?? null;
|
||||
if ($hasAccess) {
|
||||
// Eingeloggte SaaS-Nutzer werden primaer ueber die feste user_id-
|
||||
// Verknuepfung ihres Teilnehmers gefunden (bei Registrierung bzw.
|
||||
// Zugangsvergabe gesetzt) - robuster als der E-Mail-Abgleich, der bei
|
||||
// abweichender oder geleerter Teilnehmer-E-Mail ins Leere liefe. Der
|
||||
// Legacy-/Dev-Pfad ohne SaaS-User faellt weiterhin auf die E-Mail zurueck.
|
||||
$saasUserId = $saasUser !== null ? (int)$saasUser['user_id'] : 0;
|
||||
if ($saasUserId > 0) {
|
||||
$summaries = ledger_fetch_participant_summaries($pdo, $tenantId, [
|
||||
'user_ids' => [$saasUserId],
|
||||
]);
|
||||
$participant = $summaries[0] ?? null;
|
||||
}
|
||||
if ($participant === null && $emailNorm !== '') {
|
||||
$summaries = ledger_fetch_participant_summaries($pdo, $tenantId, [
|
||||
'email_norms' => [$emailNorm],
|
||||
]);
|
||||
$participant = $summaries[0] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
$settings = $hasAccess ? saas_fetch_tenant_settings($pdo, $tenantId) : null;
|
||||
@@ -86,15 +100,8 @@ function dashboard_paypal_action(string $template, string $amount): string
|
||||
/**
|
||||
* @return array{ok: bool, message?: string, error?: string}
|
||||
*/
|
||||
function dashboard_record_legacy_self_entry(PDO $pdo, array $participant, array $settings, mixed $marksValue): array
|
||||
function dashboard_record_self_entry(PDO $pdo, array $participant, array $settings, mixed $marksValue, ?int $actorUserId): array
|
||||
{
|
||||
$legacyMitarbeiterId = $participant['legacy_mitarbeiter_id'] !== null
|
||||
? (int)$participant['legacy_mitarbeiter_id']
|
||||
: 0;
|
||||
if ($legacyMitarbeiterId <= 0) {
|
||||
return ['ok' => false, 'error' => 'Für diesen Teilnehmer ist die eigene Stricherfassung noch nicht verfügbar.'];
|
||||
}
|
||||
|
||||
if ((int)$settings['self_entry_enabled'] !== 1) {
|
||||
return ['ok' => false, 'error' => 'Die eigene Stricherfassung ist aktuell deaktiviert.'];
|
||||
}
|
||||
@@ -109,25 +116,48 @@ function dashboard_record_legacy_self_entry(PDO $pdo, array $participant, array
|
||||
return ['ok' => false, 'error' => 'Der Preis pro Strich ist nicht gültig konfiguriert.'];
|
||||
}
|
||||
|
||||
$bookedAt = date('Y-m-d H:i:s');
|
||||
$cost = (($marks * $unitPriceCents) / 100);
|
||||
$unitPrice = ($unitPriceCents / 100);
|
||||
$legacyMitarbeiterId = $participant['legacy_mitarbeiter_id'] !== null
|
||||
? (int)$participant['legacy_mitarbeiter_id']
|
||||
: 0;
|
||||
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
$stmt = $pdo->prepare(
|
||||
'INSERT INTO kl_Kaffeeverbrauch
|
||||
(MitarbeiterID, AnzahlStriche, Kosten, KostenproStrich, Datum, Eintragsart)
|
||||
VALUES (?, ?, ?, ?, ?, 2)'
|
||||
);
|
||||
$stmt->execute([$legacyMitarbeiterId, $marks, $cost, $unitPrice, $bookedAt]);
|
||||
$legacyConsumptionId = (int)$pdo->lastInsertId();
|
||||
if ($legacyConsumptionId <= 0) {
|
||||
throw new RuntimeException('Legacy-Strich konnte nicht angelegt werden.');
|
||||
}
|
||||
if ($legacyMitarbeiterId > 0) {
|
||||
// Migrierter Default-Mandant: weiterhin in die Legacy-Tabelle
|
||||
// schreiben, damit die noch-legacy Sammelseiten (stricheintragen.php)
|
||||
// den Eintrag ebenfalls sehen; der Ledger-Eintrag entsteht per
|
||||
// Spiegelung.
|
||||
$bookedAt = date('Y-m-d H:i:s');
|
||||
$cost = (($marks * $unitPriceCents) / 100);
|
||||
$unitPrice = ($unitPriceCents / 100);
|
||||
|
||||
ledger_mirror_legacy_consumption($pdo, (int)$participant['tenant_id'], $legacyConsumptionId);
|
||||
$pdo->commit();
|
||||
$pdo->beginTransaction();
|
||||
$stmt = $pdo->prepare(
|
||||
'INSERT INTO kl_Kaffeeverbrauch
|
||||
(MitarbeiterID, AnzahlStriche, Kosten, KostenproStrich, Datum, Eintragsart)
|
||||
VALUES (?, ?, ?, ?, ?, 2)'
|
||||
);
|
||||
$stmt->execute([$legacyMitarbeiterId, $marks, $cost, $unitPrice, $bookedAt]);
|
||||
$legacyConsumptionId = (int)$pdo->lastInsertId();
|
||||
if ($legacyConsumptionId <= 0) {
|
||||
throw new RuntimeException('Legacy-Strich konnte nicht angelegt werden.');
|
||||
}
|
||||
|
||||
ledger_mirror_legacy_consumption($pdo, (int)$participant['tenant_id'], $legacyConsumptionId);
|
||||
$pdo->commit();
|
||||
} else {
|
||||
// SaaS-native Mandanten (alle ausser dem migrierten Default-
|
||||
// Mandanten) haben keine Legacy-Schattentabelle - direkt ins
|
||||
// Ledger buchen.
|
||||
ledger_record_consumption(
|
||||
$pdo,
|
||||
(int)$participant['tenant_id'],
|
||||
(int)$participant['participant_id'],
|
||||
$marks,
|
||||
$unitPriceCents,
|
||||
'self_entry',
|
||||
$actorUserId
|
||||
);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
if ($pdo->inTransaction()) {
|
||||
$pdo->rollBack();
|
||||
@@ -174,7 +204,7 @@ function dashboard_render_consumption(array $entries): void
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
if ($hasAccess && $participant !== null && $settings !== null) {
|
||||
$result = dashboard_record_legacy_self_entry($pdo, $participant, $settings, $_POST["anzahlStriche"] ?? null);
|
||||
$result = dashboard_record_self_entry($pdo, $participant, $settings, $_POST["anzahlStriche"] ?? null, $saasUser['user_id'] ?? null);
|
||||
if ($result['ok']) {
|
||||
$entryMessage = $result['message'] ?? null;
|
||||
$participant = ledger_fetch_participant_summary($pdo, $tenantId, (int)$participant['participant_id']);
|
||||
@@ -213,8 +243,7 @@ if ($hasAccess && $participant !== null && $settings !== null) {
|
||||
$balanceCents = (int)$participant['balance_cents'];
|
||||
$balance = dashboard_money($balanceCents);
|
||||
$currentName = dashboard_current_name($saasUser, $participant, $conn, $mailadress);
|
||||
$selfEntryEnabled = (int)$settings['self_entry_enabled'] === 1
|
||||
&& $participant['legacy_mitarbeiter_id'] !== null;
|
||||
$selfEntryEnabled = (int)$settings['self_entry_enabled'] === 1;
|
||||
$paypalEnabled = (int)$settings['paypal_enabled'] === 1
|
||||
&& trim((string)$settings['paypal_url_template']) !== '';
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user