Fixes issue where the db/id of a temporary id is different from the real one.
Cash payments always match invoices.
This commit is contained in:
@@ -33,7 +33,8 @@
|
|||||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||||
[config.core :refer [env]]
|
[config.core :refer [env]]
|
||||||
[datomic.api :as d]
|
[datomic.api :as d]
|
||||||
[digest])
|
[digest]
|
||||||
|
[clj-time.coerce :as coerce])
|
||||||
(:import
|
(:import
|
||||||
(java.io ByteArrayOutputStream)
|
(java.io ByteArrayOutputStream)
|
||||||
(java.text DecimalFormat)
|
(java.text DecimalFormat)
|
||||||
@@ -347,6 +348,7 @@
|
|||||||
invoices)))
|
invoices)))
|
||||||
payment (assoc base-payment
|
payment (assoc base-payment
|
||||||
:payment/type :payment-type/cash
|
:payment/type :payment-type/cash
|
||||||
|
:payment/date (coerce/to-date (last (sort (map :invoice/date invoices))))
|
||||||
:payment/memo memo
|
:payment/memo memo
|
||||||
:payment/status :payment-status/cleared)
|
:payment/status :payment-status/cleared)
|
||||||
transaction {:db/id (str "transaction-" (:db/id vendor))
|
transaction {:db/id (str "transaction-" (:db/id vendor))
|
||||||
@@ -359,7 +361,7 @@
|
|||||||
:transaction/raw-id transaction-id
|
:transaction/raw-id transaction-id
|
||||||
:transaction/vendor (:db/id vendor)
|
:transaction/vendor (:db/id vendor)
|
||||||
:transaction/description-original memo
|
:transaction/description-original memo
|
||||||
:transaction/date (:payment/date base-payment)
|
:transaction/date (:payment/date payment)
|
||||||
:transaction/approval-status :transaction-approval-status/approved
|
:transaction/approval-status :transaction-approval-status/approved
|
||||||
:transaction/accounts [{:transaction-account/account (:db/id (a/get-account-by-numeric-code-and-sets 21000 ["default"]))
|
:transaction/accounts [{:transaction-account/account (:db/id (a/get-account-by-numeric-code-and-sets 21000 ["default"]))
|
||||||
:transaction-account/location "A"
|
:transaction-account/location "A"
|
||||||
|
|||||||
@@ -425,7 +425,7 @@
|
|||||||
|
|
||||||
(defn transact-with-ledger [transaction id]
|
(defn transact-with-ledger [transaction id]
|
||||||
(let [db (d/db conn)
|
(let [db (d/db conn)
|
||||||
tx (d/with db transaction)
|
tx (audit-transact transaction id)
|
||||||
affected-entities (->> (:tx-data tx)
|
affected-entities (->> (:tx-data tx)
|
||||||
(map (fn [^datomic.db.Datum x]
|
(map (fn [^datomic.db.Datum x]
|
||||||
{:e (:e x)
|
{:e (:e x)
|
||||||
@@ -439,9 +439,11 @@
|
|||||||
(map #(entity-change->ledger (:db-after tx) %))
|
(map #(entity-change->ledger (:db-after tx) %))
|
||||||
(filter seq))
|
(filter seq))
|
||||||
retractions (map (fn [[_ e]] [:db/retractEntity [:journal-entry/original-entity e]]) affected-entities)]
|
retractions (map (fn [[_ e]] [:db/retractEntity [:journal-entry/original-entity e]]) affected-entities)]
|
||||||
(audit-transact retractions id)
|
(when (seq retractions)
|
||||||
(audit-transact (into transaction ledger-txs) id)))
|
(audit-transact retractions id))
|
||||||
|
(when (seq ledger-txs)
|
||||||
|
(audit-transact ledger-txs id))
|
||||||
|
tx))
|
||||||
|
|
||||||
(defn transact-batch-with-ledger [txes id]
|
(defn transact-batch-with-ledger [txes id]
|
||||||
(let [batch-id (.toString (java.util.UUID/randomUUID))]
|
(let [batch-id (.toString (java.util.UUID/randomUUID))]
|
||||||
|
|||||||
Reference in New Issue
Block a user