Feature: Asset-Verknüpfung in Buchung – Neu-Anlage oder Auswahl bei AV-Konten
This commit is contained in:
parent
05a964edbb
commit
f22d640e4e
4 changed files with 30 additions and 5 deletions
6
migrations/030_bookings_asset_id.sql
Normal file
6
migrations/030_bookings_asset_id.sql
Normal file
|
|
@ -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);
|
||||
|
|
@ -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,
|
||||
]),
|
||||
|
|
|
|||
|
|
@ -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'],
|
||||
|
|
|
|||
|
|
@ -496,7 +496,6 @@ $suppliers = $suppliers ?? [];
|
|||
<div class="modal" style="max-width:640px;width:100%">
|
||||
<div class="modal-header">
|
||||
<h3 class="modal-title">Anlagevermögen buchen</h3>
|
||||
<button type="button" class="modal-close" data-modal-close aria-label="Schließen">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p style="margin-bottom:1rem">Das gewählte Konto gehört zum Anlagevermögen. Soll ein neues Anlagegut angelegt oder ein bestehendes ausgewählt werden?</p>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue