]> git.plutz.net Git - invoices/commitdiff
support for fractional work hours
authorPaul Hänsch <paul@plutz.net>
Wed, 8 Sep 2021 16:28:16 +0000 (18:28 +0200)
committerPaul Hänsch <paul@plutz.net>
Wed, 8 Sep 2021 16:28:16 +0000 (18:28 +0200)
invoices.sh
odtgen.sh

index a88bc7fc59fc663892f198b92946407566f2f2cb..a1ec2339be82ce4e994d215282a221b5fe01b663 100755 (executable)
@@ -167,17 +167,19 @@ edit_invoice(){
            [tr [th Date] [th Work] [th Hours] [th Price] ]
 $({ 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]+' || printf 0)"
+    hours="$(UNSTRING "${hours#hours=}" \
+             |grep -m1 -xE '\.[0-9]+|[0-9]+\.?[0-9]*' || printf 0)"
     printf '[tr
             [td [textarea name=time
 %s] ]
             [td [textarea name=work
 %s] ]
-            [td [input type=number name=hours value="%s"] ]
+            [td [input type=number name=hours value="%.2g" step=any] ]
             [td %s]
    ]' "$(UNSTRING "${time#time=}" |HTML)" \
       "$(UNSTRING "${work#work=}" |HTML)" \
-      "$hours" "$((hours * hourly)) €"
+      "$hours" \
+      "$(awk "BEGIN { printf \"%.2f €\", ${hours} * ${hourly}; }")"
   done
 )
             [tr [td colspan=4 
@@ -221,10 +223,10 @@ invoice_total(){
 
     sed 1d "invoices/$id" \
     | { while read -r time work hours; do
-        [ "${hours#hours=}" -gt 0 ] 2>&- \
+        [ "${hours#hours=}" ] 2>&- \
         && hours="${hours#hours=}" \
         || hours=0
-        total=$((total + hours * hourly))
+        total=$(awk "BEGIN { printf \"%.2f\", ${total} + ${hours} * ${hourly}; }")
       done
       case $vat in
         vat=nett)
index 177065a9c9a0fd10f92cba31058aceacc51f1b98..1dfa5e87083d736bdc31035e19f81d7b14e12da0 100755 (executable)
--- a/odtgen.sh
+++ b/odtgen.sh
@@ -190,10 +190,16 @@ odt_content(){
                            <text:p text:style-name="P3">${work}</text:p>
                          </table:table-cell>
                          <table:table-cell table:style-name="Table1.2" office:value-type="string">
-                           <text:p text:style-name="P5">${hours}</text:p>
+                           <text:p text:style-name="P5">$( awk "BEGIN { 
+                                                                 if ( int(${hours}) == ${hours} ) 
+                                                                    printf \"%i\", ${hours};
+                                                                 else
+                                                                    printf \"%i:%i\", int(${hours}), int((${hours} - int(${hours})) * 60);
+                                                                 }"
+                                                           )</text:p>
                          </table:table-cell>
                          <table:table-cell table:style-name="Table1.2" office:value-type="string">
-                           <text:p text:style-name="P5">$((${hourly} * ${hours})) €</text:p>
+                           <text:p text:style-name="P5">$(awk "BEGIN { printf \"%.2f\", ${hourly} * ${hours}; }" ) €</text:p>
                          </table:table-cell>
                        </table:table-row>
                        TROW