38 $params = $documentImport->getFieldValues();
43 rsort($availableFields);
45 foreach ($availableFields as $k)
51 if(isset($params[$k]))
52 $fields[$k] = $params[$k];
55 if(isset($params[
'AMOUNT']))
56 $fields[$k] = $params[
'AMOUNT'];
59 if(isset($params[
'COMMENT']))
60 $fields[$k] = $params[
'COMMENT'];
62 case 'PAY_VOUCHER_DATE':
63 if(isset($params[
'REK_VALUES'][
'1C_PAYED_DATE']))
64 $fields[$k] = $params[
'REK_VALUES'][
'1C_PAYED_DATE'];
66 case 'PAY_VOUCHER_NUM':
67 if(isset($params[
'REK_VALUES'][
'1C_PAYED_NUM']))
68 $fields[$k] = $params[
'REK_VALUES'][
'1C_PAYED_NUM'];
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'];
81 elseif($cancel ==
'Y')
85 if(isset($params[
'REK_VALUES'][
'1C_RETURN']))
87 $value = $params[
'REK_VALUES'][
'1C_RETURN'];
92 case 'PAY_RETURN_COMMENT':
93 if(isset($params[
'REK_VALUES'][
'1C_RETURN_REASON']))
94 $fields[$k] = $params[
'REK_VALUES'][
'1C_RETURN_REASON'];
97 $fields[$k] = $this->getPaySystemId($params[
'REK_VALUES']);
99 case 'CASH_BOX_CHECKS':
100 if(is_array($params[$k]))
102 foreach($params[$k] as $property=>$value)
107 $cashBoxChecks[$property] = $value;
110 $cashBoxChecks[
'LINK_PARAMS'][
'URL'] = $value;
112 case 'CASHBOX_FISCAL_SIGN':
113 $cashBoxChecks[
'LINK_PARAMS'][
'FISCAL_SIGN'] = $value;
115 case 'CASHBOX_REG_NUMBER_KKT':
116 $cashBoxChecks[
'LINK_PARAMS'][
'REG_NUMBER_KKT'] = $value;
124 $result[
'TRAITS'] = isset($fields)? $fields:array();
125 $result[
'CASH_BOX_CHECKS'] = isset($cashBoxChecks)? $cashBoxChecks:array();
134 public function getPaySystemId($fields)
137 if(isset($fields[
'PAY_SYSTEM_ID']))
139 $paySystemId = $fields[
'PAY_SYSTEM_ID'];
144 if(isset($fields[
'PAY_SYSTEM_ID_DEFAULT']))
146 $paySystemId = $fields[
'PAY_SYSTEM_ID_DEFAULT'];
150 $settings = $this->getSettings();
154 $paySystemId = $settings->paySystemIdFor($this->getEntityTypeId());
159 $paySystemId = $settings->paySystemIdDefaultFor($this->getEntityTypeId());
169 static public function sanitizeFields($payment=
null, array &$fields, ISettings $settings)
171 if(!empty($payment) && !($payment instanceof Payment))
172 throw new ArgumentException(
"Entity must be instanceof Payment");
174 foreach($fields as $k=>$v)
179 if(!empty($payment) && $payment->isPaid())
181 unset($fields[
'SUM']);
184 case 'PAY_SYSTEM_ID':
187 unset($fields[
'PAY_SYSTEM_ID']);
196 $fields[
'CURRENCY'] = $settings->getCurrency();
198 unset($fields[
'ID']);
201 public function externalize(array $fields)
205 $traits = $fields[
'TRAITS'];
206 $businessValue = $fields[
'BUSINESS_VALUE'];
207 $checks = $fields[
'CASH_BOX_CHECKS'] ?? [];
214 foreach ($availableFields as $k=>$v)
220 $value = ($traits[
'ID_1C']<>
'' ? $traits[
'ID_1C']:$traits[
'ID']);
223 $value = $traits[
'ID'];
227 $value = $traits[
'DATE_BILL'];
236 $replaceCurrency = $settings->getReplaceCurrency();
237 $value = mb_substr($replaceCurrency <>
''? $replaceCurrency : $traits[$k], 0, 3);
239 case 'CURRENCY_RATE':
240 $value = self::CURRENCY_RATE_DEFAULT;
243 $value = $traits[
'SUM'];
246 $value = $traits[
'VERSION'];
249 $value = $traits[
'ORDER_ID'];
252 $value = $traits[
'COMMENTS'];
254 case 'CASH_BOX_CHECKS':
262 foreach($v[
'FIELDS'] as $name=>$fieldInfo)
267 case '1C_PAYED_DATE':
268 $valueRV = $traits[
'DATE_PAID'];
271 $valueRV = $traits[
'PAY_VOUCHER_NUM'];
276 case 'PAY_SYSTEM_ID':
277 $valueRV = $traits[
'PAY_SYSTEM_ID'];
280 $valueRV = $traits[
'PAY_SYSTEM_NAME'];
283 $valueRV = $traits[
'PAID'];
286 $valueRV = $traits[
'IS_RETURN'];
288 case 'PAY_RETURN_REASON':
289 $valueRV = $traits[
'PAY_RETURN_COMMENT'];
292 $valueRV =
'['.$traits[
'LID'].
'] '.static::getSiteNameByLid($traits[
'LID']);
295 $value = array_merge($value, $this->externalizeRekv($businessValue[$name], $fieldInfo));
298 if(!in_array($name, array(
'REKV')))
300 $value[] = $this->externalizeRekvValue($name, $valueRV, $fieldInfo);
305 if(!in_array($k, array(
'REK_VALUES',
'CASH_BOX_CHECKS')))
307 $this->externalizeField($value, $v);
310 $result[$k] = $value;
312 $result = $this->modifyTrim($result);
324 foreach($fieldsInfo[
'FIELDS'] as $name=>$fieldInfo)
330 $value = $fields[
'ID'];
331 $this->externalizeField($value, $fieldInfo);
332 $result[$name] = $value;
335 foreach ($fieldInfo[
'FIELDS'] as $nameProp=>$fieldInfoProp)
340 $value =
'PRINT_CHECK';
346 $this->externalizeField($value, $fieldInfoProp);
347 $result[$name][$nameProp] = $value;