Erweitere Marktmanagement-MCP fuer Durchfuehrungen

This commit is contained in:
gitea_admin committed 2026-09-19 08:51:17 +02:00
1 parent df5a533983
commit 3267a121de
3 files changed
+288

No files matched your search

+63
View File
@@ -442,3 +442,66 @@ function market_management_delete_day(PDO $pdo, int $dayId): array
}
return $day;
}
function market_management_set_organizer(PDO $pdo, array $input): array
{
$occurrenceId = market_management_require_positive_id($input['occurrence_id'] ?? null, 'occurrence_id');
$organizationId = market_management_require_positive_id($input['organization_contact_id'] ?? null, 'organization_contact_id');
$contactPersonId = market_management_require_positive_id($input['contact_person_id'] ?? null, 'contact_person_id');
$stmt = $pdo->prepare(
'INSERT INTO market_occurrence_organizer (occurrence_id, organization_contact_id, contact_person_id)
VALUES (:occurrence_id, :organization_contact_id, :contact_person_id)
ON CONFLICT (occurrence_id) DO UPDATE
SET organization_contact_id = EXCLUDED.organization_contact_id,
contact_person_id = EXCLUDED.contact_person_id,
updated_at = NOW()
RETURNING *'
);
$stmt->execute([
':occurrence_id' => $occurrenceId,
':organization_contact_id' => $organizationId,
':contact_person_id' => $contactPersonId,
]);
return (array) $stmt->fetch();
}
function market_management_create_cost_item(PDO $pdo, array $input): array
{
$occurrenceId = market_management_require_positive_id($input['occurrence_id'] ?? null, 'occurrence_id');
$costType = trim((string) ($input['cost_type'] ?? ''));
$grossAmount = market_management_optional_number($input, 'gross_amount');
$taxStatus = trim((string) ($input['tax_status'] ?? ''));
$taxRate = market_management_optional_number($input, 'tax_rate') ?? '0.00';
if ($costType === '' || $grossAmount === null || !in_array($taxStatus, ['tax_free', 'taxable'], true)) {
throw new InvalidArgumentException('cost_type, gross_amount und tax_status sind erforderlich.');
}
if (($taxStatus === 'tax_free' && $taxRate !== '0.00') || ($taxStatus === 'taxable' && (float) $taxRate <= 0)) {
throw new InvalidArgumentException('tax_rate passt nicht zu tax_status.');
}
$stmt = $pdo->prepare(
'INSERT INTO market_occurrence_cost_item
(occurrence_id, cost_type, description, gross_amount, tax_status, tax_rate)
VALUES (:occurrence_id, :cost_type, :description, :gross_amount, :tax_status, :tax_rate)
RETURNING *'
);
$stmt->execute([
':occurrence_id' => $occurrenceId,
':cost_type' => $costType,
':description' => market_management_optional_string($input, 'description'),
':gross_amount' => $grossAmount,
':tax_status' => $taxStatus,
':tax_rate' => $taxRate,
]);
return (array) $stmt->fetch();
}
function market_management_delete_cost_item(PDO $pdo, int $costItemId): array
{
$stmt = $pdo->prepare('DELETE FROM market_occurrence_cost_item WHERE id = :id RETURNING id, occurrence_id');
$stmt->execute([':id' => $costItemId]);
$item = $stmt->fetch();
if (!is_array($item)) {
throw new RuntimeException('Kostenposition nicht gefunden.');
}
return $item;
}