diff --git a/src/Bundle/ChillBudgetBundle/Controller/ElementController.php b/src/Bundle/ChillBudgetBundle/Controller/ElementController.php index e7dcd4bbf..ad3730b1a 100644 --- a/src/Bundle/ChillBudgetBundle/Controller/ElementController.php +++ b/src/Bundle/ChillBudgetBundle/Controller/ElementController.php @@ -19,6 +19,7 @@ use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Person; use DateTime; use Doctrine\ORM\EntityManagerInterface; +use Monolog\DateTimeImmutable; use Psr\Log\LoggerInterface; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -123,10 +124,34 @@ class ElementController extends AbstractController $results = $this->calculator->calculateDefault($elements); } + // quick solution to calculate the sum, difference and amount from + // controller. This should be done from the calculators + // TODO replace this by calculators + $wholeCharges = $actualCharges; + $wholeResources = $actualResources; + foreach ($household->getCurrentPersons() as $person) { + $wholeCharges = array_merge( + $wholeCharges, + $this->em + ->getRepository(Charge::class) + ->findByEntityAndDate($person, $now)); + $wholeResources = array_merge( + $wholeResources, + $this->em + ->getRepository(Resource::class) + ->findByEntityAndDate($person, $now)); + } + return $this->render('ChillBudgetBundle:Household:index.html.twig', [ 'household' => $household, 'charges' => $charges, 'resources' => $ressources, + 'wholeResources' => array_filter($wholeResources, function (Resource $r) use ($now) { + return $r->getStartDate() <= $now and ($r->getEndDate() === null or $r->getEndDate() >= $now); + }), + 'wholeCharges' => array_filter($wholeCharges, function (Charge $c) use ($now) { + return $c->getStartDate() <= $now and ($c->getEndDate() === null or $c->getEndDate() >= $now); + }), 'results' => $results ?? [], ]); } diff --git a/src/Bundle/ChillBudgetBundle/Menu/PersonMenuBuilder.php b/src/Bundle/ChillBudgetBundle/Menu/PersonMenuBuilder.php index bd8434a9f..047185b18 100644 --- a/src/Bundle/ChillBudgetBundle/Menu/PersonMenuBuilder.php +++ b/src/Bundle/ChillBudgetBundle/Menu/PersonMenuBuilder.php @@ -36,16 +36,16 @@ class PersonMenuBuilder implements LocalMenuBuilderInterface /** @var Person $person */ $person = $parameters['person']; - // if ($this->authorizationChecker->isGranted(BudgetElementVoter::SHOW, $person)) { - $menu->addChild( - $this->translator->trans('Budget'), - [ - 'route' => 'chill_budget_elements_index', - 'routeParameters' => ['id' => $person->getId()], - ] - ) - ->setExtra('order', 4000); - // } + if ($this->authorizationChecker->isGranted(BudgetElementVoter::SEE, $person)) { + $menu->addChild( + $this->translator->trans('Budget'), + [ + 'route' => 'chill_budget_elements_index', + 'routeParameters' => ['id' => $person->getId()], + ] + ) + ->setExtra('order', 4000); + } } public static function getMenuIds(): array diff --git a/src/Bundle/ChillBudgetBundle/Repository/ResourceRepository.php b/src/Bundle/ChillBudgetBundle/Repository/ResourceRepository.php index d82ce7a52..090d2893e 100644 --- a/src/Bundle/ChillBudgetBundle/Repository/ResourceRepository.php +++ b/src/Bundle/ChillBudgetBundle/Repository/ResourceRepository.php @@ -30,8 +30,11 @@ class ResourceRepository extends EntityRepository $entityStr = $entity instanceof Person ? 'person' : 'household'; $qb->where("c.{$entityStr} = :{$entityStr}") - ->andWhere('c.startDate < :date') - ->andWhere('c.startDate < :date OR c.startDate IS NULL'); + // TODO: in controller, the budget and charges asked are also for future and actual + //->andWhere('c.startDate < :date') + // TODO: there is a misconception here, the end date must be lower or null. startDate are never null + //->andWhere('c.startDate < :date OR c.startDate IS NULL'); + ; if (null !== $sort) { $qb->orderBy($sort); @@ -39,7 +42,7 @@ class ResourceRepository extends EntityRepository $qb->setParameters([ $entityStr => $entity, - 'date' => $date, + //'date' => $date, ]); return $qb->getQuery()->getResult(); diff --git a/src/Bundle/ChillBudgetBundle/Resources/views/Budget/_budget.html.twig b/src/Bundle/ChillBudgetBundle/Resources/views/Budget/_budget.html.twig index b1e9cf9f7..6e248bf0c 100644 --- a/src/Bundle/ChillBudgetBundle/Resources/views/Budget/_budget.html.twig +++ b/src/Bundle/ChillBudgetBundle/Resources/views/Budget/_budget.html.twig @@ -32,65 +32,43 @@ {% endif %} {% endfor %} -{% if resources|length == 0 and charges|length == 0 %} - {#
{{ "There isn't any element recorded"|trans }}
-{{ "There isn't any element recorded"|trans }}
-{{ "There isn't any element recorded"|trans }}
{{ "There isn't any element recorded"|trans }}
-{{ "There isn't any element recorded"|trans }}
-