Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
creditcheck.php
1<?php
2
3namespace Bitrix\Sale\Cashbox;
4
7
8Main\Localization\Loc::loadMessages(__FILE__);
9
15class CreditCheck extends Check
16{
20 public static function getType()
21 {
22 return 'credit';
23 }
24
28 public static function getName()
29 {
30 return Main\Localization\Loc::getMessage('SALE_CASHBOX_CREDIT_NAME');
31 }
32
36 public static function getCalculatedSign()
37 {
38 return static::CALCULATED_SIGN_INCOME;
39 }
40
44 public static function getSupportedEntityType()
45 {
46 return static::SUPPORTED_ENTITY_TYPE_SHIPMENT;
47 }
48
56 public function setEntities(array $entities)
57 {
58 parent::setEntities($entities);
59
60 foreach ($entities as $entity)
61 {
62 if ($entity instanceof Sale\Shipment)
63 {
64 $this->setField('SHIPMENT_ID', $entity->getId());
65
66 if (!$this->getField('CURRENCY'))
67 {
68 $this->setField('CURRENCY', $entity->getOrder()->getCurrency());
69 }
70
71 $sum = $entity->getPrice();
72 $shipmentItemCollection = $entity->getShipmentItemCollection();
73
75 foreach ($shipmentItemCollection as $item)
76 {
77 $basketItem = $item->getBasketItem();
78 $sum += Sale\PriceMaths::roundPrecision($item->getQuantity() * $basketItem->getPrice());
79 }
80
81 $this->setField('SUM', $sum);
82 }
83 }
84 }
85
89 protected function extractDataInternal()
90 {
91 $result = parent::extractDataInternal();
92
93 $totalSum = 0;
94 if (isset($result['PRODUCTS']))
95 {
96 foreach ($result['PRODUCTS'] as $item)
97 $totalSum += $item['SUM'];
98 }
99
100 if (isset($result['DELIVERY']))
101 {
102 foreach ($result['DELIVERY'] as $item)
103 $totalSum += $item['SUM'];
104 }
105
106 $result['PAYMENTS'] = array(
107 array(
108 'TYPE' => static::PAYMENT_TYPE_CREDIT,
109 'SUM' => $totalSum
110 )
111 );
112
113 $result['TOTAL_SUM'] = $totalSum;
114
115 return $result;
116 }
117
121 public static function getSupportedRelatedEntityType()
122 {
123 return static::SUPPORTED_ENTITY_TYPE_NONE;
124 }
125
126}