Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
cashboxbitrixv2.php
1<?php
2
3namespace Bitrix\Sale\Cashbox;
4
8
9Localization\Loc::loadMessages(__FILE__);
10
16{
17 const CODE_VAT_0 = 'vat0';
18 const CODE_VAT_10 = 'vat10';
19 const CODE_VAT_20 = 'vat20';
20 const CODE_CALC_VAT_10 = 'vat110';
21 const CODE_CALC_VAT_20 = 'vat120';
22
36 public function buildCheckQuery(Check $check)
37 {
38 $data = $check->getDataForCheck();
39
41 $dateTime = $data['date_create'];
42
43 $phone = \NormalizePhone($data['client_phone']);
44 if (is_string($phone))
45 {
46 if ($phone[0] === '7')
47 $phone = '+'.$phone;
48 }
49 else
50 {
51 $phone = '';
52 }
53
54 $client = $data['client_email'];
55 if ($this->getValueFromSettings('CLIENT', 'INFO') === 'PHONE'
56 && $phone
57 )
58 {
59 $client = $phone;
60 }
61
62 $result = [
63 'type' => $check::getCalculatedSign() === Check::CALCULATED_SIGN_INCOME ? 'sell' : 'sellReturn',
64 'timestamp' => $dateTime->format('d.m.Y H:i:s'),
65 'external_id' => static::buildUuid(static::UUID_TYPE_CHECK, $data['unique_id']),
66 'taxationType' => $this->getValueFromSettings('TAX', 'SNO'),
67 'zn' => (string)$this->getField('NUMBER_KKM'),
68 'clientInfo' => [
69 'emailOrPhone' => $client,
70 ],
71 'payments' => [],
72 'items' => [],
73 'total' => (float)$data['total_sum']
74 ];
75
76 foreach ($data['payments'] as $payment)
77 {
78 $result['payments'][] = [
79 'type' => $this->getValueFromSettings('PAYMENT_TYPE', $payment['type']),
80 'sum' => (float)$payment['sum']
81 ];
82 }
83
84 foreach ($data['items'] as $item)
85 {
86 $result['items'][] = $this->buildPosition($data, $item);
87 }
88
89 return $result;
90 }
91
92 protected function buildPosition(array $checkData, array $item)
93 {
94 $checkTypeMap = $this->getCheckTypeMap();
95 $paymentObjectMap = $this->getPaymentObjectMap();
96
97 $vat = $this->getValueFromSettings('VAT', $item['vat']);
98 if ($vat === null)
99 {
100 $vat = $this->getValueFromSettings('VAT', 'NOT_VAT');
101 }
102
103 $position = [
104 'type' => 'position',
105 'name' => $item['name'],
106 'price' => (float)$item['price'],
107 'quantity' => $item['quantity'],
108 'amount' => (float)$item['sum'],
109 'paymentMethod' => $checkTypeMap[$checkData['type']],
110 'paymentObject' => $paymentObjectMap[$item['payment_object']],
111 'tax' => [
112 'type' => $this->mapVatValue($checkData['type'], $vat)
113 ],
114 ];
115
116 if (isset($item['supplier_info']))
117 {
118 $position['supplierInfo'] = [
119 'phones' => $item['supplier_info']['phones'],
120 'name' => $item['supplier_info']['name'],
121 'vatin' => $item['supplier_info']['inn']
122 ];
123 }
124
125 if (isset($item['nomenclature_code']))
126 {
127 $position['nomenclatureCode'] = base64_encode($item['nomenclature_code']);
128 }
129
130 return $position;
131 }
132
161
165 protected function getPaymentObjectMap()
166 {
167 return [
168 Check::PAYMENT_OBJECT_COMMODITY => 'commodity',
173 Check::PAYMENT_OBJECT_GAMBLING_BET => 'gamblingBet',
174 Check::PAYMENT_OBJECT_GAMBLING_PRIZE => 'gamblingPrize',
176 Check::PAYMENT_OBJECT_LOTTERY_PRIZE => 'lotteryPrize',
177 Check::PAYMENT_OBJECT_INTELLECTUAL_ACTIVITY => 'intellectualActivity',
178 Check::PAYMENT_OBJECT_AGENT_COMMISSION => 'agentCommission',
179 Check::PAYMENT_OBJECT_COMPOSITE => 'composite',
181 Check::PAYMENT_OBJECT_PROPERTY_RIGHT => 'proprietaryLaw',
182 Check::PAYMENT_OBJECT_NON_OPERATING_GAIN => 'nonOperatingIncome',
183 Check::PAYMENT_OBJECT_SALES_TAX => 'merchantTax',
189 ];
190 }
191
195 public static function getName()
196 {
197 return Localization\Loc::getMessage('SALE_CASHBOX_BITRIX_V2_TITLE');
198 }
199
200
204 protected function getCheckTypeMap()
205 {
206 return [
207 SellCheck::getType() => 'fullPayment',
208 SellReturnCashCheck::getType() => 'fullPayment',
209 SellReturnCheck::getType() => 'fullPayment',
210 AdvancePaymentCheck::getType() => 'advance',
211 AdvanceReturnCashCheck::getType() => 'advance',
212 AdvanceReturnCheck::getType() => 'advance',
213 CreditCheck::getType() => 'credit',
214 CreditReturnCheck::getType() => 'credit',
215 CreditPaymentCheck::getType() => 'creditPayment',
216 CreditPaymentReturnCashCheck::getType() => 'creditPayment',
217 CreditPaymentReturnCheck::getType() => 'creditPayment',
218 PrepaymentCheck::getType() => 'prepayment',
219 PrepaymentReturnCheck::getType() => 'prepayment',
220 PrepaymentReturnCashCheck::getType() => 'prepayment',
221 FullPrepaymentCheck::getType() => 'fullPrepayment',
222 FullPrepaymentReturnCheck::getType() => 'fullPrepayment',
223 FullPrepaymentReturnCashCheck::getType() => 'fullPrepayment',
224 ];
225 }
226
231 public static function getSettings($modelId = 0)
232 {
233 $settings = parent::getSettings($modelId);
234
235 $kkmList = static::getSupportedKkmModels();
236 if (isset($kkmList[$modelId]))
237 {
238 $settings['TAX'] = [
239 'LABEL' => Localization\Loc::getMessage('SALE_CASHBOX_BITRIX_V2_SETTINGS_SNO'),
240 'REQUIRED' => 'Y',
241 'ITEMS' => [
242 'SNO' => [
243 'TYPE' => 'ENUM',
244 'LABEL' => Localization\Loc::getMessage('SALE_CASHBOX_BITRIX_V2_SETTINGS_SNO_LABEL'),
245 'VALUE' => 'osn',
246 'OPTIONS' => [
247 'osn' => Localization\Loc::getMessage('SALE_CASHBOX_BITRIX_V2_SNO_OSN'),
248 'usnIncome' => Localization\Loc::getMessage('SALE_CASHBOX_BITRIX_V2_SNO_UI'),
249 'usnIncomeOutcome' => Localization\Loc::getMessage('SALE_CASHBOX_BITRIX_V2_SNO_UIO'),
250 'envd' => Localization\Loc::getMessage('SALE_CASHBOX_BITRIX_V2_SNO_ENVD'),
251 'esn' => Localization\Loc::getMessage('SALE_CASHBOX_BITRIX_V2_SNO_ESN'),
252 'patent' => Localization\Loc::getMessage('SALE_CASHBOX_BITRIX_V2_SNO_PATENT')
253 ]
254 ]
255 ]
256 ];
257 }
258
259 $settings['CLIENT'] = [
260 'LABEL' => Localization\Loc::getMessage('SALE_CASHBOX_BITRIX_V2_SETTINGS_CLIENT'),
261 'ITEMS' => [
262 'INFO' => [
263 'TYPE' => 'ENUM',
264 'VALUE' => 'NONE',
265 'LABEL' => Localization\Loc::getMessage('SALE_CASHBOX_BITRIX_V2_SETTINGS_CLIENT_INFO'),
266 'OPTIONS' => [
267 'EMAIL' => Localization\Loc::getMessage('SALE_CASHBOX_BITRIX_V2_SETTINGS_CLIENT_EMAIL'),
268 'PHONE' => Localization\Loc::getMessage('SALE_CASHBOX_BITRIX_V2_SETTINGS_CLIENT_PHONE'),
269 ]
270 ],
271 ]
272 ];
273
274 return $settings;
275 }
276
281 public static function extractSettingsFromRequest(Main\HttpRequest $request)
282 {
283 return $request->get('SETTINGS');
284 }
285
289 public static function getSupportedKkmModels()
290 {
291 return [
292 'atol' => [
293 'NAME' => 'ATOL',
294 'SETTINGS' => [
295 'VAT' => [
296 'NOT_VAT' => 'none',
297 0 => self::CODE_VAT_0,
298 10 => self::CODE_VAT_10,
300 ],
301 'PAYMENT_TYPE' => [
302 Check::PAYMENT_TYPE_CASH => 'cash',
303 Check::PAYMENT_TYPE_CASHLESS => 'electronically',
304 Check::PAYMENT_TYPE_ADVANCE => 'prepaid',
306 ]
307 ]
308 ],
309 ];
310 }
311
315 public static function getFfdVersion(): ?float
316 {
317 return 1.05;
318 }
319
328 public static function getCashboxList(array $data)
329 {
330 $result = parent::getCashboxList($data);
331
332 foreach ($result as $zn => $cashbox)
333 {
334 if (!isset($cashbox['ID']))
335 {
336 continue;
337 }
338
339 $current = Manager::getCashboxFromCache($cashbox['ID']);
340
341 if ($current['HANDLER'] !== '\\'.static::class)
342 {
343 $cashbox['HANDLER'] = '\\'.static::class;
344 $cashbox['SETTINGS'] = static::convertSettings($cashbox['KKM_ID'], $cashbox['SETTINGS']);
345
346 $result[$zn] = $cashbox;
347 }
348 }
349
350 return $result;
351 }
352
362 protected static function convertSettings($kkmId, array $settings)
363 {
364 $result = [];
365
366 $currentModel = static::getSupportedKkmModels()[$kkmId];
367
368 foreach ($settings as $key => $setting)
369 {
370 if ($key === 'PAYMENT_TYPE')
371 {
372 $result[$key] = $currentModel['SETTINGS']['PAYMENT_TYPE'];
373 }
374 elseif ($key === 'VAT')
375 {
376 $result[$key]['NOT_VAT']= $currentModel['SETTINGS']['VAT']['NOT_VAT'];
377
378 if (Main\Loader::includeModule('catalog'))
379 {
380 $dbRes = Catalog\VatTable::getList(array('filter' => array('ACTIVE' => 'Y')));
381 $vatList = $dbRes->fetchAll();
382 if ($vatList)
383 {
384 foreach ($vatList as $vat)
385 {
386 if (isset($currentModel['SETTINGS']['VAT'][(int)$vat['RATE']]))
387 {
388 $result[$key][(int)$vat['ID']] = $currentModel['SETTINGS']['VAT'][(int)$vat['RATE']];
389 }
390 else
391 {
392 $result[$key][(int)$vat['ID']] = $currentModel['SETTINGS']['VAT']['NOT_VAT'];
393 }
394 }
395 }
396 }
397 }
398 else
399 {
400 $result[$key] = $setting;
401 }
402 }
403
404 return $result;
405 }
406}
static extractSettingsFromRequest(Main\HttpRequest $request)
buildPosition(array $checkData, array $item)
static convertSettings($kkmId, array $settings)
buildCheckQuery(Check $check)
getValueFromSettings($name, $code)
Definition cashbox.php:201
const PAYMENT_OBJECT_LOTTERY_PRIZE
Definition check.php:32
const PAYMENT_OBJECT_COMMODITY_MARKING_EXCISE
Definition check.php:50
const PAYMENT_OBJECT_NON_OPERATING_GAIN
Definition check.php:38
const PAYMENT_OBJECT_COMMODITY_MARKING_NO_MARKING_EXCISE
Definition check.php:49
const PAYMENT_OBJECT_RESORT_FEE
Definition check.php:40
const PAYMENT_OBJECT_PROPERTY_RIGHT
Definition check.php:37
const PAYMENT_OBJECT_GAMBLING_PRIZE
Definition check.php:30
const PAYMENT_OBJECT_COMMODITY_MARKING
Definition check.php:52
const PAYMENT_OBJECT_AGENT_COMMISSION
Definition check.php:34
const PAYMENT_OBJECT_INTELLECTUAL_ACTIVITY
Definition check.php:33
const PAYMENT_OBJECT_GAMBLING_BET
Definition check.php:29
const PAYMENT_OBJECT_COMMODITY_MARKING_NO_MARKING
Definition check.php:51
static getCashboxFromCache($cashboxId)
Definition manager.php:268