1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
paymentimport.php
См. документацию.
1<?php
2namespace Bitrix\Sale\Exchange\Entity;
3
4use Bitrix\Sale;
5use Bitrix\Sale\Internals;
6use Bitrix\Sale\Order;
7use Bitrix\Sale\Payment;
8use Bitrix\Sale\Exchange;
9use Bitrix\Sale\Exchange\EntityType;
10use Bitrix\Main;
11use Bitrix\Main\Error;
12
19{
25 {
26 if(!($entity instanceof Payment))
27 throw new Main\ArgumentException("Entity must be instanceof Payment");
28
29 $this->entity = $entity;
30 }
31
36 protected function checkFields(array $fields)
37 {
38 $result = new Sale\Result();
39
40 if(intval($fields['ORDER_ID'])<=0 && !$this->isLoadedParentEntity())
41 {
42 $result->addError(new Error('ORDER_ID is not defined',''));
43 }
44
45 return $result;
46 }
47
51 public function save()
52 {
55 return $parentEntity->save();
56 }
57
62 public function add(array $params)
63 {
64 $result = new Sale\Result();
65
66 if(!$this->isLoadedParentEntity())
67 {
68 $result->addError(new Error(GetMessage('SALE_EXCHANGE_ENTITY_PAYMENT_ORDER_IS_NOT_LOADED_ERROR'),'ENTITY_PAYMENT_ORDER_IS_NOT_LOADED_ERROR'));
69 return $result;
70 }
71
72 $fields = $params['TRAITS'];
73
74 if(($paySystem = Sale\PaySystem\Manager::getObjectById($fields['PAY_SYSTEM_ID'])) == null)
75 {
76 $result->addError(new Error(GetMessage('SALE_EXCHANGE_ENTITY_PAYMENT_PAYMENT_SYSTEM_IS_NOT_AVAILABLE_ERROR'),'PAYMENT_SYSTEM_IS_NOT_AVAILABLE_ERROR'));
77 }
78 else
79 {
81 $paymentCollection = $parentEntity->getPaymentCollection();
82 $payment = $paymentCollection->createItem($paySystem);
83 $result = $payment->setFields($fields);
84
85 if($result->isSuccess())
86 {
87 $this->setEntity($payment);
88 }
89 }
90
91 return $result;
92 }
93
98 public function update(array $params)
99 {
101 $payment = $this->getEntity();
102
103 $criterion = $this->getCurrentCriterion($this->getEntity());
104
105 $fields = $params['TRAITS'];
106 if(!$criterion->equals($fields))
107 {
108 unset(
109 $fields['SUM'],
110 $fields['COMMENTS'],
111 $fields['PAY_VOUCHER_DATE'],
112 $fields['PAY_VOUCHER_NUM']
113 );
114 }
115 $result = $payment->setFields($fields);
116
117 return $result;
118 }
119
124 public function delete(array $params = null)
125 {
127 $entity = $this->getEntity();
128 $result = $entity->delete();
129 if($result->isSuccess())
130 {
131 //$this->setCollisions(Exchange\EntityCollisionType::OrderPaymentDeleted, $this->getParentEntity());
132 }
133 else
134 {
135 $this->setCollisions(Exchange\EntityCollisionType::OrderPaymentDeletedError, $this->getParentEntity(), implode(',', $result->getErrorMessages()));
136 }
137
138 return $result;
139 }
140
144 protected function getExternalFieldName()
145 {
146 return 'EXTERNAL_PAYMENT';
147 }
148
154 public function load(array $fields)
155 {
156 $r = $this->checkFields($fields);
157 if(!$r->isSuccess())
158 {
159 throw new Main\ArgumentException('ORDER_ID is not defined');
160 }
161
162 if(!$this->isLoadedParentEntity() && !empty($fields['ORDER_ID']))
163 {
164 $this->setParentEntity(
165 $this->loadParentEntity(['ID'=>$fields['ORDER_ID']])
166 );
167 }
168
169 if($this->isLoadedParentEntity())
170 {
173
174 if(!empty($fields['ID']))
175 {
176 $payment = $parentEntity->getPaymentCollection()->getItemById($fields['ID']);
177 }
178
180 if(!empty($payment))
181 {
182 $this->setEntity($payment);
183 }
184 else
185 {
186 $this->setExternal();
187 }
188 }
189 return new Sale\Result();
190 }
191
195 public function refreshData(array $fields)
196 {
198 $entity = $this->getEntity();
199 if(!empty($entity) && $entity->isPaid())
200 {
201 if($fields['PAID'] == 'N')
202 $entity->setField('PAID', 'N');
203 }
204 }
205
212 {
213 if(!($payment instanceof Payment))
214 throw new Main\ArgumentException("Entity must be instanceof Payment");
215
216 $paySystem = $payment->getPaySystem();
217 $type = $paySystem->getField('IS_CASH');
218
219 return static::resolveEntityTypeIdByCodeType($type);
220 }
221
226 static public function resolveEntityTypeIdByCodeType($type)
227 {
228 switch($type)
229 {
230 case 'Y':
231 $resolveType = EntityType::PAYMENT_CASH;
232 break;
233 case 'N':
234 $resolveType = EntityType::PAYMENT_CASH_LESS;
235 break;
236 case 'A':
238 break;
239 default;
240 $resolveType = EntityType::UNDEFINED;
241 }
242 return $resolveType;
243 }
244
245 public function initFields()
246 {
247 $this->setFields(
248 array(
249 'TRAITS'=>$this->getFieldsTraits(),
250 )
251 );
252 }
253
259 {
260 if(!($entity instanceof Payment))
261 throw new Main\ArgumentException("entity must be instanceof Payment");
262
264 $collection = $entity->getCollection();
265
266 return $collection->getOrder();
267 }
268}
269
271{
272 public function __construct($parentEntityContext = null)
273 {
274 parent::__construct($parentEntityContext);
275 }
276
277 public function getOwnerTypeId()
278 {
280 }
281}
282
284{
285 public function __construct($parentEntityContext = null)
286 {
287 parent::__construct($parentEntityContext);
288 }
289
290 public function getOwnerTypeId()
291 {
293 }
294}
295
297{
298 public function __construct($parentEntityContext = null)
299 {
300 parent::__construct($parentEntityContext);
301 }
302
303 public function getOwnerTypeId()
304 {
306 }
307}
$type
Определения options.php:106
Определения error.php:15
setParentEntity(Sale\Order $parentEntity)
Определения entityimport.php:48
setCollisions($tipeId, Sale\Internals\Entity $entity, $message=null)
Определения entityimport.php:127
setExternal($external=true)
Определения entityimport.php:116
__construct($parentEntityContext=null)
Определения paymentimport.php:298
__construct($parentEntityContext=null)
Определения paymentimport.php:272
__construct($parentEntityContext=null)
Определения paymentimport.php:285
static resolveEntityTypeId(Internals\Entity $payment)
Определения paymentimport.php:211
static resolveEntityTypeIdByCodeType($type)
Определения paymentimport.php:226
setEntity(Internals\Entity $entity)
Определения paymentimport.php:24
checkFields(array $fields)
Определения paymentimport.php:36
const PAYMENT_CASH_LESS
Определения entitytype.php:11
const PAYMENT_CASH
Определения entitytype.php:10
const UNDEFINED
Определения entitytype.php:7
const PAYMENT_CARD_TRANSACTION
Определения entitytype.php:12
setFields(array $values)
Определения importbase.php:132
static getBusinessValueOrderProvider(\Bitrix\Sale\IBusinessValueProvider $entity)
Определения importbase.php:410
Определения payment.php:19
</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
GetMessage($name, $aReplace=null)
Определения tools.php:3397
Определения ufield.php:9
$payment
Определения payment.php:14
$paymentCollection
Определения payment.php:11
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$fields
Определения yandex_run.php:501