From 37080ff784d9601d32068ec552ebe615d32bca63 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Wed, 29 Nov 2023 22:46:22 +0100 Subject: [PATCH] refactoring of data model --- invoices.cgi | 130 +++++++++++++++++++++++---------------------------- 1 file changed, 59 insertions(+), 71 deletions(-) diff --git a/invoices.cgi b/invoices.cgi index 415ac25..bbf85d0 100755 --- a/invoices.cgi +++ b/invoices.cgi @@ -2,93 +2,81 @@ _EXEC="$(realpath "${0%/*}")" . "$_EXEC/cgilite/cgilite.sh" -. "$_EXEC/cgilite/logging.sh" -. "$_EXEC/cgilite/storage.sh" +# . "$_EXEC/cgilite/logging.sh" . "$_EXEC/cgilite/session.sh" +. "$_EXEC/cgilite/storage.sh" +. "$_EXEC/cgilite/file.sh" -SESSION_COOKIE +. "$_EXEC/db23.sh" +. "$_EXEC/form.sh" -yield_page(){ -printf 'Content-Type: text/html; charset=utf-8\r\n\r\n' -"$_EXEC/cgilite/html-sh.sed" <.gitignore - git add clients/ invoices/ senders/ .gitignore - git commit -m 'initialisation of invoice repo' + git add documents/ .gitignore + git commit -m 'initialisation of document repo' } >&2 -case $info in - /invoices.css) - . "$_EXEC/cgilite/file.sh" - FILE "$_EXEC/invoices.css" - ;; - /clients|/clients/) - . "$_EXEC/clients.sh" - { list_clients - printf '[a .new href="/clients/%s" New]' "$(timeid)" - } | yield_page clients - ;; - /clients/*) - . "$_EXEC/clients.sh" - edit_client "${info#/clients/}" |yield_page client +[ "$REQUEST_METHOD" = POST ] && case $(POST action) in + new_invoice) + id="$(timeid)" file="$_DATA/${id}.kvd" + DB3 new + DB3 set type "$(POST type)" + DB3 set status open + DB3 write "$file" + REDIRECT "/doc/${id}" ;; - /update_client) - . "$_EXEC/clients.sh" - update_client + update_invoice) + id="$(POST id)" file="$_DATA/${id}.kvd" seq='' + if [ "$(POST tid)" = "$(transid "$file")" ] && LOCK "$file"; then + DB3 open "$file" + for key in $(POST_KEYS); do case $key in + id|tid|session_key|action):;; + *)set -- + for seq in $(seq 1 "$(POST_COUNT "$key")"); do + set -- "$@" "$(POST "$key" $seq)" + done + DB3 set "$key" "$@" + ;; + esac; done + DB3 write "$file" + RELEASE "$file" + [ -d .git ] && { + git -C "$_DATA" add "$file" + git -C "$_DATA" commit -m 'Update invoice info for "'"${id}"'"' -- "$file" + } >/dev/null + else + debug "TID mismatch updating $file" + fi + REDIRECT "$PATH_INFO" ;; - /senders|/senders/) - . "$_EXEC/senders.sh" - { list_senders - printf '[a .new href="/senders/%s" New]' "$(timeid)" - } | yield_page senders + *) + REDIRECT / ;; - /senders/*) - . "$_EXEC/senders.sh" - edit_sender "${info#/senders/}" |yield_page sender - ;; - /update_sender) - . "$_EXEC/senders.sh" - update_sender - ;; - /invoices|/invoices/) - . "$_EXEC/invoices.sh" - { printf '[a .new href="/invoices/%s" New]' "$(timeid)" - list_invoices - } | yield_page invoices - ;; - /invoices/*) - . "$_EXEC/invoices.sh" - edit_invoice "${info#/invoices/}" |yield_page invoice +esac + +[ "$REQUEST_METHOD" != POST ] && case $PATH_INFO in + *.css|*.jpeg|*.png) + FILE "$_EXEC/${PATH_INFO#/}" ;; - /update_invoice) - . "$_EXEC/invoices.sh" - update_invoice + /) + . "$_EXEC/doclist.sh" ;; - /export/*.pdf/*) - . "$_EXEC/cgilite/file.sh" - file="${info%/*}" - FILE "${file#/}" application/pdf + /doc/*) + id="${PATH_INFO##*/}" tid="$(transid "${_DATA}/${id}.kvd")" + DB3 open "${_DATA}/${id}.kvd" || REDIRECT / + type="$(DB3 get type)" + [ -d "${_EXEC}/${type}/" ] \ + && . "${_EXEC}/${type}/form.sh" + yield_form ;; - *) REDIRECT /invoices + *) REDIRECT / ;; esac -- 2.39.5