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?
Profit:OrderSummary to OrderItem?
- William_firefold
- Commander (CMDR)
- Posts: 186
- Joined: Fri Aug 01, 2008 8:38 am
Re: Profit:OrderSummary to OrderItem?
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;
- William_firefold
- Commander (CMDR)
- Posts: 186
- Joined: Fri Aug 01, 2008 8:38 am
Re: Profit:OrderSummary to OrderItem?
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.
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:
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
not in there already?
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); ////
}
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;////////