Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
deletecashboxesondeletepaysystem.php
1<?php
2
4
6
8{
10 private $service;
11
12 public function __construct(Sale\PaySystem\Service $service)
13 {
14 $this->service = $service;
15 }
16
20 public function executeEvent(): Sale\Result
21 {
22 $result = new Sale\Result();
23
24 if (!$this->service || !$this->service->isSupportPrintCheck())
25 {
26 return $result;
27 }
28
30 $cashboxClass = $this->service->getCashboxClass();
31 $supportedKkmModels = [];
32
33 $paySystemIterator = Sale\PaySystem\Manager::getList([
34 'filter' => [
35 '=ACTIVE' => 'Y',
36 ]
37 ]);
38 while ($paySystemItem = $paySystemIterator->fetch())
39 {
40 $paySystemService = new Sale\PaySystem\Service($paySystemItem);
41 if (
42 $paySystemService->isSupportPrintCheck()
43 && $paySystemService->getCashboxClass() === $cashboxClass
44 )
45 {
46 $supportedKkmModels[] = $cashboxClass::getKkmValue($this->service);
47 }
48 }
49
50 $supportedKkmModels = array_unique(array_merge(...$supportedKkmModels));
51
52 $cashboxList = Sale\Cashbox\Manager::getList([
53 'select' => ['ID', 'KKM_ID'],
54 'filter' => [
55 '=HANDLER' => $cashboxClass,
56 '!@KKM_ID' => $supportedKkmModels,
57 ],
58 ]);
59 foreach ($cashboxList as $cashboxItem)
60 {
61 $serviceCashbox = Sale\Cashbox\Manager::getObjectById($cashboxItem['ID']);
62 $deleteResult = Sale\Cashbox\Manager::delete($cashboxItem['ID']);
63 if ($deleteResult->isSuccess())
64 {
65 AddEventToStatFile('sale', 'deleteCashbox', '', $serviceCashbox::getCode());
66 }
67 else
68 {
69 $result->addErrors($deleteResult->getErrors());
70 }
71 }
72
73 return $result;
74 }
75}