11Localization\Loc::loadMessages(__FILE__);
31 foreach ($data[
'payments'] as $payment)
33 $result[
'payments'][] = array(
35 'value' => $payment[
'sum']
40 if (isset($typeMap[$data[
'type']]))
42 $result[
'type'] = $typeMap[$data[
'type']];
49 $result[
'uuid'] = static::buildUuid(static::UUID_TYPE_CHECK, $data[
'unique_id']);
50 $result[
'zn'] = $this->
getField(
'NUMBER_KKM');
51 $result[
'items'] = array();
52 foreach ($data[
'items'] as $item)
59 'name' => $item[
'name'],
60 'price' => (
float)$item[
'base_price'],
61 'quantity' => $item[
'quantity'],
65 if (isset($item[
'discount']) && is_array($item[
'discount']))
68 $value[
'discount'] = $discountValue;
70 $discountType = $item[
'discount'][
'discount_type'] ===
'P' ? 1 : 0;
71 $value[
'discount_type'] = $discountType;
74 $result[
'items'][] = $value;
76 $result[
'client'] = $data[
'client_email'];
79 $dateTime = $data[
'date_create'];
80 $result[
'timestamp'] = (string)$dateTime->getTimestamp();
94 'type' => static::TYPE_Z_REPORT,
95 'uuid' => static::buildUuid(static::UUID_TYPE_REPORT, $id),
96 'timestamp' => (
string)$dateTime->getTimestamp(),
97 'zn' => $this->getField(
'NUMBER_KKM')
106 return Localization\Loc::getMessage(
'SALE_CASHBOX_BITRIX_TITLE');
118 if (isset($cashbox[
'ID']) && (
int)$cashbox[
'ID'] > 0)
120 if ($cashbox[
'ENABLED'] !== $cashbox[
'PRESENTLY_ENABLED'])
122 Manager::update($cashbox[
'ID'], array(
'ENABLED' => $cashbox[
'PRESENTLY_ENABLED']));
124 if ($cashbox[
'PRESENTLY_ENABLED'] ===
'N')
126 static::showAlarmMessage($cashbox[
'ID']);
130 $fields = array(
'DATE_LAST_CHECK' =>
new Main\
Type\
DateTime());
131 if (isset($cashbox[
'SETTINGS']))
133 $fields[
'SETTINGS'] = $cashbox[
'SETTINGS'];
136 if (isset($cashbox[
'HANDLER']))
138 $fields[
'HANDLER'] = $cashbox[
'HANDLER'];
141 Manager::update($cashbox[
'ID'], $fields);
149 'NAME' => static::getName(),
150 'NUMBER_KKM' => $cashbox[
'NUMBER_KKM'],
151 'HANDLER' => $cashbox[
'HANDLER'],
152 'ENABLED' => $cashbox[
'PRESENTLY_ENABLED'],
154 'EMAIL' => self::getCashboxDefaultEmail(),
158 if ($result->isSuccess())
160 if ($cashbox[
'PRESENTLY_ENABLED'] ===
'N')
162 static::showAlarmMessage($result->getId());
165 Internals\CashboxZReportTable::add(array(
167 'CASHBOX_ID' => $result->getId(),
171 'CASH_SUM' => $cashbox[
'CACHE'],
172 'CASHLESS_SUM' => $cashbox[
'INCOME'] - $cashbox[
'CACHE'],
173 'CUMULATIVE_SUM' => $cashbox[
'NZ_SUM'],
190 private static function getCashboxDefaultEmail()
192 $email = Main\Config\Option::get(
'main',
'email_from');
195 $dbRes = Main\UserGroupTable::getList([
196 'select' => [
'EMAIL' =>
'USER.EMAIL'],
205 $data = $dbRes->fetch();
208 $email = $data[
'EMAIL'];
220 $tag =
"CASHBOX_STATUS_ERROR";
222 $dbRes = \CAdminNotify::GetList([], [
"TAG" => $tag]);
224 if ($res = $dbRes->Fetch())
230 "MESSAGE" => Localization\
Loc::getMessage(
'SALE_CASHBOX_ACCESS_UNAVAILABLE', [
'#CASHBOX_ID#' => $cashboxId]),
232 "MODULE_ID" =>
"SALE",
233 "ENABLE_CLOSE" =>
"Y",
234 "NOTIFY_TYPE" => \CAdminNotify::TYPE_ERROR
247 if (isset($data[
'kkm']) && is_array($data[
'kkm']))
249 $factoryNum = array();
250 foreach ($data[
'kkm'] as $kkm)
252 $factoryNum[] = $kkm[
'zn'];
256 foreach ($cashboxList as $item)
258 if (in_array($item[
'NUMBER_KKM'], $factoryNum))
260 $result[$item[
'NUMBER_KKM']] = $item;
264 foreach ($data[
'kkm'] as $kkm)
266 if (!isset($result[$kkm[
'zn']]))
268 $result[$kkm[
'zn']] = array(
269 'NUMBER_KKM' => $kkm[
'zn'],
270 'NUMBER_FN' => $kkm[
'fn'],
271 'HANDLER' =>
'\\'.get_called_class(),
272 'CACHE' => $kkm[
'cache'],
273 'INCOME' => $kkm[
'reg_income'],
274 'NZ_SUM' => $kkm[
'nz_sum']
278 $result[$kkm[
'zn']][
'PRESENTLY_ENABLED'] = ($kkm[
'status'] ===
'ok') ?
'Y' :
'N';
291 $processedIds = array();
293 foreach ($data[
'kkm'] as $kkm)
295 if (isset($kkm[
'printed']) && is_array($kkm[
'printed']))
297 foreach ($kkm[
'printed'] as $item)
299 $uuid = static::parseUuid($item[
'uuid']);
302 if ($uuid[
'type'] === static::UUID_TYPE_CHECK)
304 $result = static::applyCheckResult($item);
306 elseif ($uuid[
'type'] === static::UUID_TYPE_REPORT)
308 $result = static::applyZReportResult($item);
311 if ($result !==
null)
313 if ($result->isSuccess())
315 $processedIds[] = $item[
'uuid'];
319 $errors = $result->getErrors();
320 foreach ($errors as $error)
322 if ($error instanceof Errors\
Error)
324 $processedIds[] = $item[
'uuid'];
334 return $processedIds;
346 'TYPE' => $uuid[
'type'],
349 if ($data[
'code'] !== 0 && isset($data[
'message']))
351 $errorMsg = Localization\Loc::getMessage(
'SALE_CASHBOX_BITRIX_ERR'.$data[
'code']);
353 $errorMsg = $data[
'message'];
355 $errorType = static::getErrorType($data[
'code']);
357 $result[
'ERROR'] = array(
358 'CODE' => $data[
'code'],
359 'MESSAGE' => $errorMsg,
360 'TYPE' => ($errorType === Errors\Error::TYPE) ? Errors\Error::TYPE : Errors\Warning::TYPE
364 $result[
'LINK_PARAMS'] = static::getCheckLinkParams($data);
373 private static function getCheckLinkParams($data)
375 $linkParams = static::parseQrParam($data[
'qr']);
384 if (isset($data[
'rn']))
401 'TYPE' => $uuid[
'type'],
404 if ($data[
'code'] !== 0 && isset($data[
'message']))
406 $errorMsg = Localization\Loc::getMessage(
'SALE_CASHBOX_BITRIX_ERR'.$data[
'code']);
408 $errorMsg = $data[
'message'];
410 $errorType = static::getErrorType($data[
'code']);
411 if ($errorType ==
null)
412 $errorType = Errors\Warning::TYPE;
414 $result[
'ERROR'] = array(
'MESSAGE' => $errorMsg,
'CODE' => $data[
'code'],
'TYPE' => $errorType);
417 $result[
'CASH_SUM'] = $data[
'payments_cache'];
418 $result[
'CASHLESS_SUM'] = $data[
'reg_income'] - $data[
'payments_cache'];
419 $result[
'CUMULATIVE_SUM'] = $data[
'nz_sum'];
420 $result[
'RETURNED_SUM'] = $data[
'reg_return'];
421 $result[
'LINK_PARAMS'] = static::parseQrParam($data[
'qr']);
442 private static function parseQrParam($qr)
445 $params = explode(
'&', $qr);
448 foreach ($params as $param)
450 [$key, $value] = explode(
'=', $param);
465 $value = (string)$dateTime->getTimestamp();
477 $result[$key] = $value;
491 $errors = array(-3800, -3803, -3804, -3805, -3816, -3807, -3896, -3897, -4026);
492 if (in_array($errorCode, $errors))
493 return Errors\Error::TYPE;
496 if (in_array($errorCode, $warnings))
497 return Errors\Warning::TYPE;
510 $kkmList = static::getSupportedKkmModels();
511 if (isset($kkmList[$modelId]))
513 $defaultSettings = $kkmList[$modelId][
'SETTINGS'];
515 if (isset($defaultSettings[
'PAYMENT_TYPE']))
517 $settings[
'PAYMENT_TYPE'] = array(
518 'LABEL' => Localization\
Loc::getMessage(
'SALE_CASHBOX_BITRIX_SETTINGS_P_TYPE'),
523 foreach ($defaultSettings[
'PAYMENT_TYPE'] as $type => $value)
525 $settings[
'PAYMENT_TYPE'][
'ITEMS'][$type] = array(
527 'LABEL' => Localization\
Loc::getMessage(
'SALE_CASHBOX_BITRIX_SETTINGS_P_TYPE_LABEL_'.ToUpper($type)),
534 $settings[
'VAT'] = array(
535 'LABEL' => Localization\
Loc::getMessage(
'SALE_CASHBOX_BITRIX_SETTINGS_VAT'),
540 'LABEL' => Localization\
Loc::getMessage(
'SALE_CASHBOX_BITRIX_SETTINGS_VAT_LABEL_NOT_VAT'),
541 'VALUE' => $defaultSettings[
'VAT'][
'NOT_VAT']
546 if (Main\Loader::includeModule(
'catalog'))
548 $dbRes = Catalog\VatTable::getList(array(
'filter' => array(
'ACTIVE' =>
'Y')));
549 $vatList = $dbRes->fetchAll();
552 foreach ($vatList as $vat)
555 if (isset($defaultSettings[
'VAT'][(
int)$vat[
'RATE']]))
556 $value = $defaultSettings[
'VAT'][(int)$vat[
'RATE']];
558 $settings[
'VAT'][
'ITEMS'][(int)$vat[
'ID']] = array(
560 'LABEL' => $vat[
'NAME'].
' ['.(
int)$vat[
'RATE'].
'%]',
569 for ($i = 0; $i < 24; $i++)
571 $value = ($i < 10) ?
'0'.$i : $i;
576 for ($i = 0; $i < 60; $i+=5)
578 $value = ($i < 10) ?
'0'.$i : $i;
579 $minutes[$i] = $value;
582 $settings[
'Z_REPORT'] = array(
583 'LABEL' => Localization\
Loc::getMessage(
'SALE_CASHBOX_BITRIX_SETTINGS_Z_REPORT'),
586 'TYPE' =>
'DELIVERY_MULTI_CONTROL_STRING',
587 'LABEL' => Localization\
Loc::getMessage(
'SALE_CASHBOX_BITRIX_SETTINGS_Z_REPORT_LABEL'),
591 'LABEL' => Localization\
Loc::getMessage(
'SALE_CASHBOX_BITRIX_SETTINGS_Z_REPORT_LABEL_H'),
597 'LABEL' => Localization\
Loc::getMessage(
'SALE_CASHBOX_BITRIX_SETTINGS_Z_REPORT_LABEL_M'),
599 'OPTIONS' => $minutes
615 $settings = parent::extractSettingsFromRequest($request);
617 if ($settings[
'PAYMENT_TYPE'])
620 foreach ($settings[
'PAYMENT_TYPE'] as $i => $payment)
623 $settings[
'PAYMENT_TYPE'][$i] = (int)$payment - 1;
625 $settings[
'PAYMENT_TYPE'][$i] = 0;
637 $generalRequiredFields = parent::getGeneralRequiredFields();
639 $map = Internals\CashboxTable::getMap();
640 $generalRequiredFields[
'KKM_ID'] = $map[
'KKM_ID'][
'title'];
641 $generalRequiredFields[
'NUMBER_KKM'] = $map[
'NUMBER_KKM'][
'title'];
643 return $generalRequiredFields;
661 'PAYMENT_TYPE' => array(
static getMessage($code, $replace=null, $language=null)
const PARAM_CALCULATION_ATTR
const PARAM_FISCAL_DOC_ATTR
const PARAM_FISCAL_DOC_NUMBER
const PARAM_REG_NUMBER_KKT
const PAYMENT_TYPE_CASHLESS
static extractZReportData(array $data)
static extractSettingsFromRequest(Main\HttpRequest $request)
static getErrorType($errorCode)
static getSettings($modelId=0)
static getGeneralRequiredFields()
static getCashboxList(array $data)
static getSupportedKkmModels()
static saveCashbox(array $cashbox)
static showAlarmMessage($cashboxId)
static extractCheckData(array $data)
static applyPrintResult(array $data)
buildCheckQuery(Check $check)
getValueFromSettings($name, $code)
static getObjectById($id)
static getListFromCache()
static roundPrecision($value)