3namespace Bitrix\Sale\Cashbox;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Main\Type\DateTime;
8use Bitrix\Sale\Cashbox\Internals\CashboxConnectTable;
9use Bitrix\Sale\Cashbox\Internals\CashboxTable;
10use Bitrix\Sale\Internals\CashboxRestHandlerTable;
11use Bitrix\Sale\Internals\CollectableEntity;
12use Bitrix\Sale\Result;
15Loc::loadMessages(__FILE__);
35 private const EVENT_ON_BEFORE_CASHBOX_ADD =
'onBeforeCashboxAdd';
46 'select' =>
array(
'*'),
47 'filter' =>
array(
'=ACTIVE' =>
'Y'),
48 'order' =>
array(
'SORT' =>
'ASC',
'NAME' =>
'ASC')
51 while ($cashbox =
$dbRes->fetch())
54 $result[$cashbox[
'ID']] = $cashbox;
66 $cashboxClass =
$service->getCashboxClass();
67 $kkm = $cashboxClass::getKkmValue(
$service);
72 '=HANDLER' => $cashboxClass,
88 $firstIteration =
true;
93 $cashbox = self::getCashboxByPayment(
$payment);
96 $cashboxList[] = $cashbox;
101 $entities = $check->getEntities();
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]);
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];
211 $scheme =
$context->getRequest()->isHttps() ?
'https' :
'http';
213 $domain = $server->getServerName();
215 if (preg_match(
'/^(?<domain>.+):(?<port>\d+)$/', $domain,
$matches))
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()));
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();
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);
320 $cashbox = static::getObjectById($cashboxId);
323 return $cashbox->buildCheckQuery($check);
337 $eventResults =
$event->getResults();
338 foreach ($eventResults as $eventResult)
340 $data = array_merge(
$data, $eventResult->getParameters());
342 $addResult = CashboxTable::add(
$data);
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);
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();
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']))
508 public static function updateChecksStatus()
510 $cashboxList = static::getListFromCache();
516 $availableCashboxList = [];
517 foreach ($cashboxList as $item)
521 $item[
'ACTIVE'] ===
'Y'
523 $cashbox?->isCheckable()
524 || $cashbox?->isCorrection()
528 $availableCashboxList[$item[
'ID']] = $cashbox;
532 if (!$availableCashboxList)
540 '@CASHBOX_ID' => array_keys($availableCashboxList),
541 '=CASHBOX.ACTIVE' =>
'Y'
546 while ($checkInfo =
$dbRes->fetch())
549 $cashbox = $availableCashboxList[$checkInfo[
'CASHBOX_ID']];
554 if ($check instanceof CorrectionCheck)
556 $result = $cashbox->checkCorrection($check);
558 elseif ($check instanceof Check)
560 $result = $cashbox->check($check);
571 if (
$error instanceof Errors\Warning)
584 return static::CHECK_STATUS_AGENT;
618 'CASHBOX_ID' => $cashboxId,
633 return self::update($cashboxId, [
'ACTIVE' =>
'N']);
642 return is_subclass_of($cashboxClassName, CashboxPaySystem::class);
static getList(array $parameters=array())
static getPaymentByCheck(Check $check)
static getList(array $parameters=array())
static create(array $settings)
static getObjectById($id)
static addWarning(?string $message, $cashboxId=null)
static addError(?string $message, $cashboxId=null)
static getRestHandlersList()
static getAvailableCashboxList(Check $check)
static buildConcreteCheckQuery($cashboxId, Check $check)
static buildChecksQuery($cashboxIds)
static buildZReportQuery($cashboxId, $id)
static getListFromCache()
static isCashboxChecksExist($cashboxId)
static isEnabledPaySystemPrint()
static getConnectionLink()
static getCashboxFromCache($cashboxId)
const LEVEL_TRACE_E_ERROR
static getListWithRestrictions(CollectableEntity $entity)
static canPaySystemPrint(Sale\Payment $payment)
const LEVEL_TRACE_E_IGNORED
const LEVEL_TRACE_E_WARNING
static writeToLog($cashboxId, Main\Error $error)
static isPaySystemCashbox(string $cashboxClassName)
static getObjectById($id)
static deactivateCashbox($cashboxId)
static chooseCashbox($cashboxList)
static getList(array $parameters=[])
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</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."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']