diff --git a/diagramme.php b/diagramme.php index f02dfd6..9fd1738 100644 --- a/diagramme.php +++ b/diagramme.php @@ -1,6 +1,11 @@ @@ -8,9 +13,47 @@ require_once __DIR__ . '/includes/db_connect.php'; + -

Hello World!

+
+

+ Diagramme +

+ + Home + +
+
+ + \ No newline at end of file diff --git a/fix_edit.php b/fix_edit.php index dda31a2..cc1515c 100644 --- a/fix_edit.php +++ b/fix_edit.php @@ -8,7 +8,7 @@ $kostenfix_id = $_POST['kostenfix_id']; - $stmt = $pdo->prepare("SELECT kf.id AS kostenfix_id, + $stmt = $pdo->query("SELECT kf.id AS kostenfix_id, kf.beschreibung, zt.id AS zahlungstag_id, zm.id AS zahlungsmonate_id, @@ -18,15 +18,8 @@ JOIN zahlungstag zt ON zt.id = kf.zahlungstag_id JOIN zahlungsmonate zm ON zm.id = kf.zahlungsmonate_id JOIN konto k ON k.id = kf.konto_id - WHERE kf.id = :kostenfix_id;"); - $stmt->execute(['kostenfix_id' => $kostenfix_id]); - $kostenfixFetchAll = $stmt->fetchAll(PDO::FETCH_ASSOC); - - if(count($kostenfixFetchAll) > 1) { - //TODO FEHLERHANDLING - } else { - $kostenfix = $kostenfixFetchAll[0]; - } + WHERE kf.id = $kostenfix_id;"); + $kostenfix = $stmt->fetch(PDO::FETCH_ASSOC); $stmt = $pdo->query("SELECT id, name FROM zahlungsmonate @@ -54,7 +47,7 @@
- +
- - abbrechen +

+ Fixkosten ändern +

+
+ abbrechen
@@ -87,9 +81,9 @@
@@ -103,9 +97,9 @@
@@ -119,9 +113,9 @@
@@ -133,7 +127,7 @@

- +
@@ -54,9 +55,9 @@
@@ -70,9 +71,9 @@
@@ -86,9 +87,9 @@
@@ -114,7 +115,7 @@

- +
@@ -122,7 +126,7 @@
@@ -144,45 +148,45 @@
- - - - - - - - - +
ZyklusTagBeschreibungBetragKonto
- - - - - - - - - - + + + + + - -
- - - - - - - € - - - ZyklusTagBeschreibungBetragKonto
+ + + + + + + + + + + + + € + + + + + +
+ + +
+ + +
diff --git a/fixkosten.php b/fixkosten.php index 036df2c..8943c8d 100644 --- a/fixkosten.php +++ b/fixkosten.php @@ -31,20 +31,17 @@
@@ -58,28 +55,23 @@ Konto - - - + + + - - + + - - + + + else echo 'td_zahl_null'; ?>"> € - - + +
diff --git a/forms/fixkosten.php b/forms/fixkosten.php index 939aa5e..ac7b6d1 100644 --- a/forms/fixkosten.php +++ b/forms/fixkosten.php @@ -174,7 +174,9 @@ FROM monat WHERE id = :monat_id;"); $stmt->execute([':monat_id' => $para_monat_id]); - $monat_wert = $stmt->fetchAll(PDO::FETCH_ASSOC); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + + $monat_wert = $row ?: null; $stmt = $para_pdo->prepare("INSERT INTO kontobewegung (konto_id, betrag, beschreibung, datum_ausgegeben, kostenfix_id, datum_fixkosten_uebernommen) SELECT kf.konto_id, @@ -192,7 +194,7 @@ WHERE kb_inner.kostenfix_id = kf.id AND EXTRACT(MONTH FROM kb_inner.datum_ausgegeben) = CAST(:monat_wert AS INT) AND EXTRACT(YEAR FROM kb_inner.datum_ausgegeben) = CAST(:jahr AS INT));"); - $stmt->execute(['monat_wert' => $monat_wert[0]['wert'], + $stmt->execute(['monat_wert' => $monat_wert['wert'], 'jahr' => $para_jahr]); $para_pdo->commit(); diff --git a/forms/kontobewegung.php b/forms/kontobewegung.php index 33be12a..40e0719 100644 --- a/forms/kontobewegung.php +++ b/forms/kontobewegung.php @@ -113,14 +113,13 @@ JOIN konto k ON k.id = kb.konto_id WHERE kb.id = :kontobewegung_id;"); $stmt->execute(['kontobewegung_id' => $para_kontobewegung_id]); - $kontobewegung = $stmt->fetchAll(PDO::FETCH_ASSOC); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + $kontobewegung = $row ?: null; - if(count($kontobewegung) > 1) throw new Exception('Mehr als eine Kontobewegung gefunden'); - - $konto_id_vorher = $kontobewegung[0]['konto_id']; - $datum_abgebucht_vorher = $kontobewegung[0]['datum_abgebucht']; - $kontostand_vorher_konto_vorher = $kontobewegung[0]['kontostand']; - $betrag_vorher = $kontobewegung[0]['betrag']; + $konto_id_vorher = $kontobewegung['konto_id']; + $datum_abgebucht_vorher = $kontobewegung['datum_abgebucht']; + $kontostand_vorher_konto_vorher = $kontobewegung['kontostand']; + $betrag_vorher = $kontobewegung['betrag']; $stmt = $para_pdo->prepare("SELECT kontostand FROM konto @@ -196,14 +195,14 @@ FROM kontobewegung WHERE id = :kontobewegung_id;"); $stmt->execute(['kontobewegung_id' => $para_kontobewegung_id]); - $kontobewegung = $stmt->fetchAll(PDO::FETCH_ASSOC); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + + $kontobewegung = $row ?: null; try { - if(count($kontobewegung) > 1) throw new Exception("Multiple Kontobewegungen gefunden"); - - $datum_abgebucht = $kontobewegung[0]['datum_abgebucht']; - $betrag = $kontobewegung[0]['betrag']; - $konto_id = $kontobewegung[0]['konto_id']; + $datum_abgebucht = $kontobewegung['datum_abgebucht']; + $betrag = $kontobewegung['betrag']; + $konto_id = $kontobewegung['konto_id']; $para_pdo->beginTransaction(); @@ -250,10 +249,10 @@ WHERE EXTRACT(MONTH FROM CAST(:datum_ausgegeben AS DATE)) = CAST(wert AS INT);"); $stmt->execute(['datum_ausgegeben' => $para_datum_ausgegeben]); - $monat = $stmt->fetchAll(PDO::FETCH_ASSOC)[0]; - - $monat_id = $monat['id']; - $jahr = $monat['jahr']; + $row = $stmt->fetch(PDO::FETCH_ASSOC); + + $monat_id = $row ? $row['id'] : -1; + $jahr = $row ? $row['jahr'] : 2000; $stmt = $para_pdo->prepare("SELECT betrag FROM hist_restguthaben @@ -261,10 +260,12 @@ AND jahr = :jahr;"); $stmt->execute(['monat_id' => $monat_id, 'jahr' => $jahr]); - $hist_restguthaben = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $row = $stmt->fetch(PDO::FETCH_ASSOC); + $hist_restguthaben = $row ?: null; if(isset($hist_restguthaben)) { - $betrag = $hist_restguthaben[0]['betrag'] + $para_betrag; + $betrag = $hist_restguthaben['betrag'] + $para_betrag; $stmt = $para_pdo->prepare("UPDATE hist_restguthaben SET betrag = :betrag diff --git a/historie.php b/historie.php deleted file mode 100644 index dea2ba2..0000000 --- a/historie.php +++ /dev/null @@ -1,50 +0,0 @@ -query("SELECT m.name, - hrg.jahr, - hrg.betrag - FROM hist_restguthaben hrg - JOIN monat m ON m.id = hrg.monat_id;"); - $historie = $stmt->fetchAll(PDO::FETCH_ASSOC); -?> - - - - - - - - - -
- - - - - - - - - - - - - -
JahrMonatBetrag
- - - - - € -
-
- - - \ No newline at end of file diff --git a/img/abbrechen.svg b/img/abbrechen.svg new file mode 100644 index 0000000..7d1e6d0 --- /dev/null +++ b/img/abbrechen.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/img/diagramme.svg b/img/diagramme.svg new file mode 100644 index 0000000..874e486 --- /dev/null +++ b/img/diagramme.svg @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/img/fixkosten.png.orig b/img/fixkosten.png.orig new file mode 100644 index 0000000..e15f693 Binary files /dev/null and b/img/fixkosten.png.orig differ diff --git a/img/fixkosten.svg b/img/fixkosten.svg new file mode 100644 index 0000000..fe3a063 --- /dev/null +++ b/img/fixkosten.svg @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/img/fixkostenZuKontobewegung.svg b/img/fixkostenZuKontobewegung.svg new file mode 100644 index 0000000..eadfb00 --- /dev/null +++ b/img/fixkostenZuKontobewegung.svg @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/img/home.svg b/img/home.svg new file mode 100644 index 0000000..7bfb94b --- /dev/null +++ b/img/home.svg @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/img/löschen.svg b/img/löschen.svg new file mode 100644 index 0000000..2a779f7 --- /dev/null +++ b/img/löschen.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/img/neueKontobewegung.svg b/img/neueKontobewegung.svg new file mode 100644 index 0000000..0abe228 --- /dev/null +++ b/img/neueKontobewegung.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/img/neueKontobewegung.svg.orig b/img/neueKontobewegung.svg.orig new file mode 100644 index 0000000..6fe7ee3 --- /dev/null +++ b/img/neueKontobewegung.svg.orig @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/img/speichern.svg b/img/speichern.svg new file mode 100644 index 0000000..74fceda --- /dev/null +++ b/img/speichern.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/index.php b/index.php index 92ef3d7..94f940d 100644 --- a/index.php +++ b/index.php @@ -15,19 +15,17 @@ ORDER BY k.id ASC;"); $kontos = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt = $pdo->prepare("SELECT SUM(betrag) AS restguthaben - FROM kontobewegung - WHERE (konto_id = :konto1 OR konto_id = :konto2) - AND EXTRACT(MONTH FROM datum_ausgegeben) = EXTRACT(MONTH FROM CURRENT_DATE);"); - $stmt->execute(['konto1' => 1, - 'konto2' => 2]); - - $restguthaben = ($stmt->fetchAll(PDO::FETCH_ASSOC))[0]['restguthaben']; - - $stmt = $pdo->query("SELECT name - FROM monat - WHERE CAST(wert AS INT) = EXTRACT(MONTH FROM CURRENT_DATE);"); - $monat = $stmt->fetchAll(PDO::FETCH_ASSOC)[0]['name']; + $stmt = $pdo->query("SELECT SUM(kb.betrag) AS restguthaben, + m.name + FROM kontobewegung kb + JOIN monat m ON CAST(m.wert AS INT) = EXTRACT(MONTH FROM CURRENT_DATE) + WHERE kb.konto_id IN (1, 2) + AND EXTRACT(MONTH FROM kb.datum_ausgegeben) = EXTRACT(MONTH FROM CURRENT_DATE) + AND COALESCE(kb.bei_restguthaben_ignorieren, false) <> true + GROUP BY m.name;;"); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + $restguthaben = $row ? $row['restguthaben'] : -0; + $monat = $row ? $row['name'] : ''; ?> @@ -39,52 +37,41 @@
- Testsystem'; - } - ?> -

- Restguthaben : € + + neue Kontobewegung + + + Fixkosten + +

+ Restguthaben :

+ + Diagramme +
+

Testsystem

' : '' ?> \ No newline at end of file diff --git a/konto.php b/konto.php index 9f47893..d8bfcad 100644 --- a/konto.php +++ b/konto.php @@ -2,42 +2,39 @@ require_once __DIR__ . '/includes/db_connect.php'; $system = getenv('POSTGRES_SYSTEM') ?? 'test'; - $konto_id = $_GET['id']; + $G_konto_id = isset($_GET['id']) ? (int)$_GET['id'] : -1; - $stmt = $pdo->prepare("SELECT id, + $stmt = $pdo->query("SELECT id, kontostand, darstellungsfarbe AS backgroundcolor, - bezeichnung AS konto + 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 = :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]; + WHERE id = $G_konto_id"); + $row = $stmt->fetch(PDO::FETCH_ASSOC); - $selectedRange = $_GET['range'] ?? $monat_aktuell['von'] . " to " . $monat_aktuell['bis']; + $konto_id = $row ? $row['id'] : -1; + $konto_bezeichnung = $row ? $row['konto'] : ''; + $konto_kontostand = $row ? $row['kontostand'] : -0; + $konto_backgroundColor = $row ? $row['backgroundcolor'] : '#ff0000'; - $stmt = $pdo->prepare("SELECT kb.id AS kontobewegung_id, + $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 - 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, + 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;"); - $stmt->execute(['konto_id' => $konto_id, 'von' => $monat_aktuell['von'], 'bis' => $monat_aktuell['bis']]); $kontobewegung = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> @@ -146,23 +143,14 @@
- - Neue Kontobewegung + + neue Kontobewegung - Testsystem'; - } - ?> -

- : € +

+ :

- - HOME + + Home
@@ -171,10 +159,8 @@ gebucht -
- - +
Beschreibung @@ -183,23 +169,20 @@ - > - - + > + + - - + + - - + + + else echo 'td_zahl_null'; ?>"> € @@ -213,6 +196,7 @@
+

Testsystem

' : '' ?> \ No newline at end of file diff --git a/kontobewegung_edit.php b/kontobewegung_edit.php index 714d70c..808c159 100644 --- a/kontobewegung_edit.php +++ b/kontobewegung_edit.php @@ -25,13 +25,7 @@ FROM kontobewegung WHERE id = :kontobewegung_id;"); $stmt->execute(['kontobewegung_id' => $kontobewegung_id]); - $kontobewegungFetchAll = $stmt->fetchAll(PDO::FETCH_ASSOC); - - if(count($kontobewegungFetchAll) > 1) { - //TODO FEHLERHANDLING - } else { - $kontobewegung = $kontobewegungFetchAll[0]; - } + $kontobewegung = $stmt->fetch(PDO::FETCH_ASSOC); ?> @@ -59,19 +53,20 @@ name="kontobewegung_submit" value="speichern" type="submit"> - speichern + speichern - - abbrechen +

+ Kontobewegung ändern +

+
+ abbrechen
@@ -112,9 +107,9 @@
@@ -129,7 +124,7 @@ + value="">
@@ -65,9 +66,9 @@
@@ -82,7 +83,9 @@
@@ -93,7 +96,7 @@

- +