216 lines
9.6 KiB
PHP
216 lines
9.6 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->query("SELECT (date_trunc('month', CURRENT_DATE::date) - interval '2 month')::date AS von,
|
|
(date_trunc('month', CURRENT_DATE::date) + interval '1 month' - interval '1 day')::date AS bis;");
|
|
$monat_aktuell = $stmt->fetchAll(PDO::FETCH_ASSOC)[0];
|
|
|
|
$selectedRange = $_GET['range'] ?? $monat_aktuell['von'] . " to " . $monat_aktuell['bis'];
|
|
|
|
$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
|
|
AND kb.datum_ausgegeben BETWEEN :von AND :bis
|
|
ORDER BY datum_ausgegeben DESC,
|
|
kb.id DESC;");
|
|
$stmt->execute(['konto_id' => $konto_id, 'von' => $monat_aktuell['von'], 'bis' => $monat_aktuell['bis']]);
|
|
$kontobewegung = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<head>
|
|
<link rel="stylesheet" href="style.css">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
|
|
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
|
|
|
|
<script>
|
|
function ändereUmsatz(kontobewegung_id, konto_id) {
|
|
document.getElementById("hiddenInputÄndereUmsatzKontobewegungID").value = kontobewegung_id;
|
|
document.getElementById("hiddenInputÄndereUmsatzKontoID").value = konto_id;
|
|
|
|
//console.log("DEBUG: ", document.getElementById("hiddenInputÄndereUmsatzKontobewegungID").value);
|
|
|
|
document.getElementById("hiddenFormÄndereUmsatz").submit();
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
flatpickr("#rangePicker", {
|
|
mode: "range",
|
|
dateFormat: "Y-m-d",
|
|
/*defaultDate: ["2025-11-01","2025-11-30"]*/
|
|
closeOnSelect: false,
|
|
|
|
onReady: function (selectedDates, dateStr, instance) {
|
|
const fpContainer = instance.calendarContainer;
|
|
|
|
if (fpContainer.querySelector(".fp-apply-btn")) return;
|
|
|
|
const applyBtn = document.createElement("button");
|
|
applyBtn.textContent = "Filtern";
|
|
applyBtn.type = "button";
|
|
applyBtn.className = "fp-apply-btn";
|
|
|
|
applyBtn.style.margin = "8px";
|
|
applyBtn.style.padding = "6px 12px";
|
|
applyBtn.style.fontSize = "14px";
|
|
|
|
applyBtn.addEventListener("click", () => {
|
|
const value = instance.input.value;
|
|
|
|
datum(<?= $konto_id ?>, value);
|
|
|
|
instance.close();
|
|
});
|
|
|
|
fpContainer.appendChild(applyBtn);
|
|
}
|
|
});
|
|
});
|
|
|
|
function datum(konto_id) {
|
|
const val = document.getElementById('rangePicker').value; // "YYYY-MM-DD to YYYY-MM-DD"
|
|
if (!val) return alert('Bitte Zeitraum wählen');
|
|
|
|
const parts = val.split(' to ');
|
|
const start = parts[0];
|
|
const end = parts[1] ?? parts[0];
|
|
|
|
fetch('forms/datepicker.php', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
body: `start=${encodeURIComponent(start)}&end=${encodeURIComponent(end)}&konto_id=${encodeURIComponent(konto_id)}`
|
|
})
|
|
.then(res => {
|
|
if (!res.ok) {
|
|
throw new Error("HTTP Fehler " + res.status);
|
|
}
|
|
return res.text(); // zuerst als Text holen
|
|
})
|
|
.then(txt => {
|
|
//console.log("Antwort-Text:", txt); // prüfen was wirklich kommt
|
|
return JSON.parse(txt);
|
|
})
|
|
//.then(data => console.log("JSON:", data)) //LOGAusgabe
|
|
.then(data => {
|
|
if (!data.success) return alert('Fehler: ' + (data.message||''));
|
|
// data.rows = Array mit Ergebnissen - Tabelle ersetzen
|
|
const tbody = document.getElementById('tableBody');
|
|
tbody.innerHTML = ''; // löschen
|
|
data.rows.forEach(r => {
|
|
const tr = document.createElement('tr');
|
|
tr.innerHTML = r.datum_abgebucht + r.datum_ausgegeben + r.beschreibung + r.betrag;
|
|
tr.classList.add(r.tr_class);
|
|
tbody.appendChild(tr);
|
|
});
|
|
})
|
|
.catch(err => console.error("Fehler:", err));
|
|
}
|
|
|
|
function escapeHtml(s){ return String(s).replace(/[&<>"']/g, c=>({ '&':'&','<':'<','>':'>','"':'"',"'":''' })[c]); }
|
|
function numberFormat(n){ return Number(n).toLocaleString('de-DE', {minimumFractionDigits:2, maximumFractionDigits:2}); }
|
|
|
|
</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>
|
|
<thead>
|
|
<tr>
|
|
<th id="th_gebucht">gebucht</th>
|
|
<th id="th_ausgegeben">
|
|
<!--ausgegeben-->
|
|
<div class="range-wrapper">
|
|
<input id="rangePicker" type="text" placeholder="ausgegben" value="<?= htmlspecialchars($selectedRange) ?>">
|
|
<!--button id="applyRange" type="button" onClick="datum(< ?= htmlspecialchars($konto_id) ?>)">Anwenden</button-->
|
|
</div>
|
|
</th>
|
|
<th id="th_beschreibung">Beschreibung</th>
|
|
<th id="th_betrag">Betrag</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="tableBody">
|
|
<?php foreach ($kontobewegung as $y): ?>
|
|
<tr <?= $y['kostenfix_id'] ? 'class="konto_fixKosten"' : 'class="standard"' ?>>
|
|
<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>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<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>
|
|
</div>
|
|
</body>
|
|
|
|
</html>
|