Kostenpositionen durch einfache Gesamtkosten ersetzen

This commit is contained in:
gitea_admin committed 2026-09-20 12:47:37 +02:00
1 parent c0c3c2600f
commit 1ad35cdcfd
9 files changed
+81 -146

No files matched your search

+13 -67
View File
@@ -43,10 +43,9 @@ if ($requestMethod === 'POST') {
echo json_encode(['ok' => true, 'occurrence_id' => (int) $occurrence['id']], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
}
$scope = (string) ($payload['scope'] ?? '');
$id = market_management_require_positive_id($payload['id'] ?? null, 'id');
$fields = is_array($payload['fields'] ?? null) ? $payload['fields'] : [];
$costTransactionStarted = false;
$scope = (string) ($payload['scope'] ?? '');
$id = market_management_require_positive_id($payload['id'] ?? null, 'id');
$fields = is_array($payload['fields'] ?? null) ? $payload['fields'] : [];
if (($payload['action'] ?? '') === 'delete') {
if (($payload['confirmation'] ?? '') !== 'DELETE') {
throw new InvalidArgumentException('Die Löschbestätigung muss exakt DELETE lauten.');
@@ -64,22 +63,6 @@ if ($requestMethod === 'POST') {
$day = market_management_delete_day($pdo, $id);
echo json_encode(['ok' => true, 'day' => $day]);
exit;
} elseif (($payload['action'] ?? '') === 'create_cost_item') {
$fields['occurrence_id'] = $id;
$costItem = market_management_create_cost_item($pdo, $fields);
echo json_encode(['ok' => true, 'cost_item' => $costItem], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
} elseif (($payload['action'] ?? '') === 'update_cost_item') {
$costItem = market_management_update_cost_item($pdo, $id, $fields);
echo json_encode(['ok' => true, 'cost_item' => $costItem], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
} elseif (($payload['action'] ?? '') === 'delete_cost_item') {
if (($payload['confirmation'] ?? '') !== 'DELETE') {
throw new InvalidArgumentException('Bestätigung muss exakt DELETE lauten.');
}
$costItem = market_management_delete_cost_item($pdo, $id);
echo json_encode(['ok' => true, 'cost_item' => $costItem], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
} elseif ($scope === 'day') {
market_management_update_day($pdo, $id, $fields);
} elseif (in_array($scope, ['occurrence', 'status', 'overview', 'participation', 'infrastructure', 'travel', 'notes'], true)) {
@@ -99,52 +82,18 @@ if ($requestMethod === 'POST') {
market_management_set_occurrence_contact($pdo, $contactFields);
}
if ($fields !== []) {
$costItems = null;
if (array_key_exists('cost_items', $fields)) {
$costItems = is_string($fields['cost_items']) ? json_decode($fields['cost_items'], true) : $fields['cost_items'];
if (!is_array($costItems)) {
throw new InvalidArgumentException('Kostenpositionen sind ungültig.');
}
if (!$pdo->inTransaction()) {
$pdo->beginTransaction();
$costTransactionStarted = true;
}
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']);
market_management_update_cost_item($pdo, $costItemId, $costItem);
} else {
$costItem['occurrence_id'] = $id;
market_management_create_cost_item($pdo, $costItem);
}
$simpleCostFields = [];
foreach (['gross_cost', 'cost_items_text'] as $costField) {
if (array_key_exists($costField, $fields)) {
$simpleCostFields[$costField] = $fields[$costField];
unset($fields[$costField]);
}
}
market_management_update_occurrence($pdo, $id, $fields);
if ($costTransactionStarted) {
$pdo->commit();
$costTransactionStarted = false;
if ($simpleCostFields !== []) {
market_management_update_occurrence_simple_costs($pdo, $id, $simpleCostFields);
}
if ($fields !== []) {
market_management_update_occurrence($pdo, $id, $fields);
}
}
} else {
@@ -153,9 +102,6 @@ if ($requestMethod === 'POST') {
echo json_encode(['ok' => true]);
exit;
} catch (Throwable $error) {
if ($costTransactionStarted && $pdo->inTransaction()) {
$pdo->rollBack();
}
http_response_code(422);
echo json_encode(['ok' => false, 'error' => $error->getMessage()], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
-17
View File
@@ -422,20 +422,3 @@ body.sg-lager-mobile-detail-open > :not([data-lager-mobile-detail-host]) {
[data-bestellungen-mobile-detail] .sg-navigation-card-layout {
margin-top: 0;
}
.sg-card-list-page-drawer .market-cost-item-delete-actions {
display: flex;
justify-content: flex-end;
margin-top: 0;
}
.sg-card-list-page-drawer [data-market-cost-item-add] {
display: block;
margin-left: auto;
}
.sg-card-list-page-drawer [data-market-cost-item-row] + [data-market-cost-item-row],
.sg-card-list-page-drawer [data-market-cost-item-row] + .sg-delete-confirmation-pattern__stage,
.sg-card-list-page-drawer .sg-delete-confirmation-pattern__stage + .sg-delete-confirmation-pattern__stage {
margin-top: calc(var(--spacing-large) * 2);
}