]> git.plutz.net Git - invoices/commitdiff
switch from work hours to pices/price per piece
authorPaul Hänsch <paul@plutz.net>
Wed, 8 Nov 2023 14:24:55 +0000 (15:24 +0100)
committerPaul Hänsch <paul@plutz.net>
Wed, 8 Nov 2023 14:24:55 +0000 (15:24 +0100)
invoices.sh

index 9ed6dfa56388fb2822d3c4129b2212e9c2ae12ac..6bbe5b553bc33d77be54957ceafba43ae56079c5 100755 (executable)
@@ -152,6 +152,7 @@ edit_invoice(){
          [label for=date Date:]
          [input #date name=date value="${date}" placeholder="YYYY-MM-TT"]
        
+         <!--
          [label for=hourly Hourly Rate:]
          [input #hourly type=number name=hourly value="${hourly}"]
 
@@ -162,24 +163,24 @@ edit_invoice(){
          [radio "vat" "gross" #vatgross $([ "${vat#vat=}" = gross ] && printf checked)]
          [label for=vatgross Gross]
          [label for=vatrate VAT Rate: [input type=number name="vatrate" value="${vatrate}"]% ]
+         -->
        
          [table
-           [tr [th Date] [th Work] [th Hours] [th Price] ]
+           [tr [th Stück] [th Leistung] [th Stückpreis] [th Summe] ]
 $({ sed 1d "invoices/$id"; printf 'time= work= hours=\n'; } \
-  | while read -r time work hours x; do
-    hours="$(UNSTRING "${hours#hours=}" \
-             |grep -m1 -xE '\.[0-9]+|[0-9]+\.?[0-9]*' || printf 0)"
+  | while read -r time work hours pcs ppp x; do
+    pcs="$(UNSTRING "${pcs#pcs=}" \
+           |grep -m1 -xE '[0-9]+' || printf 1)"
+    ppp="$(UNSTRING "${ppp#ppp=}" \
+           |grep -m1 -xE '-?(\.[0-9]+|[0-9]+\.?[0-9]*)' || printf 0)"
     printf '[tr
-            [td [textarea name=time
-%s] ]
+            [td [input type=number name=pieces value="%i" step=1] ]
             [td [textarea name=work
 %s] ]
-            [td [input type=number name=hours value="%g" step=any] ]
+            [td [input type=number name=price value="%g" step=any] ]
             [td %s]
-   ]' "$(UNSTRING "${time#time=}" |HTML)" \
-      "$(UNSTRING "${work#work=}" |HTML)" \
-      "$hours" \
-      "$(awk "BEGIN { printf \"%.2f €\", ${hours} * ${hourly}; }")"
+   ]' "$pcs" "$(UNSTRING "${work#work=}" |HTML)" "$ppp" \
+      "$(awk "BEGIN { printf \"%.2f €\", ${pcs} * ${ppp}; }")"
   done
 )
             [tr [td colspan=4 
@@ -214,19 +215,17 @@ invoice_total(){
        $(sed q "invoices/$id")
        EOF
 
-    [ "${hourly#hourly=}" -gt 0 ] 2>&- \
-    && hourly="${hourly#hourly=}" \
-    || hourly=0
     [ "${vatrate#vatrate=}" -ge 0 ] 2>&- \
     && vatrate="${vatrate#vatrate=}" \
     || vatrate=19
 
     sed 1d "invoices/$id" \
-    | { while read -r time work hours; do
-        [ "${hours#hours=}" ] 2>&- \
-        && hours="${hours#hours=}" \
-        || hours=0
-        total=$(awk "BEGIN { printf \"%.2f\", ${total} + ${hours} * ${hourly}; }")
+    | { while read -r time work hours pcs ppp; do
+        pcs="$(UNSTRING "${pcs#pcs=}" \
+               |grep -m1 -xE '[0-9]+' || printf 1)"
+        ppp="$(UNSTRING "${ppp#ppp=}" \
+               |grep -m1 -xE '-?(\.[0-9]+|[0-9]+\.?[0-9]*)' || printf 0)"
+        total=$(awk "BEGIN { printf \"%.2f\", ${total} + ${pcs} * ${ppp}; }")
       done
       case $vat in
         vat=nett)
@@ -260,7 +259,7 @@ update_invoice(){
   if [ "$(POST update)" = "$tid" ] || [ "$(POST genpdf)" = "$tid" ]; then
     mkdir -p invoices
 
-    for n in "$(POST_COUNT time)" "$(POST_COUNT work)" "$(POST_COUNT hours)"; do
+    for n in "$(POST_COUNT time)" "$(POST_COUNT work)" "$(POST_COUNT hours)" "$(POST_COUNT pieces)" "$(POST_COUNT price)"; do
       [ "$n" -gt "$extra" ] && extra="$n"
     done
 
@@ -273,10 +272,11 @@ update_invoice(){
         "$(POST hourly |grep -m1 -xE '[0-9]+')" \
         "$(POST status |grep -m1 -xE 'open|sent|resent|paid|cancelled')"
       for n in $(seq 1 $extra); do
-        printf 'time=%s        work=%s hours=%s\n' \
+        printf 'time=%s        work=%s hours=%s pcs=%s ppp=%s\n' \
           "$(POST time $n |STRING)" "$(POST work $n |STRING)" \
           "$(POST hours $n |STRING)" \
-        | grep -xvF 'time=\    work=\  hours=0'
+          "$(POST pieces $n |STRING)" "$(POST price $n |STRING)" \
+        | grep -xvF 'time=\    work=\  hours=0 pcs=1   ppp=0'
       done
     } >"invoices/$id"