stamp-duty2.taq

java -jar taq.jar stamp-duty2

Running query stamp_duty_query in global scope 
stamp_duty_payable(100077, USD3,789.00, bracket=0, payable=USD20.00)
stamp_duty_payable(100078, USD123,458.00, bracket=5, payable=USD3,768.32)
stamp_duty_payable(100079, USD55,876.33, bracket=6, payable=USD1,285.67)
stamp_duty_payable(100080, USD1,245,890.00, bracket=1, payable=USD62,353.95)

Description

stamp-duty2.taq demonstrates a select receiver template used with a skip on default strategy. The “stamp_duty_query” query calculates stamp duty (tax on a real estate purchase) according to sale amount and the bracket it falls into. There is a threshold below which a flat rate applies and no calculation is required.

The bracket range is open at the top (amount > 500000) and closed at the bottom (amount > 5000), so it is amounts under $5,000 to which the default strategy applies. The default condition simply results in the sideways execution into the receiver being skipped leaving the “duty” variable unchanged from it’s initial setting.

Note that the select variables are accessed directly in the receiver and thus improving readability

duty = base + (amount - threshold) * (percent / 100)


select sale_bracket
( amount, threshold, base, percent)
{
? > 500000: 500000, 21330.00, 5.50
? > 300000: 300000, 11330.00, 5.00
? > 250000: 250000, 8955.00, 4.75
? > 200000: 200000, 6830.00, 4.25
? > 100000: 100000, 2830.00, 4.00
? > 50000: 50000, 1080.00, 3.50
? > 30000: 30000, 480.00, 3.00
? > 12000: 12000, 120.00, 2.00
? > 5000: 0, 0.00, 1.00
}

flow stamp_duty_payable
{ currency.USD amount }
(
. duty = currency.USD 20.00,
. flow sale_bracket(amount) {
duty = base + (amount - threshold) *
(percent / 100)
},
term id,
amount.format(),
bracket = sale_bracket.index() + 1,
string payable = duty.format()
)

query<axiom> stamp_duty_query (transaction_amount : stamp_duty_payable)

axiom list transaction_amount
( id, amount )
{ 100077, 3789.00 }
{ 100078, 123458.00 }
{ 100079, 55876.33 }
{ 100080, 1245890.00 }