progress on general ledger.
This commit is contained in:
@@ -30,23 +30,28 @@
|
||||
(defmethod entity-change->ledger :invoice
|
||||
[db [type id]]
|
||||
(let [entity (d/pull db ['* {:invoice/vendor '[*] :invoice/payment '[*]}] id)]
|
||||
|
||||
(map
|
||||
(fn [ea]
|
||||
(remove-nils
|
||||
{:general-ledger/source "invoice"
|
||||
:general-ledger/client (:db/id (:invoice/client entity))
|
||||
:general-ledger/date (:invoice/date entity)
|
||||
:general-ledger/original-entity (:db/id entity)
|
||||
:general-ledger/vendor (:db/id (:invoice/vendor entity))
|
||||
:general-ledger/amount (- (:invoice-expense-account/amount ea))
|
||||
:general-ledger/location (:invoice-expense-account/location ea)
|
||||
:general-ledger/from-expense-account 2110
|
||||
:general-ledger/to-expense-account (:invoice-expense-account/expense-account-id ea)
|
||||
:general-ledger/cleared (and (< (:invoice/outstanding-balance entity) 0.01)
|
||||
(every? #(= :payment-status/cleared (:payment/status %)) (:invoice/payments entity))
|
||||
)}))
|
||||
(:invoice/expense-accounts entity))))
|
||||
(remove-nils
|
||||
{:journal-entry/source "invoice"
|
||||
:journal-entry/client (:db/id (:invoice/client entity))
|
||||
:journal-entry/date (:invoice/date entity)
|
||||
:journal-entry/original-entity (:db/id entity)
|
||||
:journal-entry/vendor (:db/id (:invoice/vendor entity))
|
||||
:journal-entry/amount (:invoice/total entity)
|
||||
|
||||
:journal-entry/line-items (mapcat (fn [ea]
|
||||
[{:journal-entry-line/expense-account 2110
|
||||
:journal-entry-line/location (:invoice-expense-account/location ea)
|
||||
:journal-entry-line/debit (:invoice-expense-account/amount ea)}
|
||||
{:journal-entry-line/expense-account (:invoice-expense-account/expense-account-id ea)
|
||||
:journal-entry-line/location (:invoice-expense-account/location ea)
|
||||
:journal-entry-line/credit (:invoice-expense-account/amount ea)}
|
||||
])
|
||||
(:invoice/expense-accounts entity))
|
||||
#_#_:general-ledger/from-expense-account 2110
|
||||
#_#_:general-ledger/to-expense-account (:invoice-expense-account/expense-account-id ea)
|
||||
:journal-entry/cleared (and (< (:invoice/outstanding-balance entity) 0.01)
|
||||
(every? #(= :payment-status/cleared (:payment/status %)) (:invoice/payments entity))
|
||||
)})))
|
||||
|
||||
(defmethod entity-change->ledger :invoice-expense-account
|
||||
[db [entity changes]]
|
||||
@@ -61,10 +66,11 @@
|
||||
[entity-id (infer-entity changes)])
|
||||
|
||||
(defn ledger-entries->transaction [entries]
|
||||
(into [[:replace-general-ledger (:general-ledger/original-entity (first entries))]]
|
||||
(into [[:replace-general-ledger (:journal-entry/original-entity (first entries))]]
|
||||
entries))
|
||||
|
||||
(defn process-one [report-queue]
|
||||
(println report-queue)
|
||||
(let [transaction (.take report-queue)
|
||||
db (:db-after transaction)
|
||||
affected-entities (->> (:tx-data transaction)
|
||||
@@ -81,10 +87,13 @@
|
||||
(filter seq))
|
||||
retractions (map (fn [[_ e]] [:replace-general-ledger e]) affected-entities)]
|
||||
|
||||
@(d/transact (d/connect uri) retractions)
|
||||
(when (seq retractions)
|
||||
@(d/transact (d/connect uri) retractions))
|
||||
(println retractions d-txs)
|
||||
|
||||
(doseq [d-tx d-txs]
|
||||
(println "updating general-ledger " d-tx)
|
||||
(clojure.pprint/pprint d-tx)
|
||||
#_(println "updating general-ledger " d-tx)
|
||||
@(d/transact (d/connect uri) d-tx))))
|
||||
|
||||
(defn process-all []
|
||||
@@ -93,10 +102,11 @@
|
||||
|
||||
|
||||
|
||||
#_(process-one)
|
||||
#_(process-one (d/tx-report-queue (d/connect uri) ))
|
||||
|
||||
#_(process-all)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user