mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Fixed: add string key for summary of charges and resources into doc generation
This commit is contained in:
@@ -14,7 +14,9 @@ namespace Chill\BudgetBundle\Service\Summary;
|
||||
use Chill\BudgetBundle\Entity\ChargeKind;
|
||||
use Chill\BudgetBundle\Entity\ResourceKind;
|
||||
use Chill\BudgetBundle\Repository\ChargeKindRepository;
|
||||
use Chill\BudgetBundle\Repository\ChargeKindRepositoryInterface;
|
||||
use Chill\BudgetBundle\Repository\ResourceKindRepository;
|
||||
use Chill\BudgetBundle\Repository\ResourceKindRepositoryInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
@@ -27,7 +29,7 @@ use function count;
|
||||
/**
|
||||
* Helps to find a summary of the budget: the sum of resources and charges.
|
||||
*/
|
||||
class SummaryBudget implements SummaryBudgetInterface
|
||||
final class SummaryBudget implements SummaryBudgetInterface
|
||||
{
|
||||
private const QUERY_CHARGE_BY_HOUSEHOLD = 'select SUM(amount) AS sum, string_agg(comment, \'|\') AS comment, charge_id AS kind_id FROM chill_budget.charge WHERE (person_id IN (_ids_) OR household_id = ?) AND NOW() BETWEEN startdate AND COALESCE(enddate, \'infinity\'::timestamp) GROUP BY charge_id';
|
||||
|
||||
@@ -37,23 +39,19 @@ class SummaryBudget implements SummaryBudgetInterface
|
||||
|
||||
private const QUERY_RESOURCE_BY_PERSON = 'select SUM(amount) AS sum, string_agg(comment, \'|\') AS comment, resource_id AS kind_id FROM chill_budget.resource WHERE person_id = ? AND NOW() BETWEEN startdate AND COALESCE(enddate, \'infinity\'::timestamp) GROUP BY resource_id';
|
||||
|
||||
private ChargeKindRepository $chargeKindRepository;
|
||||
|
||||
private array $chargeLabels;
|
||||
private ChargeKindRepositoryInterface $chargeKindRepository;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private ResourceKindRepository $resourceKindRepository;
|
||||
|
||||
private array $resourcesLabels;
|
||||
private ResourceKindRepositoryInterface $resourceKindRepository;
|
||||
|
||||
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $em,
|
||||
TranslatableStringHelperInterface $translatableStringHelper,
|
||||
ResourceKindRepository $resourceKindRepository,
|
||||
ChargeKindRepository $chargeKindRepository
|
||||
ResourceKindRepositoryInterface $resourceKindRepository,
|
||||
ChargeKindRepositoryInterface $chargeKindRepository
|
||||
) {
|
||||
$this->em = $em;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
@@ -129,19 +127,19 @@ class SummaryBudget implements SummaryBudgetInterface
|
||||
|
||||
private function getEmptyChargeArray(): array
|
||||
{
|
||||
$keys = array_map(static fn (ChargeKind $kind) => $kind->getId(), $this->chargeKindRepository->findAll());
|
||||
$keys = array_map(static fn (ChargeKind $kind) => $kind->getKind(), $this->chargeKindRepository->findAll());
|
||||
|
||||
return array_combine($keys, array_map(function ($id) {
|
||||
return ['sum' => 0.0, 'label' => $this->translatableStringHelper->localize($this->chargeKindRepository->find($id)->getName()), 'comment' => ''];
|
||||
return array_combine($keys, array_map(function ($kind) {
|
||||
return ['sum' => 0.0, 'label' => $this->translatableStringHelper->localize($this->chargeKindRepository->findOneByKind($kind)->getName()), 'comment' => ''];
|
||||
}, $keys));
|
||||
}
|
||||
|
||||
private function getEmptyResourceArray(): array
|
||||
{
|
||||
$keys = array_map(static fn (ResourceKind $kind) => $kind->getId(), $this->resourceKindRepository->findAll());
|
||||
$keys = array_map(static fn (ResourceKind $kind) => $kind->getKind(), $this->resourceKindRepository->findAll());
|
||||
|
||||
return array_combine($keys, array_map(function ($id) {
|
||||
return ['sum' => 0.0, 'label' => $this->translatableStringHelper->localize($this->resourceKindRepository->find($id)->getName()), 'comment' => ''];
|
||||
return array_combine($keys, array_map(function ($kind) {
|
||||
return ['sum' => 0.0, 'label' => $this->translatableStringHelper->localize($this->resourceKindRepository->findOneByKind($kind)->getName()), 'comment' => ''];
|
||||
}, $keys));
|
||||
}
|
||||
|
||||
@@ -152,10 +150,10 @@ class SummaryBudget implements SummaryBudgetInterface
|
||||
switch ($kind) {
|
||||
case 'charge':
|
||||
foreach ($rows as $row) {
|
||||
$chargeKind = $this->chargeKindRepository->find($row['kind_id']);
|
||||
$chargeKind = $this->chargeKindRepository->findOneByKind($row['kind_id']);
|
||||
|
||||
if (null === $chargeKind) {
|
||||
throw new RuntimeException('charge kind not found');
|
||||
throw new RuntimeException('charge kind not found: ' . $row['kind_id']);
|
||||
}
|
||||
$result[$chargeKind->getKind()] = [
|
||||
'sum' => (float) $row['sum'],
|
||||
@@ -168,10 +166,10 @@ class SummaryBudget implements SummaryBudgetInterface
|
||||
|
||||
case 'resource':
|
||||
foreach ($rows as $row) {
|
||||
$resourceKind = $this->resourceKindRepository->find($row['kind_id']);
|
||||
$resourceKind = $this->resourceKindRepository->findOneByKind($row['kind_id']);
|
||||
|
||||
if (null === $resourceKind) {
|
||||
throw new RuntimeException('charge kind not found');
|
||||
throw new RuntimeException('charge kind not found: ' . $row['kind_id']);
|
||||
}
|
||||
|
||||
$result[$resourceKind->getKind()] = [
|
||||
|
Reference in New Issue
Block a user