]> git.plutz.net Git - invoices/commitdiff
calculation table in invoice
authorPaul Hänsch <paul@plutz.net>
Tue, 20 Nov 2018 15:25:18 +0000 (16:25 +0100)
committerPaul Hänsch <paul@plutz.net>
Tue, 20 Nov 2018 15:25:18 +0000 (16:25 +0100)
invoices.css
invoices.sh

index 482984d8857804a43c8751115c354be3c36fe8db..291b847b4f932d18be671e2307d9ddb5b27dadae 100755 (executable)
@@ -189,15 +189,15 @@ form input[type=number] {
 .invoice form table tr > th:nth-child(4) {
   text-align: right;
 }
 .invoice form table tr > th:nth-child(4) {
   text-align: right;
 }
-.invoice form table tr > :nth-child(1) { width: 6em; }
-.invoice form table tr > :nth-child(2) { width: 12em; }
-.invoice form table tr > :nth-child(3) { width: 6em; }
-.invoice form table tr > :nth-child(4) { width: 6em; }
+.invoice form table tr > :nth-child(1) { width: 7em; }
+.invoice form table tr > :nth-child(2) { width: 15em; }
+.invoice form table tr > :nth-child(3) { width: 4em; }
+.invoice form table tr > :nth-child(4) { width: 4em; }
 .invoice form table tr > * textarea,
 .invoice form table tr > * input[type=number],
 .invoice form table tr > * input {
   display: block;
   font-size: 12pt;
   width: 100%; height: 100%;
 .invoice form table tr > * textarea,
 .invoice form table tr > * input[type=number],
 .invoice form table tr > * input {
   display: block;
   font-size: 12pt;
   width: 100%; height: 100%;
-  height: 4em;
+  height: 4.625em;
 }
 }
index 0e801157c4917249c9669cd69dd996021e17b2cd..a38693298d9c3c235ad9d14c5840dfca7c5f8749 100755 (executable)
@@ -40,7 +40,7 @@ list_invoices(){
       [h2
           %s]
       [label From:] %s [label To:] %s [label on] %s
       [h2
           %s]
       [label From:] %s [label To:] %s [label on] %s
-      [a href="/invoice/%s" Edit]
+      [a href="/invoices/%s" Edit]
     ]' "$(UNSTRING "${number#number=}" |HTML)" \
        "$(HTML "$sender")" \
        "$(UNSTRING "${client#address=}" |sed q |HTML)" "$(HTML "$date")" \
     ]' "$(UNSTRING "${number#number=}" |HTML)" \
        "$(HTML "$sender")" \
        "$(UNSTRING "${client#address=}" |sed q |HTML)" "$(HTML "$date")" \
@@ -49,7 +49,7 @@ list_invoices(){
 }
 
 edit_invoice(){
 }
 
 edit_invoice(){
-  id="$1"
+  local id="$1" sender client date number vat vatrate caddress hourly
   if [ -f "invoices/$id" ]; then
     read -r sender client date number vat vatrate<<-EOF
        $(sed q "invoices/$id")
   if [ -f "invoices/$id" ]; then
     read -r sender client date number vat vatrate<<-EOF
        $(sed q "invoices/$id")
@@ -62,41 +62,45 @@ edit_invoice(){
   [ "${number#number=}" ] || number="number=$(date +%s)"
   [ "${vatrate#vatrate=}" -ge 0 ] 2>&- || vatrate="vatrate=19"
 
   [ "${number#number=}" ] || number="number=$(date +%s)"
   [ "${vatrate#vatrate=}" -ge 0 ] 2>&- || vatrate="vatrate=19"
 
+  [ -f "clients/${client#client=}" ] \
+  && read -r caddress hourly <"clients/${client#client=}"
+  hourly="${hourly#hourly=}"
+
   cat <<-EOF 
        [form method="POST" action="/update_invoice"
          [hidden "id" "$(HTML "$id")"]
   cat <<-EOF 
        [form method="POST" action="/update_invoice"
          [hidden "id" "$(HTML "$id")"]
-
+       
          [label Sender:]
          [select name=sender
            $(sender_list "${sender#sender=}")
          ]
          [label Sender:]
          [select name=sender
            $(sender_list "${sender#sender=}")
          ]
-
+       
          [label Client:]
          [select name=client
            $(client_list "${client#client=}")
          ]
        
          [label Client:]
          [select name=client
            $(client_list "${client#client=}")
          ]
        
-          [label for=number Invoice Number:]
-          [input #number name=number value="$(UNSTRING "${number#number=}" |HTML)"]
-
-          [label for=date Date:]
-          [input #date name=date value="${date}" placeholder="YYYY-MM-TT"]
-
-          [radio "vat" "smallbusiness" #vatsb $([ "${vat#vat=}" = smallbusiness ] && printf checked) ]
-          [label for=vatsb Small business exemption from VAT]
-          [radio "vat" "nett" #vatnett $([ "${vat#vat=}" = nett ] && printf checked)]
-          [label for=vatnett Nett]
-          [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#vatrate=}"]% ]
-
-          [table
-            [tr [th Date] [th Work] [th Hours] [th Price] ]
+         [label for=number Invoice Number:]
+         [input #number name=number value="$(UNSTRING "${number#number=}" |HTML)"]
+       
+         [label for=date Date:]
+         [input #date name=date value="${date}" placeholder="YYYY-MM-TT"]
+       
+         [radio "vat" "smallbusiness" #vatsb $([ "${vat#vat=}" = smallbusiness ] && printf checked) ]
+         [label for=vatsb Small business exemption from VAT]
+         [radio "vat" "nett" #vatnett $([ "${vat#vat=}" = nett ] && printf checked)]
+         [label for=vatnett Nett]
+         [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#vatrate=}"]% ]
+       
+         [table
+           [tr [th Date] [th Work] [th Hours] [th Price] ]
 $({ sed 1d "invoices/$id"; printf 'time= work= hours=\n'; } \
     | while read -r time work hours; do
       hours="$(UNSTRING "${hours#hours=}" |grep -m1 -xE '[0-9]+' || printf 0)"
       printf '[tr
 $({ sed 1d "invoices/$id"; printf 'time= work= hours=\n'; } \
     | while read -r time work hours; do
       hours="$(UNSTRING "${hours#hours=}" |grep -m1 -xE '[0-9]+' || printf 0)"
       printf '[tr
-              [td [textarea name=date
+              [td [textarea name=time
 %s] ]
               [td [textarea name=work
 %s] ]
 %s] ]
               [td [textarea name=work
 %s] ]
@@ -107,22 +111,35 @@ $({ sed 1d "invoices/$id"; printf 'time= work= hours=\n'; } \
         "$hours" "$((hours * hourly)) €"
     done
 )
         "$hours" "$((hours * hourly)) €"
     done
 )
-          ]
-         [submit "update" "update" Update]
+         ]
+         [submit "update" "$(tid "invoices/$id")" Update]
        ]
        EOF
 }
 
 update_invoice(){
        ]
        EOF
 }
 
 update_invoice(){
-  id="$(POST id |checkid)"
-  if [ "$(POST update)" = update -a "$id" ]; then
+  local id="$(POST id |checkid)" extra=0
+
+  if [ "$(POST update)" = "$(tid "invoices/$id")" ]; then
     mkdir -p invoices
     mkdir -p invoices
-    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"
   fi
   fi
+  REDIRECT "/invoices/$id"
 }
 }