diff --git a/rest/index.php b/rest/index.php
index 6990d6265083f9c6e6150e87f435eb7e8f7ad29b..1c545cc4742cf23b2e0e2dea1f716ebf71708bfb 100755
--- a/rest/index.php
+++ b/rest/index.php
@@ -69,6 +69,7 @@ $app->get('/administration', \SrcCore\controllers\CoreController::class . ':getA
 
 //Attachments
 $app->post('/attachments', \Attachment\controllers\AttachmentController::class . ':create');
+$app->get('/attachmentsTypes', \Attachment\controllers\AttachmentController::class . ':getAttachmentsTypes');
 $app->get('/resources/{resId}/attachments', \Attachment\controllers\AttachmentController::class . ':getByResId');
 $app->get('/res/{resIdMaster}/attachments/{resId}/content', \Attachment\controllers\AttachmentController::class . ':getFileContent');
 $app->get('/resources/{resId}/attachments/{id}/originalContent', \Attachment\controllers\AttachmentController::class . ':getOriginalFileContent');
diff --git a/src/app/attachment/controllers/AttachmentController.php b/src/app/attachment/controllers/AttachmentController.php
index da4f7825b12e0ca1b346df7a4a85054cd8ea96c9..0a8c8cf21851ea32ddfc39dde3c8d34c9dbfb6d7 100755
--- a/src/app/attachment/controllers/AttachmentController.php
+++ b/src/app/attachment/controllers/AttachmentController.php
@@ -40,31 +40,51 @@ class AttachmentController
 {
     public function create(Request $request, Response $response)
     {
-        $data = $request->getParams();
-
-        $check = Validator::notEmpty()->validate($data['encodedFile']);
-        $check = $check && Validator::stringType()->notEmpty()->validate($data['fileFormat']);
-        $check = $check && Validator::stringType()->notEmpty()->validate($data['status']);
-        $check = $check && Validator::stringType()->notEmpty()->validate($data['collId']);
-        $check = $check && Validator::stringType()->notEmpty()->validate($data['table']);
-        $check = $check && Validator::arrayType()->notEmpty()->validate($data['data']);
-        if (!$check) {
-            return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
+        $body = $request->getParsedBody();
+
+        if (empty($body)) {
+            return $response->withStatus(400)->withJson(['errors' => 'Body is not set or empty']);
+        } elseif (!Validator::notEmpty()->validate($body['encodedFile'])) {
+            return $response->withStatus(400)->withJson(['errors' => 'Body encodedFile is empty']);
+        } elseif (!Validator::stringType()->notEmpty()->validate($body['format'])) {
+            return $response->withStatus(400)->withJson(['errors' => 'Body format is empty or not a string']);
+        }
+
+        $mandatoryColumns = ['res_id_master', 'attachment_type'];
+        foreach ($body['data'] as $value) {
+            foreach ($mandatoryColumns as $columnKey => $column) {
+                if ($column == $value['column'] && !empty($value['value'])) {
+                    if ($column == 'res_id_master' && !ResController::hasRightByResId(['resId' => [$value['value']], 'userId' => $GLOBALS['userId']])) {
+                        return $response->withStatus(403)->withJson(['errors' => 'ResId master out of perimeter']);
+                    }
+                    unset($mandatoryColumns[$columnKey]);
+                }
+            }
+        }
+        if (!empty($mandatoryColumns)) {
+            return $response->withStatus(400)->withJson(['errors' => 'Body data array needs column(s) [' . implode(', ', $mandatoryColumns) . ']']);
         }
 
-        $resId = StoreController::storeResourceRes($data);
+        $body['table'] = empty($body['version']) ? 'res_attachments' : 'res_version_attachments';
+        $body['status'] = 'A_TRA';
+        $body['collId'] = 'letterbox_coll';
+        $body['data'][] = ['column' => 'coll_id', 'value' => 'letterbox_coll'];
+        $body['data'][] = ['column' => 'type_id', 'value' => '0'];
+        $body['data'][] = ['column' => 'relation', 'value' => '1'];
+        $body['fileFormat'] = $body['format'];
+        $resId = StoreController::storeResourceRes($body);
 
         if (empty($resId) || !empty($resId['errors'])) {
             return $response->withStatus(500)->withJson(['errors' => '[AttachmentController create] ' . $resId['errors']]);
         }
 
         HistoryController::add([
-            'tableName' => 'res_attachments',
+            'tableName' => $body['table'],
             'recordId'  => $resId,
             'eventType' => 'ADD',
             'info'      => _DOC_ADDED,
             'moduleId'  => 'attachment',
-            'eventId'   => 'attachmentadd',
+            'eventId'   => 'attachmentAdd',
         ]);
 
         return $response->withJson(['resId' => $resId]);
@@ -86,6 +106,7 @@ class AttachmentController
             'excludeAttachmentTypes'    => $excludeAttachmentTypes,
             'orderBy'                   => ['res_id DESC']
         ]);
+        $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML();
         foreach ($attachments as $key => $attachment) {
             if (!empty($attachment['res_id_version'])) {
                 $attachments[$key]['res_id'] = $attachment['res_id_version'];
@@ -105,10 +126,12 @@ class AttachmentController
                     $attachments[$key]['contact'] = $contact['contact']['contact'];
                 }
             }
+            if (!empty($attachmentsTypes[$attachment['attachment_type']]['label'])) {
+                $attachments[$key]['typeLabel'] = $attachmentsTypes[$attachment['attachment_type']]['label'];
+            }
         }
-        $attachmentTypes = AttachmentModel::getAttachmentsTypesByXML();
 
-        return $response->withJson(['attachments' => $attachments, 'attachmentTypes'  => $attachmentTypes]);
+        return $response->withJson(['attachments' => $attachments]);
     }
 
     public function setInSignatureBook(Request $request, Response $response, array $aArgs)
@@ -423,6 +446,13 @@ class AttachmentController
         return $response->withHeader('Content-Type', $mimeType);
     }
 
+    public function getAttachmentsTypes(Request $request, Response $response)
+    {
+        $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML();
+
+        return $response->withJson(['attachmentsTypes' => $attachmentsTypes]);
+    }
+
     public static function getEncodedDocument(array $aArgs)
     {
         ValidatorModel::notEmpty($aArgs, ['id']);
diff --git a/src/app/entity/controllers/EntityController.php b/src/app/entity/controllers/EntityController.php
index ad52dfdfdbe7b5b4f5cbe89378e446e895381c35..cb5785ae4bac035f6e4f09381514e2043995f272 100755
--- a/src/app/entity/controllers/EntityController.php
+++ b/src/app/entity/controllers/EntityController.php
@@ -313,7 +313,6 @@ class EntityController
             }
         }
 
-        $listTemplates = ListTemplateModel::get(['select' => [1], 'where' => ['object_id = ?'], 'data' => [$aArgs['id']]]);
         $children = EntityModel::get(['select' => [1], 'where' => ['parent_entity_id = ?'], 'data' => [$aArgs['id']]]);
         $documents = ResModel::get(['select' => [1], 'where' => ['destination = ?'], 'data' => [$aArgs['id']]]);
         $users = EntityModel::getUsersById(['select' => [1], 'id' => $aArgs['id']]);
@@ -321,12 +320,14 @@ class EntityController
         $instances = ListInstanceModel::get(['select' => [1], 'where' => ['item_id = ?', 'item_type = ?'], 'data' => [$aArgs['id'], 'entity_id']]);
         $redirects = GroupBasketRedirectModel::get(['select' => [1], 'where' => ['entity_id = ?'], 'data' => [$aArgs['id']]]);
 
-        $allowedCount = count($listTemplates) + count($children) + count($documents) + count($users) + count($templates) + count($instances) + count($redirects);
+        $allowedCount = count($children) + count($documents) + count($users) + count($templates) + count($instances) + count($redirects);
         if ($allowedCount > 0) {
             return $response->withStatus(400)->withJson(['errors' => 'Entity is still used']);
         }
 
+        ListTemplateModel::delete(['where' => ['object_id = ?'], 'data' => [$aArgs['id']]]);
         EntityModel::delete(['where' => ['entity_id = ?'], 'data' => [$aArgs['id']]]);
+
         HistoryController::add([
             'tableName' => 'entities',
             'recordId'  => $aArgs['id'],