Logical functions
The following operators are available.
Operator | Description |
---|---|
|
Greater than |
|
Less than |
|
Greater than or equal |
|
Less than or equal |
|
Not equal |
|
Equal |
|
In an x and y evaluation, if x evaluates to false then its value is returned, otherwise y is evaluated and the resulting value is returned. |
|
In an x or y evaluation, if x evaluates to true then its value is returned, otherwise y is evaluated and the resulting value is returned. |
|
In a not x evaluation, if not x, we mean the opposite of x. |
If
This function compares the source data to a value. With the logical functionif, you specify an action if the result of the comparison is true.
This function has the following arguments: source, operator, and value.
print "Running UDBR Script 'IFELSE_1'\n"
source = Creator.createSource()
source.setCompany('2530')
source.setAccount('3020')
source.loadData()
print "Source after load:"
Writer.printSourceData(source)
target1 = Creator.createTarget()
target1.setCompany('2530')
target1.setAccount('4020')
target1.setEType('UD')
target1.setJournalNumber(97)
for transaction in source:
amount = transaction.getAmount()
if (amount < 0):
target1.addTransaction(transaction)
print "Target1 after addTransaction loop:"
Writer.printTargetData(target1)
target1.saveDataWithJournalHeaders()
print "Target1:"
Writer.printTargetData(target1)
#--------------Remove original transaction------------------------------------#
target2 = Creator.createTarget()
target2.setCompany('2530')
target2.setAccount('3020')
target2.setEType('UD')
target2.setJournalNumber(98)
target2.addDataWithFactor(target1,-1)
target2.saveDataWithJournalHeaders()
print "Target2:"
Writer.printTargetData(target2)
If else
This function compares the source data to a value. With the logical function if else, you specify actions for all results.
This function has the following arguments: source, operator, and value.
The following code example shows the usage of the functions if and else. If the amount of a transaction on account 3020 (source) is more than 220, the amount is posted to account 4020 (target 1). In all other cases, the amount is posted to account 3010 (target 2). The example creates a balance that is posted on account 3020 (target 3).
print "Running UDBR Script 'IFELSE_3'\n"
source = Creator.createSource()
source.setCompany('2530')
source.setAccount('3020')
source.loadData()
print "Source after load:"
Writer.printSourceData(source)
target1 = Creator.createTarget()
target1.setCompany('2530')
target1.setAccount('4020')
target1.setEType('UD')
target1.setJournalNumber(97)
target2 = Creator.createTarget()
target2.setCompany('2530')
target2.setAccount('3010')
target2.setEType('UD')
target2.setJournalNumber(98)
for transaction in source:
amount = transaction.getAmount()
if (amount > 220):
target1.addTransaction(transaction)
else:
target2.addTransaction(transaction)
print "Target1 after addTransaction loop:"
Writer.printTargetData(target1)
target1.saveDataWithJournalHeaders()
print "Target1:"
Writer.printTargetData(target1)
print "Target2 after addTransaction loop:"
Writer.printTargetData(target2)
target2.saveDataWithJournalHeaders()
print "Target2:"
Writer.printTargetData(target2)
#--------------Remove original transaction------------------------------------#
target3 = Creator.createTarget()
target3.setCompany('2530')
target3.setAccount('3020')
target3.setEType('UD')
target3.setJournalNumber(99)
target3.addDataWithFactor(target1,-1)
target3.addDataWithFactor(target2,-1)
target3.saveDataWithJournalHeaders()
print "Target3:"
Writer.printTargetData(target3)