From f22d640e4eb5b8dcad4bb126e2323b52d40b596c Mon Sep 17 00:00:00 2001 From: fds2610-bot Date: Sun, 12 Apr 2026 11:51:20 +0200 Subject: [PATCH] =?UTF-8?q?Feature:=20Asset-Verkn=C3=BCpfung=20in=20Buchun?= =?UTF-8?q?g=20=E2=80=93=20Neu-Anlage=20oder=20Auswahl=20bei=20AV-Konten?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- migrations/030_bookings_asset_id.sql | 6 ++++++ src/Controllers/BookingController.php | 21 +++++++++++++++++++-- src/Models/Booking.php | 7 +++++-- src/Views/belege/detail.php | 1 - 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 migrations/030_bookings_asset_id.sql diff --git a/migrations/030_bookings_asset_id.sql b/migrations/030_bookings_asset_id.sql new file mode 100644 index 0000000..cb6434a --- /dev/null +++ b/migrations/030_bookings_asset_id.sql @@ -0,0 +1,6 @@ +-- Migration 030: asset_id in bookings – Verknüpfung zur Anlagegut-Tabelle +ALTER TABLE bookings + ADD COLUMN asset_id INT UNSIGNED NULL + COMMENT 'FK auf assets – bei Buchungen auf Anlagevermögenskonten' + AFTER beleg_id, + ADD KEY idx_bookings_asset (asset_id); diff --git a/src/Controllers/BookingController.php b/src/Controllers/BookingController.php index 5a158b6..9712934 100644 --- a/src/Controllers/BookingController.php +++ b/src/Controllers/BookingController.php @@ -137,13 +137,28 @@ class BookingController ] ); - // Bewirtungskonto-Split: 4650→4654, 4651→4656, 4652→4657 + // Anlagevermögen: neues Asset anlegen oder bestehendes verknüpfen $konto = \Steuerkram\Database::fetchOne( - 'SELECT kontonummer FROM accounts WHERE id = ?', + 'SELECT id, kontonummer, kontenart FROM accounts WHERE id = ?', [(int)$data['kategorie_konto_id']] ); $kontonummer = $konto['kontonummer'] ?? ''; + if (($konto['kontenart'] ?? '') === 'Anlagevermögen') { + $assetId = isset($data['asset_id']) && $data['asset_id'] !== '' ? (int)$data['asset_id'] : null; + if ($assetId === null) { + // Neues Anlagegut anlegen + $assetId = \Steuerkram\Models\Asset::create([ + 'bezeichnung' => $data['buchungstext'], + 'account_id' => (int)$data['kategorie_konto_id'], + 'anschaffungsdatum' => $data['buchungs_datum'], + 'anschaffungskosten' => (float)$data['betrag_netto'], + ]); + } + $data['asset_id'] = $assetId; + } + + // Bewirtungskonto-Split: 4650→4654, 4651→4656, 4652→4657 if (in_array($kontonummer, ['4650', '4651', '4652'], true)) { $this->bucheBewirtungssplit($data, $kontonummer); } else { @@ -180,6 +195,7 @@ class BookingController $bookings = \Steuerkram\Models\Booking::forBeleg($belegId); $accounts = \Steuerkram\Models\Account::all(['aktiv' => 1]); $integrity = \Steuerkram\Models\Beleg::verifyIntegrity($belegId); + $assets = \Steuerkram\Models\Asset::all(); $view = new View(); $view->render('layout/base.php', [ @@ -189,6 +205,7 @@ class BookingController 'bookings' => $bookings, 'integrity' => $integrity, 'accounts' => $accounts, + 'assets' => $assets, 'formErrors' => $errors, 'formData' => $formData, ]), diff --git a/src/Models/Booking.php b/src/Models/Booking.php index 8537170..ecc71c3 100644 --- a/src/Models/Booking.php +++ b/src/Models/Booking.php @@ -101,15 +101,18 @@ class Booking $steuerart = 'normal'; } + $assetId = isset($data['asset_id']) && $data['asset_id'] !== '' ? (int)$data['asset_id'] : null; + Database::execute( - 'INSERT INTO bookings (buchungs_nr, beleg_id, buchungs_datum, buchungstyp, + 'INSERT INTO bookings (buchungs_nr, beleg_id, asset_id, buchungs_datum, buchungstyp, kategorie_konto_id, zahlungskonto_id, betrag_netto, ust_satz, steuerart, betrag_ust, betrag_brutto, buchungstext, fiscal_year_id) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [ $nr, (int)$data['beleg_id'], + $assetId, $data['buchungs_datum'], $data['buchungstyp'], (int)$data['kategorie_konto_id'], diff --git a/src/Views/belege/detail.php b/src/Views/belege/detail.php index 5fbab21..6996f97 100644 --- a/src/Views/belege/detail.php +++ b/src/Views/belege/detail.php @@ -496,7 +496,6 @@ $suppliers = $suppliers ?? [];