adapt Thirdparty form and templates

This commit is contained in:
Mathieu Jaumotte 2021-07-19 18:47:10 +02:00
parent 3f9e215ea5
commit 587da94645
8 changed files with 234 additions and 61 deletions

View File

@ -96,18 +96,16 @@ class ThirdParty
/** /**
* Contact Persons: One Institutional ThirdParty has Many Contact Persons * Contact Persons: One Institutional ThirdParty has Many Contact Persons
* @var ThirdParty
* @ORM\OneToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", mappedBy="parent") * @ORM\OneToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", mappedBy="parent")
*/ */
private $children; private Collection $children;
/** /**
* Institutional ThirdParty: Many Contact Persons have One Institutional ThirdParty * Institutional ThirdParty: Many Contact Persons have One Institutional ThirdParty
* @var ThirdParty
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", inversedBy="children") * @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id") * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
*/ */
private $parent; private ?ThirdParty $parent;
/** /**
* @var ThirdPartyCivility * @var ThirdPartyCivility
@ -169,16 +167,14 @@ class ThirdParty
private $centers; private $centers;
/** /**
* @var \DateTimeImmutable * @ORM\Column(name="created_at", type="datetime_immutable", nullable=false)
* @ORM\Column(name="created_at", type="datetime", nullable=false)
*/ */
private $createdAt; private \DateTimeImmutable $createdAt;
/** /**
* @var \DateTime
* @ORM\Column(name="updated_at", type="datetime", nullable=true) * @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/ */
private $updatedAt; private ?\DateTime $updatedAt;
/** /**
* @var User * @var User
@ -497,6 +493,11 @@ class ThirdParty
return $this; return $this;
} }
public function isLeaf(): bool
{
return $this->children->count() !== 0;
}
/** /**
* @return Collection * @return Collection
*/ */
@ -526,18 +527,18 @@ class ThirdParty
} }
/** /**
* @return ThirdParty * @return ThirdParty|null
*/ */
public function getParent(): ThirdParty public function getParent(): ?ThirdParty
{ {
return $this->parent; return $this->parent;
} }
/** /**
* @param ThirdParty $parent * @param ThirdParty|null $parent
* @return $this * @return $this
*/ */
public function setParent(ThirdParty $parent): ThirdParty public function setParent(?ThirdParty $parent): ThirdParty
{ {
$this->parent = $parent; $this->parent = $parent;
return $this; return $this;
@ -598,9 +599,9 @@ class ThirdParty
} }
/** /**
* @return \DateTime * @return \DateTime|null
*/ */
public function getUpdatedAt(): \DateTime public function getUpdatedAt(): ?\DateTime
{ {
return $this->updatedAt; return $this->updatedAt;
} }
@ -616,9 +617,9 @@ class ThirdParty
} }
/** /**
* @return User * @return User|null
*/ */
public function getUpdatedBy(): User public function getUpdatedBy(): ?User
{ {
return $this->updatedBy; return $this->updatedBy;
} }

View File

@ -3,6 +3,11 @@
namespace Chill\ThirdPartyBundle\Form; namespace Chill\ThirdPartyBundle\Form;
use Chill\MainBundle\Form\Type\ChillTextareaType; use Chill\MainBundle\Form\Type\ChillTextareaType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
use Chill\ThirdPartyBundle\Entity\ThirdPartyCivility;
use Chill\ThirdPartyBundle\Entity\ThirdPartyProfession;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
@ -21,32 +26,24 @@ use Chill\MainBundle\Form\Type\AddressType;
class ThirdPartyType extends AbstractType class ThirdPartyType extends AbstractType
{ {
/** protected AuthorizationHelper $authorizationHelper;
*
* @var AuthorizationHelper
*/
protected $authorizationHelper;
/** protected TokenStorageInterface $tokenStorage;
*
* @var TokenStorageInterface
*/
protected $tokenStorage;
/** protected ThirdPartyTypeManager $typesManager;
*
* @var ThirdPartyTypeManager protected TranslatableStringHelper $translatableStringHelper;
*/
protected $typesManager;
public function __construct( public function __construct(
AuthorizationHelper $authorizationHelper, AuthorizationHelper $authorizationHelper,
TokenStorageInterface $tokenStorage, TokenStorageInterface $tokenStorage,
ThirdPartyTypeManager $typesManager ThirdPartyTypeManager $typesManager,
TranslatableStringHelper $translatableStringHelper
) { ) {
$this->authorizationHelper = $authorizationHelper; $this->authorizationHelper = $authorizationHelper;
$this->tokenStorage = $tokenStorage; $this->tokenStorage = $tokenStorage;
$this->typesManager = $typesManager; $this->typesManager = $typesManager;
$this->translatableStringHelper = $translatableStringHelper;
} }
/** /**
@ -60,26 +57,87 @@ class ThirdPartyType extends AbstractType
} }
$builder $builder
->add('civility', EntityType::class, [
'label' => 'thirdparty.Civility',
'class' => ThirdPartyCivility::class,
'choice_label' => function (ThirdPartyCivility $civility) {
return $this->translatableStringHelper->localize($civility->getName());
},
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('c')
->where('c.active = true');
},
'placeholder' => 'thirdparty.choose civility',
'required' => true
])
->add('name', TextType::class, [ ->add('name', TextType::class, [
'required' => true 'required' => true
]) ])
->add('telephone', TextType::class, [
'label' => 'Phonenumber', ->add('nameCompany', TextType::class, [
'label' => 'thirdparty.NameCompany',
'required' => false 'required' => false
]) ])
->add('email', EmailType::class, [
->add('profession', EntityType::class, [
'label' => 'thirdparty.Profession',
'class' => ThirdPartyProfession::class,
'choice_label' => function (ThirdPartyProfession $profession) {
return $this->translatableStringHelper->localize($profession->getName());
},
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('p')
->where('p.active = true');
},
'placeholder' => 'thirdparty.choose profession',
'required' => false 'required' => false
]) ])
->add('comment', ChillTextareaType::class, [
->add('acronym', TextType::class, [
'label' => 'thirdparty.Acronym',
'required' => false 'required' => false
]) ])
->add('categories', EntityType::class, [
'label' => 'thirdparty.Categories',
'class' => ThirdPartyCategory::class,
'choice_label' => function (ThirdPartyCategory $category) {
return $this->translatableStringHelper->localize($category->getName());
},
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('c')
->where('c.active = true');
},
'required' => true,
'multiple' => true,
'attr' => ['class' => 'select2']
])
->add('type', ChoiceType::class, [ ->add('type', ChoiceType::class, [
'choices' => $types, 'choices' => $types,
'expanded' => true, 'expanded' => true,
'multiple' => true, 'multiple' => true,
'label' => 'thirdparty.Type' 'label' => 'thirdparty.Type'
]) ])
->add('telephone', TextType::class, [
'label' => 'Phonenumber',
'required' => false
])
->add('email', EmailType::class, [
'required' => false
])
->add('address', AddressType::class, [
'has_valid_from' => false,
'null_if_empty' => true,
'required' => false
])
->add('active', ChoiceType::class, [ ->add('active', ChoiceType::class, [
'label' => 'thirdparty.Status',
'choices' => [ 'choices' => [
'Active, shown to users' => true, 'Active, shown to users' => true,
'Inactive, not shown to users' => false 'Inactive, not shown to users' => false
@ -87,18 +145,18 @@ class ThirdPartyType extends AbstractType
'expanded' => true, 'expanded' => true,
'multiple' => false 'multiple' => false
]) ])
->add('comment', ChillTextareaType::class, [
'required' => false
])
->add('centers', EntityType::class, [ ->add('centers', EntityType::class, [
'choices' => $this->getReachableCenters($options), 'choices' => $this->getReachableCenters($options),
'class' => \Chill\MainBundle\Entity\Center::class, 'class' => \Chill\MainBundle\Entity\Center::class,
'multiple' => true, 'multiple' => true,
'expanded' => true 'attr' => ['class' => 'select2']
]) ])
->add('address', AddressType::class, [ ;
'has_valid_from' => false,
'null_if_empty' => true,
'required' => false
])
;
} }
/** /**

View File

@ -40,6 +40,9 @@
<th class="chill-pink">{{ 'Address'|trans }} <th class="chill-pink">{{ 'Address'|trans }}
<i class="fa fa-fw fa-sort"></i> <i class="fa fa-fw fa-sort"></i>
</th> </th>
<th class="chill-pink">{{ 'thirdparty.UpdatedAt.short'|trans }}
<i class="fa fa-fw fa-sort"></i>
</th>
<th class="chill-pink"></th> <th class="chill-pink"></th>
</tr> </tr>
</thead> </thead>
@ -56,6 +59,13 @@
<td> <td>
{{ tp.address|chill_entity_render_box({'multiline': false, 'with_valid_from': false}) }} {{ tp.address|chill_entity_render_box({'multiline': false, 'with_valid_from': false}) }}
</td> </td>
<td>
{% if tp.updatedAt != null %}
{{ tp.updatedAt|format_date('short') }}
{% else %}
{{ tp.createdAt|format_date('short') }}
{% endif %}
</td>
<td> <td>
<ul class="record_actions"> <ul class="record_actions">
{% if is_granted('CHILL_3PARTY_3PARTY_UPDATE', tp) %} {% if is_granted('CHILL_3PARTY_3PARTY_UPDATE', tp) %}

View File

@ -10,22 +10,42 @@
<h1>{{ 'Create third party'|trans }}</h1> <h1>{{ 'Create third party'|trans }}</h1>
{{ form_start(form) }} {{ form_start(form) }}
{% if thirdParty.isLeaf == true %}
{{ form_row(form.civility) }}
{% endif %}
{{ form_row(form.name) }} {{ form_row(form.name) }}
{% if thirdParty.isLeaf == false %}
{{ form_row(form.nameCompany) }}
{{ form_row(form.acronym) }}
{% endif %}
{% if thirdParty.isLeaf == true %}
{{ form_row(form.profession) }}
{% endif %}
{{ form_row(form.categories) }}
{{ form_row(form.type) }} {{ form_row(form.type) }}
{{ form_row(form.telephone) }} {{ form_row(form.telephone) }}
{{ form_row(form.email) }} {{ form_row(form.email) }}
{{ form_row(form.address) }} {{ form_row(form.address) }}
{{ form_row(form.active) }}
{{ form_row(form.centers) }}
{{ form_row(form.comment) }} {{ form_row(form.comment) }}
{{ form_row(form.centers) }}
{{ form_row(form.active) }}
<ul class="record_actions"> <ul class="record_actions sticky-form-buttons">
<li class="cancel"> <li class="cancel">
<a href="{{ chill_return_path_or('chill_3party_3party_index') }}" class="btn btn-cancel"> <a href="{{ chill_return_path_or('chill_3party_3party_index') }}" class="btn btn-cancel">
{{ 'Back to the list'|trans }} {{ 'Back to the list'|trans }}
</a> </a>
</li>
<li>
</li> </li>
<li> <li>
{{ form_widget(form.submit, {'label': 'Create', 'attr': {'class': 'btn btn-new' }}) }} {{ form_widget(form.submit, {'label': 'Create', 'attr': {'class': 'btn btn-new' }}) }}

View File

@ -20,24 +20,63 @@
</h1> </h1>
<dl class="chill_view_data"> <dl class="chill_view_data">
<dt>{{ 'Name'|trans }}</dt> <dt>{{ 'Name'|trans }}</dt>
<dd>{{ thirdParty.name }}</dd> <dd>
{% if thirdParty.isLeaf == true %}{{ thirdParty.civility }}{% endif %}
{{ thirdParty.name }}
</dd>
{% if thirdParty.isLeaf == false %}
<dt>{{ 'thirdparty.NameCompany'|trans }}</dt>
<dd>
{% if thirdParty.nameCompany == null %}
<span class="chill-no-data-statement">{{ 'No nameCompany given'|trans }}</span>
{% else %}
{{ thirdParty.nameCompany }}
{% endif %}
</dd>
<dt>{{ 'thirdparty.Acronym'|trans }}</dt>
<dd>
{% if thirdParty.acronym == null %}
<span class="chill-no-data-statement">{{ 'No acronym given'|trans }}</span>
{% else %}
{{ thirdParty.acronym }}
{% endif %}
</dd>
{% endif %}
<dt>{{ 'Type'|trans }}</dt> <dt>{{ 'Type'|trans }}</dt>
{% set types = [] %} {% set types = [] %}
{% for t in thirdParty.type %} {% for t in thirdParty.type %}
{% set types = types|merge( [ ('chill_3party.key_label.'~t)|trans ] ) %} {% set types = types|merge( [ ('chill_3party.key_label.'~t)|trans ] ) %}
{% endfor %} {% endfor %}
<dd>{{ types|join(', ') }}</dd> <dd>
{{ types|join(', ') }}
<dt>{{ 'Centers'|trans }}</dt> </dd>
<dd>{{ 'The party is visible in those centers'|trans }}&nbsp;: {{ thirdParty.centers|join(', ') }}</dd>
<dt>{{ 'Phonenumber'|trans }}</dt> <dt>{{ 'Phonenumber'|trans }}</dt>
<dd>{{ thirdParty.telephone|chill_print_or_message("thirdparty.No_phonenumber") }}</dd> <dd>
{% if thirdParty.telephone == null %}
<span class="chill-no-data-statement">{{ 'No phone given'|trans }}</span>
{% else %}
<a href="{{ 'tel:' ~ thirdParty.telephone }}">
{{ thirdParty.telephone|chill_print_or_message("thirdparty.No_phonenumber") }}
</a>
{% endif %}
</dd>
<dt>{{ 'email'|trans }}<dt> <dt>{{ 'email'|trans }}<dt>
<dd>{{ thirdParty.email|chill_print_or_message("thirdparty.No_email") }}</dd> <dd>
{% if thirdParty.email == null %}
<span class="chill-no-data-statement">{{ 'No email given'|trans }}</span>
{% else %}
<a href="{{ 'mailto:' ~ thirdParty.email }}">
{{ thirdParty.email|chill_print_or_message("thirdparty.No_email") }}
</a>
{% endif %}
</dd>
<dt>{{ 'Address'|trans }}</dt> <dt>{{ 'Address'|trans }}</dt>
<dd> <dd>
@ -57,6 +96,9 @@
{% endif %} {% endif %}
</dd> </dd>
<dt>{{ 'Centers'|trans }}</dt>
<dd>{{ 'The party is visible in those centers'|trans }}&nbsp;: {{ thirdParty.centers|join(', ') }}</dd>
</dl> </dl>
<ul class="record_actions sticky-form-buttons"> <ul class="record_actions sticky-form-buttons">

View File

@ -15,24 +15,55 @@
</span> </span>
</h1> </h1>
<div class="date-by">
{% if thirdParty.updatedAt != null %}
{{ 'thirdparty.UpdatedAt.short'|trans ~ thirdParty.updatedAt|format_date('short') }}
{% else %}
{{ 'thirdparty.CreatedAt.short'|trans ~ thirdParty.createdAt|format_date('short') }}
{% endif %}
{% if thirdParty.updatedBy != null %}
{{ 'thirdparty.UpdateBy.short'|trans ~ thirdParty.updatedBy.usernameCanonical }}
{% endif %}
</div>
{{ form_start(form) }} {{ form_start(form) }}
{% if thirdParty.isLeaf == true %}
{{ form_row(form.civility) }}
{% endif %}
{{ form_row(form.name) }} {{ form_row(form.name) }}
{% if thirdParty.isLeaf == false %}
{{ form_row(form.nameCompany) }}
{{ form_row(form.acronym) }}
{% endif %}
{% if thirdParty.isLeaf == true %}
{{ form_row(form.profession) }}
{% endif %}
{{ form_row(form.categories) }}
{{ form_row(form.type) }} {{ form_row(form.type) }}
{{ form_row(form.telephone) }} {{ form_row(form.telephone) }}
{{ form_row(form.email) }} {{ form_row(form.email) }}
{{ form_row(form.address) }} {{ form_row(form.address) }}
{{ form_row(form.active) }}
{{ form_row(form.centers) }}
{{ form_row(form.comment) }} {{ form_row(form.comment) }}
{{ form_row(form.centers) }}
{{ form_row(form.active) }}
<ul class="record_actions sticky-form-buttons"> <ul class="record_actions sticky-form-buttons">
<li class="cancel"> <li class="cancel">
<a class="btn btn-cancel" href="{{ chill_path_forward_return_path('chill_3party_3party_index') }}"> <a class="btn btn-cancel" href="{{ chill_path_forward_return_path('chill_3party_3party_index') }}">
{{ 'Back to the list'|trans }} {{ 'Back to the list'|trans }}
</a> </a>
</li>
<li>
</li>
<li> <li>
{{ form_widget(form.submit, {'label': 'Update', 'attr': {'class': 'btn btn-update' }}) }} {{ form_widget(form.submit, {'label': 'Update', 'attr': {'class': 'btn btn-update' }}) }}
</li> </li>

View File

@ -4,9 +4,10 @@ services:
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper' $authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
$tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface' $tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'
$typesManager: '@Chill\ThirdPartyBundle\ThirdPartyType\ThirdPartyTypeManager' $typesManager: '@Chill\ThirdPartyBundle\ThirdPartyType\ThirdPartyTypeManager'
$translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper'
tags: tags:
- { name: form.type } - { name: form.type }
Chill\ThirdPartyBundle\Form\Type\PickThirdPartyType: Chill\ThirdPartyBundle\Form\Type\PickThirdPartyType:
arguments: arguments:
$em: '@Doctrine\ORM\EntityManagerInterface' $em: '@Doctrine\ORM\EntityManagerInterface'
@ -14,4 +15,4 @@ services:
$translator: '@Symfony\Component\Translation\TranslatorInterface' $translator: '@Symfony\Component\Translation\TranslatorInterface'
$typesManager: '@Chill\ThirdPartyBundle\ThirdPartyType\ThirdPartyTypeManager' $typesManager: '@Chill\ThirdPartyBundle\ThirdPartyType\ThirdPartyTypeManager'
tags: tags:
- { name: form.type } - { name: form.type }

View File

@ -20,10 +20,15 @@ thirdparty.Children: Personnes de contact
thirdparty.Parent: Tiers institutionnel thirdparty.Parent: Tiers institutionnel
thirdparty.Parents: Tiers institutionnels thirdparty.Parents: Tiers institutionnels
thirdparty.Civility: Civilité thirdparty.Civility: Civilité
thirdparty.choose civility: --
thirdparty.Profession: Qualité thirdparty.Profession: Qualité
thirdparty.CreatedAt: Date de création thirdparty.choose profession: --
thirdparty.UpdatedAt: Date de la dernière modification thirdparty.CreatedAt.short: 'Créé le '
thirdparty.UpdateBy: Utilisateur qui a effectué la dernière modification thirdparty.UpdatedAt.short: 'Modifié le '
thirdparty.UpdateBy.short: ' par '
thirdparty.CreatedAt.long: Date de création
thirdparty.UpdatedAt.long: Date de la dernière modification
thirdparty.UpdateBy.long: Utilisateur qui a effectué la dernière modification
New third party: Ajouter un nouveau tiers New third party: Ajouter un nouveau tiers
Show third party %name%: Tiers "%name%" Show third party %name%: Tiers "%name%"
@ -32,6 +37,7 @@ Update third party %name%: Mettre à jour "%name%"
List of third parties: Liste des tiers List of third parties: Liste des tiers
Third party updated: Le tiers a été mis à jour Third party updated: Le tiers a été mis à jour
Third party created: Le tiers a été créé Third party created: Le tiers a été créé
thirdparty.Status: Statut
Active, shown to users: Actif, visible pour les utilisateurs Active, shown to users: Actif, visible pour les utilisateurs
Active: Actif Active: Actif
shown to users: visible pour les utilisateurs shown to users: visible pour les utilisateurs
@ -39,6 +45,10 @@ Inactive, not shown to users: Inactif, invisible pour les utilisateurs
Inactive: Inactif Inactive: Inactif
not shown to users: invisible pour les utilisateurs not shown to users: invisible pour les utilisateurs
No nameCompany given: Aucune raison sociale renseignée
No acronym given: Aucun sigle renseigné
No phone given: Aucun téléphone renseigné
No email given: Aucune adresse courriel renseignée
The party is visible in those centers: Le tiers est visible dans ces centres The party is visible in those centers: Le tiers est visible dans ces centres
No third parties: Aucun tiers No third parties: Aucun tiers