This example shows you how to edit invoice lines, giving quantity break pricing. We will also introduce data level scripting and use the Do ... Loop statement on invoice lines. We'll use a pretty simple rule for the script. If the quantity is:
We'll assume the user will be running this script after entering the invoice and before printing or saving. So we can either use the same starting point we used earlier for entering a narrative line using a script, or we can record this starting point again and edit it. In this example, we'll use the existing starting point.
Dim frmINInvoice1 Object
frmINInvoice1 = GetActiveObject
If IsNull(frmINInvoice1) or Form1.ClassName <> "INInvoiceEntryForm" then Error "Wrong form class for script"
1 to InvForm and change the error message:Dim InvForm as Object
InvForm = GetActiveObject
If IsNull(InvForm) or InvForm.ClassName <> "INInvoiceEntryForm" Then Error "Wrong form for script"
Dim ProdForm as Object
ProdForm = CreateObject("Accredo.ICProductForm")
Line.Dim Line as Object
Line = InvForm.Line
Line.First
Do Until Line.EOF
Line.Next
Loop
Pricebreak based on that.If Line.LineType = "Product" Then
If Line.QuantitySupplied > 30 Then
Pricebreak = 1
ElseIf Line.QuantitySupplied > 15 Then
Pricebreak = 2
Else
Pricebreak = 3
End If
End If
Prices[] and save the prices in this Array. If ProdForm.FindExact(Line.ProductCode) Then
Dim Prices[1 to 3] as number
For i = 1 To 3
Prices[i] = ProdForm.Price.SellingPrice
ProdForm.Price.Next
Next
End if
Prices Array. If PriceList = 1 Then
Form1.Line.SellingPrice = Prices[1]
ElseIf PriceList = 2 Then
Form1.Line.SellingPrice = Prices[2]
Else
Form1.Line.SellingPrice = Prices[3]
End If
Dim Form1 as Object
Form1 = GetActiveObject
If IsNull(Form1) or Form1.ClassName <> "INInvoiceEntryForm" then Error "Wrong form class for script"
Dim ProdForm as Object
ProdForm = CreateObject("Accredo.ICProductForm")
Dim Line as Object
Line = Form1.Line
Line.First
Do Until Line.EOF
If Line.LineType = "Product" Then
If Line.QuantitySupplied > 30 Then
Pricebreak = 1
ElseIf Line.QuantitySupplied > 15 Then
Pricebreak = 2
Else
Pricebreak = 3
End If
If ProdForm.FindExact(Line.ProductCode) Then
Dim Prices[1 to 3] as number
For i = 1 To 3
Prices[i] = ProdForm.Price.SellingPrice
ProdForm.Price.Next
Next
If Pricebreak = 1 Then
Form1.Line.SellingPrice = Prices[1]
ElseIf Pricebreak = 2 Then
Form1.Line.SellingPrice = Prices[2]
Else
Form1.Line.SellingPrice = Prices[3]
End If
End If
End If
Line.Next
Loop
Note: We need to move the End If and Loop statements to the end, to ensure the statements continue.
Dim ProdForm as Object
ProdForm = CreateObject("Accredo.ICProductForm")
with
Dim ProdForm as Object
ProdForm = CreateObject("Accredo.ICProductData")
Dim Form1 as Object
Form1 = GetActiveObject
If IsNull(Form1) or Form1.ClassName <> "INInvoiceEntryForm" then Error "Wrong form class for script"
Dim ProdForm as Object
If ModuleAvailable("EDI") then
ProdForm = CreateObject("Accredo.ICProductData")
Else
ProdForm = CreateObject("Accredo.ICProductForm")
End If
Dim Line as Object
Line = Form1.Line
Line.First
Do Until Line.EOF
If Line.LineType = "Product" Then
If Line.QuantitySupplied > 30 Then
Pricebreak = 1
ElseIf Line.QuantitySupplied > 15 Then
Pricebreak = 2
Else
Pricebreak = 3
End If
If ProdForm.FindExact(Line.ProductCode) Then
Dim Prices[1 to 3] as number
For i = 1 To 3
Prices[i] = ProdForm.Price.SellingPrice
ProdForm.Price.Next
Next
If Pricebreak = 1 Then
Form1.Line.SellingPrice = Prices[1]
ElseIf Pricebreak = 2 Then
Form1.Line.SellingPrice = Prices[2]
Else
Form1.Line.SellingPrice = Prices[3]
End If
End If
End If
Line.Next
Loop
If Not ModuleAvailable("EDI") then
ProdForm.Close
ProdForm = Nothing
End If