Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
importonecpackagesale.php
1<?php
2
4
5
15
17{
18 protected function convert(array $documents)
19 {
20 $documentOrder = $this->getDocumentByTypeId(DocumentType::ORDER, $documents);
21
22 if($documentOrder instanceof OrderDocument)
23 {
24 //region Presset - create Shipment if Service in the Order by information from 1C
25 $documentShipment = $this->getDocumentByTypeId(DocumentType::SHIPMENT, $documents);
26 if($documentShipment == null)
27 {
28 $fieldsOrder = $documentOrder->getFieldValues();
29 $items = $this->getProductsItems($fieldsOrder);
30
31 if($this->deliveryServiceExists($items))
32 {
33 $shipment['ID_1C'] = $documentOrder->getField('ID_1C');
34 $shipment['VERSION_1C'] = $documentOrder->getField('VERSION_1C');
35 $shipment['ITEMS'] = $items;
36 $shipment['REK_VALUES']['1C_TRACKING_NUMBER'] = $this->getDefaultTrackingNumber($documentOrder);
37
38 $documentShipment = new ShipmentDocument();
39 $documentShipment->setFields($shipment);
40 $documents[] = $documentShipment;
41 }
42 }
43 //endregion
44
45 foreach($documents as $document)
46 {
47 if($document instanceof OneC\PaymentDocument)
48 {
49 $paymentFields = $document->getFieldValues();
50 $paymentFields['REK_VALUES']['PAY_SYSTEM_ID_DEFAULT'] = $this->getDefaultPaySystem($documentOrder);
51 $document->setFields($paymentFields);
52 }
53
54 if($document instanceof OneC\ShipmentDocument)
55 {
56 $shimpentFields = $document->getFieldValues();
57 $shimpentFields['REK_VALUES']['DELIVERY_SYSTEM_ID_DEFAULT'] = $this->getDefaultDeliverySystem($documentOrder);
58 $document->setFields($shimpentFields);
59 }
60 }
61 }
62 else
63 {
64 $settingsShipment = ManagerImport::getSettingsByType(static::getShipmentEntityTypeId());
65
66 if($settingsShipment->canCreateOrder(static::getShipmentEntityTypeId())=='Y')
67 {
68 $documentShipment = $this->getDocumentByTypeId(DocumentType::SHIPMENT, $documents);
69 if($documentShipment !== null)
70 {
71 $order['ID_1C'] = $documentShipment->getField('ID_1C');
72 $order['VERSION_1C'] = $documentShipment->getField('VERSION_1C');
73 $order['AMOUNT'] = $documentShipment->getField('AMOUNT');
74 $order['ITEMS'] = $documentShipment->getField('ITEMS');
75 $order['TAXES'] = $documentShipment->getField('TAXES');
76 $order['AGENT'] = $documentShipment->getField('AGENT');
77
78 $documentOrder = new OrderDocument();
79 $documentOrder->setFields($order);
80 $documents[] = $documentOrder;
81 }
82 }
83 }
84
85 return parent::convert($documents);
86 }
87
92 protected function getDefaultTrackingNumber(OneC\OrderDocument $document)
93 {
94 $fields = $document->getFieldValues();
95 return isset($fields['REK_VALUES']['1C_TRACKING_NUMBER'])?$fields['REK_VALUES']['1C_TRACKING_NUMBER']:null;
96 }
97
102 protected function getDefaultPaySystem(OneC\OrderDocument $document)
103 {
104 $fields = $document->getFieldValues();
105 return isset($fields['REK_VALUES']['PAY_SYSTEM_ID'])?$fields['REK_VALUES']['PAY_SYSTEM_ID']:null;
106 }
107
112 protected function getDefaultDeliverySystem(OneC\OrderDocument $document)
113 {
114 $fields = $document->getFieldValues();
115 return isset($fields['REK_VALUES']['DELIVERY_SYSTEM_ID'])?$fields['REK_VALUES']['DELIVERY_SYSTEM_ID']:null;
116 }
117
124 protected function UpdateCashBoxChecks(OrderImport $orderImport, array $items)
125 {
126 $result = new Result();
127 $bCheckUpdated = false;
128
129 $order = $orderImport->getEntity();
130
131 foreach ($items as $item)
132 {
135 if($item->getOwnerTypeId() == static::getPaymentCashEntityTypeId() ||
136 $item->getOwnerTypeId() == static::getPaymentCashLessEntityTypeId() ||
137 $item->getOwnerTypeId() == static::getPaymentCardEntityTypeId()
138 )
139 {
141 $params = $item->getFieldValues();
142 static::load($item, $params['TRAITS'], $order);
143
144 if($item->getEntityId()>0)
145 {
146 $entity = $item->getEntity();
147
148 if(isset($params['CASH_BOX_CHECKS']))
149 {
150 $fields = $params['CASH_BOX_CHECKS'];
151
152 if($fields['ID']>0)
153 {
154 $res = CashboxCheckTable::getById($fields['ID']);
155 if ($data = $res->fetch())
156 {
157 if($data['STATUS']<>'Y')
158 {
159 $applyResult = Cashbox1C::applyCheckResult($params['CASH_BOX_CHECKS']);
160 $bCheckUpdated = $applyResult->isSuccess();
161 }
162 }
163 else
164 {
165 $item->setCollisions(EntityCollisionType::PaymentCashBoxCheckNotFound, $entity);
166 }
167 }
168 }
169 }
170 }
171 }
172
174 $collision = $orderImport->getCurrentCollision(EntityType::ORDER);
175 $collisionTypes = $collision->getCollision($orderImport);
176
177 if(count($collisionTypes)>0 && $bCheckUpdated)
178 {
179 return $result;
180 }
181 else
182 {
183 $result->addError(new Error('', 'CASH_BOX_CHECK_IGNORE'));
184 }
185
186 return $result;
187 }
188
189}
static applyCheckResult(array $data)
Definition cashbox.php:273
UpdateCashBoxChecks(Exchange\Entity\OrderImport $orderImport, array $items)
getDefaultDeliverySystem(OneC\OrderDocument $document)
getDefaultTrackingNumber(OneC\OrderDocument $document)