switched to graphql to create a payment.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
:from :invoices-checks))
|
||||
|
||||
(defn query [q]
|
||||
(map data->fields (u/query q)))
|
||||
(u/query q))
|
||||
|
||||
(defn get-all []
|
||||
(query base-query))
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.db.companies :as companies]
|
||||
[auto-ap.db.checks :as checks]
|
||||
[auto-ap.routes.checks :as rchecks]
|
||||
[auto-ap.db.reminders :as reminders]
|
||||
[auto-ap.db.invoices-checks :as invoices-checks]
|
||||
[auto-ap.db.utils :as utils]
|
||||
@@ -17,6 +18,7 @@
|
||||
(:import
|
||||
(clojure.lang IPersistentMap)))
|
||||
|
||||
|
||||
(def integreat-schema
|
||||
{
|
||||
:objects
|
||||
@@ -77,7 +79,13 @@
|
||||
:count {:type 'Int}
|
||||
:total {:type 'Int}
|
||||
:start {:type 'Int}
|
||||
:end {:type 'Int}}}}
|
||||
:end {:type 'Int}}}
|
||||
:check_result {:fields {:invoices {:type '(list :invoice)}
|
||||
:pdf_url {:type 'String}}}
|
||||
}
|
||||
|
||||
|
||||
|
||||
:queries
|
||||
{:invoice_page {:type '(list :invoice_page)
|
||||
:args {:imported {:type 'Boolean}
|
||||
@@ -96,7 +104,12 @@
|
||||
:company {:type '(list :company)
|
||||
:resolve :get-company}
|
||||
:vendor {:type '(list :vendor)
|
||||
:resolve :get-vendor}}})
|
||||
:resolve :get-vendor}}
|
||||
|
||||
:mutations
|
||||
{:print_checks {:type :check_result
|
||||
:args {:invoice_ids {:type '(list Int)}}
|
||||
:resolve :mutation/print-checks}}})
|
||||
|
||||
(defn by [x kf]
|
||||
(reduce
|
||||
@@ -202,6 +215,11 @@
|
||||
(->graphql
|
||||
(vendors/get-all)))
|
||||
|
||||
(defn print-checks [context args value]
|
||||
(->graphql
|
||||
|
||||
(rchecks/print-checks (:invoice_ids args))))
|
||||
|
||||
(def schema
|
||||
(-> integreat-schema
|
||||
(attach-resolvers {:get-invoice-page get-invoice-page
|
||||
@@ -211,6 +229,7 @@
|
||||
:get-invoices-checks get-invoices-checks
|
||||
:get-check-by-id get-check-by-id
|
||||
:get-company get-company
|
||||
:mutation/print-checks print-checks
|
||||
:get-vendor get-vendor})
|
||||
schema/compile))
|
||||
|
||||
|
||||
@@ -185,6 +185,34 @@
|
||||
:invoices (map :id invoices)}))
|
||||
|
||||
|
||||
(defn print-checks [invoice-ids]
|
||||
(let [invoices (invoices/get-multi invoice-ids)
|
||||
companies (into {}
|
||||
(map (fn [c] [(:id c) c])
|
||||
(companies/get-all)))
|
||||
vendors (into {}
|
||||
(map (fn [v] [(:id v) v])
|
||||
(vendors/get-all)))
|
||||
invoices-grouped-by-vendor (group-by :vendor-id invoices)
|
||||
checks (-> (for [[vendor-id invoices] invoices-grouped-by-vendor]
|
||||
[invoices (checks/insert! (check-for-invoices invoices vendor-id vendors companies))])
|
||||
doall)
|
||||
invoice-checks (invoices-checks/insert-multi!
|
||||
(mapcat
|
||||
(fn [[invoices check]]
|
||||
(map
|
||||
(fn [i]
|
||||
{:invoice-id (:id i)
|
||||
:check-id (:id check)
|
||||
:amount (:total i)})
|
||||
invoices))
|
||||
checks)) ]
|
||||
|
||||
(make-pdfs (map second checks))
|
||||
{:invoices (mapcat first checks)
|
||||
:pdf-url (merge-pdfs (map (comp :s3-key second) checks))}))
|
||||
|
||||
|
||||
(defroutes routes
|
||||
(wrap-routes
|
||||
(context "/checks" []
|
||||
|
||||
@@ -9,6 +9,14 @@
|
||||
[cljs-time.format :as format]
|
||||
[goog.string :as gstring]))
|
||||
|
||||
;; TODO show busy
|
||||
;; TODO only when one company selected
|
||||
;; TODO partial payments
|
||||
;; TODO invoice status = paid when complete
|
||||
;; TODO performance
|
||||
;; TODO check numbers
|
||||
;; TODO psql transactions
|
||||
;; TODO refactor graphql
|
||||
|
||||
|
||||
|
||||
@@ -97,4 +105,4 @@
|
||||
[:td (gstring/format "$%.2f" total )]
|
||||
[:td (for [check checks]
|
||||
^{:key (:id check)}
|
||||
[:a.tag {:href (:s3-url (:check check)) :target "_new"} (str "check " (:check-number (:check check)))])]]))]]]))))
|
||||
[:a.tag {:href (:s3-url (:check check)) :target "_new"} [:i.fa.fa-money-check] (str " " (:check-number (:check check)) " (" (gstring/format "$%.2f" (:amount check) ) ")")])]]))]]]))))
|
||||
|
||||
@@ -49,20 +49,36 @@
|
||||
(re-frame/reg-event-fx
|
||||
::print-checks
|
||||
(fn [{:keys [db]} [_ data]]
|
||||
{:db (assoc-in db [::invoice-page :checked] nil)
|
||||
:http {:method :post
|
||||
:token (:user db)
|
||||
:body (pr-str {:invoice-ids (get-in db [::invoice-page :checked])})
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:uri (str "/api/checks/")
|
||||
:on-success [::checks-created]
|
||||
:on-error [::save-error]}}))
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "PrintChecks"}
|
||||
|
||||
:venia/queries [[:print-checks
|
||||
{:invoice_ids (vec (get-in db [::invoice-page :checked]))}
|
||||
[[:invoices [:id [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]
|
||||
]
|
||||
:pdf_url]]]}
|
||||
|
||||
:on-success [::checks-created]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::checks-created
|
||||
(fn [{:keys [db]} [_ data]]
|
||||
{:new-window (:url data)
|
||||
}))
|
||||
(let [{{:keys [pdf-url invoices]} :print-checks} data
|
||||
invoices-by-id (reduce
|
||||
(fn [x a]
|
||||
(assoc x (:id a) a))
|
||||
{}
|
||||
invoices)]
|
||||
{:new-window pdf-url
|
||||
:db (-> db
|
||||
(update-in [::invoice-page :invoices]
|
||||
(fn [invoices]
|
||||
(map (fn [i]
|
||||
(merge i (invoices-by-id (:id i))))
|
||||
invoices)))
|
||||
(assoc-in [::invoice-page :checked] nil))})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invalidated
|
||||
|
||||
Reference in New Issue
Block a user