1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
storedocumenttable.php
См. документацию.
1<?php
2namespace Bitrix\Catalog;
3
4use Bitrix\Main\Entity\ReferenceField;
5use Bitrix\Main\Localization\Loc;
6use Bitrix\Main;
7use Bitrix\Main\ORM\Data\DataManager;
8use Bitrix\Main\ORM\Fields\BooleanField;
9use Bitrix\Main\ORM\Fields\DatetimeField;
10use Bitrix\Main\ORM\Fields\EnumField;
11use Bitrix\Main\ORM\Fields\FloatField;
12use Bitrix\Main\ORM\Fields\IntegerField;
13use Bitrix\Main\ORM\Fields\StringField;
14use Bitrix\Main\ORM\Fields\Validators\LengthValidator;
15use Bitrix\Main\ORM\Query\Join;
16use Bitrix\Main\UserTable;
17
62
64{
65 public const TYPE_ARRIVAL = 'A';
66 public const TYPE_STORE_ADJUSTMENT = 'S';
67 public const TYPE_MOVING = 'M';
68 public const TYPE_RETURN = 'R';
69 public const TYPE_DEDUCT = 'D';
70 public const TYPE_UNDO_RESERVE = 'U';
71 public const TYPE_SALES_ORDERS = 'W';
72 //public const TYPE_INVENTORY = 'I';
73
74 public const STATUS_CONDUCTED = 'Y';
75 public const STATUS_DRAFT = 'N';
76 public const STATUS_CANCELLED = 'C';
77
83 public static function getTableName()
84 {
85 return 'b_catalog_store_docs';
86 }
87
93 public static function getMap()
94 {
95 return [
96 'ID' => new IntegerField(
97 'ID',
98 [
99 'primary' => true,
100 'autocomplete' => true,
101 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_ID_FIELD'),
102 ]
103 ),
104 'TITLE' => new StringField(
105 'TITLE',
106 [
107 'validation' => [__CLASS__, 'validateTitle'],
108 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_TITLE_FIELD')
109 ]
110 ),
111 'DOC_TYPE' => new EnumField(
112 'DOC_TYPE',
113 [
114 'required' => true,
115 'values' => static::getTypeList(),
116 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_DOC_TYPE_FIELD'),
117 ]
118 ),
119 'DOC_NUMBER' => new StringField(
120 'DOC_NUMBER',
121 [
122 'validation' => [__CLASS__, 'validateDocNumber'],
123 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_DOC_NUMBER_FIELD'),
124 ]
125 ),
126 'SITE_ID' => new StringField(
127 'SITE_ID',
128 [
129 'validation' => [__CLASS__, 'validateSiteId'],
130 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_SITE_ID_FIELD'),
131 ]
132 ),
133 'CONTRACTOR' => new Main\ORM\Fields\Relations\Reference(
134 'CONTRACTOR',
135 ContractorTable::class,
136 Main\ORM\Query\Join::on('this.CONTRACTOR_ID', 'ref.ID')
137 ),
138 'CONTRACTOR_ID' => new IntegerField(
139 'CONTRACTOR_ID',
140 [
141 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_CONTRACTOR_ID_FIELD'),
142 ]
143 ),
144 'DATE_MODIFY' => new DatetimeField(
145 'DATE_MODIFY',
146 [
147 'default_value' => function()
148 {
149 return new Main\Type\DateTime();
150 },
151 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_DATE_MODIFY_FIELD'),
152 ]
153 ),
154 'DATE_CREATE' => new DatetimeField(
155 'DATE_CREATE',
156 [
157 'default_value' => function()
158 {
159 return new Main\Type\DateTime();
160 },
161 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_DATE_CREATE_FIELD'),
162 ]
163 ),
164 'CREATED_BY' => new IntegerField(
165 'CREATED_BY',
166 [
167 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_CREATED_BY_FIELD'),
168 ]
169 ),
170 'CREATED_BY_USER' => new Main\ORM\Fields\Relations\Reference(
171 'CREATED_BY_USER',
172 UserTable::class,
173 Main\ORM\Query\Join::on('this.CREATED_BY', 'ref.ID')
174 ),
175 'MODIFIED_BY' => new IntegerField(
176 'MODIFIED_BY',
177 [
178 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_MODIFIED_BY_FIELD'),
179 ]
180 ),
181 'MODIFIED_BY_USER' => new Main\ORM\Fields\Relations\Reference(
182 'MODIFIED_BY_USER',
183 UserTable::class,
184 Main\ORM\Query\Join::on('this.MODIFIED_BY', 'ref.ID')
185 ),
186 'RESPONSIBLE_ID' => new IntegerField(
187 'RESPONSIBLE_ID',
188 [
189 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_RESPONSIBLE_ID_FIELD')
190 ]
191 ),
192 'RESPONSIBLE' => new Main\ORM\Fields\Relations\Reference(
193 'RESPONSIBLE',
194 UserTable::class,
195 Main\ORM\Query\Join::on('this.RESPONSIBLE_ID', 'ref.ID')
196 ),
197 'CURRENCY' => new StringField(
198 'CURRENCY',
199 [
200 'validation' => [__CLASS__, 'validateCurrency'],
201 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_CURRENCY_FIELD'),
202 ]
203 ),
204 'STATUS' => new BooleanField(
205 'STATUS',
206 [
207 'values' => ['N', 'Y'],
208 'default' => 'N',
209 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_STATUS_FIELD'),
210 ]
211 ),
212 'WAS_CANCELLED' => new BooleanField(
213 'WAS_CANCELLED',
214 [
215 'values' => array('N', 'Y'),
216 'default' => 'N',
217 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_WAS_CANCELLED_FIELD'),
218 ]
219 ),
220 'DATE_STATUS' => new DatetimeField(
221 'DATE_STATUS',
222 [
223 'default_value' => null,
224 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_DATE_STATUS_FIELD'),
225 ]
226 ),
227 'DATE_DOCUMENT' => new DatetimeField(
228 'DATE_DOCUMENT',
229 [
230 'default_value' => function()
231 {
232 return new Main\Type\DateTime();
233 },
234 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_DATE_DOCUMENT_FIELD'),
235 ]
236 ),
237 'STATUS_BY' => new IntegerField(
238 'STATUS_BY',
239 [
240 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_STATUS_BY_FIELD'),
241 ]
242 ),
243 'STATUS_BY_USER' => new Main\ORM\Fields\Relations\Reference(
244 'STATUS_BY_USER',
245 UserTable::class,
246 Main\ORM\Query\Join::on('this.STATUS_BY', 'ref.ID')
247 ),
248 'TOTAL' => new FloatField(
249 'TOTAL',
250 [
251 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_TOTAL_FIELD'),
252 ]
253 ),
254 'COMMENTARY' => new StringField(
255 'COMMENTARY',
256 [
257 'validation' => [__CLASS__, 'validateCommentary'],
258 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_COMMENTARY_FIELD'),
259 ]
260 ),
261 'ITEMS_ORDER_DATE' => new DatetimeField(
262 'ITEMS_ORDER_DATE',
263 [
264 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_ITEMS_ORDER_DATE_FIELD')
265 ]
266 ),
267 'ITEMS_RECEIVED_DATE' => new DatetimeField(
268 'ITEMS_RECEIVED_DATE',
269 [
270 'title' => Loc::getMessage('INVENTORY_DOCUMENT_ENTITY_ITEMS_RECEIVED_DATE_FIELD')
271 ]
272 ),
273 'ELEMENTS' => (new Main\ORM\Fields\Relations\OneToMany(
274 'ELEMENTS',
275 StoreDocumentElementTable::class,
276 'DOCUMENT'
277 ))->configureJoinType('left'),
278 ];
279 }
280
286 public static function validateDocNumber(): array
287 {
288 return [
289 new LengthValidator(null, 64),
290 ];
291 }
292
298 public static function validateTitle()
299 {
300 return [
301 new LengthValidator(null, 255),
302 ];
303 }
304
310 public static function validateSiteId(): array
311 {
312 return [
313 new LengthValidator(null, 2),
314 ];
315 }
316
322 public static function validateCurrency(): array
323 {
324 return [
325 new LengthValidator(3, 3),
326 ];
327 }
328
334 public static function validateCommentary(): array
335 {
336 return [
337 new LengthValidator(null, 1000),
338 ];
339 }
340
341 public static function getTypeList(bool $description = false): array
342 {
343 if ($description)
344 {
345 return [
346 self::TYPE_ARRIVAL => Loc::getMessage('INVENTORY_DOCUMENT_TYPE_ARRIVAL'),
347 self::TYPE_STORE_ADJUSTMENT => Loc::getMessage('INVENTORY_DOCUMENT_TYPE_STORE_ADJUSTMENT'),
348 self::TYPE_MOVING => Loc::getMessage('INVENTORY_DOCUMENT_TYPE_MOVING'),
349 self::TYPE_RETURN => Loc::getMessage('INVENTORY_DOCUMENT_TYPE_RETURN'),
350 self::TYPE_DEDUCT => Loc::getMessage('INVENTORY_DOCUMENT_TYPE_DEDUCT'),
351 self::TYPE_UNDO_RESERVE => Loc::getMessage('INVENTORY_DOCUMENT_TYPE_UNDO_RESERVE'),
352 ];
353 }
354 else
355 {
356 return [
357 self::TYPE_ARRIVAL,
358 self::TYPE_STORE_ADJUSTMENT,
359 self::TYPE_MOVING,
360 self::TYPE_RETURN,
361 self::TYPE_DEDUCT,
362 self::TYPE_UNDO_RESERVE,
363 ];
364 }
365 }
366
367 public static function getStatusList(): array
368 {
369 return [
370 self::STATUS_CONDUCTED => Loc::getMessage('INVENTORY_DOCUMENT_STATUS_CONDUCTED'),
371 self::STATUS_DRAFT => Loc::getMessage('INVENTORY_DOCUMENT_STATUS_DRAFT'),
372 self::STATUS_CANCELLED => Loc::getMessage('INVENTORY_DOCUMENT_STATUS_CANCELLED'),
373 ];
374 }
375
376 public static function getStatusName(string $status): ?string
377 {
378 $statusList = static::getStatusList();
379
380 return $statusList[$status] ?? null;
381 }
382
383 public static function getOrmFilterByStatus(string $status): ?array
384 {
385 switch ($status)
386 {
387 case self::STATUS_CONDUCTED:
388 $result = [
389 '=STATUS' => 'Y',
390 ];
391 break;
392 case self::STATUS_DRAFT:
393 $result = [
394 '=STATUS' => 'N',
395 '=WAS_CANCELLED' => 'N',
396 ];
397 break;
398 case self::STATUS_CANCELLED:
399 $result = [
400 '=STATUS' => 'N',
401 '=WAS_CANCELLED' => 'Y',
402 ];
403 break;
404 default:
405 $result = null;
406 break;
407 }
408
409 return $result;
410 }
411
412 /*
413 * The following methods are used to select the documents that include a particular product/set of products.
414 * They are to be used with the \Bitrix\Main\ORM\Query\Query object (i.e. not with getList).
415 *
416 * Example:
417 * $docs = Catalog\StoreDocumentTable::query()->setSelect(['ID'])->withProduct($productId)->fetchAll();
418 */
419
420 public static function withProduct(Main\ORM\Query\Query $query, $productId)
421 {
422 $productId = (int)$productId;
423 if ($productId <= 0)
424 {
425 return;
426 }
427
428 $query->registerRuntimeField(
429 new ReferenceField(
430 'FILTER_ELEMENT_DOC_ID',
432 Join::on('ref.DOC_ID', 'this.ID')->where('ref.ELEMENT_ID', $productId),
433 ['join_type' => 'INNER']
434 )
435 );
436
437 $query->addGroup('ID');
438 }
439
440 public static function withProductList(Main\ORM\Query\Query $query, array $productIds)
441 {
443 if (empty($productIds))
444 {
445 return;
446 }
447
448 $query->registerRuntimeField(
449 new ReferenceField(
450 'FILTER_ELEMENT_DOC_ID',
452 Join::on('ref.DOC_ID', 'this.ID')->whereIn('ref.ELEMENT_ID', $productIds),
453 ['join_type' => 'INNER']
454 )
455 );
456
457 $query->addGroup('ID');
458 }
459
460 public static function withStore(Main\ORM\Query\Query $query, $storeId)
461 {
462 $storeId = (int)$storeId;
463 if ($storeId <= 0)
464 {
465 return;
466 }
467
469 $filter
470 ->logic('or')
471 ->where('ref.STORE_FROM', $storeId)
472 ->where('ref.STORE_TO', $storeId)
473 ;
474 $query->registerRuntimeField(
475 new ReferenceField(
476 'FILTER_STORE_DOC_ID',
478 Join::on('ref.DOC_ID', 'this.ID')->where($filter),
479 ['join_type' => 'INNER']
480 )
481 );
482
483 $query->addGroup('ID');
484 }
485
486 public static function withStoreList(Main\ORM\Query\Query $query, array $storeIds)
487 {
489 if (empty($storeIds))
490 {
491 return;
492 }
493
495 $filter
496 ->logic('or')
497 ->whereIn('ref.STORE_FROM', $storeIds)
498 ->whereIn('ref.STORE_TO', $storeIds)
499 ;
500 $query->registerRuntimeField(
501 new ReferenceField(
502 'FILTER_STORE_DOC_ID',
504 Join::on('ref.DOC_ID', 'this.ID')->where($filter),
505 ['join_type' => 'INNER']
506 )
507 );
508
509 $query->addGroup('ID');
510 }
511
512 public static function withStoreFromList(Main\ORM\Query\Query $query, array $storeIds)
513 {
514 static::addSingleStoreFilterToQuery($query, 'STORE_FROM', $storeIds);
515 }
516
517 public static function withStoreToList(Main\ORM\Query\Query $query, array $storeIds)
518 {
519 static::addSingleStoreFilterToQuery($query, 'STORE_TO', $storeIds);
520 }
521
522 protected static function addSingleStoreFilterToQuery(Main\ORM\Query\Query $query, string $fieldName, array $storeIds): void
523 {
525 if (empty($storeIds))
526 {
527 return;
528 }
529
531 $filter
532 ->whereIn('ref.' . $fieldName, $storeIds)
533 ;
534 $query->registerRuntimeField(
535 new ReferenceField(
536 'FILTER_' . $fieldName . '_DOC_ID',
538 Join::on('ref.DOC_ID', 'this.ID')->where($filter),
539 ['join_type' => 'INNER']
540 )
541 );
542 $query->addGroup('ID');
543 }
544}
static addSingleStoreFilterToQuery(Main\ORM\Query\Query $query, string $fieldName, array $storeIds)
Определения storedocumenttable.php:522
static getOrmFilterByStatus(string $status)
Определения storedocumenttable.php:383
static withStoreToList(Main\ORM\Query\Query $query, array $storeIds)
Определения storedocumenttable.php:517
static withStoreList(Main\ORM\Query\Query $query, array $storeIds)
Определения storedocumenttable.php:486
static withStoreFromList(Main\ORM\Query\Query $query, array $storeIds)
Определения storedocumenttable.php:512
static withProductList(Main\ORM\Query\Query $query, array $productIds)
Определения storedocumenttable.php:440
static withStore(Main\ORM\Query\Query $query, $storeId)
Определения storedocumenttable.php:460
static withProduct(Main\ORM\Query\Query $query, $productId)
Определения storedocumenttable.php:420
static getStatusName(string $status)
Определения storedocumenttable.php:376
static getTypeList(bool $description=false)
Определения storedocumenttable.php:341
static getEntity()
Определения datamanager.php:65
static normalizeArrayValuesByInt(&$map, $sorted=true)
Определения collection.php:150
</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
$query
Определения get_search.php:11
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
$filter
Определения iblock_catalog_list.php:54
$status
Определения session.php:10
Определения chain.php:3
if( $guestStatuses !=='') if(!is_array($guestStatuses)) $statusList
Определения options.php:2065