Skip to content
Snippets Groups Projects
Verified Commit a7f05abb authored by Damien's avatar Damien
Browse files

FEAT #12091 TIME 1:10 Send signed response when needed

parent a701f093
No related branches found
No related tags found
No related merge requests found
......@@ -30,7 +30,6 @@ use Resource\controllers\ResController;
use Resource\models\ResModel;
use Respect\Validation\Validator;
use SrcCore\models\CoreConfigModel;
use SrcCore\models\CurlModel;
use SrcCore\models\DatabaseModel;
use SrcCore\models\ValidatorModel;
use User\models\UserModel;
......
......@@ -59,9 +59,9 @@ trait ShippingTrait
$shippingTemplate['fee'] = json_decode($shippingTemplate['fee'], true);
$attachments = AttachmentModel::get([
'select' => ['res_id', 'title', 'recipient_id', 'recipient_type', 'external_id'],
'select' => ['res_id', 'title', 'recipient_id', 'recipient_type', 'external_id', 'status'],
'where' => ['res_id_master = ?', 'in_send_attach = ?', 'status not in (?)', 'attachment_type not in (?)'],
'data' => [$args['resId'], true, ['OBS', 'DEL', 'TMP', 'FRZ'], ['print_folder']]
'data' => [$args['resId'], true, ['OBS', 'DEL', 'TMP', 'FRZ'], ['print_folder', 'signed_response']]
]);
if (empty($attachments) && empty($integrations['inShipping'])) {
......@@ -73,6 +73,16 @@ trait ShippingTrait
$contacts = [];
foreach ($attachments as $attachment) {
$attachmentId = $attachment['res_id'];
if ($attachment['status'] == 'SIGN') {
$signedAttachment = AttachmentModel::get([
'select' => ['res_id'],
'where' => ['origin = ?', 'status not in (?)', 'attachment_type = ?'],
'data' => ["{$args['resId']},res_attachments", ['OBS', 'DEL', 'TMP', 'FRZ'], 'signed_response']
]);
if (!empty($signedAttachment[0])) {
$attachmentId = $signedAttachment[0]['res_id'];
}
}
$convertedDocument = AdrModel::getConvertedDocumentById([
'select' => ['docserver_id','path', 'filename', 'fingerprint'],
......@@ -105,12 +115,14 @@ trait ShippingTrait
$contactsResource = [];
if (!empty($integrations['inShipping'])) {
$convertedDocument = AdrModel::getConvertedDocumentById([
'select' => ['docserver_id','path', 'filename', 'fingerprint'],
'resId' => $args['resId'],
'collId' => 'letterbox_coll',
'type' => 'PDF'
$convertedDocument = AdrModel::getDocuments([
'select' => ['docserver_id', 'path', 'filename', 'fingerprint'],
'where' => ['res_id = ?', 'type in (?)', 'version = ?'],
'data' => [$args['resId'], ['PDF', 'SIGN'], $resource['version']],
'orderBy' => ['version', "type='SIGN' DESC"],
'limit' => 1
]);
$convertedDocument = $convertedDocument[0] ?? null;
if (empty($convertedDocument)) {
return ['errors' => ['No conversion for resource']];
}
......
......@@ -17,6 +17,7 @@ namespace ExternalSignatoryBook\controllers;
use Attachment\models\AttachmentModel;
use Contact\controllers\ContactController;
use Convert\controllers\ConvertPdfController;
use Convert\models\AdrModel;
use Docserver\models\DocserverModel;
use Entity\models\EntityModel;
use Entity\models\ListInstanceModel;
......@@ -246,8 +247,26 @@ class MaarchParapheurController
foreach ($attachments as $value) {
$resId = $value['res_id'];
$collId = 'attachments_coll';
$adrInfo = ConvertPdfController::getConvertedPdfById(['resId' => $resId, 'collId' => $collId]);
if ($value['status'] == 'SIGN') {
$signedAttachment = AttachmentModel::get([
'select' => ['res_id'],
'where' => ['origin = ?', 'status not in (?)', 'attachment_type = ?'],
'data' => ["{$resId},res_attachments", ['OBS', 'DEL', 'TMP', 'FRZ'], 'signed_response']
]);
if (!empty($signedAttachment[0])) {
$adrInfo = AdrModel::getConvertedDocumentById([
'select' => ['docserver_id','path', 'filename', 'fingerprint'],
'resId' => $signedAttachment[0]['res_id'],
'collId' => 'attachments_coll',
'type' => 'PDF'
]);
}
}
if (empty($adrInfo)) {
$adrInfo = ConvertPdfController::getConvertedPdfById(['resId' => $resId, 'collId' => $collId]);
}
if (empty($adrInfo['docserver_id']) || strtolower(pathinfo($adrInfo['filename'], PATHINFO_EXTENSION)) != 'pdf') {
return ['error' => 'Attachment ' . $resId . ' is not converted in 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