Bitrix-D7  20.5.0
checkmanager.php
См. документацию.
1 <?php
2 
3 namespace Bitrix\Sale\Cashbox;
4 
11 use Bitrix\Main;
14 use Bitrix\Sale;
16 
17 Loc::loadLanguageFile(__FILE__);
18 
19 /**
20  * Class CheckManager
21  * @package Bitrix\Sale\Cashbox
22  */
23 final class CheckManager
24 {
25  const EVENT_ON_GET_CUSTOM_CHECK = 'OnGetCustomCheckList';
26  const EVENT_ON_CHECK_PRINT_SEND = 'OnPrintableCheckSend';
27  const EVENT_ON_BEFORE_CHECK_ADD_VERIFY = 'OnBeforeCheckAddVerify';
28  const EVENT_ON_CHECK_PRINT_ERROR = 'OnCheckPrintError';
30 
31  /** This is time re-sending a check print in minutes */
34 
35  /**
36  * @param CollectableEntity[] $entities
37  * @param $type
38  * @param CollectableEntity[] $relatedEntities
39  * @return Result
40  */
41  public static function addByType(array $entities, $type, array $relatedEntities = array())
42  {
43  $result = new Result();
44 
45  if ($type === '')
46  {
47  $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_EMPTY_CHECK_TYPE')));
48  return $result;
49  }
50 
51  $check = static::createByType($type);
52  if (!$check instanceof Check)
53  {
54  $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_CHECK')));
55  return $result;
56  }
57 
58  $cashboxList = array();
59  $firstIteration = true;
60  foreach ($entities as $entity)
61  {
62  $items = Manager::getListWithRestrictions($entity);
63  if ($firstIteration)
64  {
65  $cashboxList = $items;
66  $firstIteration = false;
67  }
68  else
69  {
70  $cashboxList = array_intersect_assoc($items, $cashboxList);
71  }
72  }
73 
74  $entity = reset($entities);
75  $order = static::getOrder($entity);
76 
77  if (!$cashboxList)
78  {
79  $dbRes = CashboxTable::getList(array('filter' => array('ACTIVE' => 'Y')));
80  if ($dbRes->fetch())
81  $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_NOT_FOUND')));
82 
83  return $result;
84  }
85 
86  $check->setEntities($entities);
87  $check->setRelatedEntities($relatedEntities);
88  $check->setAvailableCashbox($cashboxList);
89 
90  $validateResult = $check->validate();
91  if (!$validateResult->isSuccess())
92  {
93  $result->addErrors($validateResult->getErrors());
94  return $result;
95  }
96 
97  $saveResult = $check->save();
98  if ($saveResult->isSuccess())
99  {
100  $checkId = $saveResult->getId();
101  $order->addPrintedCheck($check);
102 
103  $enabledImmediateCashboxList = array();
104  foreach ($cashboxList as $item)
105  {
106  if ($item['ENABLED'] === 'Y')
107  {
108  $cashbox = Cashbox::create($item);
109  if ($cashbox instanceof IPrintImmediately)
110  {
111  $enabledImmediateCashboxList[$item['ID']] = $cashbox;
112  }
113  }
114  }
115 
116  if ($enabledImmediateCashboxList)
117  {
118  $cashboxId = Manager::chooseCashbox(array_keys($enabledImmediateCashboxList));
119  /** @var Cashbox|IPrintImmediately $cashbox */
120  $cashbox = $enabledImmediateCashboxList[$cashboxId];
121 
123  $checkId,
124  array(
125  'STATUS' => 'P',
126  'DATE_PRINT_START' => new Type\DateTime(),
127  'CASHBOX_ID' => $cashbox->getField('ID')
128  )
129  );
130 
131  $printResult = $cashbox->printImmediately($check);
132  if ($printResult->isSuccess())
133  {
134  $data = $printResult->getData();
135  CashboxCheckTable::update($checkId, ['EXTERNAL_UUID' => $data['UUID']]);
136  }
137  else
138  {
139  static::savePrintResult(
140  $checkId,
141  [
142  'ID' => $checkId,
143  'ERROR' => [
144  'TYPE' => Errors\Error::TYPE,
145  'MESSAGE' => implode("\n", $printResult->getErrorMessages())
146  ]
147  ]
148  );
149  }
150 
151  $result->setId($checkId);
152 
153  return $result;
154  }
155 
156  global $CACHE_MANAGER;
157  foreach ($cashboxList as $cashbox)
158  {
159  $CACHE_MANAGER->Read(CACHED_b_sale_order, 'sale_checks_'.$cashbox['ID']);
160  $CACHE_MANAGER->SetImmediate('sale_checks_'.$cashbox['ID'], true);
161  }
162  }
163  else
164  {
165  $result->addErrors($saveResult->getErrors());
166  }
167 
168  return $result;
169  }
170 
171  /**
172  * @return bool
173  */
174  public static function isAvailableCorrection() : bool
175  {
176  foreach (Manager::getListFromCache() as $item)
177  {
178  if ($item['ACTIVE'] !== 'Y')
179  {
180  continue;
181  }
182 
183  $cashbox = Manager::getObjectById($item['ID']);
184  if ($cashbox instanceof ICorrection)
185  {
186  return true;
187  }
188  }
189 
190  return false;
191  }
192 
193  public static function addCorrection($type, $cashboxId, array $correction)
194  {
195  $result = new Result();
196 
197  if (!self::isAvailableCorrection())
198  {
199  return $result->addError(
200  new Error(
201  Loc::getMessage('SALE_CASHBOX_CHECK_CORRECTION_NOT_AVAILABLE')
202  )
203  );
204  }
205 
206  /** @var CorrectionCheck $check */
207  $check = static::createByType($type);
208  if (!$check instanceof CorrectionCheck)
209  {
210  $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_CHECK')));
211  return $result;
212  }
213 
214  $check->setField('CASHBOX_ID', $cashboxId);
215  $check->setAvailableCashbox([
216  Manager::getCashboxFromCache($cashboxId)
217  ]);
218 
219  $check->setCorrectionFields($correction);
220 
221  $r = $check->save();
222  if ($r->isSuccess())
223  {
224  $result->setId($check->getField('ID'));
225 
226  $cashbox = Manager::getObjectById($cashboxId);
227  if ($cashbox instanceof ICorrection)
228  {
230  $check->getField('ID'),
231  [
232  'STATUS' => 'P', 'DATE_PRINT_START' => new Type\DateTime()
233  ]
234  );
235 
236  $printResult = $cashbox->printCorrectionImmediately($check);
237  if ($printResult->isSuccess())
238  {
239  $data = $printResult->getData();
240  CashboxCheckTable::update($check->getField('ID'), ['EXTERNAL_UUID' => $data['UUID']]);
241  }
242  else
243  {
244  static::savePrintResult(
245  $check->getField('ID'),
246  [
247  'ID' => $check->getField('ID'),
248  'ERROR' => [
249  'TYPE' => Errors\Error::TYPE,
250  'MESSAGE' => implode("\n", $printResult->getErrorMessages())
251  ]
252  ]
253  );
254  }
255 
256  global $CACHE_MANAGER;
257  $CACHE_MANAGER->Read(CACHED_b_sale_order, 'sale_checks_'.$cashboxId);
258  $CACHE_MANAGER->SetImmediate('sale_checks_'.$cashboxId, true);
259  }
260  }
261  else
262  {
263  $result->addErrors($r->getErrors());
264  }
265 
266  return $result;
267  }
268 
269  /**
270  * @param $checkId
271  * @param array $data
272  * @return Result
273  * @throws Main\ArgumentException
274  * @throws Main\ArgumentNullException
275  * @throws Main\ArgumentOutOfRangeException
276  * @throws Main\NotImplementedException
277  * @throws Main\ObjectException
278  * @throws \Exception
279  */
280  public static function savePrintResult($checkId, array $data)
281  {
282  $result = new Result();
283 
284  if ($checkId <= 0)
285  {
286  $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_CHECK_ID')));
287  return $result;
288  }
289 
290  $order = null;
291  $payment = null;
292  $shipment = null;
293 
294  $dbRes = static::getList(array('select' => array('*'), 'filter' => array('ID' => $checkId)));
295  $check = $dbRes->fetch();
296  if (!$check)
297  {
298  $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_CHECK_NOT_FOUND', array('#CHECK_ID#' => $checkId))));
299  return $result;
300  }
301 
302  if ($check['STATUS'] === 'Y')
303  return $result;
304 
305  $registry = Sale\Registry::getInstance($check['ENTITY_REGISTRY_TYPE']);
306 
307  if ($check['ORDER_ID'] > 0)
308  {
309  /** @var Sale\Order $orderClassName */
310  $orderClassName = $registry->getOrderClassName();
311  $order = $orderClassName::load($check['ORDER_ID']);
312  if ($order === null)
313  {
314  $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_CHECK_ORDER_LOAD')));
315  return $result;
316  }
317 
318  $paymentCollection = $order->getPaymentCollection();
319  if ($check['PAYMENT_ID'] > 0)
320  {
321  $payment = $paymentCollection->getItemById($check['PAYMENT_ID']);
322  if ($payment === null)
323  {
324  $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_CHECK_PAYMENT_LOAD')));
325  return $result;
326  }
327  }
328 
329  $shipmentCollection = $order->getShipmentCollection();
330  if ($check['SHIPMENT_ID'] > 0)
331  {
332  $shipment = $shipmentCollection->getItemById($check['SHIPMENT_ID']);
333  if ($shipment === null)
334  {
335  $result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_CHECK_SHIPMENT_LOAD')));
336  return $result;
337  }
338  }
339  }
340 
341  if (isset($data['ERROR']))
342  {
343  $errorMessage = Loc::getMessage('SALE_CASHBOX_ERROR_CHECK_PRINT', array('#CHECK_ID#' => $checkId));
344  if ($data['ERROR']['MESSAGE'])
345  $errorMessage .= ': '.$data['ERROR']['MESSAGE'];
346 
347  if ($data['ERROR']['TYPE'] === Errors\Warning::TYPE)
348  {
349  if ($check['CNT_FAIL_PRINT'] >= 3)
350  {
351  $data['ERROR']['TYPE'] = Errors\Error::TYPE;
352  }
353  else
354  {
355  CashboxCheckTable::update($checkId, array('CNT_FAIL_PRINT' => $check['CNT_FAIL_PRINT'] + 1));
356  $result->addError(new Errors\Warning($errorMessage));
357  return $result;
358  }
359  }
360 
361  if ($data['ERROR']['TYPE'] === Errors\Error::TYPE)
362  {
363  $updatedFields = array('STATUS' => 'E', 'DATE_PRINT_END' => new Main\Type\DateTime());
364  if ((int)$check['CNT_FAIL_PRINT'] === 0)
365  $updatedFields['CNT_FAIL_PRINT'] = 1;
366 
367  CashboxCheckTable::update($checkId, $updatedFields);
368 
369  /** @ToDO Will be removed after OrderCheckCollection is realized */
370  if (
371  class_exists('\Bitrix\Crm\Order\Order')
372  && $order instanceof \Bitrix\Crm\Order\Order
373  && $order->getDealBinding()
374  )
375  {
376  $order->addTimelineCheckEntryOnCreate($checkId, ['PRINTED' => 'N']);
377  }
378 
379  if ($order !== null
380  && (
381  $payment !== null
382  || $shipment !== null
383  )
384  )
385  {
386  $r = new Result();
387  $errorCode = isset($data['ERROR']['CODE']) ? $data['ERROR']['CODE'] : 0;
388  $r->addWarning(new Main\Error($errorMessage, $errorCode));
389 
390  /** @var EntityMarker $markerClassName */
391  $markerClassName = $registry->getEntityMarkerClassName();
392 
393  if ($payment !== null)
394  {
395  $markerClassName::addMarker($order, $payment, $r);
396  $payment->setField('MARKED', 'Y');
397 
398  /** @var Sale\Notify $notifyClassName */
399  $notifyClassName = $registry->getNotifyClassName();
400  $notifyClassName::callNotify($payment, Sale\EventActions::EVENT_ON_CHECK_PRINT_ERROR);
401  }
402  elseif ($shipment !== null)
403  {
404  $markerClassName::addMarker($order, $shipment, $r);
405  $shipment->setField('MARKED', 'Y');
406 
407  /** @var Sale\Notify $notifyClassName */
408  $notifyClassName = $registry->getNotifyClassName();
409  $notifyClassName::callNotify($shipment, Sale\EventActions::EVENT_ON_CHECK_PRINT_ERROR);
410  }
411 
412  $order->save();
413  }
414 
415  $error = new Errors\Error($errorMessage);
416  Logger::addError($error->getMessage(), $check['CASHBOX_ID']);
417  }
418  else
419  {
420  $error = new Errors\Warning($errorMessage);
421  Logger::addWarning($error->getMessage(), $check['CASHBOX_ID']);
422  }
423 
424  $event = new Main\Event('sale', static::EVENT_ON_CHECK_PRINT_ERROR, array($data));
425  $event->send();
426 
427  $result->addError($error);
428  }
429  else
430  {
431  $updateResult = CashboxCheckTable::update(
432  $checkId,
433  array(
434  'STATUS' => 'Y',
435  'LINK_PARAMS' => $data['LINK_PARAMS'],
436  'DATE_PRINT_END' => new Main\Type\DateTime()
437  )
438  );
439 
440  if ($updateResult->isSuccess())
441  {
442  self::addStatisticOnSuccessCheckPrint($checkId);
443 
444  /** @ToDO Will be removed after OrderCheckCollection is realized */
445  if (
446  class_exists('\Bitrix\Crm\Order\Order')
447  && $order instanceof \Bitrix\Crm\Order\Order
448  && $order->getDealBinding()
449  )
450  {
451  $order->addTimelineCheckEntryOnCreate($checkId, ['PRINTED' => 'Y']);
452  }
453 
454  $isSend = false;
455  $event = new Main\Event(
456  'sale',
457  static::EVENT_ON_CHECK_PRINT_SEND,
458  array('PAYMENT' => $payment, 'SHIPMENT' => $shipment, 'CHECK' => $check)
459  );
460  $event->send();
461 
462  $eventResults = $event->getResults();
463  /** @var Main\EventResult $eventResult */
464  foreach($eventResults as $eventResult)
465  {
466  if($eventResult->getType() == Main\EventResult::SUCCESS)
467  $isSend = true;
468  }
469 
470  if (!$isSend)
471  {
472  if ($payment !== null)
473  {
474  /** @var Sale\Notify $notifyClassName */
475  $notifyClassName = $registry->getNotifyClassName();
476  $notifyClassName::callNotify($payment, Sale\EventActions::EVENT_ON_CHECK_PRINT);
477  }
478  elseif ($shipment !== null)
479  {
480  /** @var Sale\Notify $notifyClassName */
481  $notifyClassName = $registry->getNotifyClassName();
482  $notifyClassName::callNotify($shipment, Sale\EventActions::EVENT_ON_CHECK_PRINT);
483  }
484  }
485  }
486  else
487  {
488  $result->addErrors($updateResult->getErrors());
489  }
490  }
491 
492  return $result;
493  }
494 
495  private static function addStatisticOnSuccessCheckPrint($checkId)
496  {
497  $check = self::getObjectById($checkId);
498 
499  $cashbox = Manager::getObjectById($check->getField('CASHBOX_ID'));
500  if ($cashbox)
501  {
502  AddEventToStatFile('sale', 'checkPrint', $checkId, $cashbox::getCode());
503  }
504  }
505 
506  /**
507  * @param $id
508  * @throws Main\ArgumentException
509  * @throws Main\ObjectPropertyException
510  * @throws Main\SystemException
511  */
512  public static function delete($id)
513  {
514  $r = CashboxCheckTable::delete($id);
515  if ($r->isSuccess())
516  {
518  ->addSelect('ID')
519  ->where('CHECK_ID', $id);
520 
521  while ($link = $dbRes->fetchObject())
522  {
523  $link->delete();
524  }
525  }
526  }
527 
528  /**
529  * @param CollectableEntity[] $entities
530  * @return Result
531  */
532  public static function addChecks(array $entities)
533  {
534  $result = new Result();
535 
536  $map = static::collateDocuments($entities);
537  foreach ($map as $check)
538  {
539  $isCorrect = true;
540 
541  $event = new Main\Event('sale', static::EVENT_ON_BEFORE_CHECK_ADD_VERIFY, array($check));
542  $event->send();
543 
544  if ($event->getResults())
545  {
546  /** @var Main\EventResult $eventResult */
547  foreach ($event->getResults() as $eventResult)
548  {
549  if ($eventResult->getType() !== Main\EventResult::ERROR)
550  {
551  $isCorrect = (bool)$eventResult->getParameters();
552  }
553  }
554  }
555 
556  if ($isCorrect)
557  {
558  $addResult = static::addByType($check["ENTITIES"], $check["TYPE"], $check["RELATED_ENTITIES"]);
559  if (!$addResult->isSuccess())
560  $result->addErrors($addResult->getErrors());
561  }
562  }
563 
564  return $result;
565  }
566 
567  /**
568  * @param Sale\Internals\CollectableEntity $entity
569  * @throws Main\ArgumentTypeException
570  * @return Sale\Order
571  */
572  public static function getOrder($entity)
573  {
574  $order = null;
575 
576  if ($entity instanceof Sale\Payment)
577  {
578  /** @var Sale\PaymentCollection $col */
579  $col = $entity->getCollection();
580  $order = $col->getOrder();
581  }
582  elseif ($entity instanceof Sale\Shipment)
583  {
584  /** @var Sale\ShipmentCollection $col */
585  $col = $entity->getCollection();
586  $order = $col->getOrder();
587  }
588  else
589  {
590  throw new Main\ArgumentTypeException("entities");
591  }
592 
593  return $order;
594  }
595 
596  /**
597  * @return array
598  */
599  private static function getBuildInCheckList()
600  {
601  $checkList = array(
602  '\Bitrix\Sale\Cashbox\SellCheck',
603  '\Bitrix\Sale\Cashbox\SellReturnCashCheck',
604  '\Bitrix\Sale\Cashbox\SellReturnCheck'
605  );
606 
608  {
609  $checkList = array_merge(
610  $checkList,
611  array(
612  '\Bitrix\Sale\Cashbox\CorrectionSellCheck',
613  '\Bitrix\Sale\Cashbox\CorrectionBuyCheck',
614  '\Bitrix\Sale\Cashbox\AdvancePaymentCheck',
615  '\Bitrix\Sale\Cashbox\AdvanceReturnCheck',
616  '\Bitrix\Sale\Cashbox\AdvanceReturnCashCheck',
617  '\Bitrix\Sale\Cashbox\CreditPaymentCheck',
618  '\Bitrix\Sale\Cashbox\CreditPaymentReturnCheck',
619  '\Bitrix\Sale\Cashbox\CreditPaymentReturnCashCheck',
620  '\Bitrix\Sale\Cashbox\CreditCheck',
621  '\Bitrix\Sale\Cashbox\CreditReturnCheck',
622  '\Bitrix\Sale\Cashbox\PrepaymentCheck',
623  '\Bitrix\Sale\Cashbox\PrepaymentReturnCheck',
624  '\Bitrix\Sale\Cashbox\PrepaymentReturnCashCheck',
625  '\Bitrix\Sale\Cashbox\FullPrepaymentCheck',
626  '\Bitrix\Sale\Cashbox\FullPrepaymentReturnCheck',
627  '\Bitrix\Sale\Cashbox\FullPrepaymentReturnCashCheck',
628  )
629  );
630  }
631 
632  return $checkList;
633  }
634 
635  /**
636  * @return array
637  */
638  private static function getUserCheckList()
639  {
640  $checkList = array();
641 
642  $event = new Main\Event('sale', static::EVENT_ON_GET_CUSTOM_CHECK);
643  $event->send();
644  $resultList = $event->getResults();
645 
646  if (is_array($resultList) && !empty($resultList))
647  {
648  foreach ($resultList as $eventResult)
649  {
650  /** @var Main\EventResult $eventResult */
651  if ($eventResult->getType() === Main\EventResult::SUCCESS)
652  {
653  $params = $eventResult->getParameters();
654  if (!empty($params) && is_array($params))
655  $checkList = array_merge($checkList, $params);
656  }
657  }
658  }
659 
660  return $checkList;
661  }
662 
663  /**
664  * @return void
665  */
666  public static function init()
667  {
668  static $isInit = false;
669 
670  if ($isInit === false)
671  {
672  $handlers = static::getUserCheckList();
673  Main\Loader::registerAutoLoadClasses(null, $handlers);
674  $isInit = true;
675  }
676  }
677 
678  /**
679  * @return array
680  */
681  public static function getCheckList()
682  {
683  static $checkList = array();
684  if (!$checkList)
685  {
686  $checkList = array_merge(
687  static::getBuildInCheckList(),
688  array_keys(static::getUserCheckList())
689  );
690  }
691 
692  return $checkList;
693  }
694 
695  public static function getSalesCheckList()
696  {
697  return array_filter(
698  self::getCheckList(),
699  function ($value)
700  {
701  return is_subclass_of($value, Check::class);
702  }
703  );
704  }
705 
706  /**
707  * @return array
708  */
709  public static function getCheckTypeMap()
710  {
711  static::init();
712 
713  $result = array();
714  $checkMap = static::getCheckList();
715 
716  /** @var Check $className */
717  foreach ($checkMap as $className)
718  {
719  if (class_exists($className))
720  {
721  $result[$className::getType()] = $className;
722  }
723  }
724 
725  return $result;
726  }
727 
728  /**
729  * @param string $type
730  * @return null|Check
731  */
732  public static function createByType($type)
733  {
734  static::init();
735 
736  $typeMap = static::getCheckTypeMap();
737  $handler = $typeMap[$type];
738 
739  return Check::create($handler);
740  }
741 
742  /**
743  * @param array $entities
744  * @return Entity[]
745  * @throws Main\NotSupportedException
746  */
747  public static function collateDocuments(array $entities)
748  {
749  $map = [];
750 
751  $event = new Main\Event('sale', 'OnCheckCollateDocuments', [
752  'ENTITIES' => $entities
753  ]);
754  $event->send();
755  $eventResults = $event->getResults();
756  if ($eventResults != null)
757  {
758  foreach ($eventResults as $eventResult)
759  {
760  if ($eventResult->getType() === Main\EventResult::SUCCESS)
761  {
762  $d = $eventResult->getParameters();
763  if (!is_array($d))
764  throw new Main\NotSupportedException("OnCheckCollateDocuments event result");
765 
766  $map = array_merge($map, $d);
767  }
768  else if ($eventResult->getType() === Main\EventResult::ERROR)
769  {
770  return $map;
771  }
772  }
773 
774  if (count($map) > 0)
775  {
776  return $map;
777  }
778  }
779 
780  $existingChecks = null;
781  $order = null;
782 
783  /** @var Sale\Payment|Sale\Shipment $entity */
784  foreach ($entities as $entity)
785  {
786  // load existing checks
787  if ($existingChecks === null)
788  {
789  $existingChecks = [];
790  $order = static::getOrder($entity);
791 
792  $filter = [
793  'ORDER_ID' => $order->getId(),
794  'ENTITY_REGISTRY_TYPE' => $entity::getRegistryType()
795  ];
796  if ($entity instanceof Sale\Payment)
797  {
798  $filter["PAYMENT_ID"] = $entity->getId();
799  }
800  elseif ($entity instanceof Sale\Shipment)
801  {
802  $filter["SHIPMENT_ID"] = $entity->getId();
803  }
804 
805  $db = static::getList([
806  "filter" => $filter,
807  "select" => ["ID", "PAYMENT_ID", "SHIPMENT_ID", "TYPE", "STATUS"]
808  ]);
809  while ($ar = $db->fetch())
810  {
811  if (intval($ar["PAYMENT_ID"]) > 0)
812  {
813  $existingChecks["P"][ $ar["PAYMENT_ID"] ][] = $ar;
814  }
815 
816  if (intval($ar["SHIPMENT_ID"]) > 0)
817  {
818  $existingChecks["S"][ $ar["SHIPMENT_ID"] ][] = $ar;
819  }
820  }
821  }
822 
823  // analysing
824  // we should allow users to implement their own algorithms
825  if (count($existingChecks) <= 0)
826  {
827  if (static::isAutomaticEnabled($order))
828  {
830  {
831  $result = static::collateWithFFD105($entity);
832  }
833  else
834  {
835  $result = static::collate($entity);
836  }
837 
838  if ($result)
839  {
840  $map = array_merge($map, $result);
841  }
842  }
843  }
844  }
845 
846  return $map;
847  }
848 
849  /**
850  * @param Sale\Order $order
851  * @return bool
852  * @throws Main\ArgumentException
853  * @throws Main\ArgumentNullException
854  */
855  private static function isAutomaticEnabled(Sale\Order $order)
856  {
857  $shipmentCollection = $order->getShipmentCollection();
858  if (
859  (
860  $shipmentCollection->count() > 2
861  && $shipmentCollection->isExistsSystemShipment()
862  )
863  ||
864  (
865  $shipmentCollection->count() > 1
866  && !$shipmentCollection->isExistsSystemShipment()
867  )
868  )
869  {
870  return false;
871  }
872 
873  $paymentCollection = $order->getPaymentCollection();
874  if (
875  (
876  $paymentCollection->isExistsInnerPayment()
877  && $paymentCollection->count() > 2
878  )
879  ||
880  (
881  !$paymentCollection->isExistsInnerPayment()
882  && $paymentCollection->count() > 1
883  )
884  )
885  {
886  return false;
887  }
888 
889  return true;
890  }
891 
892  /**
893  * @param $entity
894  * @return array
895  * @throws Main\ArgumentException
896  * @throws Main\ArgumentNullException
897  * @throws Main\ArgumentTypeException
898  */
899  private static function collate($entity)
900  {
901  $map = array();
902 
903  if ($entity instanceof Sale\Payment)
904  {
905  $order = static::getOrder($entity);
906 
907  /** @var Sale\PaySystem\Service $service */
908  $service = $entity->getPaySystem();
909  if ($entity->isPaid() &&
910  ($service->getField("CAN_PRINT_CHECK") == "Y") &&
911  ($entity->getSum() == $order->getPrice())
912  )
913  {
914  $checkEntities[] = $entity;
915 
916  $shipmentCollection = $order->getShipmentCollection();
917  /** @var Sale\Shipment $shipment */
918  foreach ($shipmentCollection as $shipment)
919  {
920  if (!$shipment->isSystem())
921  $checkEntities[] = $shipment;
922  }
923 
924  $map[] = array("TYPE" => SellCheck::getType(), "ENTITIES" => $checkEntities, "RELATED_ENTITIES" => array());
925  }
926  }
927 
928  return $map;
929  }
930 
931  /**
932  * @param $entity
933  * @return array
934  * @throws Main\ArgumentNullException
935  * @throws Main\ArgumentOutOfRangeException
936  * @throws Main\ArgumentTypeException
937  * @throws Main\NotSupportedException
938  * @throws Main\ObjectNotFoundException
939  */
940  private static function collateWithFFD105($entity)
941  {
942  $map = array();
943 
944  $order = static::getOrder($entity);
945  if (!static::canPrintCheck($order))
946  {
947  return $map;
948  }
949 
950  $entities = array();
951  $relatedEntities = array();
952  if ($entity instanceof Sale\Payment)
953  {
954  if ($entity->isInner() || !$entity->isPaid())
955  return $map;
956 
957  $service = $entity->getPaySystem();
958  $type = $service->getField('IS_CASH') === 'Y' ? Check::PAYMENT_TYPE_CASHLESS : Check::PAYMENT_TYPE_CASH;
959  $entities[$type] = $entity;
960 
961  $fields = $order->getFields();
962  $originalFields = $fields->getOriginalValues();
963  if (!isset($originalFields['DEDUCTED']))
964  $originalFields['DEDUCTED'] = $order->getField('DEDUCTED');
965 
966  $paymentCollection = $order->getPaymentCollection();
967  if ($order->getField('DEDUCTED') === 'Y' && $originalFields['DEDUCTED'] === 'Y')
968  {
969  if ($paymentCollection->isExistsInnerPayment())
970  {
971  $relatedEntities[Check::PAYMENT_TYPE_ADVANCE][] = $paymentCollection->getInnerPayment();
972  }
973 
974  $shipmentCollection = $order->getShipmentCollection();
975  /** @var Sale\Shipment $shipment */
976  foreach ($shipmentCollection as $shipment)
977  {
978  if (!$shipment->isSystem())
979  {
980  $relatedEntities[Check::SHIPMENT_TYPE_NONE][] = $shipment;
981  }
982  }
983 
984  $map[] = array("TYPE" => CreditPaymentCheck::getType(), "ENTITIES" => $entities, "RELATED_ENTITIES" => $relatedEntities);
985  }
986  else
987  {
988  $option = Main\Config\Option::get('sale', 'check_type_on_pay', 'sell');
989  if ($option === 'prepayment')
990  {
991  $checkType = ($entity->getSum() == $entity->getOrder()->getPrice()) ? FullPrepaymentCheck::getType() : PrepaymentCheck::getType();
992 
993  $shipmentCollection = $order->getShipmentCollection()->getNotSystemItems();
994  /** @var Sale\Shipment $shipment */
995  foreach ($shipmentCollection as $shipment)
996  {
997  $relatedEntities[Check::SHIPMENT_TYPE_NONE][] = $shipment;
998  }
999 
1000  $map[] = array("TYPE" => $checkType, "ENTITIES" => $entities, "RELATED_ENTITIES" => $relatedEntities);
1001  }
1002  elseif ($option === 'advance')
1003  {
1004  $map[] = array("TYPE" => AdvancePaymentCheck::getType(), "ENTITIES" => $entities, "RELATED_ENTITIES" => $relatedEntities);
1005  }
1006  else
1007  {
1008  if ($paymentCollection->isExistsInnerPayment())
1009  {
1010  $map[] = array("TYPE" => AdvancePaymentCheck::getType(), "ENTITIES" => $entities, "RELATED_ENTITIES" => $relatedEntities);
1011  }
1012  else
1013  {
1014  $shipmentCollection = $order->getShipmentCollection()->getNotSystemItems();
1015  /** @var Sale\Shipment $shipment */
1016  foreach ($shipmentCollection as $shipment)
1017  {
1018  $relatedEntities[Check::SHIPMENT_TYPE_NONE][] = $shipment;
1019  }
1020 
1021  $map[] = array("TYPE" => SellCheck::getType(), "ENTITIES" => $entities, "RELATED_ENTITIES" => $relatedEntities);
1022  }
1023  }
1024  }
1025  }
1026  elseif ($entity instanceof Sale\Shipment)
1027  {
1028  if ($entity->getField('DEDUCTED') !== 'Y')
1029  return $map;
1030 
1031  $entities[] = $entity;
1032  if ($order->isPaid())
1033  {
1034  if (Main\Config\Option::get('sale', 'check_type_on_pay', 'sell') === 'sell')
1035  {
1036  return $map;
1037  }
1038 
1039  $paymentCollection = $order->getPaymentCollection();
1040  foreach ($paymentCollection as $payment)
1041  {
1042  $relatedEntities[Check::PAYMENT_TYPE_ADVANCE][] = $payment;
1043  }
1044 
1045  $map[] = array("TYPE" => SellCheck::getType(), "ENTITIES" => $entities, "RELATED_ENTITIES" => $relatedEntities);
1046  }
1047  else
1048  {
1049  $map[] = array("TYPE" => CreditCheck::getType(), "ENTITIES" => $entities, "RELATED_ENTITIES" => $relatedEntities);
1050  }
1051  }
1052  else
1053  {
1054  throw new Main\NotSupportedException();
1055  }
1056 
1057  return $map;
1058  }
1059 
1060  /**
1061  * @param Sale\Order $order
1062  * @return bool
1063  */
1064  private static function canPrintCheck(Sale\Order $order)
1065  {
1066  $paymentCollection = $order->getPaymentCollection();
1067  if ($paymentCollection->isEmpty())
1068  {
1069  return false;
1070  }
1071 
1072  /** @var Sale\Payment $payment */
1073  foreach ($paymentCollection as $payment)
1074  {
1075  if ($payment->isInner())
1076  continue;
1077 
1078  $service = $payment->getPaySystem();
1079  if ($service === null
1080  || $service->getField("CAN_PRINT_CHECK") !== 'Y'
1081  )
1082  {
1083  return false;
1084  }
1085  }
1086 
1087  return true;
1088  }
1089 
1090  /**
1091  * @param array $cashboxIds
1092  * @param array $orderIds
1093  * @return array
1094  * @throws Main\ArgumentException
1095  * @throws Main\Db\SqlQueryException
1096  * @throws Main\ObjectException
1097  * @throws Main\SystemException
1098  * @throws \Exception
1099  */
1100  public static function getPrintableChecks(array $cashboxIds, array $orderIds = array())
1101  {
1102  $result = array();
1103 
1105  $dbLocRes = $con->query("SELECT GET_LOCK('get_check_list', 0) as L");
1106  $locResult = $dbLocRes->fetch();
1107  if ($locResult["L"] == "0")
1108  {
1109  return $result;
1110  }
1111 
1112  $filter = array(
1113  'LINK_PARAMS' => '',
1114  'CHECK2CASHBOX.CASHBOX_ID' => $cashboxIds,
1115  array(
1116  'LOGIC' => 'OR',
1117  array(
1118  '=STATUS' => 'N',
1119  'DATE_PRINT_START' => ''
1120  ),
1121  array(
1122  '=STATUS' => 'P',
1123  '<MAX_DT_REPEAT_CHECK' => new Type\DateTime()
1124  )
1125  )
1126  );
1127 
1128  if ($orderIds)
1129  {
1130  $filter['ORDER_ID'] = $orderIds;
1131  }
1132 
1133  $limit = count($cashboxIds)*static::CHECK_LIMIT_RECORDS;
1134  $dbRes = static::getList(
1135  array(
1136  'select' => array('*', 'AVAILABLE_CASHBOX_ID' => 'CHECK2CASHBOX.CASHBOX_ID'),
1137  'filter' => $filter,
1138  'limit' => $limit,
1139  'runtime' => array(
1140  new Main\Entity\ExpressionField(
1141  'MAX_DT_REPEAT_CHECK',
1142  'DATE_ADD(DATE_PRINT_START, INTERVAL '.static::CHECK_RESENDING_TIME.' MINUTE)',
1143  null,
1144  array(
1145  'data_type' => 'datetime'
1146  )
1147  )
1148  )
1149  )
1150  );
1151 
1152  if ($data = $dbRes->fetch())
1153  {
1154  $i = 0;
1155  do
1156  {
1157  if (!isset($result[$data['ID']]))
1158  {
1159  $i++;
1160  if ($i > static::CHECK_LIMIT_RECORDS)
1161  break;
1162 
1163  $result[$data['ID']] = $data;
1164  $result[$data['ID']]['CASHBOX_LIST'] = array();
1165  }
1166 
1167  $result[$data['ID']]['CASHBOX_LIST'][] = $data['AVAILABLE_CASHBOX_ID'];
1168  }
1169  while ($data = $dbRes->fetch());
1170 
1171  foreach ($result as $checkId => $item)
1172  {
1173  if ($item['STATUS'] === 'P')
1174  {
1175  $now = new Type\DateTime();
1176  $nowTs = $now->getTimestamp();
1177 
1178  /** @var Type\DateTime $dateStartPrint */
1179  $dateStartPrint = $item['DATE_PRINT_START'];
1180  $dateStartPrintTs = $dateStartPrint->getTimestamp();
1181 
1182  if ($nowTs - $dateStartPrintTs > static::MIN_TIME_FOR_SWITCH_CASHBOX)
1183  {
1184  $availableCashboxIds = array_diff($item['CASHBOX_LIST'], array($item['CASHBOX_ID']));
1185  if ($availableCashboxIds)
1186  {
1187  $result[$checkId]['CASHBOX_ID'] = Manager::chooseCashbox($availableCashboxIds);
1188  CashboxCheckTable::update($checkId, array('CASHBOX_ID' => $result[$checkId]['CASHBOX_ID']));
1189  }
1190  }
1191  else
1192  {
1193  if ($item['CASHBOX_ID'] > 0 && !in_array($item['CASHBOX_ID'], $cashboxIds))
1194  unset($result[$checkId]);
1195  }
1196 
1197  continue;
1198  }
1199 
1200  $result[$checkId]['CASHBOX_ID'] = Manager::chooseCashbox($item['CASHBOX_LIST']);
1201  CashboxCheckTable::update($checkId, array('STATUS' => 'P', 'DATE_PRINT_START' => new Type\DateTime(), 'CASHBOX_ID' => $result[$checkId]['CASHBOX_ID']));
1202  }
1203  }
1204 
1205  $con->query("SELECT RELEASE_LOCK('get_check_list')");
1206 
1207  return $result;
1208  }
1209 
1210  /**
1211  * @param array $settings
1212  * @return Check|null
1213  */
1214  public static function create(array $settings)
1215  {
1216  $check = CheckManager::createByType($settings['TYPE']);
1217  if ($check)
1218  $check->init($settings);
1219 
1220  return $check;
1221  }
1222 
1223  /**
1224  * @param CollectableEntity $entity
1225  * @return array
1226  * @throws Main\ArgumentException
1227  * @throws Main\NotImplementedException
1228  */
1229  public static function getCheckInfo(Sale\Internals\CollectableEntity $entity)
1230  {
1231  $filter = array();
1232  if ($entity->getId() > 0)
1233  {
1234  if ($entity instanceof Sale\Payment)
1235  {
1236  $filter['ENTITY_REGISTRY_TYPE'] = $entity::getRegistryType();
1237  $filter['PAYMENT_ID'] = $entity->getId();
1238  }
1239  elseif ($entity instanceof Sale\Shipment)
1240  {
1241  $filter['ENTITY_REGISTRY_TYPE'] = $entity::getRegistryType();
1242  $filter['SHIPMENT_ID'] = $entity->getId();
1243  }
1244 
1245  return static::collectInfo($filter);
1246  }
1247 
1248  return array();
1249  }
1250 
1251  /**
1252  * @param CollectableEntity $entity
1253  * @return array|false
1254  * @throws Main\ArgumentException
1255  */
1256  public static function getLastPrintableCheckInfo(Sale\Internals\CollectableEntity $entity)
1257  {
1258  if (!($entity instanceof Sale\Payment)
1259  && !($entity instanceof Sale\Shipment)
1260  )
1261  {
1262  return array();
1263  }
1264 
1265  $filter = array(
1266  'STATUS' => 'Y',
1267  'ENTITY_REGISTRY_TYPE' => $entity::getRegistryType()
1268  );
1269  if ($entity instanceof Sale\Payment)
1270  {
1271  $filter['PAYMENT_ID'] = $entity->getId();
1272  }
1273  elseif ($entity instanceof Sale\Shipment)
1274  {
1275  $filter['SHIPMENT_ID'] = $entity->getId();
1276  }
1277 
1278  $dbRes = static::getList(
1279  array(
1280  'select' => array('*'),
1281  'filter' => $filter,
1282  'order' => array('DATE_PRINT_END' => 'DESC'),
1283  'limit' => 1
1284  )
1285  );
1286 
1287  if ($data = $dbRes->fetch())
1288  {
1289  $data['LINK'] = '';
1290  if (!empty($data['LINK_PARAMS']))
1291  {
1292  $cashbox = Manager::getObjectById($data['CASHBOX_ID']);
1293  if ($cashbox)
1294  $data['LINK'] = $cashbox->getCheckLink($data['LINK_PARAMS']);
1295  }
1296 
1297  return $data;
1298  }
1299 
1300  return array();
1301  }
1302 
1303  /**
1304  * @param array $filter
1305  * @return array
1306  * @throws Main\ArgumentException
1307  * @throws Main\NotImplementedException
1308  */
1309  public static function collectInfo(array $filter = array())
1310  {
1311  $result = array();
1312 
1313  $typeMap = CheckManager::getCheckTypeMap();
1314 
1315  $dbRes = static::getList(
1316  array(
1317  'select' => array('*'),
1318  'filter' => $filter
1319  )
1320  );
1321 
1322  while ($data = $dbRes->fetch())
1323  {
1324  $data['LINK'] = '';
1325  if (!empty($data['LINK_PARAMS']))
1326  {
1327  $cashbox = Manager::getObjectById($data['CASHBOX_ID']);
1328  if ($cashbox)
1329  {
1330  $data['LINK'] = $cashbox->getCheckLink($data['LINK_PARAMS']);
1331  }
1332  }
1333 
1334  /** @var Check $type */
1335  $type = $typeMap[$data['TYPE']];
1336  if (class_exists($type))
1337  {
1338  $data['TYPE_NAME'] = $type::getName();
1339  }
1340 
1341  $result[$data['ID']] = $data;
1342  }
1343 
1344  return $result;
1345  }
1346 
1347  /**
1348  * @param $uuid
1349  * @return array|false
1350  * @throws Main\ArgumentException
1351  */
1352  public static function getCheckInfoByExternalUuid($uuid)
1353  {
1354  $dbRes = static::getList(array('filter' => array('EXTERNAL_UUID' => $uuid)));
1355  return $dbRes->fetch();
1356  }
1357 
1358  /**
1359  * @param $id
1360  * @return Check|null
1361  * @throws Main\ArgumentException
1362  * @throws Main\ObjectPropertyException
1363  * @throws Main\SystemException
1364  */
1365  public static function getObjectById($id)
1366  {
1367  if ($id <= 0)
1368  return null;
1369 
1370  $dbRes = CashboxCheckTable::getById($id);
1371  if ($checkInfo = $dbRes->fetch())
1372  {
1373  $check = static::createByType($checkInfo['TYPE']);
1374  if ($check)
1375  {
1376  $check->init($checkInfo);
1377  return $check;
1378  }
1379  }
1380 
1381  return null;
1382  }
1383 
1384  /**
1385  * @param array $parameters
1386  * @return Main\DB\Result
1387  * @throws Main\ArgumentException
1388  */
1389  public static function getList(array $parameters = array())
1390  {
1391  return CashboxCheckTable::getList($parameters);
1392  }
1393 
1394  /**
1395  * @param $checkType
1396  * @param $paymentId
1397  * @param string $registryType
1398  * @return array
1399  * @throws Main\ArgumentException
1400  * @throws Main\ArgumentTypeException
1401  */
1402  public static function getRelatedEntitiesForPayment($checkType, $paymentId, $registryType = Sale\Registry::REGISTRY_TYPE_ORDER)
1403  {
1404  $result = array();
1405 
1406  $check = static::createByType($checkType);
1407  if ($check === null)
1408  {
1409  throw new Main\ArgumentTypeException($checkType);
1410  }
1411 
1412  $registry = Sale\Registry::getInstance($registryType);
1413  /** @var Sale\Payment $paymentClassName */
1414  $paymentClassName = $registry->getPaymentClassName();
1415 
1416  $dbRes = $paymentClassName::getList(array(
1417  'select' => array('ORDER_ID'),
1418  'filter' => array('=ID' => $paymentId)
1419  ));
1420 
1421  $paymentData = $dbRes->fetch();
1422  if (!$paymentData)
1423  {
1424  return $result;
1425  }
1426 
1427  if ($check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_PAYMENT
1428  || $check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_ALL
1429  )
1430  {
1432  {
1433  $dbRes = $paymentClassName::getList(array(
1434  'select' => array('ID', 'ACCOUNT_NUMBER', 'NAME' => 'PAY_SYSTEM.NAME'),
1435  'filter' => array(
1436  '!ID' => $paymentId,
1437  '=ORDER_ID' => $paymentData['ORDER_ID']
1438  )
1439  ));
1440 
1441  while ($data = $dbRes->fetch())
1442  {
1443  $data['PAYMENT_TYPES'] = array(
1444  array(
1446  'NAME' => Loc::getMessage('SALE_CASHBOX_CHECK_ADVANCE'),
1447  ),
1448  array(
1450  'NAME' => Loc::getMessage('SALE_CASHBOX_CHECK_CREDIT'),
1451  )
1452  );
1453 
1454  $result['PAYMENTS'][$data['ID']] = $data;
1455  }
1456  }
1457  }
1458  if ($check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_SHIPMENT
1459  || $check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_ALL
1460  )
1461  {
1462  /** @var Sale\Shipment $shipmentClassName */
1463  $shipmentClassName = $registry->getShipmentClassName();
1464  $dbRes = $shipmentClassName::getList(array(
1465  'select' => array('ID', 'ACCOUNT_NUMBER', 'NAME' => 'DELIVERY.NAME'),
1466  'filter' => array(
1467  '=ORDER_ID' => $paymentData['ORDER_ID'],
1468  'SYSTEM' => 'N'
1469  )
1470  ));
1471 
1472  while ($data = $dbRes->fetch())
1473  {
1474  $result['SHIPMENTS'][$data['ID']] = $data;
1475  }
1476  }
1477 
1478  return $result;
1479  }
1480 
1481  /**
1482  * @param $checkType
1483  * @param $shipmentId
1484  * @param string $registryType
1485  * @return array
1486  * @throws Main\ArgumentException
1487  * @throws Main\ArgumentTypeException
1488  */
1489  public static function getRelatedEntitiesForShipment($checkType, $shipmentId, $registryType = Sale\Registry::REGISTRY_TYPE_ORDER)
1490  {
1491  $result = array();
1492 
1494  {
1495  return $result;
1496  }
1497 
1498  $check = static::createByType($checkType);
1499  if ($check === null)
1500  {
1501  throw new Main\ArgumentTypeException($checkType);
1502  }
1503 
1504  $registry = Sale\Registry::getInstance($registryType);
1505  /** @var Sale\Shipment $shipmentClassName */
1506  $shipmentClassName = $registry->getShipmentClassName();
1507 
1508  $dbRes = $shipmentClassName::getList(array(
1509  'select' => array('ORDER_ID'),
1510  'filter' => array('=ID' => $shipmentId)
1511  ));
1512 
1513  $shipmentData = $dbRes->fetch();
1514  if (!$shipmentData)
1515  {
1516  return $result;
1517  }
1518 
1519  if ($check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_SHIPMENT
1520  || $check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_ALL
1521  )
1522  {
1523  $dbRes = $shipmentClassName::getList(array(
1524  'select' => array('ID', 'ACCOUNT_NUMBER', 'NAME' => 'DELIVERY.NAME'),
1525  'filter' => array(
1526  '!ID' => $shipmentId,
1527  '=ORDER_ID' => $shipmentData['ORDER_ID'],
1528  'SYSTEM' => 'N'
1529  )
1530  ));
1531 
1532  while ($data = $dbRes->fetch())
1533  {
1534  $result['SHIPMENTS'][$data['ID']] = $data;
1535  }
1536  }
1537 
1538  if ($check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_PAYMENT
1539  || $check::getSupportedRelatedEntityType() === Check::SUPPORTED_ENTITY_TYPE_ALL
1540  )
1541  {
1542  /** @var Sale\Payment $paymentClassName */
1543  $paymentClassName = $registry->getPaymentClassName();
1544  $dbRes = $paymentClassName::getList(array(
1545  'select' => array('ID', 'ACCOUNT_NUMBER', 'NAME' => 'PAY_SYSTEM.NAME'),
1546  'filter' => array(
1547  '=ORDER_ID' => $shipmentData['ORDER_ID']
1548  )
1549  ));
1550 
1551  while ($data = $dbRes->fetch())
1552  {
1553  $data['PAYMENT_TYPES'] = array(
1554  array(
1556  'NAME' => Loc::getMessage('SALE_CASHBOX_CHECK_ADVANCE'),
1557  ),
1558  array(
1560  'NAME' => Loc::getMessage('SALE_CASHBOX_CHECK_CREDIT'),
1561  )
1562  );
1563 
1564  $result['PAYMENTS'][$data['ID']] = $data;
1565  }
1566  }
1567 
1568  return $result;
1569  }
1570 }
static getConnection($name="")
Static method returns database connection for the specified name.
Exception is thrown when the type of an argument is not accepted by function.
static get($moduleId, $name, $default="", $siteId=false)
Returns a value of an option.
static registerAutoLoadClasses($moduleName, array $classes)
Registers classes for auto loading.
static loadLanguageFile($file, $language=null, $normalize=true)
Loads language messages for specified file.
Definition: loc.php:203
static getMessage($code, $replace=null, $language=null)
Returns translation by message code.
Definition: loc.php:29
Exception is thrown when operation is not supported.
static query()
Creates and returns the Query object for the entity.
static getById($id)
Returns selection by entity's primary key.
static getList(array $parameters=array())
Executes the query and returns selection by parameters of the query.
static delete($primary)
Deletes row in entity table by primary key.
static update($primary, array $data)
Updates row in entity table by primary key.
static create(array $settings)
Definition: cashbox.php:118
static getRelatedEntitiesForPayment($checkType, $paymentId, $registryType=Sale\Registry::REGISTRY_TYPE_ORDER)
static getLastPrintableCheckInfo(Sale\Internals\CollectableEntity $entity)
static getRelatedEntitiesForShipment($checkType, $shipmentId, $registryType=Sale\Registry::REGISTRY_TYPE_ORDER)
static getCheckInfo(Sale\Internals\CollectableEntity $entity)
static addChecks(array $entities)
static getList(array $parameters=array())
static addByType(array $entities, $type, array $relatedEntities=array())
static getPrintableChecks(array $cashboxIds, array $orderIds=array())
const CHECK_RESENDING_TIME
This is time re-sending a check print in minutes.
static collateDocuments(array $entities)
static create(array $settings)
static savePrintResult($checkId, array $data)
static addCorrection($type, $cashboxId, array $correction)
static collectInfo(array $filter=array())
static addError(string $message, $cashboxId=null)
static addWarning(string $message, $cashboxId=null)
static getListWithRestrictions(CollectableEntity $entity)
Class RestHandler \Handlers\PaySystem.