mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Controllers adjusted for use with person or household
This commit is contained in:
@@ -15,6 +15,7 @@ use Chill\BudgetBundle\Calculator\CalculatorManager;
|
||||
use Chill\BudgetBundle\Entity\Charge;
|
||||
use Chill\BudgetBundle\Entity\Resource;
|
||||
use Chill\BudgetBundle\Security\Authorization\BudgetElementVoter;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -28,25 +29,13 @@ use function count;
|
||||
|
||||
class ElementController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var CalculatorManager
|
||||
*/
|
||||
protected $calculator;
|
||||
protected CalculatorManager $calculator;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $chillMainLogger;
|
||||
protected LoggerInterface $chillMainLogger;
|
||||
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
protected $em;
|
||||
protected EntityManagerInterface $em;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
protected TranslatorInterface $translator;
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $em,
|
||||
@@ -68,11 +57,12 @@ class ElementController extends Controller
|
||||
*/
|
||||
public function indexAction(Person $person)
|
||||
{
|
||||
// $this->denyAccessUnlessGranted(BudgetElementVoter::SHOW, $person);
|
||||
$this->denyAccessUnlessGranted(BudgetElementVoter::SEE, $person);
|
||||
|
||||
$charges = $this->em
|
||||
->getRepository(Charge::class)
|
||||
->findByPerson($person);
|
||||
|
||||
$ressources = $this->em
|
||||
->getRepository(Resource::class)
|
||||
->findByPerson($person);
|
||||
@@ -81,10 +71,10 @@ class ElementController extends Controller
|
||||
|
||||
$actualCharges = $this->em
|
||||
->getRepository(Charge::class)
|
||||
->findByPersonAndDate($person, $now);
|
||||
->findByEntityAndDate($person, $now);
|
||||
$actualResources = $this->em
|
||||
->getRepository(Resource::class)
|
||||
->findByPersonAndDate($person, $now);
|
||||
->findByEntityAndDate($person, $now);
|
||||
|
||||
$elements = array_merge($actualCharges, $actualResources);
|
||||
|
||||
@@ -92,11 +82,52 @@ class ElementController extends Controller
|
||||
$results = $this->calculator->calculateDefault($elements);
|
||||
}
|
||||
|
||||
return $this->render('ChillBudgetBundle:Element:index.html.twig', [
|
||||
return $this->render('ChillBudgetBundle:Person:index.html.twig', [
|
||||
'person' => $person,
|
||||
'charges' => $charges,
|
||||
'resources' => $ressources,
|
||||
'results' => $results ?? [],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "{_locale}/budget/elements/by-household/{id}",
|
||||
* name="chill_budget_elements_household_index"
|
||||
* )
|
||||
*/
|
||||
public function indexHouseholdAction(Household $household)
|
||||
{
|
||||
// $this->denyAccessUnlessGranted(BudgetElementVoter::SEE, $household);
|
||||
|
||||
$charges = $this->em
|
||||
->getRepository(Charge::class)
|
||||
->findByHousehold($household);
|
||||
|
||||
$ressources = $this->em
|
||||
->getRepository(Resource::class)
|
||||
->findByHousehold($household);
|
||||
|
||||
$now = new DateTime('now');
|
||||
|
||||
$actualCharges = $this->em
|
||||
->getRepository(Charge::class)
|
||||
->findByEntityAndDate($household, $now);
|
||||
$actualResources = $this->em
|
||||
->getRepository(Resource::class)
|
||||
->findByEntityAndDate($household, $now);
|
||||
|
||||
$elements = array_merge($actualCharges, $actualResources);
|
||||
|
||||
if (count($elements) > 0) {
|
||||
$results = $this->calculator->calculateDefault($elements);
|
||||
}
|
||||
|
||||
return $this->render('ChillBudgetBundle:Household:index.html.twig', [
|
||||
'household' => $household,
|
||||
'charges' => $charges,
|
||||
'resources' => $ressources,
|
||||
'results' => $results ?? [],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user