1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ofd.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale\Cashbox;
4
5use Bitrix\Main\Localization\Loc;
6use Bitrix\Main\NotImplementedException;
7use Bitrix\Sale\Result;
8use Bitrix\Main;
9
14abstract class Ofd
15{
16 protected const EVENT_ON_GET_CUSTOM_OFD_HANDLERS = 'OnGetCustomOfdHandlers';
17 private const BX_OFD_PREFIX = 'bx_';
18
19 protected Cashbox $cashbox;
20
25 public static function getHandlerList()
26 {
27 $handlerList = self::getSystemHandlerList();
28
29 $event = new Main\Event('sale', static::EVENT_ON_GET_CUSTOM_OFD_HANDLERS);
30 $event->send();
31 $resultList = $event->getResults();
32
33 if (is_array($resultList) && !empty($resultList))
34 {
35 foreach ($resultList as $eventResult)
36 {
38 if ($eventResult->getType() === Main\EventResult::SUCCESS)
39 {
40 $params = $eventResult->getParameters();
41 if (!empty($params) && is_array($params))
42 {
43 $handlerList = array_merge($handlerList, $params);
44 }
45 }
46 }
47 }
48
49 return $handlerList;
50 }
51
55 private static function getSystemHandlerList()
56 {
57 return [
58 '\Bitrix\Sale\Cashbox\FirstOfd' => FirstOfd::getName(),
59 '\Bitrix\Sale\Cashbox\PlatformaOfd' => PlatformaOfd::getName(),
60 '\Bitrix\Sale\Cashbox\YarusOfd' => YarusOfd::getName(),
61 '\Bitrix\Sale\Cashbox\TaxcomOfd' => TaxcomOfd::getName(),
62 '\Bitrix\Sale\Cashbox\OfdruOfd' => OfdruOfd::getName(),
63 '\Bitrix\Sale\Cashbox\TenzorOfd' => TenzorOfd::getName(),
64 '\Bitrix\Sale\Cashbox\ConturOfd' => ConturOfd::getName(),
65 ];
66 }
67
68 final public static function doesHandlerExist(string $handlerClass): bool
69 {
70 return array_key_exists($handlerClass, self::getHandlerList());
71 }
72
73 final public static function getCode(): string
74 {
75 $reflectionOfdClass = new \ReflectionClass(static::class);
76 $code = $reflectionOfdClass->getShortName();
77 $systemHandlers = array_keys(self::getSystemHandlerList());
78 if (in_array('\\' . static::class, $systemHandlers))
79 {
80 $code = self::BX_OFD_PREFIX . $code;
81 }
82 return mb_strtolower($code);
83 }
84
89 public static function create(Cashbox $cashbox)
90 {
91 $handler = $cashbox->getField('OFD');
92 if (is_string($handler) && $handler && self::doesHandlerExist($handler) && class_exists($handler))
93 {
94 return new $handler($cashbox);
95 }
96
97 return null;
98 }
99
104 private function __construct(Cashbox $cashbox)
105 {
106 $this->cashbox = $cashbox;
107 }
108
112 protected function getUrl()
113 {
114 return '';
115 }
116
120 protected function getLinkParamsMap()
121 {
122 return array();
123 }
124
129 public function generateCheckLink($data)
130 {
131 $queryParams = array();
132
133 $map = $this->getLinkParamsMap();
134 foreach ($map as $queryKey => $checkKey)
135 {
136 if ($data[$checkKey])
137 $queryParams[] = $queryKey.'='.$data[$checkKey];
138 }
139
140 if (empty($queryParams))
141 return '';
142
143 $url = $this->getUrl();
144 return $url.implode('&', $queryParams);
145 }
146
151 public static function getName()
152 {
153 throw new NotImplementedException();
154 }
155
159 public static function getSettings()
160 {
161 return array(
162 'OFD_MODE' => array(
163 'LABEL' => Loc::getMessage('SALE_CASHBOX_OFD_SETTINGS'),
164 'ITEMS' => array(
165 'IS_TEST' => array(
166 'TYPE' => 'Y/N',
167 'LABEL' => Loc::getMessage('SALE_CASHBOX_OFD_TEST_MODE'),
168 'VALUE' => 'N'
169 )
170 )
171 )
172 );
173 }
174
179 public function validate()
180 {
181 return new Result();
182 }
183
189 public function getValueFromSettings($name, $code = null)
190 {
191 $map = $this->cashbox->getField('OFD_SETTINGS');
192 if (isset($map[$name]))
193 {
194 if (is_array($map[$name]))
195 {
196 if (isset($map[$name][$code]))
197 return $map[$name][$code];
198 }
199 else
200 {
201 return $map[$name];
202 }
203 }
204
205 return null;
206 }
207
211 protected function isTestMode()
212 {
213 return $this->getValueFromSettings('OFD_MODE', 'IS_TEST') === 'Y';
214 }
215}
Определения event.php:5
static getName()
Определения conturofd.php:31
static getName()
Определения firstofd.php:94
Определения ofd.php:15
validate()
Определения ofd.php:179
static create(Cashbox $cashbox)
Определения ofd.php:89
const EVENT_ON_GET_CUSTOM_OFD_HANDLERS
Определения ofd.php:16
static getName()
Определения ofd.php:151
static getCode()
Определения ofd.php:73
getValueFromSettings($name, $code=null)
Определения ofd.php:189
Cashbox $cashbox
Определения ofd.php:19
generateCheckLink($data)
Определения ofd.php:129
static doesHandlerExist(string $handlerClass)
Определения ofd.php:68
getUrl()
Определения ofd.php:112
isTestMode()
Определения ofd.php:211
static getSettings()
Определения ofd.php:159
getLinkParamsMap()
Определения ofd.php:120
static getName()
Определения ofdruofd.php:31
static getName()
Определения taxcomofd.php:30
static getName()
Определения tenzorofd.php:30
static getName()
Определения yarusofd.php:48
$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
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$name
Определения menu_edit.php:35
$map
Определения config.php:5
$event
Определения prolog_after.php:141
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$url
Определения iframe.php:7