Steuerstatus und Steuersatz in Kostenkarte wiederherstellen
This commit is contained in:
1 parent
bae293ad94
commit
af235987ea
5 files changed
+39
-22
No files matched your search
@@ -1358,34 +1358,45 @@ function market_management_update_cost_item(PDO $pdo, int $costItemId, array $in
|
||||
|
||||
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
|
||||
'SELECT id, gross_amount, tax_status, tax_rate, description 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) {
|
||||
$existingItem = $itemStmt->fetch();
|
||||
if (!is_array($existingItem)) {
|
||||
$grossAmount = market_management_optional_number($input, 'gross_cost') ?? '0.00';
|
||||
$taxStatus = trim((string) ($input['tax_status'] ?? 'taxable'));
|
||||
$taxRate = market_management_optional_number($input, 'tax_rate') ?? ($taxStatus === 'tax_free' ? '0.00' : '8.10');
|
||||
$item = market_management_create_cost_item($pdo, [
|
||||
'occurrence_id' => $occurrenceId,
|
||||
'cost_type_id' => market_management_get_cost_type_id($pdo, 'stand_fee'),
|
||||
'description' => $description,
|
||||
'description' => array_key_exists('cost_items_text', $input) ? market_management_optional_string($input, 'cost_items_text') : null,
|
||||
'gross_amount' => $grossAmount,
|
||||
'tax_status' => 'taxable',
|
||||
'tax_rate' => 8.10,
|
||||
'tax_status' => $taxStatus,
|
||||
'tax_rate' => $taxRate,
|
||||
]);
|
||||
} else {
|
||||
$item = market_management_update_cost_item($pdo, (int) $itemId, [
|
||||
'description' => $description,
|
||||
'gross_amount' => $grossAmount,
|
||||
]);
|
||||
$costFields = [];
|
||||
if (array_key_exists('gross_cost', $input)) {
|
||||
$costFields['gross_amount'] = market_management_optional_number($input, 'gross_cost');
|
||||
}
|
||||
if (array_key_exists('cost_items_text', $input)) {
|
||||
$costFields['description'] = market_management_optional_string($input, 'cost_items_text');
|
||||
}
|
||||
if (array_key_exists('tax_status', $input)) {
|
||||
$costFields['tax_status'] = trim((string) $input['tax_status']);
|
||||
if ($costFields['tax_status'] === 'tax_free' && !array_key_exists('tax_rate', $input)) {
|
||||
$costFields['tax_rate'] = '0.00';
|
||||
}
|
||||
}
|
||||
if (array_key_exists('tax_rate', $input)) {
|
||||
$costFields['tax_rate'] = market_management_optional_number($input, 'tax_rate');
|
||||
}
|
||||
$item = $costFields === []
|
||||
? (array) $existingItem
|
||||
: market_management_update_cost_item($pdo, (int) $existingItem['id'], $costFields);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
Reference in new issue
Block a user