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:
-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
-h, --help Display a help message
@ -125,6 +125,7 @@ worklog entry like the following:
:worklogs [{:type :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"
:jira-token "qypaAsdFwASasEddDDddASdC"
:jira-user "mr.blobby@boots.rs"}]

View File

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

View File

@ -8,6 +8,8 @@
[clojure-mail.message :refer (read-message) :as mess]))
(defn send-invoice [invoice to {from :user :as smtp}]
(if (sequential? to)
(doseq [address to] (send-invoice invoice address smtp))
(when (and (not-any? nil? [to from smtp invoice])
(->>
(send-message smtp {:from from
@ -17,7 +19,7 @@
:content (.getAbsolutePath invoice)
:content-type "application/pdf"}]})
:error (= :SUCCESS)))
(println " - email sent to " to)))
(println " - email sent to " to))))
(defn server-find-messages
"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
(: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]]
[clojure.string :as str])
(:import [java.awt Font]))

View File

@ -31,10 +31,11 @@
(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}]
(let [month (-> month (.plusMonths (or offset 0)))]
(condp = type
:jira (jira-timesheet (me creds) month creds)
:imap (email/get-worklogs month creds)))
:imap (email/get-worklogs month creds))))
(defn timesheets
"Return timesheets for the given month from the given worklogs."