Vendor autopay re-instated.
This commit is contained in:
@@ -98,3 +98,13 @@
|
||||
first
|
||||
:vendor-account-override/account)
|
||||
(:vendor/default-account vendor)))
|
||||
|
||||
(defn automatically-paid-for-client-id? [vendor client-id]
|
||||
(->>
|
||||
(:vendor/automatically-paid-when-due vendor)
|
||||
(filter
|
||||
(fn [client]
|
||||
(= (:db/id client)
|
||||
client-id)))
|
||||
first
|
||||
boolean))
|
||||
|
||||
@@ -62,6 +62,13 @@
|
||||
(defn add-invoice-transaction [{:keys [total invoice_number location scheduled_payment client_id vendor_id vendor_name date due expense_accounts] :as in}]
|
||||
(let [vendor (d-vendors/get-by-id vendor_id)
|
||||
account (:vendor/default-account vendor)
|
||||
due (or (and (:vendor/terms vendor)
|
||||
(coerce/to-date
|
||||
(time/plus date (time/days (d-vendors/terms-for-client-id vendor client_id)))))
|
||||
due)
|
||||
scheduled_payment (or scheduled_payment
|
||||
(and (d-vendors/automatically-paid-for-client-id? vendor client_id)
|
||||
due))
|
||||
_ (when-not (:db/id account)
|
||||
(throw (ex-info (str "Vendor '" (:vendor/name vendor) "' does not have a default expense acount.") {:vendor-id vendor_id} )))]
|
||||
(cond->
|
||||
@@ -76,8 +83,6 @@
|
||||
:invoice/date (coerce/to-date date)
|
||||
:invoice/expense-accounts (map expense-account->entity
|
||||
expense_accounts)}
|
||||
(:vendor/terms vendor) (assoc :invoice/due (coerce/to-date
|
||||
(time/plus date (time/days (d-vendors/terms-for-client-id vendor client_id)))))
|
||||
due (assoc :invoice/due (coerce/to-date due))
|
||||
|
||||
scheduled_payment (assoc :invoice/scheduled-payment (coerce/to-date scheduled_payment)))))
|
||||
|
||||
@@ -119,6 +119,7 @@
|
||||
:keywords [#"GOLDEN BRANDS"]
|
||||
:extract {:date #"(?:.*\n){4}(.*)" ;; HOW TO GO TO SPCIFIC LINE
|
||||
:customer-identifier #"Account:(?:.*\n)(.*(?=\s{2,}))"
|
||||
:account-number #"Account:\s*(.*?)\n"
|
||||
:invoice-number #"Invoice#: (\d+)"
|
||||
:total #"Invoice Total\s+([0-9,]+\.[0-9]{2})"}
|
||||
:parser {:date [:clj-time "EEE MMM dd, yyyy HH:mm aa"]
|
||||
|
||||
@@ -141,10 +141,13 @@
|
||||
::editing
|
||||
(fn [db [_ which]]
|
||||
(let [accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id (:client which)])
|
||||
vendor (get @(re-frame/subscribe [::subs/vendors-by-id]) (:id (:vendor which)))
|
||||
edit-invoice (update which :date #(date->str % standard))
|
||||
edit-invoice (update edit-invoice :due #(date->str % standard))
|
||||
edit-invoice (update edit-invoice :scheduled-payment #(date->str % standard))
|
||||
edit-invoice (assoc edit-invoice :original edit-invoice)
|
||||
edit-invoice (assoc edit-invoice :vendor-autopay? (boolean ((set (map :id (:automatically-paid-when-due vendor)))
|
||||
(:id (:client which)))))
|
||||
locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])
|
||||
]
|
||||
(-> db
|
||||
@@ -153,6 +156,8 @@
|
||||
:status (:status edit-invoice)
|
||||
:date (:date edit-invoice)
|
||||
:due (:due edit-invoice)
|
||||
:vendor-autopay? (boolean ((set (map :id (:automatically-paid-when-due vendor)))
|
||||
(:id (:client which))))
|
||||
:scheduled-payment (:scheduled-payment edit-invoice)
|
||||
:invoice-number (:invoice-number edit-invoice)
|
||||
:total (:total edit-invoice)
|
||||
|
||||
Reference in New Issue
Block a user