Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
converterdocumentpayment.php
1<?php
2
9
10
17{
21 protected function getFieldsInfo()
22 {
24 }
25
31 public function resolveParams($documentImport)
32 {
33 if(!($documentImport instanceof DocumentBase))
34 throw new ArgumentException("Document must be instanceof DocumentBase");
35
36 $result = array();
37
38 $params = $documentImport->getFieldValues();
39
40 $availableFields = array_merge(Payment::getAvailableFields(), array('CASH_BOX_CHECKS'));
41
43 rsort($availableFields);
44
45 foreach ($availableFields as $k)
46 {
47 switch($k)
48 {
49 case 'ID_1C':
50 case 'VERSION_1C':
51 if(isset($params[$k]))
52 $fields[$k] = $params[$k];
53 break;
54 case 'SUM':
55 if(isset($params['AMOUNT']))
56 $fields[$k] = $params['AMOUNT'];
57 break;
58 case 'COMMENTS':
59 if(isset($params['COMMENT']))
60 $fields[$k] = $params['COMMENT'];
61 break;
62 case 'PAY_VOUCHER_DATE':
63 if(isset($params['REK_VALUES']['1C_PAYED_DATE']))
64 $fields[$k] = $params['REK_VALUES']['1C_PAYED_DATE'];
65 break;
66 case 'PAY_VOUCHER_NUM':
67 if(isset($params['REK_VALUES']['1C_PAYED_NUM']))
68 $fields[$k] = $params['REK_VALUES']['1C_PAYED_NUM'];
69 break;
70 case 'PAID':
71 $payed='';
72 $cancel='';
73
74 if(isset($params['REK_VALUES']['1C_PAYED']))
75 $payed = $params['REK_VALUES']['1C_PAYED'];
76 if(isset($params['REK_VALUES']['CANCEL']))
77 $cancel = $params['REK_VALUES']['CANCEL'];
78
79 if($payed == 'Y')
80 $fields[$k] = 'Y';
81 elseif($cancel == 'Y')
82 $fields[$k] = 'N';
83 break;
84 case 'IS_RETURN':
85 if(isset($params['REK_VALUES']['1C_RETURN']))
86 {
87 $value = $params['REK_VALUES']['1C_RETURN'];
88 if($value == 'Y')
89 $fields[$k] = 'Y';
90 }
91 break;
92 case 'PAY_RETURN_COMMENT':
93 if(isset($params['REK_VALUES']['1C_RETURN_REASON']))
94 $fields[$k] = $params['REK_VALUES']['1C_RETURN_REASON'];
95 break;
96 case 'PAY_SYSTEM_ID':
97 $fields[$k] = $this->getPaySystemId($params['REK_VALUES']);
98 break;
99 case 'CASH_BOX_CHECKS':
100 if(is_array($params[$k]))
101 {
102 foreach($params[$k] as $property=>$value)
103 {
104 switch($property)
105 {
106 case 'ID':
107 $cashBoxChecks[$property] = $value;
108 break;
109 case 'CASHBOX_URL':
110 $cashBoxChecks['LINK_PARAMS']['URL'] = $value;
111 break;
112 case 'CASHBOX_FISCAL_SIGN':
113 $cashBoxChecks['LINK_PARAMS']['FISCAL_SIGN'] = $value;
114 break;
115 case 'CASHBOX_REG_NUMBER_KKT':
116 $cashBoxChecks['LINK_PARAMS']['REG_NUMBER_KKT'] = $value;
117 }
118 }
119 }
120 break;
121 }
122 }
123
124 $result['TRAITS'] = isset($fields)? $fields:array();
125 $result['CASH_BOX_CHECKS'] = isset($cashBoxChecks)? $cashBoxChecks:array();
126
127 return $result;
128 }
129
134 public function getPaySystemId($fields)
135 {
136 $paySystemId = 0;
137 if(isset($fields['PAY_SYSTEM_ID']))
138 {
139 $paySystemId = $fields['PAY_SYSTEM_ID'];
140 }
141
142 if($paySystemId<=0)
143 {
144 if(isset($fields['PAY_SYSTEM_ID_DEFAULT']))
145 {
146 $paySystemId = $fields['PAY_SYSTEM_ID_DEFAULT'];
147 }
148 }
150 $settings = $this->getSettings();
151
152 if($paySystemId<=0)
153 {
154 $paySystemId = $settings->paySystemIdFor($this->getEntityTypeId());
155 }
156
157 if($paySystemId<=0)
158 {
159 $paySystemId = $settings->paySystemIdDefaultFor($this->getEntityTypeId());
160 }
161
162 return $paySystemId;
163 }
164
169 static public function sanitizeFields($payment=null, array &$fields, ISettings $settings)
170 {
171 if(!empty($payment) && !($payment instanceof Payment))
172 throw new ArgumentException("Entity must be instanceof Payment");
173
174 foreach($fields as $k=>$v)
175 {
176 switch($k)
177 {
178 case 'AMOUNT':
179 if(!empty($payment) && $payment->isPaid())
180 {
181 unset($fields['SUM']);
182 }
183 break;
184 case 'PAY_SYSTEM_ID':
185 if(!empty($payment))
186 {
187 unset($fields['PAY_SYSTEM_ID']);
188 }
189 break;
190 }
191 }
192
193 if(empty($payment))
194 {
196 $fields['CURRENCY'] = $settings->getCurrency();
197 }
198 unset($fields['ID']);
199 }
200
201 public function externalize(array $fields)
202 {
203 $result = array();
204
205 $traits = $fields['TRAITS'];
206 $businessValue = $fields['BUSINESS_VALUE'];
207 $checks = $fields['CASH_BOX_CHECKS'] ?? [];
208
209 $availableFields = $this->getFieldsInfo();
210
212 $settings = $this->getSettings();
213
214 foreach ($availableFields as $k=>$v)
215 {
216 $value='';
217 switch ($k)
218 {
219 case 'ID':
220 $value = ($traits['ID_1C']<>'' ? $traits['ID_1C']:$traits['ID']);
221 break;
222 case 'NUMBER':
223 $value = $traits['ID'];
224 break;
225 case 'TIME':
226 case 'DATE':
227 $value = $traits['DATE_BILL'];
228 break;
229 case 'OPERATION':
230 $value = DocumentBase::resolveDocumentTypeName($this->getDocmentTypeId());
231 break;
232 case 'ROLE':
233 $value = DocumentBase::getLangByCodeField('SELLER');
234 break;
235 case 'CURRENCY':
236 $replaceCurrency = $settings->getReplaceCurrency();
237 $value = mb_substr($replaceCurrency <> ''? $replaceCurrency : $traits[$k], 0, 3);
238 break;
239 case 'CURRENCY_RATE':
240 $value = self::CURRENCY_RATE_DEFAULT;
241 break;
242 case 'AMOUNT':
243 $value = $traits['SUM'];
244 break;
245 case 'VERSION':
246 $value = $traits['VERSION'];
247 break;
248 case 'NUMBER_BASE':// ?????
249 $value = $traits['ORDER_ID'];
250 break;
251 case 'COMMENT':
252 $value = $traits['COMMENTS'];
253 break;
254 case 'CASH_BOX_CHECKS':
255 if (!empty($checks))
256 {
257 $value = $this->externalizeCashBoxChecksFields(current($checks), $v);
258 }
259 break;
260 case 'REK_VALUES':
261 $value=array();
262 foreach($v['FIELDS'] as $name=>$fieldInfo)
263 {
264 $valueRV='';
265 switch($name)
266 {
267 case '1C_PAYED_DATE':
268 $valueRV = $traits['DATE_PAID'];
269 break;
270 case '1C_PAYED_NUM':
271 $valueRV = $traits['PAY_VOUCHER_NUM'];
272 break;
273 case 'CANCEL':
274 $valueRV = 'N';
275 break;
276 case 'PAY_SYSTEM_ID':
277 $valueRV = $traits['PAY_SYSTEM_ID'];
278 break;
279 case 'PAY_SYSTEM':
280 $valueRV = $traits['PAY_SYSTEM_NAME'];
281 break;
282 case 'PAY_PAID':
283 $valueRV = $traits['PAID'];
284 break;
285 case 'PAY_RETURN':
286 $valueRV = $traits['IS_RETURN'];
287 break;
288 case 'PAY_RETURN_REASON':
289 $valueRV = $traits['PAY_RETURN_COMMENT'];
290 break;
291 case 'SITE_NAME':
292 $valueRV = '['.$traits['LID'].'] '.static::getSiteNameByLid($traits['LID']);
293 break;
294 case 'REKV':
295 $value = array_merge($value, $this->externalizeRekv($businessValue[$name], $fieldInfo));
296 break;
297 }
298 if(!in_array($name, array('REKV')))
299 {
300 $value[] = $this->externalizeRekvValue($name, $valueRV, $fieldInfo);
301 }
302 }
303 break;
304 }
305 if(!in_array($k, array('REK_VALUES', 'CASH_BOX_CHECKS')))
306 {
307 $this->externalizeField($value, $v);
308 }
309
310 $result[$k] = $value;
311 }
312 $result = $this->modifyTrim($result);
313 return $result;
314 }
315
321 protected function externalizeCashBoxChecksFields($fields, array $fieldsInfo)
322 {
323 $result = array();
324 foreach($fieldsInfo['FIELDS'] as $name=>$fieldInfo)
325 {
326 $value='';
327 switch($name)
328 {
329 case 'ID':
330 $value = $fields['ID'];
331 $this->externalizeField($value, $fieldInfo);
332 $result[$name] = $value;
333 break;
334 case 'PROP_VALUES':
335 foreach ($fieldInfo['FIELDS'] as $nameProp=>$fieldInfoProp)
336 {
337 switch ($nameProp)
338 {
339 case 'ID':
340 $value = 'PRINT_CHECK';
341 break;
342 case 'VALUE':
343 $value = 'Y';
344 break;
345 }
346 $this->externalizeField($value, $fieldInfoProp);
347 $result[$name][$nameProp] = $value;
348 }
349 break;
350 }
351 }
352
353 return $result;
354 }
355}
static getAvailableFields()
Definition payment.php:106