tons of bug fixes
This commit is contained in:
@@ -33,8 +33,13 @@
|
||||
|
||||
(defmethod entity-change->ledger :invoice
|
||||
[db [type id]]
|
||||
(let [entity (d/pull db ['* {:invoice/vendor '[*] :invoice/payment '[*]}] id)]
|
||||
(when-not (= true (:invoice/exclude-from-ledger entity))
|
||||
(let [entity (d/pull db ['* {:invoice/vendor '[*]
|
||||
:invoice/payment '[*]
|
||||
:invoice/status '[:db/ident]
|
||||
:invoice/import-status '[:db/ident]}] id)]
|
||||
(when-not (or (= true (:invoice/exclude-from-ledger entity))
|
||||
(= :import-status/pending (:db/ident (:invoice/import-status entity)))
|
||||
(= :invoice-status/voided (:db/ident (:invoice/status entity))))
|
||||
(remove-nils
|
||||
{:journal-entry/source "invoice"
|
||||
:journal-entry/client (:db/id (:invoice/client entity))
|
||||
@@ -157,3 +162,5 @@
|
||||
#_(process-one (d/tx-report-queue (d/connect uri) ))
|
||||
|
||||
#_(process-all)
|
||||
|
||||
#_(reset! break true)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
(ns auto-ap.parse.excel
|
||||
(:require [auto-ap.parse.templates :as t]
|
||||
[auto-ap.parse.util :as u]
|
||||
[clojure.string :as str]
|
||||
[dk.ative.docjure.spreadsheet :as d])
|
||||
(:import (org.apache.poi.ss.util CellAddress)))
|
||||
@@ -9,7 +10,7 @@
|
||||
(defn template-applies? [text {:keys [keywords]}]
|
||||
(every? #(re-find % text) keywords))
|
||||
|
||||
(defn extract [wb {:keys [extract vendor]}]
|
||||
(defn extract [wb {:keys [extract vendor parser]}]
|
||||
(if (fn? extract)
|
||||
(extract wb vendor)
|
||||
[(reduce-kv
|
||||
@@ -24,11 +25,15 @@
|
||||
(map (fn [cell]
|
||||
(let [address (.getAddress cell)
|
||||
cell-value (str (d/read-cell (d/select-cell (.toString (CellAddress. (+ offset-row (.getRow address)) (+ offset-column (.getColumn address)) ))
|
||||
(first (d/sheet-seq wb)))))]
|
||||
(if extract-regex
|
||||
(second (re-find extract-regex cell-value))
|
||||
|
||||
cell-value))))
|
||||
(first (d/sheet-seq wb)))))
|
||||
raw-result (if extract-regex
|
||||
(second (re-find extract-regex cell-value))
|
||||
|
||||
cell-value)]
|
||||
(if (get parser k)
|
||||
(u/parse-value (first (get parser k) ) (second (get parser k) ) raw-result)
|
||||
raw-result
|
||||
))))
|
||||
first)))
|
||||
{:vendor-code vendor}
|
||||
extract)]))
|
||||
|
||||
@@ -271,7 +271,7 @@
|
||||
|
||||
;; PACIFIC SEAFOOD
|
||||
{:vendor "Pacific Seafood"
|
||||
:keywords [#"pacseafood"]
|
||||
:keywords [#"(pacseafood|PACIFIC FRESH)"]
|
||||
:extract {:date #"DATE(?:.*\n.*(?=([0-9]+/[0-9]+/[0-9]+)))([0-9]+/[0-9]+/[0-9]+)"
|
||||
:customer-identifier #"DELIVER TO:(?:.*\n)(.*?)(?=\s{2})"
|
||||
:invoice-number #"INVOICE NO\.\n(?:.*?(?= [0-9]+\n)) ([0-9]+)"
|
||||
@@ -439,12 +439,15 @@
|
||||
:total [#"PAY THIS" -1 0]
|
||||
:date [#"INVOICE DATE" 0 1]
|
||||
:invoice-number [#"INVOICE NUMBER" 0 1]}}
|
||||
{:vendor "SWO"
|
||||
{:vendor "Southern Glazers"
|
||||
:keywords [#"Please note that the total invoice amount may"]
|
||||
:extract {:customer-identifier [#"Customer #" 1 0]
|
||||
:total [#"Total Invoice" 0 5]
|
||||
:total [#"Subtotal" 0 16 ]
|
||||
:date [#"Date" 0 0 #"Date: (.*)"]
|
||||
:invoice-number [#"Invoice #" 0 0 #"Invoice #: (.*)"]}}
|
||||
:invoice-number [#"Invoice #" 0 0 #"Invoice #: (.*)"]
|
||||
:account-number [#"Customer #" 0 0 #"Customer #: (.*)"]}
|
||||
:parser { :total [:trim-commas-and-remove-dollars nil]
|
||||
:date [:clj-time "MM/dd/yyyy"]}}
|
||||
{:vendor "Mama Lu's Foods"
|
||||
:keywords [#"Mama Lu's Foods"]
|
||||
:extract (fn [wb vendor]
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
[_ _ value]
|
||||
(str/replace value #"," "")
|
||||
)
|
||||
(defmethod parse-value :trim-commas-and-remove-dollars
|
||||
[_ _ value]
|
||||
(str/replace (str/replace value #"," "") #"\$" ""))
|
||||
|
||||
(defmethod parse-value :trim-commas-and-negate
|
||||
[_ _ value]
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
(let [[session token] (yodlee/get-access-token)]
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str (yodlee/get-provider-accounts-with-accounts)) }))
|
||||
:body (pr-str @yodlee/in-memory-cache) }))
|
||||
(POST "/reauthenticate/:id" {:keys [query-params identity] {:keys [id]} :route-params
|
||||
data :edn-params
|
||||
:as request}
|
||||
@@ -53,6 +53,7 @@
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str (yodlee/reauthenticate (Long/parseLong id) data)) })
|
||||
(catch Exception e
|
||||
(println e)
|
||||
{:status 500
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
(:require #_[auto-ap.background.mail :refer [always-process-sqs]]
|
||||
[auto-ap.handler :refer [app]]
|
||||
[auto-ap.ledger :refer [process-all]]
|
||||
[auto-ap.yodlee.core :refer [load-in-memory-cache]]
|
||||
[nrepl.server :refer [start-server stop-server]]
|
||||
[config.core :refer [env]]
|
||||
[ring.adapter.jetty :refer [run-jetty]])
|
||||
@@ -15,5 +16,6 @@
|
||||
(start-server :port 9000 :bind "0.0.0.0" #_#_:handler (cider-nrepl-handler))
|
||||
(let [port (Integer/parseInt (or (env :port) "3000"))]
|
||||
(future (process-all))
|
||||
(future (load-in-memory-cache))
|
||||
#_(future (always-process-sqs))
|
||||
(run-jetty app {:port port :join? false})))
|
||||
|
||||
@@ -157,20 +157,9 @@
|
||||
:as :json}))))
|
||||
|
||||
|
||||
(defn reauthenticate [pa data]
|
||||
(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 (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:body (json/write-str data)
|
||||
:as :json}))))
|
||||
|
||||
(defn update-yodlee [id]
|
||||
(update-provider-account id)
|
||||
(get-provider-account id))
|
||||
|
||||
(defn get-specific-transactions [account]
|
||||
(let [cob-session (login-cobrand)
|
||||
@@ -255,6 +244,41 @@
|
||||
(update-in provider-accounts [(:providerAccountId a) :accounts] conj a)) provider-accounts)
|
||||
vals)))
|
||||
|
||||
(defonce in-memory-cache (atom []))
|
||||
|
||||
(defn load-in-memory-cache []
|
||||
(future
|
||||
(loop []
|
||||
(try
|
||||
(reset! in-memory-cache (get-provider-accounts-with-accounts))
|
||||
(catch Exception e
|
||||
(println e)))
|
||||
(Thread/sleep (* 60 * 1000 * 5))
|
||||
(recur))))
|
||||
|
||||
(defn refresh-provider-account [id]
|
||||
(swap! in-memory-cache
|
||||
(fn [i]
|
||||
(-> (by :id i)
|
||||
(update id merge (get-provider-account-detail id))
|
||||
vals))))
|
||||
|
||||
(defn update-yodlee [id]
|
||||
(update-provider-account id)
|
||||
(refresh-provider-account id)
|
||||
)
|
||||
|
||||
(defn reauthenticate [pa data]
|
||||
(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 (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:body (json/write-str data)
|
||||
:as :json}))
|
||||
(refresh-provider-account pa)))
|
||||
#_(defn get-users []
|
||||
(let [cob-session (login-cobrand)]
|
||||
(-> "https://developer.api.yodlee.com/ysl/user"
|
||||
|
||||
@@ -224,8 +224,6 @@
|
||||
|
||||
txes (transduce
|
||||
(comp
|
||||
|
||||
|
||||
(mapcat (fn parse-map [[account account-name override-name _ type]]
|
||||
(let [code (some-> account
|
||||
not-empty
|
||||
@@ -277,3 +275,28 @@
|
||||
[{:db/id [:client/code client-code]
|
||||
:client/signature-file (str "https://s3.amazonaws.com/integreat-signature-images/" filename)}]))
|
||||
|
||||
|
||||
(defn fix-transactions-without-locations [client-code location]
|
||||
(->>
|
||||
(d/query {:query {:find ['(pull ?e [*])]
|
||||
:in ['$ '?client-code]
|
||||
:where ['[?e :transaction/accounts ?ta]
|
||||
'[?e :transaction/matched-rule]
|
||||
'[?e :transaction/approval-status :transaction-approval-status/approved]
|
||||
'(not [?ta :transaction-account/location])
|
||||
'[?e :transaction/client ?c]
|
||||
'[?c :client/code ?client-code]
|
||||
]}
|
||||
:args [(d/db (d/connect uri)) client-code]})
|
||||
(mapcat
|
||||
(fn [[{:transaction/keys [accounts]}]]
|
||||
(mapv
|
||||
(fn [a]
|
||||
{:db/id (:db/id a)
|
||||
:transaction-account/location location}
|
||||
)
|
||||
accounts)
|
||||
)
|
||||
)
|
||||
vec))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user