示例#1
0
 protected static function getShipmentsInfo(Order $order)
 {
     $result = array();
     $shipments = $order->getShipmentCollection();
     /** @var \Bitrix\Sale\Shipment $shipment */
     foreach ($shipments as $shipment) {
         if ($shipment->isSystem()) {
             continue;
         }
         /** @var \Bitrix\Sale\Delivery\Services\Base  $deliveryService */
         $deliveryService = $shipment->getDelivery();
         if (!$deliveryService) {
             continue;
         }
         $result[] = array("ID" => $shipment->getId(), "NAME" => $deliveryService->getName(), "LOGOTIP_PATH" => $deliveryService->getLogotipPath(), "IS_SHIPPED" => $shipment->isShipped(), "DEDUCTED" => $shipment->getField('DEDUCTED'));
     }
     return $result;
 }
示例#2
0
    public static function getView(Order $order, OrderBasket $orderBasket, $selectPayment = null, $selectId = null)
    {
        // prepare data
        $orderId = $order->getId();
        $data = $orderBasket->prepareData();
        $items = $data['ITEMS'];
        $documents = array();
        $itemNo = 0;
        /** @var \Bitrix\Sale\Payment $payment */
        foreach ($order->getPaymentCollection() as $payment) {
            $documents[] = $payment;
        }
        /** @var \Bitrix\Sale\Shipment $shipment */
        foreach ($order->getShipmentCollection() as $shipment) {
            if (!$shipment->isSystem()) {
                if (!$shipment->isCanceled() && $shipment->isShipped()) {
                    /** @var \Bitrix\Sale\ShipmentItem $shipmentItem */
                    foreach ($shipment->getShipmentItemCollection() as $shipmentItem) {
                        $basketItem = $shipmentItem->getBasketItem();
                        if (isset($items[$basketItem->getBasketCode()])) {
                            $item =& $items[$basketItem->getBasketCode()];
                            if ($shippedQuantity =& $item['SHIPPED_QUANTITY']) {
                                $shippedQuantity += (double) $shipmentItem->getField('QUANTITY');
                            } else {
                                $shippedQuantity = (double) $shipmentItem->getField('QUANTITY');
                            }
                        }
                    }
                }
                $documents[] = $shipment;
            }
        }
        unset($item, $shippedQuantity);
        usort($documents, array(__CLASS__, 'sortDocumentsByDate'));
        // render view
        ob_start();
        ?>
		<div class="adm-s-order-table-ddi">
			<table class="adm-s-order-table-ddi-table adm-s-bus-ordertable-option" style="width: 100%;">
				<thead>
				<tr>
					<td class="tac"><?php 
        echo Loc::getMessage('SALE_OANALYSIS_ITEM_NUMBER');
        ?>
</td>
					<td><?php 
        echo Loc::getMessage('SALE_OANALYSIS_ITEM_NAME');
        ?>
</td>
					<td class="tac"><?php 
        echo Loc::getMessage('SALE_OANALYSIS_ITEM_PROPERTIES');
        ?>
</td>
					<td class="tac"><?php 
        echo Loc::getMessage('SALE_OANALYSIS_ITEM_PLANNED');
        ?>
</td>
					<td class="tac"><?php 
        echo Loc::getMessage('SALE_OANALYSIS_ITEM_SHIPPED');
        ?>
</td>
					<td class="tac"><?php 
        echo Loc::getMessage('SALE_OANALYSIS_ITEM_TO_SHIP');
        ?>
</td>
				</tr>
				</thead>
				<tbody>
					<?php 
        foreach ($items as $item) {
            $properties = '<table style="margin: auto; width: 50%;">';
            if (is_array($item['SKU_PROPS'])) {
                foreach ($item['SKU_PROPS'] as $skuProp) {
                    $properties .= '<tr>';
                    $properties .= '<td style="text-align: left;">' . htmlspecialcharsbx($skuProp['NAME']) . ' : ' . '</td>';
                    if (isset($skuProp['VALUE']['PICT']) && $skuProp['VALUE']['PICT']) {
                        $properties .= '<td><span class="color"><img src="' . $skuProp['VALUE']['PICT'] . '" alt=""></span></td>';
                    } else {
                        $properties .= '<td><span>' . htmlspecialcharsbx($skuProp['VALUE']['NAME']) . '</span></td>';
                    }
                    $properties .= '</tr>';
                }
            }
            $properties .= '</table>';
            if (!($quantity = (double) $item['QUANTITY'])) {
                $quantity = 0;
            }
            if (!($shippedQuantity = $item['SHIPPED_QUANTITY'])) {
                $shippedQuantity = 0;
            }
            ?>
						<tr class="bdb-line">
							<td class="tac"><?php 
            echo ++$itemNo;
            ?>
</td>
							<td style="text-align: left;"><a class="fwb" href="<?php 
            echo $item['EDIT_PAGE_URL'];
            ?>
"><?php 
            echo htmlspecialcharsbx($item['NAME']);
            ?>
</a></td>
							<td class="tac"><?php 
            echo $properties;
            ?>
</td>
							<td class="tac"><?php 
            echo $quantity . ' ' . $item['MEASURE_TEXT'];
            ?>
</td>
							<td class="tac"><?php 
            echo $shippedQuantity . ' ' . $item['MEASURE_TEXT'];
            ?>
</td>
							<td class="tac"><?php 
            echo $quantity - $shippedQuantity . ' ' . $item['MEASURE_TEXT'];
            ?>
</td>
						</tr>
					<?php 
        }
        ?>
					<tr><td colspan="8" style="padding: 16px; background: #f7fafa; text-align: left;" class="fwb"><?php 
        echo Loc::getMessage('SALE_OANALYSIS_ITEMS_QUANTITY') . ': ' . count($items);
        ?>
</td></tr>
				</tbody>
			</table>
			<div class="adm-bus-table-contaier-white caption border" style="margin-top: 25px;">
				<div class="adm-bus-table-caption-white-title"><?php 
        echo Loc::getMessage('SALE_OANALYSIS_DOCUMENTS');
        ?>
:</div>
				<div class="adm-bus-orderdocs-threelist-container">
					<div class="adm-bus-orderdocs-threelist-block-top<?php 
        echo $selectPayment === null ? ' adm-bus-orderdocs-threelist-block-children-open' : '';
        ?>
">
						<div class="adm-bus-orderdocs-threelist-block-img adm-bus-orderdocs-threelist-block-img-order"></div>
						<div class="adm-bus-orderdocs-threelist-block-content">
							<div class="adm-bus-orderdocs-threelist-block-title">
								<a class="adm-bus-orderdocs-threelist-block-title-link fwb" href="/bitrix/admin/sale_order_edit.php?lang=ru&ID=<?php 
        echo $orderId;
        ?>
">
									<?php 
        echo Loc::getMessage('SALE_OANALYSIS_ORDER_TITLE', array('#USER_ID#' => $order->getField('USER_ID'), '#ORDER_ID#' => $orderId));
        ?>
								</a>
							</div>
							<?php 
        self::renderBottomBlocks($order->getField('DATE_INSERT'), $order->getField('RESPONSIBLE_ID'));
        ?>
						</div>
						<div class="clb"></div>
					</div>
					<?php 
        foreach ($documents as $document) {
            $isPayment = $document instanceof Payment;
            $documentId = $document->getId();
            ?>
						<div class="adm-bus-orderdocs-threelist-block-children<?php 
            echo $selectPayment === $isPayment && $selectId == $documentId ? ' adm-bus-orderdocs-threelist-block-children-open' : '';
            ?>
">
							<div class="adm-bus-orderdocs-threelist-block-img adm-bus-orderdocs-threelist-block-img-doc_<?php 
            echo $isPayment ? 'payment' : 'shipping';
            ?>
"></div>
							<div class="adm-bus-orderdocs-threelist-block-content">
								<div class="adm-bus-orderdocs-threelist-block-title">
									<?php 
            if ($isPayment) {
                ?>
										<?php 
                if ($document->isPaid()) {
                    ?>
											<span class="adm-bus-orderdocs-docstatus adm-bus-orderdocs-docstatus-paid"><?php 
                    echo Loc::getMessage('SALE_OANALYSIS_PAYMENT_PAID');
                    ?>
</span>
										<?php 
                } elseif ($document->isReturn()) {
                    ?>
											<span class="adm-bus-orderdocs-docstatus"><?php 
                    echo Loc::getMessage('SALE_OANALYSIS_PAYMENT_RETURN');
                    ?>
</span>
										<?php 
                }
                ?>
										<a href="/bitrix/admin/sale_order_payment_edit.php?order_id=<?php 
                echo $orderId;
                ?>
&payment_id=<?php 
                echo $documentId;
                ?>
" class="adm-bus-orderdocs-threelist-block-title-link">
											<?php 
                echo Loc::getMessage('SALE_OANALYSIS_PAYMENT_TITLE', array('#SYSTEM_NAME#' => htmlspecialcharsbx($document->getField('PAY_SYSTEM_NAME')), '#PAYMENT_ID#' => $documentId, '#SUM#' => SaleFormatCurrency($document->getField('SUM'), $document->getField('CURRENCY'))));
                ?>
										</a>
									<?php 
            } else {
                /* shipment*/
                ?>
										<?php 
                if ($document->isShipped()) {
                    ?>
											<span class="adm-bus-orderdocs-docstatus adm-bus-orderdocs-docstatus-shippingallowed"><?php 
                    echo Loc::getMessage('SALE_OANALYSIS_SHIPMENT_SHIPPED');
                    ?>
</span>
										<?php 
                } elseif ($document->isCanceled()) {
                    ?>
											<span class="adm-bus-orderdocs-docstatus adm-bus-orderdocs-docstatus-canceled"><?php 
                    echo Loc::getMessage('SALE_OANALYSIS_SHIPMENT_CANCELED');
                    ?>
</span>
										<?php 
                } elseif ($document->isAllowDelivery()) {
                    ?>
											<span class="adm-bus-orderdocs-docstatus adm-bus-orderdocs-docstatus-shippingallowed"><?php 
                    echo Loc::getMessage('SALE_OANALYSIS_SHIPMENT_ALLOWED');
                    ?>
</span>
										<?php 
                }
                ?>
										<a href="/bitrix/admin/sale_order_shipment_edit.php?order_id=<?php 
                echo $orderId;
                ?>
&shipment_id=<?php 
                echo $documentId;
                ?>
"
										   class="adm-bus-orderdocs-threelist-block-title-link<?php 
                echo $document->isCanceled() ? 'adm-bus-orderdocs-threelist-block-title-link-canceled' : '';
                ?>
">
											<?php 
                echo Loc::getMessage('SALE_OANALYSIS_SHIPMENT_TITLE', array('#SHIPMENT_ID#' => $documentId, '#ORDER_ID#' => $orderId));
                ?>
										</a>
									<?php 
            }
            ?>
								</div>
								<?php 
            self::renderBottomBlocks($document->getField($isPayment ? 'DATE_BILL' : 'DATE_INSERT'), $document->getField('RESPONSIBLE_ID'));
            ?>
							</div>
							<div class="clb"></div>
						</div>
					<?php 
        }
        ?>
				</div>
			</div>
		</div>
		<?php 
        $result = ob_get_contents();
        ob_end_clean();
        return $result;
    }
 /**
  * @param Sale\Order $order
  * @param Sale\Basket $basket
  *
  * @return Sale\Result
  * @throws Main\ArgumentNullException
  * @throws Main\ArgumentTypeException
  * @throws Main\NotSupportedException
  */
 protected static function appendBasketToOrder(Sale\Order $order, Sale\Basket $basket)
 {
     $result = new Sale\Result();
     $orderBasketCollection = $order->getBasket();
     $shipmentCollection = $order->getShipmentCollection();
     $systemShipment = $shipmentCollection->getSystemShipment();
     $systemShipmentItemCollection = $systemShipment->getShipmentItemCollection();
     /** @var Sale\BasketItem $basketItem */
     foreach ($basket as $basketItem) {
         $basketProperty = array();
         if ($basketPropertyCollection = $basketItem->getPropertyCollection()) {
             $basketProperty = $basketPropertyCollection->getPropertyValues();
         }
         if ($orderBasketItem = $orderBasketCollection->getExistsItem($basketItem->getField('MODULE'), $basketItem->getField('PRODUCT_ID'), $basketProperty)) {
             $fields = $basketItem->getFieldValues();
             $orderBasketItem->setFields(static::clearFields($fields));
         } else {
             /** @var Sale\BasketItem $orderBasketItem */
             $orderBasketCollection->addItem($basketItem);
             $basketItem->setCollection($orderBasketCollection);
             $systemShipmentItemCollection->resetCollection($orderBasketCollection);
         }
     }
     /** @var Sale\BasketItem $basketItem */
     foreach ($basket as $basketItem) {
         if ($systemShipment->getDeliveryId() > 0) {
             /** @var Sale\Shipment $shipment */
             $shipment = OrderCompatibility::getShipmentByDeliveryId($shipmentCollection, $systemShipment->getDeliveryId());
             if (!$shipment) {
                 if ($service = Sale\Delivery\Services\Manager::getService($systemShipment->getDeliveryId())) {
                     /** @var Sale\Shipment $shipment */
                     $shipment = $shipmentCollection->createItem($service);
                 }
             }
             if ($shipment) {
                 $shipmentItemCollection = $shipment->getShipmentItemCollection();
                 if (!($shipmentItem = $shipmentItemCollection->getItemByBasketCode($basketItem->getBasketCode()))) {
                     $shipmentItem = $shipmentItemCollection->createItem($basketItem);
                 }
                 /** @var Sale\Result $r */
                 $r = $shipmentItem->setQuantity($basketItem->getQuantity());
                 if (!$r->isSuccess()) {
                     $result->addErrors($r->getErrors());
                 }
             }
         }
     }
     return $result;
 }
 /**
  * @internal
  * @param Sale\Order $order
  * @return array
  */
 public static function convertOrderToArray(Sale\Order $order)
 {
     $fields = $order->getFieldValues();
     //getWeight
     $fields = array_merge($fields, array('ORDER_WEIGHT' => 0, 'BASKET_ITEMS' => array(), 'ORDER_PROP' => array(), 'DISCOUNT_LIST' => array(), 'TAX_LIST' => array(), 'VAT_RATE' => $order->getVatRate(), 'VAT_SUM' => $order->getVatSum()));
     /** @var Sale\Basket $basket */
     if ($basket = $order->getBasket()) {
         /** @var Sale\BasketItem $basketItem */
         foreach ($basket as $basketItem) {
             $fields['BASKET_ITEMS'][] = BasketCompatibility::convertBasketItemToArray($basketItem);
         }
     }
     /** @var Sale\PropertyValueCollection $basket */
     if ($propertyCollection = $order->getPropertyCollection()) {
         /** @var Sale\PropertyValue $property */
         foreach ($propertyCollection as $property) {
             //				$propertyValue = $property->getValue();
             $fields['ORDER_PROP'][$property->getPropertyId()] = $property->getValue();
         }
     }
     if ($propProfileName = $propertyCollection->getProfileName()) {
         $fields['PROFILE_NAME'] = $propProfileName->getValue();
     }
     if ($propPayerName = $propertyCollection->getPayerName()) {
         $fields['PAYER_NAME'] = $propPayerName->getValue();
     }
     if ($propUserEmail = $propertyCollection->getUserEmail()) {
         $fields['USER_EMAIL'] = $propUserEmail->getValue();
     }
     if ($propDeliveryLocationZip = $propertyCollection->getDeliveryLocationZip()) {
         $fields['DELIVERY_LOCATION_ZIP'] = $propDeliveryLocationZip->getValue();
     }
     if ($propDeliveryLocation = $propertyCollection->getDeliveryLocation()) {
         $fields['DELIVERY_LOCATION'] = $propDeliveryLocation->getValue();
     }
     if ($propTaxLocation = $propertyCollection->getTaxLocation()) {
         $fields['TAX_LOCATION'] = $propTaxLocation->getValue();
     }
     /** @var Sale\ShipmentCollection $shipmentCollection */
     if ($shipmentCollection = $order->getShipmentCollection()) {
         $fields['ORDER_WEIGHT'] = $shipmentCollection->getWeight();
     }
     $fields['DISCOUNT_LIST'] = DiscountCompatibility::getOldDiscountResult();
     /** @var Sale\Tax $tax */
     if ($tax = $order->getTax()) {
         $fields['TAX_LIST'] = $tax->getTaxList();
     }
     return $fields;
 }
示例#5
0
 /**
  * @param Order $order
  * @param array $shipments
  * @return Result
  * @throws SystemException
  */
 public static function updateData(Order &$order, array $shipments)
 {
     global $USER;
     $result = new Result();
     $data = array();
     $basketResult = null;
     if (!$order) {
         $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_ORDER_NOT_FOUND')));
         return $result;
     }
     $shipmentCollection = $order->getShipmentCollection();
     $isStartField = $shipmentCollection->isStartField();
     foreach ($shipments as $item) {
         $shipmentId = intval($item['SHIPMENT_ID']);
         $isNew = $shipmentId <= 0;
         if ($isNew) {
             self::$shipment = $shipmentCollection->createItem();
         } else {
             self::$shipment = $shipmentCollection->getItemById($shipmentId);
             if (!self::$shipment) {
                 $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_SHIPMENT_NOT_FOUND')));
                 continue;
             }
         }
         self::$defaultFields = self::$shipment->getFieldValues();
         /** @var \Bitrix\Sale\BasketItem $product */
         $countItems = count(self::$shipment->getShipmentItemCollection());
         $systemShipment = $shipmentCollection->getSystemShipment();
         $systemShipmentItemCollection = $systemShipment->getShipmentItemCollection();
         $products = array();
         if (!isset($item['PRODUCT']) && self::$shipment->getId() <= 0) {
             $basket = $order->getBasket();
             if ($basket) {
                 $basketItems = $basket->getBasketItems();
                 foreach ($basketItems as $product) {
                     $systemShipmentItem = $systemShipmentItemCollection->getItemByBasketCode($product->getBasketCode());
                     if ($product->isBundleChild() || !$systemShipmentItem || $systemShipmentItem->getQuantity() <= 0) {
                         continue;
                     }
                     $products[] = array('AMOUNT' => $product->getQuantity(), 'BASKET_CODE' => $product->getBasketCode());
                 }
             }
         } else {
             $products = $item['PRODUCT'];
         }
         if ($item['DEDUCTED'] == 'Y') {
             $basketResult = OrderBasketShipment::updateData($order, self::$shipment, $products);
             if (!$basketResult->isSuccess()) {
                 $result->addErrors($basketResult->getErrors());
             }
         }
         $extraServices = $item['EXTRA_SERVICES'] ? $item['EXTRA_SERVICES'] : array();
         $shipmentFields = array('COMPANY_ID' => isset($item['COMPANY_ID']) && $item['COMPANY_ID'] > 0 ? $item['COMPANY_ID'] : 0, 'DEDUCTED' => $item['DEDUCTED'], 'DELIVERY_DOC_NUM' => $item['DELIVERY_DOC_NUM'], 'TRACKING_NUMBER' => $item['TRACKING_NUMBER'], 'CURRENCY' => $order->getCurrency(), 'COMMENTS' => $item['COMMENTS'], 'STATUS_ID' => $isNew ? DeliveryStatus::getInitialStatus() : $item['STATUS_ID']);
         if ($item['DELIVERY_DOC_DATE']) {
             try {
                 $shipmentFields['DELIVERY_DOC_DATE'] = new Date($item['DELIVERY_DOC_DATE']);
             } catch (Main\ObjectException $exception) {
                 $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_UNCORRECT_FORM_DATE')));
             }
         }
         $shipmentFields['DELIVERY_ID'] = $item['PROFILE'] > 0 ? $item['PROFILE'] : $item['DELIVERY_ID'];
         try {
             $service = Services\Manager::getService($shipmentFields['DELIVERY_ID']);
             if ($service->getParentService()) {
                 $shipmentFields['DELIVERY_NAME'] = $service->getParentService()->getName() . ':' . $service->getName();
             } else {
                 $shipmentFields['DELIVERY_NAME'] = $service->getName();
             }
         } catch (Main\ArgumentNullException $e) {
             $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_NO_DELIVERY_SERVICE')));
         }
         $responsibleId = self::$shipment->getField('RESPONSIBLE_ID');
         if ($item['RESPONSIBLE_ID'] != $responsibleId || empty($responsibleId)) {
             if (isset($item['RESPONSIBLE_ID'])) {
                 $shipmentFields['RESPONSIBLE_ID'] = $item['RESPONSIBLE_ID'];
             } else {
                 $shipmentFields['RESPONSIBLE_ID'] = $order->getField('RESPONSIBLE_ID');
             }
             if (!empty($shipmentFields['RESPONSIBLE_ID'])) {
                 $shipmentFields['EMP_RESPONSIBLE_ID'] = $USER->getID();
                 $shipmentFields['DATE_RESPONSIBLE_ID'] = new DateTime();
             }
         }
         if ($extraServices) {
             self::$shipment->setExtraServices($extraServices);
         }
         $setFieldsResult = self::$shipment->setFields($shipmentFields);
         if (!$setFieldsResult->isSuccess()) {
             $result->addErrors($setFieldsResult->getErrors());
         }
         self::$shipment->setStoreId($item['DELIVERY_STORE_ID']);
         if ($item['DEDUCTED'] == 'N') {
             $basketResult = OrderBasketShipment::updateData($order, self::$shipment, $products);
             if (!$basketResult->isSuccess()) {
                 $result->addErrors($basketResult->getErrors());
             }
         }
         try {
             $priceDeliveryInfo = array();
             if ($item['CUSTOM_PRICE_DELIVERY'] != 'Y') {
                 $totalPrice = self::getDeliveryPrice(self::$shipment);
             } else {
                 $totalPrice = (double) str_replace(',', '.', $item['BASE_PRICE_DELIVERY']);
             }
         } catch (\Exception $e) {
             $totalPrice = 0;
         }
         $priceDeliveryInfo['CUSTOM_PRICE_DELIVERY'] = $item['CUSTOM_PRICE_DELIVERY'];
         $priceDeliveryInfo['BASE_PRICE_DELIVERY'] = $totalPrice;
         self::$shipment->setFields($priceDeliveryInfo);
         self::$shipment->setField('ALLOW_DELIVERY', $item['ALLOW_DELIVERY']);
         $data['SHIPMENT'][] = self::$shipment;
     }
     if ($isStartField) {
         $hasMeaningfulFields = $shipmentCollection->hasMeaningfulField();
         /** @var Result $r */
         $r = $shipmentCollection->doFinalAction($hasMeaningfulFields);
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
     }
     $result->setData($data);
     return $result;
 }
示例#6
0
 /**
  * @param Order $order
  * @return Result
  * @throws NotSupportedException
  */
 private static function applyShipment(Order $order)
 {
     $result = new Result();
     /** @var ShipmentCollection $shipmentCollection */
     $shipmentCollection = $order->getShipmentCollection();
     /** @var Shipment $shipment */
     foreach ($shipmentCollection as $shipment) {
         /** @var Result $r */
         $r = static::shipShipment($shipment);
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
     }
     return $result;
 }