fixes
This commit is contained in:
@@ -316,6 +316,10 @@
|
||||
invoices-grouped-by-vendor (group-by (comp :db/id :invoice/vendor) invoices)
|
||||
bank-account (d-bank-accounts/get-by-id bank-account-id)
|
||||
_ (validate-belonging client-id invoices bank-account)
|
||||
_ (when (nil? (:bank-account/check-number bank-account))
|
||||
(let [message (str "The bank account " (:bank-account/name bank-account) " does not have a starting check number. Please ask the integreat staff to initialize it.")]
|
||||
(throw (ex-info message
|
||||
{:validation-error message}))))
|
||||
_ (if (dollars-0? (reduce + 0.0 (filter
|
||||
#(>= % 0.0)
|
||||
(map :amount invoice-payments))))
|
||||
|
||||
@@ -339,7 +339,7 @@
|
||||
_ (assert-can-see-client (:id context) (:transaction/client transaction) )
|
||||
db (d/db conn)
|
||||
invoice-clients (set (map (comp :db/id :invoice/client #(d/entity db %)) unpaid_invoice_ids))
|
||||
invoice-amount (reduce + 0.0 (map (comp :invoice/total #(d/entity db %)) unpaid_invoice_ids))]
|
||||
invoice-amount (reduce + 0.0 (map (comp :invoice/outstanding-balance #(d/entity db %)) unpaid_invoice_ids))]
|
||||
(when (or (> (count invoice-clients) 1)
|
||||
(not= (:db/id (:transaction/client transaction))
|
||||
(first invoice-clients)))
|
||||
|
||||
@@ -86,13 +86,13 @@
|
||||
|
||||
(defn match-transaction-to-unpaid-invoices [amount client-id]
|
||||
(log/info "trying to find unpaid invoices for " client-id amount)
|
||||
(let [candidate-invoices-vendor-groups (->> (d/query {:query {:find ['?vendor-id '?e '?total '?d]
|
||||
(let [candidate-invoices-vendor-groups (->> (d/query {:query {:find ['?vendor-id '?e '?outstanding-balance '?d]
|
||||
:in ['$ '?client-id]
|
||||
:where ['[?e :invoice/client ?client-id]
|
||||
'[?e :invoice/status :invoice-status/unpaid]
|
||||
'(not [_ :invoice-payment/invoice ?e])
|
||||
'[?e :invoice/vendor ?vendor-id]
|
||||
'[?e :invoice/total ?total]
|
||||
'[?e :invoice/outstanding-balance ?outstanding-balance]
|
||||
'[?e :invoice/date ?d]]}
|
||||
:args [(d/db conn) client-id]})
|
||||
(sort-by last) ;; sort by scheduled payment date
|
||||
@@ -118,6 +118,7 @@
|
||||
(log/info "Adding a new payment for transaction " (:transaction/id transaction) " and invoices " invoice-payments)
|
||||
(let [payment-id (d/tempid :db.part/user)]
|
||||
(-> tx
|
||||
|
||||
(conj {:payment/bank-account bank-account-id
|
||||
:payment/client client-id
|
||||
:payment/amount (- (:transaction/amount transaction))
|
||||
@@ -126,11 +127,14 @@
|
||||
:payment/type :payment-type/debit
|
||||
:payment/status :payment-status/cleared
|
||||
:db/id payment-id})
|
||||
(into (map (fn [[vendor invoice-id invoice-amount]]
|
||||
{:invoice-payment/invoice invoice-id
|
||||
:invoice-payment/payment payment-id
|
||||
:invoice-payment/amount invoice-amount})
|
||||
invoice-payments))
|
||||
(into (mapcat (fn [[vendor invoice-id invoice-amount]]
|
||||
[{:invoice-payment/invoice invoice-id
|
||||
:invoice-payment/payment payment-id
|
||||
:invoice-payment/amount invoice-amount}
|
||||
{:db/id invoice-id
|
||||
:invoice/outstanding-balance 0.0
|
||||
:invoice/status :invoice-status/paid}])
|
||||
invoice-payments))
|
||||
(update 0 assoc
|
||||
:transaction/payment payment-id
|
||||
:transaction/approval-status :transaction-approval-status/approved
|
||||
|
||||
@@ -135,7 +135,7 @@
|
||||
(re-frame/reg-event-fx
|
||||
::set-active-page
|
||||
(fn [{:keys [db]} [_ handler params]]
|
||||
|
||||
|
||||
(if (and (not= :login handler) (not (:user db)))
|
||||
{:redirect "/login"
|
||||
:db (assoc db :active-page :login
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(defn- parse-url [url]
|
||||
(println url)
|
||||
(println "parsing url" url)
|
||||
(bidi/match-route routes/routes url))
|
||||
|
||||
(defn- dispatch-route [matched-route]
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
(def invoice-read [:id :total :outstanding-balance :date :due :invoice-number :status
|
||||
:scheduled-payment
|
||||
[:client [:id :name :locations]]
|
||||
[:payments [:amount [:payment [:amount :s3_url :check_number ]]]]
|
||||
[:payments [:amount [:payment [:id :amount :s3_url :check_number ]]]]
|
||||
[:vendor [:id :name]]
|
||||
[:expense_accounts [:amount :id
|
||||
:location
|
||||
|
||||
Reference in New Issue
Block a user