now you can schedule dom.

This commit is contained in:
Bryce Covert
2020-09-24 13:02:37 -07:00
parent 99e09b1181
commit 1b56bc9324
4 changed files with 85 additions and 38 deletions

View File

@@ -1,28 +1,27 @@
(ns auto-ap.routes.invoices
(:require [auto-ap.datomic.clients :as d-clients]
[auto-ap.datomic.vendors :as d-vendors]
[auto-ap.datomic.invoices :as d-invoices]
(:require [auto-ap.datomic :refer [remove-nils uri]]
[auto-ap.datomic.accounts :as d-accounts]
[auto-ap.yodlee.import :refer [manual-import]]
[auto-ap.utils :refer [by]]
[auto-ap.datomic :refer [remove-nils uri]]
[datomic.api :as d]
[auto-ap.datomic.clients :as d-clients]
[auto-ap.datomic.invoices :as d-invoices]
[auto-ap.datomic.vendors :as d-vendors]
[auto-ap.graphql.utils :refer [assert-admin]]
[auto-ap.logging :refer [info-event]]
[auto-ap.parse :as parse]
[auto-ap.parse.util :as parse-u]
[auto-ap.graphql.utils :refer [assert-admin]]
[auto-ap.routes.utils :refer [wrap-secure]]
[clj-time.core :as time]
[auto-ap.time-utils :refer [next-dom]]
[auto-ap.utils :refer [by]]
[auto-ap.yodlee.import :refer [manual-import]]
[clj-time.coerce :as coerce :refer [to-date]]
[ring.middleware.json :refer [wrap-json-response]]
[compojure.core :refer [GET POST context defroutes
wrap-routes]]
[clojure.string :as str]
[clojure.java.io :as io]
[clj-time.core :as time]
[clojure.data.csv :as csv]
[unilog.context :as lc]
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.logging :as log]
[auto-ap.logging :refer [info-event]]))
[compojure.core :refer [context defroutes POST wrap-routes]]
[datomic.api :as d]
[ring.middleware.json :refer [wrap-json-response]]
[unilog.context :as lc]))
(defn reset-id [i]
(update i :invoice-number
@@ -70,6 +69,10 @@
(defn parse-automatically-paid-when-due [{:keys [vendor client-id]}]
(boolean ((set (map :db/id (:vendor/automatically-paid-when-due vendor))) client-id)))
(defn parse-schedule-payment-dom [{:keys [vendor client-id]}]
(get (by (comp :db/id :vendor-schedule-payment-dom/client) :vendor-schedule-payment-dom/dom (:vendor/schedule-payment-dom vendor))
client-id))
(defn parse-amount [i]
(try
(Double/parseDouble (str/replace (or (second
@@ -128,6 +131,7 @@
(map (parse-or-error :vendor #(parse-vendor % all-vendors)))
(map (parse-or-error :vendor-id #(parse-vendor-id %)))
(map (parse-or-error :automatically-paid-when-due #(parse-automatically-paid-when-due %)))
(map (parse-or-error :schedule-payment-dom #(parse-schedule-payment-dom %)))
(map (parse-or-error :account-id parse-account-numeric-code))
(map (parse-or-error :invoice-number parse-invoice-number))
(map (parse-or-error :total parse-amount))
@@ -138,7 +142,7 @@
(defn invoice-rows->transaction [rows]
(->> rows
(mapcat (fn [{:keys [vendor-id total client-id amount date invoice-number default-location account-id check vendor automatically-paid-when-due]}]
(mapcat (fn [{:keys [vendor-id total client-id amount date invoice-number default-location account-id check vendor automatically-paid-when-due schedule-payment-dom]}]
(let [invoice (cond->
#:invoice {:db/id (.toString (java.util.UUID/randomUUID))
:vendor vendor-id
@@ -163,7 +167,10 @@
(:vendor/terms vendor) (assoc :invoice/due (coerce/to-date
(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))))))
(time/plus date (time/days (d-vendors/terms-for-client-id vendor client-id)))))
schedule-payment-dom (assoc :invoice/scheduled-payment (coerce/to-date
(next-dom date schedule-payment-dom)
)))
payment (if (= :invoice-status/paid (:invoice/status invoice))
#:invoice-payment {:invoice (:db/id invoice)
:amount (:invoice/total invoice)
@@ -260,7 +267,9 @@
(.toString e))
{:args [ invoice-number matching-vendor (:db/id matching-client)]})))
))
automatically-paid-for (set (map :db/id (:vendor/automatically-paid-when-due matching-vendor)))]
automatically-paid-for (set (map :db/id (:vendor/automatically-paid-when-due matching-vendor)))
schedule-payment-dom (get (by (comp :db/id :vendor-schedule-payment-dom/client) :vendor-schedule-payment-dom/dom (:vendor/schedule-payment-dom matching-vendor))
(:db/id matching-client))]
(cond
(not (and matching-location matching-client))
@@ -287,7 +296,9 @@
(: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))))))
(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)))))))))
(time/plus date (time/days (d-vendors/terms-for-client-id matching-vendor (:db/id matching-client))))))
schedule-payment-dom (assoc :invoice/scheduled-payment (to-date
(next-dom date schedule-payment-dom))))))
))
[]
imports)]