diff --git a/src/app/action/controllers/AcknowledgementReceiptTrait.php b/src/app/action/controllers/AcknowledgementReceiptTrait.php index 5c155eecfac1f72857ed1b15626746e5e439588b..69f1a0482d12ba929cd172c492b44311987536d8 100644 --- a/src/app/action/controllers/AcknowledgementReceiptTrait.php +++ b/src/app/action/controllers/AcknowledgementReceiptTrait.php @@ -28,7 +28,6 @@ use SrcCore\models\ValidatorModel; use Template\models\TemplateModel; use User\models\UserModel; - trait AcknowledgementReceiptTrait { public static function createAcknowledgementReceipts(array $args) @@ -40,10 +39,15 @@ trait AcknowledgementReceiptTrait if (empty($resource) || $resource['category_id'] != 'incoming') { return []; } + if ($args['data']['manual'] && $args['parameters']['mode'] == 'auto') { + return []; + } elseif (!$args['data']['manual'] && $args['parameters']['mode'] == 'manual') { + return []; + } $subjectResource = $resource['subject'] ?? ''; - if (!empty($args['parameters']['mode']) && ($args['parameters']['mode'] == 'both' || $args['parameters']['mode'] == 'manual')) { + if ($args['data']['manual']) { $contentToSend = $args['data']['content'] ?? null; $subjectToSend = !empty($args['data']['subject']) ? $args['data']['subject'] : $subjectResource; } else { @@ -73,21 +77,24 @@ trait AcknowledgementReceiptTrait } else { $templateAttachmentType = 'simple'; } - $template = TemplateModel::getWithAssociation([ - 'select' => ['template_content', 'template_path', 'template_file_name'], - 'where' => ['template_target = ?', 'template_attachment_type = ?', 'value_field = ?'], - 'data' => ['acknowledgementReceipt', $templateAttachmentType, $resource['destination']] - ]); - if (empty($template[0])) { - return []; - } - $docserver = DocserverModel::getByDocserverId(['docserverId' => 'TEMPLATES', 'select' => ['path_template']]); - $pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $template[0]['template_path']) . $template[0]['template_file_name']; + if (!$args['data']['manual']) { + $template = TemplateModel::getWithAssociation([ + 'select' => ['template_content', 'template_path', 'template_file_name'], + 'where' => ['template_target = ?', 'template_attachment_type = ?', 'value_field = ?'], + 'data' => ['acknowledgementReceipt', $templateAttachmentType, $resource['destination']] + ]); + if (empty($template[0])) { + return []; + } + + $docserver = DocserverModel::getByDocserverId(['docserverId' => 'TEMPLATES', 'select' => ['path_template']]); + $pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $template[0]['template_path']) . $template[0]['template_file_name']; + } $currentUser = UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id', 'mail']]); - $ids = []; - $errors = []; + $ids = []; + $errors = []; $emailsToSend = []; DatabaseModel::beginTransaction(); foreach ($contactsToProcess as $contactToProcess) { @@ -113,7 +120,7 @@ trait AcknowledgementReceiptTrait } $format = 'html'; } else { - if (empty($contentToSend)) { + if (!$args['data']['manual']) { if (!file_exists($pathToDocument) || !is_file($pathToDocument)) { DatabaseModel::rollbackTransaction(); return []; @@ -169,7 +176,7 @@ trait AcknowledgementReceiptTrait } DatabaseModel::commitTransaction(); - if (!empty($emailsToSend)) { + if (!empty($emailsToSend) && !empty($resource['destination'])) { $entity = EntityModel::getByEntityId(['entityId' => $resource['destination'], 'select' => ['email', 'id']]); } foreach ($emailsToSend as $email) { diff --git a/src/app/action/controllers/PreProcessActionController.php b/src/app/action/controllers/PreProcessActionController.php index fab89a798073f4c1e5ac0a42f2c9651d893e5cce..04f5cf6fa6ba97a52fcc9ded47704bbf71ca07dc 100755 --- a/src/app/action/controllers/PreProcessActionController.php +++ b/src/app/action/controllers/PreProcessActionController.php @@ -163,7 +163,19 @@ class PreProcessActionController return $response->withStatus(400)->withJson(['errors' => 'Action does not exist']); } $parameters = json_decode($action['parameters'], true); - $mode = $parameters['mode'] ?? 'auto'; + $mode = $parameters['mode'] ?? 'auto'; + $data = $request->getQueryParams(); + + if (empty($data['mode']) && $mode == 'both') { + $currentMode = 'auto'; + } elseif (empty($data['mode']) && $mode != 'both') { + $currentMode = $mode; + } elseif (!empty($data['mode'])) { + $currentMode = $data['mode']; + } + if (!in_array($currentMode, ['manual', 'auto'])) { + $currentMode = 'auto'; + } $currentUser = UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]); @@ -241,14 +253,12 @@ class PreProcessActionController $doctype = DoctypeModel::getById(['id' => $resource['type_id'], 'select' => ['process_mode']]); - if (empty($resource['destination'])) { + if (empty($resource['destination']) && $currentMode == 'auto') { $noSendAR['number'] += 1; $noSendAR['list'][] = ['resId' => $resId, 'alt_identifier' => $resource['alt_identifier'], 'info' => _NO_ENTITY]; continue; } - $entity = EntityModel::getByEntityId(['select' => ['entity_label'], 'entityId' => $resource['destination']]); - if ($doctype['process_mode'] == 'SVA') { $templateAttachmentType = 'sva'; } elseif ($doctype['process_mode'] == 'SVR') { @@ -256,22 +266,25 @@ class PreProcessActionController } else { $templateAttachmentType = 'simple'; } - - $template = TemplateModel::getWithAssociation([ - 'select' => ['template_content', 'template_path', 'template_file_name'], - 'where' => ['template_target = ?', 'template_attachment_type = ?', 'value_field = ?'], - 'data' => ['acknowledgementReceipt', $templateAttachmentType, $resource['destination']] - ]); - - if (empty($template[0])) { - $noSendAR['number'] += 1; - $noSendAR['list'][] = ['resId' => $resId, 'alt_identifier' => $resource['alt_identifier'], 'info' => _NO_TEMPLATE . ' \'' . $templateAttachmentType . '\' ' . _FOR_ENTITY . ' ' .$entity['entity_label'] ]; - continue; + + if ($currentMode == 'auto') { + $entity = EntityModel::getByEntityId(['select' => ['entity_label'], 'entityId' => $resource['destination']]); + $template = TemplateModel::getWithAssociation([ + 'select' => ['template_content', 'template_path', 'template_file_name'], + 'where' => ['template_target = ?', 'template_attachment_type = ?', 'value_field = ?'], + 'data' => ['acknowledgementReceipt', $templateAttachmentType, $resource['destination']] + ]); + + if (empty($template[0])) { + $noSendAR['number'] += 1; + $noSendAR['list'][] = ['resId' => $resId, 'alt_identifier' => $resource['alt_identifier'], 'info' => _NO_TEMPLATE . ' \'' . $templateAttachmentType . '\' ' . _FOR_ENTITY . ' ' .$entity['entity_label'] ]; + continue; + } + + $docserver = DocserverModel::getByDocserverId(['docserverId' => 'TEMPLATES', 'select' => ['path_template']]); + $pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $template[0]['template_path']) . $template[0]['template_file_name']; } - $docserver = DocserverModel::getByDocserverId(['docserverId' => 'TEMPLATES', 'select' => ['path_template']]); - $pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $template[0]['template_path']) . $template[0]['template_file_name']; - //Verify sending $acknowledgements = AcknowledgementReceiptModel::get([ 'select' => ['res_id', 'type', 'format', 'creation_date', 'send_date'], @@ -329,7 +342,7 @@ class PreProcessActionController } if (!empty($contact['email'])) { - if (empty($template[0]['template_content'])) { + if (empty($template[0]['template_content']) && $currentMode == 'auto') { $noSendAR['number'] += 1; $noSendAR['list'][] = ['resId' => $resId, 'alt_identifier' => $resource['alt_identifier'], 'info' => _NO_EMAIL_TEMPLATE . ' \'' . $templateAttachmentType . '\' ' . _FOR_ENTITY . ' ' . $entity['entity_label'] ]; continue 2; @@ -337,7 +350,7 @@ class PreProcessActionController $email += 1; } } elseif (!empty($contact['address_street']) && !empty($contact['address_town']) && !empty($contact['address_postcode'])) { - if (!file_exists($pathToDocument) || !is_file($pathToDocument)) { + if ((!file_exists($pathToDocument) || !is_file($pathToDocument)) && $currentMode == 'auto') { $noSendAR['number'] += 1; $noSendAR['list'][] = ['resId' => $resId, 'alt_identifier' => $resource['alt_identifier'], 'info' => _NO_PAPER_TEMPLATE . ' \'' . $templateAttachmentType . '\' ' . _FOR_ENTITY . ' ' . $entity['entity_label'] ]; continue 2; diff --git a/src/frontend/app/actions/create-acknowledgement-receipt-action/create-acknowledgement-receipt-action.component.html b/src/frontend/app/actions/create-acknowledgement-receipt-action/create-acknowledgement-receipt-action.component.html index 01464d2cf764e1e60952a26f2f890bc0fcdb1c14..92903e1e301613aa411bf82c59b4497c79ecd39d 100755 --- a/src/frontend/app/actions/create-acknowledgement-receipt-action/create-acknowledgement-receipt-action.component.html +++ b/src/frontend/app/actions/create-acknowledgement-receipt-action/create-acknowledgement-receipt-action.component.html @@ -5,16 +5,16 @@ </div> <div class="row"> <div class="col-md-12"> - <p *ngIf="acknowledgement.sendEmail || acknowledgement.sendPaper">{{lang.makeActionOn}} + <p *ngIf="arMode == 'both' || acknowledgement.sendEmail || acknowledgement.sendPaper">{{lang.makeActionOn}} <b *ngIf="data.resIds.length === 0" color="primary" class="highlight">{{lang.currentIndexingMail}}</b> <b *ngIf="data.resIds.length == 1" color="primary" class="highlight">{{data.resource.chrono}}</b> <b *ngIf="data.resIds.length > 1" color="primary" class="highlight">{{data.resIds.length}} {{lang.elements}}</b> ? - <div *ngIf="arMode !== 'manual' && arMode !== 'auto' && realResSelected.length > 0"> + <div *ngIf="arMode == 'both'"> <mat-slide-toggle [(ngModel)]="manualAR" color="primary" (change)="toggleArManual($event.checked)"> {{lang.editAcknowledgementReceipt}}</mat-slide-toggle> </div> - <div *ngIf="manualAR"> + <div *ngIf="manualAR && realResSelected.length > 0"> <mat-form-field floatLabel="never"> <span matPrefix><span class="attachLabel">{{lang.object}} : </span>[AR] </span> <input matInput [(ngModel)]="emailsubject" maxlength="100"> diff --git a/src/frontend/app/actions/create-acknowledgement-receipt-action/create-acknowledgement-receipt-action.component.ts b/src/frontend/app/actions/create-acknowledgement-receipt-action/create-acknowledgement-receipt-action.component.ts index e2e2c3766643bb5a3d9ce3ab76eec71141a8da9f..5df86eadd9d81bfce091b7c897cbd2defe8e9ad3 100644 --- a/src/frontend/app/actions/create-acknowledgement-receipt-action/create-acknowledgement-receipt-action.component.ts +++ b/src/frontend/app/actions/create-acknowledgement-receipt-action/create-acknowledgement-receipt-action.component.ts @@ -38,6 +38,7 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe }; realResSelected: number[]= []; + currentMode: string = ''; manualAR: boolean = false; arMode: 'auto' | 'manual' | 'both' = 'auto'; @@ -54,7 +55,11 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe ngOnInit(): void { this.loadingInit = true; - this.http.post('../../rest/resourcesList/users/' + this.data.userId + '/groups/' + this.data.groupId + '/baskets/' + this.data.basketId + '/actions/' + this.data.action.id + '/checkAcknowledgementReceipt', { resources: this.data.resIds }) + this.checkAcknowledgementReceipt(); + } + + checkAcknowledgementReceipt() { + this.http.post('../../rest/resourcesList/users/' + this.data.userId + '/groups/' + this.data.groupId + '/baskets/' + this.data.basketId + '/actions/' + this.data.action.id + '/checkAcknowledgementReceipt?' + this.currentMode, { resources: this.data.resIds }) .subscribe((data: any) => { this.acknowledgement = data; this.realResSelected = data.sendList; @@ -90,7 +95,8 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe if (this.manualAR) { data = { subject : this.emailsubject, - content : tinymce.get('emailSignature').getContent() + content : tinymce.get('emailSignature').getContent(), + manual : true } } this.http.put(this.data.processActionRoute, { resources: this.realResSelected, note: this.noteEditor.getNote(), data }).pipe( @@ -146,6 +152,8 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe toggleArManual(state: boolean) { if (state) { + this.currentMode = 'mode=manual'; + this.checkAcknowledgementReceipt(); this.manualAR = true; if (this.data.resIds.length === 1) { this.emailsubject = this.data.resource.subject; @@ -156,8 +164,10 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe this.initSignEmailModelsList(); setTimeout(() => { this.initMce(); - }, 0); + }, 800); } else { + this.currentMode = 'mode=auto'; + this.checkAcknowledgementReceipt(); tinymce.remove(); this.manualAR = false; }