From f86d7ec78f05709e5406e40b759a6f3d711a000f Mon Sep 17 00:00:00 2001
From: Guillaume Heurtier <guillaume.heurtier@maarch.org>
Date: Fri, 4 Dec 2020 13:44:17 +0100
Subject: [PATCH] FIX #15484 TIME 0:35 fix rollback status + rescan distributed
 to not distributed

---
 .../controllers/RegisteredMailController.php           |  2 ++
 .../acknowledgement-reception.component.ts             | 10 +++++++---
 src/lang/lang-en.json                                  |  3 ++-
 src/lang/lang-fr.json                                  |  5 +++--
 4 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/app/registeredMail/controllers/RegisteredMailController.php b/src/app/registeredMail/controllers/RegisteredMailController.php
index ff070f3b990..3dc595cd98b 100644
--- a/src/app/registeredMail/controllers/RegisteredMailController.php
+++ b/src/app/registeredMail/controllers/RegisteredMailController.php
@@ -201,6 +201,8 @@ class RegisteredMailController
         if (!empty($registeredMail['received_date'])) {
             if ($registeredMail['status'] == $statusNotDistributed && $body['type'] == 'distributed') {
                 return $response->withJson(['previousStatus' => $registeredMail['status'], 'canRescan' => true]);
+            } elseif ($registeredMail['status'] == $statusDistributed && $body['type'] == 'notDistributed') {
+                return $response->withJson(['previousStatus' => $registeredMail['status'], 'canRescan' => true]);
             }
             return $response->withStatus(400)->withJson(['errors' => 'Registered mail was already received', 'lang' => 'arAlreadyReceived']);
         }
diff --git a/src/frontend/app/registeredMail/acknowledgement-reception/acknowledgement-reception.component.ts b/src/frontend/app/registeredMail/acknowledgement-reception/acknowledgement-reception.component.ts
index 164a2ce928b..da8c8739c07 100644
--- a/src/frontend/app/registeredMail/acknowledgement-reception/acknowledgement-reception.component.ts
+++ b/src/frontend/app/registeredMail/acknowledgement-reception/acknowledgement-reception.component.ts
@@ -112,8 +112,12 @@ export class AcknowledgementReceptionComponent implements OnInit {
         this.http.put('../rest/registeredMails/acknowledgement', data).pipe(
             tap((resultData: any) => {
                 if (resultData.canRescan) {
-                    data['status'] = resultData.status;
-                    const dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.translate.instant('lang.confirmRescanTitle'), msg: this.translate.instant('lang.confirmRescan') } });
+                    data.status = resultData.previousStatus;
+                    let message = this.translate.instant('lang.confirmRescanToNotDistributed');
+                    if (data.type === 'distributed') {
+                        message = this.translate.instant('lang.confirmRescanToNotDistributed');
+                    }
+                    const dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.translate.instant('lang.confirmRescanTitle'), msg: message } });
 
                     dialogRef.afterClosed().pipe(
                         filter((dialogData: string) => dialogData === 'ok'),
@@ -125,7 +129,7 @@ export class AcknowledgementReceptionComponent implements OnInit {
                 } else {
                     this.notify.success(this.translate.instant('lang.arReceived'));
 
-                    data.status = resultData.status;
+                    data.status = resultData.previousStatus;
                     const receivedList = this.dataSource.data;
                     receivedList.unshift(data);
                     this.dataSource.data = receivedList;
diff --git a/src/lang/lang-en.json b/src/lang/lang-en.json
index 7aabfd170f2..27827a8fad6 100644
--- a/src/lang/lang-en.json
+++ b/src/lang/lang-en.json
@@ -2176,6 +2176,7 @@
     "templateNameMandatory": "Template name mandatory",
     "attachmentTypeUsed": "This type is used in attachment",
     "confirmRescanTitle": "Registered mail not distributed",
-    "confirmRescan": "This registerde mail was already scanned Not distributed. Do you want to rescan it to distributed ?",
+    "confirmRescanToDistributed": "This registered mail was already scanned Not distributed. Do you want to rescan it to distributed ?",
+    "confirmRescanToNotDistributed": "This registered mail was already scanned distributed. Do you want to rescan it to not distributed ?",
     "selectReturnReason": "Please select a return reason"
 }
diff --git a/src/lang/lang-fr.json b/src/lang/lang-fr.json
index 2e46284dbcf..df813db5d1c 100644
--- a/src/lang/lang-fr.json
+++ b/src/lang/lang-fr.json
@@ -2186,7 +2186,8 @@
     "noneAlt": "Aucune",
     "attachmentTypeUsed": "Ce type est utilisé pour certaines pièces jointes",
     "receptionCanceled": "Réception annulée",
-    "confirmRescanTitle": "Recommandé non distribué",
-    "confirmRescan": "Ce recommandé a déjà été scanné Non distribué. Voulez-vous le rescanner en distribué ?",
+    "confirmRescanTitle": "Recommandé déjà reçu",
+    "confirmRescanToDistributed": "Ce recommandé a déjà été scanné Non distribué. Voulez-vous le rescanner en distribué ?",
+    "confirmRescanToNotDistributed": "Ce recommandé a déjà été scanné Distribué. Voulez-vous le rescanner en non distribué ?",
     "selectReturnReason": "Veuillez sélectionner un motif de retour"
 }
-- 
GitLab