Fixed issue with paying negative invoices.
This commit is contained in:
@@ -34,6 +34,18 @@
|
||||
:code [[:db/add e a
|
||||
(-> (d/entity db e) a (+ amount))]] })}]] )
|
||||
|
||||
(defn fix-pay-function [conn]
|
||||
[[{:db/ident :pay
|
||||
:db/doc "Data function that increments value of attribute a by amount."
|
||||
:db/fn (d/function '{:lang "clojure"
|
||||
:params [db e amount]
|
||||
:code (let [current-outstanding-balance (-> (d/entity db e) :invoice/outstanding-balance)
|
||||
new-outstanding-balance (- current-outstanding-balance amount)]
|
||||
[[:db/add e :invoice/outstanding-balance new-outstanding-balance]
|
||||
[:db/add e :invoice/status (if (> -0.001 new-outstanding-balance 0.001)
|
||||
:invoice-status/paid
|
||||
:invoice-status/unpaid)]])})}]] )
|
||||
|
||||
(defn -main [& args]
|
||||
(println "Creating database...")
|
||||
(d/create-database uri)
|
||||
@@ -42,6 +54,7 @@
|
||||
conn (d/connect uri)
|
||||
norms-map {:auto-ap/base-schema {:txes auto-ap.datomic/base-schema}
|
||||
:auto-ap/functions {:txes-fn 'auto-ap.datomic.migrate/functions :requires [:auto-ap/base-schema]}
|
||||
:auto-ap/fx-pay-function {:txes-fn 'auto-ap.datomic.migrate/fix-pay-function :requires [:auto-ap/functions]}
|
||||
:auto-ap/migrate-vendors {:txes-fn 'auto-ap.datomic/migrate-vendors :requires [:auto-ap/base-schema]}
|
||||
:auto-ap/migrate-clients {:txes-fn 'auto-ap.datomic/migrate-clients :requires [:auto-ap/migrate-vendors]}
|
||||
:auto-ap/migrate-users {:txes-fn 'auto-ap.datomic/migrate-users :requires [:auto-ap/migrate-clients]}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
[clojure.walk :as walk]
|
||||
[venia.core :as v]
|
||||
[auto-ap.history :as p]
|
||||
[auto-ap.events :as events]
|
||||
[pushy.core :as pushy]))
|
||||
|
||||
(re-frame/reg-fx
|
||||
@@ -158,7 +157,7 @@
|
||||
"&variables=" (pr-str (or variables {})))}))]
|
||||
(cond
|
||||
(= (:status response) 401)
|
||||
(re-frame/dispatch [::events/logout "Your session has expired. Please log in again."])
|
||||
(re-frame/dispatch [:auto-ap.events/logout "Your session has expired. Please log in again."])
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user