allowing paying negative invoices.
This commit is contained in:
@@ -42,7 +42,7 @@
|
||||
:code (let [current-outstanding-balance (-> (d/entity db e) :invoice/outstanding-balance)
|
||||
new-outstanding-balance (- current-outstanding-balance amount)]
|
||||
[[:db/add e :invoice/outstanding-balance new-outstanding-balance]
|
||||
[:db/add e :invoice/status (if (> -0.001 new-outstanding-balance 0.001)
|
||||
[:db/add e :invoice/status (if (< -0.001 new-outstanding-balance 0.001)
|
||||
:invoice-status/paid
|
||||
:invoice-status/unpaid)]])})}]] )
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
conn (d/connect uri)
|
||||
norms-map {:auto-ap/base-schema {:txes auto-ap.datomic/base-schema}
|
||||
:auto-ap/functions {:txes-fn 'auto-ap.datomic.migrate/functions :requires [:auto-ap/base-schema]}
|
||||
:auto-ap/fx-pay-function {:txes-fn 'auto-ap.datomic.migrate/fix-pay-function :requires [:auto-ap/functions]}
|
||||
:auto-ap/fx-pay-function-2 {:txes-fn 'auto-ap.datomic.migrate/fix-pay-function :requires [:auto-ap/functions]}
|
||||
:auto-ap/migrate-vendors {:txes-fn 'auto-ap.datomic/migrate-vendors :requires [:auto-ap/base-schema]}
|
||||
:auto-ap/migrate-clients {:txes-fn 'auto-ap.datomic/migrate-clients :requires [:auto-ap/migrate-vendors]}
|
||||
:auto-ap/migrate-users {:txes-fn 'auto-ap.datomic/migrate-users :requires [:auto-ap/migrate-clients]}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.datomic.bank-accounts :as d-bank-accounts]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[auto-ap.datomic :refer [uri remove-nils]]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[auto-ap.numeric :refer [num->words]]
|
||||
[config.core :refer [env]]
|
||||
@@ -181,6 +181,7 @@
|
||||
(edn/read-string)
|
||||
|
||||
|
||||
|
||||
make-check-pdf
|
||||
(io/make-input-stream {}))
|
||||
:metadata {:content-type "application/pdf"})
|
||||
@@ -228,29 +229,32 @@
|
||||
(map (fn [i]
|
||||
(str (:invoice/invoice-number i) "(" (invoice-amounts (:db/id i)) ")"))
|
||||
invoices)))
|
||||
payment (assoc (base-payment invoices vendor client bank-account type index invoice-amounts)
|
||||
:payment/s3-uuid uuid
|
||||
:payment/s3-key (str "checks/" uuid ".pdf")
|
||||
:payment/s3-url (str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/checks/" uuid ".pdf")
|
||||
:payment/check-number (+ index (:bank-account/check-number bank-account))
|
||||
:payment/type :payment-type/check
|
||||
:payment/memo memo
|
||||
:payment/status :payment-status/pending
|
||||
:payment/pdf-data (pr-str {:vendor vendor
|
||||
:paid-to (or (:vendor/paid-to vendor) (:vendor/name vendor))
|
||||
:amount (reduce + 0 (map (comp invoice-amounts :db/id) invoices))
|
||||
:check (str (+ index (:bank-account/check-number bank-account)))
|
||||
:memo memo
|
||||
:date (date->str (local-now))
|
||||
:client client
|
||||
:bank-account bank-account
|
||||
#_#_:client {:name (:name client)
|
||||
:address (:address client)
|
||||
:signature-file (:signature-file client)
|
||||
:bank {:name (:bank-account/bank-name bank-account)
|
||||
:acct (:bank-account/bank-code bank-account)
|
||||
:routing (:bank-account/routing bank-account)
|
||||
:acct-number (:bank-account/number bank-account)}}}))]
|
||||
base-payment (base-payment invoices vendor client bank-account type index invoice-amounts)
|
||||
payment
|
||||
(remove-nils
|
||||
(assoc base-payment
|
||||
:payment/s3-uuid (when (> (:payment/amount base-payment) 0) uuid)
|
||||
:payment/s3-key (when (> (:payment/amount base-payment) 0) (str "checks/" uuid ".pdf"))
|
||||
:payment/s3-url (when (> (:payment/amount base-payment) 0) (str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/checks/" uuid ".pdf"))
|
||||
:payment/check-number (+ index (:bank-account/check-number bank-account))
|
||||
:payment/type :payment-type/check
|
||||
:payment/memo memo
|
||||
:payment/status :payment-status/pending
|
||||
:payment/pdf-data (pr-str {:vendor vendor
|
||||
:paid-to (or (:vendor/paid-to vendor) (:vendor/name vendor))
|
||||
:amount (reduce + 0 (map (comp invoice-amounts :db/id) invoices))
|
||||
:check (str (+ index (:bank-account/check-number bank-account)))
|
||||
:memo memo
|
||||
:date (date->str (local-now))
|
||||
:client client
|
||||
:bank-account bank-account
|
||||
#_#_:client {:name (:name client)
|
||||
:address (:address client)
|
||||
:signature-file (:signature-file client)
|
||||
:bank {:name (:bank-account/bank-name bank-account)
|
||||
:acct (:bank-account/bank-code bank-account)
|
||||
:routing (:bank-account/routing bank-account)
|
||||
:acct-number (:bank-account/number bank-account)}}})))]
|
||||
|
||||
(-> []
|
||||
(conj payment)
|
||||
@@ -301,7 +305,10 @@
|
||||
(conj checks [:inc (:db/id bank-account) :bank-account/check-number (count invoices-grouped-by-vendor)])
|
||||
checks)]
|
||||
(when (= type :payment-type/check)
|
||||
(make-pdfs (filter #(= :payment-type/check (:payment/type %)) checks)))
|
||||
(make-pdfs (filter #(and (= :payment-type/check (:payment/type %))
|
||||
(> (:payment/amount %) 0.0)
|
||||
)
|
||||
checks)))
|
||||
@(d/transact (d/connect uri) checks)
|
||||
|
||||
|
||||
@@ -355,9 +362,9 @@
|
||||
[[:db.fn/retractEntity (:db/id x)]
|
||||
{:db/id (:db/id invoice)
|
||||
:invoice/outstanding-balance new-balance
|
||||
:invoice/status (if (> new-balance 0)
|
||||
:invoice-status/unpaid
|
||||
(:invoice/status invoice))}]))
|
||||
:invoice/status (if (< -0.001 new-balance 0.001)
|
||||
(:invoice/status invoice)
|
||||
:invoice-status/unpaid)}]))
|
||||
(:payment/invoices check))
|
||||
updated-payment {:db/id id
|
||||
:payment/amount 0.0
|
||||
|
||||
@@ -508,7 +508,20 @@
|
||||
:disabled (cond printing?
|
||||
"disabled"
|
||||
|
||||
(seq (filter #(> (js/parseFloat (:amount %)) (js/parseFloat (:outstanding-balance %))) invoices))
|
||||
(seq (filter
|
||||
(fn [{:keys [outstanding-balance amount]}]
|
||||
(let [amount (js/parseFloat amount)
|
||||
outstanding-balance (js/parseFloat outstanding-balance)]
|
||||
(println amount outstanding-balance)
|
||||
(or (and (> outstanding-balance 0)
|
||||
(> amount outstanding-balance))
|
||||
(and (> outstanding-balance 0)
|
||||
(<= amount 0))
|
||||
(and (< outstanding-balance 0)
|
||||
(< amount outstanding-balance))
|
||||
(and (< outstanding-balance 0)
|
||||
(>= amount 0)))))
|
||||
invoices))
|
||||
"disabled"
|
||||
|
||||
:else
|
||||
@@ -872,7 +885,7 @@
|
||||
[drop-down {:header [:button.button.is-success {:aria-haspopup true
|
||||
:on-click (dispatch-event [::events/toggle-menu ::print-checks ])
|
||||
:disabled (if (and (seq checked-invoices)
|
||||
(->> checked-invoices
|
||||
#_(->> checked-invoices
|
||||
vals
|
||||
(group-by #(get-in % [:vendor :id]))
|
||||
(reduce-kv (fn [negative? _ invoices]
|
||||
|
||||
Reference in New Issue
Block a user