ref: f3cb4b36831e141994b9508139f6c2e4d69ebbe6
parent: 3b8c26ceaf773a1dcb3b3abf1be53895de7b9911
author: sirjofri <sirjofri@sirjofri.de>
date: Tue Sep 2 10:37:39 EDT 2025
adds shorthand support
--- a/README
+++ b/README
@@ -54,6 +54,7 @@
---------------------
- addr: address lines for that client
+- short: short name which will be included in the invoice ID
- msg: (optional) letter message. If this does not exist, it uses the template/name.msg. Can be overridden by a invoice/msg file.
- vcard.vcf: vcard file with contact info (TBD)
--- a/bin/buildinvoice.rc
+++ b/bin/buildinvoice.rc
@@ -27,6 +27,10 @@
# client info
cl=`{cat invoice/$1/client}cl=$cl(1)
+if (~ $#cl 0) {+ echo Skipping $1: no client >[1=2]
+ exit 'skip'
+}
cp client/$cl/addr /tmp/client_addr.tmp
test -f client/$cl/msg && cp client/$cl/msg /tmp/msg.tmp
--- a/bin/mkinvoice
+++ b/bin/mkinvoice
@@ -1,30 +1,47 @@
#!/bin/rc
+if (~ $#* 0) {+ echo usage: mkinvoice client >[1=2]
+ exit usage
+}
+
rfork en
+client=`{ basename `{echo $"1 | sed 's:/$::g'} }+
+short=`{cat client/$client/short}+if (~ $#short 0) {+ echo client $1 not found >[1=2]
+ exit error
+}
+
+year=`{date -f YYYY}+
parts=`{cd invoice
walk -d -n1 | awk -F '-' '
-NF == 2 {+NF == 3 && $2 == "'^$short^'" {if ($1 > year)
year = $1
- if ($2 > nr)
- nr = $2
+ if ($3 > nr)
+ nr = $3
}
END {- printf "%d\t%d\n", year, nr+1
+ printf "%d\n", nr+1
}
'}
-id=`{echo $parts(1)^-^$parts(2)}+id=`{echo $year^-^$short^-^$parts(1)}mkdir invoice/$id
touch invoice/$id/^(data.tsv client date msg template)
+echo $client > invoice/$id/client
+
cat <<EOF >invoice/$id/msg
Invoice number \*(iv
.LP
-Hi, here's the invoice:
+Hi, here's the invoice for WORK I did WHEN:
.LP
.IV
.LP
@@ -38,4 +55,4 @@
echo 'default' >invoice/$id/template
date -n >invoice/$id/date
-echo $id
+echo invoice/$id/msg invoice/$id/data.tsv
--- a/bin/test/vmissingfiles
+++ b/bin/test/vmissingfiles
@@ -27,6 +27,7 @@
clients=`{cd client; walk -d -n 1} for (c in $clients) {testfile client/$c/addr
+ testfile client/$c/short
testfileo client/$c/msg
testfileo client/$c/vcard.vcf
}
--
⑨