Haushaltsbuch/konto.php
2025-11-22 09:31:50 +01:00

118 lines
5.1 KiB
PHP

<?php
require_once __DIR__ . '/includes/db_connect.php';
$system = getenv('POSTGRES_SYSTEM') ?? 'test';
$konto_id = $_GET['id'];
$stmt = $pdo->prepare("SELECT id,
kontostand,
darstellungsfarbe AS backgroundcolor,
bezeichnung AS konto
FROM konto
WHERE id = :konto_id;");
$stmt->execute(['konto_id' => $konto_id]);
$konto = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Da nur ein Konto abgefragt wird, sind diese Werte in allen Ergebnissen gleich
$konto_bezeichnung = $konto[0]['konto'];
$konto_kontostand = $konto[0]['kontostand'];
$konto_backgroundColor = $konto[0]['backgroundcolor'];
$stmt = $pdo->prepare("SELECT kb.id AS kontobewegung_id,
kb.betrag,
kb.beschreibung,
kb.datum_ausgegeben,
kb.datum_abgebucht,
kb.kostenfix_id
FROM kontobewegung kb
LEFT OUTER JOIN kostenfix kf ON kf.id = kb.kostenfix_id
WHERE kb.konto_id = :konto_id
ORDER BY datum_ausgegeben DESC,
kb.id DESC;");
$stmt->execute(['konto_id' => $konto_id]);
$kontobewegung = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script>
function ändereUmsatz(kontobewegung_id, konto_id) {
document.getElementById("hiddenInputÄndereUmsatzKontobewegungID").value = kontobewegung_id;
document.getElementById("hiddenInputÄndereUmsatzKontoID").value = konto_id;
document.getElementById("hiddenFormÄndereUmsatz").submit();
}
</script>
<style>
tr.standard {
&>td {
background-color: <?= $konto_backgroundColor ?>;
}
}
</style>
</head>
<body>
<div class="header">
<a href="kontobewegung_neu.php?id=<?= htmlspecialchars($konto_id) ?>"
class="konto_header"
id="konto_navigationLinks">
Neue Kontobewegung
</a>
<?php
if($system == 'test') {
echo '<h2 class="restguthaben">Testsystem</h2>';
}
?>
<h2 class="kontoübersicht" id="h2_kontoübersicht">
<?= htmlspecialchars($konto_bezeichnung) ?>: <?= htmlspecialchars(number_format($konto_kontostand, 2, ",", ".")) ?> €
</h2>
<a href="index.php"
class="konto_header"
id="konto_navigationRechts">
HOME
</a>
</div>
<div class="inhalt">
<table>
<tr>
<th id="th_gebucht">gebucht</th>
<th id="th_ausgegeben">ausgegeben</th>
<th id="th_beschreibung">Beschreibung</th>
<th id="th_betrag">Betrag</th>
</tr>
<?php foreach ($kontobewegung as $y): ?>
<tr <?= $y['kostenfix_id'] ? 'class="konto_fixKosten"' : 'class="standard"' ?>>
<!--tr style="background-color: < ?= $konto_backgroundColor ?>"-->
<td class="td_datum"
onClick="ändereUmsatz(<?= htmlspecialchars($y['kontobewegung_id']) ?>, <?= htmlspecialchars($konto_id) ?>)">
<?= empty($y['datum_abgebucht']) ? '' : htmlspecialchars($y['datum_abgebucht']) ?>
</td>
<td class="td_datum"
onClick="ändereUmsatz(<?= htmlspecialchars($y['kontobewegung_id']) ?>, <?= htmlspecialchars($konto_id) ?>)">
<?= htmlspecialchars($y['datum_ausgegeben']) ?>
</td>
<td class="td_text"
onClick="ändereUmsatz(<?= htmlspecialchars($y['kontobewegung_id']) ?>, <?= htmlspecialchars($konto_id) ?>)">
<?= htmlspecialchars($y['beschreibung']) ?>
</td>
<td class="<?= $y['betrag'] < 0 ? 'td_zahl_neg' : 'td_zahl_pos' ?>"
onClick="ändereUmsatz(<?= htmlspecialchars($y['kontobewegung_id']) ?>, <?= htmlspecialchars($konto_id) ?>)">
<?= number_format($y['betrag'], 2, ",", ".") ?> €
</td>
<form id="hiddenFormÄndereUmsatz" method="post" action="kontobewegung_edit.php">
<input id="hiddenInputÄndereUmsatzKontobewegungID" type="hidden" name="kontobewegung_id">
<input id="hiddenInputÄndereUmsatzKontoID" type="hidden" name="konto_id">
<input id="hiddenInputEditTyp" type="hidden" name="editTyp" value="edit">
</form>
</tr>
<?php endforeach; ?>
</table>
</div>
</body>
</html>