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

+11 -24
View File
@@ -40,6 +40,7 @@ function market_management_mcp_tools(): array
'payment_status' => ['type' => ['string', 'null'], 'enum' => ['paid', 'unpaid']],
'payment_date' => ['type' => ['string', 'null'], 'format' => 'date'], 'paid_amount' => ['type' => ['number', 'null']],
'payment_method_code' => ['type' => ['string', 'null']], 'stand_size' => ['type' => ['string', 'null']],
'gross_cost' => ['type' => ['number', 'null'], 'minimum' => 0], 'cost_items_text' => ['type' => ['string', 'null']],
'table_available' => ['type' => ['boolean', 'null']], 'table_rentable' => ['type' => ['boolean', 'null']],
'own_table_required' => ['type' => ['boolean', 'null']], 'shelter_available' => ['type' => ['boolean', 'null']],
'power_available' => ['type' => ['boolean', 'null']], 'water_available' => ['type' => ['boolean', 'null']],
@@ -82,8 +83,6 @@ function market_management_mcp_tools(): array
['name' => 'market_management.create_market_organizer', 'description' => 'Veranstalter mit optionalen Kontaktdaten anlegen', 'inputSchema' => ['type' => 'object', 'required' => ['name'], 'properties' => ['name' => ['type' => 'string'], 'email' => ['type' => ['string', 'null'], 'format' => 'email'], 'phone' => ['type' => ['string', 'null']]]]],
['name' => 'market_management.list_reference_data', 'description' => 'Kategorien, Kantone und Gemeinden lesen', 'inputSchema' => ['type' => 'object', 'properties' => []]],
['name' => 'market_management.create_municipality', 'description' => 'Lokale Gemeinde im Markt-Gemeinderegister anlegen', 'inputSchema' => ['type' => 'object', 'required' => ['name'], 'properties' => ['name' => ['type' => 'string']]]],
['name' => 'market_management.list_cost_types', 'description' => 'Aktive Kostenarten lesen', 'inputSchema' => ['type' => 'object', 'properties' => []]],
['name' => 'market_management.create_cost_type', 'description' => 'Kostenart anlegen', 'inputSchema' => ['type' => 'object', 'required' => ['name'], 'properties' => ['name' => ['type' => 'string'], 'code' => ['type' => 'string']]]],
['name' => 'market_management.get_overview', 'description' => 'Marktübersicht mit serverseitigen Filtern lesen', 'inputSchema' => ['type' => 'object', 'properties' => $searchProperties]],
['name' => 'market_management.create_occurrence', 'description' => 'Marktdurchführung mit mindestens einem Markttag anlegen', 'inputSchema' => ['type' => 'object', 'required' => ['market_definition_id', 'days'], 'properties' => ['market_definition_id' => ['type' => 'integer'], 'status' => ['type' => 'string'], 'days' => ['type' => 'array', 'minItems' => 1, 'items' => ['type' => 'object', 'required' => ['date'], 'properties' => $dayProperties]] + $occurrenceProperties]]],
['name' => 'market_management.get_occurrence', 'description' => 'Marktdurchführung mit Markt, Markttagen und berechneten Verkaufsdaten lesen', 'inputSchema' => ['type' => 'object', 'required' => ['occurrence_id'], 'properties' => ['occurrence_id' => ['type' => 'integer'], 'include_archived' => ['type' => 'boolean']]]],
@@ -93,9 +92,6 @@ function market_management_mcp_tools(): array
['name' => 'market_management.create_day', 'description' => 'Markttag anlegen', 'inputSchema' => ['type' => 'object', 'required' => ['occurrence_id', 'date'], 'properties' => ['occurrence_id' => ['type' => 'integer']] + $dayProperties]],
['name' => 'market_management.update_day', 'description' => 'Markttag ändern', 'inputSchema' => ['type' => 'object', 'required' => ['day_id'], 'properties' => ['day_id' => ['type' => 'integer']] + $dayProperties]],
['name' => 'market_management.delete_day', 'description' => 'Markttag entfernen', 'inputSchema' => ['type' => 'object', 'required' => ['day_id'], 'properties' => ['day_id' => ['type' => 'integer']]]],
['name' => 'market_management.create_cost_item', 'description' => 'Kostenposition anlegen', 'inputSchema' => ['type' => 'object', 'required' => ['occurrence_id', 'cost_type_id', 'gross_amount', 'tax_status'], 'properties' => ['occurrence_id' => ['type' => 'integer'], 'cost_type_id' => ['type' => 'integer'], 'description' => ['type' => ['string', 'null']], 'gross_amount' => ['type' => 'number'], 'tax_status' => ['type' => 'string', 'enum' => ['tax_free', 'taxable']], 'tax_rate' => ['type' => 'number']]]],
['name' => 'market_management.update_cost_item', 'description' => 'Kostenposition ändern', 'inputSchema' => ['type' => 'object', 'required' => ['cost_item_id'], 'properties' => ['cost_item_id' => ['type' => 'integer'], 'cost_type_id' => ['type' => 'integer'], 'description' => ['type' => ['string', 'null']], 'gross_amount' => ['type' => ['number', 'null']], 'tax_status' => ['type' => ['string', 'null'], 'enum' => ['tax_free', 'taxable']], 'tax_rate' => ['type' => ['number', 'null']]]]],
['name' => 'market_management.delete_cost_item', 'description' => 'Kostenposition entfernen', 'inputSchema' => ['type' => 'object', 'required' => ['cost_item_id'], 'properties' => ['cost_item_id' => ['type' => 'integer']]]],
];
}
@@ -105,13 +101,10 @@ function market_management_mcp_is_write_tool(string $tool): bool
'market_management.create_market', 'market_management.update_market',
'market_management.create_market_organizer',
'market_management.create_municipality',
'market_management.create_cost_type',
'market_management.archive_market', 'market_management.reactivate_market',
'market_management.create_occurrence', 'market_management.update_occurrence',
'market_management.archive_occurrence', 'market_management.reactivate_occurrence',
'market_management.create_day', 'market_management.update_day', 'market_management.delete_day',
'market_management.create_cost_item', 'market_management.update_cost_item',
'market_management.delete_cost_item',
], true);
}
@@ -222,6 +215,16 @@ function market_management_mcp_get_market(PDO $pdo, int $marketId, bool $include
function market_management_mcp_update_occurrence(PDO $pdo, int $occurrenceId, array $input): array
{
$simpleCostFields = [];
foreach (['gross_cost', 'cost_items_text'] as $field) {
if (array_key_exists($field, $input)) {
$simpleCostFields[$field] = $input[$field];
unset($input[$field]);
}
}
if ($simpleCostFields !== []) {
market_management_update_occurrence_simple_costs($pdo, $occurrenceId, $simpleCostFields);
}
$contactFields = [];
foreach (['contact_person_name', 'contact_email', 'contact_phone'] as $field) {
if (array_key_exists($field, $input)) {
@@ -285,12 +288,6 @@ function market_management_mcp_call(PDO $pdo, string $tool, array $arguments): a
$pdo,
(string) ($arguments['name'] ?? '')
),
'market_management.list_cost_types' => market_management_list_cost_types($pdo),
'market_management.create_cost_type' => market_management_create_cost_type(
$pdo,
(string) ($arguments['name'] ?? ''),
isset($arguments['code']) ? (string) $arguments['code'] : null
),
'market_management.get_overview' => [
'markets' => market_management_search_markets($pdo, $arguments),
'occurrences' => market_management_search_occurrences($pdo, $arguments),
@@ -326,16 +323,6 @@ function market_management_mcp_call(PDO $pdo, string $tool, array $arguments): a
$pdo,
market_management_require_positive_id($arguments['day_id'] ?? null, 'day_id')
),
'market_management.create_cost_item' => market_management_create_cost_item($pdo, $arguments),
'market_management.update_cost_item' => market_management_update_cost_item(
$pdo,
market_management_require_positive_id($arguments['cost_item_id'] ?? null, 'cost_item_id'),
$arguments
),
'market_management.delete_cost_item' => market_management_delete_cost_item(
$pdo,
market_management_require_positive_id($arguments['cost_item_id'] ?? null, 'cost_item_id')
),
default => throw new InvalidArgumentException('Unbekanntes MCP-Tool: ' . $tool),
};
}
+34
View File
@@ -1355,3 +1355,37 @@ function market_management_update_cost_item(PDO $pdo, int $costItemId, array $in
$item['cost_type'] = market_management_get_cost_type($pdo, (int) $item['cost_type_id'])['name'];
return $item;
}
function market_management_update_occurrence_simple_costs(PDO $pdo, int $occurrenceId, array $input): array
{
$grossAmount = market_management_optional_number($input, 'gross_cost');
if ($grossAmount === null) {
throw new InvalidArgumentException('Gesamtkosten sind erforderlich.');
}
$itemStmt = $pdo->prepare(
'SELECT id FROM market_occurrence_cost_item
WHERE occurrence_id = :occurrence_id
ORDER BY id ASC LIMIT 1'
);
$itemStmt->execute([':occurrence_id' => $occurrenceId]);
$itemId = $itemStmt->fetchColumn();
$description = array_key_exists('cost_items_text', $input)
? market_management_optional_string($input, 'cost_items_text')
: null;
if ($itemId === false) {
$item = market_management_create_cost_item($pdo, [
'occurrence_id' => $occurrenceId,
'cost_type_id' => market_management_get_cost_type_id($pdo, 'stand_fee'),
'description' => $description,
'gross_amount' => $grossAmount,
'tax_status' => 'taxable',
'tax_rate' => 8.10,
]);
} else {
$item = market_management_update_cost_item($pdo, (int) $itemId, [
'description' => $description,
'gross_amount' => $grossAmount,
]);
}
return $item;
}