Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
contractor.php
1<?php
2
4
9
11{
12 public function createContractorAction(array $fields)
13 {
14 if (!AccessController::getCurrent()->check(ActionDictionary::ACTION_STORE_VIEW))
15 {
16 $this->addError(new Error('Access denied!'));
17
18 return null;
19 }
20
21 $companyName = $fields['companyName'];
22
23 if (empty($companyName))
24 {
25 $this->addError(new Error('Empty name'));
26
27 return null;
28 }
29
30 $userId = CurrentUser::get()->getId();
31 $fields = [
32 'PERSON_TYPE' => CONTRACTOR_JURIDICAL,
33 'COMPANY' => $companyName,
34 'CREATED_BY' => $userId,
35 'MODIFIED_BY' => $userId,
36 ];
37
38 $contractorId = \CCatalogContractor::add($fields);
39 if (!$contractorId)
40 {
41 $this->addError(new Error('Error adding contractor'));
42
43 return null;
44 }
45
46 return [
47 'id' => $contractorId
48 ];
49 }
50}