hand written checks graphql
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[clj-time.coerce :as c]
|
||||
[clojure.set :refer [rename-keys]]))
|
||||
[clojure.set :refer [rename-keys]]
|
||||
[clojure.string :as str]))
|
||||
|
||||
|
||||
(defn add-arg [query name value where & rest]
|
||||
(let [query (-> query
|
||||
@@ -97,17 +99,20 @@
|
||||
)
|
||||
(<-datomic)))
|
||||
|
||||
|
||||
|
||||
(defn find-conflicting [{:keys [:invoice/invoice-number :invoice/vendor :invoice/client :db/id]}]
|
||||
(println invoice-number vendor client id)
|
||||
(->> (doto (d/query
|
||||
(cond-> {:query {:find [default-read]
|
||||
:in ['$ '?invoice-number '?vendor '?client '?invoice-id]
|
||||
:where '[[?e :invoice/invoice-number ?invoice-number]
|
||||
[?e :invoice/vendor ?vendor]
|
||||
[?e :invoice/client ?client]
|
||||
[(not= ?e ?invoice-id)]]}
|
||||
:args [(d/db (d/connect uri)) invoice-number vendor client id]}))
|
||||
println)
|
||||
|
||||
(->> (d/query
|
||||
(cond-> {:query {:find [default-read]
|
||||
:in ['$ '?invoice-number '?vendor '?client '?invoice-id]
|
||||
:where '[[?e :invoice/invoice-number ?invoice-number]
|
||||
[?e :invoice/vendor ?vendor]
|
||||
[?e :invoice/client ?client]
|
||||
[(not= ?e ?invoice-id)]
|
||||
]}
|
||||
|
||||
:args [(d/db (d/connect uri)) invoice-number vendor client (or id 0)]}))
|
||||
(map first)
|
||||
|
||||
(<-datomic)))
|
||||
|
||||
@@ -307,11 +307,11 @@
|
||||
:resolve :mutation/print-checks}
|
||||
|
||||
:add_handwritten_check {:type :check_result
|
||||
:args {:invoice_id {:type 'Int}
|
||||
:args {:invoice_id {:type 'String}
|
||||
:amount {:type 'Float}
|
||||
:date {:type 'String}
|
||||
:check_number {:type 'Int}
|
||||
:bank_account_id {:type 'Int}}
|
||||
:bank_account_id {:type 'String}}
|
||||
:resolve :mutation/add-handwritten-check}
|
||||
:edit_user {:type :user
|
||||
:args {:edit_user {:type :edit_user}}
|
||||
|
||||
@@ -323,26 +323,34 @@
|
||||
:end (+ (:start args 0) (count payments))}]))
|
||||
|
||||
(defn add-handwritten-check [context args value]
|
||||
(let [invoice (invoices/get-by-id (:invoice_id args))
|
||||
(println args)
|
||||
|
||||
(let [invoice (d-invoices/get-by-id (Long/parseLong (:invoice_id args)))
|
||||
_ (assert-can-see-company (:id context) (:company-id invoice))
|
||||
check (checks/insert! {:s3-uuid nil
|
||||
:s3-key nil
|
||||
:s3-url nil
|
||||
:check-number (:check_number args)
|
||||
:date (parse (:date args) iso-date)
|
||||
:amount (:amount args)
|
||||
:bank-account-id (:bank_account_id args)
|
||||
:vendor-id (:vendor-id invoice)
|
||||
:company-id (:company-id invoice)
|
||||
:invoices [(:invoice_id args)]})]
|
||||
check {:payment/check-number (:check_number args)
|
||||
:payment/date (c/to-date (parse (:date args) iso-date))
|
||||
:payment/amount (:amount args)
|
||||
:payment/bank-account (Long/parseLong (:bank_account_id args))
|
||||
:payment/vendor (:db/id (:invoice/vendor invoice))
|
||||
:payment/client (:db/id (:invoice/client invoice))
|
||||
:payment/invoices [(Long/parseLong (:invoice_id args))]
|
||||
:db/id "the-check"}
|
||||
payment {:invoice-payment/payment "the-check"
|
||||
:invoice-payment/amount (:amount args)
|
||||
:invoice-payment/invoice (Long/parseLong (:invoice_id args))}
|
||||
invoice [:pay (Long/parseLong (:invoice_id args) ) (:amount args)]]
|
||||
|
||||
(invoices-checks/insert-multi! [{:invoice-id (:invoice_id args)
|
||||
#_(invoices-checks/insert-multi! [{:invoice-id (:invoice_id args)
|
||||
:check-id (:id check)
|
||||
:amount (:amount args)}])
|
||||
(invoices/apply-payment (:invoice_id args) (:amount args))
|
||||
#_(invoices/apply-payment (:invoice_id args) (:amount args))
|
||||
(println [check payment invoice])
|
||||
@(d/transact (d/connect uri) [check
|
||||
payment
|
||||
invoice])
|
||||
(->graphql
|
||||
{:s3-url nil
|
||||
:invoices [(invoices/get-by-id (:invoice_id args))]})))
|
||||
:invoices [(d-invoices/get-by-id (:invoice_id args))]})))
|
||||
|
||||
|
||||
(defn void-check [context {id :payment_id} value]
|
||||
|
||||
@@ -332,7 +332,7 @@
|
||||
:bank-account-id bank-account-id
|
||||
:invoice_id (:id invoice)
|
||||
}
|
||||
[[:invoices [:id :outstanding-balance [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]]]}]}
|
||||
[[:invoices [:id :outstanding-balance [:payments [:amount [:payment [:amount :s3_url :check_number ]]]]]]]]}]}
|
||||
:on-success [::handwrite-checks-succeeded]}})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
|
||||
Reference in New Issue
Block a user