payments work through the ui in datomic
This commit is contained in:
49
src/clj/auto_ap/datomic/checks.clj
Normal file
49
src/clj/auto_ap/datomic/checks.clj
Normal 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)))
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
:else
|
||||
(keyword "transaction" (:sort-by args))))
|
||||
|
||||
(defn get-graphql [args]
|
||||
(let [results (raw-graphql args)]
|
||||
(cond->> results
|
||||
|
||||
@@ -112,13 +112,11 @@
|
||||
:resolve :get-checks-invoices}
|
||||
}}
|
||||
|
||||
:payment {:fields {:id {:type 'Int}
|
||||
:payment {:fields {:id {:type 'String}
|
||||
: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}
|
||||
:client {:type :client}
|
||||
:date {:type 'String}
|
||||
:bank_account {:type :bank_account
|
||||
:resolve :bank-account-for-check}
|
||||
@@ -193,7 +191,7 @@
|
||||
:start {:type 'Int}
|
||||
:end {:type 'Int}}}
|
||||
|
||||
:check_page {:fields {:checks {:type '(list :check)}
|
||||
:check_page {:fields {:checks {:type '(list :payment)}
|
||||
:count {:type 'Int}
|
||||
:total {:type 'Int}
|
||||
:start {:type 'Int}
|
||||
|
||||
@@ -6,41 +6,25 @@
|
||||
[com.walmartlabs.lacinia.resolve :as resolve]
|
||||
[auto-ap.db.invoices-checks :as invoices-checks]
|
||||
[auto-ap.db.checks :as checks]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.db.invoices :as invoices]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[auto-ap.db.companies :as companies]
|
||||
[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]
|
||||
(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
|
||||
->graphql
|
||||
(checks/get-graphql (<-graphql args)))
|
||||
checks-count (checks/count-graphql (<-graphql args))]
|
||||
(resolve/with-context
|
||||
[{:checks checks
|
||||
:total checks-count
|
||||
:count (count checks)
|
||||
:start (:start args 0)
|
||||
:end (+ (:start args 0) (count checks))}] extra-context)))
|
||||
(d-checks/get-graphql (<-graphql args)))
|
||||
checks-count (d-checks/count-graphql (<-graphql args))]
|
||||
[{:checks checks
|
||||
:total checks-count
|
||||
:count (count checks)
|
||||
:start (:start args 0)
|
||||
:end (+ (:start args 0) (count checks))}]))
|
||||
|
||||
(defn add-handwritten-check [context args value]
|
||||
(let [invoice (invoices/get-by-id (:invoice_id args))
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj {:venia/queries [[:check_page
|
||||
(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
|
||||
:start
|
||||
:end]]]}
|
||||
@@ -103,10 +103,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"}
|
||||
@@ -147,12 +147,12 @@
|
||||
[:tr
|
||||
[:td {:col-span 5}
|
||||
[: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}
|
||||
[:tr {:class (:class i)}
|
||||
|
||||
(when-not selected-company
|
||||
[:td (:name company)])
|
||||
[:td (:name client)])
|
||||
[:td (:name vendor)]
|
||||
[:td (cond
|
||||
(= "cash" type) "Cash"
|
||||
|
||||
Reference in New Issue
Block a user