Group coupon in the print invoice

Post feature requests to this forum and a pre-configured poll will automatically be created for you.
Post Reply
hilohattie
Ensign (ENS)
Ensign (ENS)
Posts: 6
Joined: Wed May 16, 2012 9:18 pm

Group coupon in the print invoice

Post by hilohattie » Tue Jun 05, 2012 7:03 pm

Is there a way to group coupon instead have the coupon per item? I found one patch for the checkout page where group coupon viewtopic.php?f=42&t=15239 is there a path for print invoice?

hilohattie
Ensign (ENS)
Ensign (ENS)
Posts: 6
Joined: Wed May 16, 2012 9:18 pm

Re: Group coupon in the print invoice

Post by hilohattie » Tue Jun 05, 2012 8:54 pm

Any one please help

crazyjoe
Commander (CMDR)
Commander (CMDR)
Posts: 172
Joined: Mon Apr 26, 2010 2:20 pm

Re: Group coupon in the print invoice

Post by crazyjoe » Tue Nov 06, 2012 1:20 pm

I just did this. If this helps anyone else out. Around line 99 in the invoice.aspx.cs file (found in ~admin/orders/print)

Look for this...

Code: Select all

    private OrderItemType[] displayItemTypes = { OrderItemType.Product, OrderItemType.Discount, 
        OrderItemType.Coupon, OrderItemType.Shipping, OrderItemType.Handling, OrderItemType.GiftWrap,
        OrderItemType.Charge, OrderItemType.Credit, OrderItemType.GiftCertificate, OrderItemType.Tax};
    protected OrderItemCollection GetItems(object dataItem)
change it to this...

Code: Select all

private OrderItemType[] displayItemTypes = { OrderItemType.Product, OrderItemType.Discount, 
        OrderItemType.Shipping, OrderItemType.Handling, OrderItemType.GiftWrap,
        OrderItemType.Charge, OrderItemType.Credit, OrderItemType.GiftCertificate, OrderItemType.Tax};
    protected OrderItemCollection GetItems(object dataItem)
This removes it from the showing up below each item. It will still shown at the bottom subtotal table.
Crazy Joe Sadloski
Webmaster
Hot Leathers Inc.
http://www.hotleathers.com

hilohattie
Ensign (ENS)
Ensign (ENS)
Posts: 6
Joined: Wed May 16, 2012 9:18 pm

Re: Group coupon in the print invoice

Post by hilohattie » Fri Dec 14, 2012 5:35 pm

Thank you crazyjoe but I was able to group all coupon in the invoice and not removing it in the order items.

Code: Select all

 private OrderItemType[] displayItemTypes = { OrderItemType.Product, OrderItemType.Discount, 
        OrderItemType.Coupon, OrderItemType.Shipping, OrderItemType.Handling, OrderItemType.GiftWrap,
        OrderItemType.Charge, OrderItemType.Credit, OrderItemType.GiftCertificate, OrderItemType.Tax};
	Dictionary<string, decimal> ctr = new Dictionary<string, decimal>();
	Dictionary<string, decimal> i = new Dictionary<string, decimal>();
    protected OrderItemCollection GetItems(object dataItem)
    {
		
        Order order = (Order)dataItem;
        OrderItemCollection items = new OrderItemCollection();
		//REMOVE VAT ENTRIES
            Dictionary<string, decimal> couponTotals = new Dictionary<string, decimal>();
			Dictionary<string, decimal> couponCounter = new Dictionary<string, decimal>();
		foreach (OrderItem item in order.Items)
        {
			if (item.OrderItemType == OrderItemType.Coupon)
			{
				if (couponCounter.ContainsKey(item.Name))
				{
				ctr[item.Name]++;
				couponCounter[item.Name] =  ctr[item.Name];
				}
				else
				{
					ctr[item.Name] = 0;
					couponCounter[item.Name] = ctr[item.Name];
				}
			}
			
		}
		
			
        foreach (OrderItem item in order.Items)
        {
			
            if (Array.IndexOf(displayItemTypes, item.OrderItemType) >= 0 && (item.OrderItemType != OrderItemType.Tax))
            {
                if (item.OrderItemType == OrderItemType.Product && item.IsChildItem)
                {
                    // WHETHER THE CHILD ITEM DISPLAYS DEPENDS ON THE ROOT
                    OrderItem rootItem = item.GetParentItem(true);
                    if (rootItem.Product != null && rootItem.ItemizeChildProducts)
                    {
                        // ITEMIZED DISPLAY ENABLED, SHOW THIS CHILD ITEM
                        items.Add(item);
                    }
                }
				 else if (item.OrderItemType == OrderItemType.Coupon)
                {
                    if (couponTotals.ContainsKey(item.Name)) couponTotals[item.Name] += (decimal)item.ExtendedPrice;
                    else couponTotals[item.Name] = (decimal)item.ExtendedPrice;
					if (!i.ContainsKey(item.Name))
					i[item.Name] = 0;
					if(i[item.Name] > couponCounter[item.Name])
					i[item.Name] = 0;
					if(couponCounter[item.Name] == i[item.Name])
					{
					item.Price = couponTotals[item.Name];
					items.Add(item);
					}
					else
					{
					item.Price = item.Price - item.Price;
					i[item.Name] = i[item.Name] + 1;
					}
                }
                else  items.Add(item);
            }
        }
        //ADD IN TAX ITEMS IF SPECIFIED FOR DISPLAY
        TaxInvoiceDisplay displayMode = TaxHelper.InvoiceDisplay;
        if (displayMode == TaxInvoiceDisplay.LineItem || displayMode == TaxInvoiceDisplay.LineItemRegistered)
        {
            foreach (OrderItem item in order.Items)
            {
                //IS THIS A TAX ITEM?
                if (item.OrderItemType == OrderItemType.Tax)
                {
                    //IS THE TAX ITEM A PARENT ITEM OR A CHILD OF A DISPLAYED ITEM?
                    if (!item.IsChildItem || (items.IndexOf(item.ParentItemId) > -1))
                    {
                        //TAX SHOULD BE SHOWN
                        items.Add(item);
                    }
                }
            }
        }
        //SORT ITEMS TO COMPLETE INTITIALIZATION
        items.Sort(new OrderItemComparer());
        return items;
    }
Hope this will help anyone

Post Reply