1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
abstractcheck.php
См. документацию.
1<?php
2
4
9use Bitrix\Sale\Order;
16
21abstract class AbstractCheck
22{
23 public const PARAM_FISCAL_DOC_NUMBER = 'fiscal_doc_number';
24 public const PARAM_FISCAL_DOC_ATTR = 'fiscal_doc_attribute';
25 public const PARAM_FISCAL_RECEIPT_NUMBER = 'fiscal_receipt_number';
26 public const PARAM_FN_NUMBER = 'fn_number';
27 public const PARAM_SHIFT_NUMBER = 'shift_number';
28 public const PARAM_REG_NUMBER_KKT = 'reg_number_kkt';
29 public const PARAM_DOC_TIME = 'doc_time';
30 public const PARAM_DOC_SUM = 'doc_sum';
31 public const PARAM_CALCULATION_ATTR = 'calculation_attribute';
32 public const PARAM_OFD_RECEIPT_URL = 'ofd_receipt_url';
33
34 public const CALCULATED_SIGN_INCOME = 'income';
35 public const CALCULATED_SIGN_CONSUMPTION = 'consumption';
36
37 public const SHIPMENT_TYPE_NONE = '';
38 public const PAYMENT_TYPE_CASH = 'cash';
39 public const PAYMENT_TYPE_ADVANCE = 'advance';
40 public const PAYMENT_TYPE_CASHLESS = 'cashless';
41 public const PAYMENT_TYPE_CREDIT = 'credit';
42
43 public const SUPPORTED_ENTITY_TYPE_PAYMENT = 'payment';
44 public const SUPPORTED_ENTITY_TYPE_SHIPMENT = 'shipment';
45 public const SUPPORTED_ENTITY_TYPE_ALL = 'all';
46 public const SUPPORTED_ENTITY_TYPE_NONE = 'none';
47
48 protected const EVENT_ON_CHECK_PREPARE_DATA = 'OnSaleCheckPrepareData';
49
51 protected $fields = array();
52
54 protected $cashboxList = array();
55
57 protected $entities = array();
58
62 abstract public static function getType();
63
67 abstract public static function getCalculatedSign();
68
72 abstract public static function getName();
73
77 abstract public function getDataForCheck();
78
82 abstract protected function extractDataInternal();
83
87 abstract static function getSupportedEntityType();
88
93 public static function create($handler)
94 {
95 if (class_exists($handler))
96 {
97 return new $handler();
98 }
99
100 return null;
101 }
102
106 protected function __construct()
107 {
108 $this->fields['TYPE'] = static::getType();
109 }
110
115 public function getField($name)
116 {
117 return $this->fields[$name] ?? null;
118 }
119
124 public function setField($name, $value)
125 {
126 $this->fields[$name] = $value;
127 }
128
132 public function setFields($fields)
133 {
134 foreach ($fields as $name => $value)
135 {
136 $this->setField($name, $value);
137 }
138 }
139
143 public function getUrl()
144 {
145 if (!$this->getField('LINK_PARAMS'))
146 {
147 return '';
148 }
149
150 $cashbox = Manager::getObjectById($this->getField('CASHBOX_ID'));
151 if (!$cashbox)
152 {
153 return '';
154 }
155
156 return $cashbox->getCheckLink($this->getField('LINK_PARAMS'));
157 }
158
163 {
164 $this->cashboxList = $cashboxList;
165 }
166
172 public function setEntities(array $entities)
173 {
174 $this->entities = $entities;
175
176 $orderId = null;
177 $entityRegistryType = null;
178
179 foreach ($this->entities as $entity)
180 {
181 if ($entity instanceof Payment)
182 {
183 $this->fields['PAYMENT_ID'] = $entity->getId();
184 $this->fields['SUM'] = $entity->getSum();
185 $this->fields['CURRENCY'] = $entity->getField('CURRENCY');
186 }
187
188 // compatibility
189 if ($entity instanceof Shipment)
190 {
191 $this->fields['SHIPMENT_ID'] = $entity->getId();
192 }
193
194 if ($entityRegistryType === null)
195 {
196 $entityRegistryType = $entity::getRegistryType();
197 }
198 elseif ($entityRegistryType !== $entity::getRegistryType())
199 {
200 throw new Main\ArgumentTypeException('entities');
201 }
202
204 $collection = $entity->getCollection();
205
206 if ($orderId === null)
207 {
208 $orderId = $collection->getOrder()->getId();
209 }
210 elseif ($orderId != $collection->getOrder()->getId())
211 {
212 throw new Main\ArgumentTypeException('entities');
213 }
214 }
215
216 $this->fields['ORDER_ID'] = $orderId;
217 $this->fields['ENTITY_REGISTRY_TYPE'] = $entityRegistryType;
218 }
219
224 public function getEntities()
225 {
226 if ($this->entities)
227 {
228 return $this->entities;
229 }
230
231 $registry = Registry::getInstance($this->fields['ENTITY_REGISTRY_TYPE']);
232
233 if ($this->fields['ORDER_ID'] > 0)
234 {
235 $orderId = $this->fields['ORDER_ID'];
236 }
237 elseif ($this->fields['PAYMENT_ID'] > 0)
238 {
240 $paymentClassName = $registry->getPaymentClassName();
241 $dbRes = $paymentClassName::getList([
242 'filter' => [
243 'ID' => $this->fields['PAYMENT_ID']
244 ]
245 ]);
246 $data = $dbRes->fetch();
247 $orderId = $data['ORDER_ID'];
248 }
249 elseif ($this->fields['SHIPMENT_ID'] > 0)
250 {
252 $shipmentClassName = $registry->getShipmentClassName();
253 $dbRes = $shipmentClassName::getList([
254 'filter' => [
255 'ID' => $this->fields['SHIPMENT_ID']
256 ]
257 ]);
258 $data = $dbRes->fetch();
259 $orderId = $data['ORDER_ID'];
260 }
261 else
262 {
263 throw new Main\SystemException();
264 }
265
266 if ($orderId > 0)
267 {
268 $orderClassName = $registry->getOrderClassName();
269
271 $order = $orderClassName::load($orderId);
272 if ($order)
273 {
274 if ($this->fields['PAYMENT_ID'] > 0)
275 {
276 $payment = $order->getPaymentCollection()->getItemById($this->fields['PAYMENT_ID']);
277 if ($payment)
278 {
279 $this->entities[] = $payment;
280 }
281 }
282
283 if ($this->fields['SHIPMENT_ID'] > 0)
284 {
285 $shipment = $order->getShipmentCollection()->getItemById($this->fields['SHIPMENT_ID']);
286 if ($shipment)
287 {
288 $this->entities[] = $shipment;
289 }
290 }
291 }
292 }
293
294 return $this->entities;
295 }
296
301 public function save()
302 {
303 if ((int)$this->getField('ID') > 0)
304 {
305 return CashboxCheckTable::update($this->fields['ID'], $this->fields);
306 }
307
308 $this->fields['DATE_CREATE'] = new Main\Type\DateTime();
309
310 $result = CashboxCheckTable::add($this->fields);
311 if (!$result->isSuccess())
312 {
313 return $result;
314 }
315
316 $checkId = $result->getId();
317 $this->fields['ID'] = $checkId;
318
319 foreach ($this->cashboxList as $cashbox)
320 {
322 'CHECK_ID' => $checkId,
323 'CASHBOX_ID' => $cashbox['ID']
324 ]);
325 }
326
327 return $result;
328 }
329
333 public function linkCashbox($cashboxId)
334 {
335 $this->fields['CASHBOX_ID'] = $cashboxId;
336 }
337
341 public function init($settings)
342 {
343 $this->fields = $settings;
344 }
345
349 protected function extractData()
350 {
351 $result = $this->extractDataInternal();
352
353 $eventHandlerList = Main\EventManager::getInstance()->findEventHandlers('sale', self::EVENT_ON_CHECK_PREPARE_DATA);
354 foreach ($eventHandlerList as $event)
355 {
356 $result = ExecuteModuleEventEx($event, [$result, static::getType()]);
357 }
358
359 return $result;
360 }
361
362
371 protected function getVatIdByVatRate($vatRate)
372 {
373 static $vatList = array();
374
375 if (!$vatList)
376 {
377 if (Main\Loader::includeModule('catalog'))
378 {
379 $dbRes = Catalog\VatTable::getList(array('filter' => array('ACTIVE' => 'Y')));
380 while ($data = $dbRes->fetch())
381 {
382 $vatList[(int)$data['RATE']] = (int)$data['ID'];
383 }
384 }
385 }
386
387 if (!isset($vatList[$vatRate]))
388 {
389 return 0;
390 }
391
392 return $vatList[$vatRate];
393 }
394}
static getInstance()
Определения eventmanager.php:31
static getList(array $parameters=array())
Определения datamanager.php:431
static add(array $data)
Определения datamanager.php:877
setAvailableCashbox(array $cashboxList)
Определения abstractcheck.php:162
const CALCULATED_SIGN_INCOME
Определения abstractcheck.php:34
const EVENT_ON_CHECK_PREPARE_DATA
Определения abstractcheck.php:48
const PARAM_CALCULATION_ATTR
Определения abstractcheck.php:31
const SUPPORTED_ENTITY_TYPE_ALL
Определения abstractcheck.php:45
const SUPPORTED_ENTITY_TYPE_SHIPMENT
Определения abstractcheck.php:44
getVatIdByVatRate($vatRate)
Определения abstractcheck.php:371
const PARAM_FISCAL_DOC_ATTR
Определения abstractcheck.php:24
const PARAM_FISCAL_DOC_NUMBER
Определения abstractcheck.php:23
const CALCULATED_SIGN_CONSUMPTION
Определения abstractcheck.php:35
const SUPPORTED_ENTITY_TYPE_NONE
Определения abstractcheck.php:46
static create($handler)
Определения abstractcheck.php:93
const PARAM_OFD_RECEIPT_URL
Определения abstractcheck.php:32
linkCashbox($cashboxId)
Определения abstractcheck.php:333
setField($name, $value)
Определения abstractcheck.php:124
const PARAM_FISCAL_RECEIPT_NUMBER
Определения abstractcheck.php:25
const SUPPORTED_ENTITY_TYPE_PAYMENT
Определения abstractcheck.php:43
const PAYMENT_TYPE_CASHLESS
Определения abstractcheck.php:40
static getObjectById($id)
Определения manager.php:165
Определения payment.php:19
static getInstance($type)
Определения registry.php:183
$data['IS_AVAILABLE']
Определения .description.php:13
$orderId
Определения payment.php:5
</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
$entity
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
$name
Определения menu_edit.php:35
$payment
Определения payment.php:14
$order
Определения payment.php:8
$settings
Определения product_settings.php:43
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$dbRes
Определения yandex_detail.php:168
$vatList
Определения yandex_run.php:916