mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
docgen normalization budget: fix budget when person is null
This commit is contained in:
@@ -23,7 +23,7 @@ use function count;
|
||||
/**
|
||||
* Helps to find a summary of the budget: the sum of resources and charges.
|
||||
*/
|
||||
class SummaryBudget
|
||||
class SummaryBudget implements SummaryBudgetInterface
|
||||
{
|
||||
private const QUERY_CHARGE_BY_HOUSEHOLD = 'select SUM(amount) AS sum, type FROM chill_budget.charge WHERE (person_id IN (_ids_) OR household_id = ?) AND NOW() BETWEEN startdate AND COALESCE(enddate, \'infinity\'::timestamp) GROUP BY type';
|
||||
|
||||
@@ -52,26 +52,6 @@ class SummaryBudget
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
public function getEmptyChargeArray(): array
|
||||
{
|
||||
$keys = $this->configRepository->getChargesKeys();
|
||||
$labels = $this->chargeLabels;
|
||||
|
||||
return array_combine($keys, array_map(function ($i) use ($labels) {
|
||||
return ['sum' => 0.0, 'label' => $this->translatableStringHelper->localize($labels[$i])];
|
||||
}, $keys));
|
||||
}
|
||||
|
||||
public function getEmptyResourceArray(): array
|
||||
{
|
||||
$keys = $this->configRepository->getResourcesKeys();
|
||||
$labels = $this->resourcesLabels;
|
||||
|
||||
return array_combine($keys, array_map(function ($i) use ($labels) {
|
||||
return ['sum' => 0.0, 'label' => $this->translatableStringHelper->localize($labels[$i])];
|
||||
}, $keys));
|
||||
}
|
||||
|
||||
public function getSummaryForHousehold(?Household $household): array
|
||||
{
|
||||
if (null === $household) {
|
||||
@@ -101,8 +81,15 @@ class SummaryBudget
|
||||
];
|
||||
}
|
||||
|
||||
public function getSummaryForPerson(Person $person): array
|
||||
public function getSummaryForPerson(?Person $person): array
|
||||
{
|
||||
if (null === $person) {
|
||||
return [
|
||||
'resources' => $this->getEmptyResourceArray(),
|
||||
'charges' => $this->getEmptyChargeArray(),
|
||||
];
|
||||
}
|
||||
|
||||
$rsm = $this->buildRsm();
|
||||
|
||||
$resources = $this->em->createNativeQuery(self::QUERY_RESOURCE_BY_PERSON, $rsm)
|
||||
@@ -128,6 +115,26 @@ class SummaryBudget
|
||||
return $rsm;
|
||||
}
|
||||
|
||||
private function getEmptyChargeArray(): array
|
||||
{
|
||||
$keys = $this->configRepository->getChargesKeys();
|
||||
$labels = $this->chargeLabels;
|
||||
|
||||
return array_combine($keys, array_map(function ($i) use ($labels) {
|
||||
return ['sum' => 0.0, 'label' => $this->translatableStringHelper->localize($labels[$i])];
|
||||
}, $keys));
|
||||
}
|
||||
|
||||
private function getEmptyResourceArray(): array
|
||||
{
|
||||
$keys = $this->configRepository->getResourcesKeys();
|
||||
$labels = $this->resourcesLabels;
|
||||
|
||||
return array_combine($keys, array_map(function ($i) use ($labels) {
|
||||
return ['sum' => 0.0, 'label' => $this->translatableStringHelper->localize($labels[$i])];
|
||||
}, $keys));
|
||||
}
|
||||
|
||||
private function rowToArray(array $rows, string $kind): array
|
||||
{
|
||||
switch ($kind) {
|
||||
|
Reference in New Issue
Block a user