Page 1 of 1
Print Customer Notes on Pullsheet
Posted: Fri Jan 15, 2016 1:53 pm
by vsammons
Has anyone put customer notes on the pull sheets?
Where would I find the references for it. 'OrderNoteCollection' or share code?
Re: Print Customer Notes on Pullsheet
Posted: Fri Jan 15, 2016 2:30 pm
by vsammons
I am using this code:
Code: Select all
<asp:GridView ID="OrderNotes" runat="server" ShowHeader="true"
AutoGenerateColumns="false" CellPadding="0" CellSpacing="0" GridLines="none"
Width="100%" DataSource='<%#((Order)Container.DataItem).Notes.FindAll(on => on.NoteType == NoteType.Public)%>'
SkinID="PrintableList" >
<Columns>
<asp:BoundField DataField="Comment" HeaderText="Notes" ItemStyle-HorizontalAlign="Left" />
</Columns>
</asp:GridView>
But getting this error "System.InvalidCastException: Unable to cast object of type 'CommerceBuilder.Orders.OrderShipment' to type 'CommerceBuilder.Orders.Order'." I am not trying to use the Shipping notes but rather the Customer notes.
Re: Print Customer Notes on Pullsheet
Posted: Fri Jan 15, 2016 5:32 pm
by compunerdy
Have a look here.. its what I had in my notes as the source for what I used.
viewtopic.php?f=65&t=18182&hilit=customer+comment
Re: Print Customer Notes on Pullsheet
Posted: Sat Jan 16, 2016 3:01 am
by vsammons
I am looking to put customer notes not Shipping notes. They are separate objects.
I was able to find OrderNote GetOrderNotes but issue with building the array
Code: Select all
protected OrderNote GetOrderNotes(params int[] orders)
{
OrderNote orderNotes = new OrderNote();
foreach (int orderId in orders)
{
Order order = OrderDataSource.Load(orderId);
if (order != null)
{
if (order.Notes != null && order.Notes.Count > 0)
{
foreach (OrderNote on in order.Notes)
if (!on.IsPrivate)
orderNotes.add(on);
}
}
}
return orderNotes;
}
protected OrderNote GetOrderNotesByOrder(object dataItem)
{
Order order = (Order)dataItem;
OrderNote orderNotes = new OrderNote();
foreach (OrderNote note in order.Notes)
{
if (!note.IsPrivate)
{
orderNotes.add(note);
}
}
return orderNotes;
}
Re: Print Customer Notes on Pullsheet
Posted: Sat Jan 16, 2016 1:17 pm
by compunerdy
Re: Print Customer Notes on Pullsheet
Posted: Mon Jan 18, 2016 9:31 am
by vsammons
I get this error message when using that code: Unable to cast object of type 'CommerceBuilder.Orders.OrderShipment' to type 'CommerceBuilder.Orders.Order'.
Re: Print Customer Notes on Pullsheet
Posted: Tue Jan 19, 2016 5:25 am
by jguengerich
The PullSheet page is designed to handle items from more than one order, so the GridView's data source is simply a list of order items. Do you want to only show the notes if there is only one order included on the pull sheet, or show the notes from each order that is included? If you want to show notes from more than one order, do you want the items and notes from each order grouped together?
Re: Print Customer Notes on Pullsheet
Posted: Tue Jan 19, 2016 7:44 am
by vsammons
Goal is to query all of the notes from that order and include the grid in the repeater for each order in the repeater.
Re: Print Customer Notes on Pullsheet
Posted: Tue Jan 19, 2016 7:48 am
by jguengerich
So you are saying you want it grouped like this?
Order 1 Item 1
Order 1 Item 2
Order 1 Item 3
Order 1 Notes
Order 2 Item 1
Order 2 Item 2
Order 2 Notes
Re: Print Customer Notes on Pullsheet
Posted: Tue Jan 19, 2016 10:37 am
by vsammons
Jay - I think you are on the same page as I, I just added if there was more than one note on the order. The people filling the order needs to understand other details from the customer regarding the order.
Order1
OrderItem1
OrderItem2
Order1Note1
Order1Note2
Order2
OrderItem1
OrderItem2
Orderitem3
Order2note1
.......
Re: Print Customer Notes on Pullsheet
Posted: Tue Jan 19, 2016 12:11 pm
by jguengerich
Yeah, I just wanted to make sure I understood your requirements before I tried to offer help. I don't use the Pullsheet, so when i first looked at the code I was assuming it would be for one order, but then I realized it can have multiple orders. Do you already have modifications (aspx and/or aspx.cs) that split up the order items by order instead of just putting them all in one list? If so, could you post it?
Re: Print Customer Notes on Pullsheet
Posted: Tue Jan 19, 2016 12:39 pm
by vsammons
I believe the default code has a repeater control that does this.
I have some version 7.6 code that used to work for us. I do not have handy at the moment but will post .
Re: Print Customer Notes on Pullsheet
Posted: Tue Jan 19, 2016 12:59 pm
by jguengerich
The default code at Admin/Orders/Print/PullSheet.aspx & [same].cs does not appear to have a repeater that splits it up. It has a GridView, and the data source just loads all the items from all the orders that are selected.
Re: Print Customer Notes on Pullsheet
Posted: Wed Jan 20, 2016 7:21 am
by vsammons
I was able to do it finally this way:
Pullsheet.aspx
Code: Select all
<%@ Page Language="C#" MasterPageFile="~/Admin/Admin.master" Inherits="AbleCommerce.Admin.Orders.Print.PullSheet" Title="Pull Sheet" CodeFile="PullSheet.aspx.cs" %>
<%@ Register Src="OrderItemDetail.ascx" TagName="OrderItemDetail" TagPrefix="uc" %>
<%@ Register Src="~/Admin/UserControls/PrintableLogo.ascx" TagName="PrintableLogo" TagPrefix="uc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
<div class="pageHeader noPrint">
<div class="caption">
<h1>
<asp:Localize ID="Caption" runat="server" Text="Pull Sheet"></asp:Localize></h1>
<div class="links">
<asp:Button ID="Print" runat="server" Text="Print" OnClientClick="window.print();" OnClick="Print_Click" />
<asp:HyperLink ID="Back" runat="server" Text="Back" SkinID="CancelButton" NavigateUrl="~/Admin/Orders/Default.aspx" />
</div>
</div>
</div>
<div class="content noPrint">
<p>
<asp:Label ID="OrderListLabel" runat="server" Text="Order Number(s): " SkinID="FieldHeader"></asp:Label><asp:Label ID="OrderList" runat="server" Text=""></asp:Label></p>
<p>
<asp:Localize ID="PrintInstructions" runat="server" Text="This page contains a printable stylesheet. Your browser will print with appropriate styles and page breaks if needed. Website headers and footers (along with this message) will not be printed."></asp:Localize></p>
</div>
<div class="content">
<asp:Repeater ID="ShipmentRepeater" runat="server">
<ItemTemplate>
<div class="PullSheet<%# Container.ItemIndex > 0 ? " breakBefore" : string.Empty %>">
<div class="logo">
<uc:PrintableLogo ID="Logo" runat="server" />
</div>
<%--<div class="orderSummary">
</div>--%>
<table border="1">
<%--class="shippingAddresses"--%>
<tr>
<td style="border-right-color: transparent;"></td>
<td style="border-right-color: transparent; padding-left: 15px;">
<div style="float: left; margin-top: -50px;">
<br />
INTERNAL USE ONLY
</div>
</td>
<td style="border-right-color: transparent;"></td>
<td style="border-left-color: transparent; padding-left: 85px;">
<h1>
<asp:Label ID="PrintCaption" runat="server" Text="Pull Sheet"></asp:Label></h1>
<asp:PlaceHolder ID="trShipMessage" runat="server" Visible='<%# ((string)Eval("ShipMessage")).Length > 0 %>'>
<div class="row shipMessage">
<asp:Label ID="ShipMessageLabel" runat="server" Text="Customer Comment:" SkinID="FieldHeader"></asp:Label>
<%#Eval("ShipMessage")%>
</div>
</asp:PlaceHolder>
<div class="row">
<asp:Label ID="OrderNumberLabel" runat="server" Text="Order Number:" SkinID="FieldHeader"></asp:Label>
<%# Eval("Order.OrderNumber") %>
</div>
<div class="row">
<asp:Label ID="OrderDateLabel" runat="server" Text="Order Date:" SkinID="FieldHeader"></asp:Label>
<%#Eval("Order.OrderDate", "{0:g}") %>
</div>
</td>
</tr>
<tr>
<td style="width: 10px; text-align: center; font-weight: bold; padding: 10px;" valign="top">S O L D T O
</td>
<td valign="middle" width="50%" style="padding-left: 5px;">
<%# GetShipToAddress(Container.DataItem) %>
</td>
<td style="width: 10px; text-align: center; font-weight: bold; padding: 10px;" valign="top">S H I P T O
</td>
<td valign="middle" width="50%" style="padding-left: 5px;">
<%# GetShipToAddress(Container.DataItem) %>
</td>
</tr>
<%--<tr>
<th class="shipFrom">
<asp:Label ID="SoldToCaption" runat="server" Text="Sold To:"></asp:Label>
</th>
<th class="shipTo">
<asp:Label ID="ShipToCaption" runat="server" Text="Ship To:"></asp:Label>
</th>
</tr>
<tr>
<td class="soldTo">
<%--<asp:Label ID="ShipFrom" runat="server" Text='<%# GetShipFromAddress(Container.DataItem) %>'></asp:Label>--%>
<%--<%#AbleContext.Current.Store.Name %></span>
<br />
<%# AbleContext.Current.Store.DefaultWarehouse.FormatAddress(true) %>
<asp:Label ID="SoldTo" runat="server" Text='<%# GetShipToAddress(Container.DataItem) %>'></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text="Email: "></asp:Label><%# Eval ("ShipToEmail") %>
<br />
<asp:Label ID="Label1" runat="server" Text="Phone: "></asp:Label><%# Eval ("ShipToPhone") %>
</td>
<td class="shipTo">
<asp:Label ID="ShipTo" runat="server" Text='<%# GetShipToAddress(Container.DataItem) %>'></asp:Label>
</td>
</tr>--%>
</table>
<asp:GridView ID="ShipmentItems" runat="server" ShowHeader="true"
AutoGenerateColumns="false" CellSpacing="0" GridLines="none"
Width="100%" SkinID="PrintableList" DataSource='<%#GetProducts(Container.DataItem)%>'>
<Columns>
<asp:BoundField DataField="Quantity" HeaderText="Quantity" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="80" />
<asp:BoundField DataField="Sku" HeaderText="SKU" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="140" />
<asp:TemplateField HeaderText="Item">
<ItemTemplate>
<uc:OrderItemDetail ID="OrderItemDetail1" runat="server" OrderItem='<%#(OrderItem)Container.DataItem%>' ShowAssets="False" LinkProducts="False" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Price" HeaderText="Price" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="80" DataFormatString="{0:C}" />
<asp:BoundField HeaderText="Total" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="80" />
<asp:BoundField HeaderText="Pulled" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="60" />
</Columns>
</asp:GridView>
<table width="600px" cellpadding="0" cellspacing="0" class="dataSheet">
<tr>
<th align="right" style="padding-right: 5px;">
<asp:Label ID="SubtotalLabel" runat="server" Text="Product Subtotal:" />
</th>
<td align="right" width="80px" style="padding-right: 5px;">
<%# GetProductTotal(Container.DataItem).LSCurrencyFormat("lc") %>
</td>
</tr>
<tr>
<th align="right" style="padding-right: 5px;">
<asp:Label ID="ShippingTotalLabel" runat="server" Text="Shipping & Handling:" />
</th>
<td align="right" width="80px" style="padding-right: 5px;">
<%# GetShippingTotal(Container.DataItem).LSCurrencyFormat("lc") %>
</td>
</tr>
<tr>
<th align="right" style="padding-right: 5px;">
<asp:Label ID="TaxTotalLabel" runat="server" Text="Taxes:" />
</th>
<td align="right" width="80px" style="padding-right: 5px;">
<%# GetTotal(Container.DataItem, OrderItemType.Tax).LSCurrencyFormat("lc") %>
</td>
</tr>
<tr id="trAdjustments" runat="server" visible='<%# ShowAdjustmentsRow(Container.DataItem) %>'>
<th align="right" style="padding-right: 5px;">
<asp:Label ID="AdjustmetnsLabel" runat="server" Text="Adjustments:" />
</th>
<td align="right" width="80px" style="padding-right: 5px;">
<%# GetAdjustmentsTotal(Container.DataItem).LSCurrencyFormat("lc")%>
</td>
</tr>
<tr class="totalRow">
<th align="right" style="padding-right: 5px;">
<asp:Label ID="TotalLabel" runat="server" Text="Total:" />
</th>
<td align="right" width="80px" style="padding-right: 5px;">
<%# GetTotal(Container.DataItem).LSCurrencyFormat("lc") %>
</td>
</tr>
</table>
<table width="600px" cellpadding="0" cellspacing="0" class="dataSheet">
<tr>
<td colspan="4" class="dataSheet">
<%-- <asp:GridView ID="OrderNotesRepeater" runat="server" ShowHeader="true" AutoGenerateColumns="false" Width="100%"
CellPadding="0" CellSpacing="0" GridLines="none" CssClass="dataSheet">--%>
<asp:GridView ID="OrderNotesRepeater" runat="server" ShowHeader="true" AutoGenerateColumns="false"
CellPadding="0" CellSpacing="0" GridLines="none" Width="100%" DataSource='<%#GetOrderNotesByOrder(Container.DataItem)%>'>
<Columns>
<asp:TemplateField HeaderText="Customer notes">
<ItemTemplate>
***
<%#Eval("Comment") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
<script type="text/javascript">
$(".printableList > tbody > tr").each(function (i, v) {
var td = $(this).children();
if (i > 0) {
var quantity = td.first();
if (quantity.html() > 1) {
$(this).css({ "color": "red", "font-weight": "bold" });
} else {
$(this).css({ "color": "black", "font-weight": "normal" });
}
td.last().html("<p>[ ]</p>");
var total = quantity.html() * td.eq(3).html().replace("$", "");
total = total.toFixed(2);
td.eq(4).html("$" + total);
} else {
td.eq(4).html("Total");
}
});
</script>
</asp:Content>
Pullsheet.aspc.cs
Code: Select all
namespace AbleCommerce.Admin.Orders.Print
{
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using CommerceBuilder.Common;
using CommerceBuilder.Orders;
using CommerceBuilder.Utility;
using CommerceBuilder.Eventing;
public partial class PullSheet : CommerceBuilder.UI.AbleCommerceAdminPage
{
private IList<string> orderNumbers;
protected int ShipmentCount = 0;
private string GetOrderNumbers(IList<int> orders)
{
if (orderNumbers == null)
{
orderNumbers = new List<string>();
foreach (int orderId in orders)
{
int orderNumber = OrderDataSource.LookupOrderNumber(orderId);
orderNumbers.Add(orderNumber.ToString());
}
}
if (orderNumbers.Count == 0) return string.Empty;
return string.Join(", ", orderNumbers.ToArray());
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.UrlReferrer != null)
{
Back.NavigateUrl = Request.UrlReferrer.ToString();
}
}
IList<int> selectedOrders = GetSelectedOrders();
if ((selectedOrders == null) || (selectedOrders.Count == 0)) Response.Redirect("~/Admin/Orders/Default.aspx");
ShipmentRepeater.DataSource = GetShipments(selectedOrders.ToArray());
ShipmentRepeater.DataBind();
//ItemGrid.DataSource = OrderPullItemDataSource.GeneratePullSheet(selectedOrders.ToArray());
//ItemGrid.DataBind();
OrderList.Text = GetOrderNumbers(selectedOrders);
}
protected IList<OrderShipment> GetShipments(params int[] orders)
{
bool includeShipped = AlwaysConvert.ToInt(Request.QueryString["is"]) == 1;
int shipmentNumber = AlwaysConvert.ToInt(Request.QueryString["ShipmentNumber"]);
IList<OrderShipment> shipments = new List<OrderShipment>();
foreach (int orderId in orders)
{
Order order = OrderDataSource.Load(orderId);
if (order != null)
{
foreach (OrderShipment shipment in order.Shipments)
{
if ((shipmentNumber == 0 || shipmentNumber == shipment.ShipmentNumber)
&& (includeShipped || !shipment.IsShipped))
{
shipments.Add(shipment);
}
}
}
}
ShipmentCount = shipments.Count;
return shipments;
}
private IList<int> GetSelectedOrders()
{
IList<int> selectedOrders = null;
// CHECK FOR QUERYSTRING PARAMETERS
int orderId = AbleCommerce.Code.PageHelper.GetOrderId();
if (orderId > 0)
{
selectedOrders = new List<int>();
selectedOrders.Add(orderId);
}
// CHECK SESSION
else selectedOrders = AbleContext.Current.Session.SelectedOrderIds;
return selectedOrders;
}
protected void Print_Click(object sender, EventArgs e)
{
IList<int> selectedOrders = GetSelectedOrders();
if ((selectedOrders == null) || (selectedOrders.Count == 0))
return;
foreach (int orderId in selectedOrders)
{
Order order = OrderDataSource.Load(orderId);
if (order != null)
EventsManager.Instance.RaiseInventoryPullSheetPrinted(null, new OrderEventArgs(order));
}
}
protected string GetShipToAddress(object dataItem)
{
OrderShipment shipment = (OrderShipment)dataItem;
string pattern = shipment.ShipToCountry.AddressFormat;
if (!string.IsNullOrEmpty(shipment.ShipToEmail) && !pattern.Contains("[Email]") && !pattern.Contains("[Email_U]")) pattern += "\r\nEmail: [Email]";
if (!string.IsNullOrEmpty(shipment.ShipToPhone) && !pattern.Contains("[Phone]") && !pattern.Contains("[Phone_U]")) pattern += "\r\nPhone: [Phone]";
if (!string.IsNullOrEmpty(shipment.ShipToFax) && !pattern.Contains("[Fax]") && !pattern.Contains("[Fax_U]")) pattern += "\r\nFax: [Fax]";
return shipment.FormatToAddress(pattern, true);
}
protected IList<OrderItem> GetProducts(object dataItem)
{
OrderShipment shipment = (OrderShipment)dataItem;
Order order = shipment.Order;
IList<OrderItem> products = new List<OrderItem>();
foreach (OrderItem item in order.Items)
{
if ((item.OrderItemType == OrderItemType.Product) && (item.OrderShipmentId == shipment.Id))
{
if (item.IsChildItem)
{
// WHETHER THE CHILD ITEM DISPLAYS DEPENDS ON THE ROOT
OrderItem rootItem = item.GetParentItem(true);
if (rootItem != null && rootItem.Product != null && rootItem.ItemizeChildProducts)
{
// ITEMIZED DISPLAY ENABLED, SHOW THIS CHILD ITEM
products.Add(item);
}
}
else products.Add(item);
}
}
//products.Sort(new OrderItemComparer());
products = products.OrderBy(p => p.Sku).ToList();
return products;
}
protected decimal GetShippingTotal(object dataItem)
{
OrderShipment order = dataItem as OrderShipment;
if (order == null) return 0;
return order.OrderItems.TotalPrice(OrderItemType.Shipping, OrderItemType.Handling);
}
protected decimal GetProductTotal(object dataItem)
{
OrderShipment order = dataItem as OrderShipment;
if (order == null) return 0;
return order.OrderItems.TotalPrice(OrderItemType.Product, OrderItemType.Discount);
}
protected decimal GetTotal(object dataItem, params OrderItemType[] orderItems)
{
return ((OrderShipment)dataItem).OrderItems.TotalPrice(orderItems);
}
protected bool ShowAdjustmentsRow(object dataItem)
{
return (GetAdjustmentsTotal(dataItem) != 0);
}
protected decimal GetAdjustmentsTotal(object dataItem)
{
OrderShipment order = dataItem as OrderShipment;
if (order == null) return 0;
return order.OrderItems.TotalPrice(OrderItemType.Charge, OrderItemType.Credit, OrderItemType.Coupon, OrderItemType.GiftWrap);
}
protected List<OrderNote> GetOrderNotesByOrder(object dataItem)
{
OrderShipment orderShipment = (OrderShipment)dataItem;
List<OrderNote> orderNotes = new List<OrderNote>();
foreach (OrderNote note in orderShipment.Order.Notes)
{
if (!note.IsPrivate)
{
orderNotes.Add(note);
}
}
return orderNotes;
}
}
}
Re: Print Customer Notes on Pullsheet
Posted: Wed Jan 20, 2016 7:38 am
by jguengerich
Glad you got it working. I figured that if you already had the mods that had a repeater for each order and/or shipment, it would mainly be a matter of casting the Container.DataItem correctly so you could use it to get the notes. Without seeing those mods, I was hesitant to suggest anything specific.