1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
cashbox.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale\Cashbox;
4
5use Bitrix\Main;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Main\NotImplementedException;
8use Bitrix\Sale\Cashbox\Internals\CashboxTable;
9use Bitrix\Sale\Result;
10
11Loc::loadMessages(__FILE__);
12
17abstract class Cashbox
18{
19 const UUID_TYPE_CHECK = 'check';
20 const UUID_TYPE_REPORT = 'report';
21 const UUID_DELIMITER = '|';
22
23 const EVENT_ON_GET_CUSTOM_CASHBOX_HANDLERS = 'OnGetCustomCashboxHandlers';
24
25 protected const MAX_UUID_LENGTH = 100;
26
28 private $fields = array();
29
30 private $ofd;
31
36 public static function init()
37 {
38 $handlers = static::getHandlerList();
40 }
41
42 public static function getCode()
43 {
44 $className = (new \ReflectionClass(static::class))->getShortName();
45 return mb_strtolower($className);
46 }
47
51 public static function getHandlerList()
52 {
53 static $handlerList = array();
54
55 if (!$handlerList)
56 {
57 $zone = '';
58 $isCloud = Main\Loader::includeModule("bitrix24");
59 if ($isCloud)
60 {
61 $zone = \CBitrix24::getLicensePrefix();
62 }
63 elseif (Main\Loader::includeModule('intranet'))
64 {
65 $zone = \CIntranetUtils::getPortalZone();
66 }
67 if ($zone === 'ru' && $isCloud)
68 {
69 $handlerList = [
70 '\Bitrix\Sale\Cashbox\CashboxAtolFarm' => '/bitrix/modules/sale/lib/cashbox/cashboxatolfarm.php',
71 '\Bitrix\Sale\Cashbox\CashboxAtolFarmV4' => '/bitrix/modules/sale/lib/cashbox/cashboxatolfarmv4.php',
72 '\Bitrix\Sale\Cashbox\CashboxAtolFarmV5' => '/bitrix/modules/sale/lib/cashbox/cashboxatolfarmv5.php',
73 '\Bitrix\Sale\Cashbox\CashboxOrangeData' => '/bitrix/modules/sale/lib/cashbox/cashboxorangedata.php',
74 '\Bitrix\Sale\Cashbox\CashboxOrangeDataFfd12' => '/bitrix/modules/sale/lib/cashbox/cashboxorangedataffd12.php',
75 '\Bitrix\Sale\Cashbox\CashboxBusinessRu' => '/bitrix/modules/sale/lib/cashbox/cashboxbusinessru.php',
76 '\Bitrix\Sale\Cashbox\CashboxBusinessRuV5' => '/bitrix/modules/sale/lib/cashbox/cashboxbusinessruv5.php',
77 ];
78 }
79 elseif ($zone === 'ua')
80 {
81 $handlerList = [
82 '\Bitrix\Sale\Cashbox\CashboxCheckbox' => '/bitrix/modules/sale/lib/cashbox/cashboxcheckbox.php',
83 ];
84 }
85 else
86 {
87 $handlerList = [
88 '\Bitrix\Sale\Cashbox\CashboxAtolFarm' => '/bitrix/modules/sale/lib/cashbox/cashboxatolfarm.php',
89 '\Bitrix\Sale\Cashbox\CashboxAtolFarmV4' => '/bitrix/modules/sale/lib/cashbox/cashboxatolfarmv4.php',
90 '\Bitrix\Sale\Cashbox\CashboxAtolFarmV5' => '/bitrix/modules/sale/lib/cashbox/cashboxatolfarmv5.php',
91 '\Bitrix\Sale\Cashbox\CashboxOrangeData' => '/bitrix/modules/sale/lib/cashbox/cashboxorangedata.php',
92 '\Bitrix\Sale\Cashbox\CashboxOrangeDataFfd12' => '/bitrix/modules/sale/lib/cashbox/cashboxorangedataffd12.php',
93 '\Bitrix\Sale\Cashbox\CashboxBitrixV2' => '/bitrix/modules/sale/lib/cashbox/cashboxbitrixv2.php',
94 '\Bitrix\Sale\Cashbox\CashboxBitrixV3' => '/bitrix/modules/sale/lib/cashbox/cashboxbitrixv3.php',
95 '\Bitrix\Sale\Cashbox\CashboxBitrix' => '/bitrix/modules/sale/lib/cashbox/cashboxbitrix.php',
96 '\Bitrix\Sale\Cashbox\Cashbox1C' => '/bitrix/modules/sale/lib/cashbox/cashbox1c.php',
97 '\Bitrix\Sale\Cashbox\CashboxCheckbox' => '/bitrix/modules/sale/lib/cashbox/cashboxcheckbox.php',
98 '\Bitrix\Sale\Cashbox\CashboxBusinessRu' => '/bitrix/modules/sale/lib/cashbox/cashboxbusinessru.php',
99 '\Bitrix\Sale\Cashbox\CashboxBusinessRuV5' => '/bitrix/modules/sale/lib/cashbox/cashboxbusinessruv5.php',
100 ];
101 }
102
103 $handlerList['\Bitrix\Sale\Cashbox\CashboxRest'] = '/bitrix/modules/sale/lib/cashbox/cashboxrest.php';
104
105 $handlerList['\Bitrix\Sale\Cashbox\CashboxRobokassa'] = '/bitrix/modules/sale/lib/cashbox/cashboxrobokassa.php';
106 $handlerList['\Bitrix\Sale\Cashbox\CashboxYooKassa'] = '/bitrix/modules/sale/lib/cashbox/cashboxyookassa.php';
107
108 $event = new Main\Event('sale', static::EVENT_ON_GET_CUSTOM_CASHBOX_HANDLERS);
109 $event->send();
110 $resultList = $event->getResults();
111
112 if (is_array($resultList) && !empty($resultList))
113 {
114 foreach ($resultList as $eventResult)
115 {
117 if ($eventResult->getType() === Main\EventResult::SUCCESS)
118 {
119 $params = $eventResult->getParameters();
120 if (!empty($params) && is_array($params))
121 $handlerList = array_merge($handlerList, $params);
122 }
123 }
124 }
125 }
126
127 return $handlerList;
128 }
129
135 public static function create(array $settings)
136 {
137 static::init();
138
139 $handler = $settings['HANDLER'];
140 if (class_exists($handler))
141 return new $handler($settings);
142
143 return null;
144 }
145
150 private function __construct($settings)
151 {
152 $this->fields = $settings;
153 }
154
159 public function getField($name)
160 {
161 return $this->fields[$name] ?? null;
162 }
163
167 public function getOfd()
168 {
169 if ($this->ofd === null)
170 {
171 $this->ofd = Ofd::create($this);
172 }
173
174 return $this->ofd;
175 }
176
181 abstract public function buildCheckQuery(Check $check);
182
187 abstract public function buildZReportQuery($id);
188
193 public static function getName()
194 {
195 throw new NotImplementedException();
196 }
197
204 {
205 $map = $this->fields['SETTINGS'];
206 if (isset($map[$name]))
207 {
208 if (!is_array($map[$name]))
209 {
210 return $map[$name];
211 }
212
213 if (isset($map[$name][$code]))
214 {
215 return $map[$name][$code];
216 }
217 }
218
219 $settings = static::getSettings($this->getField('KKM_ID'));
220
221 return $settings[$name]['ITEMS'][$code]['VALUE'] ?? null;
222 }
223
228 public function getCheckLink(array $linkParams)
229 {
230 if (!$linkParams)
231 {
232 return '';
233 }
234
235 if (static::isSupportedDirectCheckLink() && isset($linkParams[Check::PARAM_OFD_RECEIPT_URL]))
236 {
237 return $linkParams[Check::PARAM_OFD_RECEIPT_URL];
238 }
239 else
240 {
242 $ofd = $this->getOfd();
243 if ($ofd !== null)
244 {
245 return $ofd->generateCheckLink($linkParams);
246 }
247 }
248
249 return '';
250 }
251
257 protected static function getErrorType($errorCode)
258 {
259 throw new NotImplementedException();
260 }
261
267 protected static function extractCheckData(array $data)
268 {
269 throw new NotImplementedException();
270 }
271
277 protected static function extractZReportData(array $data)
278 {
279 throw new NotImplementedException();
280 }
281
286 public static function applyCheckResult(array $data)
287 {
288 $result = static::extractCheckData($data);
289
290 $checkId = $result['ID'] ?? 0;
291
292 return CheckManager::savePrintResult($checkId, $result);
293 }
294
299 public static function applyZReportResult(array $data)
300 {
301 $result = static::extractZReportData($data);
302
304 }
305
310 public static function getSettings($modelId = 0)
311 {
312 return array();
313 }
314
318 public function validate()
319 {
320 $fields = $this->fields;
321 unset($fields['OFD_SETTINGS']);
322
323 $result = $this->validateFields($fields);
324
325 $ofd = $this->getOfd();
326 if ($ofd)
327 {
328 $r = $ofd->validate();
329 if (!$r->isSuccess())
330 {
331 $result->addErrors($r->getErrors());
332 }
333 }
334
335 return $result;
336 }
337
338 protected function validateFields($fields)
339 {
340 $result = new Result();
341
342 foreach ($fields as $code => $value)
343 {
344 if (is_array($value))
345 {
346 $r = $this->validateFields($value);
347 if (!$r->isSuccess())
348 {
349 $result->addErrors($r->getErrors());
350 }
351
352 continue;
353 }
354
355 if (
356 $this->isRequiredField($code)
357 && $value === ''
358 )
359 {
360 $requiredFields = $this->getRequiredFields();
361
362 $result->addError(
363 new Main\Error(
364 Loc::getMessage(
365 'SALE_CASHBOX_VALIDATE_ERROR',
366 ['#FIELD_ID#' => $requiredFields[$code]]
367 )
368 )
369 );
370 }
371 }
372
373 return $result;
374 }
375
376 protected function isRequiredField($field) : bool
377 {
378 $requiredFields = $this->getRequiredFields();
379
380 return isset($requiredFields[$field]);
381 }
382
387 public static function extractSettingsFromRequest(Main\HttpRequest $request)
388 {
390 $settings = $request->get('SETTINGS');
391
392 return $settings;
393 }
394
399 private function getRequiredFields()
400 {
401 $result = static::getGeneralRequiredFields();
402
403 $settings = static::getSettings($this->getField('KKM_ID'));
404 foreach ($settings as $groupId => $group)
405 {
406 foreach ($group['ITEMS'] as $code => $item)
407 {
408 $isRequired =
409 isset($group['REQUIRED']) && $group['REQUIRED'] === 'Y'
410 || isset($item['REQUIRED']) && $item['REQUIRED'] === 'Y'
411 ;
412 if ($isRequired)
413 {
414 $result[$code] = $item['LABEL'];
415 }
416 }
417 }
418
419 return $result;
420 }
421
425 public static function getGeneralRequiredFields()
426 {
427 $map = CashboxTable::getMap();
428
429 return array(
430 'NAME' => $map['NAME']['title'],
431 'EMAIL' => $map['EMAIL']['title'],
432 'HANDLER' => $map['HANDLER']['title']
433 );
434 }
435
441 protected static function buildUuid($type, $id)
442 {
443 $context = Main\Application::getInstance()->getContext();
444 $server = $context->getServer();
445 $domain = $server->getServerName();
446 $timestamp = time();
447
448 $uuid =
449 $type.static::UUID_DELIMITER.
450 $domain.static::UUID_DELIMITER.
451 $id.static::UUID_DELIMITER.
452 $timestamp
453 ;
454
455 return mb_substr($uuid, 0, static::MAX_UUID_LENGTH);
456 }
457
462 protected static function parseUuid($uuid)
463 {
464 $info = explode(static::UUID_DELIMITER, $uuid);
465
466 return array('type' => $info[0], 'id' => $info[2]);
467 }
468
472 public static function getSupportedKkmModels()
473 {
474 return array();
475 }
476
480 public function isCheckable()
481 {
482 return $this instanceof ICheckable;
483 }
484
488 public function isCorrection()
489 {
490 return (
491 $this instanceof ICorrection
492 && $this::isCorrectionOn()
493 );
494 }
495
499 public static function isCorrectionOn(): bool
500 {
501 return true;
502 }
503
507 public static function getFfdVersion(): ?float
508 {
509 return null;
510 }
511
517 public static function isSupportedFFD105()
518 {
519 return static::getFfdVersion() >= 1.05;
520 }
521
522 protected static function isSupportedDirectCheckLink(): bool
523 {
524 return false;
525 }
526
527 public static function isOfdSettingsNeeded(): bool
528 {
529 if (static::isSupportedDirectCheckLink())
530 {
531 return false;
532 }
533
534 return true;
535 }
536}
$type
Определения options.php:106
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static getInstance()
Определения application.php:98
Определения error.php:15
static includeModule($moduleName)
Определения loader.php:67
static registerAutoLoadClasses($moduleName, array $classes)
Определения loader.php:273
const PARAM_OFD_RECEIPT_URL
Определения abstractcheck.php:32
static extractZReportData(array $data)
Определения cashbox.php:277
static parseUuid($uuid)
Определения cashbox.php:462
static buildUuid($type, $id)
Определения cashbox.php:441
static getFfdVersion()
Определения cashbox.php:507
isCorrection()
Определения cashbox.php:488
static getErrorType($errorCode)
Определения cashbox.php:257
static getSettings($modelId=0)
Определения cashbox.php:310
static getGeneralRequiredFields()
Определения cashbox.php:425
const UUID_DELIMITER
Определения cashbox.php:21
static isOfdSettingsNeeded()
Определения cashbox.php:527
const MAX_UUID_LENGTH
Определения cashbox.php:25
static getName()
Определения cashbox.php:193
buildCheckQuery(Check $check)
static getCode()
Определения cashbox.php:42
static getSupportedKkmModels()
Определения cashbox.php:472
validateFields($fields)
Определения cashbox.php:338
const UUID_TYPE_CHECK
Определения cashbox.php:19
static isSupportedFFD105()
Определения cashbox.php:517
static applyZReportResult(array $data)
Определения cashbox.php:299
isRequiredField($field)
Определения cashbox.php:376
static init()
Определения cashbox.php:36
const UUID_TYPE_REPORT
Определения cashbox.php:20
static extractCheckData(array $data)
Определения cashbox.php:267
static create(array $settings)
Определения cashbox.php:135
static applyCheckResult(array $data)
Определения cashbox.php:286
getField($name)
Определения cashbox.php:159
const EVENT_ON_GET_CUSTOM_CASHBOX_HANDLERS
Определения cashbox.php:23
static isSupportedDirectCheckLink()
Определения cashbox.php:522
static isCorrectionOn()
Определения cashbox.php:499
getValueFromSettings($name, $code)
Определения cashbox.php:203
isCheckable()
Определения cashbox.php:480
static create(Cashbox $cashbox)
Определения ofd.php:89
static saveZReportPrintResult($reportId, $data)
Определения reportmanager.php:140
$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
$context
Определения csv_new_setup.php:223
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
Определения backup.php:924
$name
Определения menu_edit.php:35
$map
Определения config.php:5
$settings
Определения product_settings.php:43
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$fields
Определения yandex_run.php:501