Supporting new action.

This commit is contained in:
BC
2018-09-20 22:28:24 -07:00
15 changed files with 119 additions and 44 deletions

View File

@@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
resources/Dan_Sig.1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
resources/MioVicino.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

BIN
resources/iguanas.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View 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))))))

View File

@@ -307,11 +307,11 @@
:resolve :mutation/print-checks}
:add_handwritten_check {:type :check_result
:args {:invoice_id {:type 'Int}
:args {:invoice_id {:type 'String}
:amount {:type 'Float}
:date {:type 'String}
:check_number {:type 'Int}
:bank_account_id {:type 'Int}}
:bank_account_id {:type 'String}}
:resolve :mutation/add-handwritten-check}
:edit_user {:type :user
:args {:edit_user {:type :edit_user}}

View File

@@ -6,22 +6,16 @@
[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 +259,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,26 +318,22 @@
:end (+ (:start args 0) (count payments))}]))
(defn add-handwritten-check [context args value]
(let [invoice (invoices/get-by-id (: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 (checks/insert! {:s3-uuid nil
:s3-key nil
:s3-url nil
:check-number (:check_number args)
:date (parse (:date args) iso-date)
:amount (:amount args)
:bank-account-id (:bank_account_id args)
:vendor-id (:vendor-id invoice)
:company-id (:company-id invoice)
:invoices [(:invoice_id 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))
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 [(invoices/get-by-id (:invoice_id args))]})))
:invoices [(d-invoices/get-by-id (:invoice_id args))]})))
(defn void-check [context {id :payment_id} value]

View File

@@ -70,14 +70,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))))

View File

@@ -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)

View File

@@ -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" [])

View File

@@ -43,7 +43,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]]]]

View File

@@ -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)

View File

@@ -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}

View File

@@ -332,7 +332,7 @@
:bank-account-id bank-account-id
:invoice_id (:id invoice)
}
[[:invoices [:id :outstanding-balance [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]]]}]}
[[:invoices [:id :outstanding-balance [:payments [:amount [:payment [:amount :s3_url :check_number ]]]]]]]]}]}
:on-success [::handwrite-checks-succeeded]}})))
(re-frame/reg-event-fx
@@ -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