sundry fixes

This commit is contained in:
Daniel O'Connell 2020-01-22 18:34:06 +01:00
parent 63d80ddc1a
commit bb85a5f2fa
5 changed files with 25 additions and 21 deletions

View File

@ -15,7 +15,7 @@ the JIRA credentials with correct values).
The following options are available: The following options are available:
-n, --number Invoice number. In the case of multiple invoices, they will have subsequent numbers -n, --number Invoice number. In the case of multiple invoices, they will have subsequent numbers
-w, --when The month for which to generate the invoice -w, --when The date for which to generate the invoice
-c, --company The NIPs of companies for which to generate invoices. If not provided, all the companies will be used -c, --company The NIPs of companies for which to generate invoices. If not provided, all the companies will be used
-h, --help Display a help message -h, --help Display a help message
@ -125,6 +125,7 @@ worklog entry like the following:
:worklogs [{:type :jira :worklogs [{:type :jira
:ids [:from-jira] :ids [:from-jira]
:month-offset -2 ; Can be used to get a different month than the currently processed one. In this case, 2 months previous
:tempo-token "5zq7zF9LADefEGAs12eDDas3FDttiM" :tempo-token "5zq7zF9LADefEGAs12eDDas3FDttiM"
:jira-token "qypaAsdFwASasEddDDddASdC" :jira-token "qypaAsdFwASasEddDDddASdC"
:jira-user "mr.blobby@boots.rs"}] :jira-user "mr.blobby@boots.rs"}]

View File

@ -26,8 +26,8 @@
(doall (map (partial run-callback invoice) callbacks))) (doall (map (partial run-callback invoice) callbacks)))
(defn for-month [{seller :seller buyer :buyer smtp :smtp callbacks :callbacks :as invoice} when & [number font]] (defn for-month [{seller :seller buyer :buyer smtp :smtp callbacks :callbacks :as invoice} when & [number font]]
(let [file (pdf/render invoice (last-working-day when) (invoice-number when number))] (let [file (pdf/render invoice when (invoice-number when number))]
;; (email/send-invoice file (:email buyer) smtp) (email/send-invoice file (:email buyer) smtp)
(run-callbacks file callbacks))) (run-callbacks file callbacks)))
(defn item-price [worklogs item] (defn item-price [worklogs item]
@ -48,7 +48,7 @@
(defn process-invoices [{invoices :invoices :as config} month worklogs] (defn process-invoices [{invoices :invoices :as config} month worklogs]
(let [invoices (map (partial prepare-invoice config month worklogs) invoices)] (let [invoices (map (partial prepare-invoice config month worklogs) invoices)]
(doseq [[i invoice] (map-indexed vector invoices)] (doseq [[i invoice] (->> invoices (filter #(-> % :items seq)) (map-indexed vector))]
(for-month invoice month (inc i)) (for-month invoice month (inc i))
(println)))) (println))))
@ -56,8 +56,8 @@
[["-n" "--number NUMBER" "Invoice number. In the case of multiple invoices, they will have subsequent numbers" [["-n" "--number NUMBER" "Invoice number. In the case of multiple invoices, they will have subsequent numbers"
:default 1 :default 1
:parse-fn #(Integer/parseInt %)] :parse-fn #(Integer/parseInt %)]
["-w" "--when DATE" "The month for which to generate the invoice" ["-w" "--when DATE" "The day for which to generate the invoice"
:default (-> (java.time.LocalDate/now) (.minusMonths 1)) :default (-> (java.time.LocalDate/now) (.minusMonths 1) last-working-day)
:parse-fn #(java.time.LocalDate/parse %)] :parse-fn #(java.time.LocalDate/parse %)]
;; A non-idempotent option (:default is applied first) ;; A non-idempotent option (:default is applied first)
["-c" "--company NIP" "companies for which to generate invoices. All, if not provided" ["-c" "--company NIP" "companies for which to generate invoices. All, if not provided"

View File

@ -8,16 +8,18 @@
[clojure-mail.message :refer (read-message) :as mess])) [clojure-mail.message :refer (read-message) :as mess]))
(defn send-invoice [invoice to {from :user :as smtp}] (defn send-invoice [invoice to {from :user :as smtp}]
(when (and (not-any? nil? [to from smtp invoice]) (if (sequential? to)
(->> (doseq [address to] (send-invoice invoice address smtp))
(send-message smtp {:from from (when (and (not-any? nil? [to from smtp invoice])
:to [to] (->>
:subject (.getName invoice) (send-message smtp {:from from
:body [{:type :attachment :to [to]
:content (.getAbsolutePath invoice) :subject (.getName invoice)
:content-type "application/pdf"}]}) :body [{:type :attachment
:error (= :SUCCESS))) :content (.getAbsolutePath invoice)
(println " - email sent to " to))) :content-type "application/pdf"}]})
:error (= :SUCCESS)))
(println " - email sent to " to))))
(defn server-find-messages (defn server-find-messages
"Find all messages in the given folder, filtering them by subject and sender (use nil to ignore)." "Find all messages in the given folder, filtering them by subject and sender (use nil to ignore)."

View File

@ -1,6 +1,6 @@
(ns invoices.pdf (ns invoices.pdf
(:require [clj-pdf.core :refer [pdf]] (:require [clj-pdf.core :refer [pdf]]
[invoices.time :refer [skip-days-off last-working-day]] [invoices.time :refer [skip-days-off]]
[invoices.calc :refer [brutto vat round]] [invoices.calc :refer [brutto vat round]]
[clojure.string :as str]) [clojure.string :as str])
(:import [java.awt Font])) (:import [java.awt Font]))

View File

@ -31,10 +31,11 @@
(jira-timesheet (me credentials) (prev-month when) credentials))) (jira-timesheet (me credentials) (prev-month when) credentials)))
(defn get-timesheet [month {type :type :as creds}] (defn get-timesheet [month {type :type offset :month-offset :as creds}]
(condp = type (let [month (-> month (.plusMonths (or offset 0)))]
:jira (jira-timesheet (me creds) month creds) (condp = type
:imap (email/get-worklogs month creds))) :jira (jira-timesheet (me creds) month creds)
:imap (email/get-worklogs month creds))))
(defn timesheets (defn timesheets
"Return timesheets for the given month from the given worklogs." "Return timesheets for the given month from the given worklogs."