1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
importonecpackagecrm.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale\Exchange;
4
5
6use Bitrix\Crm\History\InvoiceStatusHistoryEntry;
7use Bitrix\Crm\Statistics\InvoiceSumStatisticEntry;
8use Bitrix\Main\Error;
9use Bitrix\Sale\Exchange;
10use Bitrix\Sale\Exchange\Entity\OrderImport;
11use Bitrix\Sale\Exchange\OneC\CRM\ConverterFactory;
12use Bitrix\Sale\Order;
13use Bitrix\Sale\Payment;
14use Bitrix\Sale\Result;
15use Bitrix\Sale\Shipment;
16
18{
23 protected function checkDocuments(array $documents)
24 {
25 $result = new Result();
26
27 if(!$this->hasDocumentByTypeId(Exchange\OneC\DocumentType::ORDER, $documents))
28 {
29 $result->addError(new Error(GetMessage('CRM_PACKAGE_NOT_FOUND_ORDER'), 'CRM_PACKAGE_NOT_FOUND_ORDER'));
30 }
31 else
32 {
33 $documentOrder = $this->getDocumentByTypeId(Exchange\OneC\DocumentType::ORDER, $documents);
34
35 if(!$this->hasDocumentByTypeId(Exchange\OneC\DocumentType::PAYMENT_CASH, $documents) &&
36 !$this->hasDocumentByTypeId(Exchange\OneC\DocumentType::PAYMENT_CASH_LESS, $documents) &&
37 !$this->hasDocumentByTypeId(Exchange\OneC\DocumentType::PAYMENT_CARD_TRANSACTION, $documents))
38 {
39 $result->addError(new Error(GetMessage('CRM_PACKAGE_NOT_FOUND_PAYMENT', array('#XML_1C_DOCUMENT_ID#'=>$documentOrder->getExternalId())), 'CRM_PACKAGE_NOT_FOUND_PAYMENT'));
40 }
41
42 $countShipment = 0;
43 foreach ($documents as $document)
44 {
45 if($document->getTypeId() == Exchange\OneC\DocumentType::SHIPMENT)
46 {
47 $countShipment++;
48 }
49 }
50
51 if($countShipment>=2)
52 {
53 $result->addError(new Error(GetMessage('CRM_PACKAGE_PARTIAL_SHIPMENT_NOT_SUPPORTED', array('#XML_1C_DOCUMENT_ID#'=>$documentOrder->getExternalId())), 'CRM_PACKAGE_NOT_FOUND_PAYMENT'));
54 }
55 }
56
57 return $result;
58 }
59
64 protected function modifyEntity($item)
65 {
66 $result = new Result();
67
68 if($item instanceof OrderImport)
69 {
70 if($item->getId()>0)
71 {
72 $traits = $item->getField('TRAITS');
73
74 $invoice = new \CCrmInvoice(false);
75 if (!$invoice->SetStatus($item->getId(), $traits['STATUS_ID']))
76 {
77 $result->addError(new Error('Status error!'));
78 }
79 }
80 }
81
82 if($result->isSuccess())
83 $result = parent::modifyEntity($item);
84
85
86 return $result;
87 }
88
94 protected function save(Exchange\Entity\OrderImport $orderImport, $items)
95 {
96 $isNew = !($orderImport->getId()>0);
97
98 $result = parent::save($orderImport, $items);
99
100 if($result->isSuccess())
101 {
102 if($orderImport->getId()>0)
103 {
104 InvoiceStatusHistoryEntry::register($orderImport->getId(), null, array('IS_NEW' => $isNew));
105 InvoiceSumStatisticEntry::register($orderImport->getId(), null);
106 }
107 }
108 return $result;
109 }
110
115 protected function converterFactoryCreate($typeId)
116 {
117 return ConverterFactory::create($typeId);
118 }
119
123 protected function convert(array $documents)
124 {
125 $result = $this->checkDocuments($documents);
126
127 if($result->isSuccess())
128 {
129 $documentShipment = $this->getDocumentByTypeId(Exchange\OneC\DocumentType::SHIPMENT, $documents);
130
131 if($documentShipment !== null)
132 {
133 $entityTypeId = $this->resolveOwnerEntityTypeId($documentShipment->getTypeId());
135
136 $convertor = Exchange\OneC\ConverterFactory::create($entityTypeId);
137 $convertor->init(
138 $settings,
139 $entityTypeId,
140 $documentShipment->getTypeId()
141 );
142
143 $fields = $convertor->resolveParams($documentShipment);
144
145 $shipmentPrice = $fields['TRAITS']['BASE_PRICE_DELIVERY'];
146
147 if($shipmentPrice>0)
148 {
149 $documentOrder = $this->getDocumentByTypeId(Exchange\OneC\DocumentType::ORDER, $documents);
150 $fieldsOrder = $documentOrder->getFieldValues();
151 $items = $this->getProductsItems($fieldsOrder);
152
153 if(!$this->deliveryServiceExists($items))
154 {
155 $fieldsOrder['ITEMS'][][self::DELIVERY_SERVICE_XMLID] = array(
156 'ID' => self::DELIVERY_SERVICE_XMLID,
157 'NAME' => GetMessage('CRM_PACKAGE_DELIVERY_SERVICE_ITEM'),
158 'PRICE' => $shipmentPrice,
159 'PRICE_ONE' => $shipmentPrice,
160 'QUANTITY' => 1,
161 'TYPE' => ImportBase::ITEM_ITEM,
162 'MEASURE_CODE' => 796,
163 'MEASURE_NAME' => GetMessage('CRM_PACKAGE_DELIVERY_SERVICE_ITEM_MEASURE_796'),
164 );
165
166 $documentOrder->setFields($fieldsOrder);
167 }
168 }
169
170 foreach ($documents as $k=>$document)
171 {
172 if($document->getTypeId() == Exchange\OneC\DocumentType::SHIPMENT)
173 {
174 unset($documents[$k]);
175 }
176 }
177 }
178
179 $result = parent::convert($documents);
180
181 if($result->isSuccess())
182 {
183 $personTypeId = 0;
184 $paySystemId = 0;
185 $personTypes = \CCrmPaySystem::getPersonTypeIDs();
186
188 $entityItems = $result->getData();
189 foreach ($entityItems as $entityItem)
190 {
191 if($entityItem->getOwnerTypeId() == EntityType::USER_PROFILE)
192 {
194 $personTypeId = $entityItem->isFiz()? (int)$personTypes['CONTACT']:(int)$personTypes['COMPANY'];
195 break;
196 }
197 }
198
199 if($personTypeId>0)
200 {
201 $billList = \CCrmPaySystem::GetPaySystemsListItems($personTypeId);
202 foreach($billList as $billId => $billName)
203 {
204 $paySystemId = $billId;
205 break;
206 }
207 }
208
209 if($paySystemId>0)
210 {
211 $list = [];
212 foreach ($entityItems as $entityItem)
213 {
214 if(
215 $entityItem->getOwnerTypeId() == EntityType::INVOICE_PAYMENT_CASH ||
216 $entityItem->getOwnerTypeId() == EntityType::INVOICE_PAYMENT_CASH_LESS ||
217 $entityItem->getOwnerTypeId() == EntityType::INVOICE_PAYMENT_CARD_TRANSACTION)
218 {
219 $traits = $entityItem->getFieldValues()['TRAITS'];
220 $traits['PAY_SYSTEM_ID'] = $paySystemId;
221 $entityItem->setField('TRAITS', $traits);
222 }
223 $list[] = $entityItem;
224 }
225 $result->setData($list);
226 }
227 }
228 }
229
230 return $result;
231 }
232
233 public static function configuration()
234 {
236
237 parent::configuration();
238 }
239
241 {
242 $typeId = EntityType::UNDEFINED;
243
244 if($entity instanceof Order)
246 elseif ($entity instanceof Payment)
248 elseif ($entity instanceof Shipment)
250
251 return $typeId;
252 }
253
254 static protected function getParentEntityTypeId()
255 {
256 return EntityType::INVOICE;
257 }
258
259 static protected function getShipmentEntityTypeId()
260 {
262 }
263
264 static protected function getPaymentCardEntityTypeId()
265 {
267 }
268
269 static protected function getPaymentCashEntityTypeId()
270 {
272 }
273
274 static protected function getPaymentCashLessEntityTypeId()
275 {
277 }
278}
Определения error.php:15
static resolveEntityTypeId(Sale\Internals\Entity $entity)
Определения entityimport.php:312
static resolveEntityTypeId(Entity $order)
Определения invoice.php:62
static resolveEntityTypeId(Entity $shipment)
Определения shipmentinvoice.php:53
const INVOICE_PAYMENT_CASH
Определения entitytype.php:18
const INVOICE_PAYMENT_CASH_LESS
Определения entitytype.php:19
const USER_PROFILE
Определения entitytype.php:14
const INVOICE_PAYMENT_CARD_TRANSACTION
Определения entitytype.php:20
const UNDEFINED
Определения entitytype.php:7
const INVOICE_SHIPMENT
Определения entitytype.php:17
resolveEntityTypeId(\Bitrix\Sale\Internals\Entity $entity)
Определения importonecpackagecrm.php:240
save(Exchange\Entity\OrderImport $orderImport, $items)
Определения importonecpackagecrm.php:94
convert(array $documents)
Определения importonecpackage.php:113
static getSettingsByType($typeId)
Определения managerimport.php:71
static registerInstance($typeId, ISettingsImport $settings, ICollision $collision=null, ICriterion $criterion=null)
Определения managerimport.php:49
Определения payment.php:19
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$entity
GetMessage($name, $aReplace=null)
Определения tools.php:3397
Определения ufield.php:9
$settings
Определения product_settings.php:43
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$items
Определения template.php:224
$k
Определения template_pdf.php:567
$fields
Определения yandex_run.php:501