Die Migration in participants/ledger_entries ist abgeschlossen: kein
Teilnehmer traegt noch eine legacy_mitarbeiter_id, kein Journaleintrag eine
legacy_table. Damit war der jeweils zweite Zweig ("Default-Mandant schreibt
zusaetzlich nach kl_Einzahlungen/kl_Kaffeeverbrauch/kl_Mitarbeiter") in
sechs Dateien nicht mehr erreichbar - er musste aber bei jeder Aenderung
mitgepflegt werden, zuletzt bei der Bemerkung fuer Einzahlungen.
Entfernt:
- Dual-Write beim Buchen: einzahlung.php, stricheintragen.php, index.php,
jahresauswertung.php, app/imports.php, app/paypal-inbox.php
- Dual-Write in der Mitgliederverwaltung: ledger_create_participant,
ledger_update_participant, ledger_set_participant_active,
ledger_anonymize_participant
- die verwaisten Spiegelfunktionen ledger_mirror_legacy_payment,
ledger_mirror_legacy_consumption und ledger_void_entry_by_legacy_id
Nebenbei behoben: kaffeeliste.php hat die Teilnehmer-Detailseite nur fuer
Mitglieder mit legacy_mitarbeiter_id verlinkt - die hat seit der Migration
niemand mehr, die Seite war also fuer alle unerreichbar. Verlinkt und
adressiert wird jetzt ueber participant_id; "user_id" bleibt als Alias
erhalten. Der Mandanten-Isolationstest prueft jetzt ledger_void_entry, also
den Pfad, den letzteneintraege.php tatsaechlich nutzt.
Pruefskripte unveraendert gegenueber der Baseline vor dem Umbau
(http-smoke 27/6, role-matrix 55/0); die Isolationspruefung steigt von
9 auf 11 PASS bei gleichem vorbestehendem Fehler.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
180 lines
4.7 KiB
PHP
180 lines
4.7 KiB
PHP
<?php
|
|
|
|
include "functions.php";
|
|
require_once __DIR__ . "/app/ledger.php";
|
|
app_require_csrf();
|
|
include "header.php";
|
|
include "headerline.php";
|
|
include "nav.php";
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<!-- Banner -->
|
|
<section id="banner">
|
|
<div class="content">
|
|
|
|
<?php
|
|
|
|
$pdo = app_db_pdo();
|
|
$saasUser = saas_current_user($pdo);
|
|
$tenantId = 0;
|
|
$hasAccess = false;
|
|
|
|
if ($saasUser !== null && saas_user_has_role(['owner', 'admin', 'treasurer'], $saasUser)) {
|
|
$tenantId = (int)$saasUser['tenant_id'];
|
|
$hasAccess = true;
|
|
}
|
|
|
|
if (!$hasAccess && $saasUser === null && checkKaffeelisteAdmin($conn, $mailadress)) {
|
|
$tenant = ledger_fetch_default_tenant($pdo);
|
|
if ($tenant !== null) {
|
|
$tenantId = (int)$tenant['id'];
|
|
$hasAccess = true;
|
|
}
|
|
}
|
|
|
|
if (!$hasAccess) {
|
|
echo "<h2>Kein Zugriff</h2>";
|
|
include "footer.php";
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Liefert die Teilnehmerliste fuer die Vorder-/Rueckseiten- oder
|
|
* Alle-Auswahl. Vorderseite sind die Vieltrinker (>= 10 Striche im
|
|
* Listenfenster), Rueckseite der Rest.
|
|
*
|
|
* @return list<array>
|
|
*/
|
|
function stricheintragen_fetch_participants(PDO $pdo, int $tenantId, string $action): array
|
|
{
|
|
if ($action === 'vorderseite' || $action === 'rueckseite') {
|
|
$settings = saas_fetch_tenant_settings($pdo, $tenantId);
|
|
$windowDays = $settings['sheet_window_days'] ?? 100;
|
|
|
|
return ledger_fetch_participants_by_window_marks($pdo, $tenantId, $windowDays, $action === 'vorderseite');
|
|
}
|
|
|
|
return ledger_fetch_participant_summaries($pdo, $tenantId, ['active_only' => true]);
|
|
}
|
|
|
|
$eingetragen = 0;
|
|
$fehlgeschlagen = false;
|
|
$hatGespeichert = false;
|
|
|
|
// Verarbeitung des Formulars, wenn es gesendet wurde
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$hatGespeichert = true;
|
|
$kostenproStrich = floatval($_POST["kostenproStrich"] ?? 0);
|
|
$unitPriceCents = (int)round($kostenproStrich * 100);
|
|
|
|
// Teilnehmer des Mandanten - dient der Zugehoerigkeitspruefung, damit ueber
|
|
// das Formular keine fremden IDs bebucht werden koennen.
|
|
$eigeneTeilnehmer = [];
|
|
$stmt = $pdo->prepare('SELECT id FROM participants WHERE tenant_id = ?');
|
|
$stmt->execute([$tenantId]);
|
|
foreach ($stmt->fetchAll(PDO::FETCH_COLUMN) as $id) {
|
|
$eigeneTeilnehmer[(int)$id] = true;
|
|
}
|
|
|
|
try {
|
|
$pdo->beginTransaction();
|
|
|
|
foreach ($_POST["anzahlStriche"] ?? [] as $participantId => $anzahlStriche) {
|
|
$participantId = (int)$participantId;
|
|
$anzahlStriche = (int)$anzahlStriche;
|
|
if ($participantId <= 0 || $anzahlStriche === 0 || !isset($eigeneTeilnehmer[$participantId])) {
|
|
continue;
|
|
}
|
|
|
|
ledger_record_consumption($pdo, $tenantId, $participantId, $anzahlStriche, $unitPriceCents, 'manual_bulk');
|
|
$eingetragen++;
|
|
}
|
|
|
|
$pdo->commit();
|
|
} catch (Throwable $e) {
|
|
if ($pdo->inTransaction()) {
|
|
$pdo->rollBack();
|
|
}
|
|
$fehlgeschlagen = true;
|
|
}
|
|
|
|
$action = 'alle';
|
|
} else {
|
|
$action = (string)($_GET['action'] ?? 'alle');
|
|
}
|
|
|
|
$mitarbeiter = stricheintragen_fetch_participants($pdo, $tenantId, $action);
|
|
$settings = saas_fetch_tenant_settings($pdo, $tenantId);
|
|
$kostenproStrichAnzeige = number_format(($settings['mark_price_cents'] ?? 20) / 100, 2, '.', '');
|
|
|
|
?>
|
|
|
|
<h2>Anzahl der Striche für alle Mitarbeiter</h2>
|
|
|
|
<?php if ($hatGespeichert): ?>
|
|
<?php if ($fehlgeschlagen): ?>
|
|
<div class="hint-box error"><p>Die Einträge konnten nicht gespeichert werden.</p></div>
|
|
<?php else: ?>
|
|
<div class="hint-box success"><p><?php echo (int)$eingetragen; ?> Einträge erfolgreich hinzugefügt.</p></div>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
|
|
<ul class="actions">
|
|
<li>
|
|
<form action="stricheintragen.php" method="get">
|
|
<input type="hidden" name="action" value="vorderseite">
|
|
<button type="submit">Vorderseite</button>
|
|
</form>
|
|
</li>
|
|
<li>
|
|
<form action="stricheintragen.php" method="get">
|
|
<input type="hidden" name="action" value="rueckseite">
|
|
<button type="submit">Rückseite</button>
|
|
</form>
|
|
</li>
|
|
<li>
|
|
<form action="stricheintragen.php" method="get">
|
|
<input type="hidden" name="action" value="alle">
|
|
<button type="submit">Alle</button>
|
|
</form>
|
|
</li>
|
|
</ul>
|
|
|
|
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
|
|
<?php echo app_csrf_field(); ?>
|
|
<?php
|
|
|
|
echo "<label for='kostenproStrich'>Kosten pro Strich:</label>
|
|
<input type='number' name='kostenproStrich' step='0.01' value='" . saas_html($kostenproStrichAnzeige) . "'><br>";
|
|
|
|
echo "<table>";
|
|
echo " <tr>
|
|
<th>Mitarbeiter</th>
|
|
<th>Anzahl Striche</th>
|
|
</tr>";
|
|
|
|
foreach ($mitarbeiter as $teilnehmer) {
|
|
$participantId = $teilnehmer['participant_id'];
|
|
$name = saas_html($teilnehmer['display_name']);
|
|
echo "<tr>";
|
|
echo "<td><label for='anzahlStriche[$participantId]'>$name:</label></td>";
|
|
echo "<td><input type='number' name='anzahlStriche[$participantId]' ></td>";
|
|
echo "</tr>";
|
|
}
|
|
echo "</table>";
|
|
|
|
?>
|
|
|
|
<button type="submit">Eintragen</button>
|
|
</form>
|
|
|
|
</div>
|
|
</section>
|
|
|
|
<?php include "footer.php"; ?>
|