programlibs/Format/demos/invoice.xtl

An invoice: items, quantities and prices set as a table, money to 2 places, a total with thousands separated, the tax as a percentage. Run with "just demo Format invoice".

source · imports f: libs/Format/src/Format.xtl; t: libs/Strings/src/Strings.xtl

items : Box Char

value · line 8
items ← "notebook" "pen" "stapler" "paper (ream)" "desk"
Used in: body

qty : Int

value · line 9
qty ← 4 12 1 10 1
Used in: amount, body

price : Float

value · line 10
price ← 2.5 0.85 12.99 4.25 1249.0
Used in: amount, body

amount : Float

value · line 11
amount ← price × f̲loat qty
Used in: body, total

body : Box Char

value · line 14
body ← (5 1 r̲eshape items) c̲at₂ (5 1 r̲eshape 'f̲ormat m̲ap qty) c̲at₂ (5 1 r̲eshape 2 ᶠf̲ixed price) c̲at₂ 5 1 r̲eshape 2 ᶠf̲ixed amount

total : Float

value · line 17
total ← '+ r̲/ amount

rate : Float

value · line 18
rate ← 0.0825

discount : Float

value · line 20
discount ← 0.05 × f̲loat total > 1000.0                      ⍝ 5% off orders over 1,000 (a comparison is 0 or 1)

total : Float

value · line 22
total ← total × 1.0 − discount