Balance sheet has correct data, needs formatting.
This commit is contained in:
@@ -128,8 +128,8 @@
|
||||
:requires [:auto-ap/convert-invoices]}
|
||||
:auto-ap/add-yodlee-merchant2 {:txes add-general-ledger/add-yodlee-merchant :requires [:auto-ap/convert-transactions]}
|
||||
|
||||
#_#_:auto-ap/bulk-load-invoice-ledger3 {:txes-fn `add-general-ledger/bulk-load-invoice-ledger :requires [:auto-ap/convert-transactions]}
|
||||
#_#_:auto-ap/bulk-load-transaction-ledger3 {:txes-fn `add-general-ledger/bulk-load-transaction-ledger :requires [:auto-ap/convert-transactions]}
|
||||
:auto-ap/bulk-load-invoice-ledger3 {:txes-fn `add-general-ledger/bulk-load-invoice-ledger :requires [:auto-ap/convert-transactions]}
|
||||
:auto-ap/bulk-load-transaction-ledger3 {:txes-fn `add-general-ledger/bulk-load-transaction-ledger :requires [:auto-ap/convert-transactions]}
|
||||
|
||||
}]
|
||||
(println "Conforming database...")
|
||||
|
||||
@@ -153,16 +153,19 @@
|
||||
{:db/ident :account-type/asset}
|
||||
{:db/ident :account-type/equity}]
|
||||
|
||||
(mapv
|
||||
(fn [[numeric {:keys [name location]}]]
|
||||
(remove-nils
|
||||
{:account/type :account-type/expense
|
||||
:account/numeric-code numeric
|
||||
:account/code (str numeric)
|
||||
:account/name name
|
||||
:account/location location
|
||||
:account/account-set "default"}))
|
||||
expense-accounts/chooseable-expense-accounts)])
|
||||
(->> expense-accounts/chooseable-expense-accounts
|
||||
(filter (fn [[numeric]]
|
||||
(not (#{0 2100 5800 9600 1300 8200 7400 8500 2400 8800 1400 2500 7200 1200 1600 1500 3300 9800 9200 2800 1100 5700 2600 9300 9500 8100 7500 7100 2700} numeric))))
|
||||
|
||||
(mapv
|
||||
(fn [[numeric {:keys [name location]}]]
|
||||
(remove-nils
|
||||
{:account/type :account-type/expense
|
||||
:account/numeric-code numeric
|
||||
:account/code (str numeric)
|
||||
:account/name name
|
||||
:account/location location
|
||||
:account/account-set "default"}))))])
|
||||
|
||||
(defn add-general-ledger-fns [conn]
|
||||
[[{:db/ident :replace-general-ledger
|
||||
@@ -248,18 +251,21 @@
|
||||
invoice-expense-accounts)]))
|
||||
|
||||
(defn convert-transactions [conn]
|
||||
(let [matched-transactions (d/query {:query {:find '[?transaction ?v]
|
||||
(let [matched-transactions (d/query {:query {:find '[?transaction ?v ?amount]
|
||||
:in '[$]
|
||||
:where ['[?transaction :transaction/payment ?payment]
|
||||
'[?transaction :transaction/amount ?amount]
|
||||
'[?payment :payment/invoices ?i]
|
||||
'[?i :invoice/vendor ?v]]}
|
||||
:args [(d/db (d/connect auto-ap.datomic/uri))]})]
|
||||
[(mapv
|
||||
(fn [[transaction-id vendor-id]]
|
||||
(fn [[transaction-id vendor-id amount]]
|
||||
(remove-nils {:db/id transaction-id
|
||||
:transaction/vendor vendor-id
|
||||
:transaction/location "A"
|
||||
:transaction/account (:db/id (accounts/get-account-by-numeric-code-and-sets 2110 ["default"]))
|
||||
:transaction/accounts [#:transaction-account {:account (:db/id (accounts/get-account-by-numeric-code-and-sets 2110 ["default"]))
|
||||
:location "A"
|
||||
:amount (Math/abs amount)}]
|
||||
}))
|
||||
matched-transactions)]))
|
||||
|
||||
|
||||
@@ -66,17 +66,15 @@
|
||||
:bank_name {:type 'String}
|
||||
:yodlee_account_id {:type 'Int}}}
|
||||
:balance_sheet_account
|
||||
{:fields {
|
||||
{:fields {:id {:type 'String}
|
||||
:amount {:type 'String}
|
||||
:numeric_code {:type 'Int}
|
||||
:account_type {:type :account_type}
|
||||
:name {:type 'String}}}
|
||||
|
||||
:balance_sheet_grouping
|
||||
{:fields {:accounts {:type '(list :balance_sheet_account)}
|
||||
:name {:type 'String}
|
||||
:grouping_type {:type 'String}}}
|
||||
|
||||
:balance_sheet
|
||||
{:fields {:balance_sheet_groupings {:type '(list :balance_sheet_grouping)}}}
|
||||
{:fields {:balance_sheet_accounts {:type '(list :balance_sheet_account)}
|
||||
:comparable_balance_sheet_accounts {:type '(list :balance_sheet_account)}}}
|
||||
|
||||
:address
|
||||
{:fields {:street1 {:type 'String}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
(ns auto-ap.graphql.ledger
|
||||
(:require [auto-ap.datomic :refer [uri]]
|
||||
[auto-ap.datomic.ledger :as l]
|
||||
[auto-ap.time :refer [parse iso-date]]
|
||||
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.string :as str]
|
||||
[datomic.api :as d]))
|
||||
[clj-time.core :as time]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.parse.templates :as t]))
|
||||
|
||||
(defn get-ledger-page [context args value]
|
||||
(let [args (assoc args :id (:id context))
|
||||
@@ -15,6 +18,8 @@
|
||||
:count (count journal-entries)
|
||||
:start (:start args 0)
|
||||
:end (+ (:start args 0) (count journal-entries))}))
|
||||
|
||||
;; TODO a better way to do this might be to accumulate ALL credits and ALL debits, and then just do for credits: balance = credits - debits. and for debits balance = debits - credits
|
||||
(defn credit-account? [account]
|
||||
(or
|
||||
(#{:account-type/liability
|
||||
@@ -41,72 +46,51 @@
|
||||
(mapcat :journal-entry/line-items)
|
||||
(group-by :journal-entry-line/account)
|
||||
(reduce-kv (fn [result account line-items]
|
||||
(assoc result
|
||||
account
|
||||
{:name (or (:bank-account/name account) (:account/name account))
|
||||
:amount (reduce + 0 (map
|
||||
(fn [line-item]
|
||||
(cond
|
||||
(and (credit-account? account) (:journal-entry-line/debit line-item))
|
||||
(- (:journal-entry-line/debit line-item))
|
||||
;; TODO fix
|
||||
(when-not (or (:bank-account/name account) (:account/name account))
|
||||
(println "WARNING " account line-items))
|
||||
(conj result
|
||||
{:name (or (:bank-account/name account) (:account/name account))
|
||||
:id (:db/id account)
|
||||
:numeric-code (or (:account/numeric-code account)
|
||||
(and (:bank-account/type account)
|
||||
1100))
|
||||
:account-type (or (:db/ident (:account/type account))
|
||||
({:bank-account-type/check :asset
|
||||
:bank-account-type/credit :liability}
|
||||
(:db/ident (:bank-account/type account))))
|
||||
:amount (reduce + 0 (map
|
||||
(fn [line-item]
|
||||
(cond
|
||||
(and (credit-account? account) (:journal-entry-line/debit line-item))
|
||||
(- (:journal-entry-line/debit line-item))
|
||||
|
||||
(and (credit-account? account) (:journal-entry-line/credit line-item))
|
||||
(:journal-entry-line/credit line-item)
|
||||
(and (credit-account? account) (:journal-entry-line/credit line-item))
|
||||
(:journal-entry-line/credit line-item)
|
||||
|
||||
(and (debit-account? account) (:journal-entry-line/debit line-item))
|
||||
(:journal-entry-line/debit line-item)
|
||||
(and (debit-account? account) (:journal-entry-line/debit line-item))
|
||||
(:journal-entry-line/debit line-item)
|
||||
|
||||
(and (debit-account? account) (:journal-entry-line/credit line-item))
|
||||
(- (:journal-entry-line/credit line-item))
|
||||
(and (debit-account? account) (:journal-entry-line/credit line-item))
|
||||
(- (:journal-entry-line/credit line-item))
|
||||
|
||||
:else
|
||||
0))
|
||||
line-items))}))
|
||||
{})))
|
||||
:else
|
||||
0))
|
||||
line-items))}))
|
||||
[])))
|
||||
|
||||
(defn get-balance-sheet [context args value]
|
||||
(let [args (assoc args :id (:id context))
|
||||
[results] (l/get-graphql {:client-id (:client_id args)
|
||||
:date-before (coerce/to-date (:date args))
|
||||
:count Integer/MAX_VALUE})
|
||||
accounts (roll-up results)
|
||||
accounts (reduce-kv
|
||||
|
||||
(fn [result account line-item]
|
||||
(update-in result [(cond
|
||||
(expense-account? account)
|
||||
"Expenses"
|
||||
|
||||
(credit-account? account)
|
||||
"Liabilities"
|
||||
(debit-account? account)
|
||||
"Assets")
|
||||
|
||||
(if (credit-account? account)
|
||||
"Accounts Payable"
|
||||
"1100 Cash and Bank Accounts" )
|
||||
]
|
||||
conj
|
||||
line-item
|
||||
))
|
||||
{}
|
||||
accounts)
|
||||
]
|
||||
[comparable-results] (l/get-graphql {:client-id (:client_id args)
|
||||
:date-before (coerce/to-date (time/minus (parse (:date args) iso-date) (time/months 1)))
|
||||
:count Integer/MAX_VALUE})]
|
||||
(->graphql
|
||||
{:balance-sheet-groupings
|
||||
(-> []
|
||||
(into (->> (get accounts "Assets")
|
||||
(map (fn [[n accounts]]
|
||||
{:name n
|
||||
:grouping-type "Assets"
|
||||
:accounts accounts}
|
||||
))))
|
||||
(into (->> (get accounts "Liabilities")
|
||||
(map (fn [[n accounts]]
|
||||
{:name n
|
||||
:grouping-type "Liabilities"
|
||||
:accounts accounts}
|
||||
)))))})))
|
||||
{:balance-sheet-accounts (roll-up results)
|
||||
:comparable-balance-sheet-accounts (roll-up comparable-results)})))
|
||||
|
||||
|
||||
(defn get-profit-and-loss [context args value]
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
decreasing? (< (:transaction/amount entity) 0.0)
|
||||
credit-from-bank? decreasing?
|
||||
debit-from-bank? (not decreasing?)]
|
||||
(println "processing entity" entity)
|
||||
|
||||
(when (:transaction/vendor entity)
|
||||
(remove-nils
|
||||
{:journal-entry/source "transaction"
|
||||
|
||||
Reference in New Issue
Block a user