Hi again!
I’m doing a script that calculates the percent of rebate from fields values and generates the result in another field. This script makes field’s values validation also.
There are two types to calculate the rebate.
1 - Inserting the percent of rebate and the application tells how much was rebated;
2 - Inserting the money value and the app tells the percent of money amount was rebated.
My problem is that when I put some values on a percent field, the others, which must insert or replace all values, according the amount set before, is not being replaced. I’m trying to make the refresh on the formulary but it not worked.
Theres a way to make theses values be replaced automatically without saving everytime the form to make we see them?
Heres the code:
Dim session As New NotesSession
Dim db As NotesDatabase
Dim primeiro As NotesDateTime
Dim segundo As NotesDateTime
Dim workspace As New NotesUIWorkspace
Dim doc As NotesDocument
Dim Total As Variant
Dim unitario As Variant
Dim porcentagem As Variant
Dim quantidade As Variant
Dim cento As Variant
Dim arm As Variant
Set db = session.currentDatabase
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document
data1 = uidoc.FieldGetText("vencimento_ini")
formulario = uidoc.FieldGetText("formulario")
data2 = uidoc.FieldGetText("vencimento_fim")
produto = uidoc.FieldGetText("choose_prod")
software = uidoc.FieldGetText("choose_soft")
licenca = uidoc.FieldGetText("licenca")
versao = uidoc.FieldGetText("versao")
quantidade = uidoc.FieldGetText("qtd")
unitario = uidoc.FieldGetText("ValorUnitario")
total = uidoc.FieldGetText("Total")
desconto = uidoc.FieldGetText("desconto")
valor = uidoc.FieldGetText("porcentagem")
dinheiro = uidoc.FieldGetText("desconto_1")
Set primeiro = New NotesDateTime(data1)
Set segundo = New NotesDateTime(data2)
If produto = "" And software = "" And licenca = "" And versao = "" And quantidade = "" Then
Messagebox "Para salvar este documento, preencha pelo menos um campo do mesmo."
Continue = False
Exit Sub
End If
If (formulario = "Ativos") And (data1 = "" Or data2= "") Then
Msgbox "O preenchimento dos campos de data são obrigatórios."
Continue=False
Exit Sub
End If
If Not data2 = "" Then
If primeiro.TimeDifference(segundo) > 0 Then
Messagebox "A Data do Vencimento Final deve ser maior do que a Data do Vencimento Inicial!"
Continue = False
Exit Sub
End If
End If
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------
If quantidade <> "" And unitario <> "" Then
Total = quantidade * unitario
doc.Total = total
Continue = True
Call doc.Save(True,True)
Call uidoc.Refresh
End If
If Not Total = "" Then
'If valor = "" And desconto <> "" Then
valor = total * (desconto / 100)
doc.porcentagem = total - valor
continue = True
dinheiro = desconto / total
doc.desconto_1 = valor
Call uidoc.Refresh
' End If
'If desconto = "" And dinheiro <> "" Then
desconto = (dinheiro / total) * 100
doc.desconto = desconto
Call doc.Save(True,True)
doc.porcentagem = total - dinheiro
continue = True
' Elseif desconto = "" And valor = "" Then
'If desconto = "" And valor = "" Then
' continue = True
' End If
'Else continue = True
End If
End Sub