Create/Add a note to order history when Invoice Printed

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
Thistle3408
Lieutenant (LT)
Lieutenant (LT)
Posts: 77
Joined: Mon Apr 19, 2010 4:52 pm

Create/Add a note to order history when Invoice Printed

Post by Thistle3408 » Tue Aug 03, 2010 12:26 pm

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.


Thistle3408
Lieutenant (LT)
Lieutenant (LT)
Posts: 77
Joined: Mon Apr 19, 2010 4:52 pm

Re: Create/Add a note to order history when Invoice Printed

Post by Thistle3408 » Wed Aug 04, 2010 5:12 am

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.

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

Re: Create/Add a note to order history when Invoice Printed

Post by mazhar » Wed Aug 04, 2010 5:30 am

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

Thistle3408
Lieutenant (LT)
Lieutenant (LT)
Posts: 77
Joined: Mon Apr 19, 2010 4:52 pm

Re: Create/Add a note to order history when Invoice Printed

Post by Thistle3408 » Sun Aug 08, 2010 10:45 am

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?

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

Re: Create/Add a note to order history when Invoice Printed

Post by mazhar » Mon Aug 09, 2010 4:19 am

try updating this part

Code: Select all

OnClientClick="window.print();return false;"
to

Code: Select all

OnClientClick="window.print();"

Thistle3408
Lieutenant (LT)
Lieutenant (LT)
Posts: 77
Joined: Mon Apr 19, 2010 4:52 pm

Re: Create/Add a note to order history when Invoice Printed

Post by Thistle3408 » Mon Aug 09, 2010 10:08 am

Done and works exactly as needed.

Post Reply