30 PackageTrait::load as
protected load_AliasTrait;
35 private static $instance =
null;
42 if(self::$instance ===
null)
44 self::$instance =
new static();
46 return self::$instance;
49 private function __clone() {}
50 private function __construct() {}
95 protected function getItems(array $fields)
99 $orderId = $fields[
'ORDER_ID'];
101 $orderImport = $this->entityFactoryCreate(static::getParentEntityTypeId());
103 static::load($orderImport, array(
'ID'=>$orderId));
106 $order = $orderImport->getEntity();
112 static::load($profileImport, array(
'ID'=>$order->getUserId()));
115 $this->loadItemsByCollection($order->getPaymentCollection(), $order),
116 $this->loadItemsByCollection($order->getShipmentCollection(), $order));
118 $list[] = $orderImport;
119 $list[] = $profileImport;
123 $result->setData($list);
127 $result->addError(
new Error(str_replace(
'#ID#',$orderId, DocumentBase::getLangByCodeField(
"ORDER_NOT_FOUND"))));
138 protected function loadItemsByCollection(CollectionBase $collection, Order $order)
142 if(count($collection)>0)
144 foreach ($collection as $entity)
146 if($entity instanceof Shipment)
148 if($entity->isSystem())
155 $entityExport = $this->entityFactoryCreate($typeId);
157 static::load($entityExport, array(
'ID'=>$entity->getId()), $order);
159 $list[] = $entityExport;
174 if($entity instanceof
Order)
175 $typeId = OrderImport::resolveEntityTypeId($entity);
176 elseif($entity instanceof
Payment)
177 $typeId = PaymentImport::resolveEntityTypeId($entity);
179 $typeId = ShipmentImport::resolveEntityTypeId($entity);
193 $this->convertEntityFields($items);
195 foreach ($items as $item)
200 $this->convertDocumentFields($list);
204 if($result->isSuccess())
206 $result->setData($list);
214 protected function convertDocumentFields(array $documents)
216 $documentOrder = $this->getDocumentByTypeId(DocumentType::ORDER, $documents);
217 $orderFields = $documentOrder->getFieldValues();
220 $documentProfile = $this->getDocumentByTypeId(DocumentType::USER_PROFILE, $documents);
221 $orderFields[
'AGENT'] = $documentProfile->getFieldValues();
223 $documentOrder->setFields($orderFields);
230 protected function convertEntityFields(array $items)
234 $orderImport = $this->getEntityByTypeId(static::getParentEntityTypeId(), $items);
239 $this->prepareEntityFieldsBusinessValue($orderImport);
240 $this->prepareEntityFieldsBusinessValue($profileImport, $orderImport);
242 foreach ($items as $item)
244 if($item instanceof ShipmentImport || $item instanceof PaymentImport)
246 $this->prepareEntityFieldsBusinessValue($item);
252 $orderFields = $orderImport->getFieldValues();
253 foreach ($items as $item)
255 if($item instanceof PaymentImport)
257 $paymentFields = $item->getFieldValues();
258 $paymentFields[
'TRAITS'][
'LID'] = $orderFields[
'TRAITS'][
'LID'];
259 $paymentFields[
'TRAITS'][
'VERSION'] = $orderFields[
'TRAITS'][
'VERSION'];
260 $item->setFields($paymentFields);
266 $orderFields = $orderImport->getFieldValues();
267 foreach ($items as $item)
269 if($item instanceof ShipmentImport)
271 $shipmentFields = $item->getFieldValues();
272 $shipmentFields[
'TRAITS'][
'LID'] = $orderFields[
'TRAITS'][
'LID'];
273 $shipmentFields[
'TRAITS'][
'VERSION'] = $orderFields[
'TRAITS'][
'VERSION'];
274 $item->setFields($shipmentFields);
279 $this->addItemOrderDelivery($items);
287 protected function addItemOrderDelivery(array $items)
289 $orderImport = $this->getEntityByTypeId(static::getParentEntityTypeId(), $items);
292 $orderFields = $orderImport->getFieldValues();
293 foreach ($items as $item)
295 if($item instanceof ShipmentImport)
297 $shipmentFields = $item->getFieldValues();
299 $shipmemt = $item->getEntity();
300 if($shipmemt->getPrice()>0)
303 $shipmentFields[
'ITEMS'][] = array_merge(
307 'MEASURE_CODE'=>Converter::MEASURE_CODE_DEFAULT,
308 'KOEF'=>Converter::KOEF_DEFAULT,
309 'PRICE'=>$shipmemt->getPrice(),
312 $this->getVatRateByShipment($item, $this->getSummOrderTaxes($orderFields[
'TAXES']))
315 $item->setFields($shipmentFields);
321 $orderFields = $orderImport->getFieldValues();
322 foreach ($items as $item)
324 if($item instanceof ShipmentImport)
326 $shipmentItems = $this->getProductsItems($item->getFieldValues());
327 if($this->deliveryServiceExists($shipmentItems))
333 $orderImport->setFields($orderFields);
343 foreach ($list as $k=>$items)
361 foreach ($taxes as $tax)
363 $tax[
"VALUE_MONEY"] = roundEx($tax[
"VALUE_MONEY"], 2);
364 $orderTax += $tax[
"VALUE_MONEY"];
374 protected function getVatRateByShipment(
ShipmentImport $item, $orderTax)
381 if($shipmemt->getPrice()>0)
385 $order = $shipmemt->getParentOrder();
387 foreach ($order->getBasket() as $basket)
389 $vatRate = (float)$basket->getVatRate();
390 $basketVatSum = $basket->getPrice()/($vatRate+1) * $vatRate;
391 $vatSum += roundEx($basketVatSum * $basket->getQuantity(), 2);
394 $tax = roundEx((($shipmemt->getPrice() / ($vatRate+1)) * $vatRate), 2);
396 if($orderTax > $vatSum && $orderTax == roundEx($vatSum + $tax, 2))
398 $result = array(
'VAT_RATE'=>$vatRate*100);
413 $fields[
'REK_VALUES'] = is_array($fields[
'REK_VALUES'])? $fields[
'REK_VALUES']:array();
414 $profileFields[
'REK_VALUES'] = is_array($profileFields[
'REK_VALUES'])? $profileFields[
'REK_VALUES']:array();
416 $fields[
'REK_VALUES'] = array_merge($fields[
'REK_VALUES'], $profileFields[
'REK_VALUES']);
429 throw new ArgumentException(
"Entity must be instanceof OrderImport or ShipmentImport or PaymentImport or ProfileImport");
435 $fields[
'BUSINESS_VALUE'] = $item::getBusinessValue($provider);
450 foreach ($documents as $document)
454 $result->setData($list);
467 $xml .= $document->
output($level+1);
479 foreach ($list as $document)
482 $result[] = $document;
492 foreach ($items as $item)
509 $convertor = $this->converterFactoryCreate($item->
getOwnerTypeId());
516 $fields = $convertor->externalize($params);
518 $document = $this->documentFactoryCreate($documentTypeId);
519 $document->setFields($fields);
530 $documentTypeId = DocumentType::UNDEFINED;
534 case static::getParentEntityTypeId():
535 $documentTypeId = DocumentType::ORDER;
537 case static::getPaymentCardEntityTypeId():
538 $documentTypeId = OneC\DocumentType::PAYMENT_CARD_TRANSACTION;
540 case static::getPaymentCashEntityTypeId():
541 $documentTypeId = OneC\DocumentType::PAYMENT_CASH;
543 case static::getPaymentCashLessEntityTypeId():
544 $documentTypeId = DocumentType::PAYMENT_CASH_LESS;
546 case static::getShipmentEntityTypeId():
547 $documentTypeId = OneC\DocumentType::SHIPMENT;
551 $documentTypeId = $typeId;
554 return $documentTypeId;
561 protected function export(array $documents)
569 $xml = implode(
'', $r->getData());
574 return $result->setData([$xml]);
584 static::load_AliasTrait($item, $fields, $order);
596 protected function logger(array $items)
599 $orderItem = $this->getEntityByTypeId(static::getParentEntityTypeId(), $items);