]> git.plutz.net Git - invoices/blobdiff - senders.sh
sort invoice list, newest to oldest
[invoices] / senders.sh
index 4d1f6121661d56c79f81ec5e1d563dc470d5cb94..757ce22e1aeaa55a54c3374525ce2e1eb60787ac 100755 (executable)
@@ -1,11 +1,16 @@
 #!/bin/sh
 
 edit_sender(){
-  id="$1"
-  if [ -f "senders/$id" ]; then
-    address="$(cat "senders/$id")"
-  fi
-  [ "$address" ] || address="Name
+  local id="$1" address iban bic
+  [ -f "senders/$id" ] \
+  && read -r address iban bic <"senders/$id"
+
+  iban="$(UNSTRING "${iban#iban=}")"
+   bic="$(UNSTRING "${bic#bic=}")"
+
+  [ "${address#address=}" ] \
+  && address="$(UNSTRING "${address#address=}")" \
+  || address="Name
 Street
 City
 
@@ -19,17 +24,23 @@ xxx / 000 / ###
     [form method="POST" action="/update_sender"
       [hidden "id" "%s"]
       <textarea name="address" placeholder="address">%s</textarea>
+      [label IBAN:][input name=iban value="%s" placeholder=IBAN]
+      [label BIC:][input name=bic value="%s" placeholder=BIC]
       [submit "update" "%s" Update]
     ]' \
-    "$(HTML $id)" \
-    "$(HTML "${address}")" \
-    "$(tid "senders/$id")"
+    "$(HTML $id)" "$(HTML "${address}")" \
+    "$(HTML "${iban}")" "$(HTML "${bic}")" \
+    "$(transid "senders/$id")"
 }
 
 list_senders(){
   [ -d senders/ ] && for s in senders/*; do
-    address=$(cat "$s")
-    [ "$address" ] || address="(no address)"
+    read -r address iban bic <"$s"
+
+    [ "${address#address=}" ] \
+    && address="$(UNSTRING "${address#address=}")" \
+    || address="(no address)"
+
     printf '[div .sender .address <!--
       -->%s[a href="/senders/%s" Edit]]
     ' "$(HTML "$address")" "$(HTML "${s#senders/}")"
@@ -38,9 +49,17 @@ list_senders(){
 
 update_sender(){
   id="$(POST id |checkid)"
-  if [ "$(POST update)" = "$(tid "senders/$id")" ]; then
+  if [ "$(POST update)" = "$(transid "senders/$id")" ]; then
     mkdir -p senders
-    POST address >"senders/$id"
+    printf 'address=%s iban=%s bic=%s\n' \
+    $(POST address |STRING) $(POST iban |STRING) \
+    $(POST bic |STRING) >"senders/$id"
+
+    [ -d .git ] && {
+      git add "senders/$id"
+      git commit -m 'Update sender info for "'"$(POST address |sed 1q)"'"' -- "senders/$id"
+    } >/dev/null
+
     REDIRECT "/senders/"
   else
     REDIRECT "/senders/$id"