diff --git a/rest/index.php b/rest/index.php index 6cd90df7a9796d6b365b7658abd44098221d6de2..0c5c3cad65a7699b1571f70921a60544c3fc8e1b 100755 --- a/rest/index.php +++ b/rest/index.php @@ -394,6 +394,7 @@ $app->post('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/ac $app->post('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/actions/{actionId}/checkContinueOpinionCircuit', \Action\controllers\PreProcessActionController::class . ':checkContinueOpinionCircuit'); $app->post('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/actions/{actionId}/checkGiveParallelOpinion', \Action\controllers\PreProcessActionController::class . ':checkGiveParallelOpinion'); $app->post('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/actions/{actionId}/checkValidateParallelOpinionDiffusion', \Action\controllers\PreProcessActionController::class . ':checkValidateParallelOpinionDiffusion'); +$app->post('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/actions/{actionId}/checkRejectVisaBackToPrevious', \Action\controllers\PreProcessActionController::class . ':checkRejectVisaBackToPrevious'); //Search $app->get('/search', \Search\controllers\SearchController::class . ':get'); diff --git a/src/app/action/controllers/PreProcessActionController.php b/src/app/action/controllers/PreProcessActionController.php index 8acee7bc2e9b6be7dcd46faa0c664092f0382a4e..6954695eca1e143859ff18cb479bbba2d174cf07 100755 --- a/src/app/action/controllers/PreProcessActionController.php +++ b/src/app/action/controllers/PreProcessActionController.php @@ -985,6 +985,68 @@ class PreProcessActionController return $response->withJson(['resourcesInformations' => $resourcesInformations]); } + public function checkRejectVisaBackToPrevious(Request $request, Response $response, array $args) + { + $body = $request->getParsedBody(); + + if (!Validator::arrayType()->notEmpty()->validate($body['resources'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body resources is empty or not an array']); + } + + $errors = ResourceListController::listControl(['groupId' => $args['groupId'], 'userId' => $args['userId'], 'basketId' => $args['basketId'], 'currentUserId' => $GLOBALS['id']]); + if (!empty($errors['errors'])) { + return $response->withStatus($errors['code'])->withJson(['errors' => $errors['errors']]); + } + + $body['resources'] = array_slice($body['resources'], 0, 500); + if (!ResController::hasRightByResId(['resId' => $body['resources'], 'userId' => $GLOBALS['id']])) { + return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); + } + + $signableAttachmentsTypes = []; + $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); + foreach ($attachmentsTypes as $key => $type) { + if ($type['sign']) { + $signableAttachmentsTypes[] = $key; + } + } + + $resourcesInformation = []; + foreach ($body['resources'] as $resId) { + $resource = ResModel::getById(['resId' => $resId, 'select' => ['alt_identifier']]); + if (empty($resource['alt_identifier'])) { + $resource['alt_identifier'] = _UNDEFINED; + } + + $isSignatory = ListInstanceModel::get(['select' => ['signatory', 'requested_signature'], 'where' => ['res_id = ?', 'difflist_type = ?', 'process_date is null'], 'data' => [$resId, 'VISA_CIRCUIT'], 'orderBy' => ['listinstance_id'], 'limit' => 1]); + if (empty($isSignatory[0])) { + $hasCircuit = ListInstanceModel::get(['select' => [1], 'where' => ['res_id = ?', 'difflist_type = ?'], 'data' => [$resId, 'VISA_CIRCUIT']]); + if (!empty($hasCircuit)) { + $resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'endedCircuit']; + } else { + $resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'noCircuitAvailable']; + } + } elseif ($isSignatory[0]['requested_signature'] && !$isSignatory[0]['signatory']) { + $resourcesInformation['warning'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'userHasntSigned']; + } else { + $hasPrevious = ListInstanceModel::get([ + 'select' => [1], + 'where' => ['res_id = ?', 'difflist_type = ?', 'process_date is not null'], + 'data' => [$resId, 'VISA_CIRCUIT'], + 'orderBy' => ['listinstance_id'], + 'limit' => 1 + ]); + if (!empty($hasPrevious)) { + $resourcesInformation['success'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId]; + } else { + $resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'noPreviousAvailable']; + } + } + } + + return $response->withJson(['resourcesInformations' => $resourcesInformation]); + } + public function checkValidateParallelOpinion(Request $request, Response $response, array $args) { $body = $request->getParsedBody(); diff --git a/src/frontend/app/actions/visa-reject-back-to-previous-action/reject-visa-back-to-previous-action.component.html b/src/frontend/app/actions/visa-reject-back-to-previous-action/reject-visa-back-to-previous-action.component.html index 2a1b9b13dfdbf623b0f18355ddad50dd0cb8dfb0..e1ec516307fccaf7181fb2a57bead5fd88e4c53e 100644 --- a/src/frontend/app/actions/visa-reject-back-to-previous-action/reject-visa-back-to-previous-action.component.html +++ b/src/frontend/app/actions/visa-reject-back-to-previous-action/reject-visa-back-to-previous-action.component.html @@ -11,6 +11,25 @@ {{lang.elements}}</b> ? <div *ngIf="data.resIds.length > 1" class="alert-message alert-message-info" role="alert" style="margin-top: 30px;" [innerHTML]="lang.rejectVisaBack"></div> <div *ngIf="data.resIds.length == 1 && appVisaWorkflow !== undefined && appVisaWorkflow.getLastVisaUser() !== ''" class="alert-message alert-message-info" role="alert" style="margin-top: 30px;" [innerHTML]="lang.rejectVisaBackUser + ' <b>' + appVisaWorkflow.getLastVisaUser().labelToDisplay + '</b>'"></div> + + <div *ngIf="resourcesErrors.length > 0" class="alert-message alert-message-danger mailList" role="alert"> + <p> + {{lang.canNotMakeAction}} : + </p> + <ul> + <li *ngFor="let ressource of resourcesErrors"> + <b>{{ressource.alt_identifier}}</b> : {{lang[ressource.reason]}} + </li> + </ul> + </div> + <div *ngIf="resourcesWarnings.length > 0" class="alert-message alert-message-info mailList" role="alert"> + <ul style="margin: 0;padding-bottom: 0px;"> + <li *ngFor="let ressource of resourcesWarnings"> + <b>{{ressource.alt_identifier}}</b> : {{lang[ressource.reason]}} + </li> + </ul> + </div> + <app-visa-workflow *ngIf="data.resIds.length == 1" [adminMode]="false" [resId]="data.resIds[0]" #appVisaWorkflow> </app-visa-workflow> </div> @@ -20,7 +39,7 @@ </div> </div> <div mat-dialog-actions class="actions"> - <button mat-raised-button mat-button color="primary" [disabled]="loading" + <button mat-raised-button mat-button color="primary" [disabled]="loading || !isValidAction()" (click)="onSubmit()">{{lang.validate}}</button> <button mat-raised-button mat-button [disabled]="loading" [mat-dialog-close]="">{{lang.cancel}}</button> -</div> \ No newline at end of file +</div> diff --git a/src/frontend/app/actions/visa-reject-back-to-previous-action/reject-visa-back-to-previous-action.component.ts b/src/frontend/app/actions/visa-reject-back-to-previous-action/reject-visa-back-to-previous-action.component.ts index f6bdcb4fcd9997a99b87ee87a67dd7ae056ca2ef..54b418baa2b60a990998f980fe774206a1d5ee6d 100644 --- a/src/frontend/app/actions/visa-reject-back-to-previous-action/reject-visa-back-to-previous-action.component.ts +++ b/src/frontend/app/actions/visa-reject-back-to-previous-action/reject-visa-back-to-previous-action.component.ts @@ -7,6 +7,7 @@ import { NoteEditorComponent } from '../../notes/note-editor.component'; import { tap, finalize, catchError } from 'rxjs/operators'; import { of } from 'rxjs'; import { VisaWorkflowComponent } from '../../visa/visa-workflow.component'; +import {FunctionsService} from "../../../service/functions.service"; @Component({ templateUrl: "reject-visa-back-to-previous-action.component.html", @@ -18,6 +19,11 @@ export class RejectVisaBackToPrevousActionComponent implements OnInit { lang: any = LANG; loading: boolean = false; + resourcesWarnings: any[] = []; + resourcesErrors: any[] = []; + + noResourceToProcess: boolean = null; + @ViewChild('noteEditor', { static: true }) noteEditor: NoteEditorComponent; @ViewChild('appVisaWorkflow', { static: false }) appVisaWorkflow: VisaWorkflowComponent; @@ -25,10 +31,37 @@ export class RejectVisaBackToPrevousActionComponent implements OnInit { public http: HttpClient, private notify: NotificationService, public dialogRef: MatDialogRef<RejectVisaBackToPrevousActionComponent>, - @Inject(MAT_DIALOG_DATA) public data: any + @Inject(MAT_DIALOG_DATA) public data: any, + public functions: FunctionsService ) { } - ngOnInit() { } + async ngOnInit() { + this.loading = true; + await this.checkRejectVisaBackToPrevious(); + this.loading = false; + } + + checkRejectVisaBackToPrevious() { + this.resourcesErrors = []; + this.resourcesWarnings = []; + + return new Promise((resolve, reject) => { + this.http.post('../../rest/resourcesList/users/' + this.data.userId + '/groups/' + this.data.groupId + '/baskets/' + this.data.basketId + '/actions/' + this.data.action.id + '/checkRejectVisaBackToPrevious', { resources: this.data.resIds }) + .subscribe((data: any) => { + if (!this.functions.empty(data.resourcesInformations.warning)) { + this.resourcesWarnings = data.resourcesInformations.warning; + } + + if(!this.functions.empty(data.resourcesInformations.error)) { + this.resourcesErrors = data.resourcesInformations.error; + this.noResourceToProcess = this.resourcesErrors.length === this.data.resIds.length; + } + resolve(true); + }, (err: any) => { + this.notify.handleSoftErrors(err); + }); + }); + } onSubmit() { this.loading = true; @@ -47,4 +80,8 @@ export class RejectVisaBackToPrevousActionComponent implements OnInit { }) ).subscribe(); } + + isValidAction() { + return !this.noResourceToProcess; + } } diff --git a/src/frontend/lang/lang-en.ts b/src/frontend/lang/lang-en.ts index c4721ddfdff4fbecbdc01c46231298b60cd61851..f750cb54e51b410f2aa7a2d467aa89dde8e52001 100755 --- a/src/frontend/lang/lang-en.ts +++ b/src/frontend/lang/lang-en.ts @@ -1435,4 +1435,5 @@ export const LANG_EN = { "validateBy": "Validate by", "validateAvisParallel": "Your are validating an opinion request", "validateAvisParallelSingle": "Your are validating an opinion request of", + "noPreviousAvailable": "No previous signatories or visa available", }; diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts index 0d7eabe6d436237bc79794e13163bf8b6b1ce5fb..1a7728cd64a6efe49e1d24ed4b368b50e3c1d1d2 100755 --- a/src/frontend/lang/lang-fr.ts +++ b/src/frontend/lang/lang-fr.ts @@ -1475,4 +1475,5 @@ export const LANG_FR = { "validateBy": "Validé par", "validateAvisParallel": "Vous allez valider des demandes d'avis", "validateAvisParallelSingle": "Vous allez valider la demande d'avis de", + "noPreviousAvailable": "Aucun précédent signataire ou viseur disponible", }; diff --git a/src/frontend/lang/lang-nl.ts b/src/frontend/lang/lang-nl.ts index f2907e0ca606337b8b55ce537d3bef13973a662f..03ddfc5eba344f24a6bef7c9dbb66fe06bc26edb 100755 --- a/src/frontend/lang/lang-nl.ts +++ b/src/frontend/lang/lang-nl.ts @@ -1460,4 +1460,5 @@ export const LANG_NL = { "validateBy": "Validate by", //_TO_TRANSLATE "validateAvisParallel": "Your are validating an opinion request", //_TO_TRANSLATE "validateAvisParallelSingle": "Your are validating an opinion request of", //_TO_TRANSLATE + "noPreviousAvailable": "No previous signatories or visa available", //_TO_TRANSLATE };