1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
documentcontractor.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Controller;
4
5use Bitrix\Catalog\Access\ActionDictionary;
6use Bitrix\Catalog\StoreDocumentTable;
7use Bitrix\Catalog\v2\Contractor\Provider\Manager;
8use Bitrix\Crm\Integration\Catalog\Contractor\StoreDocumentContractorTable;
9use Bitrix\Main\Engine\Action;
10use Bitrix\Main\Engine\Response\DataType\Page;
11use Bitrix\Main\Error;
12use Bitrix\Main\Result;
13use Bitrix\Main\UI\PageNavigation;
14
16{
20 protected function processBeforeAction(Action $action): ?bool
21 {
22 $result = parent::processBeforeAction($action);
23
24 if (
25 empty($this->getErrors())
26 && !Manager::isActiveProviderByModule(Manager::PROVIDER_STORE_DOCUMENT, 'crm')
27 )
28 {
29 $this->addError(new Error('Contractors should be provided by CRM'));
30
31 return null;
32 }
33
34 return $result;
35 }
36
37 // region Actions
38
48 public function getFieldsAction(): array
49 {
50 return [
51 'DOCUMENT_CONTRACTOR' => $this->getViewFields(),
52 ];
53 }
54
62 public function addAction(array $fields): ?array
63 {
64 $canModify = $this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_MODIFY);
65 if (!$canModify->isSuccess())
66 {
67 return null;
68 }
69
70 $checkFieldsResult = $this->checkFields($fields);
71 if (!$checkFieldsResult->isSuccess())
72 {
73 $this->addErrors($checkFieldsResult->getErrors());
74
75 return null;
76 }
77
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'],
82 ]);
83
84 if (!$addResult->isSuccess())
85 {
86 $this->addErrors($checkFieldsResult->getErrors());
87
88 return null;
89 }
90
91 return [
92 'DOCUMENT_CONTRACTOR' => $this->get($addResult->getId()),
93 ];
94 }
95
102 public function deleteAction(int $id): ?bool
103 {
104 $existsResult = $this->exists($id);
105 if (!$existsResult->isSuccess())
106 {
107 $this->addError(new Error('Binding was not found'));
108
109 return null;
110 }
111
112 $canModify = $this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_MODIFY);
113 if (!$canModify->isSuccess())
114 {
115 return null;
116 }
117
118 $deleteResult = StoreDocumentContractorTable::delete($id);
119 if (!$deleteResult)
120 {
121 $this->addErrors($deleteResult->getErrors());
122
123 return null;
124 }
125
126 return true;
127 }
128
137 public function listAction(
138 PageNavigation $pageNavigation,
139 array $select = [],
140 array $filter = [],
141 array $order = [],
142 bool $__calculateTotalCount = true
143 ): Page
144 {
145 return new Page(
146 'DOCUMENT_CONTRACTOR',
147 $this->getList($select, $filter, $order, $pageNavigation),
148 $__calculateTotalCount ? $this->count($filter) : 0
149 );
150 }
151
152 // end region Actions
153
160 private function checkFields(array $fields): Result
161 {
162 $result = new Result();
163 $documentId = (int)$fields['DOCUMENT_ID'];
164 $entityTypeId = (int)$fields['ENTITY_TYPE_ID'];
165 $entityId = (int)$fields['ENTITY_ID'];
166
167 if (!$documentId)
168 {
169 $result->addError(new Error('Store document was not found'));
170
171 return $result;
172 }
173
174 $document = StoreDocumentTable::getRow([
175 'select' => [
176 'ID',
177 'DOC_TYPE',
178 'STATUS',
179 ],
180 'filter' => [
181 'ID' => $documentId,
182 ],
183 ]);
184
185 if (!$document)
186 {
187 $result->addError(new Error('Store document was not found'));
188
189 return $result;
190 }
191
192 if ($document['DOC_TYPE'] !== StoreDocumentTable::TYPE_ARRIVAL)
193 {
194 $result->addError(new Error('Type of store document is wrong'));
195 }
196
197 if ($document['STATUS'] === 'Y')
198 {
199 $result->addError(new Error('Unable to edit conducted document'));
200 }
201
202 if (
203 $entityTypeId !== \CCrmOwnerType::Contact
204 && $entityTypeId !== \CCrmOwnerType::Company
205 )
206 {
207 $result->addError(new Error('Wrong entity type id'));
208 }
209
210 if (!$entityId)
211 {
212 $result->addError(new Error('Wrong entity id'));
213 }
214
215 $bindingExists = $this->existsByFilter([
216 'DOCUMENT_ID' => $documentId,
217 'ENTITY_TYPE_ID' => $entityTypeId,
218 'ENTITY_ID' => $entityId,
219 ]);
220 if ($bindingExists->isSuccess())
221 {
222 $result->addError(new Error('This contractor has been already bound to this document'));
223 }
224
225 if ($entityTypeId === \CCrmOwnerType::Company)
226 {
227 $documentCompanyBinding = StoreDocumentContractorTable::getRow([
228 'select' => ['ID'],
229 'filter' => [
230 'DOCUMENT_ID' => $documentId,
231 'ENTITY_TYPE_ID' => \CCrmOwnerType::Company,
232 ],
233 ]);
234
235 if (!empty($documentCompanyBinding))
236 {
237 $result->addError(new Error('This document already has a Company contractor'));
238 }
239 }
240
241 return $result;
242 }
243
244 protected function checkReadPermissionEntity(): Result
245 {
246 $result = $this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_VIEW);
247 if (!$result->isSuccess())
248 {
249 return $result;
250 }
251
252 $canReadDocument =
253 $this->accessController->check(Controller::CATALOG_STORE)
254 && $this->accessController->check(Controller::CATALOG_READ);
255
256 if (!$canReadDocument)
257 {
258 $result->addError(new Error('Access denied'));
259 }
260
261 return $result;
262 }
263
265 {
267 if (!$result->isSuccess())
268 {
269 return $result;
270 }
271
272 return $this->checkDocumentAccess(ActionDictionary::ACTION_STORE_DOCUMENT_MODIFY);
273 }
274
275 protected function checkPermissionEntity($name, $arguments = []): Result
276 {
277 return new Result();
278 }
279
286 private function checkDocumentAccess(string $action): Result
287 {
288 $result = new Result();
289 $can = $this->accessController->checkByValue($action, StoreDocumentTable::TYPE_ARRIVAL);
290 if (!$can)
291 {
292 $result->addError(new Error('Access denied'));
293
294 return $result;
295 }
296
297 return $result;
298 }
299
303 public function getEntityTable(): StoreDocumentContractorTable
304 {
305 return new StoreDocumentContractorTable;
306 }
307}
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[], bool $__calculateTotalCount=true)
Определения documentcontractor.php:137
checkPermissionEntity($name, $arguments=[])
Определения documentcontractor.php:275
Определения error.php:15
static getRow(array $parameters)
Определения datamanager.php:398
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$select
Определения iblock_catalog_list.php:194
$filter
Определения iblock_catalog_list.php:54
$name
Определения menu_edit.php:35
exists($id)
Определения checkexists.php:30
getList(array $select, array $filter, array $order, PageNavigation $pageNavigation=null)
Определения aliases.php:54
getErrors()
Определения errorableimplementation.php:34
trait Error
Определения error.php:11
$order
Определения payment.php:8
$entityId
Определения payment.php:4
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$action
Определения file_dialog.php:21
$fields
Определения yandex_run.php:501