Limit items with :to and :from

This commit is contained in:
Daniel O'Connell 2019-10-02 17:40:23 +02:00
parent ea4294f138
commit f650d5f40e
2 changed files with 16 additions and 9 deletions

View File

@ -55,8 +55,9 @@ The buyer can have the following keys
### Items ### Items
The list of items should contain maps with a required :title, an optional :vat (if not provided it is assumed that The list of items should contain maps with a required :title, optional :vat (if not provided it is assumed that
item is VAT free), and a key providing the cost of the item. The price can be provided in one of the following ways: item is VAT free), :to (the date from which this item is valid), :from (the date till which this item is valid)
and a key providing the cost of the item. The price can be provided in one of the following ways:
* :netto - is a set price and will be displayed as provided * :netto - is a set price and will be displayed as provided
* :hourly - is an hourly price - JIRA will be queried in order to work out how many hours should be billed * :hourly - is an hourly price - JIRA will be queried in order to work out how many hours should be billed
@ -76,11 +77,11 @@ item is VAT free), and a key providing the cost of the item. The price can be pr
Examples: Examples:
; 8% VAT, and a price of 600 ; 8% VAT, and a price of 600, recurring every period before 2019-05-30
{:vat 8 :netto 600 :title "Shoes"} {:vat 8 :netto 600 :title "Shoes" :to "2019-05-30"}
; 12% VAT, and an hourly rate of 12 ; 12% VAT, and an hourly rate of 12, first appearing on 2019-07-01
{:vat 12 :hourly 12 :title "Something worth 12/h"} {:vat 12 :hourly 12 :title "Something worth 12/h" :from "2019-07-01"}
; 23% VAT, working part time with a base salary of 5000 ; 23% VAT, working part time with a base salary of 5000
{:vat 23 :base 5000 :per-day 4 :title "Part time job at 5000"}] {:vat 23 :base 5000 :per-day 4 :title "Part time job at 5000"}]

View File

@ -1,7 +1,7 @@
(ns invoices.core (ns invoices.core
(:require [invoices.pdf :as pdf] (:require [invoices.pdf :as pdf]
[invoices.settings :refer [invoices]] [invoices.settings :refer [invoices]]
[invoices.jira :refer [prev-timesheet]] [invoices.jira :refer [prev-timesheet prev-month]]
[clojure.tools.cli :refer [parse-opts]] [clojure.tools.cli :refer [parse-opts]]
[clojure.string :as str]) [clojure.string :as str])
(:gen-class)) (:gen-class))
@ -36,9 +36,15 @@
(not (contains? item :netto)) (assoc item :netto 0) (not (contains? item :netto)) (assoc item :netto 0)
:else item)) :else item))
(defn date-applies? [when {to :to from :from}]
(and (or (nil? to) (-> when .toString (compare to) (< 0)))
(or (nil? from) (-> when .toString (compare from) (>= 0)))))
(defn for-month [when {seller :seller buyer :buyer items :items creds :credentials font-path :font-path} & [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 (prev-timesheet when creds)) items) (->> items
(filter (partial date-applies? when))
(map (partial set-price (prev-timesheet when creds))))
(pdf/last-working-day when) (pdf/last-working-day when)
(invoice-number when number) (invoice-number when number)
font-path)) font-path))
@ -54,7 +60,7 @@
: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 month for which to generate the invoice"
:default (java.time.LocalDate/now) :default (-> (java.time.LocalDate/now) prev-month)
: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"