]> git.plutz.net Git - invoices/commitdiff
Improved PDF export, hourly rate in invoice
authorPaul Hänsch <paul@plutz.net>
Wed, 28 Nov 2018 15:39:50 +0000 (16:39 +0100)
committerPaul Hänsch <paul@plutz.net>
Wed, 28 Nov 2018 15:39:50 +0000 (16:39 +0100)
invoices.cgi
invoices.sh
odtgen.sh

index 261395f9b417dbc1267de36db383959771c31418..71ab2b1e79a6aa540ec0167c3648ba4e4e7b725e 100755 (executable)
@@ -82,9 +82,10 @@ case $info in
     . "$_EXEC/invoices.sh"
     update_invoice
     ;;
-  /export/*.pdf)
+  /export/*.pdf/*)
     . "$_EXEC/cgilite/file.sh"
-    FILE "${info#/}" application/pdf
+    file="${info%/*}"
+    FILE "${file#/}" application/pdf
     ;;
   *) REDIRECT /invoices
     ;;
index 6538c967945693f7fe8711f4aa56a5f3b7450deb..aa66717c115f641bad3fe58c9365e29a606e8b5f 100755 (executable)
@@ -3,7 +3,7 @@
 sender_list(){
   local select="$1" n name address iban bic
   [ -d senders/ ] && for n in '' senders/*; do
-    [ "$n" ] &&  read -r address iban bic <"$n"
+    [ "$n" ] &&  read -r address iban bic x<"$n"
     name="$(UNSTRING "${address#address=}" |sed q |HTML)"
     [ "${n#senders/}" = "$select" ] \
     && printf '<option value="%s" selected=selected>%s</option>' "${n#senders/}" "$name" \
@@ -14,7 +14,7 @@ sender_list(){
 client_list(){
   local select="$1" n address hourly name
   [ -d clients/ ] && for n in '' clients/*; do
-    [ "$n" ] && read -r address hourly <"$n"
+    [ "$n" ] && read -r address hourly x<"$n"
     name="$(UNSTRING "${address#address=}" |sed q |HTML)"
     [ "${n#clients/}" = "$select" ] \
     && printf '<option value="%s" selected=selected>%s</option>' "${n#clients/}" "$name" \
@@ -27,23 +27,23 @@ list_invoices(){
         taxtype nett tax gross total
 
   [ -d invoices/ ] && for i in invoices/*; do
-    read -r sender client date number vat vatrate<<-EOF
+    read -r sender client date number vat vatrate hourly x<<-EOF
        $(sed q "$i")
        EOF
 
     [ ! -f "senders/${sender#sender=}" ] \
     && sender="(unset)" \
-    || read -r sender iban bic <"senders/${sender#sender=}"
+    || read -r sender iban bic x<"senders/${sender#sender=}"
 
     [ ! -f "clients/${client#client=}" ] \
     && client="(unset)" \
-    || read -r client hourly <"clients/${client#client=}"
+    || read -r client hourly x<"clients/${client#client=}"
 
     [ "${date#date=}" -ge 0 ] 2>&- \
     && date="$(date -d "@${date#date=}" +%x)" \
     || date="(unset)"
 
-    read -r taxtype nett tax gross <<-EOF
+    read -r taxtype nett tax gross x<<-EOF
        $(invoice_total "${i#invoices/}")
        EOF
     case $taxtype in
@@ -71,7 +71,7 @@ edit_invoice(){
         taxtype nett tax gross
 
   if [ -f "invoices/$id" ]; then
-    read -r sender client date number vat vatrate<<-EOF
+    read -r sender client date number vat vatrate hourly x<<-EOF
        $(sed q "invoices/$id")
        EOF
   fi
@@ -87,12 +87,17 @@ edit_invoice(){
   || vatrate=19
 
   [ -f "clients/${client#client=}" ] \
-  && read -r caddress hourly <"clients/${client#client=}"
-  hourly="${hourly#hourly=}"
+  && read -r caddress chourly x<"clients/${client#client=}"
+  [ "${chourly#hourly=}" -ge 0 ] 2>&- \
+  && chourly="${chourly#hourly=}" \
+  || chourly=0
+  [ "${hourly#hourly=}" -ge 0 ] 2>&- \
+  && hourly="${hourly#hourly=}" \
+  || hourly="${chourly}"
 
   tid="$(tid "invoices/$id")"
 
-  read -r taxtype nett tax gross <<-EOF
+  read -r taxtype nett tax gross x<<-EOF
        $(invoice_total "$id")
        EOF
 
@@ -116,6 +121,9 @@ edit_invoice(){
          [label for=date Date:]
          [input #date name=date value="${date}" placeholder="YYYY-MM-TT"]
        
+         [label for=hourly Hourly Rate:]
+         [input #hourly type=number name=hourly value="${hourly}"]
+
          [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)]
@@ -127,7 +135,7 @@ edit_invoice(){
          [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
+  | while read -r time work hours x; do
     hours="$(UNSTRING "${hours#hours=}" |grep -m1 -xE '[0-9]+' || printf 0)"
     printf '[tr
             [td [textarea name=time
@@ -162,12 +170,10 @@ invoice_total(){
         total=0 caddress hourly time work hours
 
   if [ -f "invoices/$id" ]; then
-    read -r sender client date number vat vatrate<<-EOF
+    read -r sender client date number vat vatrate hourly x<<-EOF
        $(sed q "invoices/$id")
        EOF
 
-    [ -f "clients/${client#client=}" ] \
-    && read -r caddress hourly <"clients/${client#client=}"
     [ "${hourly#hourly=}" -gt 0 ] 2>&- \
     && hourly="${hourly#hourly=}" \
     || hourly=0
@@ -218,12 +224,13 @@ update_invoice(){
       [ "$n" -gt "$extra" ] && extra="$n"
     done
 
-    { printf 'sender=%s        client=%s       date=%s number=%s       vat=%s  vatrate=%s\n' \
+    { printf 'sender=%s        client=%s       date=%s number=%s       vat=%s  vatrate=%s      hourly=%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 vatrate |grep -m1 -xE '[0-9]+')" \
+        "$(POST hourly |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)" \
@@ -233,10 +240,14 @@ update_invoice(){
     } >"invoices/$id"
   fi
   if [ "$(POST genpdf)" ]; then
+    read -r sender client date x<"invoices/$id"
+    read -r saddress x <"senders/${sender#sender=}"
+    read -r caddress x <"clients/${client#client=}"
+    filename="Rechnung $(UNSTRING "${saddress#address=}" |sed 1q) an $(UNSTRING "${caddress#address=}" |sed 1q) $(date -d@"${date#date=}" +%F).pdf"
+
     . $_EXEC/odtgen.sh
-    genodt "$id"
-    lowriter --convert-to pdf --outdir export/ "export/${id}.odt" >/dev/null
-    REDIRECT "/export/${id}.pdf"
+    pdfgen "$id"
+    REDIRECT "/export/${id}.pdf/$(URL "${filename}" |sed s/%0D//g)"
     exit 0
   fi
   REDIRECT "/invoices/$id"
index 13b3126e5d1ed084f166d75f709ec2d5d25e4651..c0f244825b74fad45a4d4e490c11cee03e5181ef 100755 (executable)
--- a/odtgen.sh
+++ b/odtgen.sh
@@ -257,11 +257,11 @@ genodt(){
     rmdir "$exdir/META-INF/" "$exdir/"
   }
 
-  read -r sender client date number vat vatrate <<-EOF
+  read -r sender client date number vat vatrate hourly x<<-EOF
        $(sed q "invoices/$id")
        EOF
-  read -r sender iban bic <"senders/${sender#sender=}"
-  read -r client hourly <"clients/${client#client=}"
+  read -r sender iban bic x<"senders/${sender#sender=}"
+  read -r client chourly x<"clients/${client#client=}"
 
   mkdir -p "$exdir/META-INF"
   odt_manifest >"$exdir/META-INF/manifest.xml"
@@ -282,3 +282,11 @@ genodt(){
   rm "$exdir/content.xml" "$exdir/styles.xml" "$exdir/META-INF/manifest.xml"
   rmdir "$exdir/META-INF/" "$exdir/"
 }
+
+genpdf(){
+  local id="$1"
+  genodt "$id"
+  writer --convert-to pdf --outdir "export/" "export/${id}.odt" >/dev/null
+  rm "export/${id}.odt"
+}
+