61 abstract public static function getType();
71 abstract public static function getName();
92 public static function create($handler)
94 if (class_exists($handler))
96 return new $handler();
107 $this->fields[
'TYPE'] = static::getType();
116 return $this->fields[$name] ??
null;
125 $this->fields[$name] = $value;
133 foreach (
$fields as $name => $value)
144 if (!$this->
getField(
'LINK_PARAMS'))
155 $ofd = $cashbox->getOfd();
161 return $ofd->generateCheckLink($this->
getField(
'LINK_PARAMS'));
177 public function setEntities(array
$entities)
182 $entityRegistryType =
null;
184 foreach ($this->entities as $entity)
186 if ($entity instanceof
Payment)
188 $this->fields[
'PAYMENT_ID'] = $entity->getId();
189 $this->fields[
'SUM'] = $entity->getSum();
190 $this->fields[
'CURRENCY'] = $entity->getField(
'CURRENCY');
196 $this->fields[
'SHIPMENT_ID'] = $entity->getId();
199 if ($entityRegistryType ===
null)
201 $entityRegistryType = $entity::getRegistryType();
203 elseif ($entityRegistryType !== $entity::getRegistryType())
205 throw new Main\ArgumentTypeException(
'entities');
209 $collection = $entity->getCollection();
211 if ($orderId ===
null)
213 $orderId = $collection->getOrder()->getId();
215 elseif ($orderId != $collection->getOrder()->getId())
217 throw new Main\ArgumentTypeException(
'entities');
221 $this->fields[
'ORDER_ID'] = $orderId;
222 $this->fields[
'ENTITY_REGISTRY_TYPE'] = $entityRegistryType;
229 public function getEntities()
238 if ($this->fields[
'ORDER_ID'] > 0)
240 $orderId = $this->fields[
'ORDER_ID'];
242 elseif ($this->fields[
'PAYMENT_ID'] > 0)
245 $paymentClassName = $registry->getPaymentClassName();
246 $dbRes = $paymentClassName::getList([
248 'ID' => $this->fields[
'PAYMENT_ID']
251 $data = $dbRes->fetch();
252 $orderId = $data[
'ORDER_ID'];
254 elseif ($this->fields[
'SHIPMENT_ID'] > 0)
257 $shipmentClassName = $registry->getShipmentClassName();
258 $dbRes = $shipmentClassName::getList([
260 'ID' => $this->fields[
'SHIPMENT_ID']
263 $data = $dbRes->fetch();
264 $orderId = $data[
'ORDER_ID'];
268 throw new Main\SystemException();
273 $orderClassName = $registry->getOrderClassName();
276 $order = $orderClassName::load($orderId);
279 if ($this->fields[
'PAYMENT_ID'] > 0)
281 $payment = $order->getPaymentCollection()->getItemById($this->fields[
'PAYMENT_ID']);
284 $this->entities[] = $payment;
288 if ($this->fields[
'SHIPMENT_ID'] > 0)
290 $shipment = $order->getShipmentCollection()->getItemById($this->fields[
'SHIPMENT_ID']);
293 $this->entities[] = $shipment;
310 return CashboxCheckTable::update($this->fields[
'ID'], $this->fields);
315 $result = CashboxCheckTable::add($this->fields);
316 if (!$result->isSuccess())
321 $checkId = $result->getId();
322 $this->fields[
'ID'] = $checkId;
324 foreach ($this->cashboxList as $cashbox)
327 'CHECK_ID' => $checkId,
328 'CASHBOX_ID' => $cashbox[
'ID']
340 $this->fields[
'CASHBOX_ID'] = $cashboxId;
346 public function init($settings)
348 $this->fields = $settings;
358 $eventHandlerList = Main\EventManager::getInstance()->findEventHandlers(
'sale', self::EVENT_ON_CHECK_PREPARE_DATA);
359 foreach ($eventHandlerList as $event)
361 $result = ExecuteModuleEventEx($event, [$result, static::getType()]);
378 static $vatList = array();
382 if (Main\Loader::includeModule(
'catalog'))
384 $dbRes = Catalog\VatTable::getList(array(
'filter' => array(
'ACTIVE' =>
'Y')));
385 while ($data = $dbRes->fetch())
387 $vatList[(int)$data[
'RATE']] = (
int)$data[
'ID'];
392 if (!isset($vatList[$vatRate]))
397 return $vatList[$vatRate];