From b7153c423c05127c5d47b404ea0c306bd7d9e266 Mon Sep 17 00:00:00 2001 From: OpenXE <> Date: Tue, 28 Mar 2023 12:30:57 +0200 Subject: [PATCH] fibu_buchungen added, rework of zahlungen auftrag, rechnung, gutschrift --- upgrade/data/db_schema.json | 41 +-- www/lib/class.erpapi.php | 32 +- www/pages/auftrag.php | 63 ++-- www/pages/content/fibu_buchungen_edit.tpl | 204 ++++++++++++ www/pages/content/fibu_buchungen_list.tpl | 10 + www/pages/content/kontoauszuege_edit.tpl | 2 +- www/pages/fibu_buchungen.php | 372 ++++++++++++++++++++++ www/pages/importvorlage.php | 2 - 8 files changed, 664 insertions(+), 62 deletions(-) create mode 100644 www/pages/content/fibu_buchungen_edit.tpl create mode 100644 www/pages/content/fibu_buchungen_list.tpl create mode 100644 www/pages/fibu_buchungen.php diff --git a/upgrade/data/db_schema.json b/upgrade/data/db_schema.json index d3a09d16..08f20d8d 100644 --- a/upgrade/data/db_schema.json +++ b/upgrade/data/db_schema.json @@ -8072,7 +8072,7 @@ "Collation": "utf8mb3_general_ci", "Null": "NO", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -10249,7 +10249,7 @@ "Collation": "utf8mb3_general_ci", "Null": "NO", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -21837,7 +21837,7 @@ "Collation": "utf8mb3_general_ci", "Null": "NO", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -27031,7 +27031,7 @@ "Collation": "utf8mb3_general_ci", "Null": "NO", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -32938,7 +32938,7 @@ "Collation": "utf8mb3_general_ci", "Null": "NO", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -44111,7 +44111,7 @@ "Collation": "utf8mb3_general_ci", "Null": "NO", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -60739,7 +60739,7 @@ "Collation": "utf8mb3_general_ci", "Null": "NO", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -65936,7 +65936,7 @@ "Collation": "utf8mb3_general_ci", "Null": "NO", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -68245,7 +68245,7 @@ "Collation": "utf8mb3_general_ci", "Null": "NO", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -72138,7 +72138,7 @@ "Collation": "utf8mb3_general_ci", "Null": "NO", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -74147,7 +74147,7 @@ "Collation": "utf8mb3_general_ci", "Null": "NO", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -81287,7 +81287,7 @@ "Collation": "utf8mb3_general_ci", "Null": "NO", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -83531,7 +83531,7 @@ "Collation": "utf8mb3_general_ci", "Null": "YES", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -104480,7 +104480,7 @@ "Collation": "utf8mb3_general_ci", "Null": "NO", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -107296,7 +107296,7 @@ "Collation": "utf8mb3_general_ci", "Null": "NO", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -110141,7 +110141,7 @@ "Collation": "utf8mb3_general_ci", "Null": "NO", "Key": "", - "Default": "'eur'", + "Default": "'EUR'", "Extra": "", "Privileges": "select,insert,update,references", "Comment": "" @@ -114485,10 +114485,15 @@ "type": "VIEW", "Create": "CREATE VIEW `belegeregs` AS select `rechnung`.`id` AS `id`,`rechnung`.`adresse` AS `adresse`,`rechnung`.`datum` AS `datum`,`rechnung`.`belegnr` AS `belegnr`,`rechnung`.`status` AS `status`,`rechnung`.`land` AS `land`,'rechnung' AS `typ`,`rechnung`.`umsatz_netto` AS `umsatz_netto`,`rechnung`.`erloes_netto` AS `erloes_netto`,`rechnung`.`deckungsbeitrag` AS `deckungsbeitrag`,`rechnung`.`provision_summe` AS `provision_summe`,`rechnung`.`vertriebid` AS `vertriebid`,`rechnung`.`gruppe` AS `gruppe`,`rechnung`.`projekt` AS `projekt` from `rechnung` union all select `gutschrift`.`id` AS `id`,`gutschrift`.`adresse` AS `adresse`,`gutschrift`.`datum` AS `datum`,`gutschrift`.`belegnr` AS `belegnr`,`gutschrift`.`status` AS `status`,`gutschrift`.`land` AS `land`,'gutschrift' AS `typ`,`gutschrift`.`umsatz_netto` * -1 AS `umsatz_netto*-1`,`gutschrift`.`erloes_netto` * -1 AS `erloes_netto*-1`,`gutschrift`.`deckungsbeitrag` * -1 AS `deckungsbeitrag*-1`,`gutschrift`.`provision_summe` * -1 AS `provision_summe*-1`,`gutschrift`.`vertriebid` AS `vertriebid`,`gutschrift`.`gruppe` AS `gruppe`,`gutschrift`.`projekt` AS `projekt` from `gutschrift`" }, - { + { "name": "fibu_buchungen_alle", "type": "VIEW", - "Create": "CREATE VIEW `fibu_buchungen_alle` AS select `fb`.`buchungsart` AS `buchungsart`,`fb`.`typ` AS `typ`,`fb`.`id` AS `id`,if(`bl`.`datum` <> '',`bl`.`datum`,`fb`.`datum`) AS `datum`,`fb`.`gegen_typ` AS `doc_typ`,`fb`.`gegen_id` AS `doc_id`,`bl`.`belegnr` AS `doc_belegnr`,`fb`.`soll` AS `betrag`,`fb`.`waehrung` AS `waehrung`,`fb`.`edit_module` AS `edit_module`,`fb`.`edit_id` AS `edit_id` from ((select 'umsatz' AS `buchungsart`,'rechnung' AS `typ`,`rechnung`.`id` AS `id`,`rechnung`.`soll` AS `soll`,`rechnung`.`waehrung` AS `waehrung`,'rechnung' AS `gegen_typ`,`rechnung`.`id` AS `gegen_id`,`rechnung`.`datum` AS `datum`,'rechnung' AS `edit_module`,`rechnung`.`id` AS `edit_id` from `rechnung` where `rechnung`.`belegnr` <> '' union select 'umsatz' AS `umsatz`,'gutschrift' AS `'gutschrift'`,`gutschrift`.`id` AS `id`,-`gutschrift`.`soll` AS `- ``openxe``.``gutschrift``.``soll```,`gutschrift`.`waehrung` AS `waehrung`,'gutschrift' AS `gutschrift`,`gutschrift`.`id` AS `id`,`gutschrift`.`datum` AS `datum`,'gutschrift' AS `edit_module`,`gutschrift`.`id` AS `edit_id` from `gutschrift` where `gutschrift`.`belegnr` <> '' union select 'abbuchung' AS `abbuchung`,'gutschrift' AS `rechnung`,`gutschrift`.`id` AS `id`,`gutschrift`.`soll` AS `- ``openxe``.``gutschrift``.``soll```,`gutschrift`.`waehrung` AS `waehrung`,'rechnung' AS `gutschrift`,`gutschrift`.`rechnungid` AS `rechnungid`,`gutschrift`.`datum` AS `datum`,'gutschrift' AS `edit_module`,`gutschrift`.`id` AS `edit_id` from `gutschrift` where `gutschrift`.`rechnungid` > 0 and `gutschrift`.`belegnr` <> '' union select 'abbuchung' AS `abbuchung`,'rechnung' AS `rechnung`,`gutschrift`.`rechnungid` AS `rechnungid`,-`gutschrift`.`soll` AS `- ``openxe``.``gutschrift``.``soll```,`gutschrift`.`waehrung` AS `waehrung`,'gutschrift' AS `gutschrift`,`gutschrift`.`id` AS `id`,`gutschrift`.`datum` AS `datum`,'gutschrift' AS `edit_module`,`gutschrift`.`id` AS `edit_id` from `gutschrift` where `gutschrift`.`rechnungid` > 0 and `gutschrift`.`belegnr` <> '' union select 'aufwand' AS `aufwand`,'verbindlichkeit' AS `verbindlichkeit`,`verbindlichkeit`.`id` AS `id`,-`verbindlichkeit`.`betrag` AS `- ``openxe``.``verbindlichkeit``.``betrag```,`verbindlichkeit`.`waehrung` AS `waehrung`,'verbindlichkeit' AS `verbindlichkeit`,`verbindlichkeit`.`id` AS `id`,`verbindlichkeit`.`rechnungsdatum` AS `rechnungsdatum`,'verbindlichkeit' AS `edit_module`,`verbindlichkeit`.`id` AS `edit_id` from `verbindlichkeit` where `verbindlichkeit`.`belegnr` <> '' union select 'abbuchung' AS `abbuchung`,`fibu_buchungen`.`von_typ` AS `von_typ`,`fibu_buchungen`.`von_id` AS `von_id`,-`fibu_buchungen`.`betrag` AS `- ``openxe``.``fibu_buchungen``.``betrag```,`fibu_buchungen`.`waehrung` AS `waehrung`,`fibu_buchungen`.`nach_typ` AS `nach_typ`,`fibu_buchungen`.`nach_id` AS `nach_id`,`fibu_buchungen`.`zeit` AS `zeit`,'fibu_buchungen' AS `edit_module`,`fibu_buchungen`.`id` AS `edit_id` from `fibu_buchungen` union select 'zubuchung' AS `zubuchung`,`fibu_buchungen`.`nach_typ` AS `nach_typ`,`fibu_buchungen`.`nach_id` AS `nach_id`,`fibu_buchungen`.`betrag` AS `betrag`,`fibu_buchungen`.`waehrung` AS `waehrung`,`fibu_buchungen`.`von_typ` AS `von_typ`,`fibu_buchungen`.`von_id` AS `von_id`,`fibu_buchungen`.`zeit` AS `zeit`,'fibu_buchungen' AS `edit_module`,`fibu_buchungen`.`id` AS `edit_id` from `fibu_buchungen`) `fb` left join (select `rechnung`.`datum` AS `datum`,'rechnung' AS `typ`,`rechnung`.`id` AS `id`,`rechnung`.`belegnr` AS `belegnr` from `rechnung` where `rechnung`.`belegnr` <> '' union select `gutschrift`.`datum` AS `datum`,'gutschrift' AS `gutschrift`,`gutschrift`.`id` AS `id`,`gutschrift`.`belegnr` AS `belegnr` from `gutschrift` where `gutschrift`.`belegnr` <> '' union select `verbindlichkeit`.`rechnungsdatum` AS `rechnungsdatum`,'verbindlichkeit' AS `verbindlichkeit`,`verbindlichkeit`.`id` AS `id`,`verbindlichkeit`.`belegnr` AS `belegnr` from `verbindlichkeit` where `verbindlichkeit`.`belegnr` <> '' union select `kontoauszuege`.`buchung` AS `buchung`,'kontoauszuege' AS `kontoauszuege`,`kontoauszuege`.`id` AS `id`,`kontoauszuege`.`buchungstext` AS `buchungstext` from `kontoauszuege` union select '','kontorahmen' AS `'kontorahmen'`,`kontorahmen`.`id` AS `id`,`kontorahmen`.`beschriftung` AS `beschriftung` from `kontorahmen`) `bl` on(`fb`.`gegen_typ` = `bl`.`typ` and `fb`.`gegen_id` = `bl`.`id`))" + "Create": "CREATE VIEW `fibu_buchungen_alle` AS select `fb`.`buchungsart` AS `buchungsart`,`fb`.`typ` AS `typ`,`fb`.`id` AS `id`,if(`fibu_objekte`.`datum` <> '',`fibu_objekte`.`datum`,`fb`.`datum`) AS `datum`,`fb`.`gegen_typ` collate utf8mb3_general_ci AS `doc_typ`,`fb`.`gegen_id` AS `doc_id`,`fibu_objekte`.`info` AS `doc_belegnr`,`fb`.`soll` AS `betrag`,`fb`.`waehrung` AS `waehrung`,`fb`.`edit_module` collate utf8mb4_general_ci AS `edit_module`,`fb`.`edit_id` AS `edit_id` from ((select 'umsatz' AS `buchungsart`,'rechnung' AS `typ`,`rechnung`.`id` AS `id`,`rechnung`.`soll` AS `soll`,`rechnung`.`waehrung` AS `waehrung`,'rechnung' AS `gegen_typ`,`rechnung`.`id` AS `gegen_id`,`rechnung`.`datum` AS `datum`,'rechnung' AS `edit_module`,`rechnung`.`id` AS `edit_id` from `rechnung` where `rechnung`.`belegnr` <> '' union select 'umsatz' AS `umsatz`,'gutschrift' AS `'gutschrift'`,`gutschrift`.`id` AS `id`,-`gutschrift`.`soll` AS `- ``openxe``.``gutschrift``.``soll```,`gutschrift`.`waehrung` AS `waehrung`,'gutschrift' AS `gutschrift`,`gutschrift`.`id` AS `id`,`gutschrift`.`datum` AS `datum`,'gutschrift' AS `edit_module`,`gutschrift`.`id` AS `edit_id` from `gutschrift` where `gutschrift`.`belegnr` <> '' union select 'abbuchung' AS `abbuchung`,'gutschrift' AS `rechnung`,`gutschrift`.`id` AS `id`,`gutschrift`.`soll` AS `- ``openxe``.``gutschrift``.``soll```,`gutschrift`.`waehrung` AS `waehrung`,'rechnung' AS `gutschrift`,`gutschrift`.`rechnungid` AS `rechnungid`,`gutschrift`.`datum` AS `datum`,'gutschrift' AS `edit_module`,`gutschrift`.`id` AS `edit_id` from `gutschrift` where `gutschrift`.`rechnungid` > 0 and `gutschrift`.`belegnr` <> '' union select 'abbuchung' AS `abbuchung`,'rechnung' AS `rechnung`,`gutschrift`.`rechnungid` AS `rechnungid`,-`gutschrift`.`soll` AS `- ``openxe``.``gutschrift``.``soll```,`gutschrift`.`waehrung` AS `waehrung`,'gutschrift' AS `gutschrift`,`gutschrift`.`id` AS `id`,`gutschrift`.`datum` AS `datum`,'gutschrift' AS `edit_module`,`gutschrift`.`id` AS `edit_id` from `gutschrift` where `gutschrift`.`rechnungid` > 0 and `gutschrift`.`belegnr` <> '' union select 'aufwand' AS `aufwand`,'verbindlichkeit' AS `verbindlichkeit`,`verbindlichkeit`.`id` AS `id`,-`verbindlichkeit`.`betrag` AS `- ``openxe``.``verbindlichkeit``.``betrag```,`verbindlichkeit`.`waehrung` AS `waehrung`,'verbindlichkeit' AS `verbindlichkeit`,`verbindlichkeit`.`id` AS `id`,`verbindlichkeit`.`rechnungsdatum` AS `rechnungsdatum`,'verbindlichkeit' AS `edit_module`,`verbindlichkeit`.`id` AS `edit_id` from `verbindlichkeit` where `verbindlichkeit`.`belegnr` <> '' union select 'zahlung' AS `zahlung`,'kontoauszuege' AS `kontoauszuege`,`kontoauszuege`.`id` AS `id`,-`kontoauszuege`.`soll` AS `- ``openxe``.``kontoauszuege``.``soll```,`kontoauszuege`.`waehrung` AS `waehrung`,'kontoauszuege' AS `kontoauszuege`,`kontoauszuege`.`id` AS `id`,`kontoauszuege`.`buchung` AS `buchung`,'kontoauszuege' AS `edit_module`,`kontoauszuege`.`id` AS `edit_id` from `kontoauszuege` where `kontoauszuege`.`importfehler` is null union select 'abbuchung' AS `abbuchung`,`fibu_buchungen`.`von_typ` AS `von_typ`,`fibu_buchungen`.`von_id` AS `von_id`,-`fibu_buchungen`.`betrag` AS `- ``openxe``.``fibu_buchungen``.``betrag```,`fibu_buchungen`.`waehrung` AS `waehrung`,`fibu_buchungen`.`nach_typ` AS `nach_typ`,`fibu_buchungen`.`nach_id` AS `nach_id`,`fibu_buchungen`.`zeit` AS `zeit`,'fibu_buchungen' AS `edit_module`,`fibu_buchungen`.`id` AS `edit_id` from `fibu_buchungen` union select 'zubuchung' AS `zubuchung`,`fibu_buchungen`.`nach_typ` AS `nach_typ`,`fibu_buchungen`.`nach_id` AS `nach_id`,`fibu_buchungen`.`betrag` AS `betrag`,`fibu_buchungen`.`waehrung` AS `waehrung`,`fibu_buchungen`.`von_typ` AS `von_typ`,`fibu_buchungen`.`von_id` AS `von_id`,`fibu_buchungen`.`zeit` AS `zeit`,'fibu_buchungen' AS `edit_module`,`fibu_buchungen`.`id` AS `edit_id` from `fibu_buchungen`) `fb` left join `fibu_objekte` on(`fb`.`gegen_typ` = `fibu_objekte`.`typ` and `fb`.`gegen_id` = `fibu_objekte`.`id`))" + }, + { + "name": "fibu_objekte", + "type": "VIEW", + "Create": "CREATE VIEW `fibu_objekte` AS select `rechnung`.`datum` AS `datum`,'rechnung' collate utf8mb4_general_ci AS `typ`,`rechnung`.`id` AS `id`,`rechnung`.`belegnr` AS `info` from `rechnung` where `rechnung`.`belegnr` <> '' union select `gutschrift`.`datum` AS `datum`,'gutschrift' AS `gutschrift`,`gutschrift`.`id` AS `id`,`gutschrift`.`belegnr` AS `belegnr` from `gutschrift` where `gutschrift`.`belegnr` <> '' union select `verbindlichkeit`.`rechnungsdatum` AS `rechnungsdatum`,'verbindlichkeit' AS `verbindlichkeit`,`verbindlichkeit`.`id` AS `id`,`verbindlichkeit`.`belegnr` AS `belegnr` from `verbindlichkeit` where `verbindlichkeit`.`belegnr` <> '' union select `kontoauszuege`.`buchung` AS `buchung`,'kontoauszuege' AS `kontoauszuege`,`kontoauszuege`.`id` AS `id`,concat(`konten`.`kurzbezeichnung`,' - ',`kontoauszuege`.`buchungstext`) AS `buchungstext` from (`kontoauszuege` left join `konten` on(`konten`.`id` = `kontoauszuege`.`konto`)) union select '' AS `Name_exp_1`,'kontorahmen' AS `'kontorahmen'`,`kontorahmen`.`id` AS `id`,`kontorahmen`.`beschriftung` AS `beschriftung` from `kontorahmen`" } ] } diff --git a/www/lib/class.erpapi.php b/www/lib/class.erpapi.php index e3d96046..1e9eb848 100644 --- a/www/lib/class.erpapi.php +++ b/www/lib/class.erpapi.php @@ -1510,6 +1510,11 @@ public function NavigationHooks(&$menu) // return "replace(trim($spalte)+0,'.',',')"; } + function FormatUCfirst($spalte) + { + return ('CONCAT(UCASE(LEFT('.$spalte.', 1)),SUBSTRING('.$spalte.', 2))'); + } + static function add_alias(string $text, $alias = false) { if (empty($alias)) { return($text); @@ -7089,6 +7094,7 @@ title: 'Abschicken', $navarray['menu']['admin'][$menu]['sec'][] = array('Gutschrift / '.$this->Firmendaten("bezeichnungstornorechnung"),'gutschrift','list'); $navarray['menu']['admin'][$menu]['sec'][] = array('Proformarechnung','proformarechnung','list'); $navarray['menu']['admin'][$menu]['sec'][] = array('Kontoauszüge','kontoauszuege','list'); + $navarray['menu']['admin'][$menu]['sec'][] = array('Buchungen','fibu_buchungen','list'); $navarray['menu']['admin'][$menu]['sec'][] = array('Abolauf','rechnungslauf','rechnungslauf'); $navarray['menu']['admin'][$menu]['sec'][] = array('Mahnwesen','mahnwesen','list'); @@ -36097,10 +36103,10 @@ function Firmendaten($field,$projekt="") * Gutschrift -> Rechnungid, Rechnung -> Auftragid */ - public function GetZahlungen(int $id, string $type, bool $cascade = false, string $lastlevel = 'auftrag') : array { + public function GetZahlungen(int $id, string $type, string $cascadelevel = '') : array { - if ($cascade) { - $documents = $this->GetZahlungenAssociatedDocuments($id, $type, $lastlevel); + if ($cascadelevel != '') { + $documents = $this->GetZahlungenAssociatedDocuments($id, $type, $cascadelevel); } else { $documents = array(array('id' => $id, 'type' => $type)); } @@ -36146,7 +36152,23 @@ function Firmendaten($field,$projekt="") * Auftrag: gesamtsumme, rechnung: soll, gutschrift: soll verbindlichkeit: betrag * returns array(array(betrag, waehrung)) one line per waehrung */ - public function GetSaldenDokument($id, $type, string $lastlevel = 'auftrag') : array { + public function GetSaldenDokument($id, $type, string $cascadelevel = '') : array { + + if ($cascadelevel != '') { + $documents = $this->GetZahlungenAssociatedDocuments($id, $type, $cascadelevel); + } else { + $documents = array(array('id' => $id, 'type' => $type)); + } + + if (empty($documents)) { + return(array()); + } + + $ids = array(); + + foreach ($documents as $document) { + $ids[] = $document['type'].$document['id']; + } $sql = " SELECT @@ -36155,7 +36177,7 @@ function Firmendaten($field,$projekt="") FROM fibu_buchungen_alle WHERE - typ = '".$type."' AND id = ".$id." + CONCAT(typ,id) IN ('".implode("','",$ids)."') GROUP BY waehrung"; diff --git a/www/pages/auftrag.php b/www/pages/auftrag.php index 5a336f42..6528b92d 100644 --- a/www/pages/auftrag.php +++ b/www/pages/auftrag.php @@ -3423,46 +3423,37 @@ class Auftrag extends GenAuftrag { $id = $this->app->Secure->GetGET('id'); - $zahlungen = $this->app->erp->GetZahlungen($id,'auftrag',true); + $zahlungen = $this->app->erp->GetZahlungen($id,'auftrag',true); + if (!empty($zahlungen)) { + $et = new EasyTable($this->app); -// print_r($zahlungen); + $et->headings = array('Datum','Beleg','Betrag','Währung'); - $result = ""; + foreach ($zahlungen as $zahlung) { + $row = array( + $zahlung['datum'], + " + ".ucfirst($zahlung['doc_typ'])." + ".$zahlung['doc_belegnr']." + ", + $zahlung['betrag'], + $zahlung['waehrung'] + ); + $et->AddRow($row); + } - foreach ($zahlungen as $zahlung) { - $result .= " -