AnsweredAssumed Answered

Avoid line item being invoiced twice

Question asked by tbcomputerguy on Feb 22, 2012
Latest reply on Feb 23, 2012 by philmodjunk

Title

Avoid line item being invoiced twice

Post

Ok this script is run by a button. What is does is the job orders are not billed all at once. They are invoiced by selecting various items from the portal. There is a y/n drop down on each line so when it comes time to invoice they select what is to be invoiced. I hope to avoid duplicate items being invoiced. So i have taken the lineitemId from the joborderitems table and copied it to the invoice items table as a check. If that item number is there, then stop, warn the user and exit back to the joborder screen. This is the part of the script that is supposed to do that. the check as you can see is the $lineid variable. When I run it, even if there are no records present i the invoice lineitem table, the error message shows up.  I tried making the jolineitem field a unique value which stops the script immediately with the revert record popup, and stops the script there at the copy process. I hope that helps.

Go to Record/Request/Page
[ First]
Loop
#--------------------------------------Set variables with line item info
Set Variable [ $lineid; Value:Job_Order_Line_Items::ID_LineItem ]
Set Variable [ $desc; Value:Job_Order_Line_Items::Description ]
Set Variable [ $quantity; Value:Job_Order_Line_Items::Quantity ]
Set Variable [ $price; Value:Job_Order_Line_Items::UnitPrice]
#--------------------------------------Go to invoice line items window
Go to Layout[ “Invoice_LineItems_Maint” (Invoice_LineItems) ]
New Record/Request
Go to Record/Request/Page [ Last ]
Set Field[ Invoice_LineItems::id_invoice ; $ID_INV ]
Set Field[ Invoice_LineItems::Description ; $desc ]
Set Field[ Invoice_LineItems::Quantity; $quantity ]
Set Field[ Invoice_LineItems::UnitPrice ; $price ]
Set Field[ Invoice_LineItems::joblineitem; $lineid ]
#--------------------------------------If lineitem from Jobs exists, notify user
If [ $lineid ]
Show Custom Dialog[ Title: "Invoicing Error!"; Message: "An Invoice with one/some of the line items you selected have already been invoiced for.  Please verify your selection and try creating another invoice!"; Buttons: “OK”, “Cancel” ]
If [ Get ( LastMessageChoice ) = "2" ]
Revert Record/Request [ No dialog ]
Go to Layout[ “Job Orders” (JobOrders) ]
Exit Script [  ]
End If
End If

Outcomes