Exemple #1
1
 protected static function getPaymentsInfo(Order $order)
 {
     $payments = $order->getPaymentCollection();
     if (!$payments) {
         return array();
     }
     $result = array();
     /** @var $payment \Bitrix\Sale\Payment  */
     foreach ($payments as $payment) {
         $id = $payment->getField("PAY_SYSTEM_ID");
         $ptId = $order->getPersonTypeId();
         if (!$id || !$ptId) {
             continue;
         }
         $params = OrderPayment::getPaySystemParams($id, $ptId);
         if (!$params) {
             continue;
         }
         $result[] = array("ID" => $payment->getId(), "NAME" => $params["NAME"], "LOGOTIP_PATH" => $params["LOGOTIP_PATH"], "IS_PAYED" => $payment->isPaid());
     }
     return $result;
 }
    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;
    }
Exemple #3
0
 /**
  * @param Order $order
  * @param $payments
  * @param bool $canSetPaid
  * @return Result
  * @throws Main\ArgumentOutOfRangeException
  * @throws Main\ObjectNotFoundException
  * @throws UserMessageException
  */
 public static function updateData(Order &$order, $payments, $canSetPaid = false)
 {
     global $USER;
     $result = new Result();
     $data['PAYMENT'] = array();
     if (!$order) {
         throw new UserMessageException('Order does not exist');
     }
     foreach ($payments as $payment) {
         $paymentId = intval($payment['PAYMENT_ID']);
         $isNew = $paymentId <= 0;
         $paymentCollection = $order->getPaymentCollection();
         /** @var \Bitrix\Sale\Payment $paymentItem */
         if ($isNew) {
             $paymentItem = $paymentCollection->createItem();
         } else {
             $paymentItem = $paymentCollection->getItemById($paymentId);
             if (!$paymentItem) {
                 throw new UserMessageException('Payment does not exist');
             }
         }
         self::$defaultFields = $paymentItem->getFieldValues();
         $isReturn = isset($payment['IS_RETURN']) && $payment['IS_RETURN'] == 'Y';
         /** @var \Bitrix\Sale\PaySystemService $paymentService */
         $paymentService = PaySystemService::load($payment['PAY_SYSTEM_ID']);
         if (!$paymentService) {
             $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_PAYMENT_ERROR_PAYSYSTEM')));
         }
         $paymentFields = array('PAY_SYSTEM_ID' => $payment['PAY_SYSTEM_ID'], 'COMPANY_ID' => isset($payment['COMPANY_ID']) ? $payment['COMPANY_ID'] : 0, 'SUM' => $payment['SUM'], 'PAY_VOUCHER_NUM' => $payment['PAY_VOUCHER_NUM'], 'PAY_RETURN_NUM' => $payment['PAY_RETURN_NUM'], 'PAY_RETURN_COMMENT' => $payment['PAY_RETURN_COMMENT'], 'COMMENTS' => $payment['COMMENTS'], 'PAY_SYSTEM_NAME' => $paymentService ? $paymentService->getName() : '');
         if ($isNew) {
             $paymentFields['DATE_BILL'] = new DateTime();
         }
         if (!empty($payment['PAY_RETURN_DATE'])) {
             try {
                 $paymentFields['PAY_RETURN_DATE'] = new Date($payment['PAY_RETURN_DATE']);
             } catch (Main\ObjectException $exception) {
                 $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_PAYMENT_ERROR_RETURN_DATE_FORMAT')));
             }
         }
         if (!empty($payment['PAY_VOUCHER_DATE'])) {
             try {
                 $paymentFields['PAY_VOUCHER_DATE'] = new Date($payment['PAY_VOUCHER_DATE']);
             } catch (Main\ObjectException $exception) {
                 $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_PAYMENT_ERROR_VOUCHER_DATE_FORMAT')));
             }
         }
         if (isset($payment['RESPONSIBLE_ID'])) {
             $paymentFields['RESPONSIBLE_ID'] = !empty($payment['RESPONSIBLE_ID']) ? $payment['RESPONSIBLE_ID'] : $USER->GetID();
             if ($payment['RESPONSIBLE_ID'] != $paymentItem->getField('RESPONSIBLE_ID')) {
                 $paymentFields['DATE_RESPONSIBLE_ID'] = new DateTime();
                 if (!$isNew) {
                     $paymentFields['EMP_RESPONSIBLE_ID'] = $USER->GetID();
                 }
             }
         }
         if ($result->isSuccess()) {
             if ($paymentItem->getField('PAID') != $payment['PAID'] && $paymentItem->getField('IS_RETURN') == 'Y') {
                 $setResult = $paymentItem->setReturn('N');
                 if (!$setResult->isSuccess()) {
                     $result->addErrors($setResult->getErrors());
                 }
             }
             if ($isReturn && $payment['OPERATION_ID'] == 'RETURN') {
                 $setResult = $paymentItem->setReturn('Y');
                 if (!$setResult->isSuccess()) {
                     $result->addErrors($setResult->getErrors());
                 }
             }
             $setResult = $paymentItem->setFields($paymentFields);
             if (!$setResult->isSuccess()) {
                 $result->addErrors($setResult->getErrors());
             }
             if (!$canSetPaid) {
                 $setResult = $paymentItem->setPaid($payment['PAID']);
                 if (!$setResult->isSuccess()) {
                     $result->addErrors($setResult->getErrors());
                 }
             }
             if ($payment['ORDER_STATUS_ID']) {
                 $order->setField('STATUS_ID', $payment['ORDER_STATUS_ID']);
             }
         }
         $data['PAYMENT'][] = $paymentItem;
     }
     $result->setData($data);
     return $result;
 }
 /**
  * @param Sale\Order $order
  *
  * @return array
  */
 public static function getOrderFields(Sale\Order $order)
 {
     $result = new Sale\Result();
     $paymentSystemId = false;
     $deliveryId = false;
     /** @var Sale\PaymentCollection $paymentCollection */
     if ($paymentCollection = $order->getPaymentCollection()) {
         /** @var Sale\Payment $payment */
         if ($payment = $paymentCollection->rewind()) {
             $paymentSystemId = $payment->getPaymentSystemId();
         }
     }
     /** @var Sale\ShipmentCollection $shipe */
     if ($shipmentCollection = $order->getShipmentCollection()) {
         /** @var Sale\Shipment $shipment */
         foreach ($shipmentCollection as $shipment) {
             if ($shipment->getDeliveryId() > 0) {
                 $deliveryId = $shipment->getDeliveryId();
                 break;
             }
         }
     }
     $fields = array("SITE_ID" => $order->getSiteId(), "LID" => $order->getSiteId(), "PERSON_TYPE_ID" => $order->getPersonTypeId(), "PRICE" => $order->getPrice(), "CURRENCY" => $order->getCurrency(), "USER_ID" => $order->getUserId(), "PAY_SYSTEM_ID" => $paymentSystemId, "PRICE_DELIVERY" => $order->getDeliveryPrice(), "DELIVERY_ID" => $deliveryId, "DISCOUNT_VALUE" => $order->getDiscountPrice(), "TAX_VALUE" => $order->getTaxValue(), "TRACKING_NUMBER" => $order->getField('TRACKING_NUMBER'), "PAYED" => $order->getField('PAYED'), "CANCELED" => $order->getField('CANCELED'), "STATUS_ID" => $order->getField('STATUS_ID'), "RESERVED" => $order->getField('RESERVED'));
     $orderFields = static::convertOrderToArray($order);
     if (is_array($orderFields)) {
         $orderFields = $fields + $orderFields;
         $orderFields = static::convertDateFieldsToOldFormat($orderFields);
     }
     $result->setData(array('FIELDS' => $fields, 'ORDER_FIELDS' => $orderFields));
     return $result;
 }
Exemple #5
0
 /**
  * Fill empty order data.
  *
  * @param Order $order			Order object.
  * @return void
  */
 protected function fillEmptyOrderData(Order $order)
 {
     $this->orderData = array('ID' => $order->getId(), 'USER_ID' => $order->getUserId(), 'SITE_ID' => $order->getSiteId(), 'ORDER_PRICE' => $order->getPrice(), 'ORDER_WEIGHT' => 0, 'CURRENCY' => $order->getCurrency(), 'PERSON_TYPE_ID' => $order->getPersonTypeId(), 'BASKET_ITEMS' => array(), 'PRICE_DELIVERY' => 0, 'PRICE_DELIVERY_DIFF' => 0, 'DELIVERY_ID' => 0, 'CUSTOM_PRICE_DELIVERY' => 'N', 'SHIPMENT_CODE' => 0, 'SHIPMENT_ID' => 0);
     $paymentCollection = $order->getPaymentCollection();
     /** @var Payment $payment */
     foreach ($paymentCollection as $payment) {
         if ($payment->isInner()) {
             continue;
         }
         if (!isset($this->orderData['PAY_SYSTEM_ID'])) {
             $this->orderData['PAY_SYSTEM_ID'] = $payment->getPaymentSystemId();
             break;
         }
     }
     unset($payment, $paymentCollection);
     if (!isset($this->orderData['PAY_SYSTEM_ID'])) {
         $this->orderData['PAY_SYSTEM_ID'] = 0;
     }
 }