199 lines
6.7 KiB
PHP
199 lines
6.7 KiB
PHP
<?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";
|
|
?>
|
|
|
|
<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; ?>
|
|
|
|
<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>";
|
|
}
|
|
?>
|
|
|
|
<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>';
|
|
}
|
|
?>
|
|
<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; ?>
|
|
|
|
<br><br>
|
|
<?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
|
|
} elseif ($hasAccess) {
|
|
echo "<h2>Auswertung</h2>";
|
|
echo "<p>Mitarbeiter wurde im aktuellen Mandanten nicht gefunden.</p>";
|
|
} else {
|
|
echo "<h2>Kein Zugriff</h2>";
|
|
}
|
|
?>
|
|
</div>
|
|
</section>
|
|
|
|
<?php include "footer.php"; ?>
|