shithub: rech

ref: f3cb4b36831e141994b9508139f6c2e4d69ebbe6
dir: /bin/mkinvoice/

View raw version
#!/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 == 3 && $2 == "'^$short^'" {
	if ($1 > year)
		year = $1
	if ($3 > nr)
		nr = $3
}
END {
	printf "%d\n", nr+1
}
'}

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 for WORK I did WHEN:
.LP
.IV
.LP
Have a nice day!
EOF

cat <<EOF >invoice/$id/data.tsv
# Amount	Price (1)	VAT	Category	Name
EOF

echo 'default' >invoice/$id/template
date -n >invoice/$id/date

echo invoice/$id/msg invoice/$id/data.tsv