(cloud) Made invoice proposition a usable ion

This commit is contained in:
2023-03-21 19:18:51 -07:00
parent 444d8d25ef
commit 142d9474ae
6 changed files with 41 additions and 21 deletions

View File

@@ -1,4 +1,5 @@
{ :allow [iol-ion.tx/upsert-entity
iol-ion.tx/reset-scalars
iol-ion.tx/reset-rels]
{ :allow [iol-ion.tx/upsert-entity
iol-ion.tx/reset-scalars
iol-ion.tx/reset-rels
iol-ion.tx/propose-invoice]
:app-name "iol-cloud"}

View File

@@ -331,18 +331,4 @@
due (assoc :invoice/due due)
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)])))

View File

@@ -3,6 +3,7 @@
[amazonica.aws.s3 :as s3]
[auto-ap.datomic.clients :as d-clients]
[auto-ap.jobs.core :refer [execute]]
[iol-ion.tx :refer [propose-invoice]]
[auto-ap.logging :as log]
[auto-ap.parse :as parse]
[auto-ap.time :as atime]
@@ -83,7 +84,7 @@
:destination-key invoice-key})
(->> (extract-invoice-details (read-csv k) clients)
(map (fn [i]
[:propose-invoice (assoc i :invoice/source-url invoice-url)]))
[`(propose-invoice ~(assoc i :invoice/source-url invoice-url))]))
))
(catch Exception e
(log/error ::cant-load-file

View File

@@ -5,6 +5,7 @@
[auto-ap.jobs.core :refer [execute]]
[auto-ap.datomic.clients :as d-clients]
[auto-ap.datomic.invoices :refer [code-invoice propose-invoice]]
[iol-ion.tx :refer [propose-invoice]]
[auto-ap.ledger :refer [transact-with-ledger]]
[auto-ap.parse :as parse]
[auto-ap.time :as t]

View File

@@ -2,6 +2,7 @@
(:require
[amazonica.aws.s3 :as s3]
[auto-ap.datomic :refer [conn remove-nils uri]]
[iol-ion.tx :refer [propose-invoice]]
[auto-ap.datomic.accounts :as a]
[auto-ap.datomic.clients :as d-clients]
[auto-ap.datomic.invoices :as d-invoices]
@@ -253,7 +254,7 @@
:transaction-account/location "A"
: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)))
(some-> payment remove-nils)
transaction])))
@@ -274,7 +275,7 @@
(map #(validate-invoice % user))
admin-only-if-multiple-clients
(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)
(let [tx (transact-with-ledger potential-invoices user)]

View File

@@ -5,6 +5,19 @@
(defn random-tempid []
(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
([f xs]
(by f identity xs))
@@ -111,3 +124,20 @@
[]))]
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)])))