37 if (!Feature::isInventoryManagementEnabled())
39 $this->addError(
new Error(
Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
53 $documentData = $this->getDocumentData($documentIds);
55 $userId = CurrentUser::get()->getId();
56 foreach ($documentIds as $documentId)
58 $document = $documentData[$documentId] ??
null;
63 'CATALOG_CONTROLLER_DOCUMENT_CONDUCT_GENERAL_ERROR',
74 $can = $this->accessController->check(
75 ActionDictionary::ACTION_STORE_DOCUMENT_CONDUCT,
76 StoreDocument::createFromArray($document)
83 '#DOC_TITLE#' => htmlspecialcharsbx($documentTitle),
91 $isConducted = \CCatalogDocs::conductDocument($documentId, $userId);
94 if ($APPLICATION->GetException())
98 'DOCUMENT_CONTROLLER_CONDUCT_ERROR',
100 '#DOC_TITLE#' => htmlspecialcharsbx($documentTitle),
101 '#ERROR#' => htmlspecialcharsbx($APPLICATION->GetException()->GetString()),
105 $APPLICATION->ResetException();
112 '#DOC_TITLE#' => htmlspecialcharsbx($documentTitle),
120 if (!$this->errorCollection->isEmpty())
135 if (!Feature::isInventoryManagementEnabled())
137 $this->addError(
new Error(
Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
151 $documentData = $this->getDocumentData($documentIds);
152 $userId = CurrentUser::get()->getId();
153 foreach ($documentIds as $documentId)
155 $document = $documentData[$documentId] ??
null;
160 'CATALOG_CONTROLLER_DOCUMENT_CANCEL_ERROR',
171 $can = $this->accessController->check(
172 ActionDictionary::ACTION_STORE_DOCUMENT_CONDUCT,
173 StoreDocument::createFromArray($document)
180 '#DOC_TITLE#' => htmlspecialcharsbx($documentTitle),
188 $isCancelled = \CCatalogDocs::cancellationDocument($documentId, $userId);
191 if ($APPLICATION->GetException())
195 'DOCUMENT_CONTROLLER_CANCEL_ERROR',
197 '#DOC_TITLE#' => htmlspecialcharsbx($documentTitle),
198 '#ERROR#' => htmlspecialcharsbx($APPLICATION->GetException()->GetString()),
202 $APPLICATION->ResetException();
209 'CATALOG_CONTROLLER_DOCUMENT_CANCEL_ERROR',
211 '#ERROR#' => htmlspecialcharsbx($documentTitle),
219 if (!$this->errorCollection->isEmpty())
227 private function prepareFieldsAdd($fields)
229 if (!array_key_exists(
'SITE_ID', $fields))
231 if (defined(
'SITE_ID'))
233 $fields[
'SITE_ID'] = SITE_ID;
237 $fields[
'SITE_ID'] =
's1';
241 if (!CurrentUser::get()->isAdmin() || !array_key_exists(
'CREATED_BY', $fields))
243 $fields[
'CREATED_BY'] = CurrentUser::get()->getId();
246 if (!CurrentUser::get()->isAdmin() || !array_key_exists(
'MODIFIED_BY', $fields))
248 $fields[
'MODIFIED_BY'] = CurrentUser::get()->getId();
262 if (!Feature::isInventoryManagementEnabled())
264 $this->addError(
new Error(
Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
269 $docType = $fields[
'DOC_TYPE'] ??
null;
271 $availableTypes = self::getAvailableRestDocumentTypes();
272 if (!isset($availableTypes[$docType]))
274 $this->addError(
new Error(
'DOC_TYPE isn\'t available'));
279 if (!$this->accessController->check(ActionDictionary::ACTION_STORE_DOCUMENT_MODIFY, StoreDocument::createFromArray($fields)))
288 $fields = $this->prepareFieldsAdd($fields);
289 $addResult = CCatalogDocs::add($fields);
293 if ($APPLICATION->GetException())
295 $exception = $APPLICATION->GetException();
296 $this->addError(
new Error($exception->GetString()));
297 $APPLICATION->ResetException();
303 return [
'DOCUMENT' => $this->
get($addResult)];
327 if (!Feature::isInventoryManagementEnabled())
329 $this->addError(
new Error(
Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
334 if (!$this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_MODIFY, $id))
339 $user = CurrentUser::get();
340 if (!array_key_exists(
'MODIFIED_BY', $fields) || !$user->isAdmin())
342 $fields[
'MODIFIED_BY'] = $user->getId();
345 $result = CCatalogDocs::update($id, $fields);
349 if ($APPLICATION->GetException())
351 $exception = $APPLICATION->GetException();
352 $this->addError(
new Error($exception->GetString()));
353 $APPLICATION->ResetException();
359 return [
'DOCUMENT' => $this->
get($id)];
367 public function deleteListAction(array $documentIds): ?bool
371 if (!Feature::isInventoryManagementEnabled())
373 $this->addError(
new Error(
Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
382 $documentData = $this->getDocumentData($documentIds);
384 foreach ($documentIds as $documentId)
387 $document = $documentData[(int)$documentId] ??
null;
393 'DOCUMENT_CONTROLLER_DELETE_ERROR',
395 '#DOC_TITLE#' =>
"#{$documentId}",
403 $can = $this->accessController->check(
404 ActionDictionary::ACTION_STORE_DOCUMENT_DELETE,
405 StoreDocument::createFromArray($document)
409 \CCatalogDocs::delete($documentId);
411 $exception = $APPLICATION->GetException();
415 $exception =
new CApplicationException(
423 if ($exception->GetID() === CCatalogDocs::DELETE_CONDUCTED_ERROR)
427 'DOCUMENT_CONTROLLER_DELETE_CONDUCTED_ERROR',
429 '#DOC_TITLE#' => htmlspecialcharsbx($documentTitle),
438 'DOCUMENT_CONTROLLER_DELETE_ERROR',
440 '#DOC_TITLE#' => htmlspecialcharsbx($documentTitle),
441 '#ERROR#' => htmlspecialcharsbx($exception->GetString()),
447 $APPLICATION->ResetException();
451 return $this->errorCollection->isEmpty() ? true :
null;
462 if (!Feature::isInventoryManagementEnabled())
464 $this->addError(
new Error(
Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
469 if (!$this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_DELETE, $id))
474 $deleteResult = CCatalogDocs::delete($id);
487 if ($exception = $APPLICATION->getException())
489 if ($exception->getID() === CCatalogDocs::DELETE_CONDUCTED_ERROR)
492 'DOCUMENT_CONTROLLER_DELETE_CONDUCTED_ERROR',
494 '#DOC_TITLE#' => $id,
501 'DOCUMENT_CONTROLLER_DELETE_ERROR',
503 '#DOC_TITLE#' => $id,
504 '#ERROR#' => htmlspecialcharsbx($exception->getString()),
513 $APPLICATION->ResetException();
518 return $deleteResult;
540 '=DOC_TYPE' => array_keys(self::getAvailableRestDocumentTypes()),
544 $accessFilter = $this->accessController->getEntityFilter(
545 ActionDictionary::ACTION_STORE_DOCUMENT_VIEW,
557 return new Page(
'DOCUMENTS',
558 $this->getList($select, $filter, $order, $pageNavigation),
559 $this->count($filter)
586 if (!Feature::isInventoryManagementEnabled())
588 $this->addError(
new Error(
Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
593 if (!$this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_CONDUCT, $id))
609 $userId = CurrentUser::get()->getId();
611 if (!CCatalogDocs::conductDocument($id, $userId))
617 if ($APPLICATION->GetException())
619 $error = $APPLICATION->GetException()->GetString();
620 $APPLICATION->ResetException();
624 'CATALOG_CONTROLLER_DOCUMENT_CONDUCT_ERROR',
630 $this->addError(
new Error($message));
659 if (!Feature::isInventoryManagementEnabled())
661 $this->addError(
new Error(
Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_INVENTORY_MANAGEMENT_ENABLED_ERROR')));
666 if (!$this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_CONDUCT, $id))
671 $userId = CurrentUser::get()->getId();
672 if (!CCatalogDocs::cancellationDocument($id, $userId))
677 if ($APPLICATION->GetException())
679 $error = $APPLICATION->GetException()->GetString();
680 $APPLICATION->ResetException();
684 'CATALOG_CONTROLLER_DOCUMENT_CANCEL_ERROR',
689 $this->addError(
new Error($message));
716 $name = mb_strtolower($name);
717 if ($name ===
'fields')
719 return $this->checkGetFieldsPermissionEntity();
722 if (in_array($name, [
'conductlist',
'cancellist',
'unconfirm',
'confirm',
'conduct',
'cancel'],
true))
724 return $this->checkUpdatePermissionEntity();
727 if ($name ===
'deletelist')
729 return $this->checkDeletePermissionEntity();
732 return parent::checkPermissionEntity($name, $arguments);
740 return new \Bitrix\Catalog\StoreDocumentTable();
748 if (!$this->accessController->check(Controller::CATALOG_STORE))
750 $message =
Loc::getMessage(
'DOCUMENT_CONTROLLER_NO_STORE_RIGHTS_ERROR');
751 $r->addError(
new Error($message));
763 !$this->accessController->check(Controller::CATALOG_STORE)
764 && !$this->accessController->check(Controller::CATALOG_READ)
768 $r->addError(
new Error($message));
774 private function getDocumentData(array $documentIds): array
777 $documentTitles = [];
778 while ($document = $documentTitlesRes->fetch())
780 $documentTitles[$document[
'ID']] = [
781 'ID' => $document[
'ID'],
782 'TITLE' => $document[
'TITLE'],
783 'DOC_TYPE' => $document[
'DOC_TYPE'],
787 return $documentTitles;
800 private function checkDocumentAccess(
string $action,
int $documentId): bool
802 $can = $this->accessController->check($action, StoreDocument::createFromId($documentId));
static getMessage($code, $replace=null, $language=null)
static getList(array $parameters=array())