Add font setting

This commit is contained in:
Daniel O'Connell 2019-10-02 14:30:09 +02:00
parent 1fb45bf0c7
commit 505aadbaa8
4 changed files with 9 additions and 5 deletions

View File

@ -27,6 +27,7 @@ following keys:
* :seller - the seller's (i.e. the entity to be paid) information. This is required * :seller - the seller's (i.e. the entity to be paid) information. This is required
* :buyer - the buyer's (i.e. the entity that will pay) information. This is required * :buyer - the buyer's (i.e. the entity that will pay) information. This is required
* :items - a list of items to be paid for * :items - a list of items to be paid for
* :font-path - (optional) *the path to a font file, e.g. "/usr/share/fonts/truetype/freefont/FreeSans.ttf"
* :credentials - JIRA and Tempo access credentials. These are needed if the price depends on tracked time * :credentials - JIRA and Tempo access credentials. These are needed if the price depends on tracked time
See `resources/config.edn` for an example configuration. See `resources/config.edn` for an example configuration.

View File

@ -10,6 +10,7 @@
:items [{:vat 8 :netto 123.21 :title "Buty kowbojskie"} :items [{:vat 8 :netto 123.21 :title "Buty kowbojskie"}
{:vat 21 :hourly 43.12 :title "Usługa szewska"} {:vat 21 :hourly 43.12 :title "Usługa szewska"}
{:vat 23 :base 4300.00 :per-day 4 :title "Praca za ladą"}] {:vat 23 :base 4300.00 :per-day 4 :title "Praca za ladą"}]
:font-path "/usr/share/fonts/truetype/freefont/FreeSans.ttf"
:credentials {:tempo-token "5zq7zF9LADefEGAs12eDDas3FDttiM" :credentials {:tempo-token "5zq7zF9LADefEGAs12eDDas3FDttiM"
:jira-token "qypaAsdFwASasEddDDddASdC" :jira-token "qypaAsdFwASasEddDDddASdC"
:jira-user "mr.blobby@boots.rs"}}] :jira-user "mr.blobby@boots.rs"}}]

View File

@ -25,11 +25,12 @@
(not (contains? item :netto)) (assoc item :netto 0) (not (contains? item :netto)) (assoc item :netto 0)
:else item)) :else item))
(defn for-month [when {seller :seller buyer :buyer items :items creds :credentials} & [number]] (defn for-month [when {seller :seller buyer :buyer items :items creds :credentials font-path :font-path} & [number]]
(pdf/render seller buyer (pdf/render seller buyer
(map (partial set-price when creds) items) (map (partial set-price when creds) items)
(pdf/last-working-day when) (pdf/last-working-day when)
(invoice-number when number))) (invoice-number when number)
font-path))
(defn get-invoices [nips config] (defn get-invoices [nips config]
(if (seq nips) (if (seq nips)

View File

@ -1,6 +1,7 @@
(ns invoices.pdf (ns invoices.pdf
(:require [clj-pdf.core :refer [pdf]] (:require [clj-pdf.core :refer [pdf]]
[clojure.string :as str])) [clojure.string :as str])
(:import [java.awt Font]))
(defn round [val] (defn round [val]
@ -32,7 +33,7 @@
(str/replace #"[ -/]" "_")))) (str/replace #"[ -/]" "_"))))
(defn render [seller buyer items when number] (defn render [seller buyer items when number & [font-path]]
(let [title (get-title (:team seller) (:name seller) number)] (let [title (get-title (:team seller) (:name seller) number)]
(println " -" title) (println " -" title)
(pdf (pdf
@ -42,7 +43,7 @@
:bottom-margin 10 :bottom-margin 10
:left-margin 10 :left-margin 10
:top-margin 20 :top-margin 20
:font {:encoding :unicode :ttf-name "/usr/share/fonts/gsfonts/NimbusSans-Regular.otf"} :font (clojure.core/when font-path{:encoding :unicode :ttf-name font-path})
:size "a4" :size "a4"
:footer "page"} :footer "page"}