adding accounts.

This commit is contained in:
Bryce Covert
2019-04-11 10:04:59 -07:00
parent 89ae2151ea
commit bde4bb4ecb
6 changed files with 83 additions and 18 deletions

View File

@@ -20,6 +20,13 @@
(defn drop-database []
(d/delete-database uri))
(defn merge-query [query-part-1 query-part-2]
(-> query-part-1
(update-in [:query :find] into (get-in query-part-2 [:query :find]))
(update-in [:query :in] into (get-in query-part-2 [:query :in]))
(update-in [:query :where] into (get-in query-part-2 [:query :where]))
(update-in [:args] into (get-in query-part-2 [:args]))))
(defn remove-nils [m]
(let [result (reduce-kv

View File

@@ -81,6 +81,7 @@
:auto-ap/make-every-account-visible {:txes-fn 'auto-ap.datomic.migrate.account-sorting/make-every-account-visible :requires [:auto-ap/add-account-visibility-fields]}
:auto-ap/add-general-ledger6 {:txes add-general-ledger/add-general-ledger :requires [:auto-ap/make-every-account-visible]}
: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/bulk-load-invoice-ledger2 {:txes-fn 'auto-ap.datomic.migrate.add-general-ledger/bulk-load-invoice-ledger :requires [:auto-ap/make-entity-not-unique]}
}]

View File

@@ -1,5 +1,7 @@
(ns auto-ap.datomic.migrate.add-general-ledger
(:require [datomic.api :as d]
[auto-ap.datomic :refer [remove-nils]]
[auto-ap.expense-accounts :as expense-accounts]
[auto-ap.ledger :as ledger]))
(def add-general-ledger
@@ -62,6 +64,55 @@
:db/doc "Location of the entry"}]
]
)
(def add-accounts
[[
{:db/ident :account/code
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The code for the expense account (e.g., A1123)"}
{:db/ident :account/numeric-code
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one
:db/doc "The numeric-only for the expense account (e.g., 5150)"}
{:db/ident :account/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The name of the code (e.g., \"Telephone - HQ\")"}
{:db/ident :account/location
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "A forced location for this code, e.g., HQ."}
{:db/ident :account/account-set
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The set of accounts this entry belongs to. Allows customization."}
{:db/ident :account/type
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The type of account, (e.g., :account-type/expense :account-type/liability)"}
{:db/ident :account-type/expense}
{:db/ident :account-type/liability}
{:db/ident :account-type/revenue}
{:db/ident :account-type/dividend}
{: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)])
(defn add-general-ledger-fns [conn]
[[{:db/ident :replace-general-ledger

View File

@@ -1,6 +1,6 @@
(ns auto-ap.datomic.transactions
(:require [datomic.api :as d]
[auto-ap.datomic :refer [uri]]
[auto-ap.datomic :refer [uri merge-query]]
[auto-ap.graphql.utils :refer [limited-clients]]
[clj-time.coerce :as c]))
@@ -29,13 +29,6 @@
(update-in [:query :where] conj where))]
(reduce #(update-in %1 [:query :where] conj %2) query rest)))
(defn merge-query [query-part-1 query-part-2]
(-> query-part-1
(update-in [:query :find] into (get-in query-part-2 [:query :find]))
(update-in [:query :in] into (get-in query-part-2 [:query :in]))
(update-in [:query :where] into (get-in query-part-2 [:query :where]))
(update-in [:args] into (get-in query-part-2 [:args]))))
(defn add-sorter-field [q sort-map args]
(merge-query q
{:query {:find ['?sorter]

View File

@@ -17,6 +17,7 @@
[auto-ap.datomic.invoices :as d-invoices]
[auto-ap.datomic.vendors :as d-vendors]
[auto-ap.graphql.users :as gq-users]
[auto-ap.graphql.accounts :as gq-accounts]
[auto-ap.graphql.clients :as gq-clients]
[auto-ap.graphql.vendors :as gq-vendors]
[auto-ap.graphql.checks :as gq-checks]
@@ -157,6 +158,13 @@
:parent {:type :expense_account
:resolve :get-expense-account-parent}}}
:account {:fields {:id {:type :id}
:numeric_code {:type 'Int}
:type {:type :ident}
:account_set {:type 'String}
:location {:type 'String}
:name {:type 'String}}}
:invoices_expense_accounts
{:fields {:id {:type :id}
:invoice_id {:type 'String}
@@ -214,12 +222,9 @@
:invoice_stat {:fields {:name {:type 'String}
:paid {:type 'String}
:unpaid {:type 'String}}}
}
:unpaid {:type 'String}}}}
:queries
{:expense_account_stats {:type '(list :expense_account_stat)
@@ -249,6 +254,10 @@
:statuses {:type '(list String)}}
:resolve :get-all-invoices}
:accounts {:type '(list :account)
:args {:account_set {:type 'String}}
:resolve :get-accounts}
:all_payments {:type '(list :payment)
:args {:client_id {:type :id}
:client_code {:type 'String}
@@ -569,6 +578,7 @@
:get-all-invoices gq-invoices/get-all-invoices
:get-all-payments get-all-payments
:get-payment-page gq-checks/get-payment-page
:get-accounts gq-accounts/get-accounts
:get-transaction-page gq-transactions/get-transaction-page
:get-expense-account-stats get-expense-account-stats
:get-invoice-stats get-invoice-stats
@@ -616,7 +626,7 @@
:else
node))
m))
(defn query
([id q]
(query id q nil ))
@@ -627,10 +637,12 @@
(when (seq (:errors result))
(throw (ex-info "GraphQL error" {:result result})))
result)
(catch Exception e
(if-let [v (:validation-error (ex-data e))]
(println "validation error" v)
(println e))
(throw e)))))
#_(query nil "{ accounts(account_set: \"default\") { numeric_code, name }}" nil)

View File

@@ -45,8 +45,8 @@
[:id :name :code :email :locations [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id] ]
[:address [:street1 :street2 :city :state :zip]]]]
[:vendor
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]
[:accounts [:numeric-code :name :type :account_set]]]}
:on-success [::received-initial]}}))))
(def vendor-query
[:id :name :default-expense-account
@@ -67,7 +67,8 @@
:query-obj {:venia/queries [[:client
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id] ]]]
[:vendor
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]
[:accounts [:numeric-code :name :type :account_set]]]}
:on-success [::received-initial]}
:db (assoc db :user (assoc user :token token))}))