Continue thirdparty merge controller and create views

This commit is contained in:
Julie Lenaerts 2025-02-05 17:08:42 +01:00
parent 7c1c1ed800
commit bf14c92567
7 changed files with 314 additions and 3 deletions

View File

@ -4,7 +4,7 @@
{% endblock crud_content_header %}
{% block crud_content_view %}
{% block crud_content_view_details %}
<dl class="chill_view_data">
<dt>id</dt>
@ -20,7 +20,7 @@
{{ 'Cancel'|trans }}
</a>
</li>
{% endblock %}
{% endblock %}
{% block content_view_actions_before %}{% endblock %}
{% block content_form_actions_delete %}
{% if chill_crud_action_exists(crud_name, 'delete') %}
@ -32,7 +32,7 @@
</li>
{% endif %}
{% endif %}
{% endblock content_form_actions_delete %}
{% endblock content_form_actions_delete %}
{% block content_view_actions_duplicate_link %}
{% if chill_crud_action_exists(crud_name, 'new') %}
{% if is_granted(chill_crud_config('role', crud_name, 'new'), entity) %}
@ -44,6 +44,14 @@
{% endif %}
{% endif %}
{% endblock content_view_actions_duplicate_link %}
{% block content_view_actions_merge %}
<li>
<a href="{{ chill_path_add_return_path('chill_thirdparty_find_duplicate',
{ 'thirdparty_id': entity.id }) }}"
title="{{ 'thirdparty_duplicate.merge'|trans }}"
class="btn btn-misc">{{ 'thirdparty_duplicate.merge'|trans }}</a>
</li>
{% endblock %}
{% block content_view_actions_edit_link %}
{% if chill_crud_action_exists(crud_name, 'edit') %}
{% if is_granted(chill_crud_config('role', crud_name, 'edit'), entity) %}

View File

@ -1,10 +1,106 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\ThirdPartyBundle\Controller;
use Chill\PersonBundle\Form\PersonConfimDuplicateType;
use Chill\ThirdPartyBundle\Form\ThirdpartyFindDuplicateType;
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
use Chill\ThirdPartyBundle\Service\ThirdpartyMergeService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class ThirdpartyDuplicateController extends AbstractController
{
public function __construct(private ThirdPartyRepository $thirdPartyRepository, private ThirdpartyMergeService $thirdPartyMergeService) {}
#[Route(path: '/{_locale}/3party/{thirdparty_id}/find-manually', name: 'chill_thirdparty_find_duplicate')]
public function findManuallyDuplicateAction(mixed $thirdparty_id, Request $request)
{
$thirdparty = $this->thirdPartyRepository->find($thirdparty_id);
dump($thirdparty_id);
dump($thirdparty);
if (null === $thirdparty) {
throw $this->createNotFoundException("Thirdparty with id {$thirdparty_id} not".' found on this server');
}
$form = $this->createForm(ThirdpartyFindDuplicateType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$thirdparty2 = $form->get('thirdparty')->getData();
if (null === $thirdparty2) {
throw $this->createNotFoundException("Thirdparty with id {$thirdparty2->getId}() not".' found on this server');
}
$direction = $form->get('direction')->getData();
if ('starting' === $direction) {
$params = [
'thirdparty1_id' => $thirdparty->getId(),
'thirdparty2_id' => $thirdparty2->getId(),
];
} else {
$params = [
'thirdparty1_id' => $thirdparty2->getId(),
'thirdparty2_id' => $thirdparty->getId(),
];
}
return $this->redirectToRoute('chill_thirdparty_duplicate_confirm', $params);
}
return $this->render('@ChillThirdParty/ThirdPartyDuplicate/find_duplicate.html.twig', [
'thirdparty' => $thirdparty,
'form' => $form->createView(),
]);
}
#[Route(path: '/{_locale}/3party/{thirdparty1_id}/duplicate/{thirdparty2_id}/confirm', name: 'chill_thirdparty_duplicate_confirm')]
public function confirmAction(mixed $thirdparty1_id, mixed $thirdparty2_id, Request $request)
{
if ($thirdparty1_id === $thirdparty2_id) {
throw new \InvalidArgumentException('Can not merge same thirdparty');
}
$thirdparty1 = $this->thirdPartyRepository->find($thirdparty1_id);
$thirdparty2 = $this->thirdPartyRepository->find($thirdparty2_id);
if (null === $thirdparty1) {
throw $this->createNotFoundException("Thirdparty with id {$thirdparty1_id} not".' found on this server');
}
if (null === $thirdparty2) {
throw $this->createNotFoundException("Person with id {$thirdparty2_id} not".' found on this server');
}
$form = $this->createForm(PersonConfimDuplicateType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->thirdPartyMergeService->merge($thirdparty1, $thirdparty2);
return $this->redirectToRoute('chill_crud_3party_3party_view', ['id' => $thirdparty1->getId()]);
}
return $this->render('@ChillThirdParty/ThirdPartyDuplicate/confirm.html.twig', [
'thirdparty' => $thirdparty1,
'thirdparty2' => $thirdparty2,
'form' => $form->createView(),
]);
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Chill\ThirdPartyBundle\Form;
use Chill\ThirdPartyBundle\Form\Type\PickThirdpartyDynamicType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
class ThirdpartyFindDuplicateType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('thirdparty', PickThirdpartyDynamicType::class, [
'label' => 'Find duplicate',
'mapped' => false,
])
->add('direction', HiddenType::class, [
'data' => 'starting',
]);
}
/**
* @return string
*/
public function getBlockPrefix()
{
return 'chill_thirdpartybundle_thirdparty_find_manually_duplicate';
}
}

View File

@ -0,0 +1,39 @@
{%- macro details(thirdparty, options) -%}
<ul>
<li><b>{{ 'name'|trans }}</b>:
{{ thirdparty.name }}</li>
<li><b>{{ 'firstName'|trans }}</b>:
{% if thirdparty.firstname %}{{ thirdparty.firstname }}{% endif %}</li>
<li><b>{{ 'thirdparty.Civility'|trans }}</b>:
{% if thirdparty.getCivility %}{{ thirdparty.getCivility.name|localize_translatable_string }}{% endif %}</li>
<li><b>{{ 'thirdparty.NameCompany'|trans }}</b>:
{% if thirdparty.nameCompany is not empty %}{{ thirdparty.nameCompany }}{% endif %}</li>
<li><b>{{ 'thirdparty.Acronym'|trans }}</b>:
{% if thirdparty.acronym %}{{ thirdparty.acronym }}{% endif %}</li>
<li><b>{{ 'thirdparty.Profession'|trans }}</b>:
{% if thirdparty.profession %}{{ thirdparty.profession }}{% endif %}</li>
<li><b>{{ 'telephone'|trans }}</b>:
{% if thirdparty.telephone %}{{ thirdparty.telephone }}{% endif %}</li>
<li><b>{{ 'email'|trans }}</b>:
{% if thirdparty.email is not null %}{{ thirdparty.email }}{% endif %}</li>
<li><b>{{ 'address'|trans }}</b>:
{%- if thirdparty.getAddress is not empty -%}
{{ thirdparty.getAddress|chill_entity_render_box }}
{% endif %}</li>
<li><b>{{ 'thirdparty.Contact data are confidential'|trans }}</b>:
{{ thirdparty.contactDataAnonymous }}</li>
</ul>
{% endmacro %}
{#{%- macro links(thirdparty, options) -%}#}
{# <ul>#}
{##}
{# <li><b>{{ person.counters.nb_activity }}</b> {{ (person.counters.nb_activity > 1)? 'échanges' : 'échange' }}</li>#}
{# <li><b>{{ person.counters.nb_task }}</b> {{ (person.counters.nb_task > 1)? 'tâches' : 'tâche' }}</li>#}
{# <li><b>{{ person.counters.nb_document }}</b> {{ (person.counters.nb_document > 1)? 'documents' : 'document' }}</li>#}
{# <li><b>{{ person.counters.nb_event }}</b> {{ (person.counters.nb_event > 1)? 'événements' : 'événement' }}</li>#}
{# <li><b>{{ person.counters.nb_addresses }}</b> {{ (person.counters.nb_addresses > 1)? 'adresses' : 'adresse' }}</li>#}
{##}
{# </ul>#}
{#{% endmacro %}#}

View File

@ -0,0 +1,97 @@
{% extends "@ChillMain/layout.html.twig" %}
{% import '@ChillThirdParty/ThirdPartyDuplicate/_details.html.twig' as details %}
{% block title %}{{ 'thirdparty_duplicate.Thirdparty duplicate title'|trans ~ ' ' ~ thirdparty.name }}{% endblock %}
{% block content %}
<style>
div.duplicate-content {
margin: 0 2rem;
}
div.col {
padding: 1em;
border: 3px solid #cccccc;
}
div.border {
border: 4px solid #3c9f8d;
}
</style>
<div class="container-fluid content"><div class="duplicate-content">
<h1>{{ 'thirdparty_duplicate.Merge duplicate thirdparties'|trans }}</h1>
<div class="col-md-11">
<p><b>{{ 'thirdparty_duplicate.Thirdparty to delete'|trans }}</b>:
{{ 'thirdparty_duplicate.Thirdparty to delete explanation'|trans }}
</p>
<div class="col">
<h1><span><a class="btn btn-show" target="_blank" title="{{ 'Open in another window'|trans }}" href="{{ path('chill_crud_3party_3party_view', { id : thirdparty2.id }) }}"></a></span>
{{ thirdparty2 }}
</h1>
<h4>{{ 'Deleted datas'|trans ~ ':' }}</h4>
{{ details.details(thirdparty2) }}
{# <h4>{{ 'Moved links'|trans ~ ':' }}</h4>#}
{# {{ details.links(thirdparty2) }}#}
</div>
</div>
<div class="col-md-11">
<p><b>{{ 'thirdparty_duplicate.Thirdparty to keep'|trans }}</b>:
{{ 'thirdparty_duplicate.Thirdparty to delete explanation'|trans }}
</p>
<div class="col border">
<h1><span><a class="btn btn-show" target="_blank" title="{{ 'Open in another window'|trans }}" href="{{ path('chill_crud_3party_3party_view', { id : thirdparty.id }) }}"></a></span>
{{ thirdparty }}
</h1>
<h4>{{ 'thirdparty_duplicate.data to keep'|trans ~ ':' }}</h4>
{{ details.details(thirdparty) }}
{# <h4>{{ 'thirdparty_duplicate.links to keep'|trans ~ ':' }}</h4>#}
{# {{ sidepane.links(thirdparty) }}#}
</div>
</div>
{{ form_start(form) }}
<div class="col-md-12 centered">
<div class="container-fluid" style="padding-top: 1em;">
<div class="clear" style="padding-top: 10px;">
{{ form_widget(form.confirm) }}
</div>
<div class="col-11">
{{ form_label(form.confirm) }}
</div>
</div>
</div>
<ul class="col-12 record_actions">
<li class="cancel">
<a href="{{ path('chill_thirdparty_find_duplicate', {thirdparty_id : thirdparty.id}) }}" class="btn btn-chill-gray center margin-5">
{{ 'Return'|trans }}
</a>
</li>
<li class="cancel">
<a href="{{ path('chill_thirdparty_duplicate_confirm', { thirdparty1_id : thirdparty2.id, thirdparty2_id : thirdparty.id }) }}"
class="btn btn-action">
<i class="fa fa-exchange"></i>
{{ 'Invert'|trans }}
</a>
</li>
<li>
<button class="btn btn-submit" type="submit"><i class="fa fa-cog fa-fw"></i>{{ 'Merge'|trans }}</button>
</li>
</ul>
{{ form_end(form) }}
</div></div>
{% endblock %}

View File

@ -0,0 +1,38 @@
{% extends "@ChillMain/layout.html.twig" %}
{% set activeRouteKey = 'chill_thirdparty_duplicate' %}
{% block title %}{{ 'Find duplicate'|trans ~ ' ' ~ thirdparty.name|capitalize }}{% endblock %}
{% block content %}
<div class="person-duplicate">
<h1>{{ 'find duplicate thirdparty'|trans }}</h1>
{{ form_start(form) }}
{{ form_rest(form) }}
<ul class="record_actions sticky-form-buttons">
<li class="cancel">
<a href="{{ path('chill_crud_3party_3party_view', {'id' : thirdparty.id}) }}" class="btn btn-cancel">
{{ 'Return'|trans }}
</a>
</li>
<li>
<button class="btn btn-save" type="submit">{{ 'Next'|trans }}</button>
</li>
</ul>
{{ form_end(form) }}
</div>
{% endblock %}
{% block js %}
{{ encore_entry_script_tags('mod_pickentity_type') }}
{% endblock %}
{% block css %}
{{ encore_entry_link_tags('mod_pickentity_type') }}
{% endblock %}

View File

@ -133,6 +133,7 @@ is thirdparty: Le demandeur est un tiers
Filter by person's who have a residential address located at a thirdparty of type: Filtrer les usagers qui ont une addresse de résidence chez un tiers
"Filtered by person's who have a residential address located at a thirdparty of type %thirdparty_type% and valid on %date_calc%": "Uniquement les usagers qui ont une addresse de résidence chez un tiers de catégorie %thirdparty_type% et valide sur la date %date_calc%"
find duplicate thirdparty: 'Désigner un tier doublon'
# admin