mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fixes for budgets
This commit is contained in:
parent
ac12e75714
commit
0833bb49ca
@ -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 ?? [],
|
||||
]);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class PersonMenuBuilder implements LocalMenuBuilderInterface
|
||||
/** @var Person $person */
|
||||
$person = $parameters['person'];
|
||||
|
||||
// if ($this->authorizationChecker->isGranted(BudgetElementVoter::SHOW, $person)) {
|
||||
if ($this->authorizationChecker->isGranted(BudgetElementVoter::SEE, $person)) {
|
||||
$menu->addChild(
|
||||
$this->translator->trans('Budget'),
|
||||
[
|
||||
@ -45,7 +45,7 @@ class PersonMenuBuilder implements LocalMenuBuilderInterface
|
||||
]
|
||||
)
|
||||
->setExtra('order', 4000);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
public static function getMenuIds(): array
|
||||
|
@ -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();
|
||||
|
@ -32,16 +32,8 @@
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% if resources|length == 0 and charges|length == 0 %}
|
||||
{# <div class="flex-table"> #}
|
||||
{# <div class="item-bloc">
|
||||
<p><span class="chill-no-data-statement">{{ "There isn't any element recorded"|trans }}</span></p>
|
||||
</div> #}
|
||||
{# </div> #}
|
||||
|
||||
{% else %}
|
||||
|
||||
<h2 class="subtitle">{{ 'Actual budget'|trans }}</h3>
|
||||
<h3 class="subtitle">{{ 'Actual budget'|trans }}</h3>
|
||||
|
||||
{% if actualCharges|length > 0 or actualResources|length > 0 %}
|
||||
{% include 'ChillBudgetBundle:Budget:_current_budget.html.twig' with {
|
||||
@ -58,38 +50,24 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% if pastCharges|length > 0 or pastResources|length > 0 %}
|
||||
<h2 class="subtitle">{{ 'Past budget'|trans }}</h2>
|
||||
|
||||
{% if pastCharges|length > 0 or pastResources|length > 0 %}
|
||||
{% include 'ChillBudgetBundle:Budget:_past_budget.html.twig' with {
|
||||
'pastCharges': pastCharges,
|
||||
'pastResources': pastResources,
|
||||
'entity': entity
|
||||
} %}
|
||||
{% else %}
|
||||
<div class="flex-table">
|
||||
<div class="item-bloc">
|
||||
<p><span class="chill-no-data-statement">{{ "There isn't any element recorded"|trans }}</span></p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if futureCharges|length > 0 or futureResources|length > 0 %}
|
||||
<h2 class="subtitle">{{ 'Future budget'|trans }}</h2>
|
||||
|
||||
{% if futureCharges|length > 0 or futureResources|length > 0 %}
|
||||
{% include 'ChillBudgetBundle:Budget:_future_budget.html.twig' with {
|
||||
'futureResources': futureResources,
|
||||
'futureCharges': futureCharges,
|
||||
'entity': entity
|
||||
} %}
|
||||
{% else %}
|
||||
<div class="flex-table">
|
||||
<div class="item-bloc">
|
||||
<p><span class="chill-no-data-statement">{{ "There isn't any element recorded"|trans }}</span></p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
{# <h2 class="subtitle">{{ 'Actual budget'|trans }}</h2> #}
|
||||
|
||||
<div class="flex-table">
|
||||
<h3 class="family-title">{{ 'Actual resources'|trans }}</h3>
|
||||
<h4 class="family-title">{{ 'Actual resources'|trans }}</h4>
|
||||
|
||||
{% if actualResources|length > 0 %}
|
||||
<div class="item-bloc">
|
||||
@ -17,6 +17,7 @@
|
||||
</div>
|
||||
|
||||
<div class="flex-table">
|
||||
<h4 class="family-title">{{ 'Actual charges'|trans }}</h4>
|
||||
{% if actualCharges|length > 0 %}
|
||||
<div class="item-bloc">
|
||||
{{ table_elements(actualCharges, 'charge') }}
|
||||
|
@ -14,7 +14,10 @@
|
||||
{% set total = total + f.amount %}
|
||||
<tr>
|
||||
<td class="column-wide el-type">
|
||||
{{ f.type|budget_element_type_display(family) }}
|
||||
<span class="badge-title">
|
||||
<span class="title_label title_label_{{ family }}"></span>
|
||||
<span class="title_action">{{ f.type|budget_element_type_display(family) }}<span>
|
||||
</span>
|
||||
</td>
|
||||
<td class="column-small">{{ f.amount|format_currency('EUR') }}</td>
|
||||
<td class="column-wide">
|
||||
|
@ -35,7 +35,7 @@
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
{{ form_widget(form.submit, { 'attr' : { 'class': 'btn btn-create' }, 'label': 'Edit' } ) }}
|
||||
{{ form_widget(form.submit, { 'attr' : { 'class': 'btn btn-edit' }, 'label': 'Edit' } ) }}
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
@ -24,9 +24,9 @@
|
||||
} %}
|
||||
|
||||
<div class="flex-table">
|
||||
<h3 class="family-title">{{ 'Budget calculator'|trans }}</h2>
|
||||
<h3 class="family-title">{{ 'Budget calculator'|trans }}</h3>
|
||||
<div class="item-bloc">
|
||||
{{ table_results(charges, resources) }}
|
||||
{{ table_results(wholeCharges, wholeResources) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -45,7 +45,7 @@
|
||||
data-bs-target="#collapse_{{ member.id }}"
|
||||
aria-expanded="false"
|
||||
aria-controls="collapse_{{ member.id }}">
|
||||
<span class="folded">{{ 'Show budget of %name%'|trans({'%name%': member.firstName ~ " " ~ member.lastName }) }}</span>
|
||||
<span class="folded">{{ 'Show budget of %name%'|trans({'%name%': member.firstName ~ " " ~ member.lastName }) }} ({{ 'budget.number of elements'|trans({ 'nb_items': member.getBudgetResources|length + member.getBudgetResources|length }) }})</span>
|
||||
<span class="unfolded text-secondary">{{ 'Hide budget of %name%'|trans({'%name%': member.firstName ~ " " ~ member.lastName }) }}</span>
|
||||
</button>
|
||||
</h2>
|
||||
|
@ -36,7 +36,7 @@
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
{{ form_widget(form.submit, { 'attr' : { 'class': 'btn btn-create' }, 'label': 'Edit' } ) }}
|
||||
{{ form_widget(form.submit, { 'attr' : { 'class': 'btn btn-edit' }, 'label': 'Edit' } ) }}
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
services:
|
||||
Chill\BudgetBundle\Menu\PersonMenuBuilder:
|
||||
autowire: true
|
||||
tags:
|
||||
- { name: 'chill.menu_builder' }
|
||||
autoconfigure: true
|
||||
|
||||
Chill\BudgetBundle\Menu\HouseholdMenuBuilder:
|
||||
autowire: true
|
||||
tags:
|
||||
- { name: 'chill.menu_builder' }
|
||||
autoconfigure: true
|
||||
|
@ -0,0 +1,8 @@
|
||||
budget:
|
||||
number of elements: >-
|
||||
{nb_items, plural,
|
||||
=0 {Aucun élément}
|
||||
one {Un élément}
|
||||
many {# éléments}
|
||||
other {# éléments}
|
||||
}
|
@ -2,8 +2,8 @@ Budget: Budget
|
||||
Resource: Ressource
|
||||
Charge: Charge
|
||||
Budget for %name%: Budget de %name%
|
||||
Budget for household %household%: Budget de ménage %household%
|
||||
Current budget household members: Budgets actuelles des membres du ménage
|
||||
Budget for household %household%: Budget du ménage
|
||||
Current budget household members: Budget actuel des membres du ménage
|
||||
Show budget of %name%: Montrer budget de %name%
|
||||
See complete budget: Voir budget complet
|
||||
Hide budget: Masquer
|
||||
@ -29,7 +29,7 @@ End of validity period: Fin de la période de validité
|
||||
Total: Total
|
||||
Create new resource: Créer une nouvelle ressource
|
||||
Create new charge: Créer une nouvelle charge
|
||||
See person: Voir person
|
||||
See person: Voir personne
|
||||
|
||||
There isn't any element recorded: Aucun élément enregistré
|
||||
No resources registered: Aucune ressource enregistrée
|
||||
@ -70,7 +70,7 @@ charge.help.not-concerned: Non concerné
|
||||
|
||||
Budget calculator: Calculs et indices sur le budget
|
||||
Budget calculator result: Résultats
|
||||
The balance: Le solde budgétaire
|
||||
The balance: Différence entre ressources et charges
|
||||
|
||||
Valid since %startDate% until %endDate%: Valide depuis le %startDate% jusqu'au %endDate%
|
||||
Valid since %startDate%: Valide depuis le %startDate%
|
@ -159,8 +159,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
||||
private $birthdate;
|
||||
|
||||
/**
|
||||
* Read-only field, computed by the database.
|
||||
*
|
||||
* @ORM\OneToMany(
|
||||
* targetEntity=Charge::class,
|
||||
* mappedBy="person"
|
||||
@ -169,8 +167,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
||||
private Collection $budgetCharges;
|
||||
|
||||
/**
|
||||
* Read-only field, computed by the database.
|
||||
*
|
||||
* @ORM\OneToMany(
|
||||
* targetEntity=Resource::class,
|
||||
* mappedBy="person"
|
||||
|
Loading…
x
Reference in New Issue
Block a user