merged.
This commit is contained in:
@@ -78,7 +78,7 @@
|
||||
:plugins [[lein-figwheel "0.5.13"]
|
||||
[lein-pdo "0.1.1"]
|
||||
[cider/cider-nrepl "0.16.0"]]
|
||||
:jvm-opts ["-Dconfig=config/dev.edn" #_#_"--add-modules" "java.xml.bind"]}
|
||||
:jvm-opts ["-Dconfig=config/dev.edn" "--add-modules" "java.xml.bind"]}
|
||||
:uberjar {:prep-tasks [["cljsbuild" "once" "min"] "compile"]}
|
||||
:provided {:dependencies [[org.clojure/clojurescript "1.10.238"]
|
||||
[reagent "0.7.0"]
|
||||
|
||||
BIN
resources/BellaSaratoga.jpg
Normal file
BIN
resources/BellaSaratoga.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
BIN
resources/Dan_Sig.1.jpg
Normal file
BIN
resources/Dan_Sig.1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
BIN
resources/MioVicino.jpg
Normal file
BIN
resources/MioVicino.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
BIN
resources/iguanas.jpg
Normal file
BIN
resources/iguanas.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
18
scratch-sessions/fix-account-id.sql
Normal file
18
scratch-sessions/fix-account-id.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
|
||||
(defn original-base-id [{:keys [date bank-account-id description-original company-id amount]} index]
|
||||
(str (t/to-time-zone date (t/time-zone-for-offset -7)) "-" description-original "-" (double amount) "-" index "-" company-id))
|
||||
|
||||
(defn new-base-id [{:keys [date bank-account-id description-original company-id amount]} index]
|
||||
(str (t/to-time-zone date (t/time-zone-for-offset -7)) "-" bank-account-id "-" description-original "-" (double amount) "-" index "-" company-id))
|
||||
|
||||
(defn replacements []
|
||||
(loop [rows (get-graphql {:limit 100000})
|
||||
replacements []
|
||||
i 0]
|
||||
(let [result (->> rows
|
||||
(filter #(= (:id %) (sha-256 (original-base-id % i))))
|
||||
(map #(assoc % :new-id (sha-256 (new-base-id % i)))))]
|
||||
(if (= 10 i)
|
||||
(into replacements result)
|
||||
(recur rows (into replacements result ) (inc i))))))
|
||||
@@ -1,9 +1,6 @@
|
||||
(ns auto-ap.background.mail
|
||||
(:require [amazonica.aws.s3 :as s3]
|
||||
[amazonica.aws.sqs :as sqs]
|
||||
[auto-ap.db.companies :as companies]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.db.invoices :as invoices]
|
||||
[auto-ap.parse :as parse]
|
||||
[clojure-mail.message :as message]
|
||||
[clojure.data.json :as json]
|
||||
@@ -14,7 +11,7 @@
|
||||
(javax.mail.internet MimeMessage)))
|
||||
|
||||
|
||||
(defn process-sqs []
|
||||
#_(defn process-sqs []
|
||||
(try
|
||||
(println "Fetching messages from sqs...")
|
||||
(let [companies (companies/get-all)
|
||||
@@ -43,6 +40,6 @@
|
||||
(catch Exception e
|
||||
(println e))))
|
||||
|
||||
(defn always-process-sqs []
|
||||
#_(defn always-process-sqs []
|
||||
(while (not (Thread/interrupted))
|
||||
(process-sqs)))
|
||||
|
||||
@@ -517,10 +517,10 @@
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "name of the user"}
|
||||
{:db/ident :user/companies
|
||||
{:db/ident :user/clients
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/many
|
||||
:db/doc "The companies this user can view"}
|
||||
:db/doc "The clients this user can view"}
|
||||
|
||||
;;enums
|
||||
{:db/ident :user-role/admin}
|
||||
@@ -706,7 +706,7 @@
|
||||
:role (keyword "user-role" role)
|
||||
:provider-id provider-id
|
||||
:provider provider
|
||||
:companies (map (fn [c] [:client/original-id c]) companies)})))
|
||||
:clients (map (fn [c] [:client/original-id c]) companies)})))
|
||||
(d/transact (d/connect uri))))
|
||||
|
||||
(defn query-vendors []
|
||||
|
||||
@@ -11,6 +11,21 @@
|
||||
(update-in [:query :where] conj where))]
|
||||
(reduce #(update-in %1 [:query :where] conj %2) query rest)))
|
||||
|
||||
(defn get-by-id [id]
|
||||
(let [query (-> {:query {:find ['(pull ?e [*
|
||||
{:user/clients [*]}
|
||||
{:user/role [:db/ident]}])]
|
||||
:in ['$]
|
||||
:where []}
|
||||
:args [(d/db (d/connect uri))]}
|
||||
(add-arg '?e (cond-> id (string? id) Long/parseLong) ['?e])
|
||||
(doto println))]
|
||||
|
||||
(->> (d/query query)
|
||||
(map first)
|
||||
(map #(update % :user/role :db/ident))
|
||||
first)))
|
||||
|
||||
(defn raw-graphql [args]
|
||||
(let [query (cond-> {:query {:find ['(pull ?e [*
|
||||
{:user/clients [*]}
|
||||
|
||||
@@ -6,26 +6,18 @@
|
||||
[com.walmartlabs.lacinia.executor :as executor]
|
||||
[com.walmartlabs.lacinia.resolve :as resolve]
|
||||
[buddy.auth :refer [throw-unauthorized]]
|
||||
[auto-ap.db.invoices :as invoices]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[auto-ap.graphql.utils :refer [assert-admin can-see-company? assert-can-see-company]]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.db.companies :as companies]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
[auto-ap.datomic.users :as d-users]
|
||||
[auto-ap.datomic.invoices :as d-invoices]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.db.users :as users]
|
||||
[auto-ap.db.checks :as checks]
|
||||
[auto-ap.graphql.users :as gq-users]
|
||||
[auto-ap.graphql.checks :as gq-checks]
|
||||
[auto-ap.graphql.expense-accounts :as expense-accounts]
|
||||
[auto-ap.graphql.invoices :as gq-invoices]
|
||||
[auto-ap.graphql.transactions :as gq-transactions]
|
||||
[auto-ap.db.reminders :as reminders]
|
||||
[auto-ap.db.invoices-checks :as invoices-checks]
|
||||
[auto-ap.db.utils :as utils]
|
||||
[clojure.walk :as walk]
|
||||
[clojure.string :as str])
|
||||
(:import
|
||||
@@ -131,8 +123,7 @@
|
||||
:status {:type 'String}
|
||||
:client {:type :client}
|
||||
:payment {:type :payment}
|
||||
:bank_account {:type :bank_account
|
||||
:resolve :bank-account-for-check}
|
||||
:bank_account {:type :bank_account}
|
||||
:date {:type 'String}
|
||||
:post_date {:type 'String}}}
|
||||
:invoice_payment
|
||||
@@ -144,10 +135,10 @@
|
||||
:invoice {:type :invoice}}}
|
||||
|
||||
:user
|
||||
{:fields {:id {:type 'Int}
|
||||
{:fields {:id {:type 'String}
|
||||
:name {:type 'String}
|
||||
:role {:type 'String}
|
||||
:clients {:type '(list :company)}}}
|
||||
:clients {:type '(list :client)}}}
|
||||
|
||||
:expense_account {:fields {:id {:type 'Int}
|
||||
:location {:type 'String}
|
||||
@@ -245,12 +236,7 @@
|
||||
:asc {:type 'Boolean}}
|
||||
|
||||
:resolve :get-payment-page}
|
||||
:reminder_page {:type '(list :reminder_page)
|
||||
:args {:start {:type 'Int}
|
||||
:sort_by {:type 'String}
|
||||
:asc {:type 'Boolean}}
|
||||
|
||||
:resolve :get-reminder-page}
|
||||
|
||||
:company {:type '(list :company)
|
||||
:resolve :get-company}
|
||||
:client {:type '(list :company)
|
||||
@@ -266,10 +252,10 @@
|
||||
:amount {:type 'Float}}}
|
||||
|
||||
:edit_user
|
||||
{:fields {:id {:type 'Int}
|
||||
{:fields {:id {:type 'String}
|
||||
:name {:type 'String}
|
||||
:role {:type 'String}
|
||||
:companies {:type '(list Int)}}}
|
||||
:clients {:type '(list String)}}}
|
||||
|
||||
:edit_expense_account
|
||||
{:fields {:id {:type 'String}
|
||||
@@ -399,22 +385,6 @@
|
||||
(d-checks/get-graphql (assoc (<-graphql args)
|
||||
:limit Integer/MAX_VALUE))))
|
||||
|
||||
(defn get-reminder-page [context args value]
|
||||
(assert-admin (:id context))
|
||||
(let [extra-context
|
||||
(cond-> {}
|
||||
(executor/selects-field? context :reminder/vendor) (assoc :vendor-cache (by :id (vendors/get-all))))
|
||||
|
||||
reminders (map
|
||||
->graphql
|
||||
(reminders/get-graphql (<-graphql args)))
|
||||
reminder-count (reminders/count-graphql (<-graphql args))]
|
||||
(resolve/with-context
|
||||
[{:reminders reminders
|
||||
:total reminder-count
|
||||
:count (count reminders)
|
||||
:start (:start args 0)
|
||||
:end (+ (:start args 0) (count reminders))}] extra-context)))
|
||||
|
||||
|
||||
|
||||
@@ -425,18 +395,7 @@
|
||||
|
||||
|
||||
|
||||
(defn bank-account-for-check [context args value]
|
||||
(->graphql
|
||||
(let [company (if-let [company-cache (:company-cache context)]
|
||||
(company-cache (:company_id value))
|
||||
(companies/get-by-id (:company_id value)))]
|
||||
(first (filter #(= (:id %) (:bank_account_id value)) (:bank-accounts company))) )))
|
||||
|
||||
(defn get-user-companies [context args value]
|
||||
(->graphql
|
||||
(if-let [company-cache (:company-cache context)]
|
||||
(map company-cache (:companies value))
|
||||
(map companies/get-by-id (:companies value)))))
|
||||
|
||||
|
||||
|
||||
@@ -445,18 +404,12 @@
|
||||
(filter #(can-see-company? (:id context) %)
|
||||
(d-clients/get-all))))
|
||||
|
||||
(defn join-companies [users]
|
||||
(let [companies (by :id (companies/get-all))]
|
||||
(map
|
||||
(fn [u]
|
||||
(update u :companies #(map companies %)))
|
||||
users)))
|
||||
|
||||
(defn get-user [context args value]
|
||||
(assert-admin (:id context))
|
||||
|
||||
(let [users (d-users/get-graphql args)]
|
||||
(->graphql users)))
|
||||
(doto (let [users (d-users/get-graphql args)]
|
||||
(->graphql users))
|
||||
println))
|
||||
|
||||
(defn get-vendor [context args value]
|
||||
(->graphql
|
||||
@@ -480,13 +433,11 @@
|
||||
(attach-resolvers {:get-invoice-page get-invoice-page
|
||||
:get-all-invoices get-all-invoices
|
||||
:get-all-payments get-all-payments
|
||||
:bank-account-for-check bank-account-for-check
|
||||
:get-payment-page gq-checks/get-payment-page
|
||||
:get-transaction-page gq-transactions/get-transaction-page
|
||||
:get-reminder-page get-reminder-page
|
||||
|
||||
:get-company get-company
|
||||
:get-user get-user
|
||||
:get-user-companies get-user-companies
|
||||
:mutation/add-handwritten-check gq-checks/add-handwritten-check
|
||||
:mutation/print-checks print-checks
|
||||
:mutation/edit-user gq-users/edit-user
|
||||
|
||||
@@ -2,26 +2,18 @@
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-company]]
|
||||
[datomic.api :as d]
|
||||
[clojure.edn :as edn]
|
||||
|
||||
[com.walmartlabs.lacinia :refer [execute]]
|
||||
[com.walmartlabs.lacinia.executor :as executor]
|
||||
[com.walmartlabs.lacinia.resolve :as resolve]
|
||||
[auto-ap.db.invoices-checks :as invoices-checks]
|
||||
[auto-ap.db.checks :as checks]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
[auto-ap.datomic.invoices :as d-invoices]
|
||||
[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.db.invoices-checks :as invoices-checks]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.db.invoices :as invoices]
|
||||
[auto-ap.db.utils :refer [query]]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[auto-ap.numeric :refer [num->words]]
|
||||
[config.core :refer [env]]
|
||||
[auto-ap.db.companies :as companies]
|
||||
[auto-ap.time :refer [parse normal-date iso-date local-now]]
|
||||
[amazonica.aws.s3 :as s3]
|
||||
[clojure.string :as str]
|
||||
@@ -265,6 +257,7 @@
|
||||
(conj [:inc (:db/id bank-account) :bank-account/check-number 1])
|
||||
(into (invoice-payments invoices invoice-amounts)))))
|
||||
|
||||
|
||||
(defmethod invoices->entities :payment-type/debit [invoices vendor client bank-account type index invoice-amounts]
|
||||
(let [payment (assoc (base-payment invoices vendor client bank-account type index invoice-amounts)
|
||||
:payment/type :payment-type/debit
|
||||
@@ -323,31 +316,19 @@
|
||||
:end (+ (:start args 0) (count payments))}]))
|
||||
|
||||
(defn add-handwritten-check [context args value]
|
||||
(println args)
|
||||
|
||||
(let [invoice (d-invoices/get-by-id (Long/parseLong (:invoice_id args)))
|
||||
(let [invoice (d-invoices/get-by-id (:invoice_id args))
|
||||
bank-account-id (Long/parseLong (:bank_account_id args))
|
||||
bank-account (d-bank-accounts/get-by-id bank-account-id)
|
||||
_ (assert-can-see-company (:id context) (:company-id invoice))
|
||||
check {:payment/check-number (:check_number args)
|
||||
:payment/date (c/to-date (parse (:date args) iso-date))
|
||||
:payment/amount (:amount args)
|
||||
:payment/bank-account (Long/parseLong (:bank_account_id args))
|
||||
:payment/vendor (:db/id (:invoice/vendor invoice))
|
||||
:payment/client (:db/id (:invoice/client invoice))
|
||||
:payment/invoices [(Long/parseLong (:invoice_id args))]
|
||||
:db/id "the-check"}
|
||||
payment {:invoice-payment/payment "the-check"
|
||||
:invoice-payment/amount (:amount args)
|
||||
:invoice-payment/invoice (Long/parseLong (:invoice_id args))}
|
||||
invoice [:pay (Long/parseLong (:invoice_id args) ) (:amount args)]]
|
||||
|
||||
#_(invoices-checks/insert-multi! [{:invoice-id (:invoice_id args)
|
||||
:check-id (:id check)
|
||||
:amount (:amount args)}])
|
||||
#_(invoices/apply-payment (:invoice_id args) (:amount args))
|
||||
(println [check payment invoice])
|
||||
@(d/transact (d/connect uri) [check
|
||||
payment
|
||||
invoice])
|
||||
base-payment (base-payment [invoice] (:invoice/vendor invoice)
|
||||
(:invoice/client invoice)
|
||||
bank-account :payment-type/check 0 {(Long/parseLong (:invoice_id args)) (:amount args)})]
|
||||
@(d/transact (d/connect uri)
|
||||
[(assoc base-payment
|
||||
:payment/check-number (:check_number args)
|
||||
:payment/date (c/to-date (parse (:date args) iso-date))
|
||||
:payment/amount (:amount args))
|
||||
[:pay (:db/id invoice) (:amount args)]])
|
||||
(->graphql
|
||||
{:s3-url nil
|
||||
:invoices [(d-invoices/get-by-id (:invoice_id args))]})))
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
(ns auto-ap.graphql.invoices
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql assert-can-see-company]]
|
||||
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.datomic.invoices :as d-invoices]
|
||||
[auto-ap.db.companies :as companies]
|
||||
[auto-ap.db.invoices-expense-accounts :as invoices-expense-accounts]
|
||||
[auto-ap.expense-accounts :as expense-accounts]
|
||||
[auto-ap.time :refer [parse iso-date]]
|
||||
[datomic.api :as d]
|
||||
@@ -13,11 +10,6 @@
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.set :as set]))
|
||||
|
||||
(defn -create-or-get-vendor [vendor-id vendor-name]
|
||||
(if vendor-id
|
||||
(vendors/get-by-id vendor-id)
|
||||
(vendors/insert {:name vendor-name :default-expense-account 0})))
|
||||
|
||||
(defn add-invoice [context {{:keys [total invoice_number location client_id vendor_id vendor_name date] :as in} :invoice} value]
|
||||
(when (seq (d-invoices/find-conflicting {:invoice/invoice-number invoice_number
|
||||
:invoice/vendor (Long/parseLong vendor_id)
|
||||
@@ -70,14 +62,16 @@
|
||||
(->graphql))))
|
||||
|
||||
(defn void-invoice [context {id :invoice_id} value]
|
||||
(let [invoice (d-invoices/get-by-id id)
|
||||
_ (assert-can-see-company (:id context) (:company-id invoice))
|
||||
updated-invoice (d-invoices/update {:db/id (Long/parseLong id)
|
||||
:invoice/total 0.0
|
||||
:invoice/outstanding-balance 0.0
|
||||
:invoice/status :invoice-status/voided})]
|
||||
(-> updated-invoice
|
||||
(->graphql))))
|
||||
(let [invoice (d-invoices/get-by-id id)
|
||||
_ (assert-can-see-company (:id context) (:company-id invoice))
|
||||
updated-invoice (d-invoices/update {:db/id (Long/parseLong id)
|
||||
:invoice/total 0.0
|
||||
:invoice/outstanding-balance 0.0
|
||||
:invoice/status :invoice-status/voided})]
|
||||
;; TODO void out all expense accounts
|
||||
|
||||
(-> updated-invoice
|
||||
(->graphql))))
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,27 +1,12 @@
|
||||
(ns auto-ap.graphql.transactions
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql]]
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
|
||||
[com.walmartlabs.lacinia :refer [execute]]
|
||||
[com.walmartlabs.lacinia.executor :as executor]
|
||||
[com.walmartlabs.lacinia.resolve :as resolve]
|
||||
[auto-ap.db.transactions :as transactions]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.db.checks :as checks]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[auto-ap.db.companies :as companies]
|
||||
[auto-ap.time :refer [parse normal-date]]))
|
||||
|
||||
(defn get-check-for-transaction [context args value]
|
||||
(->graphql
|
||||
(checks/get-by-id (:check_id value))))
|
||||
|
||||
(defn get-company-for-transaction [context args value]
|
||||
(->graphql
|
||||
(if-let [company-cache (:company-cache context)]
|
||||
(company-cache (:company_id value))
|
||||
(companies/get-by-id (:company_id value)))))
|
||||
|
||||
(defn get-transaction-page [context args value]
|
||||
(let [args (assoc args :id (:id context))
|
||||
transactions (map
|
||||
|
||||
@@ -1,10 +1,30 @@
|
||||
(ns auto-ap.graphql.users
|
||||
(:require [auto-ap.db.users :as users]
|
||||
(:require [auto-ap.datomic.users :as d-users]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[auto-ap.graphql.utils :refer [->graphql assert-admin]]))
|
||||
|
||||
(defn edit-user [context args value]
|
||||
(assert-admin (:id context))
|
||||
(users/update! (:edit_user args))
|
||||
(->graphql
|
||||
(users/get-by-id (:id (:edit_user args)))))
|
||||
(def role->datomic-role {":none" :user-role/none
|
||||
":admin" :user-role/admin
|
||||
":user" :user-role/user})
|
||||
|
||||
(defn edit-user [context {:keys [edit_user] :as args} value]
|
||||
(println args edit_user)
|
||||
(assert-admin (:id context))
|
||||
(let [user (d-users/get-by-id (:id edit_user))
|
||||
new-clients (set (map #(Long/parseLong %) (:clients edit_user)))
|
||||
clients-to-remove (->> (:user/clients user)
|
||||
(map :db/id)
|
||||
(filter #(not (new-clients %)) ))]
|
||||
|
||||
|
||||
@(d/transact (d/connect uri)
|
||||
|
||||
(doto (-> [{:db/id (:db/id user)
|
||||
:user/role (role->datomic-role (:role edit_user))
|
||||
:user/clients new-clients}]
|
||||
(into (map (fn [c] [:db/retract (:db/id user) :user/clients c]) clients-to-remove)))
|
||||
clojure.pprint/pprint))
|
||||
(->graphql
|
||||
(d-users/get-by-id (:id edit_user)))))
|
||||
|
||||
|
||||
@@ -47,7 +47,8 @@
|
||||
|
||||
(defn can-see-company? [identity company]
|
||||
(or (= "admin" (:role identity))
|
||||
((set (map :db/id (:user/companies identity))) (:db/id company))))
|
||||
((set (map :db/id (:user/companies identity))) (:db/id company))
|
||||
((set (map :db/id (:user/companies identity))) company)))
|
||||
|
||||
(defn assert-can-see-company [identity company]
|
||||
(when-not (can-see-company? identity company)
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
[auto-ap.routes.events :as events]
|
||||
[auto-ap.routes.checks :as checks]
|
||||
[auto-ap.routes.exports :as exports]
|
||||
[auto-ap.db.utils :as u]
|
||||
[buddy.auth.backends.token :refer [jws-backend]]
|
||||
[buddy.auth.middleware :refer [wrap-authentication
|
||||
wrap-authorization]]
|
||||
@@ -48,13 +47,7 @@
|
||||
|
||||
(defn wrap-transaction [handler]
|
||||
(fn [request]
|
||||
(jdbc/with-db-transaction [t (u/get-conn)]
|
||||
(binding [u/current-conn t]
|
||||
(try
|
||||
(handler (assoc request :db-conn t))
|
||||
(catch Exception e
|
||||
(jdbc/db-set-rollback-only! t)
|
||||
(throw e)))))))
|
||||
(handler request)))
|
||||
|
||||
(def app-routes
|
||||
(routes
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
(:require
|
||||
[hiccup.core :refer [html]]
|
||||
[auto-ap.routes.utils :refer [wrap-secure]]
|
||||
[compojure.core :refer [GET POST context defroutes
|
||||
wrap-routes]]))
|
||||
[compojure.core :refer [GET POST context defroutes wrap-routes]]))
|
||||
(defroutes routes
|
||||
(wrap-routes
|
||||
(context "/checks" [])
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(ns auto-ap.routes.companies
|
||||
(:require [auto-ap.db.companies :as companies]
|
||||
(:require [auto-ap.datomic.clients :as clients]
|
||||
[auto-ap.graphql.utils :refer [can-see-company? assert-can-see-company]]
|
||||
[auto-ap.routes.utils :refer [wrap-secure wrap-spec]]
|
||||
[auto-ap.entities.companies :as entity]
|
||||
@@ -10,11 +10,7 @@
|
||||
(defroutes routes
|
||||
(wrap-routes
|
||||
(context "/companies" []
|
||||
(GET "/" r
|
||||
{:status 200
|
||||
:body (pr-str (filter #(can-see-company? (:identity r) (:id %)) (companies/get-all)))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(wrap-spec
|
||||
#_(wrap-spec
|
||||
(PUT "/:id" {{:keys [address email locations new-bank-accounts]} :edn-params :keys [edn-params] {:keys [id ]} :route-params :as r}
|
||||
(assert-can-see-company (:identity r) id)
|
||||
(let [id (Integer/parseInt id)
|
||||
@@ -22,12 +18,12 @@
|
||||
updated-company (merge company {:address address
|
||||
:email email
|
||||
:locations locations})]
|
||||
(companies/upsert id updated-company)
|
||||
(doseq [bank-account new-bank-accounts]
|
||||
#_(companies/upsert id updated-company)
|
||||
#_(doseq [bank-account new-bank-accounts]
|
||||
(companies/add-bank-account id bank-account))
|
||||
|
||||
{:status 200
|
||||
:body (pr-str (companies/get-by-id id))
|
||||
:body (pr-str (clients/get-by-id id))
|
||||
:headers {"Content-Type" "application/edn"}}))
|
||||
::entity/company))
|
||||
wrap-secure))
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
(ns auto-ap.routes.events
|
||||
(:require
|
||||
[auto-ap.db.reminders :as reminders]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.routes.utils :refer [wrap-secure]]
|
||||
(:require [auto-ap.routes.utils :refer [wrap-secure]]
|
||||
[auto-ap.yodlee.import :as yodlee-import]
|
||||
[config.core :refer [env]]
|
||||
[clj-http.client :as http]
|
||||
|
||||
@@ -1,21 +1,14 @@
|
||||
(ns auto-ap.routes.exports
|
||||
(:require
|
||||
[auto-ap.db.invoices :as invoices]
|
||||
[auto-ap.db.checks :as checks]
|
||||
[auto-ap.db.transactions :as transactions]
|
||||
[auto-ap.db.companies :as companies]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.db.utils :refer [query]]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[auto-ap.parse :as parse]
|
||||
[auto-ap.graphql :as graphql]
|
||||
[auto-ap.graphql.utils :refer [<-graphql ->graphql assert-admin]]
|
||||
[auto-ap.routes.utils :refer [wrap-secure]]
|
||||
[clj-time.coerce :refer [to-date]]
|
||||
[auto-ap.db.invoices-expense-accounts :as expense-accounts]
|
||||
[ring.middleware.json :refer [wrap-json-response]]
|
||||
[compojure.core :refer [GET POST context defroutes wrap-routes]]
|
||||
[clojure.string :as str]
|
||||
@@ -43,7 +36,7 @@
|
||||
(let [query [[:all_payments
|
||||
{:client-id (query-params "client")
|
||||
:original-id (query-params "original")}
|
||||
[:id :check-number :amount :memo :date :status
|
||||
[:id :check-number :amount :memo :date :status :type
|
||||
[:invoices [[:invoice [:id]] :amount]]
|
||||
[:bank-account [:number :bank-name :bank-code :id]]
|
||||
[:vendor [:name :id [:primary-contact [:name :email :phone]] :default-expense-account [:address [:street1 :city :state :zip]]]]
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
(ns auto-ap.routes.graphql
|
||||
(:require [auto-ap.db.companies :as companies]
|
||||
[auto-ap.routes.utils :refer [wrap-secure wrap-spec]]
|
||||
[auto-ap.entities.companies :as entity]
|
||||
(:require [auto-ap.routes.utils :refer [wrap-secure wrap-spec]]
|
||||
[auto-ap.graphql :as ql]
|
||||
[buddy.auth :refer [throw-unauthorized]]
|
||||
[clojure.edn :as edn]
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
(ns auto-ap.routes.reminders
|
||||
(:require
|
||||
[auto-ap.db.reminders :as reminders]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.routes.utils :refer [wrap-secure]]
|
||||
[auto-ap.graphql.utils :refer [assert-admin]]
|
||||
[config.core :refer [env]]
|
||||
@@ -15,14 +13,14 @@
|
||||
wrap-routes]])
|
||||
(:import (org.joda.time DateTime)))
|
||||
|
||||
(defn next-sunday []
|
||||
#_(defn next-sunday []
|
||||
(let [sunday (->> (p/periodic-seq (time/plus (time/today) (time/days 1)) (time/days 1))
|
||||
(filter pred/sunday?)
|
||||
first)]
|
||||
(time/from-time-zone (time/date-time (time/year sunday) (time/month sunday) (time/day sunday))
|
||||
(time/time-zone-for-id "America/Los_Angeles"))))
|
||||
|
||||
(defn schedule-reminders []
|
||||
#_(defn schedule-reminders []
|
||||
(let [vendors (vendors/find-with-reminders)
|
||||
future-reminders (reminders/find-future (map :id vendors))
|
||||
has-reminder-scheduled? (set (map :vendor-id future-reminders))
|
||||
@@ -37,14 +35,14 @@
|
||||
:email primary-email
|
||||
:scheduled (next-sunday))))))
|
||||
|
||||
(defn find-ready-reminders []
|
||||
#_(defn find-ready-reminders []
|
||||
(let [vendors (vendors/get-all)
|
||||
ready-reminders (reminders/get-ready)]
|
||||
ready-reminders))
|
||||
|
||||
|
||||
|
||||
(defn replace-joda [x]
|
||||
#_(defn replace-joda [x]
|
||||
(into {} (map (fn [[k v]]
|
||||
[k (if (instance? DateTime v)
|
||||
(c/to-date v)
|
||||
@@ -54,7 +52,7 @@
|
||||
(defroutes routes
|
||||
(context "/reminders" []
|
||||
|
||||
(POST "/send" {:keys [query-params headers body] :as x}
|
||||
#_(POST "/send" {:keys [query-params headers body] :as x}
|
||||
(let [notification-type (get headers "x-amz-sns-message-type")]
|
||||
(println "Received notification " notification-type)
|
||||
(if (= "SubscriptionConfirmation" notification-type)
|
||||
@@ -72,7 +70,7 @@
|
||||
{:status 200
|
||||
:body "{}"
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(wrap-routes
|
||||
#_(wrap-routes
|
||||
(PUT "/:id" {:keys [ edn-params] {:keys [id] } :route-params identity :identity}
|
||||
(assert-admin identity)
|
||||
(let [id (if (int? id)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(ns auto-ap.routes.vendors
|
||||
(:require [auto-ap.db.vendors :as vendors]
|
||||
(:require [auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.entities.vendors :as entity]
|
||||
[auto-ap.graphql.utils :refer [assert-admin]]
|
||||
[auto-ap.routes.utils :refer [wrap-secure wrap-spec]]
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
[auto-ap.graphql.utils :refer [->graphql assert-admin]]
|
||||
[auto-ap.routes.utils :refer [wrap-secure]]
|
||||
[clj-time.coerce :refer [to-date]]
|
||||
[auto-ap.db.invoices-expense-accounts :as expense-accounts]
|
||||
[ring.middleware.json :refer [wrap-json-response]]
|
||||
[compojure.core :refer [GET POST context defroutes wrap-routes]]
|
||||
[clojure.string :as str]
|
||||
|
||||
@@ -47,12 +47,24 @@
|
||||
:body
|
||||
:account)))
|
||||
|
||||
(defn get-account [i]
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)]
|
||||
(-> (str (:yodlee-base-url env) (str "/accounts/" i))
|
||||
(client/get {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json})
|
||||
:body
|
||||
:account)))
|
||||
|
||||
(defn get-provider-accounts []
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)]
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts")
|
||||
(client/get {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json}))))
|
||||
(-> (client/get {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json})
|
||||
:body
|
||||
:providerAccount)
|
||||
)))
|
||||
|
||||
(defn get-transactions []
|
||||
(let [cob-session (login-cobrand)
|
||||
@@ -77,6 +89,58 @@
|
||||
(recur (concat transactions transaction-batch) (+ batch-size skip))
|
||||
transactions)))))
|
||||
|
||||
(defn get-provider-accounts []
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
batch-size 100
|
||||
get-transaction-batch (fn []
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts")
|
||||
|
||||
(client/get {:headers (doto
|
||||
(merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
println)
|
||||
:as :json})
|
||||
:body
|
||||
))]
|
||||
|
||||
(get-transaction-batch)))
|
||||
|
||||
(defn update-provider-account [pa]
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
batch-size 100]
|
||||
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts?providerAccountIds=" pa)
|
||||
|
||||
(client/put {:headers (doto
|
||||
(merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
println)
|
||||
:body "{\"dataSetName\": [\"BASIC_AGG_DATA\"]}"
|
||||
:as :json}))))
|
||||
|
||||
(defn get-specific-transactions []
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
batch-size 100
|
||||
get-transaction-batch (fn [skip]
|
||||
(-> (str (:yodlee-base-url env) "/transactions?top=" batch-size "&skip=" skip "&accountId=16422358")
|
||||
(doto println)
|
||||
|
||||
(client/get {:headers (doto
|
||||
(merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
println)
|
||||
:as :json})
|
||||
:body
|
||||
:transaction
|
||||
))]
|
||||
|
||||
(loop [transactions []
|
||||
skip 0]
|
||||
(let [transaction-batch (get-transaction-batch skip)]
|
||||
(if (seq transaction-batch)
|
||||
(recur (concat transactions transaction-batch) (+ batch-size skip))
|
||||
transactions)))))
|
||||
|
||||
(defn get-access-token []
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
|
||||
@@ -100,7 +100,7 @@
|
||||
(mapcat (fn [transaction-group]
|
||||
(map
|
||||
(fn [index {:keys [date description-original high-level-category amount account-id] :as transaction}]
|
||||
{:id (str date "-" description-original "-" amount "-" index "-" company-id)
|
||||
{:id (str date "-" account-id "-" description-original "-" amount "-" index "-" company-id)
|
||||
:bank-account-id account-id
|
||||
:date (time/unparse date "YYYY-MM-dd")
|
||||
:amount {:amount amount}
|
||||
|
||||
@@ -58,13 +58,13 @@
|
||||
::add-company
|
||||
(fn [db [_ d]]
|
||||
(let [company (get @(re-frame/subscribe [::subs/companies-by-id])
|
||||
(js/parseInt (get-in db [::editing :adding-company])))]
|
||||
(update-in db [::editing :user :companies] conj company))))
|
||||
(get-in db [::editing :adding-company]))]
|
||||
(update-in db [::editing :user :clients] conj company))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::remove-company
|
||||
(fn [db [_ d]]
|
||||
(update-in db [::editing :user :companies] #(filter (fn [c] (not= (:id c) d)) %))))
|
||||
(update-in db [::editing :user :clients] #(filter (fn [c] (not= (:id c) d)) %))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::save
|
||||
@@ -78,7 +78,7 @@
|
||||
:operation/name "EditUser"}
|
||||
|
||||
:venia/queries [{:query/data [:edit-user
|
||||
{:edit-user (update (get-in db [::editing :user]) :companies #(map :id %))}
|
||||
{:edit-user (update (get-in db [::editing :user]) :clients #(map :id %))}
|
||||
[:id :name :role [:clients [:id :name]]]]}]}
|
||||
:on-success [::saved]}}))
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
[:tr
|
||||
[:th "User"]
|
||||
[:th "Role"]
|
||||
[:th "Companies"]]]
|
||||
[:th "Clients"]]]
|
||||
[:tbody (for [{:keys [id name role clients] :as c} @users]
|
||||
^{:key (str name "-" id )}
|
||||
[:tr {:on-click (fn [] (re-frame/dispatch [::edit id]))
|
||||
@@ -145,12 +145,12 @@
|
||||
:spec ::entity/name
|
||||
:event ::change
|
||||
:subscription editing}
|
||||
[:option {:value "none"} "None"]
|
||||
[:option {:value "user"} "User"]
|
||||
[:option {:value "admin"} "Admin"]]]]]]
|
||||
[:option {:value ":none"} "None"]
|
||||
[:option {:value ":user"} "User"]
|
||||
[:option {:value ":admin"} "Admin"]]]]]]
|
||||
|
||||
|
||||
(when (= "user" (:role (:user editing)))
|
||||
(when (= ":user" (:role (:user editing)))
|
||||
[horizontal-field
|
||||
[:label.label "Clients"]
|
||||
[:div.control
|
||||
|
||||
@@ -491,7 +491,7 @@
|
||||
[:tr
|
||||
[:td.expandable [:div.control
|
||||
[bind-field
|
||||
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) chooseable-expense-accounts)
|
||||
[typeahead {:matches (map (fn [x] [(:id x) (str (:id x) " - " (:name x))]) chooseable-expense-accounts)
|
||||
:type "typeahead"
|
||||
:field [:invoice :expense-accounts index :expense-account-id]
|
||||
:event change-event
|
||||
|
||||
Reference in New Issue
Block a user