22 private $currentPaySystemService;
28 $this->consumerKey = $event->
getParameter(
'CONSUMER_KEY');
38 isset($this->oldMapping[
'PROVIDER_VALUE'], $this->newMapping[
'PROVIDER_VALUE'])
39 && $this->oldMapping[
'PROVIDER_VALUE'] === $this->newMapping[
'PROVIDER_VALUE']
43 if (empty($this->oldMapping) || $valueUnchanged || !$isPaySystemValue)
48 $paySystemIterator = Sale\PaySystem\Manager::getList([
54 while ($paySystemItem = $paySystemIterator->fetch())
56 $this->currentPaySystemService =
new Service($paySystemItem);
57 if ($this->currentPaySystemService->getConsumerName() !== $this->consumerKey || !($this->currentPaySystemService->isSupportPrintCheck()))
63 $cashboxClass = $this->currentPaySystemService->getCashboxClass();
64 $paySystemCodeForKkm = $cashboxClass::getPaySystemCodeForKkm();
65 if ($paySystemCodeForKkm !== $this->codeKey)
70 $cashboxesToChange = $this->getListOfCashboxesToChange();
72 $newKkmId = $this->newMapping[
'PROVIDER_VALUE'];
74 if ($this->valueHasBeenCleared())
76 $newKkmId = $this->getNewKkmId();
86 $this->deleteCashboxesToChange();
90 $existingCashboxes = Sale\Cashbox\Manager::getList([
91 'select' => [
'ID',
'KKM_ID'],
93 '=HANDLER' => $cashboxClass,
94 '=KKM_ID' => $newKkmId,
104 if ($existingCashboxes->fetch())
106 $this->deleteCashboxesToChange();
111 foreach ($cashboxesToChange as $cashboxItem)
113 Sale\Cashbox\Manager::update($cashboxItem[
'ID'], [
'KKM_ID' => $newKkmId]);
117 return new Sale\Result();
126 private function getListOfCashboxesToChange(): Result
128 return Sale\Cashbox\Manager::getList([
129 'select' => [
'ID',
'KKM_ID'],
131 '=HANDLER' => $this->currentPaySystemService->getCashboxClass(),
132 '=KKM_ID' => $this->oldMapping[
'PROVIDER_VALUE'],
137 private function deleteCashboxesToChange(): void
139 $cashboxesToChange = $this->getListOfCashboxesToChange();
140 foreach ($cashboxesToChange as $cashboxItem)
142 $serviceCashbox = Sale\Cashbox\Manager::getObjectById($cashboxItem[
'ID']);
143 $deleteResult = Sale\Cashbox\Manager::delete($cashboxItem[
'ID']);
144 if ($deleteResult->isSuccess())
146 AddEventToStatFile(
'sale',
'deleteCashbox',
'', $serviceCashbox::getCode());
155 private function getNewKkmId()
157 $paySystemCodeForKkm = $this->currentPaySystemService->getCashboxClass()::getPaySystemCodeForKkm();
158 return Sale\BusinessValue::getMapping(
159 $paySystemCodeForKkm,
160 $this->currentPaySystemService->getConsumerName(),
161 BusinessValueTable::COMMON_PERSON_TYPE_ID
170 private function valueHasBeenCleared(): bool
172 return empty($this->newMapping);