]> git.plutz.net Git - invoices/commitdiff
introduce status tag to see whether invoice has already been sent, or paid, etc.
authorPaul Hänsch <paul@plutz.net>
Wed, 10 Jul 2019 22:02:28 +0000 (00:02 +0200)
committerPaul Hänsch <paul@plutz.net>
Wed, 10 Jul 2019 22:02:28 +0000 (00:02 +0200)
invoices.cgi
invoices.css
invoices.sh

index 464d2849ed44d9d4a4247301f0adbd1101a0ed00..bec02be117a48964f1a14c5b2ddb17bd3f5973ab 100755 (executable)
@@ -70,8 +70,8 @@ case $info in
     ;;
   /invoices)
     . "$_EXEC/invoices.sh"
-    { list_invoices
-      printf '[a .new href="/invoices/%s" New]' "$(timeid)"
+    { printf '[a .new href="/invoices/%s" New]' "$(timeid)"
+      list_invoices
     } | yield_page invoices
     ;;
   /invoices/*)
index 41cea2d6aee02c355e154b8bbd03a79e04c26da8..592fb5526f0847fc6783aa53bc4ceea4e7b5c734 100755 (executable)
@@ -12,6 +12,13 @@ body {
 strong {font-weight: bold;}
 em {text-decoration: italic;}
 
+h1 {
+  display: block;
+  margin: 1em 1em 0 1em;
+  font-weight: bold;
+  border-bottom: 1px solid #08F;
+}
+
 /* ==================== MENU ==================== */
 
 #menu {
index b97c6e79db6c5c9ba8a1a0dd10dd3ec054fae3ff..f8dbf8514dfb97bc2bb957b604ff0ff0242858ca 100755 (executable)
@@ -23,59 +23,90 @@ client_list(){
 }
 
 list_invoices(){
+  [ -d invoices/ ] || return 0
+
+  printf '[h1 Open]'
+  for i in invoices/*; do case "$(line <$i)" in
+    *status=open*) list_invoice "$i";;
+    *status=*) :;;
+    *) list_invoice "$i";;
+  esac; done
+
+  for n in resent:Resent sent:Sent paid:Paid cancelled:Cancelled; do
+    printf '[h1 %s]' "${n#*:}"
+    for i in invoices/*; do case "$(line <$i)" in
+      *status=${n%:*}*) list_invoice "$i";;
+    esac; done
+  done
+}
+
+list_invoice(){
+  local i="$1"
   local sender client date number vat vatrate iban bic hourly \
-        taxtype nett tax gross total
+        taxtype nett tax gross total status
 
-  [ -d invoices/ ] && for i in invoices/*; do
-    read -r sender client date number vat vatrate hourly x<<-EOF
+  read -r sender client date number vat vatrate hourly status x<<-EOF
        $(sed q "$i")
        EOF
 
-    [ ! -f "senders/${sender#sender=}" ] \
-    && sender="(unset)" \
-    || read -r sender iban bic x<"senders/${sender#sender=}"
+  [ ! -f "senders/${sender#sender=}" ] \
+  && sender="(unset)" \
+  || read -r sender iban bic x<"senders/${sender#sender=}"
 
-    [ ! -f "clients/${client#client=}" ] \
-    && client="(unset)" \
-    || read -r client hourly x<"clients/${client#client=}"
+  [ ! -f "clients/${client#client=}" ] \
+  && client="(unset)" \
+  || read -r client hourly x<"clients/${client#client=}"
 
-    [ "${date#date=}" -ge 0 ] 2>&- \
-    && date="$(date -d "@${date#date=}" +%x)" \
-    || date="(unset)"
+  [ "${date#date=}" -ge 0 ] 2>&- \
+  && date="$(date -d "@${date#date=}" +%x)" \
+  || date="(unset)"
 
-    read -r taxtype nett tax gross x<<-EOF
+  read -r taxtype nett tax gross x<<-EOF
        $(invoice_total "${i#invoices/}")
        EOF
-    case $taxtype in
-      nett)  total="${nett} € + VAT";;
-      gross) total="${gross} € incl. VAT";;
-      *) total="${gross} €";;
-    esac
-
-    printf '[div .invoice
-      [h2
-          %s]
-      [label From:] %s [label To:] %s [label on] %s
-      [label Amount:] %s
-      [a href="/invoices/%s" Edit]
-    ]' "$(UNSTRING "${number#number=}" |HTML)" \
-       "$(UNSTRING "${sender#address=}" |sed q |HTML)" \
-       "$(UNSTRING "${client#address=}" |sed q |HTML)" "$(HTML "$date")" \
-       "$total" \
-       "$(HTML ${i#invoices/})"
-  done
+  case $taxtype in
+    nett)  total="${nett} € + VAT";;
+    gross) total="${gross} € incl. VAT";;
+    *) total="${gross} €";;
+  esac
+
+  case $status in
+    status=sent|status=resent|status=paid|status=cancelled)
+      status="${status#status=}"
+    ;;
+    *) status=open;;
+  esac
+
+  printf '[div .invoice
+    [h2
+        %s]
+    [label From:] %s [label To:] %s [label on] %s
+    [label Amount:] %s
+    [a href="/invoices/%s" Edit]
+  ]' "$(UNSTRING "${number#number=}" |HTML)" \
+     "$(UNSTRING "${sender#address=}" |sed q |HTML)" \
+     "$(UNSTRING "${client#address=}" |sed q |HTML)" "$(HTML "$date")" \
+     "$total" \
+     "$(HTML ${i#invoices/})"
 }
 
 edit_invoice(){
   local id="$1" sender client date number vat vatrate caddress hourly \
-        taxtype nett tax gross
+        taxtype nett tax gross status
 
   if [ -f "invoices/$id" ]; then
-    read -r sender client date number vat vatrate hourly x<<-EOF
+    read -r sender client date number vat vatrate hourly status x<<-EOF
        $(sed q "invoices/$id")
        EOF
   fi
 
+  case $status in
+    status=sent|status=resent|status=paid|status=cancelled)
+      status="${status#status=}"
+    ;;
+    *) status=open;;
+  esac
+
   [ "${date#date=}" -ge 0 ] 2>&- \
   && date="$(date -d "@${date#date=}" +%F)" \
   || date="$(date +%F)"
@@ -159,6 +190,13 @@ $({ sed 1d "invoices/$id"; printf 'time= work= hours=\n'; } \
             esac)
             ]]
          ]
+          [select name=status
+             [option value=open      $( [ $status = open      ] && printf selected=selected ) Open]
+             [option value=sent      $( [ $status = sent      ] && printf selected=selected ) Sent]
+             [option value=resent    $( [ $status = resent    ] && printf selected=selected ) Resent]
+             [option value=paid      $( [ $status = paid      ] && printf selected=selected ) Paid]
+             [option value=cancelled $( [ $status = cancelled ] && printf selected=selected ) Cancelled]
+          ]
          [submit "genpdf" "$tid" Export PDF]
          [submit "update" "$tid" Update]
        ]
@@ -224,13 +262,14 @@ update_invoice(){
       [ "$n" -gt "$extra" ] && extra="$n"
     done
 
-    { printf 'sender=%s        client=%s       date=%s number=%s       vat=%s  vatrate=%s      hourly=%s\n' \
+    { printf 'sender=%s        client=%s       date=%s number=%s       vat=%s  vatrate=%s      hourly=%s       status=%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]+')" \
-        "$(POST hourly |grep -m1 -xE '[0-9]+')"
+        "$(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' \
           "$(POST time $n |STRING)" "$(POST work $n |STRING)" \