Skip to content
Snippets Groups Projects
Verified Commit 20d1c1dd authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #13998 TIME 1 improve controls for registered mail

parent 24f4912b
No related branches found
No related tags found
No related merge requests found
......@@ -51,6 +51,8 @@ class RegisteredMailController
return $response->withStatus(400)->withJson(['errors' => 'Body warranty is not correct']);
} elseif ($body['type'] == 'RW' && $body['warranty'] == 'R3') {
return $response->withStatus(400)->withJson(['errors' => 'Body warranty R3 is not allowed for type RW']);
} elseif (!Validator::notEmpty()->validate($body['recipient'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body recipient is empty']);
}
$resource = ResModel::getById(['select' => ['departure_date'], 'resId' => $args['resId']]);
......@@ -68,6 +70,7 @@ class RegisteredMailController
'warranty' => $body['warranty'],
'reference' => $body['reference'],
'letter' => empty($body['letter']) ? 'false' : 'true',
'recipient' => json_encode($body['recipient']),
];
if ($registeredMail['type'] != $body['type']) {
......
......@@ -96,9 +96,11 @@ trait RegisteredMailTrait
if (!in_array($args['data']['type'], ['2D', '2C', 'RW'])) {
return ['errors' => ['Type is not correct']];
} elseif (!in_array($args['data']['warranty'], ['R1', 'R2', 'R3'])) {
return ['errors' => ['Type is not correct']];
return ['errors' => ['warranty is not correct']];
} elseif ($args['data']['type'] == 'RW' && $args['data']['warranty'] == 'R3') {
return ['errors' => ['R3 warranty is not allowed for type RW']];
} elseif (empty($args['data']['recipient']) || empty($args['data']['issuingSiteId'])) {
return ['errors' => ['recipient or issuingSiteId is missing to print registered mail']];
}
$issuingSite = IssuingSiteModel::getById([
......@@ -173,6 +175,8 @@ trait RegisteredMailTrait
$registeredMail = RegisteredMailModel::getByResId(['select' => ['issuing_site', 'type', 'number', 'warranty', 'letter', 'recipient', 'reference'], 'resId' => $args['resId']]);
if (empty($registeredMail)) {
return ['errors' => ['No registered mail for this resource']];
} elseif (empty(json_decode($registeredMail['recipient'])) || empty($registeredMail['issuing_site']) || empty($registeredMail['type']) || empty($registeredMail['number']) || empty($registeredMail['warranty'])) {
return ['errors' => ['recipient, issuing_site, type, number or warranty is missing to print registered mail']];
}
RegisteredMailModel::update([
......
......@@ -39,6 +39,10 @@ export class PrintRegisteredMailActionComponent implements OnInit {
const downloadLink = document.createElement('a');
this.http.put(this.data.processActionRoute, { resources: this.data.resIds, note: this.noteEditor.getNote() }).pipe(
tap((data: any) => {
if (data && data.errors != null) {
this.notify.error(data.errors);
return of(false);
}
Object.values(data.data).forEach((encodedFile: string) => {
if (!this.functions.empty(encodedFile)) {
downloadLink.href = `data:application/pdf;base64,${encodedFile}`;
......
......@@ -13,7 +13,6 @@ import { of } from 'rxjs';
})
export class SaveAndPrintRegisteredMailActionComponent implements OnInit {
loading: boolean = false;
@ViewChild('noteEditor', { static: true }) noteEditor: NoteEditorComponent;
......@@ -54,6 +53,10 @@ export class SaveAndPrintRegisteredMailActionComponent implements OnInit {
})
),
tap((data: any) => {
if (data && data.errors != null) {
this.notify.error(data.errors);
return of(false);
}
const downloadLink = document.createElement('a');
downloadLink.href = `data:application/pdf;base64,${data}`;
downloadLink.setAttribute('download', 'recommande.pdf');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment