41 if (!Feature::isInventoryManagementEnabled())
43 $this->addError(
new Error(Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
48 if (!State::isUsedInventoryManagement())
50 $this->addError(
new Error(Loc::getMessage(
'DOCUMENT_CONTROLLER_MANAGEMENT_NOT_ENABLED')));
57 $documentData = $this->getDocumentData($documentIds);
59 $userId = CurrentUser::get()->getId();
60 foreach ($documentIds as $documentId)
62 $document = $documentData[$documentId] ??
null;
66 new Error(Loc::getMessage(
67 'CATALOG_CONTROLLER_DOCUMENT_CONDUCT_GENERAL_ERROR',
69 '#ERROR#' => Loc::getMessage(
'CATALOG_CONTROLLER_DOCUMENT_NOT_FOUND'),
78 $can = $this->accessController->check(
79 ActionDictionary::ACTION_STORE_DOCUMENT_CONDUCT,
80 StoreDocument::createFromArray($document)
85 new Error(Loc::getMessage(
'CATALOG_CONTROLLER_DOCUMENT_CONDUCT_ERROR',
88 '#ERROR#' => Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_RIGHTS_ERROR'),
95 $isConducted = \CCatalogDocs::conductDocument($documentId,
$userId);
101 new Error(Loc::getMessage(
102 'DOCUMENT_CONTROLLER_CONDUCT_ERROR',
114 new Error(Loc::getMessage(
'CATALOG_CONTROLLER_DOCUMENT_CONDUCT_GENERAL_ERROR',
124 if (!$this->errorCollection->isEmpty())
139 if (!Feature::isInventoryManagementEnabled())
141 $this->addError(
new Error(Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
146 if (!State::isUsedInventoryManagement())
148 $this->addError(
new Error(Loc::getMessage(
'DOCUMENT_CONTROLLER_MANAGEMENT_NOT_ENABLED')));
155 $documentData = $this->getDocumentData($documentIds);
156 $userId = CurrentUser::get()->getId();
157 foreach ($documentIds as $documentId)
159 $document = $documentData[$documentId] ??
null;
163 new Error(Loc::getMessage(
164 'CATALOG_CONTROLLER_DOCUMENT_CANCEL_ERROR',
166 '#ERROR#' => Loc::getMessage(
'CATALOG_CONTROLLER_DOCUMENT_NOT_FOUND'),
175 $can = $this->accessController->check(
176 ActionDictionary::ACTION_STORE_DOCUMENT_CONDUCT,
177 StoreDocument::createFromArray($document)
182 new Error(Loc::getMessage(
'DOCUMENT_CONTROLLER_CANCEL_ERROR',
185 '#ERROR#' => Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_RIGHTS_ERROR'),
192 $isCancelled = \CCatalogDocs::cancellationDocument($documentId,
$userId);
198 new Error(Loc::getMessage(
199 'DOCUMENT_CONTROLLER_CANCEL_ERROR',
212 new Error(Loc::getMessage(
213 'CATALOG_CONTROLLER_DOCUMENT_CANCEL_ERROR',
223 if (!$this->errorCollection->isEmpty())
231 private function prepareFieldsAdd(
$fields)
233 if (!array_key_exists(
'SITE_ID',
$fields))
235 if (defined(
'SITE_ID'))
245 if (!CurrentUser::get()->isAdmin() || !array_key_exists(
'CREATED_BY',
$fields))
247 $fields[
'CREATED_BY'] = CurrentUser::get()->getId();
250 if (!CurrentUser::get()->
isAdmin() || !array_key_exists(
'MODIFIED_BY', $fields))
252 $fields[
'MODIFIED_BY'] = CurrentUser::get()->getId();
266 if (!Feature::isInventoryManagementEnabled())
268 $this->addError(
new Error(Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
273 $docType =
$fields[
'DOC_TYPE'] ??
null;
278 $this->addError(
new Error(
'DOC_TYPE isn\'t available'));
283 if (!$this->accessController->check(ActionDictionary::ACTION_STORE_DOCUMENT_MODIFY, StoreDocument::createFromArray(
$fields)))
286 new Error(Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_RIGHTS_ERROR'))
293 $addResult = CCatalogDocs::add(
$fields);
300 $this->addError(
new Error($exception->GetString()));
331 if (!Feature::isInventoryManagementEnabled())
333 $this->addError(
new Error(Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
338 if (!$this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_MODIFY, $id))
343 $user = CurrentUser::get();
344 if (!array_key_exists(
'MODIFIED_BY',
$fields) || !
$user->isAdmin())
356 $this->addError(
new Error($exception->GetString()));
371 public function deleteListAction(
array $documentIds): ?bool
375 if (!Feature::isInventoryManagementEnabled())
377 $this->addError(
new Error(Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
386 $documentData = $this->getDocumentData($documentIds);
388 $storeList = $this->getDocumentStoreList($documentIds);
390 foreach ($documentIds as $documentId)
393 $document = $documentData[(int)$documentId] ??
null;
398 new Error(Loc::getMessage(
399 'DOCUMENT_CONTROLLER_DELETE_ERROR',
401 '#DOC_TITLE#' =>
"#{$documentId}",
402 '#ERROR#' => Loc::getMessage(
'CATALOG_CONTROLLER_DOCUMENT_NOT_FOUND'),
409 $can = $this->accessController->check(
410 ActionDictionary::ACTION_STORE_DOCUMENT_DELETE,
411 StoreDocument::createFromArray($document)
414 if ($storeList[$documentId])
416 $can = $can && $this->checkAllStoreAccess($storeList[$documentId]);
421 \CCatalogDocs::delete($documentId);
430 new Error(Loc::getMessage(
431 'DOCUMENT_CONTROLLER_NO_RIGHTS_TO_DELETE_ERROR',
444 if ($exception->GetID() === CCatalogDocs::DELETE_CONDUCTED_ERROR)
447 new Error(Loc::getMessage(
448 'DOCUMENT_CONTROLLER_DELETE_CONDUCTED_ERROR',
458 new Error(Loc::getMessage(
459 'DOCUMENT_CONTROLLER_DELETE_ERROR',
472 return $this->errorCollection->isEmpty() ?
true :
null;
483 if (!Feature::isInventoryManagementEnabled())
485 $this->addError(
new Error(Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
490 if (!$this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_DELETE, $id))
495 $storeList = $this->getDocumentStoreList([$id]);
497 if (isset($storeList[$id]) && !$this->checkAllStoreAccess($storeList[$id]))
502 $deleteResult = CCatalogDocs::delete($id);
505 $message = Loc::getMessage(
'CATALOG_CONTROLLER_DOCUMENT_NOT_FOUND');
517 if ($exception->getID() === CCatalogDocs::DELETE_CONDUCTED_ERROR)
520 'DOCUMENT_CONTROLLER_DELETE_CONDUCTED_ERROR',
522 '#DOC_TITLE#' => $id,
529 'DOCUMENT_CONTROLLER_DELETE_ERROR',
531 '#DOC_TITLE#' => $id,
546 return $deleteResult;
577 if (!Feature::isInventoryManagementEnabled())
579 $this->addError(
new Error(Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
584 if (!$this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_CONDUCT, $id))
592 $message = Loc::getMessage(
'CATALOG_CONTROLLER_DOCUMENT_NOT_FOUND');
600 $userId = CurrentUser::get()->getId();
602 if (!CCatalogDocs::conductDocument($id,
$userId))
615 'CATALOG_CONTROLLER_DOCUMENT_CONDUCT_ERROR',
650 if (!Feature::isInventoryManagementEnabled())
652 $this->addError(
new Error(Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
657 if (!$this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_CONDUCT, $id))
662 $userId = CurrentUser::get()->getId();
663 if (!CCatalogDocs::cancellationDocument($id,
$userId))
675 'CATALOG_CONTROLLER_DOCUMENT_CANCEL_ERROR',
708 if (
$name ===
'fields')
710 return $this->checkGetFieldsPermissionEntity();
713 if (in_array(
$name, [
'conductlist',
'cancellist',
'unconfirm',
'confirm',
'conduct',
'cancel'],
true))
715 return $this->checkUpdatePermissionEntity();
718 if (
$name ===
'deletelist')
720 return $this->checkDeletePermissionEntity();
723 return parent::checkPermissionEntity(
$name, $arguments);
731 return new \Bitrix\Catalog\StoreDocumentTable();
739 if (!$this->accessController->check(Controller::CATALOG_STORE))
741 $message = Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_STORE_RIGHTS_ERROR');
754 !$this->accessController->check(Controller::CATALOG_STORE)
755 && !$this->accessController->check(Controller::CATALOG_READ)
758 $message = Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_RIGHTS_ERROR');
765 private function getDocumentData(
array $documentIds):
array
768 $documentTitles = [];
769 while ($document = $documentTitlesRes->fetch())
771 $documentTitles[$document[
'ID']] = [
772 'ID' => $document[
'ID'],
773 'TITLE' => $document[
'TITLE'],
774 'DOC_TYPE' => $document[
'DOC_TYPE'],
778 return $documentTitles;
781 private function getDocumentStoreList(
array $documentIds):
array
790 '@DOC_ID' => $documentIds,
796 while ($document = $documentRawList->fetch())
798 $documentId = (int)$document[
'DOC_ID'];
799 $storeList[$documentId] ??= [];
801 $storeFrom = (int)$document[
'STORE_FROM'];
802 $storeTo = (int)$document[
'STORE_TO'];
804 if ($document[
'STORE_FROM'] > 0)
806 $storeList[$documentId][$storeFrom] = $storeFrom;
808 if ($document[
'STORE_TO'] > 0)
810 $storeList[$documentId][$storeTo] = $storeTo;
817 private function checkAllStoreAccess(
array $documentIds): bool
823 if (!$this->accessController->checkByValue(ActionDictionary::ACTION_STORE_VIEW,
$storeId))
844 private function checkDocumentAccess(
string $action,
int $documentId): bool
846 $can = $this->accessController->check(
$action, StoreDocument::createFromId($documentId));
850 new Error(Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_RIGHTS_ERROR'))
870 '=DOC_TYPE' => array_keys(self::getAvailableRestDocumentTypes()),
874 $accessFilter = $this->accessController->getEntityFilter(
875 ActionDictionary::ACTION_STORE_DOCUMENT_VIEW,
static getList(array $parameters=array())