POP Order Status

Hi community, 

We have a small issue with the POP List. Sometimes, an order is fully received but hasn't been invoiced yet. In the system, it still appears as "Live." It's okay, but we need a better way to see what's going on. Each user as their specific filter set up to make sure they are on the top of the orders.

To solve this, we came up with an idea. We created a special Analysis code called 'Received.' When an order is fully received, users manually mark it as 'Full'. 

The trouble is, this process is a bit repetitive and not very efficient. So, I've been experimenting and came up with the following SQL Script. 

Feedback about the code would also be appreciated. Also, is there any other way of achieving the same, or improving the below code?

 

UPDATE PR
SET PR.AnalysisCode7 = CASE
    WHEN ReceivedLineCount >= TotalLines THEN 'Full'
    ELSE ''
END
FROM POPOrderReturn AS PR
INNER JOIN (
    SELECT DocumentNo,
           COUNT(CASE WHEN ConfirmationIntentTypeID <> 2 THEN 1 ELSE 0 END) AS TotalLines
    FROM POPOrderReturn
    INNER JOIN POPOrderReturnLine ON POPOrderReturn.POPOrderReturnID = POPOrderReturnLine.POPOrderReturnID
    WHERE ConfirmationIntentTypeID <> 2 AND LineTypeID <> 2
    GROUP BY DocumentNo
) AS TotalLines ON PR.DocumentNo = TotalLines.DocumentNo
INNER JOIN (
    SELECT DocumentNo,
           COUNT(CASE WHEN (ConfirmationIntentTypeID <> 2 AND ReceiptReturnQuantity >= LineQuantity) THEN POPOrderReturnLine.ItemCode END) AS ReceivedLineCount
    FROM POPOrderReturn
    INNER JOIN POPOrderReturnLine ON POPOrderReturn.POPOrderReturnID = POPOrderReturnLine.POPOrderReturnID
    WHERE ConfirmationIntentTypeID <> 2 AND LineTypeID <> 2
    GROUP BY DocumentNo
) AS Received ON PR.DocumentNo = Received.DocumentNo;

Thanks for your help.

 

Kind regards,

Parents Reply Children
  • 0 in reply to Toby

    Hi Toby,

    I appreciate your advice. I want to make it clear that I wouldn't make any changes without the approval of my BP. However, we're not keen on spending a lot of money on a feature that, for instance, comes as a standard feature in Sage 50.

    Is there a pre-made add-on available?

    Thanks,

  • 0 in reply to SAMUEL MAIA

    Hmm. Normally I'd agree, Toby.  But all that's being updated here is a string value in an AnalysisCode field. I don't think the world's going to spin off its axis if you inadvertently get the wrong value in there.

    One thing I will say without even executing the SQL is that you really need to limit the number of rows being read/updated - and the most obvious way of doing that is by restricting yourself to live purchase orders (add POPOrderReturn.DocumentStatusID = 0 to the WHERE clause of both subqueries). Otherwise you'll eventually end up with lock escalations in SQL where you're trying to lock so many rows for update that SQL Server gives up and attempts to lock the entire table instead, and that's a great way of running into deadlocks.   

  • 0 in reply to Chris Burke

    Hi Chris,

    Yes, it's only a simple analysis code. It's a small thing we're trying to do to make our work a bit easier. I understand that there are reports and workspaces, but where I work, people mainly use the PO List. 

    I did consider using the ‘Live’ condition, but for the first time, I'd like to update everything retroactively.

    Instead of adding the "Live" condition, I thought about using the DateTimeUpdated field. Your thoughts?

    Once again, I'm open to hearing what the community thinks about this, and ultimately, it's my business partner who will decide whether to implement it.

     

    Thank you very much for all the feedback