27 if(!$this->hasDocumentByTypeId(
Exchange\OneC\DocumentType::ORDER, $documents))
29 $result->addError(
new Error(GetMessage(
'CRM_PACKAGE_NOT_FOUND_ORDER'),
'CRM_PACKAGE_NOT_FOUND_ORDER'));
33 $documentOrder = $this->getDocumentByTypeId(
Exchange\OneC\DocumentType::ORDER, $documents);
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))
39 $result->addError(
new Error(GetMessage(
'CRM_PACKAGE_NOT_FOUND_PAYMENT', array(
'#XML_1C_DOCUMENT_ID#'=>$documentOrder->getExternalId())),
'CRM_PACKAGE_NOT_FOUND_PAYMENT'));
43 foreach ($documents as $document)
45 if($document->getTypeId() ==
Exchange\OneC\DocumentType::SHIPMENT)
53 $result->addError(
new Error(GetMessage(
'CRM_PACKAGE_PARTIAL_SHIPMENT_NOT_SUPPORTED', array(
'#XML_1C_DOCUMENT_ID#'=>$documentOrder->getExternalId())),
'CRM_PACKAGE_NOT_FOUND_PAYMENT'));
72 $traits = $item->getField(
'TRAITS');
74 $invoice = new \CCrmInvoice(
false);
75 if (!$invoice->SetStatus($item->getId(), $traits[
'STATUS_ID']))
77 $result->addError(
new Error(
'Status error!'));
82 if($result->isSuccess())
83 $result = parent::modifyEntity($item);
96 $isNew = !($orderImport->getId()>0);
98 $result = parent::save($orderImport, $items);
100 if($result->isSuccess())
102 if($orderImport->getId()>0)
104 InvoiceStatusHistoryEntry::register($orderImport->getId(),
null, array(
'IS_NEW' => $isNew));
105 InvoiceSumStatisticEntry::register($orderImport->getId(),
null);
117 return ConverterFactory::create($typeId);
123 protected function convert(array $documents)
127 if($result->isSuccess())
129 $documentShipment = $this->getDocumentByTypeId(
Exchange\OneC\DocumentType::SHIPMENT, $documents);
131 if($documentShipment !==
null)
136 $convertor = Exchange\OneC\ConverterFactory::create($entityTypeId);
140 $documentShipment->getTypeId()
143 $fields = $convertor->resolveParams($documentShipment);
145 $shipmentPrice =
$fields[
'TRAITS'][
'BASE_PRICE_DELIVERY'];
149 $documentOrder = $this->getDocumentByTypeId(
Exchange\OneC\DocumentType::ORDER, $documents);
150 $fieldsOrder = $documentOrder->getFieldValues();
151 $items = $this->getProductsItems($fieldsOrder);
153 if(!$this->deliveryServiceExists($items))
156 'ID' => self::DELIVERY_SERVICE_XMLID,
157 'NAME' => GetMessage(
'CRM_PACKAGE_DELIVERY_SERVICE_ITEM'),
158 'PRICE' => $shipmentPrice,
159 'PRICE_ONE' => $shipmentPrice,
162 'MEASURE_CODE' => 796,
163 'MEASURE_NAME' => GetMessage(
'CRM_PACKAGE_DELIVERY_SERVICE_ITEM_MEASURE_796'),
166 $documentOrder->setFields($fieldsOrder);
170 foreach ($documents as $k=>$document)
172 if($document->getTypeId() == Exchange\OneC\DocumentType::SHIPMENT)
174 unset($documents[$k]);
179 $result = parent::convert($documents);
181 if($result->isSuccess())
185 $personTypes = \CCrmPaySystem::getPersonTypeIDs();
188 $entityItems = $result->getData();
189 foreach ($entityItems as $entityItem)
194 $personTypeId = $entityItem->isFiz()? (int)$personTypes[
'CONTACT']:(int)$personTypes[
'COMPANY'];
201 $billList = \CCrmPaySystem::GetPaySystemsListItems($personTypeId);
202 foreach($billList as $billId => $billName)
204 $paySystemId = $billId;
212 foreach ($entityItems as $entityItem)
219 $traits = $entityItem->getFieldValues()[
'TRAITS'];
220 $traits[
'PAY_SYSTEM_ID'] = $paySystemId;
221 $entityItem->setField(
'TRAITS', $traits);
223 $list[] = $entityItem;
225 $result->setData($list);
237 parent::configuration();
244 if($entity instanceof
Order)
245 $typeId = Exchange\Entity\Invoice::resolveEntityTypeId($entity);
246 elseif ($entity instanceof
Payment)
247 $typeId = Exchange\Entity\PaymentInvoiceBase::resolveEntityTypeId($entity);
248 elseif ($entity instanceof
Shipment)
249 $typeId = Exchange\Entity\ShipmentInvoice::resolveEntityTypeId($entity);