/// <summary> /// Gets the displayable items for invoice pages /// </summary> /// <param name="basket">the basket</param> /// <param name="includeShipping">whether or not to include shipping charges in displayed items list</param> /// <param name="alwaysIncludeTaxes">if true forces taxes to be included in the displayed items list even if /// the invoice display is not configured to display them</param> /// <returns>the displayable items for the invoice pages</returns> public static IList <BasketItem> GetDisplayItemsForInvoice(Basket basket, bool includeShipping, bool alwaysIncludeTaxes = false) { // ADD STANDARD DISPLAY ITEMS IList <BasketItem> displayedBasketItems = new List <BasketItem>(); foreach (BasketItem item in basket.Items) { if (DisplayBasketItem(item, includeShipping)) { displayedBasketItems.Add(item); } } // ADD IN TAX ITEMS IF SPECIFIED FOR DISPLAY if (alwaysIncludeTaxes || TaxHelper.GetEffectiveInvoiceDisplay(basket.User) == TaxInvoiceDisplay.LineItem) { // TAXES SHOULD BE SHOWN foreach (BasketItem item in basket.Items.Where(bi => bi.OrderItemType == OrderItemType.Tax)) { displayedBasketItems.Add(item); if (AbleContext.Current.User.IsAnonymous && !AbleContext.Current.User.PrimaryAddress.IsValid) { item.Name = "<span class=\"item\">" + item.Name + " (estimated)</span>"; } } } // SORT ITEMS, THEN COMBINE ORDER COUPON ITEMS FOR DISPLAY displayedBasketItems.Sort(new BasketItemComparer()); displayedBasketItems = displayedBasketItems.CombineOrderCoupons(); return(displayedBasketItems); }
public static IList <BasketItem> GetNonShippingItems(Basket basket) { IList <BasketItem> nonShippingItems = new List <BasketItem>(); foreach (BasketItem item in basket.Items) { if (DisplayItemForShipment(item, 0)) { nonShippingItems.Add(item); } } //SHOW TAXES IF SPECIFIED FOR LINE ITEM DISPLAY if (TaxHelper.GetEffectiveInvoiceDisplay(basket.User) == TaxInvoiceDisplay.LineItem) { // LOOP ALL BASKET ITEMS foreach (BasketItem item in basket.Items) { // ONLY EXAMINE TAX ITEMS if (item.OrderItemType == OrderItemType.Tax) { // DETERMINE THE PARENT ITEM BasketItem parentItem = GetTaxParentItemForShipping(item); // DISPLAY TAX IF PARENT IS DISPLAYED OR IF THIS IS NOT A CHILD ITEM AND IS NOT PART OF ANY SHIPMENT if (nonShippingItems.IndexOf(parentItem.Id) > -1 || (!item.IsChildItem && item.ShipmentId == 0)) { nonShippingItems.Add(item); } } } } nonShippingItems.Sort(new BasketItemComparer()); return(nonShippingItems); }
//USE PRERENDER TO ALLOW FOR CALCULATIONS TO BASKET CONTENTS protected void Page_PreRender(object sender, EventArgs e) { decimal productsTotal = 0; decimal subtotal = 0; decimal shipping = 0; Dictionary <string, decimal> taxes = new Dictionary <string, decimal>(); decimal totalTaxAmount = 0; decimal coupons = 0; decimal discounts = 0; decimal total = 0; decimal giftwrap = 0; int numberOfProducts = 0; decimal giftCodes = 0; Basket basket = AbleContext.Current.User.Basket; foreach (BasketItem item in basket.Items) { decimal extendedPrice = AbleCommerce.Code.InvoiceHelper.GetInvoiceExtendedPrice(item); switch (item.OrderItemType) { case OrderItemType.Product: productsTotal += extendedPrice; subtotal += extendedPrice; bool countItem = !item.IsChildItem; if (!countItem) { BasketItem parentItem = item.GetParentItem(false); if (parentItem != null) { countItem = parentItem.Product.IsKit && parentItem.Product.Kit.ItemizeDisplay; } } if (countItem) { numberOfProducts += item.Quantity; } break; case OrderItemType.Shipping: case OrderItemType.Handling: shipping += extendedPrice; break; case OrderItemType.Tax: if (taxes.ContainsKey(item.Name)) { taxes[item.Name] += extendedPrice; } else { taxes[item.Name] = extendedPrice; } totalTaxAmount += extendedPrice; break; case OrderItemType.Coupon: coupons += extendedPrice; break; case OrderItemType.GiftWrap: giftwrap += extendedPrice; break; case OrderItemType.Discount: discounts += extendedPrice; subtotal += extendedPrice; break; case OrderItemType.GiftCertificatePayment: giftCodes += extendedPrice; break; default: subtotal += extendedPrice; break; } total += extendedPrice; } ProductTotalLabel.Text = string.Format(ProductTotalLabel.Text, numberOfProducts); ProductTotal.Text = productsTotal.LSCurrencyFormat("ulc"); Subtotal.Text = subtotal.LSCurrencyFormat("ulc"); // DISCOUNT ROW VISIBILITY if (discounts != 0) { trDiscounts.Visible = true; Discounts.Text = discounts.LSCurrencyFormat("ulc"); } else { trDiscounts.Visible = false; } if (giftwrap != 0) { trGiftWrap.Visible = true; GiftWrap.Text = giftwrap.LSCurrencyFormat("ulc"); } else { trGiftWrap.Visible = false; } Shipping.Text = shipping.LSCurrencyFormat("ulc"); if (this.ShowTaxes && TaxHelper.GetEffectiveInvoiceDisplay(AbleContext.Current.User) != TaxInvoiceDisplay.Included) { if (ShowTaxBreakdown) { TaxesBreakdownRepeater.DataSource = taxes; TaxesBreakdownRepeater.DataBind(); TaxesBreakdownRepeater.Visible = true; trTax.Visible = false; } else { TaxesLabel.Text = totalTaxAmount.LSCurrencyFormat("ulc"); TaxesBreakdownRepeater.Visible = false; trTax.Visible = true; } } else { // TAXES ARE NOT DISPLAYED, REMOVE ANY TAX FROM THE TOTAL total -= totalTaxAmount; TaxesBreakdownRepeater.Visible = false; trTax.Visible = false; } // SHIPPING SHOULD NOT BE VISIBLE WHEN USER BILLING ADDRESS IS NOT SELECTED if (!basket.User.PrimaryAddress.IsValid) { trShipping.Visible = false; } else { trShipping.Visible = ShowShipping; } if (giftCodes != 0) { trGifCodes.Visible = true; GifCodes.Text = giftCodes.LSCurrencyFormat("ulc"); } else { trGifCodes.Visible = false; } // COUPON ROW VISIBILITY if (coupons != 0) { trCoupon.Visible = true; Coupons.Text = coupons.LSCurrencyFormat("ulc"); } else { trCoupon.Visible = false; } trCouponsDivider.Visible = trCoupon.Visible || trGifCodes.Visible; Total.Text = total.LSCurrencyFormat("ulc"); TotalPendingMessagePanel.Visible = this.ShowMessage; HeaderPanel.Visible = this.ShowHeader; }
//USE PRERENDER TO ALLOW FOR CALCULATIONS TO BASKET CONTENTS protected void Page_PreRender(object sender, EventArgs e) { decimal productsTotal = 0; decimal subtotal = 0; decimal gstTotal = 0; decimal shipping = 0; decimal handling = 0; Dictionary <string, decimal> taxes = new Dictionary <string, decimal>(); decimal totalTaxAmount = 0; decimal coupons = 0; decimal discounts = 0; decimal total = 0; decimal giftwrap = 0; int numberOfProducts = 0; decimal giftCodes = 0; Basket basket = AbleContext.Current.User.Basket; foreach (BasketItem item in basket.Items) { decimal extendedPrice = InvoiceHelper.GetInvoiceExtendedPrice(item); /*TaxHelper.GetInvoiceExtendedPrice(AbleContext.Current.User.Basket, item);*/ switch (item.OrderItemType) { case OrderItemType.Product: bool countItem = !item.IsChildItem; if (!countItem) { BasketItem parentItem = item.GetParentItem(false); if (parentItem != null) { countItem = parentItem.Product.IsKit && parentItem.Product.Kit.ItemizeDisplay; } } if (countItem) { productsTotal += extendedPrice; subtotal += extendedPrice; gstTotal += ((extendedPrice * (decimal)1.1) - extendedPrice); numberOfProducts += item.Quantity; } else { // zero out the ext price - it is included with the parent extendedPrice = 0; } break; case OrderItemType.Shipping: shipping += extendedPrice; break; case OrderItemType.Handling: BasketShipment shipment = item.Shipment; if (shipment != null && shipment.ShipMethod != null && shipment.ShipMethod.SurchargeIsVisible) { handling += extendedPrice; } else { shipping += extendedPrice; } break; case OrderItemType.Tax: if (taxes.ContainsKey(item.Name + ":")) { taxes[item.Name + ":"] += extendedPrice; } else { taxes[item.Name + ":"] = extendedPrice; } totalTaxAmount += extendedPrice; break; case OrderItemType.Coupon: coupons += extendedPrice; break; case OrderItemType.GiftWrap: giftwrap += extendedPrice; break; case OrderItemType.Discount: discounts += extendedPrice; subtotal += extendedPrice; break; case OrderItemType.GiftCertificatePayment: giftCodes += extendedPrice; break; default: subtotal += extendedPrice; break; } total += (extendedPrice * (decimal)1.1); } ProductTotalLabel.Text = string.Format(ProductTotalLabel.Text, numberOfProducts); ProductTotal.Text = productsTotal.LSCurrencyFormat("ulc"); Subtotal.Text = subtotal.LSCurrencyFormat("ulc"); GstTotal.Text = gstTotal.LSCurrencyFormat("ulc"); // DISCOUNT ROW VISIBILITY if (discounts != 0) { trDiscounts.Visible = true; Discounts.Text = discounts.LSCurrencyFormat("ulc"); } else { trDiscounts.Visible = false; } if (giftwrap != 0) { trGiftWrap.Visible = true; GiftWrap.Text = giftwrap.LSCurrencyFormat("ulc"); } else { trGiftWrap.Visible = false; } if (this.ShowTaxes && AbleContext.Current.User.PrimaryAddress.IsValid && TaxHelper.GetEffectiveInvoiceDisplay(AbleContext.Current.User) != TaxInvoiceDisplay.Included) { if (ShowTaxBreakdown) { TaxesBreakdownRepeater.DataSource = taxes; TaxesBreakdownRepeater.DataBind(); TaxesBreakdownRepeater.Visible = true; trTax.Visible = false; } else { TaxesLabel.Text = totalTaxAmount.LSCurrencyFormat("ulc"); TaxesBreakdownRepeater.Visible = false; trTax.Visible = true; } } else { // TAXES ARE NOT DISPLAYED, REMOVE ANY TAX FROM THE TOTAL total -= totalTaxAmount; TaxesBreakdownRepeater.Visible = false; trTax.Visible = false; trTaxCloudTaxExemption.Visible = false; } // SHIPPING SHOULD NOT BE VISIBLE WHEN USER BILLING ADDRESS IS NOT SELECTED Shipping.Text = shipping.LSCurrencyFormat("ulc"); if (!basket.User.PrimaryAddress.IsValid) { trShipping.Visible = false; } else if (shipping > 0) { trShipping.Visible = true; } else { trShipping.Visible = ShowShipping; } if (handling > 0 && trShipping.Visible) { trHandling.Visible = true; Handling.Text = handling.LSCurrencyFormat("ulc"); } else { trHandling.Visible = false; } if (giftCodes != 0) { trGifCodes.Visible = true; GifCodes.Text = giftCodes.LSCurrencyFormat("ulc"); } else { trGifCodes.Visible = false; } // COUPON ROW VISIBILITY if (coupons != 0) { trCoupon.Visible = true; Coupons.Text = coupons.LSCurrencyFormat("ulc"); } else { trCoupon.Visible = false; } trCouponsDivider.Visible = trCoupon.Visible || trGifCodes.Visible; Total.Text = total.LSCurrencyFormat("ulc"); TotalPendingMessagePanel.Visible = this.ShowMessage; TaxCloudProvider taxProvider = ProviderHelper.LoadTaxProvider <TaxCloudProvider>(); if (taxProvider != null && taxProvider.EnableTaxCloud && ShowTaxes && taxes.Count > 0 && taxProvider.UseTaxExemption) { trTaxCloudTaxExemption.Visible = true; } }
private void InitializeBasketContents() { decimal productsTotal = 0; decimal subtotal = 0; decimal shipping = 0; decimal handling = 0; Dictionary <string, decimal> taxes = new Dictionary <string, decimal>(); decimal totalTaxAmount = 0; decimal total = 0; int numberOfProducts = 0; decimal giftCodes = 0; Basket basket = AbleContext.Current.User.Basket; if (!_Recalculated) { IBasketService preCheckoutService = AbleContext.Resolve <IBasketService>(); preCheckoutService.Recalculate(basket); preCheckoutService.Combine(basket); _Recalculated = true; } foreach (BasketItem item in basket.Items) { decimal extendedPrice = AbleCommerce.Code.InvoiceHelper.GetInvoiceExtendedPrice(item); switch (item.OrderItemType) { case OrderItemType.Product: bool countItem = !item.IsChildItem; if (!countItem) { BasketItem parentItem = item.GetParentItem(false); if (parentItem != null) { countItem = parentItem.Product.IsKit && parentItem.Product.Kit.ItemizeDisplay; } } if (countItem) { productsTotal += extendedPrice; subtotal += extendedPrice; numberOfProducts += item.Quantity; } else { // zero out the ext price - it is included with the parent extendedPrice = 0; } break; case OrderItemType.Shipping: shipping += extendedPrice; break; case OrderItemType.Handling: BasketShipment shipment = item.Shipment; if (shipment != null && shipment.ShipMethod != null && shipment.ShipMethod.SurchargeIsVisible) { handling += extendedPrice; } else { shipping += extendedPrice; } break; case OrderItemType.Tax: TaxInvoiceDisplay taxDisplay = TaxHelper.GetEffectiveInvoiceDisplay(AbleContext.Current.User); if (taxDisplay == TaxInvoiceDisplay.Summary) { if (taxes.ContainsKey(item.Name)) { taxes[item.Name] += extendedPrice; } else { taxes[item.Name] = extendedPrice; } } else if (taxDisplay != TaxInvoiceDisplay.Included) { subtotal += extendedPrice; } totalTaxAmount += extendedPrice; break; case OrderItemType.GiftCertificatePayment: giftCodes += extendedPrice; break; default: subtotal += extendedPrice; break; } total += extendedPrice; } Subtotal.Text = subtotal.LSCurrencyFormat("ulc"); TaxInvoiceDisplay taxInvoiceDisplay = TaxHelper.GetEffectiveInvoiceDisplay(AbleContext.Current.User); if (AbleContext.Current.User.PrimaryAddress.IsValid && taxInvoiceDisplay == TaxInvoiceDisplay.Summary) { TaxesBreakdownRepeater.DataSource = taxes; TaxesBreakdownRepeater.DataBind(); if (ShowTaxBreakdown) { TaxesBreakdownRepeater.Visible = true; trTax.Visible = false; } else { TaxesLabel.Text = totalTaxAmount.LSCurrencyFormat("ulc"); TaxesBreakdownRepeater.Visible = false; trTax.Visible = true; } } else { // TAXES ARE NOT DISPLAYED, REMOVE ANY TAX FROM THE TOTAL if (taxInvoiceDisplay == TaxInvoiceDisplay.Included) { total -= totalTaxAmount; } TaxesBreakdownRepeater.Visible = false; trTax.Visible = false; } // SHIPPING SHOULD NOT BE VISIBLE WHEN USER BILLING ADDRESS IS NOT SELECTED Shipping.Text = shipping.LSCurrencyFormat("ulc"); if (!basket.User.PrimaryAddress.IsValid) { trShipping.Visible = false; } else if (shipping > 0) { trShipping.Visible = true; } else { trShipping.Visible = ShowShipping; } if (handling > 0) { trHandling.Visible = trShipping.Visible; Handling.Text = handling.LSCurrencyFormat("ulc"); } else { trHandling.Visible = false; } if (giftCodes != 0) { trGifCodes.Visible = true; GifCodes.Text = giftCodes.LSCurrencyFormat("ulc"); } else { trGifCodes.Visible = false; } trCouponsDivider.Visible = trGifCodes.Visible; Total.Text = total.LSCurrencyFormat("ulc"); TotalPendingMessagePanel.Visible = this.ShowMessage; // ENABLE THE TAXCLOUD Exemption link only if taxcloud is configured and there are tax line items TaxGateway taxGateway = null; TaxCloudProvider taxProvider = null; int taxGatewayId = TaxGatewayDataSource.GetTaxGatewayIdByClassId(Misc.GetClassId(typeof(TaxCloudProvider))); if (taxGatewayId > 0) { taxGateway = TaxGatewayDataSource.Load(taxGatewayId); } if (taxGateway != null) { taxProvider = taxGateway.GetProviderInstance() as TaxCloudProvider; } if (taxProvider == null || !taxProvider.EnableTaxCloud || taxes.Count == 0) { TaxCloudTaxExemptionCert1.Visible = false; } }
protected void Page_PreRender(object sender, EventArgs e) { if (this.Order != null) { // construct the totals table decimal subtotal = 0; decimal gstTotal = 0; decimal shipping = 0; decimal handling = 0; Dictionary <string, decimal> taxes = new Dictionary <string, decimal>(); decimal totalTaxAmount = 0; decimal coupons = 0; decimal total = 0; decimal giftwrap = 0; decimal adjustments = 0; foreach (OrderItem item in this.Order.Items) { decimal extendedPrice = AbleCommerce.Code.InvoiceHelper.GetInvoiceExtendedPrice(item); switch (item.OrderItemType) { case OrderItemType.Product: bool countItem = !item.IsChildItem; if (!countItem) { OrderItem parentItem = item.GetParentItem(false); if (parentItem != null) { countItem = parentItem.ItemizeChildProducts; } } if (countItem) { subtotal += extendedPrice; gstTotal += ((extendedPrice * (decimal)1.1) - extendedPrice); } else { // zero out the ext price - it is included with the parent extendedPrice = 0; } break; case OrderItemType.Shipping: shipping += extendedPrice; break; case OrderItemType.Handling: handling += extendedPrice; break; case OrderItemType.Tax: if (taxes.ContainsKey(item.Name)) { taxes[item.Name] += extendedPrice; } else { taxes[item.Name] = extendedPrice; } totalTaxAmount += extendedPrice; break; case OrderItemType.Coupon: coupons += extendedPrice; break; case OrderItemType.GiftWrap: giftwrap += extendedPrice; break; case OrderItemType.Charge: case OrderItemType.Credit: adjustments += extendedPrice; break; default: subtotal += extendedPrice; break; } total += (extendedPrice * (decimal)1.1); } Subtotal.Text = subtotal.LSCurrencyFormat("ulc"); Gst.Text = gstTotal.LSCurrencyFormat("ulc"); if (giftwrap != 0) { trGiftWrap.Visible = true; GiftWrap.Text = giftwrap.LSCurrencyFormat("ulc"); } else { trGiftWrap.Visible = false; } Shipping.Text = shipping.LSCurrencyFormat("ulc"); if (handling > 0) { trHandling.Visible = true; Handling.Text = handling.LSCurrencyFormat("ulc"); } else { trHandling.Visible = false; } string taxRow = "<tr><th>{0}: </th><td>{1}</td></tr>"; if (TaxHelper.GetEffectiveInvoiceDisplay(AbleContext.Current.User) != TaxInvoiceDisplay.Included) { // TAXES ARE DISPLAYED, ITEMIZE BY TAX NAME foreach (string taxName in taxes.Keys) { phTaxes.Controls.Add(new LiteralControl(string.Format(taxRow, taxName, taxes[taxName].LSCurrencyFormat("ulc")))); } } else { // TAXES ARE NOT DISPLAYED, REMOVE ANY TAX FROM THE TOTAL total -= totalTaxAmount; } if (coupons != 0) { trCoupon.Visible = true; Coupons.Text = coupons.LSCurrencyFormat("ulc"); } else { trCoupon.Visible = false; } if (adjustments != 0) { trAdjustments.Visible = true; Adjustments.Text = adjustments.LSCurrencyFormat("ulc"); } else { trAdjustments.Visible = false; } Total.Text = total.LSCurrencyFormat("ulc"); } else { OrderTotalSummaryPanel.Visible = false; } }
protected void Page_PreRender(object sender, EventArgs e) { if (this.Order != null) { // construct the totals table decimal subtotal = 0; decimal shipping = 0; Dictionary <string, decimal> taxes = new Dictionary <string, decimal>(); decimal totalTaxAmount = 0; decimal coupons = 0; decimal total = 0; decimal giftwrap = 0; decimal adjustments = 0; foreach (OrderItem item in this.Order.Items) { decimal extendedPrice = AbleCommerce.Code.InvoiceHelper.GetInvoiceExtendedPrice(item); switch (item.OrderItemType) { case OrderItemType.Shipping: case OrderItemType.Handling: shipping += extendedPrice; break; case OrderItemType.Tax: if (taxes.ContainsKey(item.Name)) { taxes[item.Name] += extendedPrice; } else { taxes[item.Name] = extendedPrice; } totalTaxAmount += extendedPrice; break; case OrderItemType.Coupon: coupons += extendedPrice; break; case OrderItemType.GiftWrap: giftwrap += extendedPrice; break; case OrderItemType.Charge: case OrderItemType.Credit: adjustments += extendedPrice; break; default: subtotal += extendedPrice; break; } total += extendedPrice; } Subtotal.Text = subtotal.LSCurrencyFormat("ulc"); if (giftwrap != 0) { trGiftWrap.Visible = true; GiftWrap.Text = giftwrap.LSCurrencyFormat("ulc"); } else { trGiftWrap.Visible = false; } Shipping.Text = shipping.LSCurrencyFormat("ulc"); string taxRow = "<div class='inlineField'><span class='fieldHeader'>{0}: </span><span class='fieldValue price'>{1}</span></div>"; if (TaxHelper.GetEffectiveInvoiceDisplay(AbleContext.Current.User) != TaxInvoiceDisplay.Included) { // TAXES ARE DISPLAYED, ITEMIZE BY TAX NAME foreach (string taxName in taxes.Keys) { phTaxes.Controls.Add(new LiteralControl(string.Format(taxRow, taxName, taxes[taxName].LSCurrencyFormat("ulc")))); } } else { // TAXES ARE NOT DISPLAYED, REMOVE ANY TAX FROM THE TOTAL total -= totalTaxAmount; } if (coupons != 0) { trCoupon.Visible = true; Coupons.Text = coupons.LSCurrencyFormat("ulc"); } else { trCoupon.Visible = false; } if (adjustments != 0) { trAdjustments.Visible = true; Adjustments.Text = adjustments.LSCurrencyFormat("ulc"); } else { trAdjustments.Visible = false; } Total.Text = total.LSCurrencyFormat("ulc"); } else { OrderTotalSummaryPanel.Visible = false; } }