On Error Resume Next
SetLocale("en-US")
' Set Error by default
UserField_Invoice_Total.ValidateMessage = "Error: Net Total+Tax Total is not equal to Invoice Total"
UserField_Invoice_Total.ValidateStatus = false
' Get Values
Subtotal = CDbl(UserField_Net_Total.value)
tax = CDbl(UserField_Tax_Total.value)
total = CDbl(UserField_Invoice_Total.value)
transport = CDbl(UserField_Transport_Total.value)
' Validate values
dif = Abs(total - (subtotal + tax + transport))
If dif <= 0.03 Then
UserField_Invoice_Total.ValidateStatus = true
End If
If UserField_Invoice_Total.value = "" Then
UserField_Invoice_Total.ValidateStatus = false
End If
If CDbl(UserField_Net_Total.value) + CDbl(UserField_Transport_Total.value) = CDbl(UserField_Grid_Total.value) Then
UserField_Grid_Total.ValidateStatus = 1
Else
UserField_Grid_Total.ValidateStatus = 0
UserField_Grid_Total.ValidateMessage = "There is something wrong with the line items"
End If
Also, extra functionality can be added by using custom buttons. This code will help when there are missing Line Total values on the grid. The button will fill in the calculated value when the Line Total value is missing.
This code goes inside OnButtonClick for Button 1:
SetLocale("en-US")
PanelNo = 1
Total = CDbl(0)
NumRows = ChronoDocument.GetXgridRowCount(PanelNo)
For i = 0 To NumRows - 1
If ChronoDocument.GetXgridFieldValue (PanelNo,i,"Quantity") = "" Then
Qty = CDbl(0)
Else
Qty = CDbl(ChronoDocument.GetXgridFieldValue (PanelNo,i,"Quantity"))
End If
If ChronoDocument.GetXgridFieldValue (PanelNo,i,"Unit Price") = "" Then
UPrice = CDbl(0)
Else
UPrice = CDbl(ChronoDocument.GetXgridFieldValue (PanelNo,i,"Unit Price"))
End If
If ChronoDocument.GetXgridFieldValue (PanelNo,i,"Line total") = "" Then
CurrLine = CDbl(0)
Else
CurrLine = ChronoDocument.GetXgridFieldValue (PanelNo,i,"Line total")
End If
LineTotal = FormatNumber(Qty * UPrice)
If CurrLine = 0 Then
Call ChronoDocument.SetXgridFieldValue(PanelNo,i,"Line total",LineTotal)
CurrLine = LineTotal
End If
If LineTotal <> FormatNumber(CurrLine) Then
Call ChronoDocument.SetXgridFieldColor(PanelNo,i,"Line total",rgb(255,0,0))
Else
Call ChronoDocument.SetXgridFieldColor(PanelNo,i,"Line total",-1)
End If
Total = CDbl(Total + CurrLine)
Next
'msgbox FormatNumber(ChronoDocument.GetXgridFieldValue (PanelNo,6,"Quantity") * ChronoDocument.GetXgridFieldValue (PanelNo,6,"Unit Price"))
'msgbox FormatNumber(Total)
UserField_Grid_Total.value = FormatNumber(Total)
|