payments work through the ui in datomic

This commit is contained in:
Bryce Covert
2018-08-14 08:41:11 -07:00
parent 67dea65159
commit a25232a195
5 changed files with 67 additions and 35 deletions

View File

@@ -0,0 +1,49 @@
(ns auto-ap.datomic.checks
(:require [datomic.api :as d]
[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 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))]}
(: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))))
(defn sort-fn [args]
(cond
(= "client" (:sort-by args))
#(-> % :payment/client :client/name)
:else
(keyword "payment" (:sort-by args))))
(defn get-graphql [args]
(let [results (raw-graphql args)]
(cond->> results
(:sort-by args) (sort-by (sort-fn args))
(= (:asc args) false) (reverse)
true (drop (:start args 0))
true (take (:count args 20)))))
(defn count-graphql [args]
(->> (raw-graphql args)
(count)))

View File

@@ -30,6 +30,7 @@
:else :else
(keyword "transaction" (:sort-by args)))) (keyword "transaction" (:sort-by args))))
(defn get-graphql [args] (defn get-graphql [args]
(let [results (raw-graphql args)] (let [results (raw-graphql args)]
(cond->> results (cond->> results

View File

@@ -112,13 +112,11 @@
:resolve :get-checks-invoices} :resolve :get-checks-invoices}
}} }}
:payment {:fields {:id {:type 'Int} :payment {:fields {:id {:type 'String}
:type {:type 'String} :type {:type 'String}
:amount {:type 'String} :amount {:type 'String}
:vendor {:type :vendor :vendor {:type :vendor}
:resolve :get-vendor-for-check} :client {:type :client}
: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}
@@ -193,7 +191,7 @@
:start {:type 'Int} :start {:type 'Int}
:end {:type 'Int}}} :end {:type 'Int}}}
:check_page {:fields {:checks {:type '(list :check)} :check_page {:fields {:checks {:type '(list :payment)}
:count {:type 'Int} :count {:type 'Int}
:total {:type 'Int} :total {:type 'Int}
:start {:type 'Int} :start {:type 'Int}

View File

@@ -6,41 +6,25 @@
[com.walmartlabs.lacinia.resolve :as resolve] [com.walmartlabs.lacinia.resolve :as resolve]
[auto-ap.db.invoices-checks :as invoices-checks] [auto-ap.db.invoices-checks :as invoices-checks]
[auto-ap.db.checks :as checks] [auto-ap.db.checks :as checks]
[auto-ap.datomic.checks :as d-checks]
[auto-ap.db.vendors :as vendors] [auto-ap.db.vendors :as vendors]
[auto-ap.db.invoices :as invoices] [auto-ap.db.invoices :as invoices]
[auto-ap.utils :refer [by]] [auto-ap.utils :refer [by]]
[auto-ap.db.companies :as companies] [auto-ap.db.companies :as companies]
[auto-ap.time :refer [parse normal-date iso-date]])) [auto-ap.time :refer [parse normal-date iso-date]]))
(defn get-vendor-for-check [context args value]
(->graphql
(if-let [vendor-cache (:vendor-cache context)]
(vendor-cache (:vendor_id value))
(vendors/get-by-id (:vendor_id value)))))
(defn get-company-for-check [context args value]
(->graphql
(if-let [company-cache (:company-cache context)]
(company-cache (:company_id value))
(companies/get-by-id (:company_id value)))))
(defn get-check-page [context args value] (defn get-check-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))))
checks (map checks (map
->graphql ->graphql
(checks/get-graphql (<-graphql args))) (d-checks/get-graphql (<-graphql args)))
checks-count (checks/count-graphql (<-graphql args))] checks-count (d-checks/count-graphql (<-graphql args))]
(resolve/with-context
[{:checks checks [{:checks checks
:total checks-count :total checks-count
:count (count checks) :count (count checks)
:start (:start args 0) :start (:start args 0)
:end (+ (:start args 0) (count checks))}] extra-context))) :end (+ (:start args 0) (count checks))}]))
(defn add-handwritten-check [context args value] (defn add-handwritten-check [context args value]
(let [invoice (invoices/get-by-id (:invoice_id args)) (let [invoice (invoices/get-by-id (:invoice_id args))

View File

@@ -36,7 +36,7 @@
:graphql {:token (-> cofx :db :user) :graphql {:token (-> cofx :db :user)
:query-obj {:venia/queries [[:check_page :query-obj {:venia/queries [[:check_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]] [:company [:name :id]]]] [[:checks [:id :status :amount :type :check_number :s3_url :date [:vendor [:name :id]] [:client [:name :id]]]]
:total :total
:start :start
:end]]]} :end]]]}
@@ -103,10 +103,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"}
@@ -147,12 +147,12 @@
[: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 s3-url checks type check-number date amount id vendor status] :as i} (:checks @check-page)] (for [{:keys [client s3-url checks type check-number date amount id vendor status] :as i} (:checks @check-page)]
^{:key id} ^{:key id}
[:tr {:class (:class i)} [:tr {:class (:class i)}
(when-not selected-company (when-not selected-company
[:td (:name company)]) [:td (:name client)])
[:td (:name vendor)] [:td (:name vendor)]
[:td (cond [:td (cond
(= "cash" type) "Cash" (= "cash" type) "Cash"