From bf14c9256747fac843eb5830ec315a90a4e47a4f Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 5 Feb 2025 17:08:42 +0100 Subject: [PATCH] Continue thirdparty merge controller and create views --- .../views/CRUD/_view_content.html.twig | 14 ++- .../ThirdpartyDuplicateController.php | 96 ++++++++++++++++++ .../Form/ThirdpartyFindDuplicateType.php | 32 ++++++ .../ThirdPartyDuplicate/_details.html.twig | 39 ++++++++ .../ThirdPartyDuplicate/confirm.html.twig | 97 +++++++++++++++++++ .../find_duplicate.html.twig | 38 ++++++++ .../translations/messages.fr.yml | 1 + 7 files changed, 314 insertions(+), 3 deletions(-) create mode 100644 src/Bundle/ChillThirdPartyBundle/Form/ThirdpartyFindDuplicateType.php create mode 100644 src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/_details.html.twig create mode 100644 src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/confirm.html.twig create mode 100644 src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/find_duplicate.html.twig diff --git a/src/Bundle/ChillMainBundle/Resources/views/CRUD/_view_content.html.twig b/src/Bundle/ChillMainBundle/Resources/views/CRUD/_view_content.html.twig index 203a24926..7d0023a39 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/CRUD/_view_content.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/CRUD/_view_content.html.twig @@ -4,7 +4,7 @@ {% endblock crud_content_header %} {% block crud_content_view %} - + {% block crud_content_view_details %}
id
@@ -20,7 +20,7 @@ {{ 'Cancel'|trans }} - {% 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 @@ {% 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 %} +
  • + {{ 'thirdparty_duplicate.merge'|trans }} +
  • + {% 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) %} diff --git a/src/Bundle/ChillThirdPartyBundle/Controller/ThirdpartyDuplicateController.php b/src/Bundle/ChillThirdPartyBundle/Controller/ThirdpartyDuplicateController.php index 5bcb52db0..a7fb87458 100644 --- a/src/Bundle/ChillThirdPartyBundle/Controller/ThirdpartyDuplicateController.php +++ b/src/Bundle/ChillThirdPartyBundle/Controller/ThirdpartyDuplicateController.php @@ -1,10 +1,106 @@ 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(), + ]); + } } diff --git a/src/Bundle/ChillThirdPartyBundle/Form/ThirdpartyFindDuplicateType.php b/src/Bundle/ChillThirdPartyBundle/Form/ThirdpartyFindDuplicateType.php new file mode 100644 index 000000000..8b2534bca --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/Form/ThirdpartyFindDuplicateType.php @@ -0,0 +1,32 @@ +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'; + } + +} diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/_details.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/_details.html.twig new file mode 100644 index 000000000..8896c8deb --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/_details.html.twig @@ -0,0 +1,39 @@ +{%- macro details(thirdparty, options) -%} + + +{% endmacro %} + +{#{%- macro links(thirdparty, options) -%}#} +{# #} +{#{% endmacro %}#} diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/confirm.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/confirm.html.twig new file mode 100644 index 000000000..4baa4552e --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/confirm.html.twig @@ -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 %} + +
    + +

    {{ 'thirdparty_duplicate.Merge duplicate thirdparties'|trans }}

    + +
    +

    {{ 'thirdparty_duplicate.Thirdparty to delete'|trans }}: + {{ 'thirdparty_duplicate.Thirdparty to delete explanation'|trans }} +

    +
    + +

    + {{ thirdparty2 }} +

    + +

    {{ 'Deleted datas'|trans ~ ':' }}

    + {{ details.details(thirdparty2) }} + +{#

    {{ 'Moved links'|trans ~ ':' }}

    #} +{# {{ details.links(thirdparty2) }}#} +
    +
    + +
    +

    {{ 'thirdparty_duplicate.Thirdparty to keep'|trans }}: + {{ 'thirdparty_duplicate.Thirdparty to delete explanation'|trans }} +

    +
    + +

    + {{ thirdparty }} +

    + +

    {{ 'thirdparty_duplicate.data to keep'|trans ~ ':' }}

    + {{ details.details(thirdparty) }} + +{#

    {{ 'thirdparty_duplicate.links to keep'|trans ~ ':' }}

    #} +{# {{ sidepane.links(thirdparty) }}#} +
    +
    + + {{ form_start(form) }} + +
    + +
    +
    + {{ form_widget(form.confirm) }} +
    +
    + {{ form_label(form.confirm) }} +
    +
    +
    + + + + {{ form_end(form) }} + +
    +{% endblock %} diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/find_duplicate.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/find_duplicate.html.twig new file mode 100644 index 000000000..9dd1a0992 --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdPartyDuplicate/find_duplicate.html.twig @@ -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 %} +
    + +

    {{ 'find duplicate thirdparty'|trans }}

    + + {{ form_start(form) }} + {{ form_rest(form) }} + + + + {{ form_end(form) }} + +
    +{% endblock %} + +{% block js %} + {{ encore_entry_script_tags('mod_pickentity_type') }} +{% endblock %} + +{% block css %} + {{ encore_entry_link_tags('mod_pickentity_type') }} +{% endblock %} diff --git a/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml b/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml index 52bae6fee..9432fbdc0 100644 --- a/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml @@ -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