Feature: Anlageart-Spalte (FK auf accounts) in assets hinzugefügt
This commit is contained in:
parent
921ba57419
commit
f77b228fdb
5 changed files with 72 additions and 18 deletions
6
migrations/029_assets_anlageart.sql
Normal file
6
migrations/029_assets_anlageart.sql
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-- Migration 029: Anlageart (Kontonummer) zu assets hinzufügen
|
||||
ALTER TABLE assets
|
||||
ADD COLUMN account_id INT UNSIGNED NULL
|
||||
COMMENT 'FK auf accounts – Anlagevermögenskonto (Anlageart)'
|
||||
AFTER bezeichnung,
|
||||
ADD KEY idx_assets_account (account_id);
|
||||
|
|
@ -32,6 +32,7 @@ class AssetController
|
|||
'asset' => [],
|
||||
'errors' => [],
|
||||
'action' => '/assets',
|
||||
'anlagearten' => Asset::anlagearten(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
|
@ -49,6 +50,7 @@ class AssetController
|
|||
'asset' => $data,
|
||||
'errors' => $errors,
|
||||
'action' => '/assets',
|
||||
'anlagearten' => Asset::anlagearten(),
|
||||
]),
|
||||
]);
|
||||
return;
|
||||
|
|
@ -70,6 +72,7 @@ class AssetController
|
|||
'asset' => $asset,
|
||||
'errors' => [],
|
||||
'action' => '/assets/' . $asset['id'],
|
||||
'anlagearten' => Asset::anlagearten(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
|
@ -91,6 +94,7 @@ class AssetController
|
|||
'asset' => array_merge($asset, $data),
|
||||
'errors' => $errors,
|
||||
'action' => '/assets/' . $id,
|
||||
'anlagearten' => Asset::anlagearten(),
|
||||
]),
|
||||
]);
|
||||
return;
|
||||
|
|
@ -115,6 +119,7 @@ class AssetController
|
|||
{
|
||||
return [
|
||||
'bezeichnung' => trim($_POST['bezeichnung'] ?? ''),
|
||||
'account_id' => trim($_POST['account_id'] ?? ''),
|
||||
'anschaffungsdatum' => trim($_POST['anschaffungsdatum'] ?? ''),
|
||||
'anschaffungskosten' => $_POST['anschaffungskosten'] ?? '0',
|
||||
'zugaenge' => $_POST['zugaenge'] ?? '0',
|
||||
|
|
|
|||
|
|
@ -14,19 +14,38 @@ class Asset
|
|||
$params = [];
|
||||
|
||||
if ($fiscalYearId !== null) {
|
||||
$where = 'fiscal_year_id = ?';
|
||||
$where = 'a.fiscal_year_id = ?';
|
||||
$params[] = $fiscalYearId;
|
||||
}
|
||||
|
||||
return Database::fetchAll(
|
||||
"SELECT * FROM assets WHERE $where ORDER BY lfd_nr ASC, id ASC",
|
||||
"SELECT a.*, ac.kontonummer AS anlageart_kontonummer, ac.bezeichnung AS anlageart_bezeichnung
|
||||
FROM assets a
|
||||
LEFT JOIN accounts ac ON a.account_id = ac.id
|
||||
WHERE $where
|
||||
ORDER BY a.lfd_nr ASC, a.id ASC",
|
||||
$params
|
||||
);
|
||||
}
|
||||
|
||||
public static function find(int $id): array|false
|
||||
{
|
||||
return Database::fetchOne('SELECT * FROM assets WHERE id = ?', [$id]);
|
||||
return Database::fetchOne(
|
||||
'SELECT a.*, ac.kontonummer AS anlageart_kontonummer, ac.bezeichnung AS anlageart_bezeichnung
|
||||
FROM assets a
|
||||
LEFT JOIN accounts ac ON a.account_id = ac.id
|
||||
WHERE a.id = ?',
|
||||
[$id]
|
||||
);
|
||||
}
|
||||
|
||||
public static function anlagearten(): array
|
||||
{
|
||||
return Database::fetchAll(
|
||||
"SELECT id, kontonummer, bezeichnung FROM accounts
|
||||
WHERE kontenart = 'Anlagevermögen'
|
||||
ORDER BY kontonummer ASC"
|
||||
);
|
||||
}
|
||||
|
||||
public static function nextLfdNr(): int
|
||||
|
|
@ -46,12 +65,13 @@ class Asset
|
|||
|
||||
Database::execute(
|
||||
'INSERT INTO assets
|
||||
(lfd_nr, bezeichnung, anschaffungsdatum, anschaffungskosten,
|
||||
(lfd_nr, bezeichnung, account_id, anschaffungsdatum, anschaffungskosten,
|
||||
zugaenge, abgaenge, abschreibung_jahr, nutzungsdauer, notizen, fiscal_year_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
[
|
||||
$data['lfd_nr'] ?? self::nextLfdNr(),
|
||||
$data['bezeichnung'],
|
||||
isset($data['account_id']) && $data['account_id'] !== '' ? (int)$data['account_id'] : null,
|
||||
$data['anschaffungsdatum'],
|
||||
$data['anschaffungskosten'] ?? 0,
|
||||
$data['zugaenge'] ?? 0,
|
||||
|
|
@ -77,6 +97,7 @@ class Asset
|
|||
Database::execute(
|
||||
'UPDATE assets SET
|
||||
bezeichnung = ?,
|
||||
account_id = ?,
|
||||
anschaffungsdatum = ?,
|
||||
anschaffungskosten = ?,
|
||||
zugaenge = ?,
|
||||
|
|
@ -89,6 +110,7 @@ class Asset
|
|||
WHERE id = ?',
|
||||
[
|
||||
$data['bezeichnung'],
|
||||
isset($data['account_id']) && $data['account_id'] !== '' ? (int)$data['account_id'] : null,
|
||||
$data['anschaffungsdatum'],
|
||||
$data['anschaffungskosten'] ?? 0,
|
||||
$data['zugaenge'] ?? 0,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,19 @@
|
|||
<div class="card-body">
|
||||
<form method="post" action="<?= $h($action) ?>">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="account_id">Anlageart (Konto)</label>
|
||||
<select id="account_id" name="account_id">
|
||||
<option value="">– bitte wählen –</option>
|
||||
<?php foreach ($anlagearten as $kto): ?>
|
||||
<option value="<?= $h($kto['id']) ?>"
|
||||
<?= (string)($asset['account_id'] ?? '') === (string)$kto['id'] ? 'selected' : '' ?>>
|
||||
<?= $h($kto['kontonummer']) ?> – <?= $h($kto['bezeichnung']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="bezeichnung">Bezeichnung des Wirtschaftsguts *</label>
|
||||
<input type="text" id="bezeichnung" name="bezeichnung"
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
<tr>
|
||||
<th style="width:4rem">Nr.</th>
|
||||
<th>Anschaffungsdatum</th>
|
||||
<th>Anlageart</th>
|
||||
<th>Wirtschaftsgut</th>
|
||||
<th class="td-num">Anschaffungskosten</th>
|
||||
<th class="td-num">Zugänge</th>
|
||||
|
|
@ -20,6 +21,13 @@
|
|||
<tr>
|
||||
<td class="td-mono text-sm"><?= $h($a['lfd_nr']) ?></td>
|
||||
<td class="td-muted text-sm"><?= View::formatDate($a['anschaffungsdatum']) ?></td>
|
||||
<td class="td-muted text-sm">
|
||||
<?php if ($a['anlageart_kontonummer']): ?>
|
||||
<?= $h($a['anlageart_kontonummer']) ?> <?= $h($a['anlageart_bezeichnung']) ?>
|
||||
<?php else: ?>
|
||||
<span class="text-muted">–</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?= $h($a['bezeichnung']) ?></td>
|
||||
<td class="td-num"><?= number_format((float)$a['anschaffungskosten'], 2, ',', '.') ?> €</td>
|
||||
<td class="td-num"><?= number_format((float)$a['zugaenge'], 2, ',', '.') ?> €</td>
|
||||
|
|
@ -46,7 +54,7 @@
|
|||
<?php endforeach; ?>
|
||||
<?php if (empty($assets)): ?>
|
||||
<tr>
|
||||
<td colspan="8" class="text-center text-muted" style="padding:2rem">
|
||||
<td colspan="9" class="text-center text-muted" style="padding:2rem">
|
||||
Noch keine Wirtschaftsgüter angelegt.
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue