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

FEAT #12981 TIME 2:30 change control in manual AR

parent 732662ee
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,6 @@ use SrcCore\models\ValidatorModel; ...@@ -28,7 +28,6 @@ use SrcCore\models\ValidatorModel;
use Template\models\TemplateModel; use Template\models\TemplateModel;
use User\models\UserModel; use User\models\UserModel;
trait AcknowledgementReceiptTrait trait AcknowledgementReceiptTrait
{ {
public static function createAcknowledgementReceipts(array $args) public static function createAcknowledgementReceipts(array $args)
...@@ -40,10 +39,15 @@ trait AcknowledgementReceiptTrait ...@@ -40,10 +39,15 @@ trait AcknowledgementReceiptTrait
if (empty($resource) || $resource['category_id'] != 'incoming') { if (empty($resource) || $resource['category_id'] != 'incoming') {
return []; return [];
} }
if ($args['data']['manual'] && $args['parameters']['mode'] == 'auto') {
return [];
} elseif (!$args['data']['manual'] && $args['parameters']['mode'] == 'manual') {
return [];
}
$subjectResource = $resource['subject'] ?? ''; $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; $contentToSend = $args['data']['content'] ?? null;
$subjectToSend = !empty($args['data']['subject']) ? $args['data']['subject'] : $subjectResource; $subjectToSend = !empty($args['data']['subject']) ? $args['data']['subject'] : $subjectResource;
} else { } else {
...@@ -73,21 +77,24 @@ trait AcknowledgementReceiptTrait ...@@ -73,21 +77,24 @@ trait AcknowledgementReceiptTrait
} else { } else {
$templateAttachmentType = 'simple'; $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']]); if (!$args['data']['manual']) {
$pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $template[0]['template_path']) . $template[0]['template_file_name']; $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']]); $currentUser = UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id', 'mail']]);
$ids = []; $ids = [];
$errors = []; $errors = [];
$emailsToSend = []; $emailsToSend = [];
DatabaseModel::beginTransaction(); DatabaseModel::beginTransaction();
foreach ($contactsToProcess as $contactToProcess) { foreach ($contactsToProcess as $contactToProcess) {
...@@ -113,7 +120,7 @@ trait AcknowledgementReceiptTrait ...@@ -113,7 +120,7 @@ trait AcknowledgementReceiptTrait
} }
$format = 'html'; $format = 'html';
} else { } else {
if (empty($contentToSend)) { if (!$args['data']['manual']) {
if (!file_exists($pathToDocument) || !is_file($pathToDocument)) { if (!file_exists($pathToDocument) || !is_file($pathToDocument)) {
DatabaseModel::rollbackTransaction(); DatabaseModel::rollbackTransaction();
return []; return [];
...@@ -169,7 +176,7 @@ trait AcknowledgementReceiptTrait ...@@ -169,7 +176,7 @@ trait AcknowledgementReceiptTrait
} }
DatabaseModel::commitTransaction(); DatabaseModel::commitTransaction();
if (!empty($emailsToSend)) { if (!empty($emailsToSend) && !empty($resource['destination'])) {
$entity = EntityModel::getByEntityId(['entityId' => $resource['destination'], 'select' => ['email', 'id']]); $entity = EntityModel::getByEntityId(['entityId' => $resource['destination'], 'select' => ['email', 'id']]);
} }
foreach ($emailsToSend as $email) { foreach ($emailsToSend as $email) {
......
...@@ -163,7 +163,19 @@ class PreProcessActionController ...@@ -163,7 +163,19 @@ class PreProcessActionController
return $response->withStatus(400)->withJson(['errors' => 'Action does not exist']); return $response->withStatus(400)->withJson(['errors' => 'Action does not exist']);
} }
$parameters = json_decode($action['parameters'], true); $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']]); $currentUser = UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
...@@ -241,14 +253,12 @@ class PreProcessActionController ...@@ -241,14 +253,12 @@ class PreProcessActionController
$doctype = DoctypeModel::getById(['id' => $resource['type_id'], 'select' => ['process_mode']]); $doctype = DoctypeModel::getById(['id' => $resource['type_id'], 'select' => ['process_mode']]);
if (empty($resource['destination'])) { if (empty($resource['destination']) && $currentMode == 'auto') {
$noSendAR['number'] += 1; $noSendAR['number'] += 1;
$noSendAR['list'][] = ['resId' => $resId, 'alt_identifier' => $resource['alt_identifier'], 'info' => _NO_ENTITY]; $noSendAR['list'][] = ['resId' => $resId, 'alt_identifier' => $resource['alt_identifier'], 'info' => _NO_ENTITY];
continue; continue;
} }
$entity = EntityModel::getByEntityId(['select' => ['entity_label'], 'entityId' => $resource['destination']]);
if ($doctype['process_mode'] == 'SVA') { if ($doctype['process_mode'] == 'SVA') {
$templateAttachmentType = 'sva'; $templateAttachmentType = 'sva';
} elseif ($doctype['process_mode'] == 'SVR') { } elseif ($doctype['process_mode'] == 'SVR') {
...@@ -256,22 +266,25 @@ class PreProcessActionController ...@@ -256,22 +266,25 @@ class PreProcessActionController
} else { } else {
$templateAttachmentType = 'simple'; $templateAttachmentType = 'simple';
} }
$template = TemplateModel::getWithAssociation([ if ($currentMode == 'auto') {
'select' => ['template_content', 'template_path', 'template_file_name'], $entity = EntityModel::getByEntityId(['select' => ['entity_label'], 'entityId' => $resource['destination']]);
'where' => ['template_target = ?', 'template_attachment_type = ?', 'value_field = ?'], $template = TemplateModel::getWithAssociation([
'data' => ['acknowledgementReceipt', $templateAttachmentType, $resource['destination']] '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'] ]; if (empty($template[0])) {
continue; $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 //Verify sending
$acknowledgements = AcknowledgementReceiptModel::get([ $acknowledgements = AcknowledgementReceiptModel::get([
'select' => ['res_id', 'type', 'format', 'creation_date', 'send_date'], 'select' => ['res_id', 'type', 'format', 'creation_date', 'send_date'],
...@@ -329,7 +342,7 @@ class PreProcessActionController ...@@ -329,7 +342,7 @@ class PreProcessActionController
} }
if (!empty($contact['email'])) { if (!empty($contact['email'])) {
if (empty($template[0]['template_content'])) { if (empty($template[0]['template_content']) && $currentMode == 'auto') {
$noSendAR['number'] += 1; $noSendAR['number'] += 1;
$noSendAR['list'][] = ['resId' => $resId, 'alt_identifier' => $resource['alt_identifier'], 'info' => _NO_EMAIL_TEMPLATE . ' \'' . $templateAttachmentType . '\' ' . _FOR_ENTITY . ' ' . $entity['entity_label'] ]; $noSendAR['list'][] = ['resId' => $resId, 'alt_identifier' => $resource['alt_identifier'], 'info' => _NO_EMAIL_TEMPLATE . ' \'' . $templateAttachmentType . '\' ' . _FOR_ENTITY . ' ' . $entity['entity_label'] ];
continue 2; continue 2;
...@@ -337,7 +350,7 @@ class PreProcessActionController ...@@ -337,7 +350,7 @@ class PreProcessActionController
$email += 1; $email += 1;
} }
} elseif (!empty($contact['address_street']) && !empty($contact['address_town']) && !empty($contact['address_postcode'])) { } 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['number'] += 1;
$noSendAR['list'][] = ['resId' => $resId, 'alt_identifier' => $resource['alt_identifier'], 'info' => _NO_PAPER_TEMPLATE . ' \'' . $templateAttachmentType . '\' ' . _FOR_ENTITY . ' ' . $entity['entity_label'] ]; $noSendAR['list'][] = ['resId' => $resId, 'alt_identifier' => $resource['alt_identifier'], 'info' => _NO_PAPER_TEMPLATE . ' \'' . $templateAttachmentType . '\' ' . _FOR_ENTITY . ' ' . $entity['entity_label'] ];
continue 2; continue 2;
......
...@@ -5,16 +5,16 @@ ...@@ -5,16 +5,16 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-12"> <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 === 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.resource.chrono}}</b>
<b *ngIf="data.resIds.length > 1" color="primary" class="highlight">{{data.resIds.length}} <b *ngIf="data.resIds.length > 1" color="primary" class="highlight">{{data.resIds.length}}
{{lang.elements}}</b> ? {{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)"> <mat-slide-toggle [(ngModel)]="manualAR" color="primary" (change)="toggleArManual($event.checked)">
{{lang.editAcknowledgementReceipt}}</mat-slide-toggle> {{lang.editAcknowledgementReceipt}}</mat-slide-toggle>
</div> </div>
<div *ngIf="manualAR"> <div *ngIf="manualAR && realResSelected.length > 0">
<mat-form-field floatLabel="never"> <mat-form-field floatLabel="never">
<span matPrefix><span class="attachLabel">{{lang.object}}&nbsp;:&nbsp;</span>[AR]&nbsp;</span> <span matPrefix><span class="attachLabel">{{lang.object}}&nbsp;:&nbsp;</span>[AR]&nbsp;</span>
<input matInput [(ngModel)]="emailsubject" maxlength="100"> <input matInput [(ngModel)]="emailsubject" maxlength="100">
......
...@@ -38,6 +38,7 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe ...@@ -38,6 +38,7 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe
}; };
realResSelected: number[]= []; realResSelected: number[]= [];
currentMode: string = '';
manualAR: boolean = false; manualAR: boolean = false;
arMode: 'auto' | 'manual' | 'both' = 'auto'; arMode: 'auto' | 'manual' | 'both' = 'auto';
...@@ -54,7 +55,11 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe ...@@ -54,7 +55,11 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe
ngOnInit(): void { ngOnInit(): void {
this.loadingInit = true; 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) => { .subscribe((data: any) => {
this.acknowledgement = data; this.acknowledgement = data;
this.realResSelected = data.sendList; this.realResSelected = data.sendList;
...@@ -90,7 +95,8 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe ...@@ -90,7 +95,8 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe
if (this.manualAR) { if (this.manualAR) {
data = { data = {
subject : this.emailsubject, 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( 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 ...@@ -146,6 +152,8 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe
toggleArManual(state: boolean) { toggleArManual(state: boolean) {
if (state) { if (state) {
this.currentMode = 'mode=manual';
this.checkAcknowledgementReceipt();
this.manualAR = true; this.manualAR = true;
if (this.data.resIds.length === 1) { if (this.data.resIds.length === 1) {
this.emailsubject = this.data.resource.subject; this.emailsubject = this.data.resource.subject;
...@@ -156,8 +164,10 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe ...@@ -156,8 +164,10 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe
this.initSignEmailModelsList(); this.initSignEmailModelsList();
setTimeout(() => { setTimeout(() => {
this.initMce(); this.initMce();
}, 0); }, 800);
} else { } else {
this.currentMode = 'mode=auto';
this.checkAcknowledgementReceipt();
tinymce.remove(); tinymce.remove();
this.manualAR = false; this.manualAR = false;
} }
......
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