switched from auto pay to scheduled payment

This commit is contained in:
Bryce Covert
2020-09-24 08:06:17 -07:00
parent 4ab492d759
commit c5ed61b2e1
16 changed files with 918 additions and 39 deletions

View File

@@ -15,12 +15,11 @@
(let [invoices-to-close (d/query {:query {:find ['?e]
:in ['$ '?today]
:where ['[?e :invoice/automatically-paid-when-due true]
:where ['[?e :invoice/scheduled-payment ?d]
'[?e :invoice/status :invoice-status/unpaid]
'[?e :invoice/due ?d]
'[(<= ?d ?today)]]}
:args [(d/db conn) (coerce/to-date (time/local-now))]})]
(log/info "Closing " (count invoices-to-close) "automatic invoices")
(log/info "Closing " (count invoices-to-close) "scheduled invoices")
(some->> invoices-to-close
seq
@@ -29,7 +28,7 @@
:invoice/status :invoice-status/paid}))
(d/transact conn)
deref)
(log/info "Closed " (count invoices-to-close) "automatic invoices"))
(log/info "Closed " (count invoices-to-close) "scheduled invoices"))
(catch Exception e
(log/error e)))))

View File

@@ -21,6 +21,7 @@
(-> x
(update :invoice/date c/from-date)
(update :invoice/due c/from-date)
(update :invoice/scheduled-payment c/from-date)
(update :invoice/status :db/ident)
(rename-keys {:invoice-payment/_invoice :invoice/payments})))

View File

@@ -311,7 +311,12 @@
:db/doc "Whether this invoice should be marked as paid when it's due"
:db/valueType :db.type/boolean
:db/cardinality :db.cardinality/one}]]}
:auto-ap/fix-reset-rels {:txes-fn `reset-function}}
:auto-ap/fix-reset-rels {:txes-fn `reset-function}
:auto-ap/add-scheduled-payment {:txes [[{:db/ident :invoice/scheduled-payment
:db/doc "When an invoice gets marked as paid"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}]]}}
sales/norms-map
clients/norms-map
ledger/norms-map

View File

@@ -349,7 +349,7 @@
:payments {:type '(list :invoice_payment)}
:vendor {:type :vendor}
:client {:type :client}
:automatically_paid_when_due {:type 'Boolean}}}
:scheduled_payment {:type :iso_date}}}
@@ -718,7 +718,7 @@
:invoice_number {:type 'String}
:expense_accounts {:type '(list :edit_expense_account)}
:location {:type :iso_date}
:automatically_paid_when_due {:type 'Boolean}
:scheduled_payment {:type :iso_date}
:date {:type :iso_date}
:due {:type :iso_date}
:client_id {:type :id}
@@ -731,7 +731,7 @@
:invoice_number {:type 'String}
:expense_accounts {:type '(list :edit_expense_account)}
:date {:type :iso_date}
:automatically_paid_when_due {:type 'Boolean}
:scheduled_payment {:type :iso_date}
:due {:type :iso_date}
:total {:type 'Float}}}
:edit_transaction

View File

@@ -56,7 +56,7 @@
:account account_id
:location location}))
(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}]
(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)
_ (when-not (:db/id account)
@@ -76,7 +76,8 @@
(: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))
(boolean? automatically_paid_when_due) (assoc :invoice/automatically-paid-when-due automatically_paid_when_due))))
scheduled_payment (assoc :invoice/scheduled-payment (coerce/to-date scheduled_payment)))))
(defn deleted-expense-accounts [invoice expense-accounts]
@@ -121,7 +122,7 @@
->graphql)))
(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]
(defn edit-invoice [context {{:keys [id due invoice_number total vendor_id date client_id expense_accounts scheduled_payment] :as in} :invoice} value]
(let [invoice (d-invoices/get-by-id id)
_ (when (seq (d-invoices/find-conflicting {:db/id id
:invoice/invoice-number invoice_number
@@ -146,7 +147,7 @@
:invoice/expense-accounts (map expense-account->entity
expense_accounts)}
due (assoc :invoice/due (coerce/to-date due))
(boolean? automatically_paid_when_due) (assoc :invoice/automatically-paid-when-due automatically_paid_when_due))]
scheduled_payment (assoc :invoice/scheduled-payment (coerce/to-date scheduled_payment)))]
(audit-transact (concat [updated-invoice]
(map (fn [d] [:db/retract id :invoice/expense-accounts d]) deleted))
(:id context))

View File

@@ -161,7 +161,9 @@
:location default-location
:amount total}]}
(:vendor/terms vendor) (assoc :invoice/due (coerce/to-date
(time/plus date (time/days (d-vendors/terms-for-client-id vendor client-id))))))
(time/plus date (time/days (d-vendors/terms-for-client-id vendor client-id)))))
automatically-paid-when-due (assoc :invoice/scheduled-payment (coerce/to-date
(time/plus date (time/days (d-vendors/terms-for-client-id vendor client-id))))))
payment (if (= :invoice-status/paid (:invoice/status invoice))
#:invoice-payment {:invoice (:db/id invoice)
:amount (:invoice/total invoice)
@@ -272,7 +274,6 @@
:invoice/client-identifier customer-identifier
:invoice/vendor (:db/id matching-vendor)
:invoice/invoice-number invoice-number
:invoice/automatically-paid-when-due (boolean (automatically-paid-for (:db/id matching-client)))
:invoice/total (Double/parseDouble total)
:invoice/date (to-date date)
:invoice/import-status :import-status/pending
@@ -284,7 +285,9 @@
:db/id existing-id
})
(:vendor/terms matching-vendor) (assoc :invoice/due (coerce/to-date
(time/plus date (time/days (d-vendors/terms-for-client-id matching-vendor (:db/id matching-client)))))))))
(time/plus date (time/days (d-vendors/terms-for-client-id matching-vendor (:db/id matching-client))))))
(boolean (automatically-paid-for (:db/id matching-client))) (assoc :invoice/scheduled-payment (coerce/to-date
(time/plus date (time/days (d-vendors/terms-for-client-id matching-vendor (:db/id matching-client)))))))))
))
[]
imports)]