scalar type for id simplifies parsing longs.
This commit is contained in:
@@ -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}]
|
||||
|
||||
|
||||
@@ -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}
|
||||
]}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user