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 [] (defn drop-database []
(d/delete-database uri)) (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] (defn remove-nils [m]
(let [result (reduce-kv (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/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-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-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]} #_#_: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 (ns auto-ap.datomic.migrate.add-general-ledger
(:require [datomic.api :as d] (:require [datomic.api :as d]
[auto-ap.datomic :refer [remove-nils]]
[auto-ap.expense-accounts :as expense-accounts]
[auto-ap.ledger :as ledger])) [auto-ap.ledger :as ledger]))
(def add-general-ledger (def add-general-ledger
@@ -62,6 +64,55 @@
:db/doc "Location of the entry"}] :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] (defn add-general-ledger-fns [conn]
[[{:db/ident :replace-general-ledger [[{:db/ident :replace-general-ledger

View File

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

View File

@@ -17,6 +17,7 @@
[auto-ap.datomic.invoices :as d-invoices] [auto-ap.datomic.invoices :as d-invoices]
[auto-ap.datomic.vendors :as d-vendors] [auto-ap.datomic.vendors :as d-vendors]
[auto-ap.graphql.users :as gq-users] [auto-ap.graphql.users :as gq-users]
[auto-ap.graphql.accounts :as gq-accounts]
[auto-ap.graphql.clients :as gq-clients] [auto-ap.graphql.clients :as gq-clients]
[auto-ap.graphql.vendors :as gq-vendors] [auto-ap.graphql.vendors :as gq-vendors]
[auto-ap.graphql.checks :as gq-checks] [auto-ap.graphql.checks :as gq-checks]
@@ -157,6 +158,13 @@
:parent {:type :expense_account :parent {:type :expense_account
:resolve :get-expense-account-parent}}} :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 :invoices_expense_accounts
{:fields {:id {:type :id} {:fields {:id {:type :id}
:invoice_id {:type 'String} :invoice_id {:type 'String}
@@ -214,10 +222,7 @@
:invoice_stat {:fields {:name {:type 'String} :invoice_stat {:fields {:name {:type 'String}
:paid {:type 'String} :paid {:type 'String}
:unpaid {:type 'String}}} :unpaid {:type 'String}}}}
}
@@ -249,6 +254,10 @@
:statuses {:type '(list String)}} :statuses {:type '(list String)}}
:resolve :get-all-invoices} :resolve :get-all-invoices}
:accounts {:type '(list :account)
:args {:account_set {:type 'String}}
:resolve :get-accounts}
:all_payments {:type '(list :payment) :all_payments {:type '(list :payment)
:args {:client_id {:type :id} :args {:client_id {:type :id}
:client_code {:type 'String} :client_code {:type 'String}
@@ -569,6 +578,7 @@
:get-all-invoices gq-invoices/get-all-invoices :get-all-invoices gq-invoices/get-all-invoices
:get-all-payments get-all-payments :get-all-payments get-all-payments
:get-payment-page gq-checks/get-payment-page :get-payment-page gq-checks/get-payment-page
:get-accounts gq-accounts/get-accounts
:get-transaction-page gq-transactions/get-transaction-page :get-transaction-page gq-transactions/get-transaction-page
:get-expense-account-stats get-expense-account-stats :get-expense-account-stats get-expense-account-stats
:get-invoice-stats get-invoice-stats :get-invoice-stats get-invoice-stats
@@ -634,3 +644,5 @@
(println e)) (println e))
(throw 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] ] [: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]]]] [:address [:street1 :street2 :city :state :zip]]]]
[:vendor [: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]}})))) :on-success [::received-initial]}}))))
(def vendor-query (def vendor-query
[:id :name :default-expense-account [:id :name :default-expense-account
@@ -67,7 +67,8 @@
:query-obj {:venia/queries [[:client :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] ]]] [: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 [: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]} :on-success [::received-initial]}
:db (assoc db :user (assoc user :token token))})) :db (assoc db :user (assoc user :token token))}))