Ejemplo n.º 1
0
        /// <summary>
        /// Attaches an element named ShippingNotRequired that serves as a flag whether our order does not require shipping checking all the available factors
        /// </summary>
        /// <param name="nav">The XPathNavigator</param>
        private void CheckIfWeShouldRequireShipping(XPathNavigator nav)
        {
            XmlNode orderInfoNode         = GetXmlNode(nav.SelectSingleNode("Order/OrderInfo"));
            bool    weDontRequireShipping = false;

            if (AppLogic.AppConfigBool("SkipShippingOnCheckout") == true)
            {
                weDontRequireShipping = true;
            }
            else
            {
                bool isMultiShipping        = XmlCommon.XmlFieldBool(orderInfoNode, "multiship");
                bool allAreDownloadProducts = XmlCommon.XmlFieldBool(orderInfoNode, "allDownloads");
                bool allAreSystemProducts   = XmlCommon.XmlFieldBool(orderInfoNode, "allSystemproducts");

                weDontRequireShipping = isMultiShipping == false &&
                                        (allAreDownloadProducts || allAreSystemProducts);

                if (weDontRequireShipping == false)
                {
                    // now check if all of the line items is No Shipping Required..
                    XPathNodeIterator lineItemsThatAreNotFreeShippingIfAnyNodeIterator = nav.Select("OrderItems/Item[FreeShipping != 2]");
                    weDontRequireShipping = !lineItemsThatAreNotFreeShippingIfAnyNodeIterator.MoveNext();
                }
            }

            XmlNode shippingNotRequiredNode = orderInfoNode.OwnerDocument.CreateNode(XmlNodeType.Element, "ShippingNotRequired", string.Empty);

            shippingNotRequiredNode.InnerText = XmlCommon.XmlEncode(weDontRequireShipping.ToString());
            orderInfoNode.InsertAfter(shippingNotRequiredNode, orderInfoNode.LastChild);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Precompute the line item vat and discounts and attach it inside the order info node
        /// </summary>
        /// <param name="nav">The XPathNavigator</param>
        private void PreComputeLineItemIntrinsics(XPathNavigator nav)
        {
            XmlNode           orderInfoNode        = GetXmlNode(nav.SelectSingleNode("Order/OrderInfo"));
            XPathNodeIterator lineItemNodeIterator = nav.Select("OrderItems/Item");
            CultureInfo       cultureInfo;
            var orderCultureInfo = CommonLogic.Application("DBSQLServerLocaleSetting");

            cultureInfo = string.IsNullOrEmpty(orderCultureInfo)
                                ? CultureInfo.InvariantCulture
                                : new CultureInfo(orderCultureInfo);

            decimal allLineItemDiscounts = decimal.Zero;

            while (lineItemNodeIterator.MoveNext())
            {
                XmlNode lineItemNode = GetXmlNode(lineItemNodeIterator.Current);

                bool isAKit = XmlCommon.XmlFieldBool(lineItemNode, "IsAKit");

                int quantity = 1;
                int.TryParse(XmlCommon.XmlField(lineItemNode, "Quantity"), out quantity);

                decimal price = 0;
                Decimal.TryParse(XmlCommon.XmlField(lineItemNode, "OrderedProductRegularPrice"), NumberStyles.AllowDecimalPoint, cultureInfo, out price);

                decimal orderedExtendedPrice = 0;
                Decimal.TryParse(XmlCommon.XmlField(lineItemNode, "OrderedProductPrice"), NumberStyles.AllowDecimalPoint, cultureInfo, out orderedExtendedPrice);

                decimal taxRate = Decimal.Parse(XmlCommon.XmlField(lineItemNode, "TaxRate"), NumberStyles.AllowDecimalPoint, cultureInfo);

                decimal vatAmount         = decimal.Zero;
                decimal extendedVatAmount = decimal.Zero;

                bool applyVat = AppLogic.AppConfigBool("VAT.Enabled") == true &&
                                XmlCommon.XmlFieldBool(orderInfoNode, "LevelHasNoTax") == false &&
                                XmlCommon.XmlFieldBool(lineItemNode, "IsTaxable") == true &&
                                string.IsNullOrEmpty(XmlCommon.XmlField(orderInfoNode, "VATRegistrationID"));

                if (applyVat)
                {
                    if (AppLogic.AppConfigBool("VAT.RoundPerItem"))
                    {
                        vatAmount         = (((price / quantity) * taxRate) / 100M) * quantity;
                        extendedVatAmount = (((orderedExtendedPrice / quantity) * taxRate) / 100M) * quantity;
                    }
                    else
                    {
                        vatAmount         = (price * taxRate) / 100M;
                        extendedVatAmount = (orderedExtendedPrice * taxRate) / 100M;
                    }

                    if (isAKit)
                    {
                        vatAmount = extendedVatAmount / quantity;
                    }
                }
                // let's save these as decimal values, leave out formatting on a later call
                XmlNode vatAmountNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "VatAmount", string.Empty);
                vatAmountNode.InnerText = XmlCommon.XmlEncode(vatAmount.ToString(cultureInfo));

                XmlNode extVatAmountNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "ExtVatAmount", string.Empty);
                extVatAmountNode.InnerText = XmlCommon.XmlEncode(extendedVatAmount.ToString(cultureInfo));

                // insert these nodes on the bottom
                lineItemNode.InsertAfter(vatAmountNode, lineItemNode.LastChild);
                lineItemNode.InsertAfter(extVatAmountNode, lineItemNode.LastChild);

                decimal regularExtendedPrice = decimal.Zero;
                decimal discount             = decimal.Zero;

                // kit products don't save the regular price only the sales price
                // we won't be supporting line item discounts on these item types then
                if (isAKit)
                {
                    regularExtendedPrice = decimal.Zero;
                    discount             = decimal.Zero;

                    price = orderedExtendedPrice / quantity;
                }
                else
                {
                    // make sure to round to 2 decimal places
                    price = Math.Round(price, 2, MidpointRounding.AwayFromZero);
                    regularExtendedPrice = price * quantity;
                    discount             = (regularExtendedPrice - orderedExtendedPrice);
                }

                bool showPriceVatInclusive = ThisCustomer.VATSettingReconciled == VATSettingEnum.ShowPricesInclusiveOfVAT;

                decimal displayPrice = price;
                if (applyVat && showPriceVatInclusive)
                {
                    displayPrice += vatAmount;
                }

                decimal displayExtPrice = orderedExtendedPrice;
                if (applyVat && showPriceVatInclusive)
                {
                    displayExtPrice += extendedVatAmount;
                }

                // let's save these as decimal values, leave out formatting on a later call
                XmlNode extRegularPriceNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "ExtendedRegularPrice", string.Empty);
                extRegularPriceNode.InnerText = XmlCommon.XmlEncode(regularExtendedPrice.ToString(cultureInfo));
                // insert these nodes on the bottom
                lineItemNode.InsertAfter(extRegularPriceNode, lineItemNode.LastChild);

                XmlNode discountNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "DiscountAmount", string.Empty);
                discountNode.InnerText = XmlCommon.XmlEncode(discount.ToString(cultureInfo));
                // insert these nodes on the bottom
                lineItemNode.InsertAfter(discountNode, lineItemNode.LastChild);

                // price column
                XmlNode priceNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "Price", string.Empty);
                priceNode.InnerText = XmlCommon.XmlEncode(price.ToString(cultureInfo));
                // insert these nodes on the bottom
                lineItemNode.InsertAfter(priceNode, lineItemNode.LastChild);

                XmlNode displayPriceNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "DisplayPrice", string.Empty);
                displayPriceNode.InnerText = XmlCommon.XmlEncode(displayPrice.ToString(cultureInfo));
                // insert these nodes on the bottom
                lineItemNode.InsertAfter(displayPriceNode, lineItemNode.LastChild);

                XmlNode displayExtPriceNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "DisplayExtPrice", string.Empty);
                displayExtPriceNode.InnerText = XmlCommon.XmlEncode(displayExtPrice.ToString(cultureInfo));
                // insert these nodes on the bottom
                lineItemNode.InsertAfter(displayExtPriceNode, lineItemNode.LastChild);

                XmlNode discountWithVATNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "DiscountWithVAT", string.Empty);
                discountWithVATNode.InnerText = XmlCommon.XmlEncode((displayPrice - displayExtPrice).ToString(cultureInfo));
                // insert these nodes on the bottom
                lineItemNode.InsertAfter(discountWithVATNode, lineItemNode.LastChild);

                // store the line item discounts
                allLineItemDiscounts += XmlCommon.XmlFieldNativeDecimal(lineItemNode, "DiscountAmount");
            }

            bool hasLineItemDiscounts = false;

            hasLineItemDiscounts = allLineItemDiscounts > decimal.Zero;

            XmlNode hasLineItemDiscountsNode = orderInfoNode.OwnerDocument.CreateNode(XmlNodeType.Element, "HasLineItemDiscounts", string.Empty);

            hasLineItemDiscountsNode.InnerText = XmlCommon.XmlEncode(hasLineItemDiscounts.ToString(cultureInfo));
            orderInfoNode.InsertAfter(hasLineItemDiscountsNode, orderInfoNode.LastChild);
        }