transactions.typ (2677B)
1 #import "@preview/cetz:0.4.2": canvas, draw, palette 2 #import "@preview/cetz-plot:0.1.3": plot, chart 3 #import "@taler-merchant/common:0.0.0": format_timeframe, format_timestamp, format_round_timestamp 4 5 #let form(data) = { 6 set page( 7 paper: "a4", 8 margin: (left: 2cm, right: 2cm, top: 2cm, bottom: 2.5cm), 9 footer: context [ 10 #grid( 11 columns: (1fr, 1fr), 12 align: (left, right), 13 text(size: 8pt)[], 14 text(size: 8pt)[ 15 Page #here().page() of #counter(page).final().first() 16 ] 17 ) 18 ] 19 ) 20 21 heading(level: 1)[GNU Taler Merchant Accounting: #data.business_name] 22 23 [Transaction report from 24 #underline([#format_round_timestamp(data.start_date,data.bucket_period.d_us,false)]) to 25 #underline([#format_round_timestamp(data.end_date,data.bucket_period.d_us,false)]) 26 with 27 #text(weight: "bold")[#format_timeframe(data.bucket_period.d_us)] 28 granularity. 29 ] 30 31 let p = palette.new(colors: (blue, green, yellow, orange, purple, lime, teal, gray, red)) 32 v(1cm) 33 34 for dchart in data.charts { 35 36 heading(level: 2)[#dchart.chart_name] 37 38 let data_groups = dchart.data_groups.map(dg => ( 39 values: dg.values, 40 start_date_str: format_round_timestamp(dg.start_date,data.bucket_period.d_us, false), 41 start_date_mini: format_round_timestamp(dg.start_date,data.bucket_period.d_us, true), 42 )) 43 44 canvas(length: 1cm, { 45 import draw: * 46 47 chart.columnchart( 48 size: (12, 8), 49 label-key: "start_date_mini", 50 value-key: "values", 51 x-label: [Time], 52 y-label: dchart.y_label, 53 x-tick-step: none, 54 y-tick-step: auto, 55 mode : if dchart.cumulative { "stacked" } else { "clustered" }, 56 // alternatives: "clustered" or "basic" or "stacked" 57 bar-style: p, 58 data_groups, 59 labels: dchart.labels, 60 legend: "east", 61 ) 62 }) 63 64 v(1cm) 65 66 let cols = (auto,) + dchart.labels.map(_ => auto) 67 if dchart.cumulative { 68 cols.push(auto) 69 } 70 71 let aligns = (left,) + dchart.labels.map(_ => right) 72 if dchart.cumulative { 73 aligns.push(right) 74 } 75 76 let header = ([*When*],) + dchart.labels.map(label => [*#label*]) 77 if dchart.cumulative { 78 header.push([*Total*]) 79 } 80 81 let rows = data_groups.map(entry => { 82 let row = (entry.at("start_date_str"),) 83 row += entry.at("values").map(val => str(val)) 84 if dchart.cumulative { 85 row.push(str(entry.at("values").sum())) 86 } 87 row 88 }).flatten() 89 90 align(center, 91 table( 92 columns: cols, 93 align: aligns, 94 ..header, 95 ..rows 96 )) 97 v(1cm) 98 99 } // For all charts 100 101 }