scalar type for id simplifies parsing longs.

This commit is contained in:
Bryce Covert
2018-11-12 08:26:47 -08:00
parent 2263a5f24a
commit 6eaff40608
12 changed files with 80 additions and 81 deletions

View File

@@ -26,7 +26,7 @@
:in ['$]
:where []}
:args [(d/db (d/connect uri))]}
(add-arg '?e (cond-> id (string? id) Long/parseLong) ['?e])))
(add-arg '?e id ['?e])))
(map first)
(<-datomic)
(first)))

View File

@@ -27,13 +27,12 @@
{:payment/type [:db/ident]}]))
(defn raw-graphql [args]
(println "ARGS" args)
(let [query (cond-> {:query {:find [default-read]
:in ['$]
:where ['[?e :payment/client]]}
:args [(d/db (d/connect uri))]}
(:client-id args) (add-arg '?client-id (cond-> (:client-id args) (string? (:client-id args)) Long/parseLong )
(:client-id args) (add-arg '?client-id (:client-id args)
'[?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]
@@ -77,6 +76,6 @@
:in ['$]
:where []}
:args [(d/db (d/connect uri))]}
(add-arg '?e (cond-> id (string? id) Long/parseLong) ['?e])))
(add-arg '?e id ['?e])))
(<-datomic)
(first)))

View File

@@ -19,7 +19,7 @@
(d/query (-> {:query {:find ['(pull ?e [*])]
:in ['$ '?e]
:where [['?e]]}
:args [(d/db (d/connect uri)) (cond-> id (string? id) Long/parseLong)]}
:args [(d/db (d/connect uri)) id]}
))
(first)
(first)

View File

@@ -34,9 +34,7 @@
:where ['[?e :invoice/invoice-number]]}
:args [(d/db (d/connect uri))]}
(:client-id args) (add-arg '?client-id (cond-> (:client-id args)
(string? (:client-id args))
Long/parseLong)
(:client-id args) (add-arg '?client-id (:client-id args)
'[?e :invoice/client ?client-id])
(:original-id args) (add-arg '?original-id (cond-> (:original-id args) (string? (:original-id args)) Long/parseLong )
@@ -77,7 +75,7 @@
:in ['$]
:where []}
:args [(d/db (d/connect uri))]}
(add-arg '?e (cond-> id (string? id) Long/parseLong) ['?e])))
(add-arg '?e id ['?e])))
(map first)
(<-datomic)
(first)))
@@ -92,8 +90,7 @@
:in ['$ ['?e '...]]
:where [['?e]]}
:args [(d/db (d/connect uri))
(mapv #(cond-> % (string? %) Long/parseLong)
ids)] }
ids] }
)

View File

@@ -19,7 +19,7 @@
:where ['[?e :transaction/id]]}
:args [(d/db (d/connect uri))]}
(:client-id args) (add-arg '?client-id (Long/parseLong (:client-id args))
(:client-id args) (add-arg '?client-id (: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]

View File

@@ -18,7 +18,7 @@
:in ['$]
:where []}
:args [(d/db (d/connect uri))]}
(add-arg '?e (cond-> id (string? id) Long/parseLong) ['?e])
(add-arg '?e id ['?e])
(doto println))]
(->> (d/query query)

View File

@@ -21,9 +21,7 @@
:in $ ?e
:where [?e]]
(d/db (d/connect uri))
(if (string? id)
(Long/parseLong id)
id))
id)
(map first)
(first)
#_(map (fn [c]

View File

@@ -27,6 +27,9 @@
(def integreat-schema
{
:scalars {:id {
:parse (schema/as-conformer #(Long/parseLong %))
:serialize (schema/as-conformer #(.toString %))}}
:objects
{
:company
@@ -37,20 +40,20 @@
:locations {:type '(list String)}
:bank_accounts {:type '(list :bank_account)}}}
:client
{:fields {:id {:type 'String}
{:fields {:id {:type :id}
:name {:type 'String}
:email {:type 'String}
:address {:type :address}
:locations {:type '(list String)}
:bank_accounts {:type '(list :bank_account)}}}
:contact
{:fields {:id {:type 'String}
{:fields {:id {:type :id}
:name {:type 'String}
:email {:type 'String}
:phone {:type 'String}}}
:bank_account
{:fields {:id {:type 'String}
{:fields {:id {:type :id }
:type {:type :bank_account_type}
:number {:type 'String}
:check_number {:type 'Int}
@@ -65,7 +68,7 @@
:state {:type 'String}
:zip {:type 'String}}}
:vendor
{:fields {:id {:type 'String}
{:fields {:id {:type :id}
:name {:type 'String}
:code {:type 'String}
@@ -89,7 +92,7 @@
:check {:fields {:id {:type 'Int}
:check {:fields {:id {:type :id}
:type {:type 'String}
:amount {:type 'String}
:vendor {:type :vendor}
@@ -103,7 +106,7 @@
:invoices {:type '(list :invoice_payment)}
}}
:payment {:fields {:id {:type 'String}
:payment {:fields {:id {:type :id}
:type {:type :payment_type}
:amount {:type 'String}
:vendor {:type :vendor}
@@ -117,7 +120,7 @@
:invoices {:type '(list :invoice_payment)}
}}
:transaction {:fields {:id {:type 'String}
:transaction {:fields {:id {:type :id}
:amount {:type 'String}
:description_original {:type 'String}
:description_simple {:type 'String}
@@ -128,7 +131,7 @@
:date {:type 'String}
:post_date {:type 'String}}}
:invoice_payment
{:fields {:id {:type 'Int}
{:fields {:id {:type :id}
:amount {:type 'String}
:invoice_id {:type 'String}
:payment_id {:type 'String}
@@ -136,19 +139,19 @@
:invoice {:type :invoice}}}
:user
{:fields {:id {:type 'String}
{:fields {:id {:type :id}
:name {:type 'String}
:role {:type 'String}
:clients {:type '(list :client)}}}
:expense_account {:fields {:id {:type 'Int}
:expense_account {:fields {:id {:type :id}
:location {:type 'String}
:name {:type 'String}
:parent {:type :expense_account
:resolve :get-expense-account-parent}}}
:invoices_expense_accounts
{:fields {:id {:type 'String}
{:fields {:id {:type :id}
:invoice_id {:type 'String}
:expense_account_id {:type 'Int}
:location {:type 'String}
@@ -158,7 +161,7 @@
:amount {:type 'String}}}
:invoice
{:fields {:id {:type 'String}
{:fields {:id {:type :id}
:total {:type 'String}
:outstanding_balance {:type 'String}
:invoice_number {:type 'String}
@@ -203,7 +206,7 @@
{:invoice_page {:type '(list :invoice_page)
:args {:imported {:type 'Boolean}
:status {:type 'String}
:client_id {:type 'String}
:client_id {:type :id}
:start {:type 'Int}
:sort_by {:type 'String}
:asc {:type 'Boolean}}
@@ -211,19 +214,19 @@
:resolve :get-invoice-page}
:all_invoices {:type '(list :invoice)
:args {:client_id {:type 'String}
:args {:client_id {:type :id}
:original_id {:type 'Int}
:statuses {:type '(list String)}}
:resolve :get-all-invoices}
:all_payments {:type '(list :payment)
:args {:client_id {:type 'String}
:args {:client_id {:type :id}
:original_id {:type 'Int}
:statuses {:type '(list String)}}
:resolve :get-all-payments}
:transaction_page {:type '(list :transaction_page)
:args {:client_id {:type 'String}
:args {:client_id {:type :id}
:start {:type 'Int}
:sort_by {:type 'String}
:asc {:type 'Boolean}}
@@ -231,7 +234,7 @@
:resolve :get-transaction-page}
:payment_page {:type '(list :payment_page)
:args {:client_id {:type 'String}
:args {:client_id {:type :id}
:start {:type 'Int}
:sort_by {:type 'String}
:asc {:type 'Boolean}}
@@ -249,17 +252,17 @@
:input-objects
{
:invoice_payment_amount {:fields {:invoice_id {:type 'String}
:invoice_payment_amount {:fields {:invoice_id {:type :id}
:amount {:type 'Float}}}
:edit_user
{:fields {:id {:type 'String}
{:fields {:id {:type :id}
:name {:type 'String}
:role {:type 'String}
:clients {:type '(list String)}}}
:add_contact
{:fields {:id {:type 'String}
{:fields {:id {:type :id}
:name {:type 'String}
:email {:type 'String}
:phone {:type 'String}}}
@@ -271,7 +274,7 @@
:zip {:type 'String}}}
:add_vendor
{:fields {:id {:type 'String}
{:fields {:id {:type :id}
:name {:type 'String}
:code {:type 'String}
@@ -284,23 +287,23 @@
:invoice_reminder_schedule {:type 'String}}}
:edit_expense_account
{:fields {:id {:type 'String}
{:fields {:id {:type :id}
:expense_account_id {:type 'Int}
:location {:type 'String}
:amount {:type 'String}}}
:add_invoice
{:fields {:id {:type 'String}
{:fields {:id {:type :id}
:invoice_number {:type 'String}
:location {:type 'String}
:date {:type 'String}
:client_id {:type 'String}
:vendor_id {:type 'String}
:client_id {:type :id}
:vendor_id {:type :id}
:vendor_name {:type 'String}
:total {:type 'Float}}}
:edit_invoice
{:fields {:id {:type 'String}
{:fields {:id {:type :id}
:invoice_number {:type 'String}
:date {:type 'String}
:total {:type 'Float}}}}
@@ -313,17 +316,17 @@
:mutations
{:print_checks {:type :check_result
:args {:invoice_payments {:type '(list :invoice_payment_amount)}
:bank_account_id {:type 'String}
:bank_account_id {:type :id}
:type {:type :payment_type}
:client_id {:type 'String}}
:client_id {:type :id}}
:resolve :mutation/print-checks}
:add_handwritten_check {:type :check_result
:args {:invoice_id {:type 'String}
:args {:invoice_id {:type :id}
:amount {:type 'Float}
:date {:type 'String}
:check_number {:type 'Int}
:bank_account_id {:type 'String}}
:bank_account_id {:type :id}}
:resolve :mutation/add-handwritten-check}
:edit_user {:type :user
:args {:edit_user {:type :edit_user}}
@@ -339,13 +342,13 @@
:args {:invoice {:type :edit_invoice}}
:resolve :mutation/edit-invoice}
:void_invoice {:type :invoice
:args {:invoice_id {:type 'String}}
:args {:invoice_id {:type :id}}
:resolve :mutation/void-invoice}
:void_payment {:type :payment
:args {:payment_id {:type 'String}}
:args {:payment_id {:type :id}}
:resolve :mutation/void-payment}
:edit_expense_accounts {:type :invoice
:args {:invoice_id {:type 'String}
:args {:invoice_id {:type :id}
:expense_accounts {:type '(list :edit_expense_account)}}
:resolve :mutation/edit-expense-accounts}}})

View File

@@ -206,17 +206,17 @@
(defn invoice-payments [invoices invoice-amounts]
(->> (for [invoice invoices
:let [invoice-amount (invoice-amounts (:db/id invoice))]]
[{:invoice-payment/payment (-> invoice :invoice/vendor :db/id)
[{:invoice-payment/payment (-> invoice :invoice/vendor :db/id str)
:invoice-payment/amount invoice-amount
:invoice-payment/invoice (:db/id invoice)}
[:pay (:db/id invoice) invoice-amount]])
(reduce into [])))
(defn base-payment [invoices vendor-id client bank-account type index invoice-amounts]
{:db/id (str vendor-id)
(defn base-payment [invoices vendor client bank-account type index invoice-amounts]
{:db/id (str (:db/id vendor))
:payment/bank-account (:db/id bank-account)
:payment/amount (reduce + 0 (map (comp invoice-amounts :db/id) invoices))
:payment/vendor vendor-id
:payment/vendor (:db/id vendor)
:payment/client (:db/id client)
:payment/date (c/to-date (time/now))
:payment/invoices (map :db/id invoices)})
@@ -278,13 +278,11 @@
(defn print-checks [invoice-payments client-id bank-account-id type]
(let [type (keyword "payment-type" (name type))
client-id (Long/parseLong client-id)
bank-account-id (Long/parseLong bank-account-id)
invoices (d-invoices/get-multi (map :invoice-id invoice-payments))
client (d-clients/get-by-id client-id)
vendors (by :db/id (d-vendors/get-graphql {}))
invoice-amounts (by (comp #(Long/parseLong %) :invoice-id) :amount invoice-payments)
invoice-amounts (by :invoice-id :amount invoice-payments)
invoices-grouped-by-vendor (group-by (comp :db/id :invoice/vendor) invoices)
bank-account (d-bank-accounts/get-by-id bank-account-id)
@@ -292,7 +290,6 @@
(invoices->entities invoices (vendors vendor-id) client bank-account type index invoice-amounts))
(reduce into [])
doall)]
(when (= type :payment-type/check)
(make-pdfs (filter #(= :payment-type/check (:payment/type %)) checks)))
@(d/transact (d/connect uri) checks)
@@ -317,19 +314,22 @@
(defn add-handwritten-check [context args value]
(let [invoice (d-invoices/get-by-id (:invoice_id args))
bank-account-id (Long/parseLong (:bank_account_id args))
bank-account-id (:bank_account_id args)
bank-account (d-bank-accounts/get-by-id bank-account-id)
_ (assert-can-see-company (:id context) (:company-id invoice))
base-payment (base-payment [invoice] (:invoice/vendor invoice)
(:invoice/client invoice)
bank-account :payment-type/check 0 {(Long/parseLong (:invoice_id args)) (:amount args)})]
bank-account :payment-type/check 0 {(:invoice_id args) (:amount args)})]
@(d/transact (d/connect uri)
[(assoc base-payment
:payment/status :payment-status/pending
:payment/check-number (:check_number args)
:payment/date (c/to-date (parse (:date args) iso-date))
:payment/amount (:amount args))
[:pay (:db/id invoice) (:amount args)]])
(into [(assoc base-payment
:payment/type :payment-type/check
:payment/status :payment-status/pending
:payment/check-number (:check_number args)
:payment/date (c/to-date (parse (:date args) iso-date))
:payment/amount (:amount args))]
(invoice-payments [invoice] {(:invoice_id args) (:amount args)})))
(->graphql
{:s3-url nil
:invoices [(d-invoices/get-by-id (:invoice_id args))]})))
@@ -351,7 +351,7 @@
:invoice-status/unpaid
(:invoice/status invoice))}]))
(:payment/invoices check))
updated-payment {:db/id (Long/parseLong id)
updated-payment {:db/id id
:payment/amount 0.0
:payment/status :payment-status/voided}]

View File

@@ -31,8 +31,8 @@
(defn add-invoice [context {{:keys [total invoice_number location client_id vendor_id vendor_name date] :as in} :invoice} value]
(when (seq (d-invoices/find-conflicting {:invoice/invoice-number invoice_number
:invoice/vendor (Long/parseLong vendor_id)
:invoice/client (Long/parseLong client_id)}))
:invoice/vendor vendor_id
:invoice/client client_id}))
(throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number})))
(let [_ (assert-can-see-company (:id context) client_id)
vendor (d-vendors/get-by-id vendor_id)
@@ -42,8 +42,8 @@
(throw (ex-info (str "Vendor '" (:vendor/name vendor) "' does not have a default expense acount.") {:vendor-id vendor_id} )))
transaction [{:db/id "invoice"
:invoice/invoice-number invoice_number
:invoice/client (Long/parseLong client_id)
:invoice/vendor (Long/parseLong vendor_id)
:invoice/client client_id
:invoice/vendor vendor_id
:invoice/total total
:invoice/outstanding-balance total
:invoice/status :invoice-status/unpaid
@@ -64,7 +64,7 @@
(let [invoice (d-invoices/get-by-id id)
_ (when (seq (doto (d-invoices/find-conflicting {:db/id (Long/parseLong id)
_ (when (seq (doto (d-invoices/find-conflicting {:db/id id
:invoice/invoice-number invoice_number
:invoice/vendor (:db/id (:invoice/vendor invoice))
:invoice/client (:db/id (:invoice/client invoice))})
@@ -72,7 +72,7 @@
(throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number})))
paid-amount (- (:invoice/total invoice) (:invoice/outstanding-balance invoice))
_ (assert-can-see-company (:id context) (:db/id (:client invoice)))
updated-invoice (d-invoices/update {:db/id (Long/parseLong id)
updated-invoice (d-invoices/update {:db/id id
:invoice/invoice-number invoice_number
:invoice/date (coerce/to-date (parse date iso-date))
:invoice/total total
@@ -83,7 +83,7 @@
(defn void-invoice [context {id :invoice_id} value]
(let [invoice (d-invoices/get-by-id id)
_ (assert-can-see-company (:id context) (:company-id invoice))
updated-invoice (d-invoices/update {:db/id (Long/parseLong id)
updated-invoice (d-invoices/update {:db/id id
:invoice/total 0.0
:invoice/outstanding-balance 0.0
:invoice/status :invoice-status/voided})]
@@ -96,12 +96,14 @@
(defn edit-expense-accounts [context args value]
;; TODO - Can expense account id be used as a unique field? It may compose with component, meaning
;; that you don't have to figure out which ones to delete and which ones to add. Just set to 0.
(assert-can-see-company (:id context) (:db/id (:client (d-invoices/get-by-id (:invoice_id args)))))
(let [current-expense-accounts (:invoice/expense-accounts (d-invoices/get-by-id (:invoice_id args)))
invoice-id (Long/parseLong (:invoice_id args))
invoice-id (:invoice_id args)
specified-ids (->> (:expense_accounts args)
(map #(some-> % :id (Long/parseLong )))
(map :id)
set)
existing-ids (->> current-expense-accounts
@@ -114,7 +116,7 @@
{:db/id invoice-id
:invoice/expense-accounts [#:invoice-expense-account {
:amount (Double/parseDouble amount)
:db/id (some-> id Long/parseLong)
:db/id id
:expense-account-id expense_account_id
:location location}
]}

View File

@@ -10,7 +10,7 @@
(defn upsert-vendor [context {{:keys [id name code print_as primary_contact secondary_contact address default_expense_account invoice_reminder_schedule] :as in} :vendor} value]
(let [transaction [(remove-nils #:vendor {:db/id (if id
(Long/parseLong id)
id
"vendor")
:name name
:code code
@@ -19,7 +19,7 @@
:invoice-reminder-schedule (keyword invoice_reminder_schedule)
:address (when address
(remove-nils #:address {:db/id (if (:id address)
(Long/parseLong (:id address))
(:id address)
"address")
:street1 (:street1 address)
:street2 (:street2 address)
@@ -29,7 +29,7 @@
:primary-contact (when primary_contact
(remove-nils #:contact {:db/id (if (:id primary_contact)
(Long/parseLong (:id primary_contact))
(:id primary_contact)
"primary")
:name (:name primary_contact)
:phone (:phone primary_contact)
@@ -38,7 +38,7 @@
:secondary-contact (when secondary_contact
(remove-nils #:contact {:db/id (if (:id secondary_contact)
(Long/parseLong (:id secondary_contact))
(:id secondary_contact)
"secondary")
:name (:name secondary_contact)
:phone (:phone secondary_contact)

View File

@@ -163,7 +163,7 @@
[:td status]
[:td
(when (or (= ":pending" status)
(#{":cash" ":debit"} type))
(#{":cash" ":debit" :cash :debit} type))
[:button.button.is-warning.is-outlined {:on-click (dispatch-event [::void-check i])} [:span [:span.icon [:i.fa.fa-minus-circle]]]])
(if s3-url
[:a.tag {:href s3-url :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " check-number " (" (gstring/format "$%.2f" amount ) ")")]