huge number of changes to start making all usages of expense accounts dynamic.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
{:invoice/client [:client/name :db/id :client/locations :client/code]}
|
||||
{:invoice/vendor [* {:vendor/address [*]}]}
|
||||
{:invoice/status [:db/ident]}
|
||||
{:invoice/expense-accounts [* {:invoice-expense-account/account [*]}]}
|
||||
{:invoice-payment/_invoice [* {:invoice-payment/payment [* {:payment/status [*]}
|
||||
{:payment/bank-account [*]}
|
||||
{:transaction/_payment [*]}]}]}]))
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
:auto-ap/add-general-ledger-fns2 {:txes-fn 'auto-ap.datomic.migrate.add-general-ledger/add-general-ledger-fns :requires [:auto-ap/add-general-ledger6]}
|
||||
:auto-ap/add-accounts {:txes auto-ap.datomic.migrate.add-general-ledger/add-accounts :requires [:auto-ap/add-general-ledger-fns2]}
|
||||
:auto-ap/add-transaction-account {:txes auto-ap.datomic.migrate.add-general-ledger/add-transaction-account :requires [:auto-ap/add-general-ledger-fns2]}
|
||||
:auto-ap/change-expense-account-to-entity {:txes auto-ap.datomic.migrate.add-general-ledger/change-expense-account-to-entity :requires [:auto-ap/add-transaction-account]}
|
||||
:auto-ap/add-account-to-vendor {:txes auto-ap.datomic.migrate.add-general-ledger/add-account-to-vendor :requires [:auto-ap/add-transaction-account]}
|
||||
#_#_:auto-ap/bulk-load-invoice-ledger2 {:txes-fn 'auto-ap.datomic.migrate.add-general-ledger/bulk-load-invoice-ledger :requires [:auto-ap/make-entity-not-unique]}
|
||||
|
||||
}]
|
||||
|
||||
@@ -145,6 +145,16 @@
|
||||
|
||||
#_(bulk-load-invoice-ledger (d/connect auto-ap.datomic/uri))
|
||||
|
||||
(def change-expense-account-to-entity
|
||||
[[{:db/ident :invoice-expense-account/account
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "The account entity that this expense is for"}]])
|
||||
|
||||
|
||||
|
||||
(def add-account-to-vendor
|
||||
[[{:db/ident :vendor/default-account
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "The account will be used when a bill is created."}]])
|
||||
|
||||
@@ -23,16 +23,11 @@
|
||||
|
||||
(defn get-by-id [id]
|
||||
|
||||
(->> (d/q '[:find (pull ?e [*])
|
||||
(->> (d/q '[:find (pull ?e [* {:default-account [:account/name :db/id :account/location]}])
|
||||
:in $ ?e
|
||||
:where [?e]]
|
||||
(d/db (d/connect uri))
|
||||
id)
|
||||
(map first)
|
||||
(first)
|
||||
#_(map (fn [c]
|
||||
(update c :client/bank-accounts
|
||||
(fn [bas]
|
||||
(map (fn [ba]
|
||||
(update ba :bank-account/type :db/ident ))
|
||||
bas)))))))
|
||||
))
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
:secondary_contact {:type :contact}
|
||||
:address {:type :address}
|
||||
|
||||
:default_expense_account {:type 'Int}
|
||||
:default_account {:type :account}
|
||||
:invoice_reminder_schedule {:type 'String}}}
|
||||
:reminder
|
||||
{:fields {:id {:type 'Int}
|
||||
@@ -196,6 +196,7 @@
|
||||
:invoices_expense_accounts
|
||||
{:fields {:id {:type :id}
|
||||
:invoice_id {:type 'String}
|
||||
:account {:type :account}
|
||||
:expense_account_id {:type 'Int}
|
||||
:location {:type 'String}
|
||||
:expense_account {:type :expense_account
|
||||
@@ -250,8 +251,7 @@
|
||||
:check_result {:fields {:invoices {:type '(list :invoice)}
|
||||
:pdf_url {:type 'String}}}
|
||||
|
||||
:expense_account_stat {:fields {:expense_account_id {:type 'Int}
|
||||
:expense_account_name {:type 'String}
|
||||
:expense_account_stat {:fields {:account {:type :account}
|
||||
:total {:type 'String}}}
|
||||
|
||||
:invoice_stat {:fields {:name {:type 'String}
|
||||
@@ -392,12 +392,12 @@
|
||||
:secondary_contact {:type :add_contact}
|
||||
:address {:type :add_address}
|
||||
|
||||
:default_expense_account {:type 'Int}
|
||||
:default_account_id {:type :id}
|
||||
:invoice_reminder_schedule {:type 'String}}}
|
||||
|
||||
:edit_expense_account
|
||||
{:fields {:id {:type :id}
|
||||
:expense_account_id {:type 'Int}
|
||||
:account_id {:type :id}
|
||||
:location {:type 'String}
|
||||
:amount {:type 'String}}}
|
||||
|
||||
@@ -581,7 +581,7 @@
|
||||
(:type args))))
|
||||
|
||||
(defn get-expense-account-stats [context {:keys [client_id] } value]
|
||||
(let [result (cond-> {:query {:find ['?expense-account-id '(sum ?amount)]
|
||||
(let [result (cond-> {:query {:find ['?account '?account-name '(sum ?amount)]
|
||||
:in ['$]
|
||||
:where []}
|
||||
:args [(d/db (d/connect uri)) client_id]}
|
||||
@@ -592,13 +592,13 @@
|
||||
|
||||
true (merge-query {:query {:where ['[?i :invoice/client ?c]
|
||||
'[?i :invoice/expense-accounts ?expense-account]
|
||||
'[?expense-account :invoice-expense-account/expense-account-id ?expense-account-id]
|
||||
'[?expense-account :invoice-expense-account/account ?account]
|
||||
'[?account :account/name ?account-name]
|
||||
'[?expense-account :invoice-expense-account/amount ?amount]]}})
|
||||
true (doto println)
|
||||
|
||||
true (d/query ))]
|
||||
(for [[expense-account-id total] result]
|
||||
{:expense_account_id expense-account-id :total total :expense_account_name (-> expense-account-id e-expense-accounts/expense-accounts :name)})))
|
||||
(for [[account-id account-name total] result]
|
||||
{:account {:id account-id :name account-name} :total total })))
|
||||
|
||||
(defn categorize [x]
|
||||
(cond (<= x 0) :due
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.datomic.invoices :as d-invoices]
|
||||
[auto-ap.datomic.accounts :as d-accounts]
|
||||
[auto-ap.expense-accounts :as expense-accounts]
|
||||
[auto-ap.graphql.checks :as gq-checks]
|
||||
[auto-ap.time :refer [parse iso-date]]
|
||||
@@ -53,8 +54,8 @@
|
||||
|
||||
(defn add-invoice-transaction [{:keys [total invoice_number location client_id vendor_id vendor_name date] :as in}]
|
||||
(let [vendor (d-vendors/get-by-id vendor_id)
|
||||
expense-account-id (:vendor/default-expense-account vendor)
|
||||
_ (when-not expense-account-id
|
||||
account (:vendor/default-account vendor)
|
||||
_ (when-not (:db/id account)
|
||||
(throw (ex-info (str "Vendor '" (:vendor/name vendor) "' does not have a default expense acount.") {:vendor-id vendor_id} )))]
|
||||
{:db/id "invoice"
|
||||
:invoice/invoice-number invoice_number
|
||||
@@ -65,8 +66,8 @@
|
||||
:invoice/outstanding-balance total
|
||||
:invoice/status :invoice-status/unpaid
|
||||
:invoice/date (coerce/to-date date)
|
||||
:invoice/expense-accounts [{:invoice-expense-account/expense-account-id expense-account-id
|
||||
:invoice-expense-account/location (get-in expense-accounts/expense-accounts [expense-account-id :location] location)
|
||||
:invoice/expense-accounts [{:invoice-expense-account/account (:db/id account)
|
||||
:invoice-expense-account/location (:account/location account location)
|
||||
:invoice-expense-account/amount total}]}))
|
||||
|
||||
(defn add-invoice [context {{:keys [total invoice_number location client_id vendor_id vendor_name date] :as in} :invoice} value]
|
||||
@@ -188,12 +189,12 @@
|
||||
|
||||
deleted (set/difference existing-ids specified-ids)
|
||||
updated (map
|
||||
(fn [{:keys [id expense_account_id amount location]}]
|
||||
(fn [{:keys [id account_id amount location]}]
|
||||
{:db/id invoice-id
|
||||
:invoice/expense-accounts [#:invoice-expense-account {
|
||||
:amount (Double/parseDouble amount)
|
||||
:db/id id
|
||||
:expense-account-id expense_account_id
|
||||
:account account_id
|
||||
:location location}
|
||||
]}
|
||||
)
|
||||
|
||||
@@ -8,14 +8,15 @@
|
||||
[clojure.set :as set]))
|
||||
|
||||
|
||||
(defn upsert-vendor [context {{:keys [id name code print_as primary_contact secondary_contact address default_expense_account invoice_reminder_schedule] :as in} :vendor} value]
|
||||
(let [transaction [(remove-nils #:vendor {:db/id (if id
|
||||
(defn upsert-vendor [context {{:keys [id name code print_as primary_contact secondary_contact address default_account_id invoice_reminder_schedule] :as in} :vendor} value]
|
||||
(let [_ (println default_account_id)
|
||||
transaction [(remove-nils #:vendor {:db/id (if id
|
||||
id
|
||||
"vendor")
|
||||
:name name
|
||||
:code code
|
||||
:print-as print_as
|
||||
:default-expense-account default_expense_account
|
||||
:default-account default_account_id
|
||||
:invoice-reminder-schedule (keyword invoice_reminder_schedule)
|
||||
:address (when address
|
||||
(remove-nils #:address {:db/id (if (:id address)
|
||||
|
||||
@@ -45,14 +45,11 @@
|
||||
:journal-entry/line-items (into [{:journal-entry-line/account (a/get-account-by-numeric-code-and-sets 2110 ["default"])
|
||||
:journal-entry-line/credit (:invoice/total entity)}]
|
||||
(map (fn [ea]
|
||||
{:journal-entry-line/account (a/get-account-by-numeric-code-and-sets
|
||||
(:invoice-expense-account/expense-account-id ea)
|
||||
["default"])
|
||||
{:journal-entry-line/account (:db/id (:invoice-expense-account/account ea))
|
||||
:journal-entry-line/location (:invoice-expense-account/location ea)
|
||||
:journal-entry-line/debit (: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))
|
||||
)})))
|
||||
@@ -76,8 +73,7 @@
|
||||
:journal-entry-line/location "HQ"
|
||||
:journal-entry-line/credit (Math/abs (:transaction/amount entity))}
|
||||
]
|
||||
#_#_:general-ledger/from-expense-account 2110
|
||||
#_#_:general-ledger/to-expense-account (:invoice-expense-account/expense-account-id ea)
|
||||
|
||||
:journal-entry/cleared true})))
|
||||
|
||||
(defmethod entity-change->ledger :invoice-expense-account
|
||||
|
||||
Reference in New Issue
Block a user