]> git.plutz.net Git - invoices/blobdiff - clients.sh
sort invoice list, newest to oldest
[invoices] / clients.sh
index fc047a2447aad54669b64e3f927631785b7aa628..052a0c84c897f82a38bbe4b82ad7b86f285442be 100755 (executable)
@@ -14,11 +14,12 @@ edit_client(){
 %s</textarea>
       [label for=hourly Hourly Rate:]
       [input #hourly type=number name=hourly value="%s"]
-      [submit "update" "update" Update]
+      [submit "update" "%s" Update]
     ]' \
     "$(HTML $id)" \
     "$(UNSTRING "${address#address=}" |HTML)" \
-    "$(UNSTRING "${hourly#hourly=}" |grep -xE '[0-9]+')"
+    "$(UNSTRING "${hourly#hourly=}" |grep -xE '[0-9]+')" \
+    "$(transid "clients/$id")"
 }
 
 list_clients(){
@@ -38,13 +39,21 @@ list_clients(){
 }
 
 update_client(){
-  id="$(POST id |checkid)"
-  if [ "$(POST update)" = update -a "$id" ]; then
+  local id="$(POST id |checkid)"
+  if [ "$(POST update)" = "$(transid "clients/$id")" ]; then
     mkdir -p clients
     printf 'address=%s hourly=%s' \
       "$(POST address |STRING)" "$(POST hourly |STRING)" \
       >"clients/$id"
+
+    [ -d .git ] && {
+      git add "clients/$id"
+      git commit -m 'Update client info for "'"$(POST address |sed 1q)"'"' -- "clients/$id"
+    } >/dev/null
+
+    REDIRECT "/clients/"
   else
-    echo Invalid Data "$(POST id)" "$(POST update)" >&2
+    error Invalid Data "$id" "$(POST update)"
+    REDIRECT "/clients/$1"
   fi
 }