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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -206,17 +206,17 @@
(defn invoice-payments [invoices invoice-amounts] (defn invoice-payments [invoices invoice-amounts]
(->> (for [invoice invoices (->> (for [invoice invoices
:let [invoice-amount (invoice-amounts (:db/id invoice))]] :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/amount invoice-amount
:invoice-payment/invoice (:db/id invoice)} :invoice-payment/invoice (:db/id invoice)}
[:pay (:db/id invoice) invoice-amount]]) [:pay (:db/id invoice) invoice-amount]])
(reduce into []))) (reduce into [])))
(defn base-payment [invoices vendor-id client bank-account type index invoice-amounts] (defn base-payment [invoices vendor client bank-account type index invoice-amounts]
{:db/id (str vendor-id) {:db/id (str (:db/id vendor))
:payment/bank-account (:db/id bank-account) :payment/bank-account (:db/id bank-account)
:payment/amount (reduce + 0 (map (comp invoice-amounts :db/id) invoices)) :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/client (:db/id client)
:payment/date (c/to-date (time/now)) :payment/date (c/to-date (time/now))
:payment/invoices (map :db/id invoices)}) :payment/invoices (map :db/id invoices)})
@@ -278,13 +278,11 @@
(defn print-checks [invoice-payments client-id bank-account-id type] (defn print-checks [invoice-payments client-id bank-account-id type]
(let [type (keyword "payment-type" (name 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)) invoices (d-invoices/get-multi (map :invoice-id invoice-payments))
client (d-clients/get-by-id client-id) client (d-clients/get-by-id client-id)
vendors (by :db/id (d-vendors/get-graphql {})) 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) invoices-grouped-by-vendor (group-by (comp :db/id :invoice/vendor) invoices)
bank-account (d-bank-accounts/get-by-id bank-account-id) 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)) (invoices->entities invoices (vendors vendor-id) client bank-account type index invoice-amounts))
(reduce into []) (reduce into [])
doall)] doall)]
(when (= type :payment-type/check) (when (= type :payment-type/check)
(make-pdfs (filter #(= :payment-type/check (:payment/type %)) checks))) (make-pdfs (filter #(= :payment-type/check (:payment/type %)) checks)))
@(d/transact (d/connect uri) checks) @(d/transact (d/connect uri) checks)
@@ -317,19 +314,22 @@
(defn add-handwritten-check [context args value] (defn add-handwritten-check [context args value]
(let [invoice (d-invoices/get-by-id (:invoice_id args)) (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) bank-account (d-bank-accounts/get-by-id bank-account-id)
_ (assert-can-see-company (:id context) (:company-id invoice)) _ (assert-can-see-company (:id context) (:company-id invoice))
base-payment (base-payment [invoice] (:invoice/vendor invoice) base-payment (base-payment [invoice] (:invoice/vendor invoice)
(:invoice/client 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) @(d/transact (d/connect uri)
[(assoc base-payment (into [(assoc base-payment
:payment/status :payment-status/pending :payment/type :payment-type/check
:payment/check-number (:check_number args) :payment/status :payment-status/pending
:payment/date (c/to-date (parse (:date args) iso-date)) :payment/check-number (:check_number args)
:payment/amount (:amount args)) :payment/date (c/to-date (parse (:date args) iso-date))
[:pay (:db/id invoice) (:amount args)]]) :payment/amount (:amount args))]
(invoice-payments [invoice] {(:invoice_id args) (:amount args)})))
(->graphql (->graphql
{:s3-url nil {:s3-url nil
:invoices [(d-invoices/get-by-id (:invoice_id args))]}))) :invoices [(d-invoices/get-by-id (:invoice_id args))]})))
@@ -351,7 +351,7 @@
:invoice-status/unpaid :invoice-status/unpaid
(:invoice/status invoice))}])) (:invoice/status invoice))}]))
(:payment/invoices check)) (:payment/invoices check))
updated-payment {:db/id (Long/parseLong id) updated-payment {:db/id id
:payment/amount 0.0 :payment/amount 0.0
:payment/status :payment-status/voided}] :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] (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 (when (seq (d-invoices/find-conflicting {:invoice/invoice-number invoice_number
:invoice/vendor (Long/parseLong vendor_id) :invoice/vendor vendor_id
:invoice/client (Long/parseLong client_id)})) :invoice/client client_id}))
(throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number}))) (throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number})))
(let [_ (assert-can-see-company (:id context) client_id) (let [_ (assert-can-see-company (:id context) client_id)
vendor (d-vendors/get-by-id vendor_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} ))) (throw (ex-info (str "Vendor '" (:vendor/name vendor) "' does not have a default expense acount.") {:vendor-id vendor_id} )))
transaction [{:db/id "invoice" transaction [{:db/id "invoice"
:invoice/invoice-number invoice_number :invoice/invoice-number invoice_number
:invoice/client (Long/parseLong client_id) :invoice/client client_id
:invoice/vendor (Long/parseLong vendor_id) :invoice/vendor vendor_id
:invoice/total total :invoice/total total
:invoice/outstanding-balance total :invoice/outstanding-balance total
:invoice/status :invoice-status/unpaid :invoice/status :invoice-status/unpaid
@@ -64,7 +64,7 @@
(let [invoice (d-invoices/get-by-id id) (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/invoice-number invoice_number
:invoice/vendor (:db/id (:invoice/vendor invoice)) :invoice/vendor (:db/id (:invoice/vendor invoice))
:invoice/client (:db/id (:invoice/client 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}))) (throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number})))
paid-amount (- (:invoice/total invoice) (:invoice/outstanding-balance invoice)) paid-amount (- (:invoice/total invoice) (:invoice/outstanding-balance invoice))
_ (assert-can-see-company (:id context) (:db/id (:client 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/invoice-number invoice_number
:invoice/date (coerce/to-date (parse date iso-date)) :invoice/date (coerce/to-date (parse date iso-date))
:invoice/total total :invoice/total total
@@ -83,7 +83,7 @@
(defn void-invoice [context {id :invoice_id} value] (defn void-invoice [context {id :invoice_id} value]
(let [invoice (d-invoices/get-by-id id) (let [invoice (d-invoices/get-by-id id)
_ (assert-can-see-company (:id context) (:company-id invoice)) _ (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/total 0.0
:invoice/outstanding-balance 0.0 :invoice/outstanding-balance 0.0
:invoice/status :invoice-status/voided})] :invoice/status :invoice-status/voided})]
@@ -96,12 +96,14 @@
(defn edit-expense-accounts [context args value] (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))))) (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))) (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) specified-ids (->> (:expense_accounts args)
(map #(some-> % :id (Long/parseLong ))) (map :id)
set) set)
existing-ids (->> current-expense-accounts existing-ids (->> current-expense-accounts
@@ -114,7 +116,7 @@
{:db/id invoice-id {:db/id invoice-id
:invoice/expense-accounts [#:invoice-expense-account { :invoice/expense-accounts [#:invoice-expense-account {
:amount (Double/parseDouble amount) :amount (Double/parseDouble amount)
:db/id (some-> id Long/parseLong) :db/id id
:expense-account-id expense_account_id :expense-account-id expense_account_id
:location location} :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] (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 (let [transaction [(remove-nils #:vendor {:db/id (if id
(Long/parseLong id) id
"vendor") "vendor")
:name name :name name
:code code :code code
@@ -19,7 +19,7 @@
:invoice-reminder-schedule (keyword invoice_reminder_schedule) :invoice-reminder-schedule (keyword invoice_reminder_schedule)
:address (when address :address (when address
(remove-nils #:address {:db/id (if (:id address) (remove-nils #:address {:db/id (if (:id address)
(Long/parseLong (:id address)) (:id address)
"address") "address")
:street1 (:street1 address) :street1 (:street1 address)
:street2 (:street2 address) :street2 (:street2 address)
@@ -29,7 +29,7 @@
:primary-contact (when primary_contact :primary-contact (when primary_contact
(remove-nils #:contact {:db/id (if (:id primary_contact) (remove-nils #:contact {:db/id (if (:id primary_contact)
(Long/parseLong (:id primary_contact)) (:id primary_contact)
"primary") "primary")
:name (:name primary_contact) :name (:name primary_contact)
:phone (:phone primary_contact) :phone (:phone primary_contact)
@@ -38,7 +38,7 @@
:secondary-contact (when secondary_contact :secondary-contact (when secondary_contact
(remove-nils #:contact {:db/id (if (:id secondary_contact) (remove-nils #:contact {:db/id (if (:id secondary_contact)
(Long/parseLong (:id secondary_contact)) (:id secondary_contact)
"secondary") "secondary")
:name (:name secondary_contact) :name (:name secondary_contact)
:phone (:phone secondary_contact) :phone (:phone secondary_contact)

View File

@@ -163,7 +163,7 @@
[:td status] [:td status]
[:td [:td
(when (or (= ":pending" status) (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]]]]) [:button.button.is-warning.is-outlined {:on-click (dispatch-event [::void-check i])} [:span [:span.icon [:i.fa.fa-minus-circle]]]])
(if s3-url (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 ) ")")] [: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 ) ")")]