- printf 'sender=%s client=%s date=%s number=%s vat=%s vatrate=%s\n' \
- "$(POST sender)" "$(POST client)" \
- "$(date -d "$(POST date)" +%s)" \
- "$(POST number |STRING)" \
- "$(POST vat |grep -m1 -xE 'smallbusiness|gross|nett')" \
- "$(POST vatrate |grep -m1 -xE '[0-9]+')" \
- >"invoices/$id"
+
+ for n in "$(POST_COUNT time)" "$(POST_COUNT work)" "$(POST_COUNT hours)"; do
+ [ "$n" -gt "$extra" ] && extra="$n"
+ done
+
+ { printf 'sender=%s client=%s date=%s number=%s vat=%s vatrate=%s\n' \
+ "$(POST sender)" "$(POST client)" \
+ "$(date -d "$(POST date)" +%s)" \
+ "$(POST number |STRING)" \
+ "$(POST vat |grep -m1 -xE 'smallbusiness|gross|nett')" \
+ "$(POST vatrate |grep -m1 -xE '[0-9]+')"
+ for n in $(seq 1 $extra); do
+ printf 'time=%s work=%s hours=%s\n' \
+ "$(POST time $n |STRING)" "$(POST work $n |STRING)" \
+ "$(POST hours $n |STRING)" \
+ | grep -xvF 'time= work= hours=0'
+ done
+ } >"invoices/$id"