everything is now looked up through datomic

This commit is contained in:
Bryce Covert
2018-08-16 07:13:29 -07:00
parent a25232a195
commit 202ed6b0e2
5 changed files with 57 additions and 71 deletions

View File

@@ -512,6 +512,7 @@
(d/transact (d/connect uri)))) (d/transact (d/connect uri))))
(defn load-entities [] (defn load-entities []
(d/transact (d/connect uri) (d/transact (d/connect uri)
[{:db/ident :test [{:db/ident :test
@@ -555,7 +556,7 @@
(map (map
(fn [{:keys [name address id code locations email bank-accounts signature-file] client-id :id}] (fn [{:keys [name address id code locations email bank-accounts signature-file] client-id :id}]
(remove-nils #:client {:original-id id (remove-nils #:client {:original-id id
:name (str name "-test") :name (str name)
:code nil :code nil
:email email :email email
:signature-file signature-file :signature-file signature-file
@@ -706,7 +707,7 @@
(d/db (d/connect uri)))) (d/db (d/connect uri))))
(defn query-check-payments [] (defn query-check-payments []
(d/q '[:find (pull ?e [*]) (d/q '[:find (pull ?e [* {:invoice-payment/payment [*]}])
:where [?e :invoice-payment/original-id]] :where [?e :invoice-payment/original-id]]
(d/db (d/connect uri)))) (d/db (d/connect uri))))

View File

@@ -2,7 +2,7 @@
(:require [datomic.api :as d] (:require [datomic.api :as d]
[auto-ap.datomic :refer [uri]])) [auto-ap.datomic :refer [uri]]))
(defn get-graphql [] (defn get-graphql [args]
(->> (d/q '[:find (pull ?e [*]) (->> (d/q '[:find (pull ?e [*])
:where [?e :vendor/name]] :where [?e :vendor/name]]

View File

@@ -12,6 +12,7 @@
[auto-ap.db.vendors :as vendors] [auto-ap.db.vendors :as vendors]
[auto-ap.db.companies :as companies] [auto-ap.db.companies :as companies]
[auto-ap.datomic.clients :as d-clients] [auto-ap.datomic.clients :as d-clients]
[auto-ap.datomic.invoices :as d-invoices]
[auto-ap.datomic.vendors :as d-vendors] [auto-ap.datomic.vendors :as d-vendors]
[auto-ap.db.users :as users] [auto-ap.db.users :as users]
[auto-ap.db.checks :as checks] [auto-ap.db.checks :as checks]
@@ -97,10 +98,8 @@
:check {:fields {:id {:type 'Int} :check {:fields {:id {:type 'Int}
:type {:type 'String} :type {:type 'String}
:amount {:type 'String} :amount {:type 'String}
:vendor {:type :vendor :vendor {:type :vendor}
:resolve :get-vendor-for-check} :company {:type :company}
:company {:type :company
:resolve :get-company-for-check}
:date {:type 'String} :date {:type 'String}
:bank_account {:type :bank_account :bank_account {:type :bank_account
:resolve :bank-account-for-check} :resolve :bank-account-for-check}
@@ -108,8 +107,7 @@
:s3_url {:type 'String} :s3_url {:type 'String}
:check_number {:type 'Int} :check_number {:type 'Int}
:status {:type 'String} :status {:type 'String}
:invoices {:type '(list :invoice_check) :invoices {:type '(list :invoice_payment)}
:resolve :get-checks-invoices}
}} }}
:payment {:fields {:id {:type 'String} :payment {:fields {:id {:type 'String}
@@ -124,8 +122,7 @@
:s3_url {:type 'String} :s3_url {:type 'String}
:check_number {:type 'Int} :check_number {:type 'Int}
:status {:type 'String} :status {:type 'String}
:invoices {:type '(list :invoice_check) :invoices {:type '(list :invoice_payment)}
:resolve :get-checks-invoices}
}} }}
:transaction {:fields {:id {:type 'String} :transaction {:fields {:id {:type 'String}
@@ -137,13 +134,12 @@
:payment {:type :payment} :payment {:type :payment}
:date {:type 'String} :date {:type 'String}
:post_date {:type 'String}}} :post_date {:type 'String}}}
:invoice_check :invoice_payment
{:fields {:id {:type 'Int} {:fields {:id {:type 'Int}
:amount {:type 'String} :amount {:type 'String}
:invoice_id {:type 'Int} :invoice_id {:type 'String}
:check_id {:type 'Int} :payment_id {:type 'String}
:check {:type :check :payment {:type :payment}}}
:resolve :get-check-by-id}}}
:user :user
{:fields {:id {:type 'Int} {:fields {:id {:type 'Int}
@@ -159,30 +155,27 @@
:resolve :get-expense-account-parent}}} :resolve :get-expense-account-parent}}}
:invoices_expense_accounts :invoices_expense_accounts
{:fields {:id {:type 'Int} {:fields {:id {:type 'String}
:invoice_id {:type 'Int} :invoice_id {:type 'String}
:expense_account_id {:type 'Int} :expense_account_id {:type 'Int}
:location {:type 'String} :location {:type 'String}
:expense_account {:type :expense_account :expense_account {:type :expense_account
:resolve :get-expense-account} :resolve :get-expense-account
}
:amount {:type 'String}}} :amount {:type 'String}}}
:invoice :invoice
{:fields {:id {:type 'Int} {:fields {:id {:type 'String}
:total {:type 'String} :total {:type 'String}
:outstanding_balance {:type 'String} :outstanding_balance {:type 'String}
:invoice_number {:type 'String} :invoice_number {:type 'String}
:expense_accounts {:type '(list :invoices_expense_accounts) :expense_accounts {:type '(list :invoices_expense_accounts)}
:resolve :get-invoices-expense-accounts}
:date {:type 'String} :date {:type 'String}
:company_id {:type 'Int} :company_id {:type 'Int}
:checks {:type '(list :invoice_check) :payments {:type '(list :invoice_payment)}
:resolve :get-invoices-checks} :vendor {:type :vendor}
:vendor {:type :vendor :client {:type :client}}}
:resolve :get-vendor-for-invoice}
:company {:type :company
:resolve :get-company-for-invoice}}}
:invoice_page {:fields {:invoices {:type '(list :invoice)} :invoice_page {:fields {:invoices {:type '(list :invoice)}
@@ -191,7 +184,7 @@
:start {:type 'Int} :start {:type 'Int}
:end {:type 'Int}}} :end {:type 'Int}}}
:check_page {:fields {:checks {:type '(list :payment)} :payment_page {:fields {:checks {:type '(list :payment)}
:count {:type 'Int} :count {:type 'Int}
:total {:type 'Int} :total {:type 'Int}
:start {:type 'Int} :start {:type 'Int}
@@ -217,7 +210,7 @@
{:invoice_page {:type '(list :invoice_page) {:invoice_page {:type '(list :invoice_page)
:args {:imported {:type 'Boolean} :args {:imported {:type 'Boolean}
:status {:type 'String} :status {:type 'String}
:company_id {:type 'Int} :client_id {:type 'String}
:start {:type 'Int} :start {:type 'Int}
:sort_by {:type 'String} :sort_by {:type 'String}
:asc {:type 'Boolean}} :asc {:type 'Boolean}}
@@ -228,7 +221,7 @@
:args {:company_id {:type 'Int}} :args {:company_id {:type 'Int}}
:resolve :get-all-invoices} :resolve :get-all-invoices}
:all_checks {:type '(list :check) :all_checks {:type '(list :payment)
:args {:company_id {:type 'Int}} :args {:company_id {:type 'Int}}
:resolve :get-all-checks} :resolve :get-all-checks}
@@ -240,7 +233,7 @@
:resolve :get-transaction-page} :resolve :get-transaction-page}
:check_page {:type '(list :check_page) :payment_page {:type '(list :payment_page)
:args {:company_id {:type 'Int} :args {:company_id {:type 'Int}
:start {:type 'Int} :start {:type 'Int}
:sort_by {:type 'String} :sort_by {:type 'String}
@@ -264,7 +257,7 @@
:input-objects :input-objects
{ {
:invoice_payment {:fields {:invoice_id {:type 'Int} :invoice_payment_amount {:fields {:invoice_id {:type 'String}
:amount {:type 'Float}}} :amount {:type 'Float}}}
:edit_user :edit_user
@@ -297,7 +290,7 @@
:mutations :mutations
{:print_checks {:type :check_result {:print_checks {:type :check_result
:args {:invoice_payments {:type '(list :invoice_payment)} :args {:invoice_payments {:type '(list :invoice_payment_amount)}
:bank_account_id {:type 'Int} :bank_account_id {:type 'Int}
:type {:type 'String} :type {:type 'String}
:company_id {:type 'Int}} :company_id {:type 'Int}}
@@ -370,21 +363,16 @@
(defn get-invoice-page [context args value] (defn get-invoice-page [context args value]
(let [args (assoc args :id (:id context)) (let [args (assoc args :id (:id context))
extra-context
(cond-> {}
(executor/selects-field? context :invoice/vendor) (assoc :vendor-cache (by :id (vendors/get-all)))
(executor/selects-field? context :invoice/company) (assoc :company-cache (by :id (companies/get-all))))
invoices (map invoices (map
->graphql ->graphql
(invoices/get-graphql (<-graphql (assoc args :id (:id context))))) (d-invoices/get-graphql (<-graphql (assoc args :id (:id context)))))
invoice-count (invoices/count-graphql (<-graphql args))] invoice-count (d-invoices/count-graphql (<-graphql args))]
(resolve/with-context
[{:invoices invoices [{:invoices invoices
:total invoice-count :total invoice-count
:count (count invoices) :count (count invoices)
:start (:start args 0) :start (:start args 0)
:end (+ (:start args 0) (count invoices))}] extra-context))) :end (+ (:start args 0) (count invoices))}]))
(defn get-all-invoices [context args value] (defn get-all-invoices [context args value]
@@ -475,7 +463,6 @@
(defn get-company [context args value] (defn get-company [context args value]
(println "GETTING COMPANY" (:id context))
(->graphql (->graphql
(filter #(can-see-company? (:id context) %) (filter #(can-see-company? (:id context) %)
(d-clients/get-all)))) (d-clients/get-all))))
@@ -500,7 +487,7 @@
(defn get-vendor [context args value] (defn get-vendor [context args value]
(->graphql (->graphql
(d-vendors/get-all))) (d-vendors/get-graphql args)))
(defn print-checks [context args value] (defn print-checks [context args value]
@@ -525,8 +512,6 @@
:get-transaction-page gq-transactions/get-transaction-page :get-transaction-page gq-transactions/get-transaction-page
:get-reminder-page get-reminder-page :get-reminder-page get-reminder-page
:get-vendor-for-invoice get-vendor-for-invoice :get-vendor-for-invoice get-vendor-for-invoice
:get-vendor-for-check gq-checks/get-vendor-for-check
:get-company-for-check gq-checks/get-company-for-check
:get-check-for-transaction gq-transactions/get-check-for-transaction :get-check-for-transaction gq-transactions/get-check-for-transaction
:get-company-for-invoice get-company-for-invoice :get-company-for-invoice get-company-for-invoice
:get-invoices-checks get-invoices-checks :get-invoices-checks get-invoices-checks

View File

@@ -41,13 +41,13 @@
(defn query [params] (defn query [params]
{:venia/queries [[:invoice_page {:venia/queries [[:invoice_page
(assoc params (assoc params
:company-id (:id @(re-frame/subscribe [::subs/company]))) :client-id (:id @(re-frame/subscribe [::subs/company])))
[[:invoices [:id :total :outstanding-balance :invoice-number :date [[:invoices [:id :total :outstanding-balance :invoice-number :date
[:vendor [:name :id]] [:vendor [:name :id]]
[:expense_accounts [:amount :id :expense_account_id :location [:expense_accounts [:amount :id :expense_account_id :location
[:expense_account [:id :name :location [:parent [:id :name]]]]]] [:expense_account [:id :name :location [:parent [:id :name]]]]]]
[:company [:name :id :locations]] [:client [:name :id :locations]]
[:checks [:amount [:check [:amount :s3_url :check_number ]]]] [:payments [:amount [:payment [:amount :s3_url :check_number ]]]]
]] ]]
:total :total
:start :start
@@ -86,10 +86,10 @@
(when-not selected-company (when-not selected-company
[sorted-column {:on-sort opc [sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"} :style {:width percentage-size :cursor "pointer"}
:sort-key "company" :sort-key "client"
:sort-by sort-by :sort-by sort-by
:asc asc} :asc asc}
"Company"]) "Client"])
[sorted-column {:on-sort opc [sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"} :style {:width percentage-size :cursor "pointer"}
:sort-key "vendor" :sort-key "vendor"
@@ -123,7 +123,7 @@
[sorted-column {:on-sort opc [sorted-column {:on-sort opc
:style {:width "10em" :cursor "pointer"} :style {:width "10em" :cursor "pointer"}
:sort-key "outstanding" :sort-key "outstanding-balance"
:sort-by sort-by :sort-by sort-by
:asc asc} :asc asc}
"Outstanding"] "Outstanding"]
@@ -139,7 +139,7 @@
[:tr [:tr
[:td {:col-span 5} [:td {:col-span 5}
[:i.fa.fa-spin.fa-spinner]]] [:i.fa.fa-spin.fa-spinner]]]
(for [{:keys [company checks expense-accounts invoice-number date total outstanding-balance id vendor] :as i} (:invoices @invoice-page)] (for [{:keys [client payments expense-accounts invoice-number date total outstanding-balance id vendor] :as i} (:invoices @invoice-page)]
^{:key id} ^{:key id}
[:tr {:class (:class i)} [:tr {:class (:class i)}
(when check-boxes (when check-boxes
@@ -150,7 +150,7 @@
:on-change (fn [x e] (when on-check-changed :on-change (fn [x e] (when on-check-changed
(on-check-changed id)))} ]]) (on-check-changed id)))} ]])
(when-not selected-company (when-not selected-company
[:td (:name company)]) [:td (:name client)])
[:td (:name vendor)] [:td (:name vendor)]
[:td invoice-number] [:td invoice-number]
[:td (date->str date) ] [:td (date->str date) ]
@@ -169,7 +169,7 @@
:aria-haspopup true :aria-haspopup true
:tab-index "0" :tab-index "0"
#_#_:on-blur (delayed-dispatch [::toggle-expense-accounts id]) :on-blur (delayed-dispatch [::toggle-expense-accounts id])
:on-focus (dispatch-event [::toggle-expense-accounts id]) :on-focus (dispatch-event [::toggle-expense-accounts id])
} "Accounts"]] } "Accounts"]]
[:div.dropdown-menu {:role "menu"} [:div.dropdown-menu {:role "menu"}
@@ -187,13 +187,13 @@
[:button.button {:on-click (fn [] (on-edit-invoice i))} [:span.icon [:i.fa.fa-pencil]]]) [:button.button {:on-click (fn [] (on-edit-invoice i))} [:span.icon [:i.fa.fa-pencil]]])
(when (and on-void-invoice (= (:outstanding-balance i) (:total i))) (when (and on-void-invoice (= (:outstanding-balance i) (:total i)))
[:button.button.is-warning.is-outlined {:on-click (fn [] (on-void-invoice i))} [:span [:span.icon [:i.fa.fa-minus-circle]]]]) [:button.button.is-warning.is-outlined {:on-click (fn [] (on-void-invoice i))} [:span [:span.icon [:i.fa.fa-minus-circle]]]])
(when (seq checks) (when (seq payments)
[:div.dropdown.is-right {:class (if (= id visible-checks) [:div.dropdown.is-right {:class (if (= id visible-checks)
"is-active" "is-active"
"")} "")}
[:div.dropdown-trigger [:div.dropdown-trigger
[:a.button.badge {:data-badge (str (clojure.core/count checks)) [:a.button.badge {:data-badge (str (clojure.core/count payments))
:aria-haspopup true :aria-haspopup true
:tab-index "0" :tab-index "0"
@@ -202,12 +202,12 @@
} "Checks"]] } "Checks"]]
[:div.dropdown-menu {:role "menu"} [:div.dropdown-menu {:role "menu"}
[:div.dropdown-content [:div.dropdown-content
(for [check checks] (for [payment payments]
(if (:s3-url (:check check)) (if (:s3-url (:payment payment))
^{:key (:id check)} ^{:key (:id payment)}
[:a.dropdown-item {:href (:s3-url (:check check)) :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " (:check-number (:check check)) " (" (gstring/format "$%.2f" (:amount check) ) ")")] [:a.dropdown-item {:href (:s3-url (:payment payment)) :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " (:check-number (:payment payment)) " (" (gstring/format "$%.2f" (:amount payment) ) ")")]
^{:key (:id check)} ^{:key (:id payment)}
[:span.dropdown-item [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " (:check-number (:check check)) " (" (gstring/format "$%.2f" (:amount check) ) ")")]))]]]) [:span.dropdown-item [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " (:check-number (:payment payment)) " (" (gstring/format "$%.2f" (:amount payment) ) ")")]))]]])
]]))]]])))) ]]))]]]))))

View File

@@ -34,7 +34,7 @@
(assoc-in [:status :loading] true) (assoc-in [:status :loading] true)
(assoc-in [::params] params)) (assoc-in [::params] params))
:graphql {:token (-> cofx :db :user) :graphql {:token (-> cofx :db :user)
:query-obj {:venia/queries [[:check_page :query-obj {:venia/queries [[:payment_page
(assoc params :company-id (:id @(re-frame/subscribe [::subs/company]))) (assoc params :company-id (:id @(re-frame/subscribe [::subs/company])))
[[:checks [:id :status :amount :type :check_number :s3_url :date [:vendor [:name :id]] [:client [:name :id]]]] [[:checks [:id :status :amount :type :check_number :s3_url :date [:vendor [:name :id]] [:client [:name :id]]]]
:total :total
@@ -70,7 +70,7 @@
::received ::received
(fn [db [_ data]] (fn [db [_ data]]
(-> db (-> db
(assoc ::check-page (first (:check-page data))) (assoc ::check-page (first (:payment-page data)))
(assoc-in [:status :loading] false)))) (assoc-in [:status :loading] false))))
(re-frame/reg-event-fx (re-frame/reg-event-fx