shithub: rech

Download patch

ref: 521aed03530e987473d55abd50dfb263e1473181
parent: 7f6ff00b80a487acc913327b33dc2e977add72f2
author: sirjofri <sirjofri@sirjofri.de>
date: Thu Aug 14 07:44:28 EDT 2025

adds balance variables

--- a/README
+++ b/README
@@ -3,11 +3,13 @@
 - all: test and build everything
 - test: run some tests
 - invoices: build invoices
+- balance: generate balance.pdf
 
 
 FOLDERS
 
 - /bin contains helper scripts that don't fit into the mkfile
+- /lib contains additional template files for use in other scripts
 - /client contains all clients and their information
 - /invoice contains all invoices
 - /template contains all invoice templates
@@ -56,7 +58,7 @@
 - vcard.vcf: vcard file with contact info (TBD)
 
 
-INDIVIDUAL FILES
+INDIVIDUAL INVOICE FILES
 
 
 The message file (msg):
@@ -69,8 +71,8 @@
 - These macros can also be used in template files
 
 
-The data.tsv file:
-------------------
+The invoice data.tsv file:
+--------------------------
 
 - tab separated values
 - lines that start with '#' are comments
@@ -82,3 +84,20 @@
 
 - troff format, no fill (newlines are newlines)
 - Address like on an envelope
+
+
+BALANCE GENERATION
+
+balance collects all the data in the invoice, in, and out folders.
+
+- invoice  → self-explanatory
+- in       → other sources of income, e.g. from stores
+- out      → purchases, etc.
+
+It uses the following additional files for generation:
+
+- lib/balance_hdr.ms → header troff source (optional)
+- lib/balance_ftr.ms → footer troff source (optional)
+- lib/balance.sed → sed string replacements of troff source
+
+Use the balance.sed file to also manage category names and so on.
--- a/bin/balance
+++ b/bin/balance
@@ -21,7 +21,7 @@
 	for (i in vats) {
 		if (i == 0)
 			continue;
-		printf "USt.%d\t%.2f\n", i, vats[i] * i / 100.
+		printf "##VAT.%d##\t%.2f\n", i, vats[i] * i / 100.
 	}
 }
 ' > /tmp/invoices
@@ -42,7 +42,7 @@
 		printf "%s\t%.2f\n", c, cats[c]
 	}
 	for (v in vats) {
-		printf "USt.%d\t%.2f\n", v, vats[v] * v / 100.
+		printf "##VAT.%d##\t%.2f\n", v, vats[v] * v / 100.
 	}
 }
 ' > /tmp/in
@@ -82,15 +82,17 @@
 		total += cats[c]
 	}
 	print "_"
-	printf "Summe\t%.2f EUR\n", total
+	printf "##SUM##\t%.2f EUR\n", total
 }'
 
+test -r lib/balance_hdr.ms && cat lib/balance_hdr.ms
+
 echo '.TS
 expand linesize(5);
 l s
 l n .
 _
-\fBBetriebseinnahmen\fR
+\fB##TITLE_IN##\fR
 _'
 
 
@@ -101,7 +103,7 @@
 l s
 l n .
 =
-\fBBetriebsausgaben\fR
+\fB##TITLE_OUT##\fR
 _'
 
 # Ausgaben
@@ -111,7 +113,7 @@
 l s
 l n .
 =
-\fBErgebnis\fR
+\fB##SUMMARY##\fR
 _'
 
 # Ergebnis
@@ -123,11 +125,13 @@
 		totalin += $2
 }
 END {
-	printf "Gesamteinnahmen\t%.2f EUR\n", totalin
-	printf "Gesamtausgaben\t%.2f EUR\n", totalout
-	printf "\\fBGewinn vor Steuern\\fR\t\\fB%.2f EUR\\fR\n", totalin + totalout
+	printf "##TOTAL_IN##\t%.2f EUR\n", totalin
+	printf "##TOTAL_OUT##\t%.2f EUR\n", totalout
+	printf "\\fB##TOTAL_PROFIT_NOTAX##\\fR\t\\fB%.2f EUR\\fR\n", totalin + totalout
 }
 '
 
 echo '_
 .TE'
+
+test -r lib/balance_ftr.ms && cat lib/balance_ftr.ms
--- /dev/null
+++ b/lib/balance.sed
@@ -1,0 +1,8 @@
+s:##VAT\.([0-9]+)##:Umsatzsteuer \1%:g
+s:##SUM##:Summe:g
+s:##TOTAL_IN##:Gesamteinnahmen:g
+s:##TOTAL_OUT##:Gesamtausgaben:g
+s:##TOTAL_PROFIT_NOTAX##:Gewinn vor Steuern:g
+s:##TITLE_IN##:Betriebseinnahmen:g
+s:##TITLE_OUT##:Betriebsausgaben:g
+s:##SUMMARY##:Ergebnis:g
--- /dev/null
+++ b/lib/balance_ftr.ms
@@ -1,0 +1,3 @@
+.
+.LP
+That's it.
--- /dev/null
+++ b/lib/balance_hdr.ms
@@ -1,0 +1,8 @@
+.TL
+Balance
+.
+.LP
+.ce 1
+Generated: \n(dy.\n(mo.\n(yr
+.
+.LP
--- a/mkfile
+++ b/mkfile
@@ -11,7 +11,7 @@
 balance:VQ: balance.pdf
 
 balance.pdf:VQ:
-	bin/balance | tbl | troff -ms | lp -dstdout | ps2pdf > $target
+	bin/balance | sed -f lib/balance.sed | tbl | troff -ms | lp -dstdout | ps2pdf > $target
 	echo '√' balance.pdf
 
 invoices:VQ: $targets
--