Teilnehmerauswertung auf Ledger-Lesemodell umstellen

This commit is contained in:
2026-07-14 22:21:28 +02:00
parent 539117b409
commit 8688cc78db
8 changed files with 284 additions and 217 deletions
+63
View File
@@ -41,6 +41,44 @@ function ledger_current_year(): int
return (int)date('Y');
}
function ledger_default_tenant_slug(): string
{
$tenantSlug = app_env('M4_DEFAULT_TENANT_SLUG');
if ($tenantSlug === null || trim($tenantSlug) === '') {
$tenantSlug = app_env('M3_DEFAULT_TENANT_SLUG', 'default');
}
return trim((string)$tenantSlug) !== '' ? trim((string)$tenantSlug) : 'default';
}
/**
* @return array{id: int, name: string, slug: string}|null
*/
function ledger_fetch_tenant_by_slug(PDO $pdo, string $slug): ?array
{
$stmt = $pdo->prepare('SELECT id, name, slug FROM tenants WHERE slug = ? LIMIT 1');
$stmt->execute([trim($slug)]);
$tenant = $stmt->fetch();
if ($tenant === false) {
return null;
}
return [
'id' => (int)$tenant['id'],
'name' => (string)$tenant['name'],
'slug' => (string)$tenant['slug'],
];
}
/**
* @return array{id: int, name: string, slug: string}|null
*/
function ledger_fetch_default_tenant(PDO $pdo): ?array
{
return ledger_fetch_tenant_by_slug($pdo, ledger_default_tenant_slug());
}
/**
* @return array{total_payments_cents: int, total_costs_cents: int, total_marks: int, balance_cents: int, year_payments_cents: int, year_costs_cents: int, year_marks: int}
*/
@@ -99,6 +137,7 @@ function ledger_fetch_tenant_totals(PDO $pdo, int $tenantId, ?int $year = null):
* - year: int
* - active_only: bool|null
* - participant_ids: list<int>
* - legacy_mitarbeiter_ids: list<int>
* - email_norms: list<string>
*
* @return list<array{participant_id: int, tenant_id: int, legacy_mitarbeiter_id: ?int, display_name: string, email: ?string, email_norm: ?string, paypal_name: ?string, active: bool, total_payments_cents: int, total_costs_cents: int, total_marks: int, balance_cents: int, year_payments_cents: int, year_costs_cents: int, year_marks: int}>
@@ -125,6 +164,17 @@ function ledger_fetch_participant_summaries(PDO $pdo, int $tenantId, array $opti
array_push($params, ...$participantIds);
}
if (array_key_exists('legacy_mitarbeiter_ids', $options)) {
$legacyIds = is_array($options['legacy_mitarbeiter_ids'])
? ledger_normalize_ids($options['legacy_mitarbeiter_ids'])
: [];
if ($legacyIds === []) {
return [];
}
$where[] = 'p.legacy_mitarbeiter_id IN (' . implode(',', array_fill(0, count($legacyIds), '?')) . ')';
array_push($params, ...$legacyIds);
}
if (array_key_exists('email_norms', $options)) {
$emailNorms = is_array($options['email_norms'])
? ledger_normalize_email_norms($options['email_norms'])
@@ -202,6 +252,19 @@ function ledger_fetch_participant_summary(PDO $pdo, int $tenantId, int $particip
return $summaries[0] ?? null;
}
/**
* @return array{participant_id: int, tenant_id: int, legacy_mitarbeiter_id: ?int, display_name: string, email: ?string, email_norm: ?string, paypal_name: ?string, active: bool, total_payments_cents: int, total_costs_cents: int, total_marks: int, balance_cents: int, year_payments_cents: int, year_costs_cents: int, year_marks: int}|null
*/
function ledger_fetch_participant_summary_by_legacy_id(PDO $pdo, int $tenantId, int $legacyMitarbeiterId, ?int $year = null): ?array
{
$summaries = ledger_fetch_participant_summaries($pdo, $tenantId, [
'legacy_mitarbeiter_ids' => [$legacyMitarbeiterId],
'year' => $year ?? ledger_current_year(),
]);
return $summaries[0] ?? null;
}
/**
* Options:
* - participant_id: int
+1 -1
View File
@@ -151,7 +151,7 @@ Installation aus `.local/` verwendet werden.
## Aktueller Prüfstatus
- M4 Ledger-Migration: grün mit 73 Assertions.
- M4 Ledger-Service: grün mit 110 Assertions.
- M4 Ledger-Service: grün mit 115 Assertions.
- M3 SaaS-Basis: weiterhin grün.
- M3 Tenant-Auflösung: weiterhin grün.
- M3 Passwort/E-Mail: weiterhin grün.
+23 -5
View File
@@ -13,15 +13,16 @@ Darstellung gegen die bestehende Legacy-Oberfläche vergleichbar bleiben.
- Schreibende Legacy-Flows erst nach stabiler Leseparität umstellen.
- Tenant-Kontext serverseitig bestimmen, nicht aus Formularfeldern.
## Umgesetzter erster Schritt
## Umgesetzte Schritte
Umgesetzte Datei:
Umgesetzte Dateien:
```text
kaffeeliste.php
teilnehmerauswertung.php
```
Umgesetzter Umfang:
Umgesetzter Umfang `kaffeeliste.php`:
- Die Gesamtübersicht liest aktive Teilnehmer aus
`ledger_fetch_participant_summaries()`.
@@ -36,9 +37,26 @@ Umgesetzter Umfang:
Ledger-Leseansichten sind für passende SaaS-Rollen sichtbar.
- Export, letzte Einträge, CSV-Upload und Info-Mail bleiben noch Legacy-Flows.
Umgesetzter Umfang `teilnehmerauswertung.php`:
- Die Detailauswertung liest Teilnehmerdaten über
`ledger_fetch_participant_summary_by_legacy_id()`.
- Die Route bleibt kompatibel zu bestehenden Links:
`teilnehmerauswertung.php?user_id=<legacy_mitarbeiter_id>`.
- Gesamtwerte, Jahresübersicht und letzte Buchungen werden aus
`ledger_entries` geladen.
- PayPal-Anzeige nutzt die neuen Tenant-Settings statt `kl_config`.
- Owner, Admin und Treasurer dürfen die SaaS-Ansicht lesen; der lokale
Legacy-/Dev-Admin-Fallback nutzt weiterhin den Default-Tenant.
Ergänzte Ledger-Helfer:
- `ledger_fetch_default_tenant()`
- `ledger_fetch_participant_summary_by_legacy_id()`
- Filter `legacy_mitarbeiter_ids` in `ledger_fetch_participant_summaries()`
## Noch offen
- `teilnehmerauswertung.php` lesend auf Ledger umstellen.
- `index.php` Dashboard lesend auf Ledger umstellen.
- Schreibseiten `stricheintragen.php` und `einzahlung.php` erst danach mit
Storno-/Reversal-Strategie vorbereiten.
@@ -47,6 +65,6 @@ Umgesetzter Umfang:
## Aktueller Prüfstatus
- M4 Ledger-Migration: grün mit 73 Assertions.
- M4 Ledger-Service: grün mit 110 Assertions.
- M4 Ledger-Service: grün mit 115 Assertions.
- Golden Master: grün mit 104 Assertions.
- HTTP-Smoke: grün mit 23 geprüften Seiten.
+2
View File
@@ -511,6 +511,8 @@ Schritte:
- Mitgliederverwaltung tenant- und rollenbasiert umsetzen.
- Gesamtübersicht umsetzen: erster read-only Stand in `kaffeeliste.php`
erledigt.
- Teilnehmerauswertung umsetzen: read-only Stand in `teilnehmerauswertung.php`
erledigt.
- Letzte Einträge und Korrekturen als Storno statt Delete umsetzen.
- Hinweise als tenant-spezifische Notices umsetzen.
+1 -18
View File
@@ -8,23 +8,6 @@ $saasUser = saas_current_user($pdo);
$tenantId = 0;
$hasAccess = false;
function kaffeeliste_default_tenant(PDO $pdo): ?array
{
$tenantSlug = getenv('M4_DEFAULT_TENANT_SLUG');
if ($tenantSlug === false || trim($tenantSlug) === '') {
$tenantSlug = getenv('M3_DEFAULT_TENANT_SLUG');
}
$tenantSlug = $tenantSlug !== false && trim($tenantSlug) !== ''
? trim($tenantSlug)
: 'default';
$stmt = $pdo->prepare('SELECT id, name, slug FROM tenants WHERE slug = ? LIMIT 1');
$stmt->execute([$tenantSlug]);
$tenant = $stmt->fetch();
return $tenant !== false ? $tenant : null;
}
function kaffeeliste_money(int $cents): string
{
return saas_format_money_cents($cents) . ' €';
@@ -36,7 +19,7 @@ if ($saasUser !== null && saas_user_has_role(['owner', 'admin', 'treasurer'], $s
}
if (!$hasAccess && $saasUser === null && checkKaffeelisteAdmin($conn, $mailadress)) {
$tenant = kaffeeliste_default_tenant($pdo);
$tenant = ledger_fetch_default_tenant($pdo);
if ($tenant !== null) {
$tenantId = (int)$tenant['id'];
$hasAccess = true;
+16
View File
@@ -148,6 +148,18 @@ if ($paypalSummary !== null) {
m4_service_assert_equal('ledger service single participant balance', 650, $singleSummary['balance_cents'], $failures, $passes);
}
$legacySummary = ledger_fetch_participant_summary_by_legacy_id(
$pdo,
$tenantId,
(int)$paypalSummary['legacy_mitarbeiter_id'],
gm_current_year()
);
m4_service_assert('ledger service legacy participant summary is present', $legacySummary !== null, $failures, $passes);
if ($legacySummary !== null) {
m4_service_assert_equal('ledger service legacy participant id matches', $paypalSummary['participant_id'], $legacySummary['participant_id'], $failures, $passes);
m4_service_assert_equal('ledger service legacy participant balance', 650, $legacySummary['balance_cents'], $failures, $passes);
}
$paypalEntries = ledger_fetch_recent_entries($pdo, $tenantId, [
'participant_id' => $paypalSummary['participant_id'],
'limit' => 100,
@@ -181,6 +193,10 @@ m4_service_assert_equal('ledger service consumption entry count', $legacyConsump
m4_service_assert_equal('ledger service empty participant id filter', [], ledger_fetch_participant_summaries($pdo, $tenantId, [
'participant_ids' => [],
]), $failures, $passes);
m4_service_assert_equal('ledger service empty legacy id filter', [], ledger_fetch_participant_summaries($pdo, $tenantId, [
'legacy_mitarbeiter_ids' => [],
]), $failures, $passes);
m4_service_assert_equal('ledger service unknown legacy summary', null, ledger_fetch_participant_summary_by_legacy_id($pdo, $tenantId, 0), $failures, $passes);
m4_service_assert_equal('ledger service unknown tenant summaries', [], ledger_fetch_participant_summaries($pdo, 0), $failures, $passes);
m4_service_assert_equal('ledger service unknown tenant entries', [], ledger_fetch_recent_entries($pdo, 0), $failures, $passes);
m4_service_assert_equal('ledger service unknown tenant totals', ledger_empty_totals(), ledger_fetch_tenant_totals($pdo, 0), $failures, $passes);
+1 -1
View File
@@ -115,7 +115,7 @@ $checks = [
[
'label' => 'Teilnehmerauswertung',
'path' => 'teilnehmerauswertung.php?user_id=1',
'contains' => ['Auswertung', 'Test Admin'],
'contains' => ['Auswertung', 'Test Admin', 'Jahresübersicht', 'Letzte Einzahlungen'],
],
[
'label' => 'Mailausgabe',
+177 -192
View File
@@ -1,213 +1,198 @@
<?php
include "functions.php";
require_once __DIR__ . "/app/ledger.php";
$legacyUserId = filter_input(INPUT_GET, 'user_id', FILTER_VALIDATE_INT);
if ($legacyUserId === null) {
http_response_code(400);
exit('Fehlender Parameter');
}
if ($legacyUserId === false || $legacyUserId <= 0) {
http_response_code(400);
exit('Ungültige Benutzer-ID');
}
$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;
}
}
$participant = $hasAccess
? ledger_fetch_participant_summary_by_legacy_id($pdo, $tenantId, $legacyUserId)
: null;
$settings = $hasAccess ? saas_fetch_tenant_settings($pdo, $tenantId) : null;
$paymentEntries = $participant !== null
? ledger_fetch_recent_entries($pdo, $tenantId, [
'participant_id' => $participant['participant_id'],
'type' => 'payment',
'limit' => 100,
])
: [];
$consumptionEntries = $participant !== null
? ledger_fetch_recent_entries($pdo, $tenantId, [
'participant_id' => $participant['participant_id'],
'type' => 'consumption',
'limit' => 100,
])
: [];
function teilnehmerauswertung_money(int $cents): string
{
return saas_format_money_cents($cents) . ' €';
}
function teilnehmerauswertung_date(string $value): string
{
try {
return (new DateTimeImmutable($value))->format('d.m.Y');
} catch (Throwable $e) {
return $value;
}
}
function teilnehmerauswertung_current_name(?array $saasUser, mixed $conn, string $mailadress): string
{
$name = trim((string)($saasUser['display_name'] ?? ''));
if ($name !== '') {
return $name;
}
return trim((string)getUserName($conn, $mailadress));
}
function teilnehmerauswertung_paypal_action(string $template, string $amount): string
{
return trim($template) . $amount;
}
function teilnehmerauswertung_render_payments(array $entries): void
{
echo "<h4>Letzte Einzahlungen</h4>";
echo "<table><tr><th style='width:120px'>Datum</th><th>Einzahlung</th></tr>";
if ($entries === []) {
echo "<tr><td colspan='2'>Keine Einzahlungen vorhanden.</td></tr>";
}
foreach ($entries as $entry) {
echo "<tr>";
echo "<td>" . saas_html(teilnehmerauswertung_date((string)$entry['booked_at'])) . "</td>";
echo "<td>" . saas_html(teilnehmerauswertung_money((int)$entry['amount_cents'])) . "</td>";
echo "</tr>";
}
echo "</table>";
}
function teilnehmerauswertung_render_consumption(array $entries): void
{
echo "<h4>Letzte Striche</h4>";
echo "<table><tr><th style='width:120px'>Datum</th><th>Striche</th><th>Kosten</th></tr>";
if ($entries === []) {
echo "<tr><td colspan='3'>Keine Striche vorhanden.</td></tr>";
}
foreach ($entries as $entry) {
echo "<tr>";
echo "<td>" . saas_html(teilnehmerauswertung_date((string)$entry['booked_at'])) . "</td>";
echo "<td>" . number_format((int)($entry['marks_count'] ?? 0), 0, ',', '.') . "</td>";
echo "<td>" . saas_html(teilnehmerauswertung_money(abs((int)$entry['amount_cents']))) . "</td>";
echo "</tr>";
}
echo "</table>";
}
include "header.php";
include "headerline.php";
include "nav.php";
?>
<!-- Banner -->
<section id="banner">
<div class="content">
<section id="banner">
<div class="content">
<?php
if ($hasAccess && $participant !== null) {
$balanceCents = (int)$participant['balance_cents'];
$balance = teilnehmerauswertung_money($balanceCents);
$currentName = teilnehmerauswertung_current_name($saasUser, $conn, $mailadress);
$paypalEnabled = $settings !== null
&& (int)$settings['paypal_enabled'] === 1
&& trim((string)$settings['paypal_url_template']) !== '';
?>
<h2>Auswertung</h2>
<?php if ($currentName !== ''): ?>
Hallo <?php echo saas_html($currentName); ?>!<br><br>
<?php endif; ?>
if(checkKaffeelisteAdmin($conn, $mailadress)){
// Sichere Entgegennahme
$userId = filter_input(INPUT_GET, 'user_id', FILTER_VALIDATE_INT);
if ($userId === null) {
http_response_code(400);
exit('Fehlender Parameter');
<h2>Gesamtausgabe und Gesamtstriche</h2>
<p>Name: <?php echo saas_html($participant['display_name']); ?></p>
<p>E-Mail: <?php echo saas_html((string)($participant['email'] ?? '')); ?></p>
Gesamtausgabe: <?php echo saas_html(teilnehmerauswertung_money((int)$participant['total_costs_cents'])); ?><br>
Gesamtstriche: <?php echo number_format((int)$participant['total_marks'], 0, ',', '.'); ?><br>
<p>Gesamteinzahlung: <?php echo saas_html(teilnehmerauswertung_money((int)$participant['total_payments_cents'])); ?></p>
<?php
if ($balanceCents > 0) {
echo "<p><b>Aktueller Stand: " . saas_html($balance) . " (Guthaben)</b></p>";
} elseif ($balanceCents < 0) {
echo "<p><b>Aktueller Stand: " . saas_html($balance) . " (Schulden)</b></p>";
} else {
echo "<p><b>Aktueller Stand: " . saas_html($balance) . "</b></p>";
}
if ($userId === false) {
http_response_code(400);
exit('Ungültige Benutzer-ID');
?>
<h2>Jahresübersicht</h2>
Ausgabe im aktuellen Jahr: <?php echo saas_html(teilnehmerauswertung_money((int)$participant['year_costs_cents'])); ?><br>
Gesamtstriche im aktuellen Jahr: <?php echo number_format((int)$participant['year_marks'], 0, ',', '.'); ?><br>
<p>Gesamteinzahlung im aktuellen Jahr: <?php echo saas_html(teilnehmerauswertung_money((int)$participant['year_payments_cents'])); ?></p>
<?php if ($paypalEnabled): ?>
<h2>PayPal-Einzahlungen</h2>
<b>Bezahle immer über die Freunde-Funktion von PayPal. Ansonsten stellen wir 20% des Betrags als Gebühr in Rechnung.</b><br>
<br>
<?php
$paypalTemplate = trim((string)$settings['paypal_url_template']);
if ($balanceCents < 0) {
$debtCents = abs($balanceCents);
$debtAmount = teilnehmerauswertung_money($debtCents);
echo '<form action="' . saas_html(teilnehmerauswertung_paypal_action($paypalTemplate, saas_format_money_cents($debtCents))) . '" target="_blank"><button type="submit">' . saas_html($debtAmount) . ' bezahlen</button></form>';
}
echo "<h2>Auswertung</h2>";
echo "Hallo " . getUserName($conn,$mailadress) . "!<br><br>";
// Funktion zum Berechnen der Gesamtausgabe und Gesamtstriche pro Mitarbeiter
function berechneGesamtausgabe($email, $conn) {
// MitarbeiterID anhand der E-Mail-Adresse abrufen
$sqlMitarbeiterID = "SELECT MitarbeiterID FROM kl_Mitarbeiter WHERE Email = ?";
$stmtMitarbeiterID = sqlsrv_query($conn, $sqlMitarbeiterID, array($email));
$rowMitarbeiterID = sqlsrv_fetch_array($stmtMitarbeiterID, SQLSRV_FETCH_ASSOC);
?>
<ul class="actions">
<li><form action="<?php echo saas_html(teilnehmerauswertung_paypal_action($paypalTemplate, '5')); ?>" target="_blank"><button type="submit">5,00 € einzahlen</button></form></li>
<li><form action="<?php echo saas_html(teilnehmerauswertung_paypal_action($paypalTemplate, '10')); ?>" target="_blank"><button type="submit">10,00 € einzahlen</button></form></li>
<li><form action="<?php echo saas_html(teilnehmerauswertung_paypal_action($paypalTemplate, '15')); ?>" target="_blank"><button type="submit">15,00 € einzahlen</button></form></li>
</ul>
<?php endif; ?>
if (!$rowMitarbeiterID) {
return null; // Mitarbeiter nicht gefunden
}
$mitarbeiterID = $rowMitarbeiterID["MitarbeiterID"];
// Gesamteinzahlung pro Mitarbeiter
$sqleinzahlung = "SELECT SUM(Betrag) AS Gesamteinzahlung FROM kl_Einzahlungen WHERE MitarbeiterID = ?";
$stmteinzahlung = sqlsrv_query($conn, $sqleinzahlung, array($mitarbeiterID));
$roweinzahlung = sqlsrv_fetch_array($stmteinzahlung, SQLSRV_FETCH_ASSOC);
$gesamteinzahlung = $roweinzahlung['Gesamteinzahlung'];
// Gesamtausgabe für Kaffeeverbrauch pro Mitarbeiter
$sqlAusgabe = "SELECT SUM(AnzahlStriche) AS Gesamtstriche, SUM(Kosten) AS Gesamtausgabe FROM kl_Kaffeeverbrauch WHERE MitarbeiterID = ?";
$stmtAusgabe = sqlsrv_query($conn, $sqlAusgabe, array($mitarbeiterID));
$rowAusgabe = sqlsrv_fetch_array($stmtAusgabe, SQLSRV_FETCH_ASSOC);
$gesamtausgabe = $rowAusgabe['Gesamtausgabe'];
$gesamtstriche = $rowAusgabe['Gesamtstriche'];
$aktuellerStand = $gesamteinzahlung - $gesamtausgabe;
// Gesamteinzahlung pro Mitarbeiter und Aktuellem Jahr
$sqleinzahlung = "SELECT SUM(Betrag) AS Gesamteinzahlung FROM kl_Einzahlungen WHERE MitarbeiterID = ? AND FORMAT(Datum, 'yyyy') = FORMAT(GETDATE(), 'yyyy') ";
$stmteinzahlung = sqlsrv_query($conn, $sqleinzahlung, array($mitarbeiterID));
$roweinzahlung = sqlsrv_fetch_array($stmteinzahlung, SQLSRV_FETCH_ASSOC);
$yeareinzahlung = $roweinzahlung['Gesamteinzahlung'];
// Gesamtausgabe für Kaffeeverbrauch pro Mitarbeiter und Aktuellem Jahr
$sqlAusgabe = "SELECT SUM(AnzahlStriche) AS Gesamtstriche, SUM(Kosten) AS Gesamtausgabe FROM kl_Kaffeeverbrauch WHERE MitarbeiterID = ? AND FORMAT(Datum, 'yyyy') = FORMAT(GETDATE(), 'yyyy')";
$stmtAusgabe = sqlsrv_query($conn, $sqlAusgabe, array($mitarbeiterID));
$rowAusgabe = sqlsrv_fetch_array($stmtAusgabe, SQLSRV_FETCH_ASSOC);
$yearausgabe = $rowAusgabe['Gesamtausgabe'];
$yearstriche = $rowAusgabe['Gesamtstriche'];
return array('Jahresausgabe' => $yearausgabe, 'Jahresstriche' => $yearstriche, 'Jahreseinzahlung' => $yeareinzahlung, 'Gesamtausgabe' => $gesamtausgabe, 'Gesamtstriche' => $gesamtstriche, 'Gesamteinzahlung' => $gesamteinzahlung, 'aktuellerStand' => $aktuellerStand);
#return array('Gesamtausgabe' => $gesamtausgabe, 'Gesamtstriche' => $gesamtstriche, 'Gesamteinzahlung' => $gesamteinzahlung, 'aktuellerStand' => $aktuellerStand);
}
function AusgabeletztenEinzahlungen($email, $conn) {
// MitarbeiterID anhand der E-Mail-Adresse abrufen
$sqlMitarbeiterID = "SELECT TOP 20 MitarbeiterID FROM kl_Mitarbeiter WHERE Email = ?";
$stmtMitarbeiterID = sqlsrv_query($conn, $sqlMitarbeiterID, array($email));
$rowMitarbeiterID = sqlsrv_fetch_array($stmtMitarbeiterID, SQLSRV_FETCH_ASSOC);
if (!$rowMitarbeiterID) {
return null; // Mitarbeiter nicht gefunden
}
$mitarbeiterID = $rowMitarbeiterID["MitarbeiterID"];
// Gesamteinzahlung pro Mitarbeiter
$sqleinzahlung = "SELECT Betrag,Datum FROM kl_Einzahlungen WHERE MitarbeiterID = ? ORDER BY Datum DESC ";
$stmteinzahlung = sqlsrv_query($conn, $sqleinzahlung, array($mitarbeiterID));
$ausgabe = "<h4>Letzte Einzahlungen</h4><table><tr><th style='width:120'>Datum</th><th>Einzahlung</th></tr>";
while ($row = sqlsrv_fetch_array($stmteinzahlung, SQLSRV_FETCH_ASSOC)) {
$ausgabe .= "<tr><td>" . date_format($row["Datum"],"d.m.Y") . "</td><td>" . number_format($row["Betrag"], 2, ',', '') . "€</td></tr>";
}
$ausgabe .= "</table>";
return $ausgabe;
}
function AusgabeletztenStriche($email, $conn) {
// MitarbeiterID anhand der E-Mail-Adresse abrufen
$sqlMitarbeiterID = "SELECT TOP 20 MitarbeiterID FROM kl_Mitarbeiter WHERE Email = ?";
$stmtMitarbeiterID = sqlsrv_query($conn, $sqlMitarbeiterID, array($email));
$rowMitarbeiterID = sqlsrv_fetch_array($stmtMitarbeiterID, SQLSRV_FETCH_ASSOC);
if (!$rowMitarbeiterID) {
return null; // Mitarbeiter nicht gefunden
}
$mitarbeiterID = $rowMitarbeiterID["MitarbeiterID"];
// Gesamteinzahlung pro Mitarbeiter
$sqleinzahlung = "SELECT AnzahlStriche,Kosten,Datum FROM kl_Kaffeeverbrauch WHERE MitarbeiterID = ? ORDER BY Datum DESC ";
$stmteinzahlung = sqlsrv_query($conn, $sqleinzahlung, array($mitarbeiterID));
$ausgabe = "<h4>Letzte Striche</h4><table ><tr><th style='width:120'>Datum</th><th>Striche</th><th>Kosten</th></tr>";
while ($row = sqlsrv_fetch_array($stmteinzahlung, SQLSRV_FETCH_ASSOC)) {
$ausgabe .= "<tr><td>" . date_format($row["Datum"],"d.m.Y") . "</td><td>" . $row["AnzahlStriche"] . "</td><td>" . number_format($row["Kosten"], 2, ',', '') . "€</td></tr>";
}
$ausgabe .= "</table>";
return $ausgabe;
}
$sqlMitglieder = "SELECT MitarbeiterID, Name, Email FROM kl_Mitarbeiter WHERE MitarbeiterID = $userId";
$stmtMitglieder = sqlsrv_query($conn, $sqlMitglieder);
while ($row = sqlsrv_fetch_array($stmtMitglieder, SQLSRV_FETCH_ASSOC)) {
$mitarbeiterID = $row['MitarbeiterID'];
$name = $row['Name'];
$email = $row['Email'];
}
// Berechne Gesamtausgabe und Gesamtstriche für den Mitarbeiter
$result = berechneGesamtausgabe($email, $conn);
if ($result !== null) {
echo "<h2>Gesamtausgabe und Gesamtstriche</h2>";
echo "<p>Name: $name</p>";
echo "<p>E-Mail: $email</p>";
echo "Gesamtausgabe: " . number_format($result['Gesamtausgabe'], 2, ',', '') . " €<br>";
echo "Gesamtstriche: {$result['Gesamtstriche']}<br>";
echo "<p>Gesamteinzahlung: " . number_format($result['Gesamteinzahlung'], 2, ',', '') . " €<br>";
$aktuellerstand = number_format($result['aktuellerStand'], 2, ',', '.');
if($result['aktuellerStand'] > 0){
echo "<p><b>Aktueller Stand: {$aktuellerstand} € (Guthaben)</p>";
}elseif($result['aktuellerStand'] < 0){
echo "<p><b>Aktueller Stand: {$aktuellerstand} € (Schulden)</p>";
}else{
echo "<p><b>Aktueller Stand: {$aktuellerstand} €</p>";
}
echo "</b>";
echo "<h2>Jahresübersicht</h2>";
echo "Ausgabe im aktuellem Jahr: " . number_format($result['Jahresausgabe'], 2, ',', '') . " €<br>";
echo "Gesamtstriche im aktuellem Jahr: {$result['Jahresstriche']}<br>";
echo "<p>Gesamteinzahlung im aktuellem Jahr: " . number_format($result['Jahreseinzahlung'], 2, ',', '') . " €<br>";
$sqlconfig = "SELECT paypaluse,paypallink FROM kl_config";
$stmtconfig = sqlsrv_query($conn, $sqlconfig, array($email));
$rowconfig = sqlsrv_fetch_array($stmtconfig, SQLSRV_FETCH_ASSOC);
if($rowconfig["paypaluse"] == 1){
echo "<h2>Paypal-Einzahlungen</h2>";
echo '<b>Bezahle immer über die Freunde-Funktion von Paypal. Ansonsten stellen wir 20% des Betrags als Gebühr in Rechnung.</b><br>';
$paypallink = trim($rowconfig["paypallink"]);
echo "<br>";
if($result['aktuellerStand'] < 0){
echo '<form action="' . $paypallink .'' . $aktuellerstand . '" target="_blank" ><button type="submit">'. $aktuellerstand . ' € bezahlen</button></form>';
}
echo'<ul class="actions">
<li>';
echo '<form action="' . $paypallink .'5" target="_blank" ><button type="submit">5,00 € einzahlen</button></form>';
echo '</li><li>';
echo '<form action="' . $paypallink .'10" target="_blank" ><button type="submit">10,00 € einzahlen</button></form>';
echo '</li><li>';
echo '<form action="' . $paypallink .'15" target="_blank" ><button type="submit">15,00 € einzahlen</button></form>';
echo '</li></ul>';
}
echo "<br>";
echo "<br>";
echo AusgabeletztenEinzahlungen($email, $conn);
echo "<br>";
echo AusgabeletztenStriche($email, $conn);
?>
<br><br>
<!-- Formular mit Button zum Anpassen des Namens -->
<?php
teilnehmerauswertung_render_payments($paymentEntries);
echo "<br>";
teilnehmerauswertung_render_consumption($consumptionEntries);
?>
<br><br>
<form action="namenanpassen.php" method="get">
<button type="submit">Namensanpassung</button>
</form>
<?php
} else {
echo "<p>Mitarbeiter mit der E-Mail-Adresse $email wurde nicht gefunden.</p>";
}
}else{
echo "<h2>Sie haben keine Zugang zu dieser Webseite</h2>";
<?php
} elseif ($hasAccess) {
echo "<h2>Auswertung</h2>";
echo "<p>Mitarbeiter wurde im aktuellen Mandanten nicht gefunden.</p>";
} else {
echo "<h2>Kein Zugriff</h2>";
}
?>
</div>
</div>
</section>
<?php include "footer.php";
?>
<?php include "footer.php"; ?>