Complete market occurrence drawer details

This commit is contained in:
gitea_admin committed 2026-09-19 12:59:14 +02:00
1 parent 16882207bb
commit 278e415e08
4 files changed
+57 -2

No files matched your search

+25 -1
View File
@@ -1,6 +1,8 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/../erp/kontakte/service.php';
require_once __DIR__ . '/../shared/db.php';
const MARKET_MANAGEMENT_STATUSES = [
@@ -523,10 +525,32 @@ function market_management_get_occurrence(PDO $pdo, int $occurrenceId, bool $inc
$occurrence['days'] = $days->fetchAll();
$organizer = $pdo->prepare('SELECT * FROM market_occurrence_organizer WHERE occurrence_id = :occurrence_id');
$organizer->execute([':occurrence_id' => $occurrenceId]);
$occurrence['organizer'] = $organizer->fetch() ?: null;
$organizer = $organizer->fetch();
if (is_array($organizer)) {
$organizer['organization'] = get_party_reference($pdo, (int) $organizer['organization_contact_id']);
$organizer['contact_person'] = get_contact_reference($pdo, (int) $organizer['contact_person_id']);
}
$occurrence['organizer'] = is_array($organizer) ? $organizer : null;
$costs = $pdo->prepare('SELECT * FROM market_occurrence_cost_item WHERE occurrence_id = :occurrence_id ORDER BY id ASC');
$costs->execute([':occurrence_id' => $occurrenceId]);
$occurrence['cost_items'] = $costs->fetchAll();
$costSummary = $pdo->prepare(
'SELECT COALESCE(SUM(gross_amount), 0) AS gross_amount,
COALESCE(SUM(net_amount), 0) AS net_amount,
COALESCE(SUM(tax_amount), 0) AS tax_amount
FROM market_occurrence_cost_item
WHERE occurrence_id = :occurrence_id'
);
$costSummary->execute([':occurrence_id' => $occurrenceId]);
$summary = $costSummary->fetch() ?: ['gross_amount' => 0, 'net_amount' => 0, 'tax_amount' => 0];
$occurrence['cost_summary'] = [
'gross_amount' => (float) ($summary['gross_amount'] ?? 0),
'net_amount' => (float) ($summary['net_amount'] ?? 0),
'tax_amount' => (float) ($summary['tax_amount'] ?? 0),
'open_amount' => $occurrence['paid_amount'] === null
? null
: round((float) $summary['gross_amount'] - (float) $occurrence['paid_amount'], 2),
];
return $occurrence;
}