From 21ea0ced86d11b5ce60eb889c1d9e9d696f898d0 Mon Sep 17 00:00:00 2001 From: oskarimysteerio <43133397+oskarimysteerio@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:01:05 +0200 Subject: [PATCH] fix: AU-2213: Allow budget explantion to be saved without a value --- .../src/GrantsBudgetComponentService.php | 24 ++++++++++++++----- .../Definition/NuorisoLomaDefinition.php | 4 +++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/public/modules/custom/grants_budget_components/src/GrantsBudgetComponentService.php b/public/modules/custom/grants_budget_components/src/GrantsBudgetComponentService.php index e25f20b473..ec5e8e7f2e 100644 --- a/public/modules/custom/grants_budget_components/src/GrantsBudgetComponentService.php +++ b/public/modules/custom/grants_budget_components/src/GrantsBudgetComponentService.php @@ -88,15 +88,22 @@ public static function processBudgetOtherValues(ListInterface $property): array } $value = $values['value']; + $isEmptyValue = (is_null($value) || $value === ""); - if (is_null($value) || $value === "") { + if ($isEmptyValue && empty(trim($values['label']))) { continue; } + elseif ($isEmptyValue && $values['label']) { + $valueToSave = NULL; + } + else { + $valueToSave = (string) GrantsHandler::convertToFloat($value); + } $itemValues = [ 'ID' => $property->getName() . '_' . $index, 'label' => $values['label'] ?? NULL, - 'value' => (string) GrantsHandler::convertToFloat($value), + 'value' => $valueToSave, 'valueType' => 'double', ]; @@ -137,14 +144,19 @@ public static function getBudgetOtherValues(array $documentData, array $jsonPath if (!empty($parent) && isset($parent[$pathLast])) { $retVal[$groupName] = array_map(function ($e) { $value = GrantsHandler::convertToFloat($e['value']); - return [ - 'label' => $e['label'] ?? NULL, - 'value' => number_format( + + if ($value !== NULL) { + $value = number_format( $value, 2, ',', ' ', - ) ?? NULL, + ); + } + + return [ + 'label' => $e['label'] ?? NULL, + 'value' => $value, ]; }, $parent[$pathLast]); } diff --git a/public/modules/custom/grants_metadata/src/TypedData/Definition/NuorisoLomaDefinition.php b/public/modules/custom/grants_metadata/src/TypedData/Definition/NuorisoLomaDefinition.php index 111bdd69ac..848ae2c362 100644 --- a/public/modules/custom/grants_metadata/src/TypedData/Definition/NuorisoLomaDefinition.php +++ b/public/modules/custom/grants_metadata/src/TypedData/Definition/NuorisoLomaDefinition.php @@ -47,7 +47,9 @@ public function getPropertyDefinitions(): array { ->setPropertyDefinition( 'meno', GrantsBudgetInfoDefinition::getOtherCostDefinition() - ); + ) + ->setPropertyDefinition('budget_other_income') + ->setPropertyDefinition('budget_other_cost'); $info['lisakysymys_1'] = DataDefinition::create('string') ->setSetting('jsonPath', [