several fixes.
This commit is contained in:
@@ -184,22 +184,12 @@
|
||||
:customer-identifier customer-identifier
|
||||
:vendor-code vendor-code})))
|
||||
|
||||
[matching-vendor default-account] (->> (d/query
|
||||
{:query {:find ['?vendor '?default-account]
|
||||
[matching-vendor] (->> (d/query
|
||||
{:query {:find [(list 'pull '?vendor d-vendors/default-read)]
|
||||
:in ['$ '?vendor-name]
|
||||
:where ['[?vendor :vendor/name ?vendor-name]
|
||||
'[?vendor :vendor/default-account ?default-account]]}
|
||||
:where ['[?vendor :vendor/name ?vendor-name]]}
|
||||
:args [(d/db (d/connect uri)) vendor-code]})
|
||||
first)
|
||||
[account-override] (->> (d/query
|
||||
{:query {:find ['?account-override-account]
|
||||
:in ['$ '?vendor '?client]
|
||||
:where ['[?vendor :vendor/account-overrides ?account-override]
|
||||
'[?account-override :vendor-account-override/client ?client]
|
||||
'[?account-override :vendor-account-override/account ?account-override-account]]}
|
||||
:args [(d/db (d/connect uri)) matching-vendor (:db/id matching-client)]})
|
||||
first)
|
||||
|
||||
_ (when-not matching-vendor
|
||||
(throw (ex-info (str "No vendor with the name " vendor-code " was found.")
|
||||
{:invoice-number invoice-number
|
||||
@@ -221,7 +211,7 @@
|
||||
[?e :invoice/status ?status]
|
||||
[?e :invoice/import-status ?import-status]
|
||||
[?import-status :db/ident ?import-status2]]}
|
||||
:args [(d/db (d/connect uri)) invoice-number matching-vendor (:db/id matching-client)]}))
|
||||
:args [(d/db (d/connect uri)) invoice-number (:db/id matching-vendor) (:db/id matching-client)]}))
|
||||
first)
|
||||
(catch Exception e
|
||||
(throw (ex-info (str "Failed to find potential matching invoice with"
|
||||
@@ -239,20 +229,22 @@
|
||||
result
|
||||
|
||||
:else
|
||||
(conj result (remove-nils #:invoice {:invoice/client (:db/id matching-client)
|
||||
:invoice/client-identifier customer-identifier
|
||||
:invoice/vendor matching-vendor
|
||||
:invoice/invoice-number invoice-number
|
||||
:invoice/total (Double/parseDouble total)
|
||||
:invoice/date (to-date date)
|
||||
:invoice/import-status :import-status/pending
|
||||
:invoice/outstanding-balance (or existing-outstanding-balance (Double/parseDouble total))
|
||||
:invoice/status (or existing-status :invoice-status/unpaid)
|
||||
:invoice/expense-accounts (when-not existing-id [#:invoice-expense-account {:account (or account-override default-account)
|
||||
:location matching-location
|
||||
:amount (Double/parseDouble total)}])
|
||||
:db/id existing-id
|
||||
})))
|
||||
(conj result (cond-> (remove-nils #:invoice {:invoice/client (:db/id matching-client)
|
||||
:invoice/client-identifier customer-identifier
|
||||
:invoice/vendor matching-vendor
|
||||
:invoice/invoice-number invoice-number
|
||||
:invoice/total (Double/parseDouble total)
|
||||
:invoice/date (to-date date)
|
||||
:invoice/import-status :import-status/pending
|
||||
:invoice/outstanding-balance (or existing-outstanding-balance (Double/parseDouble total))
|
||||
:invoice/status (or existing-status :invoice-status/unpaid)
|
||||
:invoice/expense-accounts (when-not existing-id [#:invoice-expense-account {:account (d-vendors/account-for-client-id matching-vendor (:db/id matching-client))
|
||||
:location matching-location
|
||||
:amount (Double/parseDouble total)}])
|
||||
:db/id existing-id
|
||||
})
|
||||
(:vendor/terms matching-vendor) (assoc :invoice/due (coerce/to-date
|
||||
(time/plus date (time/days (d-vendors/terms-for-client-id matching-vendor (:db/id matching-client)))))))))
|
||||
))
|
||||
[]
|
||||
imports)]
|
||||
|
||||
Reference in New Issue
Block a user