Tons of small fixes
This commit is contained in:
@@ -293,6 +293,19 @@
|
||||
(conj payment)
|
||||
(into (invoice-payments invoices invoice-amounts)))))
|
||||
|
||||
(defn validate-belonging [client-id invoices bank-account]
|
||||
(when-not (apply = client-id (map (comp :db/id :invoice/client) invoices ))
|
||||
(throw (ex-info "You can't pay for that invoice from this bank account."
|
||||
{:validation-error "You can't pay for that invoice from this bank account."
|
||||
:client-id client-id
|
||||
:invoices (map :invoice/invoice-number invoices)}))
|
||||
)
|
||||
(when-not (= client-id (:db/id (:client/_bank-accounts bank-account)))
|
||||
(throw (ex-info "The selected bank doesn't belong to this client"
|
||||
{:validation-error "The selected bank doesn't belong to this client"
|
||||
:client-id client-id
|
||||
:invoices (map :invoice/invoice-number invoices)}))))
|
||||
|
||||
(defn print-checks [invoice-payments client-id bank-account-id type]
|
||||
(let [type (keyword "payment-type" (name type))
|
||||
invoices (d-invoices/get-multi (map :invoice-id invoice-payments))
|
||||
@@ -303,6 +316,8 @@
|
||||
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)
|
||||
|
||||
checks (->> (for [[[vendor-id invoices] index] (map vector invoices-grouped-by-vendor (range))]
|
||||
(invoices->entities invoices (vendors vendor-id) client bank-account type index invoice-amounts))
|
||||
(reduce into [])
|
||||
@@ -347,6 +362,7 @@
|
||||
bank-account (d-bank-accounts/get-by-id bank-account-id)
|
||||
_ (doseq [invoice invoices]
|
||||
(assert-can-see-client (:id context) (:invoice/client invoice)))
|
||||
_ (validate-belonging (:db/id (:client/_bank-accounts bank-account)) invoices bank-account)
|
||||
invoice-payment-lookup (by :invoice_id :amount (:invoice_payments args))
|
||||
base-payment (base-payment invoices
|
||||
(:invoice/vendor (first invoices))
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
:account account_id
|
||||
:location location}))
|
||||
|
||||
(defn add-invoice-transaction [{:keys [total invoice_number location client_id vendor_id vendor_name date due expense_accounts] :as in}]
|
||||
(defn add-invoice-transaction [{:keys [total invoice_number location automatically_paid_when_due client_id vendor_id vendor_name date due expense_accounts] :as in}]
|
||||
(println date)
|
||||
(let [vendor (d-vendors/get-by-id vendor_id)
|
||||
account (:vendor/default-account vendor)
|
||||
@@ -77,7 +77,8 @@
|
||||
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)))))
|
||||
due (assoc :invoice/due (coerce/to-date due))
|
||||
(boolean? automatically_paid_when_due) (assoc :invoice/automatically-paid-when-due automatically_paid_when_due))))
|
||||
|
||||
|
||||
(defn deleted-expense-accounts [invoice expense-accounts]
|
||||
@@ -116,7 +117,7 @@
|
||||
->graphql)))
|
||||
|
||||
|
||||
(defn edit-invoice [context {{:keys [id due invoice_number total vendor_id date client_id expense_accounts] :as in} :invoice} value]
|
||||
(defn edit-invoice [context {{:keys [id due invoice_number total vendor_id date client_id expense_accounts automatically_paid_when_due] :as in} :invoice} value]
|
||||
(let [invoice (d-invoices/get-by-id id)
|
||||
_ (when (seq (doto (d-invoices/find-conflicting {:db/id id
|
||||
:invoice/invoice-number invoice_number
|
||||
@@ -136,11 +137,13 @@
|
||||
updated-invoice (cond-> {:db/id id
|
||||
:invoice/invoice-number invoice_number
|
||||
:invoice/date (coerce/to-date date)
|
||||
|
||||
:invoice/total total
|
||||
:invoice/outstanding-balance (- total paid-amount)
|
||||
:invoice/expense-accounts (map expense-account->entity
|
||||
expense_accounts)}
|
||||
due (assoc :invoice/due (coerce/to-date due)))]
|
||||
due (assoc :invoice/due (coerce/to-date due))
|
||||
(boolean? automatically_paid_when_due) (assoc :invoice/automatically-paid-when-due automatically_paid_when_due))]
|
||||
@(d/transact (d/connect uri) (concat [updated-invoice]
|
||||
(map (fn [d] [:db/retract id :invoice/expense-accounts d]) deleted)))
|
||||
(-> (d-invoices/get-by-id id)
|
||||
|
||||
@@ -70,11 +70,21 @@
|
||||
:email (:email secondary_contact)})
|
||||
)})]
|
||||
(is-admin? (:id context)) (conj [:reset (if id id "vendor") :vendor/account-overrides account-overrides])
|
||||
(is-admin? (:id context)) (conj [:reset (if id id "vendor") :vendor/terms-overrides terms-overrides]))
|
||||
(is-admin? (:id context)) (conj [:reset (if id id "vendor") :vendor/terms-overrides terms-overrides])
|
||||
(is-admin? (:id context)) (conj [:reset (if id id "vendor") :vendor/automatically-paid-when-due
|
||||
(doto (mapv
|
||||
(fn [apwd]
|
||||
{:db/id apwd})
|
||||
(:automatically_paid_when_due in))
|
||||
println)]))
|
||||
|
||||
_ (println transaction)
|
||||
transaction-result @(d/transact (d/connect uri) transaction)]
|
||||
|
||||
(-> (d-vendors/get-by-id (or (-> transaction-result :tempids (get "vendor"))
|
||||
id))
|
||||
|
||||
(doto println)
|
||||
(->graphql))))
|
||||
|
||||
(defn merge-vendors [context {:keys [from to]} value]
|
||||
|
||||
Reference in New Issue
Block a user