add budget to docgen

This commit is contained in:
2022-03-24 18:22:49 +01:00
parent 531f940b65
commit 84f9fdba28
8 changed files with 199 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Serializer\Normalizer;
use Chill\BudgetBundle\Service\Summary\SummaryBudget;
use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Civility;
@@ -44,6 +45,8 @@ class PersonDocGenNormalizer implements
private RelationshipRepository $relationshipRepository;
private SummaryBudget $summaryBudget;
private TranslatableStringHelper $translatableStringHelper;
private TranslatorInterface $translator;
@@ -52,12 +55,14 @@ class PersonDocGenNormalizer implements
PersonRenderInterface $personRender,
RelationshipRepository $relationshipRepository,
TranslatorInterface $translator,
TranslatableStringHelper $translatableStringHelper
TranslatableStringHelper $translatableStringHelper,
SummaryBudget $summaryBudget
) {
$this->personRender = $personRender;
$this->relationshipRepository = $relationshipRepository;
$this->translator = $translator;
$this->translatableStringHelper = $translatableStringHelper;
$this->summaryBudget = $summaryBudget;
}
public function normalize($person, $format = null, array $context = [])
@@ -127,6 +132,7 @@ class PersonDocGenNormalizer implements
'docgen:expects' => Household::class,
'docgen:person:with-household' => false,
'docgen:person:with-relations' => false,
'docgen:person:with-budget' => false,
])
);
}
@@ -139,10 +145,19 @@ class PersonDocGenNormalizer implements
'docgen:person:with-household' => false,
'docgen:person:with-relation' => false,
'docgen:relationship:counterpart' => $person,
'docgen:person:with-budget' => false,
])
);
}
if ($context['docgen:person:with-budget'] ?? false) {
$data['budget']['person'] = $this->summaryBudget->getSummaryForPerson($person);
if ($context['docgen:person:with-household'] ?? false) {
$data['budget']['household'] = $this->summaryBudget->getSummaryForHousehold($person->getCurrentHousehold());
}
}
return $data;
}