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