1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
checkmanager.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale\Cashbox;
4
5use Bitrix\Main\Error;
6use Bitrix\Sale\Cashbox\Internals\CashboxCheckCorrectionTable;
7use Bitrix\Sale\Cashbox\Internals\CashboxCheckTable;
8use Bitrix\Sale\Cashbox\Internals\CashboxTable;
9use Bitrix\Sale\EntityMarker;
10use Bitrix\Sale\Internals\CollectableEntity;
11use Bitrix\Sale\Internals\Entity;
12use Bitrix\Main;
13use Bitrix\Main\Localization\Loc;
14use Bitrix\Main\Type;
15use Bitrix\Sale;
16use Bitrix\Sale\Result;
17
18Loc::loadLanguageFile(__FILE__);
19
24final class CheckManager
25{
26 private const LOCK_NAME = 'get_check_list';
27
28 public const EVENT_ON_GET_CUSTOM_CHECK = 'OnGetCustomCheckList';
29 public const EVENT_ON_CHECK_PRINT_SEND = 'OnPrintableCheckSend';
30 public const EVENT_ON_BEFORE_CHECK_ADD_VERIFY = 'OnBeforeCheckAddVerify';
31 public const EVENT_ON_CHECK_PRINT_ERROR = 'OnCheckPrintError';
32 public const EVENT_ON_CHECK_COLLATE_DOCUMENTS = 'OnCheckCollateDocuments';
33 public const EVENT_ON_CHECK_VALIDATION_ERROR = 'OnCheckValidationError';
34 public const MIN_TIME_FOR_SWITCH_CASHBOX = 240;
35
39
46 public static function addByType(array $entities, $type, array $relatedEntities = array())
47 {
48 $result = new Result();
49
50 if ($type === '')
51 {
52 $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_EMPTY_CHECK_TYPE')));
53 return $result;
54 }
55
56 $check = self::createByType($type);
57 if (!$check instanceof Check)
58 {
59 $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_CHECK')));
60 return $result;
61 }
62
63 $check->setEntities($entities);
64 $check->setRelatedEntities($relatedEntities);
65
66 $cashboxList = Manager::getAvailableCashboxList($check);
67
68 $entity = reset($entities);
69 $order = self::getOrder($entity);
70
71 if (!$cashboxList)
72 {
73 $dbRes = CashboxTable::getList(array('filter' => array('ACTIVE' => 'Y')));
74 if ($dbRes->fetch())
75 $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_NOT_FOUND')));
76
77 return $result;
78 }
79
80 $check->setAvailableCashbox($cashboxList);
81
82 $registry = Sale\Registry::getInstance($check->getField("ENTITY_REGISTRY_TYPE"));
83
84 $validateResult = $check->validate();
85 if (!$validateResult->isSuccess())
86 {
87 if (Main\Loader::includeModule('crm'))
88 {
89 \Bitrix\Crm\Timeline\OrderCheckController::getInstance()->onCheckFailure(
90 [
91 'ORDER_FIELDS' => $order->getFieldValues(),
92 'SETTINGS' => [
93 'FAILURE' => 'Y',
94 'PRINTED' => 'N',
95 ],
96 'BINDINGS' => \Bitrix\Crm\Order\BindingsMaker\TimelineBindingsMaker::makeByOrder($order),
97 ]
98 );
99 }
100
101 $notifyClassName = $registry->getNotifyClassName();
102 $notifyClassName::callNotify($order, Sale\EventActions::EVENT_ON_CHECK_VALIDATION_ERROR);
103 $result->addErrors($validateResult->getErrors());
104
105 $event = new Main\Event('sale', self::EVENT_ON_CHECK_VALIDATION_ERROR, $check->getDataForCheck());
106 $event->send();
107
108 return $result;
109 }
110
111 $saveResult = $check->save();
112 if ($saveResult->isSuccess())
113 {
114 $checkId = $saveResult->getId();
115 $order->addPrintedCheck($check);
116
117 $enabledImmediateCashboxList = array();
118 foreach ($cashboxList as $item)
119 {
120 if ($item['ENABLED'] === 'Y')
121 {
122 $cashbox = Cashbox::create($item);
123 if ($cashbox instanceof IPrintImmediately)
124 {
125 $enabledImmediateCashboxList[$item['ID']] = $cashbox;
126 }
127 }
128 }
129
130 if ($enabledImmediateCashboxList)
131 {
132 $cashboxId = Manager::chooseCashbox(array_keys($enabledImmediateCashboxList));
134 $cashbox = $enabledImmediateCashboxList[$cashboxId];
135
136 CashboxCheckTable::update(
137 $checkId,
138 array(
139 'STATUS' => 'P',
140 'DATE_PRINT_START' => new Type\DateTime(),
141 'CASHBOX_ID' => $cashbox->getField('ID')
142 )
143 );
144
145 $printResult = $cashbox->printImmediately($check);
146 if ($printResult->isSuccess())
147 {
148 $data = $printResult->getData();
149 if ($data)
150 {
151 CashboxCheckTable::update($checkId, ['EXTERNAL_UUID' => $data['UUID']]);
152 }
153
154 if (Main\Loader::includeModule('crm'))
155 {
156 \Bitrix\Crm\Timeline\OrderCheckController::getInstance()->onPrintingCheck(
157 $checkId,
158 [
159 'ORDER_FIELDS' => $order->getFieldValues(),
160 'SETTINGS' => [
161 'PRINTING' => 'Y',
162 ],
163 'BINDINGS' => \Bitrix\Crm\Order\BindingsMaker\TimelineBindingsMaker::makeByOrder($order),
164 ]
165 );
166 }
167 }
168 else
169 {
170 self::savePrintResult(
171 $checkId,
172 [
173 'ID' => $checkId,
174 'ERROR' => [
175 'TYPE' => Errors\Error::TYPE,
176 'MESSAGE' => implode("\n", $printResult->getErrorMessages())
177 ]
178 ]
179 );
180 }
181
182 $result->setId($checkId);
183
184 return $result;
185 }
186
187 global $CACHE_MANAGER;
188 foreach ($cashboxList as $cashbox)
189 {
190 $CACHE_MANAGER->Read(CACHED_b_sale_order, 'sale_checks_'.$cashbox['ID']);
191 $CACHE_MANAGER->SetImmediate('sale_checks_'.$cashbox['ID'], true);
192 }
193 }
194 else
195 {
196 $result->addErrors($saveResult->getErrors());
197 }
198
199 return $result;
200 }
201
202 public static function reprint(int $checkId): Result
203 {
204 $result = new Result();
205
206 $check = self::getObjectById($checkId);
207 if (!$check)
208 {
209 return $result->addError(
210 new Error(Loc::getMessage('SALE_CASHBOX_ERROR_CHECK_NOT_FOUND', ['#CHECK_ID#' => $checkId]))
211 );
212 }
213
214 if (CashboxCheckCorrectionTable::getRow(['filter' => ['=CHECK_ID' => $checkId]]))
215 {
216 return $result->addError(
217 new Error(Loc::getMessage('SALE_CASBHOX_ERROR_CHECK_IS_CORRECTION_CHECK', ['#CHECK_ID#' => $checkId]))
218 );
219 }
220
221 if ($check->getField('STATUS') === 'Y')
222 {
223 return $result->addError(
224 new Error(Loc::getMessage('SALE_CASBHOX_ERROR_CHECK_ALREADY_PRINTED', ['#CHECK_ID#' => $checkId]))
225 );
226 }
227
228 if ($check->getField('STATUS') === 'P')
229 {
230 return $result->addError(
231 new Error(Loc::getMessage('SALE_CASBHOX_ERROR_CHECK_IS_PRINTING', ['#CHECK_ID#' => $checkId]))
232 );
233 }
234
235 $cashboxList = Manager::getAvailableCashboxList($check);
236
237 $entity = $check->getEntities()[0];
238 $order = self::getOrder($entity);
239
240 if (!$cashboxList)
241 {
242 $dbRes = CashboxTable::getList(array('filter' => array('ACTIVE' => 'Y')));
243 if ($dbRes->fetch())
244 $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_NOT_FOUND')));
245
246 return $result;
247 }
248
249 $check->setAvailableCashbox($cashboxList);
250
251 $registry = Sale\Registry::getInstance($check->getField("ENTITY_REGISTRY_TYPE"));
252
253 $validateResult = $check->validate();
254 if (!$validateResult->isSuccess())
255 {
256 if (Main\Loader::includeModule('crm'))
257 {
258 \Bitrix\Crm\Timeline\OrderCheckController::getInstance()->onCheckFailure(
259 [
260 'ORDER_FIELDS' => $order->getFieldValues(),
261 'SETTINGS' => [
262 'FAILURE' => 'Y',
263 'PRINTED' => 'N',
264 ],
265 'BINDINGS' => \Bitrix\Crm\Order\BindingsMaker\TimelineBindingsMaker::makeByOrder($order),
266 ]
267 );
268 }
269
270 $notifyClassName = $registry->getNotifyClassName();
271 $notifyClassName::callNotify($order, Sale\EventActions::EVENT_ON_CHECK_VALIDATION_ERROR);
272 $result->addErrors($validateResult->getErrors());
273
274 $event = new Main\Event('sale', self::EVENT_ON_CHECK_VALIDATION_ERROR, $check->getDataForCheck());
275 $event->send();
276
277 return $result;
278 }
279
280 $saveResult = $check->save();
281 if ($saveResult->isSuccess())
282 {
283 $checkId = $saveResult->getId();
284 $order->addPrintedCheck($check);
285
286 $enabledImmediateCashboxList = array();
287 foreach ($cashboxList as $item)
288 {
289 if ($item['ENABLED'] === 'Y')
290 {
291 $cashbox = Cashbox::create($item);
292 if ($cashbox instanceof IPrintImmediately)
293 {
294 $enabledImmediateCashboxList[$item['ID']] = $cashbox;
295 }
296 }
297 }
298
299 if ($enabledImmediateCashboxList)
300 {
301 $cashboxId = Manager::chooseCashbox(array_keys($enabledImmediateCashboxList));
303 $cashbox = $enabledImmediateCashboxList[$cashboxId];
304
305 CashboxCheckTable::update(
306 $checkId,
307 array(
308 'STATUS' => 'P',
309 'DATE_PRINT_START' => new Type\DateTime(),
310 'CASHBOX_ID' => $cashbox->getField('ID')
311 )
312 );
313
314 $printResult = $cashbox->printImmediately($check);
315 if ($printResult->isSuccess())
316 {
317 $data = $printResult->getData();
318 if ($data)
319 {
320 CashboxCheckTable::update($checkId, ['EXTERNAL_UUID' => $data['UUID']]);
321 }
322
323 if (Main\Loader::includeModule('crm'))
324 {
325 \Bitrix\Crm\Timeline\OrderCheckController::getInstance()->onPrintingCheck(
326 $checkId,
327 [
328 'ORDER_FIELDS' => $order->getFieldValues(),
329 'SETTINGS' => [
330 'PRINTING' => 'Y',
331 ],
332 'BINDINGS' => \Bitrix\Crm\Order\BindingsMaker\TimelineBindingsMaker::makeByOrder($order),
333 ]
334 );
335 }
336 }
337 else
338 {
339 self::savePrintResult(
340 $checkId,
341 [
342 'ID' => $checkId,
343 'ERROR' => [
344 'TYPE' => Errors\Error::TYPE,
345 'MESSAGE' => implode("\n", $printResult->getErrorMessages())
346 ]
347 ]
348 );
349 }
350
351 $result->setId($checkId);
352
353 return $result;
354 }
355
356 global $CACHE_MANAGER;
357 foreach ($cashboxList as $cashbox)
358 {
359 $CACHE_MANAGER->Read(CACHED_b_sale_order, 'sale_checks_'.$cashbox['ID']);
360 $CACHE_MANAGER->SetImmediate('sale_checks_'.$cashbox['ID'], true);
361 }
362 }
363 else
364 {
365 $result->addErrors($saveResult->getErrors());
366 }
367
368 return $result;
369 }
370
374 public static function isAvailableCorrection() : bool
375 {
376 foreach (Manager::getListFromCache() as $item)
377 {
378 if ($item['ACTIVE'] !== 'Y')
379 {
380 continue;
381 }
382
383 $cashbox = Manager::getObjectById($item['ID']);
384 if ($cashbox && $cashbox->isCorrection())
385 {
386 return true;
387 }
388 }
389
390 return false;
391 }
392
393 public static function addCorrection($type, $cashboxId, array $correction)
394 {
395 $result = new Result();
396
397 if (!self::isAvailableCorrection())
398 {
399 return $result->addError(
400 new Error(
401 Loc::getMessage('SALE_CASHBOX_CHECK_CORRECTION_NOT_AVAILABLE')
402 )
403 );
404 }
405
407 $check = self::createByType($type);
408 if (!$check instanceof CorrectionCheck)
409 {
410 $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_CHECK')));
411 return $result;
412 }
413
414 $check->setField('CASHBOX_ID', $cashboxId);
415 $check->setAvailableCashbox([
417 ]);
418
419 $check->setCorrectionFields($correction);
420
421 $r = $check->save();
422 if ($r->isSuccess())
423 {
424 $result->setId($check->getField('ID'));
425
426 $cashbox = Manager::getObjectById($cashboxId);
427 if ($cashbox->isCorrection())
428 {
429 CashboxCheckTable::update(
430 $check->getField('ID'),
431 [
432 'STATUS' => 'P', 'DATE_PRINT_START' => new Type\DateTime()
433 ]
434 );
435
436 $printResult = $cashbox->printCorrectionImmediately($check);
437 if ($printResult->isSuccess())
438 {
439 $data = $printResult->getData();
440 CashboxCheckTable::update($check->getField('ID'), ['EXTERNAL_UUID' => $data['UUID']]);
441 }
442 else
443 {
444 self::savePrintResult(
445 $check->getField('ID'),
446 [
447 'ID' => $check->getField('ID'),
448 'ERROR' => [
449 'TYPE' => Errors\Error::TYPE,
450 'MESSAGE' => implode("\n", $printResult->getErrorMessages())
451 ]
452 ]
453 );
454 }
455
456 global $CACHE_MANAGER;
457 $CACHE_MANAGER->Read(CACHED_b_sale_order, 'sale_checks_'.$cashboxId);
458 $CACHE_MANAGER->SetImmediate('sale_checks_'.$cashboxId, true);
459 }
460 }
461 else
462 {
463 $result->addErrors($r->getErrors());
464 }
465
466 return $result;
467 }
468
480 public static function savePrintResult($checkId, array $data)
481 {
482 $result = new Result();
483
484 if ($checkId <= 0)
485 {
486 $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_CHECK_ID')));
487 return $result;
488 }
489
490 $order = null;
491 $payment = null;
492 $shipment = null;
493
494 $dbRes = self::getList(array('select' => array('*'), 'filter' => array('ID' => $checkId)));
495 $check = $dbRes->fetch();
496 if (!$check)
497 {
498 $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_CHECK_NOT_FOUND', array('#CHECK_ID#' => $checkId))));
499 return $result;
500 }
501
502 if ($check['STATUS'] === 'Y')
503 return $result;
504
505 $registry = Sale\Registry::getInstance($check['ENTITY_REGISTRY_TYPE']);
506
507 if ($check['ORDER_ID'] > 0)
508 {
510 $orderClassName = $registry->getOrderClassName();
511 $order = $orderClassName::load($check['ORDER_ID']);
512 if ($order === null)
513 {
514 $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_CHECK_ORDER_LOAD')));
515 return $result;
516 }
517
518 $paymentCollection = $order->getPaymentCollection();
519 if ($check['PAYMENT_ID'] > 0)
520 {
521 $payment = $paymentCollection->getItemById($check['PAYMENT_ID']);
522 if ($payment === null)
523 {
524 $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_CHECK_PAYMENT_LOAD')));
525 return $result;
526 }
527 }
528
529 $shipmentCollection = $order->getShipmentCollection();
530 if ($check['SHIPMENT_ID'] > 0)
531 {
532 $shipment = $shipmentCollection->getItemById($check['SHIPMENT_ID']);
533 if ($shipment === null)
534 {
535 $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_CHECK_SHIPMENT_LOAD')));
536 return $result;
537 }
538 }
539 }
540
541 if (isset($data['ERROR']))
542 {
543 $errorMessage = Loc::getMessage('SALE_CASHBOX_ERROR_CHECK_PRINT', array('#CHECK_ID#' => $checkId));
544 if ($data['ERROR']['MESSAGE'])
545 $errorMessage .= ': '.$data['ERROR']['MESSAGE'];
546
547 if ($data['ERROR']['TYPE'] === Errors\Warning::TYPE)
548 {
549 if ($check['CNT_FAIL_PRINT'] >= 3)
550 {
551 $data['ERROR']['TYPE'] = Errors\Error::TYPE;
552 }
553 else
554 {
555 CashboxCheckTable::update($checkId, array('CNT_FAIL_PRINT' => $check['CNT_FAIL_PRINT'] + 1));
556 $result->addError(new Errors\Warning($errorMessage));
557 return $result;
558 }
559 }
560
561 if ($data['ERROR']['TYPE'] === Errors\Error::TYPE)
562 {
563 $updatedFields = [
564 'STATUS' => 'E',
565 'DATE_PRINT_END' => new Main\Type\DateTime(),
566 'ERROR_MESSAGE' => $data['ERROR']['MESSAGE']
567 ];
568 if ((int)$check['CNT_FAIL_PRINT'] === 0)
569 $updatedFields['CNT_FAIL_PRINT'] = 1;
570
571 CashboxCheckTable::update($checkId, $updatedFields);
572
574 self::addTimelineCheckEntryOnCreateToOrder(
575 $order,
576 $checkId,
577 [
578 'PRINTED' => 'N',
579 'ERROR_MESSAGE' => $data['ERROR']['MESSAGE'],
580 ]
581 );
582
583 if ($order !== null
584 && (
585 $payment !== null
586 || $shipment !== null
587 )
588 )
589 {
590 $r = new Result();
591 $errorCode = isset($data['ERROR']['CODE']) ? $data['ERROR']['CODE'] : 0;
592 $r->addWarning(new Main\Error($errorMessage, $errorCode));
593
595 $markerClassName = $registry->getEntityMarkerClassName();
596
597 if ($payment !== null)
598 {
599 $markerClassName::addMarker($order, $payment, $r);
600 $payment->setField('MARKED', 'Y');
601
603 $notifyClassName = $registry->getNotifyClassName();
604 $notifyClassName::callNotify($payment, Sale\EventActions::EVENT_ON_CHECK_PRINT_ERROR);
605 }
606 elseif ($shipment !== null)
607 {
608 $markerClassName::addMarker($order, $shipment, $r);
609 $shipment->setField('MARKED', 'Y');
610
612 $notifyClassName = $registry->getNotifyClassName();
613 $notifyClassName::callNotify($shipment, Sale\EventActions::EVENT_ON_CHECK_PRINT_ERROR);
614 }
615
616 $order->save();
617 }
618
619 $error = new Errors\Error($errorMessage);
620 Logger::addError($error->getMessage(), $check['CASHBOX_ID']);
621 }
622 else
623 {
624 $error = new Errors\Warning($errorMessage);
625 Logger::addWarning($error->getMessage(), $check['CASHBOX_ID']);
626 }
627
628 $event = new Main\Event('sale', self::EVENT_ON_CHECK_PRINT_ERROR, array($data));
629 $event->send();
630
631 $result->addError($error);
632 }
633 else
634 {
635 $updateParams = [
636 'STATUS' => 'Y',
637 'LINK_PARAMS' => $data['LINK_PARAMS'],
638 'DATE_PRINT_END' => new Main\Type\DateTime(),
639 'ERROR_MESSAGE' => null,
640 ];
641
642 if (isset($data['EXTERNAL_UUID']))
643 {
644 $updateParams['EXTERNAL_UUID'] = $data['EXTERNAL_UUID'];
645 }
646
647 $updateResult = CashboxCheckTable::update($checkId, $updateParams);
648
649 if ($updateResult->isSuccess())
650 {
651 self::addStatisticOnSuccessCheckPrint($checkId);
652
653 self::addTimelineCheckEntryOnCreateToOrder($order, $checkId, ['PRINTED' => 'Y']);
654
655 $isSend = false;
656 $event = new Main\Event(
657 'sale',
658 self::EVENT_ON_CHECK_PRINT_SEND,
659 array('PAYMENT' => $payment, 'SHIPMENT' => $shipment, 'CHECK' => $check)
660 );
661 $event->send();
662
663 $eventResults = $event->getResults();
665 foreach($eventResults as $eventResult)
666 {
667 if($eventResult->getType() == Main\EventResult::SUCCESS)
668 $isSend = true;
669 }
670
671 if (!$isSend)
672 {
673 if ($payment !== null)
674 {
676 $notifyClassName = $registry->getNotifyClassName();
677 $notifyClassName::callNotify($payment, Sale\EventActions::EVENT_ON_CHECK_PRINT);
678 }
679 elseif ($shipment !== null)
680 {
682 $notifyClassName = $registry->getNotifyClassName();
683 $notifyClassName::callNotify($shipment, Sale\EventActions::EVENT_ON_CHECK_PRINT);
684 }
685 }
686 }
687 else
688 {
689 $result->addErrors($updateResult->getErrors());
690 }
691 }
692
693 return $result;
694 }
695
696 private static function addStatisticOnSuccessCheckPrint($checkId)
697 {
698 $check = self::getObjectById($checkId);
699
700 $cashbox = Manager::getObjectById($check->getField('CASHBOX_ID'));
701 if ($cashbox)
702 {
703 AddEventToStatFile('sale', 'checkPrint', $checkId, $cashbox::getCode());
704 }
705 }
706
707 private static function addTimelineCheckEntryOnCreateToOrder($order, $checkId, $params)
708 {
709 if ($order && Main\Loader::includeModule('crm'))
710 {
711 \Bitrix\Crm\Timeline\OrderCheckController::getInstance()->onPrintCheck(
712 $checkId,
713 [
714 'ORDER_FIELDS' => $order->getFieldValues(),
715 'SETTINGS' => $params,
716 'BINDINGS' => \Bitrix\Crm\Order\BindingsMaker\TimelineBindingsMaker::makeByOrder($order),
717 ]
718 );
719 }
720 }
721
728 public static function delete($id)
729 {
730 $r = CashboxCheckTable::delete($id);
731 if ($r->isSuccess())
732 {
734 ->addSelect('ID')
735 ->where('CHECK_ID', $id);
736
737 while ($link = $dbRes->fetchObject())
738 {
739 $link->delete();
740 }
741 }
742 }
743
748 public static function addChecks(array $entities)
749 {
750 $result = new Result();
751
752 $map = self::collateDocuments($entities);
753 foreach ($map as $check)
754 {
755 $isCorrect = true;
756
757 $event = new Main\Event('sale', self::EVENT_ON_BEFORE_CHECK_ADD_VERIFY, array($check));
758 $event->send();
759
760 if ($event->getResults())
761 {
763 foreach ($event->getResults() as $eventResult)
764 {
765 if ($eventResult->getType() !== Main\EventResult::ERROR)
766 {
767 $isCorrect = (bool)$eventResult->getParameters();
768 }
769 }
770 }
771
772 if ($isCorrect)
773 {
774 $addResult = self::addByType($check["ENTITIES"], $check["TYPE"], $check["RELATED_ENTITIES"]);
775 if (!$addResult->isSuccess())
776 {
777 $result->addErrors($addResult->getErrors());
778 }
779 }
780 }
781
782 return $result;
783 }
784
790 public static function getOrder($entity)
791 {
792 $order = null;
793
794 if ($entity instanceof Sale\Payment)
795 {
797 $col = $entity->getCollection();
798 $order = $col->getOrder();
799 }
800 elseif ($entity instanceof Sale\Shipment)
801 {
803 $col = $entity->getCollection();
804 $order = $col->getOrder();
805 }
806 else
807 {
808 throw new Main\ArgumentTypeException("entities");
809 }
810
811 return $order;
812 }
813
817 private static function getBuildInCheckList()
818 {
819 $checkList = array(
820 '\Bitrix\Sale\Cashbox\SellCheck',
821 '\Bitrix\Sale\Cashbox\SellReturnCashCheck',
822 '\Bitrix\Sale\Cashbox\SellReturnCheck'
823 );
824
825 if (Manager::isSupportedFFD105())
826 {
827 $checkList = array_merge(
828 $checkList,
829 array(
830 '\Bitrix\Sale\Cashbox\CorrectionSellCheck',
831 '\Bitrix\Sale\Cashbox\CorrectionBuyCheck',
832 '\Bitrix\Sale\Cashbox\AdvancePaymentCheck',
833 '\Bitrix\Sale\Cashbox\AdvanceReturnCheck',
834 '\Bitrix\Sale\Cashbox\AdvanceReturnCashCheck',
835 '\Bitrix\Sale\Cashbox\CreditPaymentCheck',
836 '\Bitrix\Sale\Cashbox\CreditPaymentReturnCheck',
837 '\Bitrix\Sale\Cashbox\CreditPaymentReturnCashCheck',
838 '\Bitrix\Sale\Cashbox\CreditCheck',
839 '\Bitrix\Sale\Cashbox\CreditReturnCheck',
840 '\Bitrix\Sale\Cashbox\PrepaymentCheck',
841 '\Bitrix\Sale\Cashbox\PrepaymentReturnCheck',
842 '\Bitrix\Sale\Cashbox\PrepaymentReturnCashCheck',
843 '\Bitrix\Sale\Cashbox\FullPrepaymentCheck',
844 '\Bitrix\Sale\Cashbox\FullPrepaymentReturnCheck',
845 '\Bitrix\Sale\Cashbox\FullPrepaymentReturnCashCheck',
846 )
847 );
848 }
849
850 return $checkList;
851 }
852
856 private static function getUserCheckList()
857 {
858 $checkList = array();
859
860 $event = new Main\Event('sale', self::EVENT_ON_GET_CUSTOM_CHECK);
861 $event->send();
862 $resultList = $event->getResults();
863
864 if (is_array($resultList) && !empty($resultList))
865 {
866 foreach ($resultList as $eventResult)
867 {
869 if ($eventResult->getType() === Main\EventResult::SUCCESS)
870 {
871 $params = $eventResult->getParameters();
872 if (!empty($params) && is_array($params))
873 $checkList = array_merge($checkList, $params);
874 }
875 }
876 }
877
878 return $checkList;
879 }
880
884 public static function init()
885 {
886 static $isInit = false;
887
888 if ($isInit === false)
889 {
890 $handlers = self::getUserCheckList();
892 $isInit = true;
893 }
894 }
895
899 public static function getCheckList()
900 {
901 static $checkList = array();
902 if (!$checkList)
903 {
904 $checkList = array_merge(
905 self::getBuildInCheckList(),
906 array_keys(self::getUserCheckList())
907 );
908 }
909
910 return $checkList;
911 }
912
913 public static function getSalesCheckList()
914 {
915 return array_filter(
916 self::getCheckList(),
917 function ($value)
918 {
919 return is_subclass_of($value, Check::class);
920 }
921 );
922 }
923
927 public static function getCheckTypeMap()
928 {
929 self::init();
930
931 $result = array();
932 $checkMap = self::getCheckList();
933
935 foreach ($checkMap as $className)
936 {
937 if (class_exists($className))
938 {
939 $result[$className::getType()] = $className;
940 }
941 }
942
943 return $result;
944 }
945
950 public static function createByType($type)
951 {
952 self::init();
953
954 $typeMap = self::getCheckTypeMap();
955 $handler = $typeMap[$type];
956
957 return Check::create($handler);
958 }
959
965 public static function collateDocuments(array $entities)
966 {
967 $map = [];
968
969 $event = new Main\Event('sale', self::EVENT_ON_CHECK_COLLATE_DOCUMENTS, [
970 'ENTITIES' => $entities
971 ]);
972 $event->send();
973 $eventResults = $event->getResults();
974 if ($eventResults != null)
975 {
976 foreach ($eventResults as $eventResult)
977 {
978 if ($eventResult->getType() === Main\EventResult::SUCCESS)
979 {
980 $d = $eventResult->getParameters();
981 if (!is_array($d))
982 throw new Main\NotSupportedException("OnCheckCollateDocuments event result");
983
984 $map = array_merge($map, $d);
985 }
986 else if ($eventResult->getType() === Main\EventResult::ERROR)
987 {
988 return $map;
989 }
990 }
991
992 if (count($map) > 0)
993 {
994 return $map;
995 }
996 }
997
998 $existingChecks = null;
999 $order = null;
1000
1002 foreach ($entities as $entity)
1003 {
1004 // load existing checks
1005 if ($existingChecks === null)
1006 {
1007 $existingChecks = [];
1008 $order = self::getOrder($entity);
1009
1010 $filter = [
1011 'ORDER_ID' => $order->getId(),
1012 'ENTITY_REGISTRY_TYPE' => $entity::getRegistryType()
1013 ];
1014 if ($entity instanceof Sale\Payment)
1015 {
1016 $filter["PAYMENT_ID"] = $entity->getId();
1017 }
1018 elseif ($entity instanceof Sale\Shipment)
1019 {
1020 $filter["SHIPMENT_ID"] = $entity->getId();
1021 }
1022
1023 $db = self::getList([
1024 "filter" => $filter,
1025 "select" => ["ID", "PAYMENT_ID", "SHIPMENT_ID", "TYPE", "STATUS"]
1026 ]);
1027 while ($ar = $db->fetch())
1028 {
1029 if (intval($ar["PAYMENT_ID"]) > 0)
1030 {
1031 $existingChecks["P"][ $ar["PAYMENT_ID"] ][] = $ar;
1032 }
1033
1034 if (intval($ar["SHIPMENT_ID"]) > 0)
1035 {
1036 $existingChecks["S"][ $ar["SHIPMENT_ID"] ][] = $ar;
1037 }
1038 }
1039 }
1040
1041 // analysing
1042 // we should allow users to implement their own algorithms
1043 if (count($existingChecks) <= 0)
1044 {
1045 if (self::isAutomaticEnabled($order))
1046 {
1047 if (Manager::isSupportedFFD105())
1048 {
1050 {
1051 $result = self::collatePaySystemWithFFD105($entity);
1052 }
1053 else
1054 {
1055 $result = self::collateWithFFD105($entity);
1056 }
1057 }
1058 else
1059 {
1060 $result = self::collate($entity);
1061 }
1062
1063 if ($result)
1064 {
1065 $map = array_merge($map, $result);
1066 }
1067 }
1068 }
1069 }
1070
1071 return $map;
1072 }
1073
1080 private static function isAutomaticEnabled(Sale\Order $order)
1081 {
1082 $shipmentCollection = $order->getShipmentCollection();
1083 if (
1084 (
1085 $shipmentCollection->count() > 2
1086 && $shipmentCollection->isExistsSystemShipment()
1087 )
1088 ||
1089 (
1090 $shipmentCollection->count() > 1
1091 && !$shipmentCollection->isExistsSystemShipment()
1092 )
1093 )
1094 {
1095 return false;
1096 }
1097
1098 $paymentCollection = $order->getPaymentCollection();
1099 if (
1100 (
1101 $paymentCollection->isExistsInnerPayment()
1102 && $paymentCollection->count() > 2
1103 )
1104 ||
1105 (
1106 !$paymentCollection->isExistsInnerPayment()
1107 && $paymentCollection->count() > 1
1108 )
1109 )
1110 {
1111 return false;
1112 }
1113
1114 return true;
1115 }
1116
1124 private static function collate($entity)
1125 {
1126 $map = array();
1127
1128 if ($entity instanceof Sale\Payment)
1129 {
1130 $order = self::getOrder($entity);
1131
1133 $service = $entity->getPaySystem();
1134 if ($entity->isPaid() &&
1135 ($service->getField("CAN_PRINT_CHECK") == "Y") &&
1136 ($entity->getSum() == $order->getPrice())
1137 )
1138 {
1139 $checkEntities[] = $entity;
1140
1141 $shipmentCollection = $order->getShipmentCollection();
1143 foreach ($shipmentCollection as $shipment)
1144 {
1145 if (!$shipment->isSystem())
1146 $checkEntities[] = $shipment;
1147 }
1148
1149 $map[] = array("TYPE" => SellCheck::getType(), "ENTITIES" => $checkEntities, "RELATED_ENTITIES" => array());
1150 }
1151 }
1152
1153 return $map;
1154 }
1155
1165 private static function collateWithFFD105($entity)
1166 {
1167 $map = array();
1168
1169 $order = self::getOrder($entity);
1170 if (!self::canPrintCheck($order))
1171 {
1172 return $map;
1173 }
1174
1175 $entities = array();
1176 $relatedEntities = array();
1177 if ($entity instanceof Sale\Payment)
1178 {
1179 if ($entity->isInner() || !$entity->isPaid())
1180 return $map;
1181
1182 $service = $entity->getPaySystem();
1183 $type = $service->getField('IS_CASH') === 'Y' ? Check::PAYMENT_TYPE_CASHLESS : Check::PAYMENT_TYPE_CASH;
1184 $entities[$type] = $entity;
1185
1186 $fields = $order->getFields();
1187 $originalFields = $fields->getOriginalValues();
1188 if (!isset($originalFields['DEDUCTED']))
1189 $originalFields['DEDUCTED'] = $order->getField('DEDUCTED');
1190
1191 $paymentCollection = $order->getPaymentCollection();
1192 if ($order->getField('DEDUCTED') === 'Y' && $originalFields['DEDUCTED'] === 'Y')
1193 {
1194 if ($paymentCollection->isExistsInnerPayment())
1195 {
1196 $relatedEntities[Check::PAYMENT_TYPE_ADVANCE][] = $paymentCollection->getInnerPayment();
1197 }
1198
1199 $map[] = array("TYPE" => CreditPaymentCheck::getType(), "ENTITIES" => $entities, "RELATED_ENTITIES" => $relatedEntities);
1200 }
1201 else
1202 {
1203 $option = Main\Config\Option::get('sale', 'check_type_on_pay', 'sell');
1204 if ($option === 'prepayment')
1205 {
1206 $checkType = ($entity->getSum() == $entity->getOrder()->getPrice()) ? FullPrepaymentCheck::getType() : PrepaymentCheck::getType();
1207
1208 $shipmentCollection = $order->getShipmentCollection()->getNotSystemItems();
1210 foreach ($shipmentCollection as $shipment)
1211 {
1212 $relatedEntities[Check::SHIPMENT_TYPE_NONE][] = $shipment;
1213 }
1214
1215 $map[] = array("TYPE" => $checkType, "ENTITIES" => $entities, "RELATED_ENTITIES" => $relatedEntities);
1216 }
1217 elseif ($option === 'advance')
1218 {
1219 $map[] = array("TYPE" => AdvancePaymentCheck::getType(), "ENTITIES" => $entities, "RELATED_ENTITIES" => $relatedEntities);
1220 }
1221 else
1222 {
1223 if ($paymentCollection->isExistsInnerPayment())
1224 {
1225 $map[] = array("TYPE" => AdvancePaymentCheck::getType(), "ENTITIES" => $entities, "RELATED_ENTITIES" => $relatedEntities);
1226 }
1227 else
1228 {
1229 $shipmentCollection = $order->getShipmentCollection()->getNotSystemItems();
1231 foreach ($shipmentCollection as $shipment)
1232 {
1233 $relatedEntities[Check::SHIPMENT_TYPE_NONE][] = $shipment;
1234 }
1235
1236 $map[] = array("TYPE" => SellCheck::getType(), "ENTITIES" => $entities, "RELATED_ENTITIES" => $relatedEntities);
1237 }
1238 }
1239 }
1240 }
1241 elseif ($entity instanceof Sale\Shipment)
1242 {
1243 if ($entity->getField('DEDUCTED') !== 'Y')
1244 return $map;
1245
1246 $entities[] = $entity;
1247 if ($order->isPaid())
1248 {
1249 if (Main\Config\Option::get('sale', 'check_type_on_pay', 'sell') === 'sell')
1250 {
1251 return $map;
1252 }
1253
1254 $paymentCollection = $order->getPaymentCollection();
1255 foreach ($paymentCollection as $payment)
1256 {
1257 $relatedEntities[Check::PAYMENT_TYPE_ADVANCE][] = $payment;
1258 }
1259
1260 $map[] = array("TYPE" => SellCheck::getType(), "ENTITIES" => $entities, "RELATED_ENTITIES" => $relatedEntities);
1261 }
1262 else
1263 {
1264 $map[] = array("TYPE" => CreditCheck::getType(), "ENTITIES" => $entities, "RELATED_ENTITIES" => $relatedEntities);
1265 }
1266 }
1267 else
1268 {
1269 throw new Main\NotSupportedException();
1270 }
1271
1272 return $map;
1273 }
1274
1282 private static function collatePaySystemWithFFD105($entity): array
1283 {
1284 $map = [];
1285 $entities = [];
1286 $relatedEntities = [];
1288
1289 $option = Main\Config\Option::get('sale', 'check_type_on_pay', 'sell');
1290
1291 if ($entity instanceof Sale\Payment)
1292 {
1293 $fields = $entity->getFields();
1294 $originalFields = $fields->getOriginalValues();
1295 if ($originalFields['PAID'] === 'Y' || $fields->get('IS_RETURN') === 'Y')
1296 {
1297 return $map;
1298 }
1299
1300 $order = $entity->getOrder();
1301
1302 $entities[] = $entity;
1303
1304 $isShipped = false;
1306 foreach ($order->getShipmentCollection()->getNotSystemItems() as $shipment)
1307 {
1308 $isShipped = $shipment->isShipped();
1309 if (!$isShipped)
1310 {
1311 $relatedEntities = [];
1312 break;
1313 }
1314
1315 $relatedEntities[Check::SHIPMENT_TYPE_NONE][] = $shipment;
1316 }
1317
1318 if (!$isShipped)
1319 {
1320 $order = $entity->getOrder();
1321 if ($option === 'prepayment')
1322 {
1323 $type = (Sale\PriceMaths::roundPrecision($entity->getSum()) === Sale\PriceMaths::roundPrecision($order->getPrice()))
1326
1327 $shipmentCollection = $order->getShipmentCollection()->getNotSystemItems();
1329 foreach ($shipmentCollection as $shipment)
1330 {
1331 $relatedEntities[Check::SHIPMENT_TYPE_NONE][] = $shipment;
1332 }
1333 }
1334 elseif ($option === 'advance')
1335 {
1337 }
1338 else
1339 {
1340 $shipmentCollection = $order->getShipmentCollection()->getNotSystemItems();
1342 foreach ($shipmentCollection as $shipment)
1343 {
1344 $relatedEntities[Check::SHIPMENT_TYPE_NONE][] = $shipment;
1345 }
1346 }
1347 }
1348 }
1349 elseif ($entity instanceof Sale\Shipment)
1350 {
1351 $fields = $entity->getFields();
1352 $originalFields = $fields->getOriginalValues();
1353 if ($originalFields['DEDUCTED'] === 'Y' || $fields->get('DEDUCTED') !== 'Y')
1354 {
1355 return $map;
1356 }
1357
1358 $order = $entity->getOrder();
1359 if ($order->isPaid() && $entity->isShipped())
1360 {
1361 if ($option === 'sell')
1362 {
1363 return $map;
1364 }
1365
1366 $entities[] = $entity;
1367
1369 foreach ($order->getPaymentCollection() as $payment)
1370 {
1371 if ($payment->isInner())
1372 {
1373 continue;
1374 }
1375
1376 $relatedEntities[Check::PAYMENT_TYPE_CASHLESS][] = $payment;
1377 }
1378 }
1379 }
1380
1381 if ($entities)
1382 {
1383 $map[] = [
1384 'TYPE' => $type,
1385 'ENTITIES' => $entities,
1386 'RELATED_ENTITIES' => $relatedEntities,
1387 ];
1388 }
1389
1390 return $map;
1391 }
1392
1397 private static function canPrintCheck(Sale\Order $order)
1398 {
1399 $paymentCollection = $order->getPaymentCollection();
1400 if ($paymentCollection->isEmpty())
1401 {
1402 return false;
1403 }
1404
1406 foreach ($paymentCollection as $payment)
1407 {
1408 if ($payment->isInner())
1409 continue;
1410
1411 $service = $payment->getPaySystem();
1412 if ($service === null
1413 || $service->getField("CAN_PRINT_CHECK") !== 'Y'
1414 )
1415 {
1416 return false;
1417 }
1418 }
1419
1420 return true;
1421 }
1422
1433 public static function getPrintableChecks(array $cashboxIds, array $orderIds = array())
1434 {
1435 $result = array();
1436
1437 $con = Main\Application::getConnection();
1438 if (!$con->lock(self::LOCK_NAME))
1439 {
1440 return $result;
1441 }
1442
1443 $helper = $con->getSqlHelper();
1444
1445 $filter = array(
1446 'LINK_PARAMS' => '',
1447 'CHECK2CASHBOX.CASHBOX_ID' => $cashboxIds,
1448 array(
1449 'LOGIC' => 'OR',
1450 array(
1451 '=STATUS' => 'N',
1452 'DATE_PRINT_START' => ''
1453 ),
1454 array(
1455 '=STATUS' => 'P',
1456 '<MAX_DT_REPEAT_CHECK' => new Type\DateTime()
1457 )
1458 )
1459 );
1460
1461 if ($orderIds)
1462 {
1463 $filter['ORDER_ID'] = $orderIds;
1464 }
1465
1466 $limit = count($cashboxIds)*self::CHECK_LIMIT_RECORDS;
1468 array(
1469 'select' => array('*', 'AVAILABLE_CASHBOX_ID' => 'CHECK2CASHBOX.CASHBOX_ID'),
1470 'filter' => $filter,
1471 'limit' => $limit,
1472 'runtime' => array(
1473 new Main\Entity\ExpressionField(
1474 'MAX_DT_REPEAT_CHECK',
1475 $helper->addSecondsToDateTime(self::CHECK_RESENDING_TIME * 60, 'DATE_PRINT_START'),
1476 null,
1477 array(
1478 'data_type' => 'datetime'
1479 )
1480 )
1481 )
1482 )
1483 );
1484
1485 if ($data = $dbRes->fetch())
1486 {
1487 $i = 0;
1488 do
1489 {
1490 if (!isset($result[$data['ID']]))
1491 {
1492 $i++;
1493 if ($i > self::CHECK_LIMIT_RECORDS)
1494 break;
1495
1496 $result[$data['ID']] = $data;
1497 $result[$data['ID']]['CASHBOX_LIST'] = array();
1498 }
1499
1500 $result[$data['ID']]['CASHBOX_LIST'][] = $data['AVAILABLE_CASHBOX_ID'];
1501 }
1502 while ($data = $dbRes->fetch());
1503
1504 foreach ($result as $checkId => $item)
1505 {
1506 if ($item['STATUS'] === 'P')
1507 {
1508 $now = new Type\DateTime();
1509 $nowTs = $now->getTimestamp();
1510
1512 $dateStartPrint = $item['DATE_PRINT_START'];
1513 $dateStartPrintTs = $dateStartPrint->getTimestamp();
1514
1515 if ($nowTs - $dateStartPrintTs > self::MIN_TIME_FOR_SWITCH_CASHBOX)
1516 {
1517 $availableCashboxIds = array_diff($item['CASHBOX_LIST'], array($item['CASHBOX_ID']));
1518 if ($availableCashboxIds)
1519 {
1520 $result[$checkId]['CASHBOX_ID'] = Manager::chooseCashbox($availableCashboxIds);
1521 CashboxCheckTable::update($checkId, array('CASHBOX_ID' => $result[$checkId]['CASHBOX_ID']));
1522 }
1523 }
1524 else
1525 {
1526 if ($item['CASHBOX_ID'] > 0 && !in_array($item['CASHBOX_ID'], $cashboxIds))
1527 unset($result[$checkId]);
1528 }
1529
1530 continue;
1531 }
1532
1533 $result[$checkId]['CASHBOX_ID'] = Manager::chooseCashbox($item['CASHBOX_LIST']);
1534 CashboxCheckTable::update($checkId, array('STATUS' => 'P', 'DATE_PRINT_START' => new Type\DateTime(), 'CASHBOX_ID' => $result[$checkId]['CASHBOX_ID']));
1535 }
1536 }
1537
1538 $con->unlock(self::LOCK_NAME);
1539
1540 return $result;
1541 }
1542
1547 public static function create(array $settings)
1548 {
1549 $check = CheckManager::createByType($settings['TYPE']);
1550 if ($check)
1551 $check->init($settings);
1552
1553 return $check;
1554 }
1555
1563 {
1564 $filter = array();
1565 if ($entity->getId() > 0)
1566 {
1567 if ($entity instanceof Sale\Payment)
1568 {
1569 $filter['=ENTITY_REGISTRY_TYPE'] = $entity::getRegistryType();
1570 $filter['=PAYMENT_ID'] = $entity->getId();
1571 }
1572 elseif ($entity instanceof Sale\Shipment)
1573 {
1574 $filter['=ENTITY_REGISTRY_TYPE'] = $entity::getRegistryType();
1575 $filter['=SHIPMENT_ID'] = $entity->getId();
1576 }
1577
1578 return self::collectInfo($filter);
1579 }
1580
1581 return array();
1582 }
1583
1590 {
1591 if (!($entity instanceof Sale\Payment)
1592 && !($entity instanceof Sale\Shipment)
1593 )
1594 {
1595 return array();
1596 }
1597
1598 $filter = array(
1599 '=STATUS' => 'Y',
1600 '=ENTITY_REGISTRY_TYPE' => $entity::getRegistryType()
1601 );
1602 if ($entity instanceof Sale\Payment)
1603 {
1604 $filter['PAYMENT_ID'] = $entity->getId();
1605 }
1606 elseif ($entity instanceof Sale\Shipment)
1607 {
1608 $filter['SHIPMENT_ID'] = $entity->getId();
1609 }
1610
1612 array(
1613 'select' => array('*'),
1614 'filter' => $filter,
1615 'order' => array('DATE_PRINT_END' => 'DESC'),
1616 'limit' => 1
1617 )
1618 );
1619
1620 if ($data = $dbRes->fetch())
1621 {
1622 $data['LINK'] = '';
1623 if (!empty($data['LINK_PARAMS']))
1624 {
1625 $cashbox = Manager::getObjectById($data['CASHBOX_ID']);
1626 if ($cashbox)
1627 $data['LINK'] = $cashbox->getCheckLink($data['LINK_PARAMS']);
1628 }
1629
1630 return $data;
1631 }
1632
1633 return array();
1634 }
1635
1642 public static function collectInfo(array $filter = array())
1643 {
1644 $result = array();
1645
1646 $typeMap = CheckManager::getCheckTypeMap();
1647
1649 array(
1650 'select' => array('*'),
1651 'filter' => $filter
1652 )
1653 );
1654
1655 while ($data = $dbRes->fetch())
1656 {
1657 $data['LINK'] = '';
1658 if (!empty($data['LINK_PARAMS']))
1659 {
1660 $cashbox = Manager::getObjectById($data['CASHBOX_ID']);
1661 if ($cashbox)
1662 {
1663 $data['LINK'] = $cashbox->getCheckLink($data['LINK_PARAMS']);
1664 }
1665 }
1666
1668 $type = $typeMap[$data['TYPE']];
1669 if (class_exists($type))
1670 {
1671 $data['TYPE_NAME'] = $type::getName();
1672 }
1673
1674 $result[$data['ID']] = $data;
1675 }
1676
1677 return $result;
1678 }
1679
1685 public static function getCheckInfoByExternalUuid($uuid)
1686 {
1687 $dbRes = self::getList(array('filter' => array('=EXTERNAL_UUID' => $uuid)));
1688 return $dbRes->fetch();
1689 }
1690
1698 public static function getObjectById($id)
1699 {
1700 if ($id <= 0)
1701 return null;
1702
1703 $dbRes = CashboxCheckTable::getById($id);
1704 if ($checkInfo = $dbRes->fetch())
1705 {
1706 $check = self::createByType($checkInfo['TYPE']);
1707 if ($check)
1708 {
1709 $check->init($checkInfo);
1710 return $check;
1711 }
1712 }
1713
1714 return null;
1715 }
1716
1722 public static function getList(array $parameters = array())
1723 {
1724 return CashboxCheckTable::getList($parameters);
1725 }
1726
1735 public static function getRelatedEntitiesForPayment($checkType, $paymentId, $registryType = Sale\Registry::REGISTRY_TYPE_ORDER)
1736 {
1737 $result = array();
1738
1739 $check = self::createByType($checkType);
1740 if ($check === null)
1741 {
1742 throw new Main\ArgumentTypeException($checkType);
1743 }
1744
1745 $registry = Sale\Registry::getInstance($registryType);
1747 $paymentClassName = $registry->getPaymentClassName();
1748
1749 $dbRes = $paymentClassName::getList(array(
1750 'select' => array('ORDER_ID'),
1751 'filter' => array('=ID' => $paymentId)
1752 ));
1753
1754 $paymentData = $dbRes->fetch();
1755 if (!$paymentData)
1756 {
1757 return $result;
1758 }
1759
1760 if ($check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_PAYMENT
1761 || $check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_ALL
1762 )
1763 {
1764 if (Manager::isSupportedFFD105())
1765 {
1766 $dbRes = $paymentClassName::getList(array(
1767 'select' => array('ID', 'ACCOUNT_NUMBER', 'SUM', 'CURRENCY', 'NAME' => 'PAY_SYSTEM.NAME'),
1768 'filter' => array(
1769 '!ID' => $paymentId,
1770 '=ORDER_ID' => $paymentData['ORDER_ID']
1771 )
1772 ));
1773
1774 while ($data = $dbRes->fetch())
1775 {
1776 $data['PAYMENT_TYPES'] = array(
1777 array(
1778 'CODE' => Sale\Cashbox\Check::PAYMENT_TYPE_ADVANCE,
1779 'NAME' => Loc::getMessage('SALE_CASHBOX_CHECK_ADVANCE'),
1780 ),
1781 array(
1782 'CODE' => Sale\Cashbox\Check::PAYMENT_TYPE_CREDIT,
1783 'NAME' => Loc::getMessage('SALE_CASHBOX_CHECK_CREDIT'),
1784 )
1785 );
1786
1787 $result['PAYMENTS'][$data['ID']] = $data;
1788 }
1789 }
1790 }
1791 if ($check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_SHIPMENT
1792 || $check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_ALL
1793 )
1794 {
1796 $shipmentClassName = $registry->getShipmentClassName();
1797 $dbRes = $shipmentClassName::getList(array(
1798 'select' => array('ID', 'ACCOUNT_NUMBER', 'PRICE_DELIVERY', 'CURRENCY', 'NAME' => 'DELIVERY.NAME'),
1799 'filter' => array(
1800 '=ORDER_ID' => $paymentData['ORDER_ID'],
1801 'SYSTEM' => 'N'
1802 )
1803 ));
1804
1805 while ($data = $dbRes->fetch())
1806 {
1807 $result['SHIPMENTS'][$data['ID']] = $data;
1808 }
1809 }
1810
1811 return $result;
1812 }
1813
1822 public static function getRelatedEntitiesForShipment($checkType, $shipmentId, $registryType = Sale\Registry::REGISTRY_TYPE_ORDER)
1823 {
1824 $result = array();
1825
1826 if (!Manager::isSupportedFFD105())
1827 {
1828 return $result;
1829 }
1830
1831 $check = self::createByType($checkType);
1832 if ($check === null)
1833 {
1834 throw new Main\ArgumentTypeException($checkType);
1835 }
1836
1837 $registry = Sale\Registry::getInstance($registryType);
1839 $shipmentClassName = $registry->getShipmentClassName();
1840
1841 $dbRes = $shipmentClassName::getList(array(
1842 'select' => array('ORDER_ID'),
1843 'filter' => array('=ID' => $shipmentId)
1844 ));
1845
1846 $shipmentData = $dbRes->fetch();
1847 if (!$shipmentData)
1848 {
1849 return $result;
1850 }
1851
1852 if ($check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_SHIPMENT
1853 || $check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_ALL
1854 )
1855 {
1856 $dbRes = $shipmentClassName::getList(array(
1857 'select' => array('ID', 'ACCOUNT_NUMBER', 'PRICE_DELIVERY', 'CURRENCY', 'NAME' => 'DELIVERY.NAME'),
1858 'filter' => array(
1859 '!ID' => $shipmentId,
1860 '=ORDER_ID' => $shipmentData['ORDER_ID'],
1861 'SYSTEM' => 'N'
1862 )
1863 ));
1864
1865 while ($data = $dbRes->fetch())
1866 {
1867 $result['SHIPMENTS'][$data['ID']] = $data;
1868 }
1869 }
1870
1871 if ($check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_PAYMENT
1872 || $check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_ALL
1873 )
1874 {
1876 $paymentClassName = $registry->getPaymentClassName();
1877 $dbRes = $paymentClassName::getList(array(
1878 'select' => array('ID', 'ACCOUNT_NUMBER', 'SUM', 'CURRENCY', 'NAME' => 'PAY_SYSTEM.NAME'),
1879 'filter' => array(
1880 '=ORDER_ID' => $shipmentData['ORDER_ID']
1881 )
1882 ));
1883
1884 while ($data = $dbRes->fetch())
1885 {
1886 $data['PAYMENT_TYPES'] = array(
1887 array(
1888 'CODE' => Sale\Cashbox\Check::PAYMENT_TYPE_ADVANCE,
1889 'NAME' => Loc::getMessage('SALE_CASHBOX_CHECK_ADVANCE'),
1890 ),
1891 array(
1892 'CODE' => Sale\Cashbox\Check::PAYMENT_TYPE_CREDIT,
1893 'NAME' => Loc::getMessage('SALE_CASHBOX_CHECK_CREDIT'),
1894 )
1895 );
1896
1897 $result['PAYMENTS'][$data['ID']] = $data;
1898 }
1899 }
1900
1901 return $result;
1902 }
1903
1910 public static function getPaymentByCheck(Check $check): ?Sale\Payment
1911 {
1912 $payment = null;
1913
1914 $entities = $check->getEntities();
1915 foreach ($entities as $entity)
1916 {
1917 if ($entity instanceof Sale\Payment)
1918 {
1919 $payment = $entity;
1920 }
1921 }
1922
1923 if (!$payment)
1924 {
1925 $relatedEntities = $check->getRelatedEntities();
1926 foreach ($relatedEntities as $relatedEntityCollection)
1927 {
1928 foreach ($relatedEntityCollection as $relatedEntity)
1929 {
1930 if ($relatedEntity instanceof Sale\Payment)
1931 {
1932 $payment = $relatedEntity;
1933 }
1934 }
1935 }
1936 }
1937
1938 return $payment;
1939 }
1940}
$con
Определения admin_tab.php:7
$type
Определения options.php:106
Определения error.php:15
Определения event.php:5
create()
Определения directoryentry.php:12
static registerAutoLoadClasses($moduleName, array $classes)
Определения loader.php:273
const SUPPORTED_ENTITY_TYPE_ALL
Определения abstractcheck.php:45
const SUPPORTED_ENTITY_TYPE_SHIPMENT
Определения abstractcheck.php:44
static create($handler)
Определения abstractcheck.php:93
const SUPPORTED_ENTITY_TYPE_PAYMENT
Определения abstractcheck.php:43
const PAYMENT_TYPE_CASHLESS
Определения abstractcheck.php:40
static getLastPrintableCheckInfo(Sale\Internals\CollectableEntity $entity)
Определения checkmanager.php:1589
static getCheckInfoByExternalUuid($uuid)
Определения checkmanager.php:1685
const EVENT_ON_CHECK_PRINT_SEND
Определения checkmanager.php:29
const EVENT_ON_GET_CUSTOM_CHECK
Определения checkmanager.php:28
const EVENT_ON_CHECK_PRINT_ERROR
Определения checkmanager.php:31
static getCheckInfo(Sale\Internals\CollectableEntity $entity)
Определения checkmanager.php:1562
static getPaymentByCheck(Check $check)
Определения checkmanager.php:1910
static getList(array $parameters=array())
Определения checkmanager.php:1722
const EVENT_ON_BEFORE_CHECK_ADD_VERIFY
Определения checkmanager.php:30
static createByType($type)
Определения checkmanager.php:950
static getCheckList()
Определения checkmanager.php:899
const EVENT_ON_CHECK_COLLATE_DOCUMENTS
Определения checkmanager.php:32
const CHECK_RESENDING_TIME
Определения checkmanager.php:37
const EVENT_ON_CHECK_VALIDATION_ERROR
Определения checkmanager.php:33
const MIN_TIME_FOR_SWITCH_CASHBOX
Определения checkmanager.php:34
static create(array $settings)
Определения checkmanager.php:1547
static isAvailableCorrection()
Определения checkmanager.php:374
static getSalesCheckList()
Определения checkmanager.php:913
static getObjectById($id)
Определения checkmanager.php:1698
const CHECK_LIMIT_RECORDS
Определения checkmanager.php:38
static getType()
Определения creditcheck.php:20
static addWarning(?string $message, $cashboxId=null)
Определения logger.php:34
static addError(?string $message, $cashboxId=null)
Определения logger.php:25
static getAvailableCashboxList(Check $check)
Определения manager.php:85
static getListFromCache()
Определения manager.php:243
static isEnabledPaySystemPrint()
Определения manager.php:468
static getCashboxFromCache($cashboxId)
Определения manager.php:268
static getObjectById($id)
Определения manager.php:165
static chooseCashbox($cashboxList)
Определения manager.php:198
static getType()
Определения sellcheck.php:19
const EVENT_ON_CHECK_PRINT_ERROR
Определения eventactions.php:57
const EVENT_ON_CHECK_VALIDATION_ERROR
Определения eventactions.php:59
const EVENT_ON_CHECK_PRINT
Определения eventactions.php:55
Определения payment.php:19
static getInstance($type)
Определения registry.php:183
const REGISTRY_TYPE_ORDER
Определения registry.php:16
global $CACHE_MANAGER
Определения clear_component_cache.php:7
$data['IS_AVAILABLE']
Определения .description.php:13
</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
$entity
$filter
Определения iblock_catalog_list.php:54
while($arParentIBlockProperty=$dbParentIBlockProperty->Fetch()) $errorMessage
AddEventToStatFile($module, $action, $tag, $label, $action_type='', $user_id=null)
Определения tools.php:3976
$map
Определения config.php:5
getType()
Определения Param.php:116
Order
Определения order.php:6
Определения collection.php:2
trait Error
Определения error.php:11
trait Warning
Определения warning.php:11
$payment
Определения payment.php:14
$order
Определения payment.php:8
$paymentCollection
Определения payment.php:11
$service
Определения payment.php:18
$settings
Определения product_settings.php:43
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
$i
Определения factura.php:643
</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
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
const CACHED_b_sale_order
Определения include.php:33
$option
Определения options.php:1711
$error
Определения subscription_card_product.php:20
$dbRes
Определения yandex_detail.php:168
$fields
Определения yandex_run.php:501