/// <summary>
            /// Processes a save customer order request in headquarter.
            /// </summary>
            /// <param name="request">The save customer order request.</param>
            /// <returns>The customer order service default response.</returns>
            private static Response SaveCustomerOrderInHeadquarter(SaveCustomerOrderRealtimeRequest request)
            {
                string                      xmlRequest;
                SalesTransaction            salesTransaction;
                ReadOnlyCollection <object> resultCollection;

                salesTransaction = request.SalesTransaction;

                // Converts transaction into xml request blob
                xmlRequest = SalesTransactionSerializationHelper.ConvertSalesTransactionToXml(
                    salesTransaction,
                    request.CardTokenInfo,
                    request.CardAuthorizationTokenResponseXml ?? string.Empty,
                    request.RequestContext);

                // Calls TS API
                resultCollection = new TransactionServiceClient(request.RequestContext).SaveCustomerOrder(
                    salesTransaction.SalesId,
                    salesTransaction.CustomerOrderType,
                    salesTransaction.CustomerOrderMode,
                    xmlRequest);

                switch (salesTransaction.CustomerOrderMode)
                {
                case CustomerOrderMode.QuoteCreateOrEdit:
                case CustomerOrderMode.CustomerOrderCreateOrEdit:
                case CustomerOrderMode.Return:
                    // Sets Sales Id for the order on the transaction
                    salesTransaction.SalesId           = (string)resultCollection[0];
                    salesTransaction.CustomerOrderType = salesTransaction.CustomerOrderMode == CustomerOrderMode.QuoteCreateOrEdit
                            ? CustomerOrderType.Quote
                            : CustomerOrderType.SalesOrder;
                    break;

                // no return value for pick up and cancellation
                case CustomerOrderMode.Cancellation:
                case CustomerOrderMode.Pickup:
                    break;

                default:
                    throw new NotSupportedException(salesTransaction.CustomerOrderMode + " type for customer order is not supported.");
                }

                return(new NullResponse());
            }
Exemplo n.º 2
0
            /// <summary>
            /// Converts a sales transaction into the XML that transaction service can consume.
            /// </summary>
            /// <param name="salesTransaction">The sales transaction to be converted.</param>
            /// <param name="cardToken">The card token object.</param>
            /// <param name="cardTokenResponseXml">The card token response XML.</param>
            /// <param name="context">The request context.</param>
            /// <returns>The customer order info object.</returns>
            public static string ConvertSalesTransactionToXml(
                SalesTransaction salesTransaction,
                CardTokenInfo cardToken,
                string cardTokenResponseXml,
                RequestContext context)
            {
                string storeCurrency = context.GetChannelConfiguration().Currency;

                CustomerOrderInfo parameters = new CustomerOrderInfo();

                parameters.OrderType = salesTransaction.CustomerOrderMode == CustomerOrderMode.QuoteCreateOrEdit
                    ? CustomerOrderType.Quote
                    : CustomerOrderType.SalesOrder;
                parameters.AutoPickOrder = false;

                parameters.Id          = salesTransaction.SalesId;
                parameters.QuotationId = salesTransaction.SalesId;

                parameters.CustomerAccount      = salesTransaction.CustomerId;
                parameters.ChannelRecordId      = salesTransaction.ChannelId.ToString(CultureInfo.InvariantCulture);
                parameters.SalespersonStaffId   = salesTransaction.StaffId ?? string.Empty;
                parameters.IsTaxIncludedInPrice = salesTransaction.IsTaxIncludedInPrice.ToString();

                parameters.WarehouseId    = salesTransaction.InventoryLocationId;
                parameters.CurrencyCode   = storeCurrency;
                parameters.StoreId        = salesTransaction.StoreId;
                parameters.TerminalId     = salesTransaction.TerminalId;
                parameters.TransactionId  = salesTransaction.Id;
                parameters.LocalHourOfDay = DateTime.Now.Hour + 1; // headquarters will match this value with an id

                parameters.AddressRecordId = SalesTransactionSerializationHelper.ConvertAddressRecIdToString(salesTransaction.ShippingAddress);

                parameters.ExpiryDateString = Utilities.ConvertDateToAxString(salesTransaction.QuotationExpiryDate);

                parameters.RequestedDeliveryDateString = Utilities.ConvertDateToAxString(salesTransaction.RequestedDeliveryDate);
                parameters.DeliveryMode = string.IsNullOrWhiteSpace(salesTransaction.DeliveryMode) ? string.Empty : salesTransaction.DeliveryMode;
                parameters.PrepaymentAmountOverridden = salesTransaction.IsDepositOverridden;
                parameters.PrepaymentAmountApplied    = salesTransaction.PrepaymentAmountAppliedOnPickup;
                parameters.OriginalTransactionTime    = DateTime.UtcNow;

                parameters.TotalManualDiscountAmount     = salesTransaction.TotalManualDiscountAmount;
                parameters.TotalManualDiscountPercentage = salesTransaction.TotalManualDiscountPercentage;

                parameters.Email         = salesTransaction.ReceiptEmail;
                parameters.Comment       = salesTransaction.Comment ?? string.Empty;
                parameters.LoyaltyCardId = string.IsNullOrWhiteSpace(salesTransaction.LoyaltyCardId) ? string.Empty : salesTransaction.LoyaltyCardId;

                parameters.ChannelReferenceId = salesTransaction.ChannelReferenceId;

                parameters.ReturnReasonCodeId = SalesTransactionSerializationHelper.GetReturnReasonCodeId(salesTransaction, context);

                if (cardToken != null)
                {
                    parameters.CreditCardToken = cardTokenResponseXml;
                }

                // Sales lines
                SalesTransactionSerializationHelper.FillSaleLines(parameters, salesTransaction);

                // Payments
                SalesTransactionSerializationHelper.FillPaymentInformation(parameters, salesTransaction, storeCurrency);

                // Charges
                SalesTransactionSerializationHelper.ConvertChargeLinesToChargeInfos(salesTransaction.ChargeLines, parameters.Charges);

                // Affiliations and loyalty tiers
                SalesTransactionSerializationHelper.FillAffiliationsAndLoyaltyTiers(parameters, salesTransaction);

                // Discount codes
                parameters.DiscountCodes.AddRange(salesTransaction.DiscountCodes.ToArray());

                // Extension properties
                parameters.ExtensionProperties.AddRange(salesTransaction.ExtensionProperties);

                return(parameters.ToXml());
            }
Exemplo n.º 3
0
            /// <summary>
            /// Fills a customer order info object with a sales transaction sales line information.
            /// </summary>
            /// <param name="parameters">The customer order info object to be filled.</param>
            /// <param name="salesTransaction">The sales transaction object used as source.</param>
            private static void FillSaleLines(CustomerOrderInfo parameters, SalesTransaction salesTransaction)
            {
                ProductVariant emptyVariant = new ProductVariant();

                // Line Items
                foreach (SalesLine salesLine in salesTransaction.ActiveSalesLines)
                {
                    if (!salesLine.IsVoided && !(salesTransaction.CustomerOrderMode == CustomerOrderMode.Return && salesLine.Quantity == 0))
                    {
                        // use property from header, override with line property if available
                        string deliveryMode = string.IsNullOrWhiteSpace(salesLine.DeliveryMode) ? parameters.DeliveryMode : salesLine.DeliveryMode;

                        // use property from header, override with line property if available
                        string deliveryDateString =
                            Utilities.IsDateNullOrDefaultValue(salesLine.RequestedDeliveryDate)
                                ? parameters.RequestedDeliveryDateString
                                : Utilities.ConvertDateToAxString(salesLine.RequestedDeliveryDate);

                        // If no line-level warehouse is specified, fall back to the header warehouse
                        string inventLocationId = string.IsNullOrWhiteSpace(salesLine.InventoryLocationId) ? parameters.WarehouseId : salesLine.InventoryLocationId;

                        // AX SO line stores discount amount per item, CRT stores for whole line, calculate per item discount amount
                        decimal lineDiscount = salesLine.Quantity == 0M ? 0M : (salesLine.TotalDiscount + salesLine.LineDiscount + salesLine.PeriodicDiscount) / salesLine.Quantity;

                        string lineAddress = SalesTransactionSerializationHelper.ConvertAddressRecIdToString(salesLine.ShippingAddress);

                        // use header address is line does not have it set
                        if (string.IsNullOrWhiteSpace(lineAddress))
                        {
                            lineAddress = parameters.AddressRecordId;
                        }

                        ProductVariant variant = salesLine.Variant ?? emptyVariant;

                        ItemInfo itemInfo = new ItemInfo()
                        {
                            RecId = salesLine.RecordId,

                            // quantity
                            ItemId   = salesLine.ItemId,
                            Quantity = salesLine.Quantity,
                            Comment  = salesLine.Comment,
                            Unit     = salesLine.SalesOrderUnitOfMeasure,

                            // pricing
                            Price         = salesLine.Price,
                            Discount      = lineDiscount,
                            NetAmount     = salesLine.NetAmount,
                            ItemTaxGroup  = salesLine.ItemTaxGroupId,
                            SalesTaxGroup = salesLine.SalesTaxGroupId,
                            SalesMarkup   = 0M,

                            PeriodicDiscount           = salesLine.PeriodicDiscount,
                            PeriodicPercentageDiscount = salesLine.PeriodicPercentageDiscount,
                            LineDscAmount                = salesLine.LineDiscount,
                            LineManualDiscountAmount     = salesLine.LineManualDiscountAmount,
                            LineManualDiscountPercentage = salesLine.LineManualDiscountPercentage,
                            TotalDiscount                = salesLine.TotalDiscount,
                            TotalPctDiscount             = salesLine.TotalPercentageDiscount,

                            // delivery
                            WarehouseId                 = inventLocationId,
                            AddressRecordId             = lineAddress,
                            DeliveryMode                = deliveryMode,
                            RequestedDeliveryDateString = deliveryDateString,
                            FulfillmentStoreId          = salesLine.FulfillmentStoreId,

                            // inventDim
                            BatchId   = salesLine.BatchId,
                            SerialId  = salesLine.SerialNumber,
                            VariantId = variant.VariantId ?? string.Empty,
                            ColorId   = variant.ColorId ?? string.Empty,
                            SizeId    = variant.SizeId ?? string.Empty,
                            StyleId   = variant.StyleId ?? string.Empty,
                            ConfigId  = variant.ConfigId ?? string.Empty,

                            // Return
                            InvoiceId           = salesLine.ReturnTransactionId,
                            ReturnInventTransId = salesLine.ReturnInventTransId,

                            Catalog = salesLine.CatalogId,

                            Giftcard = false,
                        };

                        // line-level misc. charges
                        SalesTransactionSerializationHelper.ConvertChargeLinesToChargeInfos(salesLine.ChargeLines, itemInfo.Charges);

                        // line -level discount
                        SalesTransactionSerializationHelper.ConvertDiscountLineToDiscountInfos(salesLine.DiscountLines, itemInfo.Discounts);

                        parameters.Items.Add(itemInfo);
                    }
                }
            }