From f650d5f40ee3c349b6e39f35d672dabf6dd29cd3 Mon Sep 17 00:00:00 2001 From: Daniel O'Connell Date: Wed, 2 Oct 2019 17:40:23 +0200 Subject: [PATCH] Limit items with :to and :from --- README.md | 13 +++++++------ src/invoices/core.clj | 12 +++++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 02aad4b..98f9ffb 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,9 @@ The buyer can have the following keys ### Items -The list of items should contain maps with a required :title, an 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: +The list of items should contain maps with a required :title, optional :vat (if not provided it is assumed that +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 * :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: - ; 8% VAT, and a price of 600 - {:vat 8 :netto 600 :title "Shoes"} + ; 8% VAT, and a price of 600, recurring every period before 2019-05-30 + {:vat 8 :netto 600 :title "Shoes" :to "2019-05-30"} - ; 12% VAT, and an hourly rate of 12 - {:vat 12 :hourly 12 :title "Something worth 12/h"} + ; 12% VAT, and an hourly rate of 12, first appearing on 2019-07-01 + {:vat 12 :hourly 12 :title "Something worth 12/h" :from "2019-07-01"} ; 23% VAT, working part time with a base salary of 5000 {:vat 23 :base 5000 :per-day 4 :title "Part time job at 5000"}] diff --git a/src/invoices/core.clj b/src/invoices/core.clj index ad95d61..0e3237e 100644 --- a/src/invoices/core.clj +++ b/src/invoices/core.clj @@ -1,7 +1,7 @@ (ns invoices.core (:require [invoices.pdf :as pdf] [invoices.settings :refer [invoices]] - [invoices.jira :refer [prev-timesheet]] + [invoices.jira :refer [prev-timesheet prev-month]] [clojure.tools.cli :refer [parse-opts]] [clojure.string :as str]) (:gen-class)) @@ -36,9 +36,15 @@ (not (contains? item :netto)) (assoc item :netto 0) :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]] (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) (invoice-number when number) font-path)) @@ -54,7 +60,7 @@ :default 1 :parse-fn #(Integer/parseInt %)] ["-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 %)] ;; A non-idempotent option (:default is applied first) ["-c" "--company NIP" "companies for which to generate invoices. All, if not provided"