diff --git a/src/invoices/pdf.clj b/src/invoices/pdf.clj index b230594..e4a3767 100644 --- a/src/invoices/pdf.clj +++ b/src/invoices/pdf.clj @@ -5,9 +5,11 @@ [clojure.string :as str]) (:import [java.awt Font])) +(defn total [items getter] + (->> items (map getter) (reduce +) round str)) + (defn format-total [items getter] - [:cell {:background-color [216 247 249]} - (->> items (map getter) (reduce +) round str)]) + [:cell {:background-color [216 247 249]} (total items getter)]) (defn format-param [param] [:cell.param {:align :right} (str param ": ")]) (defn format-value [value] [:cell {:colspan 2} (str value)]) @@ -21,6 +23,17 @@ (-> item vat round str) (brutto item)]))) +(defn format-summary + ([items vat-level] (format-summary (filter #(= (:vat %) vat-level) items) vat-level "")) + ([items vat-level text] + [[:cell {:background-color [84 219 229] :set-border [] :colspan 5 :align :center} text] + (format-total items (constantly 1)) + (format-total items :netto) + ({:total "wszystkie" nil "zw."} vat-level (str vat-level "%")) + (format-total items vat) + (format-total items brutto) + ])) + (defn format-notes "Adds an `Uwagi` section with the given notes, one per line." [notes] @@ -89,12 +102,14 @@ (->> items (map format-product) (map-indexed #(concat [(inc %1)] %2))) - [[[:cell {:background-color [84 219 229] :colspan 5 :align :center} "Razem"] - (format-total items (constantly 1)) - (format-total items :netto) - "" - (format-total items vat) - (format-total items brutto)]])]) + [(format-summary items :total (str "Razem do zapłaty: " (total items brutto) " PLN"))] + (->> items (map :vat) distinct sort (map (partial format-summary items)))) + + [:table {:border false :padding 0 :spacing 0 :num-cols 6} + [(format-param "Zapłacono") (format-value "0.00 PLN") + (format-param "Do zapłaty") (format-value (str (total items brutto) " PLN"))]] + + ]) (defn add-notes "Some items require extra notes to be added (for various legal reasons)"