diff --git a/src/clj/auto_ap/datomic.clj b/src/clj/auto_ap/datomic.clj index 472649a6..05363411 100644 --- a/src/clj/auto_ap/datomic.clj +++ b/src/clj/auto_ap/datomic.clj @@ -512,6 +512,7 @@ (d/transact (d/connect uri)))) + (defn load-entities [] (d/transact (d/connect uri) [{:db/ident :test @@ -555,7 +556,7 @@ (map (fn [{:keys [name address id code locations email bank-accounts signature-file] client-id :id}] (remove-nils #:client {:original-id id - :name (str name "-test") + :name (str name) :code nil :email email :signature-file signature-file @@ -706,7 +707,7 @@ (d/db (d/connect uri)))) (defn query-check-payments [] - (d/q '[:find (pull ?e [*]) + (d/q '[:find (pull ?e [* {:invoice-payment/payment [*]}]) :where [?e :invoice-payment/original-id]] (d/db (d/connect uri)))) diff --git a/src/clj/auto_ap/datomic/vendors.clj b/src/clj/auto_ap/datomic/vendors.clj index 7bd02e08..4b391dff 100644 --- a/src/clj/auto_ap/datomic/vendors.clj +++ b/src/clj/auto_ap/datomic/vendors.clj @@ -2,7 +2,7 @@ (:require [datomic.api :as d] [auto-ap.datomic :refer [uri]])) -(defn get-graphql [] +(defn get-graphql [args] (->> (d/q '[:find (pull ?e [*]) :where [?e :vendor/name]] diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 03fa3f0c..17dc5f53 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -12,6 +12,7 @@ [auto-ap.db.vendors :as vendors] [auto-ap.db.companies :as companies] [auto-ap.datomic.clients :as d-clients] + [auto-ap.datomic.invoices :as d-invoices] [auto-ap.datomic.vendors :as d-vendors] [auto-ap.db.users :as users] [auto-ap.db.checks :as checks] @@ -97,10 +98,8 @@ :check {:fields {:id {:type 'Int} :type {:type 'String} :amount {:type 'String} - :vendor {:type :vendor - :resolve :get-vendor-for-check} - :company {:type :company - :resolve :get-company-for-check} + :vendor {:type :vendor} + :company {:type :company} :date {:type 'String} :bank_account {:type :bank_account :resolve :bank-account-for-check} @@ -108,8 +107,7 @@ :s3_url {:type 'String} :check_number {:type 'Int} :status {:type 'String} - :invoices {:type '(list :invoice_check) - :resolve :get-checks-invoices} + :invoices {:type '(list :invoice_payment)} }} :payment {:fields {:id {:type 'String} @@ -124,8 +122,7 @@ :s3_url {:type 'String} :check_number {:type 'Int} :status {:type 'String} - :invoices {:type '(list :invoice_check) - :resolve :get-checks-invoices} + :invoices {:type '(list :invoice_payment)} }} :transaction {:fields {:id {:type 'String} @@ -137,13 +134,12 @@ :payment {:type :payment} :date {:type 'String} :post_date {:type 'String}}} - :invoice_check + :invoice_payment {:fields {:id {:type 'Int} :amount {:type 'String} - :invoice_id {:type 'Int} - :check_id {:type 'Int} - :check {:type :check - :resolve :get-check-by-id}}} + :invoice_id {:type 'String} + :payment_id {:type 'String} + :payment {:type :payment}}} :user {:fields {:id {:type 'Int} @@ -159,30 +155,27 @@ :resolve :get-expense-account-parent}}} :invoices_expense_accounts - {:fields {:id {:type 'Int} - :invoice_id {:type 'Int} + {:fields {:id {:type 'String} + :invoice_id {:type 'String} :expense_account_id {:type 'Int} :location {:type 'String} :expense_account {:type :expense_account - :resolve :get-expense-account} + :resolve :get-expense-account + + } :amount {:type 'String}}} :invoice - {:fields {:id {:type 'Int} + {:fields {:id {:type 'String} :total {:type 'String} :outstanding_balance {:type 'String} :invoice_number {:type 'String} - :expense_accounts {:type '(list :invoices_expense_accounts) - :resolve :get-invoices-expense-accounts} + :expense_accounts {:type '(list :invoices_expense_accounts)} :date {:type 'String} :company_id {:type 'Int} - :checks {:type '(list :invoice_check) - :resolve :get-invoices-checks} - :vendor {:type :vendor - - :resolve :get-vendor-for-invoice} - :company {:type :company - :resolve :get-company-for-invoice}}} + :payments {:type '(list :invoice_payment)} + :vendor {:type :vendor} + :client {:type :client}}} :invoice_page {:fields {:invoices {:type '(list :invoice)} @@ -191,7 +184,7 @@ :start {:type 'Int} :end {:type 'Int}}} - :check_page {:fields {:checks {:type '(list :payment)} + :payment_page {:fields {:checks {:type '(list :payment)} :count {:type 'Int} :total {:type 'Int} :start {:type 'Int} @@ -217,7 +210,7 @@ {:invoice_page {:type '(list :invoice_page) :args {:imported {:type 'Boolean} :status {:type 'String} - :company_id {:type 'Int} + :client_id {:type 'String} :start {:type 'Int} :sort_by {:type 'String} :asc {:type 'Boolean}} @@ -228,7 +221,7 @@ :args {:company_id {:type 'Int}} :resolve :get-all-invoices} - :all_checks {:type '(list :check) + :all_checks {:type '(list :payment) :args {:company_id {:type 'Int}} :resolve :get-all-checks} @@ -240,7 +233,7 @@ :resolve :get-transaction-page} - :check_page {:type '(list :check_page) + :payment_page {:type '(list :payment_page) :args {:company_id {:type 'Int} :start {:type 'Int} :sort_by {:type 'String} @@ -264,7 +257,7 @@ :input-objects { - :invoice_payment {:fields {:invoice_id {:type 'Int} + :invoice_payment_amount {:fields {:invoice_id {:type 'String} :amount {:type 'Float}}} :edit_user @@ -297,7 +290,7 @@ :mutations {: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} :type {:type 'String} :company_id {:type 'Int}} @@ -370,21 +363,16 @@ (defn get-invoice-page [context args value] (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 ->graphql - (invoices/get-graphql (<-graphql (assoc args :id (:id context))))) - invoice-count (invoices/count-graphql (<-graphql args))] - (resolve/with-context - [{:invoices invoices - :total invoice-count - :count (count invoices) - :start (:start args 0) - :end (+ (:start args 0) (count invoices))}] extra-context))) + (d-invoices/get-graphql (<-graphql (assoc args :id (:id context))))) + invoice-count (d-invoices/count-graphql (<-graphql args))] + [{:invoices invoices + :total invoice-count + :count (count invoices) + :start (:start args 0) + :end (+ (:start args 0) (count invoices))}])) (defn get-all-invoices [context args value] @@ -475,7 +463,6 @@ (defn get-company [context args value] - (println "GETTING COMPANY" (:id context)) (->graphql (filter #(can-see-company? (:id context) %) (d-clients/get-all)))) @@ -500,7 +487,7 @@ (defn get-vendor [context args value] (->graphql - (d-vendors/get-all))) + (d-vendors/get-graphql args))) (defn print-checks [context args value] @@ -525,8 +512,6 @@ :get-transaction-page gq-transactions/get-transaction-page :get-reminder-page get-reminder-page :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-company-for-invoice get-company-for-invoice :get-invoices-checks get-invoices-checks diff --git a/src/cljs/auto_ap/views/components/invoice_table.cljs b/src/cljs/auto_ap/views/components/invoice_table.cljs index 6cefe61e..e44dc829 100644 --- a/src/cljs/auto_ap/views/components/invoice_table.cljs +++ b/src/cljs/auto_ap/views/components/invoice_table.cljs @@ -41,13 +41,13 @@ (defn query [params] {:venia/queries [[:invoice_page (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 [:vendor [:name :id]] [:expense_accounts [:amount :id :expense_account_id :location [:expense_account [:id :name :location [:parent [:id :name]]]]]] - [:company [:name :id :locations]] - [:checks [:amount [:check [:amount :s3_url :check_number ]]]] + [:client [:name :id :locations]] + [:payments [:amount [:payment [:amount :s3_url :check_number ]]]] ]] :total :start @@ -86,10 +86,10 @@ (when-not selected-company [sorted-column {:on-sort opc :style {:width percentage-size :cursor "pointer"} - :sort-key "company" + :sort-key "client" :sort-by sort-by :asc asc} - "Company"]) + "Client"]) [sorted-column {:on-sort opc :style {:width percentage-size :cursor "pointer"} :sort-key "vendor" @@ -123,7 +123,7 @@ [sorted-column {:on-sort opc :style {:width "10em" :cursor "pointer"} - :sort-key "outstanding" + :sort-key "outstanding-balance" :sort-by sort-by :asc asc} "Outstanding"] @@ -139,7 +139,7 @@ [:tr [:td {:col-span 5} [: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} [:tr {:class (:class i)} (when check-boxes @@ -150,7 +150,7 @@ :on-change (fn [x e] (when on-check-changed (on-check-changed id)))} ]]) (when-not selected-company - [:td (:name company)]) + [:td (:name client)]) [:td (:name vendor)] [:td invoice-number] [:td (date->str date) ] @@ -169,7 +169,7 @@ :aria-haspopup true :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]) } "Accounts"]] [:div.dropdown-menu {:role "menu"} @@ -187,13 +187,13 @@ [: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))) [: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) "is-active" "")} [: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 :tab-index "0" @@ -202,12 +202,12 @@ } "Checks"]] [:div.dropdown-menu {:role "menu"} [:div.dropdown-content - (for [check checks] - (if (:s3-url (:check check)) - ^{:key (:id check)} - [: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) ) ")")] + (for [payment payments] + (if (:s3-url (:payment payment)) + ^{:key (:id payment)} + [: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)} - [:span.dropdown-item [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " (:check-number (:check check)) " (" (gstring/format "$%.2f" (:amount check) ) ")")]))]]]) + ^{:key (:id payment)} + [:span.dropdown-item [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " (:check-number (:payment payment)) " (" (gstring/format "$%.2f" (:amount payment) ) ")")]))]]]) ]]))]]])))) diff --git a/src/cljs/auto_ap/views/pages/checks.cljs b/src/cljs/auto_ap/views/pages/checks.cljs index 3e666df1..1aa97f5a 100644 --- a/src/cljs/auto_ap/views/pages/checks.cljs +++ b/src/cljs/auto_ap/views/pages/checks.cljs @@ -34,7 +34,7 @@ (assoc-in [:status :loading] true) (assoc-in [::params] params)) :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]))) [[:checks [:id :status :amount :type :check_number :s3_url :date [:vendor [:name :id]] [:client [:name :id]]]] :total @@ -70,7 +70,7 @@ ::received (fn [db [_ data]] (-> db - (assoc ::check-page (first (:check-page data))) + (assoc ::check-page (first (:payment-page data))) (assoc-in [:status :loading] false)))) (re-frame/reg-event-fx