]> git.plutz.net Git - invoices/commitdiff
tax calculation in pdf export
authorPaul Hänsch <paul@plutz.net>
Wed, 28 Nov 2018 06:46:23 +0000 (07:46 +0100)
committerPaul Hänsch <paul@plutz.net>
Wed, 28 Nov 2018 06:46:23 +0000 (07:46 +0100)
invoices.css
invoices.sh
odtgen.sh

index aecfd06c200b83f1fcbc9824e5a03598453ce3ea..41cea2d6aee02c355e154b8bbd03a79e04c26da8 100755 (executable)
@@ -125,13 +125,16 @@ form input[type=number] {
 .invoice form button[type=submit],
 .client form button[type=submit],
 .sender form button[type=submit] {
-  display: block;
   margin: .5em 0 0 auto;
   padding: .25em .5em;
   background-color: #DEF;
   border-radius: .25em;
   border: 1px solid #08F;
 }
+.client form button[type=submit],
+.sender form button[type=submit] {
+  display: block;
+}
 
 /* ==================== INVOICE FORMS ==================== */
 .invoice form select {
index 56dd244a6472bcc0cb996ac25a20cb065e16fcfa..6538c967945693f7fe8711f4aa56a5f3b7450deb 100755 (executable)
@@ -23,7 +23,9 @@ client_list(){
 }
 
 list_invoices(){
-  local sender client date number vat vatrate iban bic hourly
+  local sender client date number vat vatrate iban bic hourly \
+        taxtype nett tax gross total
+
   [ -d invoices/ ] && for i in invoices/*; do
     read -r sender client date number vat vatrate<<-EOF
        $(sed q "$i")
@@ -41,22 +43,33 @@ list_invoices(){
     && date="$(date -d "@${date#date=}" +%x)" \
     || date="(unset)"
 
+    read -r taxtype nett tax gross <<-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:] %.2f €
+      [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")" \
-       "$(invoice_total "${i#invoices/}")" \
+       "$total" \
        "$(HTML ${i#invoices/})"
   done
 }
 
 edit_invoice(){
-  local id="$1" sender client date number vat vatrate caddress hourly total
+  local id="$1" sender client date number vat vatrate caddress hourly \
+        taxtype nett tax gross
+
   if [ -f "invoices/$id" ]; then
     read -r sender client date number vat vatrate<<-EOF
        $(sed q "invoices/$id")
@@ -78,7 +91,10 @@ edit_invoice(){
   hourly="${hourly#hourly=}"
 
   tid="$(tid "invoices/$id")"
-  total=$(invoice_total "$id")
+
+  read -r taxtype nett tax gross <<-EOF
+       $(invoice_total "$id")
+       EOF
 
   cat <<-EOF 
        [form method="POST" action="/update_invoice"
@@ -126,20 +142,12 @@ $({ sed 1d "invoices/$id"; printf 'time= work= hours=\n'; } \
   done
 )
             [tr [td colspan=4 
-            $(case $vat in
-              vat=nett)
-                awk "BEGIN {
-                  printf \"Sum: %7.2f €<br/> + VAT: %7.2f €<br/> [strong Total:] %7.2f €\",
-                   $total, int($total * $vatrate + .5) / 100,
-                   $total + int($total * $vatrate + .5) / 100
-                }" ;;
-              vat=gross)
-                awk "BEGIN {
-                  printf \"[strong Total:] %7.2f €<br/> incl VAT: %7.2f €<br/>+ nett: %7.2f €\",
-                   $total, int($total / (100 + $vatrate) * $vatrate * 100 + .5) / 100,
-                   $total - int($total / (100 + $vatrate) * $vatrate * 100 + .5) / 100
-                }" ;;
-              *) printf '[strong Total:] %.2f €' "$total" ;;
+            $(case $taxtype in
+              (nett)  printf 'Sum: %7.2f €[br] + VAT: %7.2f €[br] [strong Total:] %7.2f €' \
+                      $nett $tax $gross ;;
+              (gross) printf '[strong Total:] %7.2f €[br] incl. nett: %7.2f €[br] + VAT: %7.2f €' \
+                      $gross $nett $tax ;;
+              (*) printf '[strong Total:] %.2f €' $nett ;;
             esac)
             ]]
          ]
@@ -163,6 +171,9 @@ invoice_total(){
     [ "${hourly#hourly=}" -gt 0 ] 2>&- \
     && hourly="${hourly#hourly=}" \
     || hourly=0
+    [ "${vatrate#vatrate=}" -ge 0 ] 2>&- \
+    && vatrate="${vatrate#vatrate=}" \
+    || vatrate=19
 
     sed 1d "invoices/$id" \
     | { while read -r time work hours; do
@@ -171,7 +182,25 @@ invoice_total(){
         || hours=0
         total=$((total + hours * hourly))
       done
-      printf %.2f\\n "$total"
+      case $vat in
+        vat=nett)
+          awk "BEGIN {
+            printf \"nett      %.2f    %.2f    %.2f\",
+              $total, int($total * $vatrate + .5) / 100,
+              $total + int($total * $vatrate + .5) / 100
+          }" ;;
+        vat=gross)
+          awk "BEGIN {
+            printf \"gross     %.2f    %.2f    %.2f\",
+              $total - int($total / (100 + $vatrate) * $vatrate * 100 + .5) / 100,
+              int($total / (100 + $vatrate) * $vatrate * 100 + .5) / 100, $total
+          }" ;;
+        *)
+          awk "BEGIN {
+            printf \"notax     %.2f    %.2f    %.2f\",
+              $total, 0, $total
+          }" ;;
+      esac
     }
   else
     printf %.2f\\n 0
index f9b7d62cf920e7c0371eea17609203b5f59379dc..13b3126e5d1ed084f166d75f709ec2d5d25e4651 100755 (executable)
--- a/odtgen.sh
+++ b/odtgen.sh
@@ -58,7 +58,11 @@ odt_stylesheet(){
 }
 
 odt_content(){
-  local id="$1" sender="$2" client="$3" date="$4" number="$5" vat="$6" vatrate="$7" hourly="$8"
+  local id="$1" sender="$2" client="$3" date="$4" number="$5" vat="$6" vatrate="$7" hourly="$8" \
+        taxtype nett tax gross
+  read -r taxtype nett tax gross <<-EOF
+       $(invoice_total "$id")
+       EOF
 
   cat <<-EOF
        <?xml version="1.0" encoding="UTF-8"?>
@@ -140,8 +144,8 @@ odt_content(){
              -->$(case $vat in
                   (smallbusiness)
                     printf '<text:line-break/>Gemäß Kleinunternehmerregelung (§19 Umsatzsteuergesetz) wird keine Umsatzsteuer berechnet.';;
-                  (nett)  printf 'zuzüglich %i%% MWSt.' "$vatrate";;
-                  (gross) printf '(einschließlich %i\% MWSt.)' "$vatrate";;
+                  (nett)  printf 'zuzüglich %i%% MwSt.' "$vatrate";;
+                  (gross) printf '(einschließlich %i%% MwSt.)' "$vatrate";;
                  esac)<!--
            --></text:p>
              <text:p text:style-name="P3"/>
@@ -191,15 +195,53 @@ odt_content(){
                  <table:table-cell table:style-name="Table1.6" office:value-type="string">
                    <text:p text:style-name="P6"/>
                  </table:table-cell>
-                 <table:table-cell table:style-name="Table1.6" office:value-type="string">
-                   <text:p text:style-name="P6"/>
-                 </table:table-cell>
-                 <table:table-cell table:style-name="Table1.6" office:value-type="string">
-                   <text:p text:style-name="P7">Summe:</text:p>
-                 </table:table-cell>
-                 <table:table-cell table:style-name="Table1.6" office:value-type="string">
-                   <text:p text:style-name="P7">$(invoice_total "$id") €</text:p>
-                 </table:table-cell>
+                  $(case $taxtype in
+                    (nett) cat <<-TCELL
+                       <table:table-cell table:style-name="Table1.6" table:number-columns-spanned="2" office:value-type="string">
+                         <text:p text:style-name="P5">
+                         Zwischensumme:<text:line-break/>
+                         zzgl. ${vatrate}% MwSt.:<text:line-break/>
+                         </text:p>
+                         <text:p text:style-name="P7">zu zahlender Betrag:</text:p>
+                       </table:table-cell>
+                       <table:table-cell table:style-name="Table1.6" office:value-type="string">
+                         <text:p text:style-name="P5">
+                         ${nett} €<text:line-break/>
+                         ${tax} €<text:line-break/>
+                         </text:p>
+                         <text:p text:style-name="P7">${gross} €</text:p>
+                       </table:table-cell>
+                       TCELL
+                        ;;
+                    (gross) cat <<-TCELL
+                       <table:table-cell table:style-name="Table1.6" table:number-columns-spanned="2" office:value-type="string">
+                         <text:p text:style-name="P7">zu zahlender Betrag:</text:p>
+                         <text:p text:style-name="P5">
+                         <text:line-break/>
+                         enthaltene MwSt (${vatrate}%):<text:line-break/>
+                         enthaltener Netto-Betrag:<!--
+                       --></text:p>
+                       </table:table-cell>
+                       <table:table-cell table:style-name="Table1.6" office:value-type="string">
+                         <text:p text:style-name="P7">${gross} €</text:p>
+                         <text:p text:style-name="P5">
+                         <text:line-break/>
+                         ${tax} €<text:line-break/>
+                         ${nett} €<!--
+                       --></text:p>
+                       </table:table-cell>
+                       TCELL
+                        ;;
+                    (*) cat <<-TCELL
+                       <table:table-cell table:style-name="Table1.6" table:number-columns-spanned="2" office:value-type="string">
+                         <text:p text:style-name="P7">zu zahlender Betrag:</text:p>
+                       </table:table-cell>
+                       <table:table-cell table:style-name="Table1.6" office:value-type="string">
+                         <text:p text:style-name="P7">${gross} €</text:p>
+                       </table:table-cell>
+                       TCELL
+                        ;;
+                  esac)
                </table:table-row>
              </table:table>
            </office:text>