Shipping Method on Invoice

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
Hostmaster
Commander (CMDR)
Commander (CMDR)
Posts: 126
Joined: Fri Jan 04, 2008 3:30 pm
Location: Melbourne Fl
Contact:

Shipping Method on Invoice

Post by Hostmaster » Fri Apr 11, 2008 10:04 am

Does anyone know a way to get the Shipping method printed on the invoice?

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

Re: Shipping Method on Invoice

Post by compunerdy » Fri Apr 11, 2008 10:55 am

Yes..with the help of BHA on here I got the one page setup I wanted. It has shipping method/pullsheet/prices/etc all on one sheet so I dont need to print multiples. I stripped it down quite a bit because I just use the info to pull/ship the order and then save it as my paper copy. Anyways, Here is the code and you should be able to customize it to how you want it.

Code: Select all

<%-- BH080407 V4.21 ADDED SHIPMESSAGE --%>
<%@ Page Language="C#" MasterPageFile="~/Admin/Admin.master" Title="Invoices" Inherits="CommerceBuilder.Web.UI.AbleCommerceAdminPage" %>
<%@ Register Src="../../UserControls/OrderItemDetail.ascx" TagName="OrderItemDetail" TagPrefix="uc" %>

<script runat="server">
    private List<string> orderNumbers;
    protected int OrderCount = 0;
    
    private List<int> GetSelectedOrders()
    {
        //CHECK FOR QUERYSTRING PARAMETERS
        List<int> selectedOrders = new List<int>();
        string orderIdList = Request.QueryString["orders"];
        if (!string.IsNullOrEmpty(orderIdList))
        {
            string[] numberTokens = orderIdList.Split(",".ToCharArray());
            foreach (string numberToken in numberTokens)
            {
                int temp = AlwaysConvert.ToInt(numberToken);
                if (temp > 0) selectedOrders.Add(temp);
            }
        }
        return selectedOrders;
    }

    private string GetOrderNumbers(List<int> orders)
    {
        if (orderNumbers == null)
        {
            orderNumbers = new List<string>();
            foreach (int orderId in orders)
            {
                orderNumbers.Add(orderId.ToString());
            }
        }
        if (orderNumbers.Count == 0) return string.Empty;
        return string.Join(", ", orderNumbers.ToArray());
    }

    /// <summary>
    /// Gets a collection of orders from a list of order ids.
    /// </summary>
    /// <param name="orderIds">The orderIds to load.</param>
    /// <returns>A collection of orders from the list of ids.</returns>
    protected OrderCollection GetOrders(params int[] orderIds)
    {
        OrderCollection orders = new OrderCollection();
        orderNumbers = new List<string>();
        foreach (int orderId in orderIds)
        {
            Order order = OrderDataSource.Load(orderId);

			if (order != null)
            {
                orderNumbers.Add(order.OrderId.ToString());
                orders.Add(order);
            }
        }
        OrderCount = orders.Count;
        return orders;
    }

//BH080405 Create a new collection for Payments to access payment reference
    protected PaymentCollection GetPayments(int orderId)
    {
		Order order = OrderDataSource.Load(orderId);
        return order.Payments;
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {
        List<int> selectedOrders = GetSelectedOrders();
        if ((selectedOrders == null) || (selectedOrders.Count == 0)) Response.Redirect("~/Admin/Orders/Default.aspx");
        OrderRepeater.DataSource = GetOrders(selectedOrders.ToArray());
        OrderRepeater.DataBind();
        OrderList.Text = GetOrderNumbers(selectedOrders);
    }

    protected OrderItemCollection GetProducts(object dataItem)
    {
        Order order = (Order)dataItem;
        OrderItemCollection products = new OrderItemCollection();
        foreach (OrderItem item in order.Items)
        {
            if (item.OrderItemType == OrderItemType.Product)
            {
                products.Add(item);
            }
        }
        products.Sort("Name");
        return products;
    }

    protected string GetBillToAddress(object dataItem)
    {
        return ((Order)dataItem).FormatAddress(true);
    }

    protected string GetShipToAddress(object dataItem)
    {
        Order order = (Order)dataItem;
        List<string> addressList = new List<string>();
        foreach (OrderShipment shipment in order.Shipments)
        {
            string shipTo = shipment.FormatToAddress();
            if (!addressList.Contains(shipTo)) addressList.Add(shipTo);
        }
        if (addressList.Count == 0) return "n/a";
        return string.Join("<hr />", addressList.ToArray());
    }
	
//BH080406  LOAD SHIPMETHOD NAME TO SHIPMENT
	protected string GetShippingMethod(object dataItem)
    {
        Order order = (Order)dataItem;
        List<string> shipmethodList = new List<string>();
        foreach (OrderShipment shipment in order.Shipments)
        {
            string shipmethod = shipment.ShipMethodName;
			shipmethodList.Add(shipmethod);
        }
        return string.Join("<hr/>", shipmethodList.ToArray());
    }
//////

//BH080406  LOAD SHIPMESSAGE TO SHIPMENT
	protected string GetShipMessage(object dataItem)
    {
        Order order = (Order)dataItem;
        List<string> shipmethodList = new List<string>();
        foreach (OrderShipment shipment in order.Shipments)
        {
            string shipmethod = shipment.ShipMessage;
			shipmethodList.Add(shipmethod);
        }
        return string.Join("<hr/>", shipmethodList.ToArray());
    }
//////


    protected LSDecimal GetTotal(object dataItem, params OrderItemType[] orderItems)
    {
        return ((Order)dataItem).Items.TotalPrice(orderItems);
    }

    protected LSDecimal GetTotalPayments(object dataItem)
    {
        return ((Order)dataItem).Payments.Total(true);
    }
    
    protected LSDecimal GetBalance(object dataItem)
    {
        return GetTotal(dataItem) - GetTotalPayments(dataItem);
    }
    
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
    <div class="pageHeader noPrint">
        <div class="caption">
            <h1><asp:Localize ID="Caption" runat="server" Text="Invoices"></asp:Localize></h1>
        </div>
        <div class="content">
            <h2><asp:Localize ID="OrderListLabel" runat="server" Text="Includes Order Numbers: "></asp:Localize></h2>
            <asp:Label ID="OrderList" runat="server" Text=""></asp:Label><br />
            <p><asp:Localize ID="PrintInstructions" runat="server" Text="This document includes a printable stylesheet.  If you are using a modern browser (such as IE7, FF2, or Opera 7) this page will print with appropriate styles and page breaks if needed.  Website headers, footers, and this message will not be printed."></asp:Localize></p>
        </div>
    </div>
    <div class="noPrint">
        <asp:Button ID="Print" runat="server" Text="Print" OnClientClick="window.print();return false;" />
        <asp:Button ID="Back" runat="server" Text="Back" OnClientClick="window.history.go(-1);return false;" />
    </div>
   
    <asp:Repeater ID="OrderRepeater" runat="server">
      <ItemTemplate>
          <table align="center" class="form<%# (Container.ItemIndex < (OrderCount - 1)) ? " breakAfter" : string.Empty %>" cellpadding="0" cellspacing="0" border="1">
                <tr>
                    <td colspan="4" valign="middle">
                        <div style="float:left">
                            <br />
							
                            <%# GetShipToAddress(Container.DataItem) %>
                        </div>
                        <div style="float:right">
                            <h1 class="invoice">INVOICE <%# Eval("OrderId") %></h1>
                            
                            <asp:Label ID="OrderDateLabel" runat="server" Text="Order Date:" SkinID="FieldHeader"></asp:Label>
                            <asp:Label ID="OrderDate" runat="server" Text='<%# Eval("OrderDate", "{0:g}") %>'></asp:Label><br />

<%-- BH080402 Show Payment Reference by passing "OrderId" --%>
                            <asp:formview 
                            	runat="server"
                                HorizontalAlign="left" 
                                id="paymentref_fv" 
                                DataSource='<%#GetPayments(Convert.ToInt32(Eval("OrderId")))%>' 
                            >
                            	<ItemTemplate>
									<asp:Label ID="PaymentMethodLabel" runat="server" Text="Ref: " SkinID="FieldHeader"></asp:Label>
                                    <asp:Label ID="PaymentMethodName" runat="server" Text='<%#Eval("PaymentMethodName")%>'></asp:Label>
					                <asp:Label ID="ReferenceNumber" runat="server" Text='<%#Eval("ReferenceNumber")%>'></asp:Label> 
								</ItemTemplate>
		                    </asp:formview>
<%-- BH080402 Create GridView for Payment Reference by passing "OrderId" --%>  
                            
                            
                        </div>
                    </td>
                </tr>
               

<%-- BH080406 ADD ROW FOR SHIPPING METHOD AND SHIP MESSAGE --%>                
                
                <tr>
                    <td colspan="4" valign="middle" >
                    <asp:Label ID="GetShipMessageLabel" runat="server" Text="Ship Message: " SkinID="FieldHeader"></asp:Label>
                        <%# GetShipMessage(Container.DataItem) %>
                    </td>
                </tr>
<%-- BH080406 ADD ROW FOR SHIPPING METHOD AND SHIP MESSAGE --%>
                     
                <tr>
                    <td colspan="5" class="dataSheet">
                        <asp:GridView ID="OrderItems" runat="server" ShowHeader="true"
                            AutoGenerateColumns="false" CellPadding=0 CellSpacing=0 GridLines="none" 
                            Width="100%" DataSource='<%#GetProducts(Container.DataItem)%>' CssClass="dataSheet">
                            <Columns>


<asp:TemplateField HeaderText="Pulled" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
                  		  <ItemTemplate>
                     			   [&nbsp;&nbsp;&nbsp;]
                   		 </ItemTemplate>
               		 </asp:TemplateField> 



                                <asp:BoundField DataField="Quantity" HeaderText="Quantity" ItemStyle-HorizontalAlign="Center" />
                                <asp:BoundField DataField="Sku" HeaderText="Sku" ItemStyle-HorizontalAlign="Center" />
                                <asp:TemplateField HeaderText="Item">
                                    <ItemTemplate>
                                        <uc:OrderItemDetail ID="OrderItemDetail1" runat="server" OrderItem='<%#(OrderItem)Container.DataItem%>' ShowAssets="False" LinkProducts="False" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Price">
                                    <ItemStyle HorizontalAlign="right" width="80px" />
                                    <ItemTemplate>
                                        <asp:Label ID="Price" runat="server" Text='<%#Eval("ExtendedPrice", "{0:lc}")%>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                        <table width="100%" cellpadding="0" cellspacing="0" class="dataSheet">
                            <tr>
                                <th align="right">
                                    <asp:Label ID="SubtotalLabel" runat="server" Text="Subtotal:" />
                                </th>
                                <td align="right" width="80px">
                                    <%# string.Format("{0:lc}", GetTotal(Container.DataItem, OrderItemType.Product)) %>
                                </td>
                            </tr>
                            <tr>
                                <th align="right">
				<%# GetShippingMethod(Container.DataItem) %>
                                    <asp:Label ID="ShippingTotalLabel" runat="server" Text="Shipping:" />
                                </th>
                                <td align="right" width="80px">
                                    <%# string.Format("{0:lc}", GetTotal(Container.DataItem, OrderItemType.Shipping, OrderItemType.Handling)) %>
                                </td>
                            </tr>
                            <tr>
                                <th align="right">
                                    <asp:Label ID="TaxTotalLabel" runat="server" Text="Tax:" />
                                </th>
                                <td align="right" width="80px">
                                    <%# string.Format("{0:lc}", GetTotal(Container.DataItem, OrderItemType.Tax)) %>
                                </td>
                            </tr>
                            <tr id="trOther" runat="server" visible='<%# GetTotal(Container.DataItem, OrderItemType.Charge, OrderItemType.Coupon, OrderItemType.Credit, OrderItemType.Discount, OrderItemType.GiftCertificate, OrderItemType.GiftWrap) > 0 %>'>
                                <th align="right">
                                    <asp:Label ID="OtherTotalLabel" runat="server" Text="Other:" />
                                </th>
                                <td align="right" width="80px">
                                    <%# string.Format("{0:lc}", GetTotal(Container.DataItem, OrderItemType.Charge, OrderItemType.Coupon, OrderItemType.Credit, OrderItemType.Discount, OrderItemType.GiftCertificate, OrderItemType.GiftWrap)) %>
                                </td>
                            </tr>
                            <tr class="totalRow">
                                <th align="right">
                                    <asp:Label ID="TotalLabel" runat="server" Text="Total:" />
                                </th>
                                <td align="right" width="80px">
                                    <%# string.Format("{0:lc}", GetTotal(Container.DataItem)) %>
                                </td>
                            </tr>
                            
                            
                            <%--
                            <tr>
                                <th align="right">
                                    <asp:Label ID="PaymentsLabel" runat="server" Text="Payments:" />
                                </th>
                                <td align="right" width="80px">
                                    <%# string.Format("{0:lc}", GetTotalPayments(Container.DataItem)) %>
                                </td>
                            </tr>
                            <tr>
                                <th align="right">
                                    <asp:Label ID="BalanceLabel" runat="server" Text="Balance:" />
                                </th>
                                <td align="right" width="80px">
                                    <%# string.Format("{0:lc}", GetBalance(Container.DataItem)) %>
                                </td>
                            </tr>
                            --%>
                            
                        </table>
                    </td>
                </tr>
            </table>
        </ItemTemplate>
    </asp:Repeater>         

</asp:Content>

User avatar
Hostmaster
Commander (CMDR)
Commander (CMDR)
Posts: 126
Joined: Fri Jan 04, 2008 3:30 pm
Location: Melbourne Fl
Contact:

Re: Shipping Method on Invoice

Post by Hostmaster » Fri Apr 11, 2008 2:13 pm

Thanks, Just what I was looking for

Post Reply