Kostenarten und geschützte Standkosten umsetzen
This commit is contained in:
1 parent
313475afec
commit
3a0cb81a97
7 files changed
+200
-17
No files matched your search
@@ -105,10 +105,27 @@ if ($requestMethod === 'POST') {
|
||||
throw new InvalidArgumentException('Kostenpositionen sind ungültig.');
|
||||
}
|
||||
unset($fields['cost_items']);
|
||||
$keptCostItemIds = array_values(array_filter(array_map(
|
||||
static fn (array $costItem): ?int => isset($costItem['id']) ? (int) $costItem['id'] : null,
|
||||
array_filter($costItems, 'is_array')
|
||||
)));
|
||||
$existingCostItems = $pdo->prepare('SELECT id FROM market_occurrence_cost_item WHERE occurrence_id = :occurrence_id ORDER BY id ASC');
|
||||
$existingCostItems->execute([':occurrence_id' => $id]);
|
||||
foreach ($existingCostItems->fetchAll(PDO::FETCH_COLUMN) as $existingCostItemId) {
|
||||
if (!in_array((int) $existingCostItemId, $keptCostItemIds, true)) {
|
||||
market_management_delete_cost_item($pdo, (int) $existingCostItemId);
|
||||
}
|
||||
}
|
||||
foreach ($costItems as $costItem) {
|
||||
if (!is_array($costItem)) {
|
||||
throw new InvalidArgumentException('Kostenposition ist ungültig.');
|
||||
}
|
||||
if (($costItem['cost_type_id'] ?? null) === '__new__') {
|
||||
$newCostTypeName = trim((string) ($costItem['cost_type_name'] ?? ''));
|
||||
$newCostType = market_management_create_cost_type($pdo, $newCostTypeName);
|
||||
$costItem['cost_type_id'] = (int) $newCostType['id'];
|
||||
}
|
||||
unset($costItem['cost_type_name']);
|
||||
if (isset($costItem['id'])) {
|
||||
$costItemId = market_management_require_positive_id($costItem['id'], 'cost_item_id');
|
||||
unset($costItem['id']);
|
||||
|
||||
Reference in new issue
Block a user