BastliPOSPrinter

A collection of programs that allow receipt printing
git clone git://xatko.vsos.ethz.ch/BastliPOSPrinter.git
Log | Files | Refs

commit 73cbfb261d91a13e2b8ce6bbed51146f86d73f3a
Author: Dominik Schmidt <doeme@bastli.ethz.ch>
Date:   Mon,  3 Sep 2018 16:59:26 +0200

Initial commit

Diffstat:
daemon.sh | 6++++++
pipeline.sh | 7+++++++
pipeline/GROFF_to_printable | 3+++
pipeline/JSON_to_GROFF.d | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
pipeline/print | 3+++
template.roff | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 141 insertions(+), 0 deletions(-)

diff --git a/daemon.sh b/daemon.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +USERNAME="${1}" +PASSWORD="${2}" + +./amqp-consume --server=backdoor.bastli.ch "--username=${USERNAME}" "--password=${PASSWORD}" --vhost="/" -q print_queue ./pipeline.sh diff --git a/pipeline.sh b/pipeline.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +cd pipeline + +./JSON_to_GROFF ../template.roff \ +| ./GROFF_to_printable \ +| ./print diff --git a/pipeline/GROFF_to_printable b/pipeline/GROFF_to_printable @@ -0,0 +1,3 @@ +#!/bin/sh + +groff -k -Tutf8 -t diff --git a/pipeline/JSON_to_GROFF.d b/pipeline/JSON_to_GROFF.d @@ -0,0 +1,61 @@ +import std.stdio; +import std.json; +import std.array; +import std.algorithm; +import std.regex; +import std.format; +import std.conv; +import std.range; +import std.datetime : Clock; + +void main(string[] argv){ + auto str=stdin.byChunk(4096).map!(a=>cast(char[])a).joiner(); + auto j=parseJSON(str); + + string positions(){ + Appender!string app; + app~=".na\n"; + app~=".TS\n"; + "llxri\n".repeat(j["articles"].array.length).copy(app); + app~="===\n"; + app~="lbr\n"; + app~=".\n"; + double total=0; + foreach(ulong ix,art; j["articles"]){ + double price=art["price"].str.to!double; + string name=art["name"].str; + ulong amount=art["amount"].integer; + app.formattedWrite!"%d\tT{\n%s\nT}\t%.2f\n"(amount,name,price); + total+=price * amount; + } + app~="\n"; + app.formattedWrite("\tTOTAL\t%.2f\n", total); + app~=".TE\n"; + app~=".al\n"; + return app.data; + } + string delegate()[string] tbl=[ + "sale_id": (){return j["sale_id"].integer.to!string;}, + "positions": &positions, + "today": (){return Clock.currTime.toISOExtString();}, + ]; + auto lookup(Captures!(char[]) cap){ + auto b=cap[1]; + auto fct=b in tbl; + if(!fct){ + return "{{"~b~"}}"; + } + else{ + return cast(const(char)[])(*fct)(); + } + } + File tmplate=File(argv[1], "r"); + scope(exit)tmplate.close(); + auto reg=ctRegex!("\\{\\{([^}]+)\\}\\}"); + auto sink=stdout.lockingTextWriter; + + foreach(line; tmplate.byLine(KeepTerminator.yes)){ + replaceAllInto!(lookup)(sink, line, reg); + } + +} diff --git a/pipeline/print b/pipeline/print @@ -0,0 +1,3 @@ +#!/bin/sh + +cat diff --git a/template.roff b/template.roff @@ -0,0 +1,61 @@ +.ll 7.9c-0.4c +.po 0.2c +\" Inifinte Page definitions +. de1 ne +. ie \\n[.$] \ +. nr an-ne (v;\\$*) +. el \ +. nr an-ne 1v +. if (\\n[an-ne] >= \\n[.t]) \ +. pl +(\\n[an-ne]u - \\n[.t]u + 1v) +. . +. +. rn bp an-bp +. de1 bp +. br +. pl \\n[nl]u +. an-bp \\$* +. . +.de1 an-end +. nr % 1 +. fl +. pl \\n[nl]u +.. +.em an-end +\" Done with infinipage +. +.ft CR +.br + ____ +.br + / __ ) +.br + / __ | +.br + / /_/ / +.br +/_____/ +.br + +RECEIPT + +{{positions}} + +AMIV an der ETH +.br +BASTLI +.br +CAB E38 +.br +Universitätsstrasse 6 +.br +8004 Zürich +.br +044 632 49 41 +.br +Sales ID: {{sale_id}} +.br +{{today}} +.br +.pl 0c +\n[.p]