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);
|
||||||
|
|
@ -29,9 +29,10 @@ class AssetController
|
||||||
$view->render('layout/base.php', [
|
$view->render('layout/base.php', [
|
||||||
'pageTitle' => 'Wirtschaftsgut anlegen',
|
'pageTitle' => 'Wirtschaftsgut anlegen',
|
||||||
'content' => $this->renderView('assets/form', [
|
'content' => $this->renderView('assets/form', [
|
||||||
'asset' => [],
|
'asset' => [],
|
||||||
'errors' => [],
|
'errors' => [],
|
||||||
'action' => '/assets',
|
'action' => '/assets',
|
||||||
|
'anlagearten' => Asset::anlagearten(),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
@ -46,9 +47,10 @@ class AssetController
|
||||||
$view->render('layout/base.php', [
|
$view->render('layout/base.php', [
|
||||||
'pageTitle' => 'Wirtschaftsgut anlegen',
|
'pageTitle' => 'Wirtschaftsgut anlegen',
|
||||||
'content' => $this->renderView('assets/form', [
|
'content' => $this->renderView('assets/form', [
|
||||||
'asset' => $data,
|
'asset' => $data,
|
||||||
'errors' => $errors,
|
'errors' => $errors,
|
||||||
'action' => '/assets',
|
'action' => '/assets',
|
||||||
|
'anlagearten' => Asset::anlagearten(),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
return;
|
return;
|
||||||
|
|
@ -67,9 +69,10 @@ class AssetController
|
||||||
$view->render('layout/base.php', [
|
$view->render('layout/base.php', [
|
||||||
'pageTitle' => 'Wirtschaftsgut bearbeiten',
|
'pageTitle' => 'Wirtschaftsgut bearbeiten',
|
||||||
'content' => $this->renderView('assets/form', [
|
'content' => $this->renderView('assets/form', [
|
||||||
'asset' => $asset,
|
'asset' => $asset,
|
||||||
'errors' => [],
|
'errors' => [],
|
||||||
'action' => '/assets/' . $asset['id'],
|
'action' => '/assets/' . $asset['id'],
|
||||||
|
'anlagearten' => Asset::anlagearten(),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
@ -88,9 +91,10 @@ class AssetController
|
||||||
$view->render('layout/base.php', [
|
$view->render('layout/base.php', [
|
||||||
'pageTitle' => 'Wirtschaftsgut bearbeiten',
|
'pageTitle' => 'Wirtschaftsgut bearbeiten',
|
||||||
'content' => $this->renderView('assets/form', [
|
'content' => $this->renderView('assets/form', [
|
||||||
'asset' => array_merge($asset, $data),
|
'asset' => array_merge($asset, $data),
|
||||||
'errors' => $errors,
|
'errors' => $errors,
|
||||||
'action' => '/assets/' . $id,
|
'action' => '/assets/' . $id,
|
||||||
|
'anlagearten' => Asset::anlagearten(),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
return;
|
return;
|
||||||
|
|
@ -115,6 +119,7 @@ class AssetController
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'bezeichnung' => trim($_POST['bezeichnung'] ?? ''),
|
'bezeichnung' => trim($_POST['bezeichnung'] ?? ''),
|
||||||
|
'account_id' => trim($_POST['account_id'] ?? ''),
|
||||||
'anschaffungsdatum' => trim($_POST['anschaffungsdatum'] ?? ''),
|
'anschaffungsdatum' => trim($_POST['anschaffungsdatum'] ?? ''),
|
||||||
'anschaffungskosten' => $_POST['anschaffungskosten'] ?? '0',
|
'anschaffungskosten' => $_POST['anschaffungskosten'] ?? '0',
|
||||||
'zugaenge' => $_POST['zugaenge'] ?? '0',
|
'zugaenge' => $_POST['zugaenge'] ?? '0',
|
||||||
|
|
|
||||||
|
|
@ -14,19 +14,38 @@ class Asset
|
||||||
$params = [];
|
$params = [];
|
||||||
|
|
||||||
if ($fiscalYearId !== null) {
|
if ($fiscalYearId !== null) {
|
||||||
$where = 'fiscal_year_id = ?';
|
$where = 'a.fiscal_year_id = ?';
|
||||||
$params[] = $fiscalYearId;
|
$params[] = $fiscalYearId;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Database::fetchAll(
|
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
|
$params
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function find(int $id): array|false
|
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
|
public static function nextLfdNr(): int
|
||||||
|
|
@ -46,12 +65,13 @@ class Asset
|
||||||
|
|
||||||
Database::execute(
|
Database::execute(
|
||||||
'INSERT INTO assets
|
'INSERT INTO assets
|
||||||
(lfd_nr, bezeichnung, anschaffungsdatum, anschaffungskosten,
|
(lfd_nr, bezeichnung, account_id, anschaffungsdatum, anschaffungskosten,
|
||||||
zugaenge, abgaenge, abschreibung_jahr, nutzungsdauer, notizen, fiscal_year_id)
|
zugaenge, abgaenge, abschreibung_jahr, nutzungsdauer, notizen, fiscal_year_id)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||||
[
|
[
|
||||||
$data['lfd_nr'] ?? self::nextLfdNr(),
|
$data['lfd_nr'] ?? self::nextLfdNr(),
|
||||||
$data['bezeichnung'],
|
$data['bezeichnung'],
|
||||||
|
isset($data['account_id']) && $data['account_id'] !== '' ? (int)$data['account_id'] : null,
|
||||||
$data['anschaffungsdatum'],
|
$data['anschaffungsdatum'],
|
||||||
$data['anschaffungskosten'] ?? 0,
|
$data['anschaffungskosten'] ?? 0,
|
||||||
$data['zugaenge'] ?? 0,
|
$data['zugaenge'] ?? 0,
|
||||||
|
|
@ -77,6 +97,7 @@ class Asset
|
||||||
Database::execute(
|
Database::execute(
|
||||||
'UPDATE assets SET
|
'UPDATE assets SET
|
||||||
bezeichnung = ?,
|
bezeichnung = ?,
|
||||||
|
account_id = ?,
|
||||||
anschaffungsdatum = ?,
|
anschaffungsdatum = ?,
|
||||||
anschaffungskosten = ?,
|
anschaffungskosten = ?,
|
||||||
zugaenge = ?,
|
zugaenge = ?,
|
||||||
|
|
@ -89,6 +110,7 @@ class Asset
|
||||||
WHERE id = ?',
|
WHERE id = ?',
|
||||||
[
|
[
|
||||||
$data['bezeichnung'],
|
$data['bezeichnung'],
|
||||||
|
isset($data['account_id']) && $data['account_id'] !== '' ? (int)$data['account_id'] : null,
|
||||||
$data['anschaffungsdatum'],
|
$data['anschaffungsdatum'],
|
||||||
$data['anschaffungskosten'] ?? 0,
|
$data['anschaffungskosten'] ?? 0,
|
||||||
$data['zugaenge'] ?? 0,
|
$data['zugaenge'] ?? 0,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,19 @@
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form method="post" action="<?= $h($action) ?>">
|
<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">
|
<div class="form-group">
|
||||||
<label for="bezeichnung">Bezeichnung des Wirtschaftsguts *</label>
|
<label for="bezeichnung">Bezeichnung des Wirtschaftsguts *</label>
|
||||||
<input type="text" id="bezeichnung" name="bezeichnung"
|
<input type="text" id="bezeichnung" name="bezeichnung"
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th style="width:4rem">Nr.</th>
|
<th style="width:4rem">Nr.</th>
|
||||||
<th>Anschaffungsdatum</th>
|
<th>Anschaffungsdatum</th>
|
||||||
|
<th>Anlageart</th>
|
||||||
<th>Wirtschaftsgut</th>
|
<th>Wirtschaftsgut</th>
|
||||||
<th class="td-num">Anschaffungskosten</th>
|
<th class="td-num">Anschaffungskosten</th>
|
||||||
<th class="td-num">Zugänge</th>
|
<th class="td-num">Zugänge</th>
|
||||||
|
|
@ -20,6 +21,13 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td class="td-mono text-sm"><?= $h($a['lfd_nr']) ?></td>
|
<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"><?= 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><?= $h($a['bezeichnung']) ?></td>
|
||||||
<td class="td-num"><?= number_format((float)$a['anschaffungskosten'], 2, ',', '.') ?> €</td>
|
<td class="td-num"><?= number_format((float)$a['anschaffungskosten'], 2, ',', '.') ?> €</td>
|
||||||
<td class="td-num"><?= number_format((float)$a['zugaenge'], 2, ',', '.') ?> €</td>
|
<td class="td-num"><?= number_format((float)$a['zugaenge'], 2, ',', '.') ?> €</td>
|
||||||
|
|
@ -46,7 +54,7 @@
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php if (empty($assets)): ?>
|
<?php if (empty($assets)): ?>
|
||||||
<tr>
|
<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.
|
Noch keine Wirtschaftsgüter angelegt.
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue