more conversion to datomic

This commit is contained in:
Bryce Covert
2018-08-16 08:23:44 -07:00
parent 0741b27239
commit a4e3fe2327
7 changed files with 114 additions and 103 deletions

View File

@@ -1,31 +1,40 @@
(ns auto-ap.datomic.checks
(:require [datomic.api :as d]
[auto-ap.datomic :refer [uri]]
[clojure.set :refer [rename-keys]]
[clj-time.coerce :as c]))
(defn add-arg [query name value where]
(-> query
(update :args conj value)
(update-in [:query :in] conj name)
(update-in [:query :where] conj where)))
(defn add-arg [query name value where & rest]
(let [query (-> query
(update :args conj value)
(update-in [:query :in] conj name)
(update-in [:query :where] conj where))]
(reduce #(update-in %1 [:query :where] conj %2) query rest)))
(defn raw-graphql [args]
(->> (d/query
(cond-> {:query {:find ['(pull ?e [*
{:payment/client [:client/name :db/id]}
{:payment/vendor [:vendor/name :db/id]}
{:payment/status [:db/ident]}])]
:in ['$]
:where ['[?e :payment/original-id]]}
:args [(d/db (d/connect uri))]}
(let [query (cond-> {:query {:find ['(pull ?e [*
{:invoice-payment/_payment [* {:invoice-payment/invoice [*]}]}
{:payment/client [:client/name :db/id]}
{:payment/vendor [:vendor/name :db/id]}
{:payment/status [:db/ident]}])]
:in ['$]
:where ['[?e :payment/original-id]]}
:args [(d/db (d/connect uri))]}
(:company-id args) (add-arg '?company-id (Long/parseLong (:company-id args))
'[?e :payment/client ?company-id])))
(map first)
(map #(update % :payment/date c/from-date))
(map #(update % :payment/status :db/ident))
#_(map #(update % :transaction/post-date c/from-date))))
(:client-id args) (add-arg '?client-id (cond-> (:client-id args) (string? (:client-id args)) Long/parseLong )
'[?e :payment/client ?client-id])
(:original-id args) (add-arg '?original-id (cond-> (:original-id args) (string? (:original-id args)) Long/parseLong )
'[?e :payment/client ?c]
'[?c :client/original-id ?original-id]))]
(->> (d/query
query)
(map first)
(map #(update % :payment/date c/from-date))
(map #(update % :payment/status :db/ident))
(map #(rename-keys % {:invoice-payment/_payment :payments/invoices}))
#_(map #(update % :transaction/post-date c/from-date)))))
(defn sort-fn [args]
(cond

View File

@@ -4,11 +4,12 @@
[clj-time.coerce :as c]
[clojure.set :refer [rename-keys]]))
(defn add-arg [query name value where]
(-> query
(update :args conj value)
(update-in [:query :in] conj name)
(update-in [:query :where] conj where)))
(defn add-arg [query name value where & rest]
(let [query (-> query
(update :args conj value)
(update-in [:query :in] conj name)
(update-in [:query :where] conj where))]
(reduce #(update-in %1 [:query :where] conj %2) query rest)))
(defn raw-graphql [args]
(->> (d/query
@@ -23,8 +24,14 @@
:args [(d/db (d/connect uri))]}
println)
(:client-id args) (add-arg '?client-id (Long/parseLong (:client-id args))
'[?e :invoice/client ?client-id])
(:client-id args) (add-arg '?client-id (cond-> (:client-id args)
(string? (:client-id args))
Long/parseLong)
'[?e :invoice/client ?client-id])
(:original-id args) (add-arg '?original-id (cond-> (:original-id args) (string? (:original-id args)) Long/parseLong )
'[?e :invoice/client ?c]
'[?c :client/original-id ?original-id])
(:status args) (add-arg '?status (keyword "invoice-status" (:status args))
'[?e :invoice/status ?status])))
(map first)

View File

@@ -3,11 +3,13 @@
[auto-ap.datomic :refer [uri]]
[clj-time.coerce :as c]))
(defn add-arg [query name value where]
(-> query
(update :args conj value)
(update-in [:query :in] conj name)
(update-in [:query :where] conj where)))
(defn add-arg [query name value where & rest]
(let [query (-> query
(update :args conj value)
(update-in [:query :in] conj name)
(update-in [:query :where] conj where))]
(reduce #(update-in %1 [:query :where] conj %2) query rest)))
(defn raw-graphql [args]
(->> (d/query
@@ -16,8 +18,11 @@
:where ['[?e :transaction/original-id]]}
:args [(d/db (d/connect uri))]}
(:company-id args) (add-arg '?company-id (Long/parseLong (:company-id args))
'[?e :transaction/client ?company-id])))
(:client-id args) (add-arg '?client-id (Long/parseLong (:client-id args))
'[?e :transaction/client ?client-id])
(:original-id args) (add-arg '?original-id (cond-> (:original-id args) (string? (:original-id args)) Long/parseLong )
'[?e :transaction/client ?c]
'[?c :client/original-id ?original-id])))
(map first)
(map #(update % :transaction/date c/from-date))

View File

@@ -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.checks :as d-checks]
[auto-ap.datomic.invoices :as d-invoices]
[auto-ap.datomic.vendors :as d-vendors]
[auto-ap.db.users :as users]
@@ -101,8 +102,7 @@
:vendor {:type :vendor}
:company {:type :company}
:date {:type 'String}
:bank_account {:type :bank_account
:resolve :bank-account-for-check}
:bank_account {:type :bank_account}
:memo {:type 'String}
:s3_url {:type 'String}
:check_number {:type 'Int}
@@ -116,8 +116,7 @@
:vendor {:type :vendor}
:client {:type :client}
:date {:type 'String}
:bank_account {:type :bank_account
:resolve :bank-account-for-check}
:bank_account {:type :bank_account}
:memo {:type 'String}
:s3_url {:type 'String}
:check_number {:type 'Int}
@@ -139,7 +138,8 @@
:amount {:type 'String}
:invoice_id {:type 'String}
:payment_id {:type 'String}
:payment {:type :payment}}}
:payment {:type :payment}
:invoice {:type :invoice}}}
:user
{:fields {:id {:type 'Int}
@@ -160,8 +160,7 @@
:expense_account_id {:type 'Int}
:location {:type 'String}
:expense_account {:type :expense_account
:resolve :get-expense-account
:resolve :get-expense-account
}
:amount {:type 'String}}}
@@ -184,7 +183,7 @@
:start {:type 'Int}
:end {:type 'Int}}}
:payment_page {:fields {:checks {:type '(list :payment)}
:payment_page {:fields {:payments {:type '(list :payment)}
:count {:type 'Int}
:total {:type 'Int}
:start {:type 'Int}
@@ -218,12 +217,14 @@
:resolve :get-invoice-page}
:all_invoices {:type '(list :invoice)
:args {:company_id {:type 'Int}}
:args {:client_id {:type 'String}
:original_id {:type 'Int}}
:resolve :get-all-invoices}
:all_checks {:type '(list :payment)
:args {:company_id {:type 'Int}}
:resolve :get-all-checks}
:all_payments {:type '(list :payment)
:args {:client_id {:type 'String}
:original_id {:type 'Int}}
:resolve :get-all-payments}
:transaction_page {:type '(list :transaction_page)
:args {:company_id {:type 'String}
@@ -234,12 +235,12 @@
:resolve :get-transaction-page}
:payment_page {:type '(list :payment_page)
:args {:company_id {:type 'Int}
:args {:client_id {:type 'String}
:start {:type 'Int}
:sort_by {:type 'String}
:asc {:type 'Boolean}}
:resolve :get-check-page}
:resolve :get-payment-page}
:reminder_page {:type '(list :reminder_page)
:args {:start {:type 'Int}
:sort_by {:type 'String}
@@ -377,34 +378,17 @@
(defn get-all-invoices [context args value]
(assert-admin (:id context))
(let [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))))
(map
->graphql
(d-invoices/get-graphql (assoc (<-graphql args)
:limit Integer/MAX_VALUE))))
invoices (map
->graphql
(invoices/get-graphql (assoc (<-graphql args)
:limit Integer/MAX_VALUE)))]
(resolve/with-context
invoices extra-context)))
(defn get-all-checks [context args value]
(defn get-all-payments [context args value]
(assert-admin (:id context))
(let [extra-context
(cond-> {}
(executor/selects-field? context :invoice/vendor) (assoc :vendor-cache (by :id (vendors/get-all)))
(or (executor/selects-field? context :check/company)
(executor/selects-field? context :check/bank_account)) (assoc :company-cache (by :id (companies/get-all))))
checks (map
->graphql
(checks/get-graphql (assoc (<-graphql args)
:limit Integer/MAX_VALUE)))]
(resolve/with-context
checks extra-context)))
(map
->graphql
(d-checks/get-graphql (assoc (<-graphql args)
:limit Integer/MAX_VALUE))))
(defn get-reminder-page [context args value]
(assert-admin (:id context))
@@ -506,9 +490,9 @@
(-> integreat-schema
(attach-resolvers {:get-invoice-page get-invoice-page
:get-all-invoices get-all-invoices
:get-all-checks get-all-checks
:get-all-payments get-all-payments
:bank-account-for-check bank-account-for-check
:get-check-page gq-checks/get-check-page
:get-payment-page gq-checks/get-payment-page
:get-transaction-page gq-transactions/get-transaction-page
:get-reminder-page get-reminder-page
:get-vendor-for-invoice get-vendor-for-invoice

View File

@@ -14,17 +14,17 @@
[auto-ap.time :refer [parse normal-date iso-date]]))
(defn get-check-page [context args value]
(defn get-payment-page [context args value]
(let [args (assoc args :id (:id context))
checks (map
payments (map
->graphql
(d-checks/get-graphql (<-graphql args)))
checks-count (d-checks/count-graphql (<-graphql args))]
[{:checks checks
[{:payments payments
:total checks-count
:count (count checks)
:count (count payments)
:start (:start args 0)
:end (+ (:start args 0) (count checks))}]))
:end (+ (:start args 0) (count payments))}]))
(defn add-handwritten-check [context args value]
(let [invoice (invoices/get-by-id (:invoice_id args))

View File

@@ -4,12 +4,15 @@
[auto-ap.db.checks :as checks]
[auto-ap.db.transactions :as transactions]
[auto-ap.db.companies :as companies]
[auto-ap.datomic.clients :as d-clients]
[auto-ap.datomic.vendors :as d-vendors]
[auto-ap.datomic.transactions :as d-transactions]
[auto-ap.db.vendors :as vendors]
[auto-ap.db.utils :refer [query]]
[auto-ap.utils :refer [by]]
[auto-ap.parse :as parse]
[auto-ap.graphql :as graphql]
[auto-ap.graphql.utils :refer [->graphql assert-admin]]
[auto-ap.graphql.utils :refer [<-graphql ->graphql assert-admin]]
[auto-ap.routes.utils :refer [wrap-secure]]
[clj-time.coerce :refer [to-date]]
[auto-ap.db.invoices-expense-accounts :as expense-accounts]
@@ -25,39 +28,42 @@
(GET "/invoices/export" {:keys [query-params identity] :as request}
(assert-admin identity)
(let [query [[:all_invoices
{:company-id (query-params "company")}
{:client-id (query-params "client")
:original-id (query-params "original")}
[:id :total :outstanding-balance :invoice-number :date
[:checks [:amount [:check [:check-number :memo [:bank_account [:id :number :bank-name :bank-code]]]]]]
[:vendor [:name :id :primary_contact [:address [:street1 :city :state :zip]]]]
[:payments [:amount [:payment [:check-number :memo [:bank_account [:id :number :bank-name :bank-code]]]]]]
[:vendor [:name :id [:primary_contact [:name]] [:address [:street1 :city :state :zip]]]]
[:expense_accounts [:amount :id :expense_account_id :location
[:expense_account [:id :name [:parent [:id :name]]]]]]
[:company [:name :id :locations]]]]]
[:client [:name :id :locations]]]]]
invoices (graphql/query identity (venia/graphql-query {:venia/queries (->graphql query)}))]
(list (:all-invoices (:data invoices)))))
(GET "/checks/export" {:keys [query-params identity]}
(GET "/payments/export" {:keys [query-params identity]}
(assert-admin identity)
(let [query [[:all_checks
{:company-id (query-params "company")}
(let [query [[:all_payments
{:client-id (query-params "client")
:original-id (query-params "original")}
[:id :check-number :amount :memo :date
[:invoices [:invoice-id :amount]]
[:invoices [[:invoice [:id]] :amount]]
[:bank-account [:number :bank-name :bank-code :id]]
[:vendor [:name :id :primary-contact :primary-email :primary-phone :default-expense-account [:address [:street1 :city :state :zip]]]]
[:company [:id :name]]
[:vendor [:name :id [:primary-contact [:name :email :phone]] :default-expense-account [:address [:street1 :city :state :zip]]]]
[:client [:id :name]]
]]]
checks (graphql/query identity (venia/graphql-query {:venia/queries (->graphql query)}))]
(list (:all-checks (:data checks)))))
payments (graphql/query identity (venia/graphql-query {:venia/queries (->graphql query)}))]
(list (:all-payments (:data payments)))))
(GET "/companies/export" {:keys [query-params identity]}
(GET "/clients/export" {:keys [query-params identity]}
(assert-admin identity)
(companies/get-all))
(map <-graphql (d-clients/get-all)))
(GET "/vendors/export" {:keys [query-params identity]}
(assert-admin identity)
(vendors/get-all))
(map <-graphql (d-vendors/get-graphql {})))
(GET "/transactions/export" {:keys [query-params identity]}
(assert-admin identity)
(let [transactions (transactions/get-graphql {:company-id (Integer/parseInt (query-params "company"))
:limit Integer/MAX_VALUE})]
(let [transactions (map <-graphql (d-transactions/get-graphql {:client-id (query-params "client")
:original-id (Integer/parseInt (query-params "original"))
:limit Integer/MAX_VALUE}))]
(map (fn [i]
(-> i
(update :date to-date)

View File

@@ -35,8 +35,8 @@
(assoc-in [::params] params))
:graphql {:token (-> cofx :db :user)
: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]]]]
(assoc params :client-id (:id @(re-frame/subscribe [::subs/company])))
[[:payments [:id :status :amount :type :check_number :s3_url :date [:vendor [:name :id]] [:client [:name :id]]]]
:total
:start
:end]]]}
@@ -86,7 +86,7 @@
(on-params-change p))]
(fn [{:keys [id check-page status on-params-change vendors checked]}]
(let [{:keys [sort-by asc]} @state
{:keys [checks start end count total]} @check-page
{:keys [payments start end count total]} @check-page
selected-company @(re-frame/subscribe [::subs/company])
percentage-size (if selected-company "50%" "33%")]
[:div
@@ -147,7 +147,7 @@
[:tr
[:td {:col-span 5}
[:i.fa.fa-spin.fa-spinner]]]
(for [{:keys [client s3-url checks type check-number date amount id vendor status] :as i} (:checks @check-page)]
(for [{:keys [client s3-url payments type check-number date amount id vendor status] :as i} (:payments @check-page)]
^{:key id}
[:tr {:class (:class i)}