Profit:OrderSummary to OrderItem?

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
William_firefold
Commander (CMDR)
Commander (CMDR)
Posts: 186
Joined: Fri Aug 01, 2008 8:38 am

Profit:OrderSummary to OrderItem?

Post by William_firefold » Wed Feb 11, 2009 2:08 pm

We would like to put a label on the admin/vieworder page that shows the profit generated by a single order.
The only place I have really seen profit is in the sales reports, and the profit field comes from an ordersummary class.
I didnt see anything about profit in the order or orderitem classes.
Should I just calculate profit myself from the orderTotal-costofgoods ?
Is this how it is calculated in the reports and the ordersummary class?

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Profit:OrderSummary to OrderItem?

Post by mazhar » Thu Feb 12, 2009 4:31 am

Yes you have to put either some custom code to get the profit or there could be another way to accomplish this. If you have Product Total, Discount Total, Coupon Total, CostOfGoodTotal amounts then you can create OrderSummary object, provide these values and get the profit by through profit total as below.

Code: Select all

 OrderSummary orderSummary = new OrderSummary();
        orderSummary.ProductTotal = yourProductTotal;
        orderSummary.DiscountTotal =yourDiscountTotal;
        orderSummary.CouponTotal = yourCouponTotal;
        orderSummary.CostOfGoodTotal = yourCostOfGoodTotal;
        return orderSummary.ProfitTotal;

User avatar
William_firefold
Commander (CMDR)
Commander (CMDR)
Posts: 186
Joined: Fri Aug 01, 2008 8:38 am

Re: Profit:OrderSummary to OrderItem?

Post by William_firefold » Thu Feb 12, 2009 1:58 pm

Alright, this code worked, but...It caused a weird problem.
In the end, it would calculate the profit correctly, but would disrupt the product grid at the bottom of the page, with none of the products populating the grid, and the order totals being 0.00.
Here is most of the code ive used to do this. My additions have 4 / slashes.

Code: Select all

    protected void BindOrderItemGrid()
    {
        LSDecimal itemTotal = 0;
        LSDecimal shippingTotal = 0;
        LSDecimal taxTotal = 0;
        LSDecimal otherTotal = 0;
        LSDecimal total = 0;
		LSDecimal discounttotal=0;  ////
		LSDecimal coupontotal=0;  ////
		LSDecimal costtotal=0; ////
		LSDecimal pricetotal=0; ////
        OrderItemCollection itemList = new OrderItemCollection();
        foreach (OrderItem item in _Order.Items)
        {
            switch (item.OrderItemType)
            {
                case OrderItemType.Discount:
					discounttotal += item.ExtendedPrice; ////
					break; ////
                case OrderItemType.GiftCertificate:
                case OrderItemType.Product:
					pricetotal += item.ExtendedPrice; ////
					costtotal += item.CostOfGoods; ////
					break; ////
                case OrderItemType.Coupon:
					coupontotal += item.ExtendedPrice; ////
					break; ////
                case OrderItemType.GiftWrap:
                    itemList.Add(item);
                    itemTotal += item.ExtendedPrice;
                    break;
                case OrderItemType.Shipping:
                case OrderItemType.Handling:
                    shippingTotal += item.ExtendedPrice;
                    break;
                case OrderItemType.Tax:
                    taxTotal += item.ExtendedPrice;
                    break;
                case OrderItemType.Charge:
                case OrderItemType.Credit:
                    otherTotal += item.ExtendedPrice;
                    break;
            }
            total += item.ExtendedPrice;
        }
        itemList.Sort(new OrderItemComparer());
        OrderItemGrid.DataSource = itemList;
        OrderItemGrid.DataBind();
        //BIND TOTALS
        ItemSubtotal.Text = string.Format("{0:lc}", itemTotal);
        ShippingTotal.Text = string.Format("{0:lc}", shippingTotal);
        TaxTotal.Text = string.Format("{0:lc}", taxTotal);
        OtherTotal.Text = string.Format("{0:lc}", otherTotal);
        GrandTotal.Text = string.Format("{0:lc}", total);
		
		OrderSummary orderSummary = new OrderSummary(); ////
        orderSummary.ProductTotal = pricetotal; ////
        orderSummary.DiscountTotal =discounttotal; ////
        orderSummary.CouponTotal = coupontotal; ////

        profittag.Text= string.Format("{0:lc}", orderSummary.ProfitTotal); ////
    }
But when this code is in place, the items are missing from the grid at the bottom of vieworder.aspx.
When I mod a little more and add this:

Code: Select all

case OrderItemType.Product:
					itemList.Add(item);  ////////
					itemTotal += item.ExtendedPrice;////////
					pricetotal += item.ExtendedPrice; ////
					costtotal += item.CostOfGoods; ////
					break; ////


The items DO show up down below, and it seems to fix it, but I do not know if this is proper. If it is correct, why was this

Code: Select all

itemList.Add(item);  ////////
itemTotal += item.ExtendedPrice;////////
not in there already?

Post Reply