35 private const EVENT_ON_BEFORE_CASHBOX_ADD =
'onBeforeCashboxAdd';
45 $dbRes = CashboxTable::getList(array(
46 'select' => array(
'*'),
47 'filter' => array(
'ACTIVE' =>
'Y'),
48 'order' => array(
'SORT' =>
'ASC',
'NAME' =>
'ASC')
51 while ($cashbox = $dbRes->fetch())
53 if (Restrictions\Manager::checkService($cashbox[
'ID'], $entity) === Restrictions\Manager::SEVERITY_NONE)
54 $result[$cashbox[
'ID']] = $cashbox;
60 private static function getCashboxByPayment(
Sale\
Payment $payment): array
62 $service = $payment->getPaySystem();
63 if ($service && $service->isSupportPrintCheck())
66 $cashboxClass = $service->getCashboxClass();
67 $kkm = $cashboxClass::getKkmValue($service);
72 '=HANDLER' => $cashboxClass,
88 $firstIteration =
true;
91 if ($payment && self::canPaySystemPrint($payment))
93 $cashbox = self::getCashboxByPayment($payment);
96 $cashboxList[] = $cashbox;
101 $entities = $check->getEntities();
102 foreach ($entities as $entity)
107 $cashboxList = $items;
108 $firstIteration =
false;
112 $cashboxList = array_intersect_assoc($items, $cashboxList);
116 foreach ($cashboxList as $key => $cashbox)
118 if (self::isPaySystemCashbox($cashbox[
'HANDLER']))
120 unset($cashboxList[$key]);
135 public static function getList(array $parameters = [])
137 return CashboxTable::getList($parameters);
153 foreach ($handlerList as $handler)
155 $result[$handler[
'CODE']] = $handler;
167 static $cashboxObjects = array();
174 if (!isset($cashboxObjects[$id]))
176 $data = static::getCashboxFromCache($id);
180 if ($cashbox ===
null)
185 $cashboxObjects[$id] = $cashbox;
189 return $cashboxObjects[$id] ??
null;
200 $index = rand(0, count($cashboxList)-1);
202 return $cashboxList[$index];
210 $context = Main\Application::getInstance()->getContext();
211 $scheme = $context->getRequest()->isHttps() ?
'https' :
'http';
212 $server = $context->getServer();
213 $domain = $server->getServerName();
215 if (preg_match(
'/^(?<domain>.+):(?<port>\d+)$/', $domain, $matches))
217 $domain = $matches[
'domain'];
218 $port = $matches[
'port'];
222 $port = $server->getServerPort();
224 $port = in_array($port, array(80, 443)) ?
'' :
':'.$port;
226 return sprintf(
'%s://%s%s/bitrix/tools/sale_check_print.php?hash=%s', $scheme, $domain, $port, static::generateHash());
232 private static function generateHash()
234 $hash = md5(base64_encode(time()));
245 $cacheManager = Main\Application::getInstance()->getManagedCache();
247 if($cacheManager->read(self::TTL, self::CACHE_ID))
248 $cashboxList = $cacheManager->get(self::CACHE_ID);
250 if (empty($cashboxList))
252 $cashboxList = array();
254 $dbRes = CashboxTable::getList();
255 while ($data = $dbRes->fetch())
256 $cashboxList[$data[
'ID']] = $data;
258 $cacheManager->set(self::CACHE_ID, $cashboxList);
270 $cashboxList = static::getListFromCache();
271 if (isset($cashboxList[$cashboxId]))
272 return $cashboxList[$cashboxId];
285 if ($cashbox->getField(
'USE_OFFLINE') ===
'Y')
288 return $cashbox->buildZReportQuery($id);
298 $checks = CheckManager::getPrintableChecks($cashboxIds);
299 foreach ($checks as $item)
304 $printResult = static::buildConcreteCheckQuery($check->getField(
'CASHBOX_ID'), $check);
306 $result[] = $printResult;
320 $cashbox = static::getObjectById($cashboxId);
323 return $cashbox->buildCheckQuery($check);
333 public static function add(array $data)
335 $event =
new Main\Event(
'sale', self::EVENT_ON_BEFORE_CASHBOX_ADD, $data);
337 $eventResults = $event->getResults();
338 foreach ($eventResults as $eventResult)
340 $data = array_merge($data, $eventResult->getParameters());
342 $addResult = CashboxTable::add($data);
344 $cacheManager = Main\Application::getInstance()->getManagedCache();
348 is_subclass_of($data[
'HANDLER'], ICheckable::class)
350 is_subclass_of($data[
'HANDLER'], ICorrection::class)
351 && $data[
'HANDLER']::isCorrectionOn()
355 static::addCheckStatusAgent();
364 private static function addCheckStatusAgent()
366 \CAgent::AddAgent(static::CHECK_STATUS_AGENT,
"sale",
"N", 120,
"",
"Y");
374 public static function update($primary, array $data)
376 $updateResult = CashboxTable::update($primary, $data);
378 $cacheManager = Main\Application::getInstance()->getManagedCache();
381 if ($service && self::isPaySystemCashbox($service->getField(
'HANDLER')))
384 $cashboxClass = $service->getField(
'HANDLER');
385 if ($cashboxClass::CACHE_ID)
387 $cacheManager->clean($cashboxClass::CACHE_ID);
393 if (is_subclass_of($data[
'HANDLER'],
'\Bitrix\Sale\Cashbox\ICheckable'))
395 static::addCheckStatusAgent();
398 return $updateResult;
405 public static function delete($primary)
408 $deleteResult = CashboxTable::delete($primary);
409 $cacheManager = Main\Application::getInstance()->getManagedCache();
416 if ($service && self::isPaySystemCashbox($service->getField(
'HANDLER')))
419 $cashboxClass = $service->getField(
'HANDLER');
420 if ($cashboxClass::CACHE_ID)
422 $cacheManager->clean($cashboxClass::CACHE_ID);
428 return $deleteResult;
434 public static function isSupportedFFD105()
438 $cashboxList = static::getListFromCache();
439 foreach ($cashboxList as $cashbox)
441 if ($cashbox[
'ACTIVE'] ===
'N')
444 $handler = $cashbox[
'HANDLER'];
445 $isRestHandler = $handler ===
'\Bitrix\Sale\Cashbox\CashboxRest';
448 $handlerCode = $cashbox[
'SETTINGS'][
'REST'][
'REST_CODE'];
450 $currentHandler = $restHandlers[$handlerCode];
451 if ($currentHandler[
'SETTINGS'][
'SUPPORTS_FFD105'] !==
'Y')
457 !is_callable(array($handler,
'isSupportedFFD105')) ||
458 !$handler::isSupportedFFD105()
473 foreach ($cashboxList as $cashbox)
475 if ($cashbox[
'ACTIVE'] ===
'N')
480 if (self::isPaySystemCashbox($cashbox[
'HANDLER']))
495 $service = $payment->getPaySystem();
498 && $service->isSupportPrintCheck()
499 && $service->canPrintCheck()
500 && $service->canPrintCheckSelf($payment)
508 public static function updateChecksStatus()
510 $cashboxList = static::getListFromCache();
516 $availableCashboxList = [];
517 foreach ($cashboxList as $item)
522 || $cashbox->isCorrection()
525 $availableCashboxList[$item[
'ID']] = $cashbox;
529 if (!$availableCashboxList)
537 '@CASHBOX_ID' => array_keys($availableCashboxList),
538 '=CASHBOX.ACTIVE' =>
'Y'
543 while ($checkInfo = $dbRes->fetch())
546 $cashbox = $availableCashboxList[$checkInfo[
'CASHBOX_ID']];
551 if ($check instanceof CorrectionCheck)
553 $result = $cashbox->checkCorrection($check);
555 elseif ($check instanceof Check)
557 $result = $cashbox->check($check);
564 if (!$result->isSuccess())
566 foreach ($result->getErrors() as $error)
568 if ($error instanceof Errors\Warning)
581 return static::CHECK_STATUS_AGENT;
596 if ($error instanceof Errors\
Warning)
615 'CASHBOX_ID' => $cashboxId,
621 return (
bool)$result->fetch();
630 return self::update($cashboxId, [
'ACTIVE' =>
'N']);
639 return is_subclass_of($cashboxClassName, CashboxPaySystem::class);
static loadMessages($file)
static getList(array $parameters=array())