private void GetEligibleUsePoint()
        {
            string          msg         = (string)GetLocalResourceObject("EligiblePCLearningPoint.Text");
            decimal         eligibleAmt = 0;
            OrderTotals_V01 totals      = ShoppingCart.Totals as OrderTotals_V01;

            Charge_V01 freightCharge =
                totals.ChargeList.Find(
                    delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.FREIGHT); }) as
                Charge_V01 ?? new Charge_V01(ChargeTypes.FREIGHT, (decimal)0.0);

            decimal PCLearningPoint = ShoppingCart.PCLearningPoint;

            if (PCLearningPoint == 0)
            {
                eligibleAmt = 0;
            }
            else if (freightCharge.Amount >= PCLearningPoint)
            {
                eligibleAmt = Math.Truncate(PCLearningPoint);
            }
            else if (PCLearningPoint > freightCharge.Amount)
            {
                eligibleAmt = Math.Truncate(freightCharge.Amount);
            }

            lblEligiblePCLearningPoint.Text = string.Format(msg, PCLearningPoint.ToString(), eligibleAmt.ToString());
        }
        public void Initial()
        {
            shoppingCart = new MyHLShoppingCart
            {
                OrderHeaderID  = 123456,
                ShoppingCartID = 123456,
                OrderDate      = new DateTime(2016, 3, 1),
                CountryCode    = "CN",
                OrderMonth     = 3,
                Totals         = new OrderTotals_V01
                {
                    AmountDue = 100
                },
                CartItems = new MyHerbalife3.Ordering.ServiceProvider.CatalogSvc.ShoppingCartItemList
                {
                    new MyHerbalife3.Ordering.ServiceProvider.CatalogSvc.ShoppingCartItem_V01 {
                        SKU = "1314", Quantity = 2
                    },
                    new MyHerbalife3.Ordering.ServiceProvider.CatalogSvc.ShoppingCartItem_V01 {
                        SKU = "1317", Quantity = 2
                    }
                }
            };

            Charge_V01 chrg = new Charge_V01
            {
                Amount     = 10,
                ChargeType = ChargeTypes.FREIGHT
            };

            req = new MyHerbalife3.Ordering.ServiceProvider.OrderChinaSvc.PCLearningPointRequest_V01
            {
                DistributorID = "test_id",
                OrderNumber   = "111",
                Platform      = "CN",
                Point         = 5,
                VolumeMonth   = "201603",
                Opt           = ""
            };
        }
        protected override void BindTotals()
        {
            decimal earnBase = 0.00M;
            List <DistributorShoppingCartItem> lstShoppingCartItems =
                (Page as ProductsBase).ShoppingCart.ShoppingCartItems;

            try
            {
                if (lstShoppingCartItems.Count > 0 && _shoppingCart.Totals != null)
                {
                    OrderTotals_V01 totals = _shoppingCart.Totals as OrderTotals_V01;
                    foreach (DistributorShoppingCartItem shoppingCartItem in lstShoppingCartItems)
                    {
                        earnBase += shoppingCartItem.EarnBase;
                    }

                    lblDiscountRate.Text = _shoppingCart.Totals == null
                                               ? "0%"
                                               : (totals.DiscountPercentage).ToString() + "%";
                    lblDistributorSubtotal.Text = getAmountString(totals.DiscountedItemsTotal);
                    lblEarnBase.Text            = getAmountString(GetTotalEarnBase(lstShoppingCartItems));
                    if (ProductsBase.IsEventTicketMode)
                    {
                        var orderMonthShortString = string.Empty;
                        var ordermonth            = OrderMonth.DualOrderMonthForEventTicket(true, out orderMonthShortString); // dual ordermonth should be desable for ETO
                        lblOrderMonth.Text = string.IsNullOrWhiteSpace(ordermonth) ? GetOrderMonthString() : ordermonth;
                        var currentSession = SessionInfo;

                        if (null != currentSession && !string.IsNullOrWhiteSpace(orderMonthShortString))
                        {
                            currentSession.OrderMonthString      = ordermonth;
                            currentSession.OrderMonthShortString = orderMonthShortString;
                        }
                    }
                    else
                    {
                        lblOrderMonth.Text = GetOrderMonthString();
                    }

                    decimal currentMonthVolume = 0;
                    if (decimal.TryParse((Page as ProductsBase).CurrentMonthVolume, out currentMonthVolume))
                    {
                        lblOrderMonthVolume.Text =
                            HLConfigManager.Configurations.CheckoutConfiguration.UseUSPricesFormat
                                ? currentMonthVolume.ToString("N", CultureInfo.GetCultureInfo("en-US"))
                                : currentMonthVolume.ToString("N2");
                    }
                    else
                    {
                        lblOrderMonthVolume.Text = (Page as ProductsBase).CurrentMonthVolume;
                    }

                    Charge_V01 otherCharges =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.OTHER); }) as
                        Charge_V01 ?? new Charge_V01(ChargeTypes.OTHER, (decimal)0.0);
                    Charge_V01 pHCharge =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.PH); }) as Charge_V01 ??
                        new Charge_V01(ChargeTypes.PH, (decimal)0.0);
                    Charge_V01 freightCharge =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.FREIGHT); }) as
                        Charge_V01 ?? new Charge_V01(ChargeTypes.FREIGHT, (decimal)0.0);
                    lblOtherCharges.Text = getAmountString(otherCharges.Amount);
                    Charge_V01 localTaxCharge = OrderProvider.GetLocalTax(_shoppingCart.Totals as OrderTotals_V01);
                    lblLocalTax.Text        = getAmountString(localTaxCharge.Amount);
                    lblPackageHandling.Text = getAmountString(pHCharge.Amount);
                    Charge_V01 logisticCharge =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.LOGISTICS_CHARGE); })
                        as Charge_V01 ?? new Charge_V01(ChargeTypes.LOGISTICS_CHARGE, (decimal)0.0);
                    lblLogisticCharges.Text = getAmountString(logisticCharge.Amount);
                    var amount = GetSubTotalValue(totals, CountryCode);
                    lblSubtotal.Text        = getAmountString(amount);
                    lblRetailPrice.Text     = getAmountString(totals.ItemsTotal);
                    lblShippingCharges.Text = getAmountString(freightCharge.Amount);
                    lblTaxVAT.Text          = getAmountString(OrderProvider.GetTaxAmount(_shoppingCart.Totals as OrderTotals_V01));

                    Charge_V01 taxedNet =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.TAXEDNET); }) as
                        Charge_V01 ?? new Charge_V01(ChargeTypes.TAXEDNET, (decimal)0.0);
                    lblTaxedNet.Text = getAmountString(taxedNet.Amount);


                    lblVolumePoints.Text = HLConfigManager.Configurations.CheckoutConfiguration.UseUSPricesFormat
                                               ? totals.VolumePoints.ToString("N",
                                                                              CultureInfo.GetCultureInfo(
                                                                                  "en-US"))
                                               : totals.VolumePoints.ToString("N2");

                    lblGrandTotal.Text = getAmountString(totals.AmountDue);
                }
                else
                {
                    DisplayEmptyLabels();
                }

                if (HLConfigManager.Configurations.CheckoutConfiguration.HasTotalTaxable)
                {
                    trTaxedNet.Visible = true;
                    trTax.Visible      = false;
                }

                if (_shoppingCart.Totals != null)
                {
                    OrderTotals_V01 totals = _shoppingCart.Totals as OrderTotals_V01;
                    if (HLConfigManager.Configurations.CheckoutConfiguration.HasTaxPercentage)
                    {
                        trTaxPercentage.Visible = true;
                        //lblPercentage.Text = HLConfigManager.Configurations.CheckoutConfiguration.TaxPercentage + "%";
                        lblPercentage.Text = _shoppingCart.Totals != null
                                                 ? getAmountString(OrderProvider.GetTaxAmount(_shoppingCart.Totals as OrderTotals_V01))
                                                 : string.Empty;
                    }

                    if (HLConfigManager.Configurations.CheckoutConfiguration.HasTotalDiscount)
                    {
                        trTotalDiscount.Visible = true;
                        lblTotalDiscount2.Text  = _shoppingCart.Totals != null
                                                     ? getAmountString(totals.TotalItemDiscount)
                                                     : string.Empty;
                    }
                    // hide this row if there is no local tax return
                    trLocalTax.Visible = OrderProvider.HasLocalTax(totals);
                }
            }
            catch (Exception ex)
            {
                //Log Exception
                LoggerHelper.Error("Exception while displaying totals - " + ex);
                DisplayEmptyLabels();
            }
        }
Exemplo n.º 4
0
        protected override void BindTotals()
        {
            var lstShoppingCartItems = (Page as ProductsBase).ShoppingCart.ShoppingCartItems;

            try
            {
                if ((HLConfigManager.Configurations.DOConfiguration.CalculateWithoutItems &&
                     _shoppingCart.Totals != null &&
                     (_shoppingCart.Totals as OrderTotals_V01).AmountDue != decimal.Zero) || (lstShoppingCartItems.Count > 0 && ShoppingCart.Totals != null))

                //                if (lstShoppingCartItems.Count > 0 && ShoppingCart.Totals != null)
                {
                    OrderTotals_V01 totals = ShoppingCart.Totals as OrderTotals_V01;

                    lblDiscountRate.Text = _shoppingCart.Totals == null
                                               ? "0%"
                                               : ((_shoppingCart.Totals as OrderTotals_V01).DiscountPercentage).ToString() + "%";
                    _shoppingCart.EmailValues.DistributorSubTotal          = OrderProvider.GetDistributorSubTotal(_shoppingCart.Totals as OrderTotals_V01);
                    _shoppingCart.EmailValues.DistributorSubTotalFormatted = getAmountString(_shoppingCart.EmailValues.DistributorSubTotal);
                    lblDistributorSubtotal.Text = _shoppingCart.EmailValues.DistributorSubTotalFormatted;
                    lblEarnBase.Text            = getAmountString(GetTotalEarnBase(lstShoppingCartItems));
                    if (lblDiscountTotal != null)
                    {
                        lblDiscountTotal.Text =
                            getAmountString(CheckoutTotalsDetailed.GetDiscountTotal(lstShoppingCartItems));
                    }

                    // added for China DO
                    if (HLConfigManager.Configurations.CheckoutConfiguration.HasDiscountAmount)
                    {
                        OrderTotals_V02 totals_V02 = ShoppingCart.Totals as OrderTotals_V02;
                        if (totals_V02 != null)
                        {
                            HLRulesManager.Manager.PerformDiscountRules(_shoppingCart, null, Locale,
                                                                        ShoppingCartRuleReason.CartCalculated);
                            lblDiscountAmount.Text = getAmountString(totals_V02.DiscountAmount);
                            trDiscountRate.Visible = false;
                        }
                    }
                    if (HLConfigManager.Configurations.DOConfiguration.DonationWithoutSKU)
                    {
                        if (trDonationAmount != null)
                        {
                            trDonationAmount.Visible = true;
                            OrderTotals_V02 totals_V02 = ShoppingCart.Totals as OrderTotals_V02;
                            if (totals_V02 != null)
                            {
                                lblDonationAmount.Text = getAmountString(totals_V02.Donation);
                            }
                        }
                    }
                    lblOrderMonth.Text = GetOrderMonthString();

                    decimal currentMonthVolume = 0;
                    if (HLConfigManager.Configurations.CheckoutConfiguration.DisplayFormatNeedsDecimal)
                    {
                        lblOrderMonthVolume.Text = decimal.TryParse(ProductsBase.CurrentMonthVolume, NumberStyles.Any, CultureInfo.InstalledUICulture, out currentMonthVolume)
                            ? ProductsBase.GetVolumePointsFormat(currentMonthVolume) :
                                                   (Page as ProductsBase).CurrentMonthVolume;
                    }
                    else if (decimal.TryParse((Page as ProductsBase).CurrentMonthVolume, out currentMonthVolume))
                    {
                        lblOrderMonthVolume.Text = ProductsBase.GetVolumePointsFormat(currentMonthVolume);
                    }
                    else
                    {
                        lblOrderMonthVolume.Text = (Page as ProductsBase).CurrentMonthVolume;
                    }


                    Charge_V01 otherCharges =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.OTHER); }) as
                        Charge_V01 ?? new Charge_V01(ChargeTypes.OTHER, (decimal)0.0);
                    Charge_V01 pHCharge =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.PH); }) as Charge_V01 ??
                        new Charge_V01(ChargeTypes.PH, (decimal)0.0);
                    Charge_V01 freightCharge =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.FREIGHT); }) as
                        Charge_V01 ?? new Charge_V01(ChargeTypes.FREIGHT, (decimal)0.0);
                    Charge_V01 localTaxCharge =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.LOCALTAX); }) as
                        Charge_V01 ?? new Charge_V01(ChargeTypes.LOCALTAX, (decimal)0.0);
                    lblOtherCharges.Text = getAmountString(otherCharges.Amount);
                    lblLocalTax.Text     = getAmountString(localTaxCharge.Amount);
                    Charge_V01 logisticCharge =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.LOGISTICS_CHARGE); })
                        as Charge_V01 ?? new Charge_V01(ChargeTypes.LOGISTICS_CHARGE, (decimal)0.0);
                    lblLogisticCharges.Text = getAmountString(logisticCharge.Amount);
                    lblPackageHandling.Text = getAmountString(pHCharge.Amount + totals.MarketingFundAmount);
                    lblShippingCharges.Text = getAmountString(freightCharge.Amount);
                    lblRetailPrice.Text     = getAmountString(totals.ItemsTotal);

                    decimal vatTax = totals.VatTax != null ? (decimal)totals.VatTax : decimal.Zero;
                    lblTaxVAT.Text = getAmountString(vatTax);

                    //Changes as per User Story 235045
                    bool    hideLabels = RemovePHCharge();
                    decimal serviceTax = totals.ServiceTax != null ? (decimal)totals.ServiceTax: decimal.Zero;
                    lblServiceTax.Text = getAmountString(serviceTax);
                    if (serviceTax == 0)
                    {
                        serviceTAX.Visible = hideLabels ? false : true;
                    }

                    decimal bharatTax = totals.SwachhBharatCess != null ? (decimal)totals.SwachhBharatCess : decimal.Zero;
                    lblBharatCessTax.Text = getAmountString(bharatTax);
                    if (bharatTax == 0)
                    {
                        bharatCessTAX.Visible = hideLabels ? false : true;
                    }

                    var kkcEnabled = HL.Common.Configuration.Settings.GetRequiredAppSetting("KKCEnabled", false);
                    if (kkcEnabled)
                    {
                        decimal krishiTax = totals.KrishiKalyanCess != null ? (decimal)totals.KrishiKalyanCess : decimal.Zero;
                        lblKKCTax.Text = getAmountString(krishiTax);
                        if (krishiTax == 0)
                        {
                            kkcTax.Visible = hideLabels ? false : true;
                        }
                    }
                    else
                    {
                        kkcTax.Visible = false;
                    }
                    //User Story 251995:GDO[PRODUCTION SUPPORT]: IN: For fixing the Tax display issue on GDO Checkout page for Additional/Exceptional Tax applicable states
                    decimal AdditionalTax = totals.AdditionalTaxCess != null ? (decimal)totals.AdditionalTaxCess : decimal.Zero;
                    lblAdditionalTax.Text = getAmountString(AdditionalTax);
                    if (AdditionalTax == 0)
                    {
                        additionalTax.Visible = hideLabels ? false : true;
                    }
                    decimal CSTTax = totals.CstTax != null ? (decimal)totals.CstTax : decimal.Zero;
                    lblCSTTax.Text = getAmountString(CSTTax);
                    if (CSTTax == 0)
                    {
                        cstTax.Visible = hideLabels ? false : true;
                    }
                    //

                    if (lblSubtotal != null)
                    {
                        lblSubtotal.Text = getAmountString(logisticCharge.Amount);
                    }
                    if (lblAdditionalDiscount != null)
                    {
                        lblAdditionalDiscount.Text = getAmountString(otherCharges.Amount);
                    }
                    lblVolumePoints.Text = ProductsBase.GetVolumePointsFormat(totals.VolumePoints);
                }
                else
                {
                    if (HLConfigManager.Configurations.DOConfiguration.DonationWithoutSKU)
                    {
                        if (trDonationAmount != null)
                        {
                            trDonationAmount.Visible = true;
                            OrderTotals_V02 totals_V02 = ShoppingCart.Totals as OrderTotals_V02;
                            if (totals_V02 != null)
                            {
                                lblDonationAmount.Text = getAmountString(totals_V02.Donation);
                            }
                        }
                    }

                    DisplayEmptyLabels();
                }
            }
            catch (Exception ex)
            {
                //Log Exception
                LoggerHelper.Error("Exception while displaying totals - " + ex);
                DisplayEmptyLabels();
            }
        }
        protected virtual void BindTotals()
        {
            List <DistributorShoppingCartItem> lstShoppingCartItems =
                (Page as ProductsBase).ShoppingCart.ShoppingCartItems;

            try
            {
                if ((HLConfigManager.Configurations.DOConfiguration.CalculateWithoutItems &&
                     _shoppingCart.Totals != null &&
                     (_shoppingCart.Totals as OrderTotals_V01).AmountDue != decimal.Zero) || (lstShoppingCartItems.Count > 0 && ShoppingCart.Totals != null))
                {
                    OrderTotals_V01 totals = ShoppingCart.Totals as OrderTotals_V01;

                    lblDiscountRate.Text = _shoppingCart.Totals == null
                                               ? "0%"
                                               : ((_shoppingCart.Totals as OrderTotals_V01).DiscountPercentage).ToString() + "%";
                    _shoppingCart.EmailValues.DistributorSubTotal          = OrderProvider.GetDistributorSubTotal(_shoppingCart.Totals as OrderTotals_V01);
                    _shoppingCart.EmailValues.DistributorSubTotalFormatted = getAmountString(_shoppingCart.EmailValues.DistributorSubTotal);
                    lblDistributorSubtotal.Text = _shoppingCart.EmailValues.DistributorSubTotalFormatted;
                    lblEarnBase.Text            = getAmountString(GetTotalEarnBase(lstShoppingCartItems));
                    if (lblDiscountTotal != null)
                    {
                        lblDiscountTotal.Text =
                            getAmountString(CheckoutTotalsDetailed.GetDiscountTotal(lstShoppingCartItems));
                    }
                    if (IsChina && (DistributorOrderingProfile.IsPC || (ShoppingCart.OrderCategory == OrderCategoryType.ETO && SessionInfo != null && !SessionInfo.IsReplacedPcOrder)))
                    {
                        lblPCLearningPointAmount.Text = getAmountString(_shoppingCart.pcLearningPointOffSet);
                    }
                    // added for China DO
                    if (HLConfigManager.Configurations.CheckoutConfiguration.HasDiscountAmount)
                    {
                        OrderTotals_V02 totals_V02 = ShoppingCart.Totals as OrderTotals_V02;
                        if (totals_V02 != null)
                        {
                            HLRulesManager.Manager.PerformDiscountRules(_shoppingCart, null, Locale,
                                                                        ShoppingCartRuleReason.CartCalculated);
                            lblDiscountAmount.Text = getAmountString(totals_V02.DiscountAmount);
                            trDiscountRate.Visible = false;
                        }
                    }
                    if (HLConfigManager.Configurations.DOConfiguration.DonationWithoutSKU)
                    {
                        if (trDonationAmount != null)
                        {
                            trDonationAmount.Visible = true;
                            OrderTotals_V02 totals_V02 = ShoppingCart.Totals as OrderTotals_V02;
                            if (totals_V02 != null)
                            {
                                lblDonationAmount.Text = getAmountString(totals_V02.Donation);
                            }
                        }
                    }
                    if (ProductsBase.IsEventTicketMode)
                    {
                        var orderMonthShortString = string.Empty;
                        var ordermonth            = OrderMonth.DualOrderMonthForEventTicket(true, out orderMonthShortString); // dual ordermonth should be desable for ETO
                        lblOrderMonth.Text = string.IsNullOrWhiteSpace(ordermonth) ? GetOrderMonthString() : ordermonth;
                        var currentSession = SessionInfo;

                        if (null != currentSession && !string.IsNullOrWhiteSpace(orderMonthShortString))
                        {
                            currentSession.OrderMonthString      = ordermonth;
                            currentSession.OrderMonthShortString = orderMonthShortString;
                        }
                    }
                    else
                    {
                        lblOrderMonth.Text = GetOrderMonthString();
                    }

                    decimal currentMonthVolume = 0;
                    if (HLConfigManager.Configurations.CheckoutConfiguration.DisplayFormatNeedsDecimal)
                    {
                        lblOrderMonthVolume.Text = decimal.TryParse(ProductsBase.CurrentMonthVolume, NumberStyles.Any, CultureInfo.InstalledUICulture, out currentMonthVolume)
                            ? ProductsBase.GetVolumePointsFormat(currentMonthVolume) :
                                                   (Page as ProductsBase).CurrentMonthVolume;
                    }
                    else
                    {
                        lblOrderMonthVolume.Text = (Page as ProductsBase).CurrentMonthVolume;
                    }

                    Charge_V01 otherCharges =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.OTHER); }) as
                        Charge_V01 ?? new Charge_V01(ChargeTypes.OTHER, (decimal)0.0);
                    Charge_V01 pHCharge =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.PH); }) as Charge_V01 ??
                        new Charge_V01(ChargeTypes.PH, (decimal)0.0);
                    Charge_V01 freightCharge =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.FREIGHT); }) as
                        Charge_V01 ?? new Charge_V01(ChargeTypes.FREIGHT, (decimal)0.0);
                    Charge_V01 localTaxCharge =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.LOCALTAX); }) as
                        Charge_V01 ?? new Charge_V01(ChargeTypes.LOCALTAX, (decimal)0.0);
                    lblOtherCharges.Text = getAmountString(otherCharges.Amount);
                    lblLocalTax.Text     = getAmountString(localTaxCharge.Amount);
                    Charge_V01 logisticCharge =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.LOGISTICS_CHARGE); })
                        as Charge_V01 ?? new Charge_V01(ChargeTypes.LOGISTICS_CHARGE, (decimal)0.0);
                    lblLogisticCharges.Text = getAmountString(logisticCharge.Amount);
                    lblPackageHandling.Text = getAmountString(pHCharge.Amount);
                    lblShippingCharges.Text = getAmountString(freightCharge.Amount);
                    lblRetailPrice.Text     = getAmountString(totals.ItemsTotal);
                    lblTaxVAT.Text          = getAmountString(totals.TaxAmount);
                    if (lblSubtotal != null)
                    {
                        lblSubtotal.Text = getAmountString(logisticCharge.Amount);
                    }
                    if (lblAdditionalDiscount != null)
                    {
                        lblAdditionalDiscount.Text = getAmountString(otherCharges.Amount);
                    }
                    lblVolumePoints.Text = ProductsBase.GetVolumePointsFormat(totals.VolumePoints);

                    //added for HR
                    if (HLConfigManager.Configurations.CheckoutConfiguration.MergePHAndShippingCharges)
                    {
                        decimal phShippingCharges = pHCharge.Amount + freightCharge.Amount;
                        lblPackageHandling.Text = getAmountString(phShippingCharges);
                    }

                    if (HLConfigManager.Configurations.CheckoutConfiguration.DisplayWeight && !SessionInfo.IsEventTicketMode && lblWeight != null)
                    {
                        lblWeight.Text = ShoppingCartProvider.GetWeight(ShoppingCart);
                    }
                }
                else
                {
                    if (HLConfigManager.Configurations.DOConfiguration.DonationWithoutSKU)
                    {
                        if (trDonationAmount != null)
                        {
                            trDonationAmount.Visible = true;
                            OrderTotals_V02 totals_V02 = ShoppingCart.Totals as OrderTotals_V02;
                            if (totals_V02 != null)
                            {
                                lblDonationAmount.Text = getAmountString(totals_V02.Donation);
                            }
                        }
                    }

                    DisplayEmptyLabels();
                }
            }
            catch (Exception ex)
            {
                //Log Exception
                LoggerHelper.Error("Exception while displaying totals - " + ex);
                DisplayEmptyLabels();
            }
        }
        protected override void BindTotals()
        {
            var lstShoppingCartItems = (this.Page as ProductsBase).ShoppingCart.ShoppingCartItems;

            _shoppingCart = (this.Page as ProductsBase).ShoppingCart;
            try
            {
                if (lstShoppingCartItems.Count > 0 && _shoppingCart.Totals != null)
                {
                    OrderTotals_V01 totals = _shoppingCart.Totals as OrderTotals_V01;
                    lblDiscountRate.Text    = HLRulesManager.Manager.PerformDiscountRangeRules(_shoppingCart, Locale, ProductsBase.DistributorDiscount);
                    divDiscountRate.Visible = !string.IsNullOrEmpty(lblDiscountRate.Text);

                    if (ProductsBase.IsEventTicketMode)
                    {
                        var orderMonthShortString = string.Empty;
                        var ordermonth            = OrderMonth.DualOrderMonthForEventTicket(true, out orderMonthShortString); // dual ordermonth should be desable for ETO
                        lblOrderMonth.Text = string.IsNullOrWhiteSpace(ordermonth)?GetOrderMonthString():ordermonth;
                        var currentSession = SessionInfo;

                        if (null != currentSession && !string.IsNullOrWhiteSpace(orderMonthShortString))
                        {
                            currentSession.OrderMonthString      = ordermonth;
                            currentSession.OrderMonthShortString = orderMonthShortString;
                        }
                    }
                    else
                    {
                        lblOrderMonth.Text = GetOrderMonthString();
                    }
                    lblOrderMonthVolume.Text = (this.Page as ProductsBase).CurrentMonthVolume;
                    lblVolumePoints.Text     = totals.VolumePoints.ToString("N2");

                    Charge_V01 pHCharge = GetCharge(totals.ChargeList, ChargeTypes.PH);
                    lblPackageHandling.Text = getAmountString(pHCharge.Amount);
                    lblGrandTotal.Text      = getAmountString(totals.AmountDue);

                    // Brasil exclusive labels.
                    lblDiscountedProductRetail.Text    = getAmountString(totals.ProductRetailAmount);
                    lblDiscountedLiteratureRetail.Text = getAmountString(totals.LiteratureRetailAmount);
                    lblDiscountedPromoteRetail.Text    = getAmountString(totals.PromotionRetailAmount);

                    lblRetailPrice.Text = getAmountString(totals.ItemsTotal);

                    Charge_V01 freightCharge = GetCharge(totals.ChargeList, ChargeTypes.FREIGHT);
                    lblFreightCharges.Text = getAmountString(freightCharge.Amount);
                    lblICMS.Text           = getAmountString(totals.IcmsTax);
                    lblIPI.Text            = getAmountString(totals.IpiTax);
                    //lbSubtotal.Text = getAmountString(freightCharge.Amount + pHCharge.Amount+_shoppingCart.Totals.ProductRetailAmount + _shoppingCart.Totals.LiteratureRetailAmount + _shoppingCart.Totals.PromotionRetailAmount);
                }
                else
                {
                    DisplayEmptyLabels();
                }
            }
            catch (Exception ex)
            {
                //Log Exception
                LoggerHelper.Error("Exception while displaying totals - " + ex.ToString());
                DisplayEmptyLabels();
            }
        }
Exemplo n.º 7
0
        public MyHLShoppingCart LoadOrderAcknowledgement(string orderNumber, string locale, string distributorID)
        {
            var req = new GetPendingOrdersRequest_V03();

            req.CountryCode         = locale;
            req.DistributorId       = distributorID;
            req.IncludeXmlOrderData = true;
            req.OrderNumberList     = new List <string> {
                orderNumber
            };

            var proxy = ServiceClientProvider.GetOrderServiceProxy();

            var rsp = proxy.GetOrders(new GetOrdersRequest1(req)).GetOrdersResult as GetPendingOrdersResponse_V01;

            if (!Helper.Instance.ValidateResponse(rsp))
            {
                Helper.Instance.LogError(rsp.Message, string.Format("{0}.LoadOrderAcknowledgement()", ThisClassName));
                return(null);
            }

            var cart = new MyHLShoppingCart();

            var pendingOdr = rsp.PendingOrders.FirstOrDefault();

            XElement xRoot = XElement.Parse(pendingOdr.XmlOrderData.OuterXml);

            var xBTOrder = GetChild(xRoot, "BTOrder");
            var xOrder   = GetChild(xRoot, "Order");

            #region ShoppingCart

            cart.CountryCode     = GetChildValue(xBTOrder, "countryOfProcessingField");
            cart.DistributorID   = GetChildValue(xBTOrder, "distributorIDField");
            cart.Locale          = GetChildValue(xBTOrder, "localeField");
            cart.OrderMonth      = int.Parse(GetChildValue(xBTOrder, "orderMonthField"));
            cart.OrderSubType    = GetChildValue(xBTOrder, "orderSubTypeField");
            cart.SMSNotification = GetChildValue(xBTOrder, "sMSNumberField");

            cart.EmailAddress = GetChildValue(xRoot, "Email");

            #region DeliveryInfo

            var xShipment = GetChild(xOrder, "Shipment");

            ShippingInfo_V01 shpInfoV01 = new ShippingInfo_V01
            {
                Carrier          = GetChildValue(xShipment, "Carrier"),
                FreightVariant   = GetChildValue(xShipment, "FreightVariant"),
                Phone            = GetChildValue(xShipment, "Phone"),
                Recipient        = GetChildValue(xShipment, "Recipient"),
                ShippingMethodID = GetChildValue(xShipment, "ShippingMethodID"),
                Version          = GetChildValue(xShipment, "Version"),
                WarehouseCode    = GetChildValue(xShipment, "WarehouseCode"),
                DeliveryNickName = GetChildValue(xShipment, "DeliveryNickName"),
            };

            var phone = shpInfoV01.Phone;
            if (!string.IsNullOrWhiteSpace(phone))
            {
                // trim the start and end with -
                if (phone.StartsWith("-") && phone.EndsWith("-") && (phone.Length >= 2))
                {
                    shpInfoV01.Phone = phone.Substring(1, phone.Length - 2);
                }
            }

            var deliveryInfo = new MyHerbalife3.Ordering.Providers.Shipping.ShippingInfo
            {
                //Description
                DeliveryNickName = shpInfoV01.DeliveryNickName,
                FreightCode      = shpInfoV01.ShippingMethodID,
                FreightVariant   = shpInfoV01.FreightVariant, // somehow FreightVariant will be null, due to the prop get implementation
                //Id
                WarehouseCode = shpInfoV01.WarehouseCode,
            };

            deliveryInfo.Option = DeliveryOptionTypes.Convert(shpInfoV01.FreightVariant);

            cart.FreightCode = deliveryInfo.FreightCode;

            #region ShippingAddress_V01

            var shippingAddr = new ServiceProvider.ShippingSvc.ShippingAddress_V01
            {
                Alias = shpInfoV01.DeliveryNickName,
                //AreaCode
                //DisplayName
                Phone     = shpInfoV01.Phone,
                Recipient = shpInfoV01.Recipient,
            };

            #region Address_V01

            var xAddress = GetChild(xShipment, "Address");
            var addr     = new ServiceProvider.ShippingSvc.Address_V01
            {
                City                   = GetChildValue(xAddress, "City"),
                Country                = GetChildValue(xAddress, "Country"),
                CountyDistrict         = GetChildValue(xAddress, "CountyDistrict"),
                Line1                  = GetChildValue(xAddress, "Line1"),
                Line2                  = GetChildValue(xAddress, "Line2"),
                Line3                  = GetChildValue(xAddress, "Line3"),
                Line4                  = GetChildValue(xAddress, "Line4"),
                PostalCode             = GetChildValue(xAddress, "PostalCode"),
                StateProvinceTerritory = GetChildValue(xAddress, "StateProvinceTerritory"),
            };

            shippingAddr.Address = addr;

            #endregion

            deliveryInfo.Address = shippingAddr;

            #endregion

            #region HandlingInfo_V01

            var xHandling = GetChild(xOrder, "Handling");
            HandlingInfo_V01 handlingInfoV01 = new HandlingInfo_V01
            {
                PickupName           = GetChildValue(xHandling, "PickupName"),
                ShippingInstructions = GetChildValue(xHandling, "ShippingInstructions"),
                Version = GetChildValue(xHandling, "Version"),
            };

            deliveryInfo.Instruction = handlingInfoV01.ShippingInstructions;

            #endregion

            cart.DeliveryInfo = deliveryInfo;

            #endregion

            #region ShoppingCartItems, CartItems

            cart.ShoppingCartItems = new List <DistributorShoppingCartItem>();
            cart.CartItems         = new ServiceProvider.CatalogSvc.ShoppingCartItemList();

            var itemList     = new List <DistributorShoppingCartItem>();
            var cartItemList = new List <ServiceProvider.CatalogSvc.ShoppingCartItem_V01>();

            var xOrderItemsField = GetChild(xBTOrder, "orderItemsField");
            var xBTItemList      = GetChildList(xOrderItemsField, "Item");

            var xOrderItems = GetChild(xOrder, "OrderItems");
            var xItemList   = GetChildList(xOrderItems, "Item");

            foreach (var xItem in xItemList)
            {
                var sku = GetChildValue(xItem, "SKU");

                #region Shared.Providers.DistributorShoppingCartItem

                DistributorShoppingCartItem item = new DistributorShoppingCartItem
                {
                    Description  = GetChildValue(xItem, "Description"),
                    IsPromo      = GetChildValue <bool>(xItem, "IsPromo"),
                    RetailPrice  = GetChildValue <decimal>(xItem, "RetailPrice"),
                    Quantity     = GetChildValue <int>(xItem, "Quantity"),
                    SKU          = sku,
                    VolumePoints = GetChildValue <decimal>(xItem, "VolumePoint"),
                };

                var xBTItem = LookupBTOrderItem(xBTItemList, sku);
                if (xBTItem != null)
                {
                    item.DiscountPrice = GetChildValue <decimal>(xBTItem, "discountAmountField");
                    item.EarnBase      = GetChildValue <decimal>(xBTItem, "earnBaseField");
                    item.Flavor        = GetChildValue(xBTItem, "flavorField");
                }

                #endregion

                #region ShoppingCartItem_V01

                var cartItem = new ServiceProvider.CatalogSvc.ShoppingCartItem_V01
                {
                    IsPromo  = GetChildValue <bool>(xItem, "IsPromo"),
                    Quantity = GetChildValue <int>(xItem, "Quantity"),
                    SKU      = sku,
                };

                #endregion

                itemList.Add(item);
                cartItemList.Add(cartItem);
            }

            var itemListSorted     = itemList.OrderBy(x => x.SKU).ToList();
            var cartItemListSorted = cartItemList.OrderBy(x => x.SKU).ToList();

            cart.ShoppingCartItems.AddRange(itemListSorted);
            cart.CartItems.AddRange(cartItemListSorted);

            #endregion

            #region Totals

            var xPricing = GetChild(xOrder, "Pricing");

            #region ChargeList

            var        xChargeList = GetChild(xPricing, "ChargeList");
            ChargeList chargeList  = new ChargeList();

            var xChargeList_List = GetChildList(xChargeList, "Charge");
            foreach (var xCharge in xChargeList_List)
            {
                #region Charge_V01

                if (GetAttributeValue(xCharge, "type") == "Charge_V01")
                {
                    Charge_V01 chargeV01 = new Charge_V01(ChargeTypes.None, 0)
                    {
                        Amount    = GetChildValue <decimal>(xCharge, "Amount"),
                        TaxAmount = GetChildValue <decimal>(xCharge, "TaxAmount"),
                        Type      = GetChildValue(xCharge, "Type"),
                        Version   = GetChildValue(xCharge, "Version"),
                    };

                    chargeList.Add(chargeV01);
                }

                #endregion
            }

            #endregion

            #region ItemTotalsList

            var xItemTotalsList = GetChild(xPricing, "ItemTotalsList");
            var itemTotalsList  = new ServiceProvider.OrderSvc.ItemTotalsList();

            var xItemTotalsList_List = GetChildList(xItemTotalsList, "ItemTotal");
            foreach (var xItemTotal in xItemTotalsList_List)
            {
                #region ItemTotal_V01

                ItemTotal_V01 itemTotalV01 = new ItemTotal_V01
                {
                    AfterDiscountTax = GetChildValue <decimal>(xItemTotal, "AfterDiscountTax"),
                    ChargeList       = new ChargeList(), // just empty list
                    Discount         = GetChildValue <decimal>(xItemTotal, "Discount"),
                    DiscountedPrice  = GetChildValue <decimal>(xItemTotal, "DiscountedPrice"),
                    EarnBase         = GetChildValue <decimal>(xItemTotal, "EarnBase"),
                    LinePrice        = GetChildValue <decimal>(xItemTotal, "LinePrice"),
                    LineTax          = GetChildValue <decimal>(xItemTotal, "LineTax"),
                    //ProductType = GetChildValue(xItemTotal, "ProductType"),
                    Quantity      = GetChildValue <int>(xItemTotal, "Quantity"),
                    RetailPrice   = GetChildValue <decimal>(xItemTotal, "RetailPrice"),
                    SKU           = GetChildValue(xItemTotal, "SKU"),
                    TaxableAmount = GetChildValue <decimal>(xItemTotal, "TaxableAmount"),
                    VolumePoints  = GetChildValue <decimal>(xItemTotal, "VolumePoints"),
                    Version       = GetChildValue(xItemTotal, "Version"),
                };

                itemTotalsList.Add(itemTotalV01);

                var itemMatch = cart.ShoppingCartItems.FirstOrDefault(x => x.SKU == itemTotalV01.SKU);
                if (itemMatch != null)
                {
                    itemMatch.DiscountPrice = itemTotalV01.DiscountedPrice;
                }

                #endregion
            }

            #endregion

            #region OrderFreight

            var xOrderFreight = GetChild(xPricing, "OrderFreight");

            #region Packages

            var            xPackages   = GetChild(xOrderFreight, "Packages");
            List <Package> packageList = new List <Package>();

            var xPackageList = GetChildList(xPackages, "Package");
            foreach (var xPck in xPackageList)
            {
                #region Package

                var pck = new Package
                {
                    Packagetype = GetChildValue(xPck, "Packagetype"),
                    Unit        = GetChildValue <int>(xPck, "Unit"),
                    Volume      = GetChildValue <decimal>(xPck, "Volume"),
                };

                #endregion

                packageList.Add(pck);
            }

            #endregion

            var ordFreight = new OrderFreight
            {
                ActualFreight         = GetChildValue <decimal>(xOrderFreight, "ActualFreight"),
                BeforeDiscountFreight = GetChildValue <decimal>(xOrderFreight, "BeforeDiscountFreight"),
                BeforeWeight          = GetChildValue <decimal>(xOrderFreight, "BeforeWeight"),
                CaseRate       = GetChildValue <decimal>(xOrderFreight, "CaseRate"),
                FreightCharge  = GetChildValue <decimal>(xOrderFreight, "FreightCharge"),
                Insurance      = GetChildValue <decimal>(xOrderFreight, "Insurance"),
                InsuranceRate  = GetChildValue <decimal>(xOrderFreight, "InsuranceRate"),
                MaterialFee    = GetChildValue <decimal>(xOrderFreight, "MaterialFee"),
                Packages       = packageList,
                PackageType    = GetChildValue(xOrderFreight, "PackageType"),
                PackageWeight  = GetChildValue <decimal>(xOrderFreight, "PackageWeight"),
                PhysicalWeight = GetChildValue <decimal>(xOrderFreight, "PhysicalWeight"),
                Unit           = GetChildValue <int>(xOrderFreight, "Unit"),
                VolumeWeight   = GetChildValue <decimal>(xOrderFreight, "VolumeWeight"),
                Weight         = GetChildValue <decimal>(xOrderFreight, "Weight"),
            };

            #endregion

            #region OrderTotals_V02

            if (GetAttributeValue(xPricing, "type") == "OrderTotals_V02")
            {
                var total = new OrderTotals_V02
                {
                    AmountDue            = GetChildValue <decimal>(xPricing, "AmountDue"),
                    BalanceAmount        = GetChildValue <decimal>(xPricing, "BalanceAmount"),
                    ChargeList           = chargeList,
                    DiscountedItemsTotal = GetChildValue <decimal>(xPricing, "DiscountedItemsTotal"),
                    DiscountPercentage   = GetChildValue <decimal>(xPricing, "DiscountPercentage"),
                    DiscountType         = GetChildValue(xPricing, "DiscountType"),
                    Donation             = GetChildValue <decimal>(xPricing, "Donation"),
                    Donation2            = GetChildValue <decimal>(xPricing, "Donation2"),
                    ExciseTax            = GetChildValue <decimal>(xPricing, "ExciseTax"),
                    IcmsTax                 = GetChildValue <decimal>(xPricing, "IcmsTax"),
                    IpiTax                  = GetChildValue <decimal>(xPricing, "IpiTax"),
                    ItemsTotal              = GetChildValue <decimal>(xPricing, "ItemsTotal"),
                    ItemTotalsList          = itemTotalsList,
                    LiteratureRetailAmount  = GetChildValue <decimal>(xPricing, "LiteratureRetailAmount"),
                    MiscAmount              = GetChildValue <decimal>(xPricing, "MiscAmount"),
                    OrderFreight            = ordFreight,
                    PricingServerName       = GetChildValue(xPricing, "PricingServerName"),
                    ProductRetailAmount     = GetChildValue <decimal>(xPricing, "ProductRetailAmount"),
                    ProductTaxTotal         = GetChildValue <decimal>(xPricing, "ProductTaxTotal"),
                    PromotionRetailAmount   = GetChildValue <decimal>(xPricing, "PromotionRetailAmount"),
                    TaxableAmountTotal      = GetChildValue <decimal>(xPricing, "TaxableAmountTotal"),
                    TaxAfterDiscountAmount  = GetChildValue <decimal>(xPricing, "TaxAfterDiscountAmount"),
                    TaxAmount               = GetChildValue <decimal>(xPricing, "TaxAmount"),
                    TaxBeforeDiscountAmount = GetChildValue <decimal>(xPricing, "TaxBeforeDiscountAmount"),
                    TotalEarnBase           = GetChildValue <decimal>(xPricing, "TotalEarnBase"),
                    TotalItemDiscount       = GetChildValue <decimal>(xPricing, "TotalItemDiscount"),
                    Version                 = GetChildValue(xPricing, "Version"),
                    VolumePoints            = GetChildValue <decimal>(xPricing, "VolumePoints"),
                };

                cart.Totals = total;
            }

            #endregion

            #endregion

            #endregion

            var xEmailInfoField = GetChild(xBTOrder, "emailInfoField");

            cart.InvoiceOption = GetChildValue(xEmailInfoField, "invoiceOptionField");

            return(cart);
        }
Exemplo n.º 8
0
        //Name:GenerateXmlRequest
        //Description:Generate the xml file for the BankSlip Request
        //
        private string GenerateXmlRequest(string returnUrl, string key, string password)
        {
            InstallmentConfiguration _installmentsConfiguration;

            #region "create Skeleton"

            MyHLShoppingCart myCart = ShoppingCartProvider.GetShoppingCart(this._distributorId, this._locale);


            // Create Skeleton
            XDocument    xmlToSend    = new XDocument();
            XDeclaration xDeclaration = new XDeclaration("1.0", "utf-8", "no");

            XNamespace aw  = "http://wwww.w3.org/2001/XMLSchema-instance";
            XNamespace aw1 = "http://wwww.w3.org/2001/XMLSchema";
            XNamespace xn  = "http://www2.superpag.com.br/Schemas";
            xmlToSend.Declaration = xDeclaration;

            XElement xmlRoot = new XElement(xn + "RequisicaoPagamento",
                                            new XAttribute(XNamespace.Xmlns + "xsi", aw),
                                            new XAttribute(XNamespace.Xmlns + "xsd", aw1));

            xmlToSend.Add(xmlRoot);

            XElement EstabelecimentoComercial_data = new XElement(xn + "EstabelecimentoComercial",
                                                                  new XAttribute("ChaveAutenticacao", key),
                                                                  new XAttribute("SenhaAutenticacao", password));



            XElement Pagamento_data = new XElement(xn + "OrdemPagamento",
                                                   new XAttribute("Codigo", this.OrderNumber));


            EstabelecimentoComercial_data.Add(Pagamento_data);
            xmlRoot.Add(EstabelecimentoComercial_data);

            XElement Consumidor = new XElement(xn + "Consumidor");
            Pagamento_data.Add(Consumidor);

            XElement DetalhesPessoaisDoConsumidor = new XElement(xn + "DetalhesPessoaisDoConsumidor");
            Consumidor.Add(DetalhesPessoaisDoConsumidor);

            DetalhesPessoaisDoConsumidor.Add(new XElement(xn + "PessoaFisica", new XAttribute("Nome", null != myCart.DeliveryInfo.Address.Recipient ? myCart.DeliveryInfo.Address.Recipient : string.Empty)));

            XElement Emails = new XElement(xn + "Emails");
            Consumidor.Add(Emails);

            Emails.Add(new XElement(xn + "Email", new XAttribute("Endereco", null != myCart.EmailAddress ? myCart.EmailAddress : string.Empty)));

            XElement Telefones = new XElement(xn + "Telefones");
            Consumidor.Add(Telefones);

            Telefones.Add(new XElement(xn + "Telefone", new XAttribute("Tipo", "1"),
                                       new XAttribute("CodigoPais", "55"),
                                       new XAttribute("DDD", null != myCart.DeliveryInfo.Address.AreaCode ? myCart.DeliveryInfo.Address.AreaCode : string.Empty),
                                       new XAttribute("Numero", null != myCart.DeliveryInfo.Address.Phone ? myCart.DeliveryInfo.Address.Phone : string.Empty)));


            XElement EnderecoCobranca = new XElement(xn + "EnderecoCobranca", "");
            Pagamento_data.Add(EnderecoCobranca);

            string address = string.Empty;
            if (myCart.DeliveryInfo.Address.Address.Line1 != null && myCart.DeliveryInfo.Address.Address.Line1.Length > 60)
            {
                address = myCart.DeliveryInfo.Address.Address.Line1.Substring(0, 60);
            }
            else
            {
                address = myCart.DeliveryInfo.Address.Address.Line1;
            }



            EnderecoCobranca.Add(new XElement(xn + "Endereco", new XAttribute("Logradouro", null != myCart.DeliveryInfo.Address.Address.Line1 ? address : string.Empty),
                                              new XAttribute("Numero", ""),
                                              new XAttribute("Cep", null != myCart.DeliveryInfo.Address.Address.PostalCode ? myCart.DeliveryInfo.Address.Address.PostalCode : string.Empty),
                                              new XAttribute("Complemento", ""),
                                              new XAttribute("Bairro", null != myCart.DeliveryInfo.Address.Address.Line2 ? myCart.DeliveryInfo.Address.Address.Line2 : string.Empty),
                                              new XAttribute("Cidade", null != myCart.DeliveryInfo.Address.Address.City ? myCart.DeliveryInfo.Address.Address.City : string.Empty),
                                              new XAttribute("UF", null != myCart.DeliveryInfo.Address.Address.StateProvinceTerritory ? myCart.DeliveryInfo.Address.Address.StateProvinceTerritory : string.Empty),
                                              new XAttribute("Pais", "BRAZIL")));


            XElement EnderecoEntrega = new XElement(xn + "EnderecoEntrega", "");
            Pagamento_data.Add(EnderecoEntrega);


            EnderecoEntrega.Add(new XElement(xn + "Endereco", new XAttribute("Logradouro", null != myCart.DeliveryInfo.Address.Address.Line1 ? address : string.Empty),
                                             new XAttribute("Numero", ""),
                                             new XAttribute("Cep", null != myCart.DeliveryInfo.Address.Address.PostalCode ? myCart.DeliveryInfo.Address.Address.PostalCode : string.Empty),
                                             new XAttribute("Complemento", ""),
                                             new XAttribute("Bairro", null != myCart.DeliveryInfo.Address.Address.Line2 ? myCart.DeliveryInfo.Address.Address.Line2 : string.Empty),
                                             new XAttribute("Cidade", null != myCart.DeliveryInfo.Address.Address.City ? myCart.DeliveryInfo.Address.Address.City : string.Empty),
                                             new XAttribute("UF", null != myCart.DeliveryInfo.Address.Address.StateProvinceTerritory ? myCart.DeliveryInfo.Address.Address.StateProvinceTerritory : string.Empty),
                                             new XAttribute("Pais", "BRAZIL")));

            #region Items

            XElement ItemsDaOrdem = new XElement(xn + "ItensDaOrdem");
            Pagamento_data.Add(ItemsDaOrdem);


            // Fill order items section
            foreach (var item in myCart.ShoppingCartItems)
            {
                ItemsDaOrdem.Add(new XElement(xn + "Item", new XAttribute("Codigo", item.ID),
                                              new XAttribute("Valor", Math.Round((item.DiscountPrice / item.Quantity), 2)),
                                              new XAttribute("Quantidade", item.Quantity),
                                              new XAttribute("Descricao", item.Description)));
            }

            OrderTotals_V01 totals = myCart.Totals as OrderTotals_V01;
            ItemsDaOrdem.Add(new XElement(xn + "Item", new XAttribute("Codigo", "02"),
                                          new XAttribute("Valor", totals.TaxAmount),
                                          new XAttribute("Quantidade", 1),
                                          new XAttribute("Descricao", "Impostos")));
            Charge_V01 pHCharge      = new Charge_V01();
            Charge_V01 freightCharge = new Charge_V01();
            if (null != totals && null != totals.ChargeList)
            {
                pHCharge      = GetCharge(totals.ChargeList, ChargeTypes.PH);
                freightCharge = GetCharge(totals.ChargeList, ChargeTypes.FREIGHT);
            }


            ItemsDaOrdem.Add(new XElement(xn + "Item", new XAttribute("Codigo", "03"),
                                          new XAttribute("Valor", pHCharge.Amount + freightCharge.Amount),
                                          new XAttribute("Quantidade", 1),
                                          new XAttribute("Descricao", "Manuseio")));

            #endregion


            XElement Pagamento = new XElement(xn + "Pagamento", new XAttribute("ValorTotal", totals.AmountDue),
                                              new XAttribute("Data", System.DateTime.Now.Date.ToString("yyyy-MM-dd")),
                                              new XAttribute("Batch", "False"),
                                              new XAttribute("Email", "*****@*****.**"));
            Pagamento_data.Add(Pagamento);

            XElement DetalheDoMeioDePagamento = new XElement(xn + "DetalheDoMeioDePagamento", new XAttribute("MeioPagamento", "ITA"));
            Pagamento.Add(DetalheDoMeioDePagamento);

            DateTime currentDate = DateTime.Now;
            var      orderType   = "RSO";
            if (myCart.OrderCategory == ServiceProvider.CatalogSvc.OrderCategoryType.ETO)
            {
                orderType = "ETO";
            }
            else if (myCart.OrderCategory == ServiceProvider.CatalogSvc.OrderCategoryType.APF)
            {
                orderType = "APF";
            }
            _installmentsConfiguration = InstallmentsProvider.GetInstallmentsConfiguration(myCart.CountryCode, new DateTime(currentDate.Year, currentDate.Month, 1), orderType);

            if (_installmentsConfiguration == null)
            {
                DateTime today = DateTime.Today;
                currentDate = new DateTime(today.Year, today.Month, 1).AddMonths(1).AddDays(-1);
            }


            DetalheDoMeioDePagamento.Add(new XElement(xn + "Boleto", new XAttribute("Banco", "341"),
                                                      new XAttribute("DataVencimento", _installmentsConfiguration.LastPaymentDateTime.ToString("yyyy-MM-dd")),
                                                      new XAttribute("Instrucoes", "")));

            XElement Parcelamento = new XElement(xn + "Parcelamento");
            Pagamento.Add(Parcelamento);

            Parcelamento.Add(new XElement(xn + "Parcelas", new XAttribute("Quantidade", "1"),
                                          new XAttribute("Juros", "00.00"),
                                          new XAttribute("TipoJuros", "Aquirer"),
                                          new XAttribute("FormaParcelamento", "Integral")));

            XElement Setup = new XElement(xn + "Setup", "");
            Pagamento_data.Add(Setup);

            Setup.Add(new XElement(xn + "PostRetorno", new XAttribute("Url", (string.Format("{0}?Agency=Itau", returnUrl)))));

            String xmlReadyToSend;
            xmlReadyToSend = xmlToSend.Declaration.ToString() + xmlToSend.Root.ToString();
            return(xmlReadyToSend);

            #endregion
        }
        private void BindTotals()
        {
            //init etosku
            InitEtoPanel();
            try
            {
                if (ShoppingCart != null)
                {
                    var lstShoppingCartItems = ShoppingCart.ShoppingCartItems;
                    if (lstShoppingCartItems.Count > 0 && ShoppingCart.Totals != null)
                    {
                        MyHLShoppingCart shoppingCart = ProductsBase.ShoppingCart;
                        OrderTotals_V01  totals       = shoppingCart.Totals as OrderTotals_V01;
                        lblDiscountRate.Text =
                            HLConfigManager.Configurations.CheckoutConfiguration.ShowVolumePointRange ?
                            HLRulesManager.Manager.PerformDiscountRangeRules(shoppingCart, Locale, ProductsBase.DistributorDiscount) : (totals.DiscountPercentage).ToString() + "%";
                        trDiscountRate.Visible = !string.IsNullOrEmpty(lblDiscountRate.Text);

                        if (HLConfigManager.Configurations.DOConfiguration.IsChina)
                        {
                            if (ShoppingCart.OrderCategory == OrderCategoryType.ETO && SessionInfo != null && !SessionInfo.IsReplacedPcOrder)
                            {
                                GetEligibleUseETOPoints();
                            }
                            else
                            {
                                GetEligibleUsePoint();
                            }
                            if (shoppingCart != null && shoppingCart.pcLearningPointOffSet > 0)
                            {
                                txtPCLearningPoint.Text = shoppingCart.pcLearningPointOffSet.ToString();
                            }
                            else
                            {
                                txtPCLearningPoint.Text = "0";
                            }
                            // added for China DO
                            if (HLConfigManager.Configurations.CheckoutConfiguration.HasDiscountAmount)
                            {
                                OrderTotals_V02 totals_V02 = ShoppingCart.Totals as OrderTotals_V02;
                                if (totals_V02 != null)
                                {
                                    HLRulesManager.Manager.PerformDiscountRules(ShoppingCart, null, Locale,
                                                                                ShoppingCartRuleReason.CartCalculated);
                                    trDiscountTotal.Visible = totals_V02.DiscountAmount > 0;
                                    lblDiscountTotal.Text   = getAmountString(totals_V02.DiscountAmount);
                                    trDiscountRate.Visible  = false;
                                }
                            }

                            if ((HLConfigManager.Configurations.DOConfiguration.CalculateWithoutItems &&
                                 ShoppingCart.Totals != null &&
                                 (ShoppingCart.Totals as OrderTotals_V01).AmountDue != decimal.Zero) || (ShoppingCart.CartItems.Count > 0 && ShoppingCart.Totals != null))
                            {
                                if (HLConfigManager.Configurations.CheckoutConfiguration.ConvertAmountDue)
                                {
                                    decimal amountDue = OrderProvider.GetConvertedAmount(totals.AmountDue, CountryCode);
                                    if (HLConfigManager.Configurations.PaymentsConfiguration.RoundAmountDue == "Standard")
                                    {
                                        amountDue = Math.Round(amountDue);
                                    }
                                    if (DistributorOrderingProfile.IsPC)
                                    {
                                        if (HttpContext.Current.Request.UrlReferrer != null &&
                                            HttpContext.Current.Request.UrlReferrer.ToString().Contains("Checkout.aspx"))
                                        {
                                            totals.AmountDue   = ShoppingCart.AmountduepriorpcLearningoffset;
                                            lblGrandTotal.Text =
                                                getAmountString(shoppingCart.AmountduepriorpcLearningoffset, true);
                                        }
                                        else
                                        {
                                            lblGrandTotal.Text = getAmountString(amountDue, true);
                                        }
                                    }
                                    else
                                    {
                                        lblGrandTotal.Text = getAmountString(amountDue, true);
                                    }
                                }
                                else
                                {
                                    if (HLConfigManager.Configurations.PaymentsConfiguration.RoundAmountDue == "Standard")
                                    {
                                        totals.AmountDue = Math.Round(totals.AmountDue);
                                    }
                                    if (DistributorOrderingProfile.IsPC)
                                    {
                                        if (HttpContext.Current.Request.UrlReferrer != null &&
                                            HttpContext.Current.Request.UrlReferrer.ToString().Contains("Checkout.aspx"))
                                        {
                                            totals.AmountDue   = ShoppingCart.AmountduepriorpcLearningoffset;
                                            lblGrandTotal.Text =
                                                getAmountString(ShoppingCart.AmountduepriorpcLearningoffset);
                                        }
                                        else
                                        {
                                            lblGrandTotal.Text =
                                                getAmountString(ShoppingCart.Totals != null ? totals.AmountDue : (decimal)0.00);
                                        }
                                    }
                                    else
                                    {
                                        lblGrandTotal.Text =
                                            getAmountString(ShoppingCart.Totals != null ? totals.AmountDue : (decimal)0.00);
                                    }
                                }
                            }
                            if (IsReturnFromCheckout && ShoppingCart.OrderCategory == OrderCategoryType.ETO)
                            {
                                lblGrandTotal.Text = getAmountString(totals != null ? totals.ItemsTotal : 0M);
                                lblDisplayPCLearningPoint.ForeColor = System.Drawing.Color.Green;
                                lblDisplayPCLearningPoint.Font.Bold = true;
                            }
                        }
                        else
                        {
                            if (lblDiscountTotal != null)
                            {
                                lblDiscountTotal.Text =
                                    getAmountString(CheckoutTotalsDetailed.GetDiscountTotal(lstShoppingCartItems));
                            }
                        }

                        lblEarnBase.Text = getAmountString(CheckoutTotalsDetailed.GetTotalEarnBase(lstShoppingCartItems));

                        decimal currentMonthVolume = 0.00M;
                        if (HLConfigManager.Configurations.CheckoutConfiguration.DisplayFormatNeedsDecimal)
                        {
                            lblOrderMonthVolume.Text = decimal.TryParse(ProductsBase.CurrentMonthVolume, NumberStyles.Any, CultureInfo.InstalledUICulture, out currentMonthVolume)
                                ? ProductsBase.GetVolumePointsFormat(currentMonthVolume) :
                                                       (Page as ProductsBase).CurrentMonthVolume;
                        }
                        else
                        {
                            lblOrderMonthVolume.Text = (Page as ProductsBase).CurrentMonthVolume;
                        }

                        lblRetailPrice.Text  = getAmountString(totals.ItemsTotal);
                        lblSubtotal.Text     = getAmountString(totals.DiscountedItemsTotal);
                        lblVolumePoints.Text = ProductsBase.GetVolumePointsFormat(totals.VolumePoints);

                        if (HLConfigManager.Configurations.DOConfiguration.IsChina)
                        {
                            if (totals.ChargeList != null)
                            {
                                Charge_V01 otherCharges =
                                    totals.ChargeList.Find(
                                        delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.OTHER); }) as
                                    Charge_V01 ?? new Charge_V01(ChargeTypes.OTHER, (decimal)0.0);
                                Charge_V01 pHCharge =
                                    totals.ChargeList.Find(
                                        delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.PH); }) as Charge_V01 ??
                                    new Charge_V01(ChargeTypes.PH, (decimal)0.0);
                                Charge_V01 freightCharge =
                                    totals.ChargeList.Find(
                                        delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.FREIGHT); }) as
                                    Charge_V01 ?? new Charge_V01(ChargeTypes.FREIGHT, (decimal)0.0);
                                Charge_V01 localTaxCharge =
                                    totals.ChargeList.Find(
                                        delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.LOCALTAX); }) as
                                    Charge_V01 ?? new Charge_V01(ChargeTypes.LOCALTAX, (decimal)0.0);
                                lblOtherCharges.Text = getAmountString(otherCharges.Amount);
                                lblLocalTax.Text     = getAmountString(localTaxCharge.Amount);
                                Charge_V01 logisticCharge =
                                    totals.ChargeList.Find(
                                        delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.LOGISTICS_CHARGE); })
                                    as Charge_V01 ?? new Charge_V01(ChargeTypes.LOGISTICS_CHARGE, (decimal)0.0);
                                lblLogisticCharges.Text = getAmountString(logisticCharge.Amount);
                                lblPackageHandling.Text = getAmountString(pHCharge.Amount);
                                lblShippingCharges.Text = getAmountString(freightCharge.Amount);

                                //added for HR
                                if (HLConfigManager.Configurations.CheckoutConfiguration.MergePHAndShippingCharges)
                                {
                                    decimal phShippingCharges = pHCharge.Amount + freightCharge.Amount;
                                    lblPackageHandling.Text = getAmountString(phShippingCharges);
                                }
                            }
                            lblTaxVAT.Text = getAmountString(totals.TaxAmount);
                        }
                        else
                        {
                            lblRetailPrice.Text = getAmountString((ShoppingCart.Totals as OrderTotals_V01).ItemsTotal);
                            lblSubtotal.Text    = getAmountString(OrderProvider.GetDistributorSubTotal(ShoppingCart.Totals as OrderTotals_V01));
                        }
                        if (HLConfigManager.Configurations.DOConfiguration.ShowFreightChrageonCOP1)
                        {
                            if (totals.ChargeList != null)
                            {
                                Charge_V01 freightCharge =
                                    totals.ChargeList.Find(
                                        delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.FREIGHT); }) as
                                    Charge_V01 ?? new Charge_V01(ChargeTypes.FREIGHT, (decimal)0.0);
                                lblShippingCharges.Text  = getAmountString(freightCharge.Amount);
                                trShippingCharge.Visible = !string.IsNullOrEmpty(lblShippingCharges.Text) && HLConfigManager.Configurations.DOConfiguration.ShowFreightChrageonCOP1 &&
                                                           shoppingCart.DeliveryInfo != null && shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping;
                            }
                        }
                        if (HLConfigManager.Configurations.CheckoutConfiguration.DisplayWeight && !SessionInfo.IsEventTicketMode && lblWeight != null)
                        {
                            lblWeight.Text = ShoppingCartProvider.GetWeight(ShoppingCart);
                        }
                    }
                    else
                    {
                        if (HLConfigManager.Configurations.DOConfiguration.IsChina)
                        {
                            if ((ShoppingCart.Totals == null || (ShoppingCart.Totals as OrderTotals_V01).AmountDue == 0.0M) &&
                                !(ShoppingCart.OrderCategory == OrderCategoryType.ETO && HLConfigManager.Configurations.DOConfiguration.AllowZeroPricingEventTicket) &&
                                (ShoppingCart.ShoppingCartItems != null && ShoppingCart.ShoppingCartItems.Any()))
                            {
                                OnQuoteError(null, null);
                            }

                            if (trDonationTotal != null)
                            {
                                trDonationTotal.Visible = true;
                                OrderTotals_V02 totals_V02 = ShoppingCart.Totals as OrderTotals_V02;
                                if (totals_V02 != null)
                                {
                                    lblDonationTotal.Text = getAmountString(totals_V02.Donation);
                                }
                            }
                            //trDiscountRate.Visible = false;
                            lblGrandTotal.Text = getAmountString(ShoppingCart.Totals != null ? (ShoppingCart.Totals as OrderTotals_V01).AmountDue : (decimal)0.00);
                        }

                        DisplayEmptyTotals();
                    }
                    if (ShoppingCart.Totals != null && HLConfigManager.Configurations.DOConfiguration.DonationWithoutSKU)
                    {
                        if (trDonationTotal != null)
                        {
                            trDonationTotal.Visible = true;
                            OrderTotals_V02 totals_V02 = ShoppingCart.Totals as OrderTotals_V02;
                            if (totals_V02 != null)
                            {
                                lblDonationTotal.Text = getAmountString(totals_V02.Donation);
                            }
                        }
                    }
                }
                else
                {
                    if (trDonationTotal != null)
                    {
                        trDonationTotal.Visible = true;
                        OrderTotals_V02 totals_V02 = ShoppingCart.Totals as OrderTotals_V02;
                        if (totals_V02 != null)
                        {
                            lblDonationTotal.Text = getAmountString(totals_V02.Donation);
                        }
                    }
                    lblGrandTotal.Text = getAmountString(ShoppingCart.Totals != null ? (ShoppingCart.Totals as OrderTotals_V01).AmountDue : (decimal)0.00);
                    DisplayEmptyTotals();
                }
            }
            catch (Exception ex)
            {
                //Log Exception
                LoggerHelper.Error(string.Format("Exception while displaying totals. Message: {0}, StackTrace: {1}, TargetSite:{2}, DistributorID: {3}", ex.Message, ex.StackTrace, ex.TargetSite, DistributorID));

                if (HLConfigManager.Configurations.DOConfiguration.IsChina)
                {
                    if (trDonationTotal != null)
                    {
                        trDonationTotal.Visible = true;
                        OrderTotals_V02 totals_V02 = ShoppingCart.Totals as OrderTotals_V02;
                        if (totals_V02 != null)
                        {
                            lblDonationTotal.Text = getAmountString(totals_V02.Donation);
                        }
                    }
                }

                DisplayEmptyTotals();
            }
        }
        public void OnProceedingToCheckout(object sender, EventArgs e)
        {
            if (HLConfigManager.Configurations.DOConfiguration.IsChina && DistributorOrderingProfile != null && DistributorOrderingProfile.IsPC || (ShoppingCart.OrderCategory == OrderCategoryType.ETO && SessionInfo != null && !SessionInfo.IsReplacedPcOrder))
            {
                try
                {
                    //if (!DistributorOrderingProfile.IsPC) return;
                    blErrors.Items.Clear();
                    blErrors.DataSource = null;
                    blErrors.DataBind();
                    var errors = blErrors.DataSource as List <string> ?? new List <string>();

                    OrderTotals_V01 totals        = ShoppingCart.Totals as OrderTotals_V01;
                    Charge_V01      freightCharge =
                        totals.ChargeList.Find(
                            delegate(Charge p) { return(((Charge_V01)p).ChargeType == ChargeTypes.FREIGHT); }) as
                        Charge_V01 ?? new Charge_V01(ChargeTypes.FREIGHT, (decimal)0.0);

                    decimal inputLearnPoint;
                    bool    rsl = decimal.TryParse(txtPCLearningPoint.Text, out inputLearnPoint);

                    decimal PCLearningPoint = ShoppingCart.OrderCategory == OrderCategoryType.ETO ? ETOLearningPoint : ShoppingCart.PCLearningPoint;
                    if (ShoppingCart.OrderCategory == OrderCategoryType.ETO)
                    {
                        if (inputLearnPoint != 0 && inputLearnPoint > PCLearningPoint)
                        {
                            errors.Add((string)GetLocalResourceObject("ETOLearningInputExceedAccumulated"));
                        }
                        else if (totals != null && inputLearnPoint != 0 && inputLearnPoint >= totals.AmountDue)
                        {
                            errors.Add((string)GetLocalResourceObject("ETOLearningInputExceedOrdertotal"));
                        }
                    }
                    else
                    {
                        if (inputLearnPoint != 0 && inputLearnPoint > PCLearningPoint)
                        {
                            errors.Add((string)GetLocalResourceObject("PCLearningInputExceedAccumulated.Text"));
                        }
                        //errors.Add("Offset PC Learning point exceeding accumulated learning point");
                        else if (totals != null && inputLearnPoint != 0 && (inputLearnPoint > freightCharge.Amount || inputLearnPoint > totals.AmountDue))
                        {
                            errors.Add((string)GetLocalResourceObject("PCLearningInputExceedFreight.Text"));
                        }
                        //errors.Add("PC Learning point exceeding freightcharge");
                    }

                    if (errors.Count > 0)
                    {
                        blErrors.DataSource = errors;
                        blErrors.DataBind();
                        OnCheckOutOptionsNotPopulated(this, null);
                        hasValidationErrors.Value = "true";
                    }
                    else
                    {
                        //totals.AmountDue -= inputLearnPoint;
                        this.ShoppingCart.pcLearningPointOffSet = inputLearnPoint;
                        hasValidationErrors.Value = "false";
                    }
                }
                catch (Exception ex)
                {
                    HL.Common.Logging.LoggerHelper.Error("CnCheckOutOptions: onProceedingToCheckout error : " + ex);
                }
            }
        }