Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
order.php
1<?php
9
10use Bitrix\Main;
12
13Loc::loadMessages(__FILE__);
14
31class OrderTable extends Main\Entity\DataManager
32{
38 public static function getTableName()
39 {
40 return 'b_sale_order';
41 }
42
48 public static function getMap()
49 {
50 global $DB, $USER;
51
52 $maxLock = intval(Main\Config\Option::get('sale','MAX_LOCK_TIME', 60));
53
54 $userID = (is_object($USER) ? (int)$USER->getID() : 0);
55
56 $connection = Main\Application::getConnection();
57 $helper = $connection->getSqlHelper();
58
59 return array(
60 new Main\Entity\IntegerField('ID',
61 array(
62 'autocomplete' => true,
63 'primary' => true,
64 )
65 ),
66
67 new Main\Entity\StringField('LID'),
68
69 new Main\Entity\StringField(
70 'ACCOUNT_NUMBER',
71 array(
72 'size' => 100
73 )
74 ),
75
76 new Main\Entity\StringField('TRACKING_NUMBER'),
77
78 new Main\Entity\IntegerField('PAY_SYSTEM_ID'),
79 new Main\Entity\IntegerField('DELIVERY_ID'),
80
81 new Main\Entity\DatetimeField('DATE_INSERT'),
82
83 new Main\Entity\ExpressionField(
84 'DATE_INSERT_SHORT',
85 $DB->datetimeToDateFunction('%s'),
86 array('DATE_INSERT'),
87 array('data_type' => 'datetime')
88 ),
89
90 new Main\Entity\ExpressionField(
91 'DATE_INSERT_FORMAT',
92 static::replaceDateTime(),
93 array('DATE_INSERT'),
94 array('data_type' => 'datetime')
95 ),
96
97 new Main\Entity\DatetimeField('DATE_UPDATE'),
98
99 new Main\Entity\ExpressionField(
100 'DATE_UPDATE_SHORT',
101 $DB->datetimeToDateFunction('%s'),
102 array('DATE_UPDATE'),
103 array('data_type' => 'datetime')
104 ),
105
106 new Main\Entity\ExpressionField(
107 'PRODUCTS_QUANT',
108 '(SELECT SUM(b_sale_basket.QUANTITY)
109 FROM b_sale_basket
110 WHERE b_sale_basket.ORDER_ID = %s)',
111 array('ID')
112 ),
113
114 new Main\Entity\StringField('PERSON_TYPE_ID'),
115
116 new Main\Entity\IntegerField(
117 'USER_ID',
118 array(
119 'required' => true
120 )
121 ),
122
123 new Main\Entity\ReferenceField(
124 'USER',
125 '\Bitrix\Main\User',
126 array('=this.USER_ID' => 'ref.ID'),
127 array('join_type' => 'left')
128 ),
129
130 new Main\Entity\BooleanField(
131 'PAYED',
132 array(
133 'values' => array('N', 'Y'),
134 'default_value' => 'N'
135 )
136 ),
137
138 new Main\Entity\BooleanField(
139 'IS_SYNC_B24',
140 array(
141 'values' => array('N', 'Y'),
142 'default_value' => 'N'
143 )
144 ),
145
146 new Main\Entity\DatetimeField('DATE_PAYED'),
147
148 new Main\Entity\IntegerField('EMP_PAYED_ID'),
149
150 new Main\Entity\BooleanField(
151 'DEDUCTED',
152 array(
153 'values' => array('N','Y'),
154 'default_value' => 'N'
155 )
156 ),
157 new Main\Entity\DatetimeField('DATE_DEDUCTED'),
158
159 new Main\Entity\IntegerField('EMP_DEDUCTED_ID'),
160
161 new Main\Entity\StringField('REASON_UNDO_DEDUCTED'),
162
163 new Main\Entity\StringField('STATUS_ID'),
164
165 new Main\Entity\ReferenceField(
166 'STATUS',
167 'Bitrix\Sale\Internals\StatusLang',
168 array(
169 '=this.STATUS_ID' => 'ref.STATUS_ID',
170 '=ref.LID' => array('?', LANGUAGE_ID)
171 )
172 ),
173
174 new Main\Entity\DatetimeField('DATE_STATUS'),
175
176 new Main\Entity\ExpressionField(
177 'DATE_STATUS_SHORT',
178 $DB->datetimeToDateFunction('%s'),
179 array('DATE_STATUS'),
180 array('data_type' => 'datetime')
181 ),
182
183 new Main\Entity\IntegerField('EMP_STATUS_ID'),
184
185 new Main\Entity\ReferenceField(
186 'EMP_STATUS_BY',
187 'Bitrix\Main\User',
188 array(
189 '=this.EMP_STATUS_ID' => 'ref.ID'
190 )
191 ),
192
193 new Main\Entity\BooleanField(
194 'MARKED',
195 array(
196 'values' => array('N', 'Y'),
197 'default_value' => 'N'
198 )
199 ),
200
201 new Main\Entity\DatetimeField('DATE_MARKED'),
202
203 new Main\Entity\IntegerField('EMP_MARKED_ID'),
204
205 new Main\Entity\ReferenceField(
206 'EMP_MARKED_BY',
207 'Bitrix\Main\User',
208 array(
209 '=this.EMP_MARKED_ID' => 'ref.ID'
210 )
211 ),
212
213
214 new Main\Entity\StringField('REASON_MARKED'),
215
216 new Main\Entity\FloatField(
217 'PRICE_DELIVERY'
218 ),
219 new Main\Entity\BooleanField(
220 'ALLOW_DELIVERY',
221 array(
222 'values' => array('N', 'Y'),
223 'default_value' => 'N'
224 )
225 ),
226 new Main\Entity\DatetimeField('DATE_ALLOW_DELIVERY'),
227
228 new Main\Entity\IntegerField('EMP_ALLOW_DELIVERY_ID'),
229
230 new Main\Entity\BooleanField(
231 'RESERVED',
232 array(
233 'values' => array('N', 'Y'),
234 'default_value' => 'N'
235 )
236 ),
237
238 new Main\Entity\FloatField(
239 'PRICE',
240 array(
241 'default_value' => '0.0000'
242 )
243 ),
244
245 new Main\Entity\StringField(
246 'CURRENCY',
247 array(
248 'required' => true,
249 'size' => 3
250 )
251 ),
252
253 new Main\Entity\FloatField(
254 'DISCOUNT_VALUE',
255 array(
256 'default_value' => '0.0000'
257 )
258 ),
259
260 new Main\Entity\ExpressionField(
261 'DISCOUNT_ALL',
262 "%s + (SELECT SUM(b_sale_basket.DISCOUNT_PRICE)
263 FROM b_sale_basket
264 WHERE b_sale_basket.ORDER_ID = %s)",
265 array('DISCOUNT_VALUE', 'ID')
266 ),
267
268 new Main\Entity\FloatField('TAX_VALUE'),
269
270 new Main\Entity\FloatField('SUM_PAID'),
271
272 new Main\Entity\ExpressionField(
273 'SUM_PAID_FORREP',
274 'CASE WHEN %s = \'Y\' THEN %s ELSE %s END',
275 array('PAYED', 'PRICE', 'SUM_PAID')
276 ),
277
278 new Main\Entity\StringField(
279 'USER_DESCRIPTION',
280 array(
281 'size' => 2000
282 )
283 ),
284
285 new Main\Entity\StringField(
286 'PAY_VOUCHER_NUM',
287 array(
288 'size' => 20,
289 )
290 ),
291
292 new Main\Entity\DateField('PAY_VOUCHER_DATE'),
293
294 new Main\Entity\StringField('ADDITIONAL_INFO'),
295
296 new Main\Entity\StringField('COMMENTS'),
297
298 new Main\Entity\IntegerField('COMPANY_ID'),
299
300 new Main\Entity\IntegerField('CREATED_BY'),
301
302 new Main\Entity\ReferenceField(
303 'CREATED_USER',
304 'Bitrix\Main\User',
305 array(
306 '=this.CREATED_BY' => 'ref.ID'
307 )
308 ),
309
310 new Main\Entity\IntegerField('RESPONSIBLE_ID'),
311
312 new Main\Entity\ReferenceField(
313 'RESPONSIBLE_BY',
314 'Bitrix\Main\User',
315 array(
316 '=this.RESPONSIBLE_ID' => 'ref.ID'
317 )
318 ),
319
320 new Main\Entity\StringField('STAT_GID'),
321
322 new Main\Entity\DateField('DATE_PAY_BEFORE'),
323
324 new Main\Entity\DateField('DATE_BILL'),
325
326 new Main\Entity\BooleanField(
327 'IS_RECURRING',
328 array(
329 'values' => array('N', 'Y'),
330 'default_value' => 'N'
331 )
332 ),
333
334 new Main\Entity\IntegerField('RECURRING_ID'),
335
336 new Main\Entity\IntegerField('LOCKED_BY'),
337
338 new Main\Entity\ReferenceField(
339 'LOCK_USER',
340 'Bitrix\Main\User',
341 array(
342 '=this.LOCKED_BY' => 'ref.ID'
343 )
344 ),
345
346 new Main\Entity\DatetimeField('DATE_LOCK'),
347
348
349
350 new Main\Entity\ExpressionField(
351 'LOCK_USER_NAME',
352 $helper->getConcatFunction("'('", "%s", "') '", "%s", "' '", "%s"),
353 array('LOCK_USER.LOGIN', 'LOCK_USER.NAME', 'LOCK_USER.LAST_NAME')
354 ),
355
356 new Main\Entity\ExpressionField(
357 'LOCK_STATUS',
358 "case when DATE_LOCK is null or " . $helper->addSecondsToDateTime($maxLock * 60, 'DATE_LOCK') . " < now() then 'green' when LOCKED_BY = ".$userID." then 'yellow' else 'red' end"
359 ),
360
361 new Main\Entity\ReferenceField(
362 'USER_GROUP',
363 'Bitrix\Main\UserGroup',
364 array(
365 '=ref.USER_ID' => 'this.USER_ID'
366 )
367 ),
368
369 new Main\Entity\ReferenceField(
370 'RESPONSIBLE',
371 'Bitrix\Main\User',
372 array(
373 '=this.RESPONSIBLE_ID' => 'ref.ID'
374 )
375 ),
376
377 new Main\Entity\ReferenceField(
378 'BASKET',
379 'Bitrix\Sale\Internals\Basket',
380 array(
381 '=this.ID' => 'ref.ORDER_ID'
382 ),
383 array('join_type' => 'INNER')
384
385 ),
386
387 new Main\Entity\ExpressionField(
388 'BASKET_PRICE_TOTAL',
389 '(%s * %s)',
390 array('BASKET.PRICE', 'BASKET.QUANTITY')
391 ),
392
393 new Main\Entity\ReferenceField(
394 'PAYMENT',
395 'Bitrix\Sale\Internals\Payment',
396 array(
397 '=ref.ORDER_ID' => 'this.ID',
398 )
399 ),
400
401 new Main\Entity\ReferenceField(
402 'SHIPMENT',
403 'Bitrix\Sale\Internals\Shipment',
404 array(
405 '=ref.ORDER_ID' => 'this.ID',
406 )
407 ),
408
409 new Main\Entity\ReferenceField(
410 'PROPERTY',
411 'Bitrix\Sale\Internals\OrderPropsValue',
412 array(
413 '=ref.ORDER_ID' => 'this.ID',
414 ),
415 array('join_type' => 'INNER')
416 ),
417
418 new Main\Entity\BooleanField(
419 'RECOUNT_FLAG',
420 array(
421 'values' => array('N', 'Y')
422 )
423 ),
424
425 new Main\Entity\IntegerField('AFFILIATE_ID'),
426
427 new Main\Entity\StringField(
428 'DELIVERY_DOC_NUM',
429 array(
430 'size' => 20
431 )
432 ),
433
434 new Main\Entity\DatetimeField('DELIVERY_DOC_DATE'),
435
436 new Main\Entity\BooleanField(
437 'UPDATED_1C',
438 array(
439 'values' => array('N', 'Y'),
440 'default' => 'N'
441 )
442 ),
443
444 new Main\Entity\StringField('ORDER_TOPIC'),
445
446 new Main\Entity\StringField('XML_ID'),
447
448 new Main\Entity\StringField('ID_1C'),
449
450 new Main\Entity\StringField('VERSION_1C'),
451
452 new Main\Entity\IntegerField('VERSION'),
453
454 new Main\Entity\BooleanField(
455 'EXTERNAL_ORDER',
456 array(
457 'values' => array('N', 'Y')
458 )
459 ),
460
461 new Main\Entity\IntegerField('STORE_ID'),
462
463 new Main\Entity\BooleanField(
464 'CANCELED',
465 array(
466 'values' => array('N', 'Y'),
467 'default_value' => 'N'
468 )
469 ),
470 new Main\Entity\IntegerField('EMP_CANCELED_ID'),
471
472 new Main\Entity\ReferenceField(
473 'EMP_CANCELED_BY',
474 'Bitrix\Main\User',
475 array(
476 '=this.EMP_CANCELED_ID' => 'ref.ID'
477 )
478 ),
479
480 new Main\Entity\DatetimeField('DATE_CANCELED'),
481
482 new Main\Entity\ExpressionField(
483 'DATE_CANCELED_SHORT',
484 $DB->datetimeToDateFunction('%s'),
485 array('DATE_CANCELED'),
486 array('DATA_TYPE' => 'datetime')
487 ),
488
489 new Main\Entity\StringField('REASON_CANCELED'),
490
491
492 new Main\Entity\StringField('BX_USER_ID'),
493
494 new Main\Entity\TextField('SEARCH_CONTENT'),
495
496 new Main\Entity\BooleanField(
497 'RUNNING',
498 array(
499 'values' => array('N', 'Y'),
500 'default_value' => 'N'
501 )
502 ),
503
504 new Main\Entity\ReferenceField(
505 'ORDER_COUPONS',
506 'Bitrix\Sale\Internals\OrderCoupons',
507 array(
508 '=ref.ORDER_ID' => 'this.ID',
509 ),
510 array('join_type' => 'LEFT')
511 ),
512
513 new Main\Entity\ReferenceField(
514 'ORDER_DISCOUNT_DATA',
515 'Bitrix\Sale\Internals\OrderDiscountData',
516 array(
517 '=ref.ORDER_ID' => 'this.ID',
518 '=ref.ENTITY_TYPE' => new Main\DB\SqlExpression('?', OrderDiscountDataTable::ENTITY_TYPE_ORDER)
519 ),
520 array('join_type' => 'LEFT')
521 ),
522
523 new Main\Entity\ReferenceField(
524 'ORDER_DISCOUNT_RULES',
525 'Bitrix\Sale\Internals\OrderRules',
526 array(
527 '=ref.ORDER_ID' => 'this.ID',
528 ),
529 array('join_type' => 'LEFT')
530 ),
531
532 new Main\Entity\ExpressionField(
533 'BY_RECOMMENDATION',
534 "(SELECT (CASE WHEN MAX(BR.RECOMMENDATION) IS NULL OR MAX(BR.RECOMMENDATION) = '' THEN 'N' ELSE 'Y' END) FROM b_sale_basket BR WHERE BR.ORDER_ID=%s GROUP BY BR.ORDER_ID)",
535 array('ID')
536 ),
537
538 new Main\Entity\ReferenceField(
539 'TRADING_PLATFORM',
540 \Bitrix\Sale\TradingPlatform\OrderTable::getEntity(),
541 array(
542 '=ref.ORDER_ID' => 'this.ID',
543 ),
544 array('join_type' => 'LEFT')
545 ),
546 );
547 }
548
549 public static function getUfId()
550 {
551 return 'ORDER';
552 }
553
554 protected static function replaceDateTime()
555 {
556 global $DB;
557 $datetime = $DB->DateToCharFunction('___DATETIME___');
558 $datetime = str_replace('%', '%%', $datetime);
559 $datetime = str_replace('___DATETIME___', '%1$s', $datetime);
560 return $datetime;
561 }
562}
static loadMessages($file)
Definition loc.php:64