202 lines
8.8 KiB
PHP
202 lines
8.8 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/db_connect.php';
|
|
$system = getenv('POSTGRES_SYSTEM') ?? 'test';
|
|
|
|
$G_konto_id = isset($_GET['id']) ? (int)$_GET['id'] : -1;
|
|
|
|
$stmt = $pdo->query("SELECT id,
|
|
kontostand,
|
|
darstellungsfarbe AS backgroundcolor,
|
|
bezeichnung AS konto,
|
|
(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
|
|
FROM konto
|
|
WHERE id = $G_konto_id;");
|
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
$konto_id = $row ? $row['id'] : -1;
|
|
$konto_bezeichnung = $row ? $row['konto'] : '';
|
|
$konto_kontostand = $row ? $row['kontostand'] : -0;
|
|
$konto_backgroundColor = $row ? $row['backgroundcolor'] : '#ff0000';
|
|
|
|
$monat_aktuell_von = $row ? $row['von'] : '2000-01-01';
|
|
$monat_aktuell_bis = $row ? $row['bis'] : '2000-01-01';
|
|
|
|
$G_selectedRange = $_GET['range'] ?? $row['von'] . " to " . $row['bis'];
|
|
|
|
$stmt = $pdo->query("SELECT kb.id AS kontobewegung_id,
|
|
kb.betrag,
|
|
kb.beschreibung,
|
|
kb.datum_ausgegeben,
|
|
kb.datum_abgebucht,
|
|
kb.kostenfix_id
|
|
FROM kontobewegung kb
|
|
WHERE kb.konto_id = $konto_id
|
|
AND kb.datum_ausgegeben BETWEEN '$monat_aktuell_von' AND '$monat_aktuell_bis'
|
|
ORDER BY kb.datum_ausgegeben DESC,
|
|
kb.id DESC;");
|
|
$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();
|
|
})
|
|
.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||''));
|
|
|
|
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=<?= $konto_id ?>" class="konto_header" id="konto_navigationLinks">
|
|
<img src="img\neueKontobewegung.svg" alt="neue Kontobewegung" class="menue">
|
|
</a>
|
|
<h2 class="seitentitel">
|
|
<?= $konto_bezeichnung ?>: <?= number_format($konto_kontostand, 2, ",", ".") ?> €
|
|
</h2>
|
|
<a href="index.php" class="konto_header" id="konto_navigationRechts">
|
|
<img src="img\home.svg" alt="Home" class="menue">
|
|
</a>
|
|
</div>
|
|
<div class="inhalt">
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th id="th_gebucht">gebucht</th>
|
|
<th id="th_ausgegeben">
|
|
<div class="range-wrapper">
|
|
<input id="rangePicker" type="text" placeholder="ausgegben" value="<?= htmlspecialchars($G_selectedRange, ENT_QUOTES, 'UTF-8') ?>">
|
|
</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 onClick="ändereUmsatz(<?= $y['kontobewegung_id'] ?>, <?= $konto_id ?>)"
|
|
<?= $y['kostenfix_id'] ? 'class="konto_fixKosten"' : 'class="standard"' ?>>
|
|
<td class="td_datum">
|
|
<?= empty($y['datum_abgebucht']) ? '' : $y['datum_abgebucht'] ?>
|
|
</td>
|
|
<td class="td_datum">
|
|
<?= $y['datum_ausgegeben'] ?>
|
|
</td>
|
|
<td class="td_text">
|
|
<?= htmlspecialchars($y['beschreibung'], ENT_QUOTES, 'UTF-8') ?>
|
|
</td>
|
|
<td class="<?php if($y['betrag'] < 0) echo 'td_zahl_neg';
|
|
elseif($y['betrag'] > 0) echo 'td_zahl_pos';
|
|
else echo 'td_zahl_null'; ?>">
|
|
<?= 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>
|
|
<?= $system === 'test' ? '<div class="menue"><h2 class="seitentitel">Testsystem</h2></div>' : '' ?>
|
|
</body>
|
|
|
|
</html>
|