Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
vat.php
1<?php
2
3
5
6
14
18final class Vat extends Controller
19{
20 //region Actions
21
26 public function addAction(array $fields): ?array
27 {
28 $application = self::getApplication();
29 $application->ResetException();
30
31 $addResult = \CCatalogVat::Add($fields);
32 if (!$addResult)
33 {
34 if ($application->GetException())
35 {
36 $this->addError(new Error($application->GetException()->GetString()));
37 }
38 else
39 {
40 $this->addError(new Error('Error adding VAT'));
41 }
42
43 return null;
44 }
45
46 return ['VAT' => $this->get($addResult)];
47 }
48
54 public function updateAction(int $id, array $fields): ?array
55 {
56 $existsResult = $this->exists($id);
57 if (!$existsResult->isSuccess())
58 {
59 $this->addErrors($existsResult->getErrors());
60
61 return null;
62 }
63
64 $updateResult = \CCatalogVat::Update($id, $fields);
65 if (!$updateResult)
66 {
67 $this->addError(new Error('Error updating VAT'));
68
69 return null;
70 }
71
72 return ['VAT' => $this->get($id)];
73 }
74
79 public function deleteAction(int $id): ?bool
80 {
81 $existsResult = $this->exists($id);
82 if (!$existsResult->isSuccess())
83 {
84 $this->addErrors($existsResult->getErrors());
85
86 return null;
87 }
88
89 $deleteResult = \CCatalogVat::Delete($id);
90 if (!$deleteResult)
91 {
92 $this->addError(new Error('Error deleting VAT'));
93
94 return null;
95 }
96
97 return true;
98 }
99
103 public function getFieldsAction(): array
104 {
105 return ['VAT' => $this->getViewFields()];
106 }
107
115 public function listAction(PageNavigation $pageNavigation, array $select = [], array $filter = [], array $order = []): Page
116 {
117 return new Page(
118 'VATS',
119 $this->getList($select, $filter, $order, $pageNavigation),
120 $this->count($filter)
121 );
122 }
123
128 public function getAction($id): ?array
129 {
130 $r = $this->exists($id);
131 if($r->isSuccess())
132 {
133 return ['VAT' => $this->get($id)];
134 }
135 else
136 {
137 $this->addErrors($r->getErrors());
138
139 return null;
140 }
141 }
142 //endregion
143
147 protected function exists($id)
148 {
149 $r = new Result();
150 if (!isset($this->get($id)['ID']))
151 {
152 $r->addError(new Error('VAT does not exist'));
153 }
154
155 return $r;
156 }
157
161 protected function getEntityTable()
162 {
163 return new VatTable();
164 }
165
169 protected function checkModifyPermissionEntity()
170 {
171 $r = new Result();
172
173 if (!$this->accessController->check(ActionDictionary::ACTION_VAT_EDIT))
174 {
175 $r->addError(new Error('Access Denied', 200040300020));
176 }
177
178 return $r;
179 }
180
184 protected function checkReadPermissionEntity()
185 {
186 $r = new Result();
187
188 if (
189 !$this->accessController->check(ActionDictionary::ACTION_CATALOG_READ)
190 && !$this->accessController->check(ActionDictionary::ACTION_VAT_EDIT)
191 )
192 {
193 $r->addError(new Error('Access Denied', 200040300010));
194 }
195
196 return $r;
197 }
198}
addAction(array $fields)
Definition vat.php:26
updateAction(int $id, array $fields)
Definition vat.php:54
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[])
Definition vat.php:115