22 $result = parent::processBeforeAction($action);
26 && !Manager::isActiveProviderByModule(Manager::PROVIDER_STORE_DOCUMENT,
'crm')
29 $this->addError(
new Error(
'Contractors should be provided by CRM'));
64 $canModify = $this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_MODIFY);
65 if (!$canModify->isSuccess())
70 $checkFieldsResult = $this->checkFields($fields);
71 if (!$checkFieldsResult->isSuccess())
73 $this->addErrors($checkFieldsResult->getErrors());
78 $addResult = StoreDocumentContractorTable::add([
79 'DOCUMENT_ID' => (
int)$fields[
'DOCUMENT_ID'],
80 'ENTITY_ID' => (
int)$fields[
'ENTITY_ID'],
81 'ENTITY_TYPE_ID' => (
int)$fields[
'ENTITY_TYPE_ID'],
84 if (!$addResult->isSuccess())
86 $this->addErrors($checkFieldsResult->getErrors());
92 'DOCUMENT_CONTRACTOR' => $this->
get($addResult->getId()),
104 $existsResult = $this->exists($id);
105 if (!$existsResult->isSuccess())
107 $this->addError(
new Error(
'Binding was not found'));
112 $canModify = $this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_MODIFY);
113 if (!$canModify->isSuccess())
118 $deleteResult = StoreDocumentContractorTable::delete($id);
121 $this->addErrors($deleteResult->getErrors());
144 'DOCUMENT_CONTRACTOR',
145 $this->getList($select, $filter, $order, $pageNavigation),
146 $this->count($filter)
158 private function checkFields(array $fields):
Result
161 $documentId = (int)$fields[
'DOCUMENT_ID'];
162 $entityTypeId = (int)$fields[
'ENTITY_TYPE_ID'];
163 $entityId = (int)$fields[
'ENTITY_ID'];
167 $result->addError(
new Error(
'Store document was not found'));
185 $result->addError(
new Error(
'Store document was not found'));
192 $result->addError(
new Error(
'Type of store document is wrong'));
195 if ($document[
'STATUS'] ===
'Y')
197 $result->addError(
new Error(
'Unable to edit conducted document'));
201 $entityTypeId !== \CCrmOwnerType::Contact
202 && $entityTypeId !== \CCrmOwnerType::Company
205 $result->addError(
new Error(
'Wrong entity type id'));
210 $result->addError(
new Error(
'Wrong entity id'));
213 $bindingExists = $this->existsByFilter([
214 'DOCUMENT_ID' => $documentId,
215 'ENTITY_TYPE_ID' => $entityTypeId,
216 'ENTITY_ID' => $entityId,
218 if ($bindingExists->isSuccess())
220 $result->addError(
new Error(
'This contractor has been already bound to this document'));
223 if ($entityTypeId === \CCrmOwnerType::Company)
225 $documentCompanyBinding = StoreDocumentContractorTable::getRow([
228 'DOCUMENT_ID' => $documentId,
229 'ENTITY_TYPE_ID' => \CCrmOwnerType::Company,
233 if (!empty($documentCompanyBinding))
235 $result->addError(
new Error(
'This document already has a Company contractor'));
244 $result = $this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_VIEW);
245 if (!$result->isSuccess())
251 $this->accessController->check(Controller::CATALOG_STORE)
252 && $this->accessController->check(Controller::CATALOG_READ);
254 if (!$canReadDocument)
256 $result->addError(
new Error(
'Access denied'));
265 if (!$result->isSuccess())
270 return $this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_MODIFY);
284 private function checkDocumentAccess(
string $action):
Result
290 $result->addError(
new Error(
'Access denied'));
303 return new StoreDocumentContractorTable;
static getRow(array $parameters)