Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
entityimportloader.php
1<?php
3
4use Bitrix\Crm\InvoiceTable;
12
19{
21 protected $settings = null;
22
27 protected static function getFields()
28 {
29 throw new Main\ArgumentException('The method is not implemented.');
30 }
31
35 protected static function getExternalField()
36 {
37 return 'ID_1C';
38 }
39
45 public function getByNumber($number)
46 {
47 if($number === "")
48 {
49 throw new Main\ArgumentException('Is not defined', 'ID');
50 }
51 $entity = static::getEntityTable();
53 $accountNumberPrefix = $this->settings->prefixFor(EntityType::ORDER);
54
55 if(is_numeric($number))
56 {
57 if($r = $entity::getById($number)->fetch())
58 return $r;
59
60 if($r = $entity::getList(array(
61 'select' => array('ID'),
62 'filter' => array('ID_1C' => $number),
63 'order' => array('ID' => 'DESC')))->fetch()
64 )
65 return $r;
66
67
68 if($r = $entity::getList(array(
69 'select' => array('ID'),
70 'filter' => array('=ACCOUNT_NUMBER' => $number),
71 'order' => array('ID' => 'DESC')))->fetch()
72 )
73 return $r;
74
75 if ($accountNumberPrefix !== "")
76 {
77 if(mb_strpos($number, $accountNumberPrefix) === 0)
78 {
79 $number = mb_substr($number, mb_strlen($accountNumberPrefix));
80 if ($r = $entity::getById($number)->fetch())
81 return $r;
82 }
83 }
84 }
85 else
86 {
87 if ($r = $entity::getList(array(
88 'select' => array('ID'),
89 'filter' => array('ID_1C' => $number),
90 'order' => array('ID' => 'DESC')))->fetch()
91 )
92 return $r;
93
94 if ($r = $entity::getList(array(
95 'select' => array('ID'),
96 'filter' => array('=ACCOUNT_NUMBER' => $number),
97 'order' => array('ID' => 'DESC')))->fetch()
98 )
99 return $r;
100
101 if($accountNumberPrefix != "")
102 {
103 if(mb_strpos($number, $accountNumberPrefix) === 0)
104 {
105 $number = mb_substr($number, mb_strlen($accountNumberPrefix));
106 if($r = $entity::getById($number)->fetch())
107 return $r;
108
109 if($r = $entity::getList(array(
110 'select' => array('ID'),
111 'filter' => array('=ACCOUNT_NUMBER' => $number),
112 'order' => array('ID' => 'DESC')))->fetch()
113 )
114 return $r;
115 }
116 }
117 }
118 return null;
119 }
120
126 public function getByExternalId($xmlId)
127 {
128 if($xmlId === "")
129 {
130 throw new Main\ArgumentException('Is not defined', 'XML_1C_DOCUMENT_ID');
131 }
132
133 $entity = static::getEntityTable();
134
135 if($r = $entity::getList(array(
136 'select' => static::getFields(),
137 'filter' => array(static::getExternalField() => $xmlId),
138 'order' => array('ID' => 'DESC')))->fetch()
139 )
140 {
141 return $r;
142 }
143
144 return null;
145 }
146
151 protected static function getEntityTable()
152 {
153 throw new Main\ArgumentException('The method is not implemented.');
154 }
155
160 {
161 $this->settings = $settings;
162 }
163}
164
166{
167 protected static function getFields()
168 {
169 return array(
170 'ID',
171 'ID_1C'
172 );
173 }
174
175 protected static function getEntityTable()
176 {
177 return new OrderTable();
178 }
179}
180
182{
183 protected static function getFields()
184 {
185 return array(
186 'ID',
187 'ID_1C',
188 'ORDER_ID'
189 );
190 }
191
192 protected static function getEntityTable()
193 {
194 return new PaymentTable();
195 }
196}
197
199{
200 protected static function getFields()
201 {
202 return array(
203 'ID',
204 'ID_1C',
205 'ORDER_ID'
206 );
207 }
208
209 protected static function getEntityTable()
210 {
211 return new ShipmentTable();
212 }
213}
214
221{
225 protected static function getExternalField()
226 {
227 return 'XML_ID';
228 }
229
230 protected static function getFields()
231 {
232 return array(
233 'ID'
234 );
235 }
236
237 protected static function getEntityTable()
238 {
239 return new UserPropsTable();
240 }
241}
242
244{
250 public function getByNumber($number)
251 {
252 return null;
253 }
254
258 protected static function getExternalField()
259 {
260 return 'XML_ID';
261 }
262
263 protected static function getFields()
264 {
265 return array(
266 'ID'
267 );
268 }
269
270 protected static function getEntityTable()
271 {
272 return new Main\UserTable();
273 }
274
275 public function getByExternalId($xmlId)
276 {
277 $result = parent::getByExternalId($xmlId);
278
279 if(empty($result))
280 {
281 $result = self::getUserByCode($xmlId);
282 }
283
284 return $result;
285 }
286
291 static public function getUserByCode($code)
292 {
293 $result = array();
294 $code = rtrim($code);
295
296 $userCode = explode("#", $code);
297 if(intval($userCode[0]) > 0)
298 {
299 $r = \CUser::GetByID($userCode[0]);
300 if ($arUser = $r->Fetch())
301 {
302 if(rtrim(htmlspecialcharsback(mb_substr(htmlspecialcharsbx($arUser["ID"]."#".$arUser["LOGIN"]."#".$arUser["LAST_NAME"]." ".$arUser["NAME"]." ".$arUser["SECOND_NAME"]), 0, 80))) == $code)
303 $result = $arUser;
304 }
305 }
306 return $result;
307 }
308}
309
311{
312 protected static function getEntityTable()
313 {
314 return new \Bitrix\Crm\Invoice\Internals\InvoiceTable();
315 }
316}
317
319{
320 protected static function getEntityTable()
321 {
322 return new \Bitrix\Crm\Invoice\Internals\PaymentTable();
323 }
324}
325
327{
328 protected static function getEntityTable()
329 {
330 return new \Bitrix\Crm\Invoice\Internals\ShipmentTable();
331 }
332}