Page 1 of 1

How to selectively mark as printed based on a certain status

Posted: Wed Oct 28, 2015 4:14 pm
by compunerdy
I got the orders to be marked as printed after printing but I have found this can be a issue sometimes. Is there a way to make it so that if the order is not a certain status then it does not get marked as printed. For instance if it is not order status of payment completed then do not mark as printed. The issue I have is sometimes I will reprint a invoice after it has been shipped and this will change the status from completed to packing list printed.

Re: Customizations in Gold

Posted: Thu Oct 29, 2015 12:02 am
by mazhar
compunerdy wrote:I got the orders to be marked as printed after printing but I have found this can be a issue sometimes. Is there a way to make it so that if the order is not a certain status then it does not get marked as printed. For instance if it is not order status of payment completed then do not mark as printed. The issue I have is sometimes I will reprint a invoice after it has been shipped and this will change the status from completed to packing list printed.
Edit Your Admin/Orders/Print/Invoices.aspx.cs file and locate following code

Code: Select all

foreach (Order order in orders)
            {
                EventsManager.Instance.RaiseOrderInvoicePrinted(null, new OrderEventArgs(order));
            }
then update it like

Code: Select all

foreach (Order order in orders)
            {
                if (order.OrderStatus != null && order.OrderStatus.Name != "YOUR PRINT ONLY STATUS NAME")
                    continue;
                EventsManager.Instance.RaiseOrderInvoicePrinted(null, new OrderEventArgs(order));
            }
Where you will need replace "YOUR PRINT ONLY STATUS NAME" with order status name allowed for printing

Re: Customizations in Gold

Posted: Thu Oct 29, 2015 12:32 am
by jmestep
Mazhar, what version of Gold/browser are you using to get the above to work? I had to struggle with that also and when I print an invoice in R9 and R10, the Print_Click is never hit as long as the OnClientClick is present.

Re: Customizations in Gold

Posted: Thu Oct 29, 2015 12:49 am
by mazhar
I am using Gold R11 but I haven't tried the code. I just looked at the place where we trigger print event. In above change it will still open the print screen but it wouldn't trigger print event unless order status is of a specific name.

Re: Customizations in Gold

Posted: Sat Oct 31, 2015 1:29 pm
by compunerdy
This is not working for me. Here is my code..

Code: Select all

protected void Print_Click(object sender, EventArgs e)
        {
            IList<int> selectedOrders = GetSelectedOrders();
            if ((selectedOrders == null) || (selectedOrders.Count == 0))
                return;
            IList<Order> orders = GetOrders(selectedOrders.ToArray());
            foreach (Order order in orders)
            {
                if (order.OrderStatus != null && order.OrderStatus.Name != "Payment Completed")
                    continue;
                EventsManager.Instance.RaiseOrderInvoicePrinted(null, new OrderEventArgs(order));
            }
        }
I printed a invoice for a order with order status completed and it still was changed to packing list printed.

Re: Customizations in Gold

Posted: Fri Nov 06, 2015 2:15 am
by nadeem
This is the issue with firefox browser with printing. When you call print using button OnClientClick event, the OnClick event never got fired. As a result the code inside Print_Click never executed.

To fix this issue, you can put the print function inside Print_Click and remove the OnClientClick from print button.

To do so open Admin/Orders/Print/Invoices.aspx

Locate

Code: Select all

<asp:Button ID="Print" runat="server" Text="Print" OnClientClick="window.print();" OnClick="Print_Click" />
and replace with

Code: Select all

<asp:Button ID="Print" runat="server" Text="Print" OnClick="Print_Click" />
Similarly, open Admin/Orders/Print/Invoices.aspx.cs

Locate

Code: Select all

protected void Print_Click(object sender, EventArgs e)
        {            
            IList<int> selectedOrders = GetSelectedOrders();
            if ((selectedOrders == null) || (selectedOrders.Count == 0))
                return;
            IList<Order> orders = GetOrders(selectedOrders.ToArray());
            foreach (Order order in orders)
            {
                EventsManager.Instance.RaiseOrderInvoicePrinted(null, new OrderEventArgs(order));
            }
        }
and replace with

Code: Select all

protected void Print_Click(object sender, EventArgs e)
        {
            string scriptKey = "scriptKey";
            if (!Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), scriptKey))
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), scriptKey, "window.print();", true);
            }

            IList<int> selectedOrders = GetSelectedOrders();
            if ((selectedOrders == null) || (selectedOrders.Count == 0))
                return;
            IList<Order> orders = GetOrders(selectedOrders.ToArray());
            foreach (Order order in orders)
            {
                EventsManager.Instance.RaiseOrderInvoicePrinted(null, new OrderEventArgs(order));
            }
        }

Re: Customizations in Gold

Posted: Fri Nov 06, 2015 7:00 am
by compunerdy
I am confused here..

The original code to change the order status to "packing list printed" worked just fine for me. The problem was if I tried to reprint a order that was order status "completed" for example it would change the status to "packing list printed" which I did not want it to do. So I asked for code that would only change the status to "packing list printed" if the current order status was "payment completed" which I think Maz tried to give me but it did not work for me. Obviously the order status's I listed may not be standard ones but I am sure you get where I am going. If it matters I am using the Edge browser.

Re: Customizations in Gold

Posted: Mon Nov 09, 2015 1:08 am
by nadeem
Original code wasn't working in Firefox browser because the Print_Click event wasn't firing. Now that the main issue is fixed, you can use part of code provided by Mazhar to get your desired results.

At Admin/Orders/Print/Invoices.aspx use the following code

Code: Select all

<asp:Button ID="Print" runat="server" Text="Print" OnClick="Print_Click" />

and below code at Admin/Orders/Print/Invoices.aspx.cs

Code: Select all

    protected void Print_Click(object sender, EventArgs e)
            {
                string scriptKey = "scriptKey";
                if (!Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), scriptKey))
                {
                     this.Page.ClientScript.RegisterStartupScript(this.GetType(), scriptKey, "window.print();", true);
                }

                IList<int> selectedOrders = GetSelectedOrders();
                if ((selectedOrders == null) || (selectedOrders.Count == 0))
                    return;
                IList<Order> orders = GetOrders(selectedOrders.ToArray());
                foreach (Order order in orders)
                {
                    if (order.OrderStatus != null && order.OrderStatus.Name != "Payment Completed")
                        continue;
                    EventsManager.Instance.RaiseOrderInvoicePrinted(null, new OrderEventArgs(order));
                }
            }

Re: Customizations in Gold

Posted: Tue Nov 10, 2015 6:43 am
by compunerdy
This code below is what made it so orders where marked as printed.. using the code you posted above does not mark orders as printed.
mazhar wrote:
When an order is printed the status needs to be updated to Order Printed. It was originally addressed at viewtopic.php?f=42&t=8681, but those modifications do not seem to work with Gold, no matter how many different ways we try them.
Edit your Invoice.ascx.cs file and add following method to it

Code: Select all

protected void MarkPrinted_Click(object sender, EventArgs e)
        {
            IList<int> selectedOrders = GetSelectedOrders();
            if ((selectedOrders == null) || (selectedOrders.Count == 0)) Response.Redirect("~/Admin/Orders/Default.aspx");
            IList<Order> orders = GetOrders(selectedOrders.ToArray());
            OrderStatus orderStatus = OrderStatusDataSource.Load(7);
            foreach (Order order in orders)
                order.UpdateOrderStatus(orderStatus);
        }
Now find the following line of code in Invoices.ascx file

Code: Select all

<asp:Button ID="Print" runat="server" Text="Print" OnClientClick="window.print();return false;" />
and make it look like

Code: Select all

<asp:Button ID="Print" runat="server" Text="Print" OnClientClick="window.print();return true;" OnClick="MarkPrinted_Click" />
This change will change the order status with the print button.

Re: Customizations in Gold

Posted: Tue Nov 10, 2015 8:54 am
by Katie
Sorry if I'm jumping into the middle of this conversation, but I didn't know if you had seen that we have new triggers in Gold so you can change the order status automatically upon printing. Three new triggers are available for Order Invoice Printed, Packing List Printed, and Inventory Pull Sheet Printed.

Re: How to selectively mark as printed based on a certain status

Posted: Wed Nov 11, 2015 7:13 am
by compunerdy
Thanks to Katie I setup the built in trigger and then Nadeem's code worked for me.. Thanks!!!