lots of QOL improvements.

This commit is contained in:
Bryce Covert
2020-07-31 18:26:57 -07:00
parent 98f0d40313
commit be9c789003
15 changed files with 302 additions and 282 deletions

View File

@@ -0,0 +1,29 @@
(ns auto-ap.background.invoices
(:require [auto-ap.datomic.invoices :as d-invoices]
[auto-ap.datomic :refer [uri]]
[datomic.api :as d]
[auto-ap.time :as time]
[clj-time.coerce :as coerce]))
(def break (atom false))
(defn close-auto-invoices []
(while (and (not @break)
(not (Thread/interrupted)))
(println "Clearing automatic invoices")
(try
(->> (d/query {:query {:find ['?e]
:in ['$ '?today]
:where ['[?e :invoice/automatically-paid-when-due true]
'[?e :invoice/status :invoice-status/unpaid]
'[?e :invoice/due ?d]
'[(<= ?d ?today)]]}
:args [(d/db (d/connect uri)) (coerce/to-date (time/local-now))]})
(mapv (fn [[i]] {:db/id i
:invoice/outstanding-balance 0.0
:invoice/status :invoice-status/paid}))
(d/transact (d/connect uri))
deref)
(Thread/sleep (* 1000 60 60))
(catch Exception e
(println (.toString e))))))