(cloud) Made invoice proposition a usable ion
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
{ :allow [iol-ion.tx/upsert-entity
|
{ :allow [iol-ion.tx/upsert-entity
|
||||||
iol-ion.tx/reset-scalars
|
iol-ion.tx/reset-scalars
|
||||||
iol-ion.tx/reset-rels]
|
iol-ion.tx/reset-rels
|
||||||
|
iol-ion.tx/propose-invoice]
|
||||||
:app-name "iol-cloud"}
|
:app-name "iol-cloud"}
|
||||||
|
|||||||
@@ -331,18 +331,4 @@
|
|||||||
due (assoc :invoice/due due)
|
due (assoc :invoice/due due)
|
||||||
scheduled-payment (assoc :invoice/scheduled-payment scheduled-payment))))
|
scheduled-payment (assoc :invoice/scheduled-payment scheduled-payment))))
|
||||||
|
|
||||||
(defn propose-invoice [db invoice]
|
|
||||||
(let [existing? (boolean (seq (dc/q '[:find ?i
|
|
||||||
:in $ ?invoice-number ?client ?vendor
|
|
||||||
:where
|
|
||||||
[?i :invoice/invoice-number ?invoice-number]
|
|
||||||
[?i :invoice/client ?client]
|
|
||||||
[?i :invoice/vendor ?vendor]
|
|
||||||
(not [?i :invoice/status :invoice-status/voided])]
|
|
||||||
db
|
|
||||||
(:invoice/invoice-number invoice)
|
|
||||||
(:invoice/client invoice)
|
|
||||||
(:invoice/vendor invoice))))]
|
|
||||||
(if existing?
|
|
||||||
[]
|
|
||||||
[(remove-nils invoice)])))
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
[amazonica.aws.s3 :as s3]
|
[amazonica.aws.s3 :as s3]
|
||||||
[auto-ap.datomic.clients :as d-clients]
|
[auto-ap.datomic.clients :as d-clients]
|
||||||
[auto-ap.jobs.core :refer [execute]]
|
[auto-ap.jobs.core :refer [execute]]
|
||||||
|
[iol-ion.tx :refer [propose-invoice]]
|
||||||
[auto-ap.logging :as log]
|
[auto-ap.logging :as log]
|
||||||
[auto-ap.parse :as parse]
|
[auto-ap.parse :as parse]
|
||||||
[auto-ap.time :as atime]
|
[auto-ap.time :as atime]
|
||||||
@@ -83,7 +84,7 @@
|
|||||||
:destination-key invoice-key})
|
:destination-key invoice-key})
|
||||||
(->> (extract-invoice-details (read-csv k) clients)
|
(->> (extract-invoice-details (read-csv k) clients)
|
||||||
(map (fn [i]
|
(map (fn [i]
|
||||||
[:propose-invoice (assoc i :invoice/source-url invoice-url)]))
|
[`(propose-invoice ~(assoc i :invoice/source-url invoice-url))]))
|
||||||
))
|
))
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(log/error ::cant-load-file
|
(log/error ::cant-load-file
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
[auto-ap.jobs.core :refer [execute]]
|
[auto-ap.jobs.core :refer [execute]]
|
||||||
[auto-ap.datomic.clients :as d-clients]
|
[auto-ap.datomic.clients :as d-clients]
|
||||||
[auto-ap.datomic.invoices :refer [code-invoice propose-invoice]]
|
[auto-ap.datomic.invoices :refer [code-invoice propose-invoice]]
|
||||||
|
[iol-ion.tx :refer [propose-invoice]]
|
||||||
[auto-ap.ledger :refer [transact-with-ledger]]
|
[auto-ap.ledger :refer [transact-with-ledger]]
|
||||||
[auto-ap.parse :as parse]
|
[auto-ap.parse :as parse]
|
||||||
[auto-ap.time :as t]
|
[auto-ap.time :as t]
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
(:require
|
(:require
|
||||||
[amazonica.aws.s3 :as s3]
|
[amazonica.aws.s3 :as s3]
|
||||||
[auto-ap.datomic :refer [conn remove-nils uri]]
|
[auto-ap.datomic :refer [conn remove-nils uri]]
|
||||||
|
[iol-ion.tx :refer [propose-invoice]]
|
||||||
[auto-ap.datomic.accounts :as a]
|
[auto-ap.datomic.accounts :as a]
|
||||||
[auto-ap.datomic.clients :as d-clients]
|
[auto-ap.datomic.clients :as d-clients]
|
||||||
[auto-ap.datomic.invoices :as d-invoices]
|
[auto-ap.datomic.invoices :as d-invoices]
|
||||||
@@ -253,7 +254,7 @@
|
|||||||
:transaction-account/location "A"
|
:transaction-account/location "A"
|
||||||
:transaction-account/amount (Math/abs (:invoice/total invoice))}]}))
|
:transaction-account/amount (Math/abs (:invoice/total invoice))}]}))
|
||||||
]
|
]
|
||||||
[`(d-invoices/propose-invoice ~(d-invoices/code-invoice (validate-invoice (remove-nils invoice)
|
[`(propose-invoice ~(d-invoices/code-invoice (validate-invoice (remove-nils invoice)
|
||||||
user)))
|
user)))
|
||||||
(some-> payment remove-nils)
|
(some-> payment remove-nils)
|
||||||
transaction])))
|
transaction])))
|
||||||
@@ -274,7 +275,7 @@
|
|||||||
(map #(validate-invoice % user))
|
(map #(validate-invoice % user))
|
||||||
admin-only-if-multiple-clients
|
admin-only-if-multiple-clients
|
||||||
(mapv d-invoices/code-invoice)
|
(mapv d-invoices/code-invoice)
|
||||||
(mapv (fn [i] `(d-invoices/propose-invoice ~i))))]
|
(mapv (fn [i] `(propose-invoice ~i))))]
|
||||||
|
|
||||||
(log/info "creating invoice" potential-invoices)
|
(log/info "creating invoice" potential-invoices)
|
||||||
(let [tx (transact-with-ledger potential-invoices user)]
|
(let [tx (transact-with-ledger potential-invoices user)]
|
||||||
|
|||||||
@@ -5,6 +5,19 @@
|
|||||||
(defn random-tempid []
|
(defn random-tempid []
|
||||||
(str (UUID/randomUUID)))
|
(str (UUID/randomUUID)))
|
||||||
|
|
||||||
|
(defn remove-nils [m]
|
||||||
|
(let [result (reduce-kv
|
||||||
|
(fn [m k v]
|
||||||
|
(if (not (nil? v))
|
||||||
|
(assoc m k v)
|
||||||
|
m
|
||||||
|
))
|
||||||
|
{}
|
||||||
|
m)]
|
||||||
|
(if (seq result)
|
||||||
|
result
|
||||||
|
nil)))
|
||||||
|
|
||||||
(defn by
|
(defn by
|
||||||
([f xs]
|
([f xs]
|
||||||
(by f identity xs))
|
(by f identity xs))
|
||||||
@@ -111,3 +124,20 @@
|
|||||||
[]))]
|
[]))]
|
||||||
ops))
|
ops))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(defn propose-invoice [db invoice]
|
||||||
|
(let [existing? (boolean (seq (dc/q '[:find ?i
|
||||||
|
:in $ ?invoice-number ?client ?vendor
|
||||||
|
:where
|
||||||
|
[?i :invoice/invoice-number ?invoice-number]
|
||||||
|
[?i :invoice/client ?client]
|
||||||
|
[?i :invoice/vendor ?vendor]
|
||||||
|
(not [?i :invoice/status :invoice-status/voided])]
|
||||||
|
db
|
||||||
|
(:invoice/invoice-number invoice)
|
||||||
|
(:invoice/client invoice)
|
||||||
|
(:invoice/vendor invoice))))]
|
||||||
|
(if existing?
|
||||||
|
[]
|
||||||
|
[(remove-nils invoice)])))
|
||||||
|
|||||||
Reference in New Issue
Block a user