Page 1 of 1
Create/Add a note to order history when Invoice Printed
Posted: Tue Aug 03, 2010 12:26 pm
by Thistle3408
Anyone have the code to add a note (private) to the order history when an invoice is printed?
Bottom line is that our coordination would be enhanced if we could look in the history/notes and see that one of us had already printed the invoice.
Seems that capturing that when it is actually printed (admin user hits the print button instead of the back button) there is no current way to get control. Maybe there is...
I'd even be semi-satisfied if we could just know when the order's invoice was displayed for printing.
Re: Create/Add a note to order history when Invoice Printed
Posted: Wed Aug 04, 2010 4:59 am
by mazhar
Re: Create/Add a note to order history when Invoice Printed
Posted: Wed Aug 04, 2010 5:12 am
by Thistle3408
mazhar
Perhaps I wasn't clear. The thread you referred me to is for the situation where they want the existing notes to be added to the invoice displayed and printed.
I am seeking the opposite...When an admin prints a customer invoice I want to add a private note to the history that shows when/who printed that invoice.
So, when the administrator prints the invoice I want to add a note that would appear in the Order History and Notes as something like this:
8/2/2010 1:00:02 PM
admin@ourstore.com The invoice has been printed.
Re: Create/Add a note to order history when Invoice Printed
Posted: Wed Aug 04, 2010 5:30 am
by mazhar
You can try following trick. Edit your Admin/Orders/Print/Invoices.aspx file and locate following code line
Code: Select all
<asp:Button ID="Print" runat="server" Text="Print" OnClientClick="window.print();return false;" />
and update it as
Code: Select all
<asp:Button ID="Print" runat="server" Text="Print" OnClientClick="window.print();return false;" OnClick="Print_Click" />
Now edit Admin/Orders/Print/Invoices.aspx.cs file and add following code just above the last closing curly brace.
Code: Select all
protected void Print_Click(Object sender,EventArgs e)
{
List<int> selectedOrders = GetSelectedOrders();
foreach (int orderId in selectedOrders)
{
Order order = OrderDataSource.Load(orderId);
OrderNote note = new OrderNote();
note.Comment = string.Format("Invoice Printed By {0}", Token.Instance.User.UserName);
note.CreatedDate = LocaleHelper.LocalNow;
note.NoteType = NoteType.Private;
order.Notes.Add(note);
order.Save();
}
}
save the changes and try print invoice for some test order then see its not section for private note
Re: Create/Add a note to order history when Invoice Printed
Posted: Sun Aug 08, 2010 10:45 am
by Thistle3408
Hmm, it doesn't seem to be running both scripts (the actual print, caused by the OnClientClick, and the "Print_Click" script.
I can tell the "Print_Click" is correctly in the .cs because I can take the following line and add it to the Admin/Orders/Print/Invoices.aspx file and cause the note to be added:
Code: Select all
<asp:Button ID="Print1" runat="server" Text="Print1" OnClick="Print_Click" />
Why isn't the OnClick="Print_Click and OnClientClick="window.print();return false;" not both running when the button is clicked? DId we miss something obvious?
Re: Create/Add a note to order history when Invoice Printed
Posted: Mon Aug 09, 2010 4:19 am
by mazhar
try updating this part
Code: Select all
OnClientClick="window.print();return false;"
to
Re: Create/Add a note to order history when Invoice Printed
Posted: Mon Aug 09, 2010 10:08 am
by Thistle3408
Done and works exactly as needed.