Merge branch 'master' into side-panel
This commit is contained in:
@@ -22,8 +22,9 @@
|
||||
|
||||
(def default-read '(pull ?e [*
|
||||
{:invoice-payment/_payment [* {:invoice-payment/invoice [*]}]}
|
||||
{:payment/client [:client/name :db/id]}
|
||||
{:payment/vendor [:vendor/name :db/id]}
|
||||
{:payment/client [:client/name :db/id :client/code]}
|
||||
{:payment/bank-account [*]}
|
||||
{:payment/vendor [:vendor/name :vendor/default-expense-account :db/id {:vendor/primary-contact [*]} {:vendor/address [*]}]}
|
||||
{:payment/status [:db/ident]}
|
||||
{:payment/type [:db/ident]}]))
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
(ns auto-ap.datomic.invoices
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[auto-ap.datomic :refer [uri remove-nils]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[auto-ap.parse :as parse]
|
||||
[clj-time.coerce :as c]
|
||||
[clojure.set :refer [rename-keys]]
|
||||
[clojure.string :as str]))
|
||||
@@ -15,8 +16,8 @@
|
||||
(reduce #(update-in %1 [:query :where] conj %2) query rest)))
|
||||
|
||||
(def default-read '(pull ?e [*
|
||||
{:invoice/client [:client/name :db/id :client/locations]}
|
||||
{:invoice/vendor [:vendor/name :db/id]}
|
||||
{:invoice/client [:client/name :db/id :client/locations :client/code]}
|
||||
{:invoice/vendor [* {:vendor/address [*]}]}
|
||||
{:invoice/status [:db/ident]}
|
||||
{:invoice-payment/_invoice [* {:invoice-payment/payment [* {:payment/status [*]}
|
||||
{:payment/bank-account [*]}
|
||||
@@ -49,6 +50,8 @@
|
||||
(:original-id args) (add-arg '?original-id (cond-> (:original-id args) (string? (:original-id args)) Long/parseLong )
|
||||
'[?e :invoice/client ?c]
|
||||
'[?c :client/original-id ?original-id])
|
||||
(:import-status args) (add-arg '?import-status (keyword "import-status" (:import-status args))
|
||||
'[?e :invoice/import-status ?import-status])
|
||||
(:status args) (add-arg '?status (keyword "invoice-status" (:status args))
|
||||
'[?e :invoice/status ?status])
|
||||
(:vendor-id args) (add-arg '?vendor-id (:vendor-id args)
|
||||
@@ -127,3 +130,5 @@
|
||||
(map first)
|
||||
|
||||
(<-datomic)))
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic.migrate.add-client-codes :refer [add-client-codes]]
|
||||
[auto-ap.datomic.migrate.add-bank-account-codes :refer [add-bank-account-codes]]
|
||||
[auto-ap.datomic.migrate.invoice-converter :refer [add-import-status-existing-invoices]]
|
||||
[clojure.java.io :as io]
|
||||
[io.rkn.conformity :as c])
|
||||
(:import [datomic Util])
|
||||
@@ -53,6 +54,14 @@
|
||||
:auto-ap/add-client-codes {:txes-fn 'auto-ap.datomic.migrate.add-client-codes/add-client-codes :requires [:auto-ap/migrate-transactions]}
|
||||
:auto-ap/add-bank-account-codes-schema {:txes-fn 'auto-ap.datomic.migrate.add-bank-account-codes/add-bank-account-codes-schema :requires [:auto-ap/add-client-codes]}
|
||||
:auto-ap/add-bank-account-codes {:txes-fn 'auto-ap.datomic.migrate.add-bank-account-codes/add-bank-account-codes :requires [:auto-ap/add-bank-account-codes-schema]}
|
||||
:auto-ap/add-nick-the-greek {:txes [[{:client/name "Nick the Greek" :client/code "NGAK" :client/locations ["MH"] :client/bank-accounts [{:bank-account/code "NGAK-0" :bank-account/type :bank-account-type/cash :bank-account/name "Cash"}]}]] :requires [:auto-ap/add-bank-account-codes]}
|
||||
:auto-ap/rename-codes-1 {:txes-fn 'auto-ap.datomic.migrate.rename-codes/rename-codes-1 :requires [:auto-ap/add-nick-the-greek]}
|
||||
:auto-ap/invoice-converter {:txes auto-ap.datomic.migrate.invoice-converter/add-matches :requires [:auto-ap/rename-codes-1]}
|
||||
:auto-ap/starter {:txes auto-ap.datomic.migrate.invoice-converter/add-starter :requires [:auto-ap/invoice-converter]}
|
||||
:auto-ap/add-default-location {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-default-location :requires [:auto-ap/invoice-converter]}
|
||||
:auto-ap/add-default-location-2 {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-default-location-2 :requires [:auto-ap/add-default-location]}
|
||||
:auto-ap/add-import-status {:txes auto-ap.datomic.migrate.invoice-converter/add-import-status :requires [:auto-ap/add-default-location-2]}
|
||||
:auto-ap/add-import-status-existing-invoices {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-import-status-existing-invoices :requires [:auto-ap/add-import-status]}
|
||||
}]
|
||||
(println "Conforming database...")
|
||||
(println (c/ensure-conforms conn norms-map))
|
||||
|
||||
58
src/clj/auto_ap/datomic/migrate/invoice_converter.clj
Normal file
58
src/clj/auto_ap/datomic/migrate/invoice_converter.clj
Normal file
@@ -0,0 +1,58 @@
|
||||
(ns auto-ap.datomic.migrate.invoice-converter
|
||||
(:require [datomic.api :as d]))
|
||||
|
||||
(def add-matches
|
||||
[[{:db/ident :client/matches
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/many
|
||||
:db/doc "The strings that match the client"}
|
||||
{:db/ident :client/location-matches
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/many
|
||||
:db/isComponent true
|
||||
:db/doc "The mapping from string to location"}
|
||||
|
||||
{:db/ident :location-match/matches
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/many
|
||||
:db/doc "The strings that match the location"}
|
||||
|
||||
{:db/ident :location-match/location
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "The location of the location match"}
|
||||
]])
|
||||
|
||||
(def add-starter
|
||||
[[{:db/id [:client/code "CBC"]
|
||||
:client/matches ["campbell brewing company"]
|
||||
:client/location-matches [{:location-match/location "CB"
|
||||
:location-match/matches ["campbell brewing company"]}]}]])
|
||||
|
||||
(defn add-default-location [conn]
|
||||
[[{:db/ident :client/default-location
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "The default location if one can't be found"}]])
|
||||
|
||||
(defn add-default-location-2 [conn]
|
||||
[[{:db/id [:client/code "CBC"]
|
||||
:client/default-location "CB"}]])
|
||||
|
||||
(def add-import-status
|
||||
[[{:db/ident :invoice/import-status
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "The status of importing the transaction"}
|
||||
|
||||
{:db/ident :import-status/pending}
|
||||
{:db/ident :import-status/imported}]])
|
||||
|
||||
(defn add-import-status-existing-invoices [conn]
|
||||
(let [existing-invoices (->> (d/query {:query {:find ['?e]
|
||||
:in ['$]
|
||||
:where ['[?e :invoice/invoice-number]]}
|
||||
:args [(d/db conn)]}))]
|
||||
[(map (fn [i] {:db/id (first i)
|
||||
:invoice/import-status :import-status/imported})
|
||||
existing-invoices)]))
|
||||
41
src/clj/auto_ap/datomic/migrate/rename_codes.clj
Normal file
41
src/clj/auto_ap/datomic/migrate/rename_codes.clj
Normal file
@@ -0,0 +1,41 @@
|
||||
(ns auto-ap.datomic.migrate.rename-codes
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[clojure.string :as str]))
|
||||
|
||||
(defn rename [old-code new-code conn ]
|
||||
(let [results (->> (d/query {:query {:find ['?e '?b '?bc]
|
||||
:in ['$ '?old-code]
|
||||
:where ['[?e :client/code ?old-code]
|
||||
'[?e :client/bank-accounts ?b]
|
||||
'[?b :bank-account/code ?bc]]}
|
||||
:args [(d/db conn) old-code]})
|
||||
(group-by first))
|
||||
|
||||
#_#_[[id]] results]
|
||||
(for [[id change] results
|
||||
[_ ba-id ba-code] change]
|
||||
[{:db/id id
|
||||
:client/code new-code}
|
||||
{:db/id ba-id
|
||||
:bank-account/code (str/replace ba-code #"^.*-" (str new-code "-"))}])
|
||||
|
||||
#_[{:db/id id
|
||||
:client/code new-code
|
||||
#_#_:client/bank-accounts (map)}]
|
||||
)
|
||||
)
|
||||
|
||||
(defn rename-codes-1 [conn]
|
||||
(let [result (apply concat [(rename "WE" "WME" (d/connect uri))
|
||||
(rename "HM" "HIM" (d/connect uri))
|
||||
(rename "BES" "SBE" (d/connect uri))
|
||||
(rename "BES" "SBE" (d/connect uri))
|
||||
(rename "ORA" "OMG" (d/connect uri))
|
||||
(rename "INT" "IGC" (d/connect uri))
|
||||
(rename "MV" "MVSC" (d/connect uri))])]
|
||||
(if (seq (seq result))
|
||||
result
|
||||
[[]]))
|
||||
)
|
||||
|
||||
@@ -112,8 +112,8 @@
|
||||
true (apply-pagination args))))
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
(->> (d/pull-many db '[* {:transaction/client [:client/name :db/id]
|
||||
:transaction/bank-account [:bank-account/name :bank-account/yodlee-account-id]}]
|
||||
(->> (d/pull-many db '[* {:transaction/client [:client/name :db/id :client/code]
|
||||
:transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id]}]
|
||||
ids)
|
||||
(map #(update % :transaction/date c/from-date))
|
||||
(map #(update % :transaction/post-date c/from-date))
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
:check_number {:type 'Int}
|
||||
:name {:type 'String}
|
||||
:bank_code {:type 'String}
|
||||
:routing {:type 'String}
|
||||
:bank_name {:type 'String}
|
||||
:yodlee_account_id {:type 'Int}}}
|
||||
:address
|
||||
@@ -106,6 +107,7 @@
|
||||
|
||||
:payment {:fields {:id {:type :id}
|
||||
:type {:type :payment_type}
|
||||
:original_id {:type 'Int}
|
||||
:amount {:type 'String}
|
||||
:vendor {:type :vendor}
|
||||
:client {:type :client}
|
||||
@@ -161,6 +163,7 @@
|
||||
|
||||
:invoice
|
||||
{:fields {:id {:type :id}
|
||||
:original_id {:type 'Int}
|
||||
:total {:type 'String}
|
||||
:outstanding_balance {:type 'String}
|
||||
:invoice_number {:type 'String}
|
||||
@@ -203,7 +206,7 @@
|
||||
|
||||
:queries
|
||||
{:invoice_page {:type '(list :invoice_page)
|
||||
:args {:imported {:type 'Boolean}
|
||||
:args {:import_status {:type 'String}
|
||||
:status {:type 'String}
|
||||
:client_id {:type :id}
|
||||
:vendor_id {:type :id}
|
||||
@@ -335,12 +338,20 @@
|
||||
:bank_account_type {:values [{:enum-value :check}
|
||||
{:enum-value :cash}]}}
|
||||
:mutations
|
||||
{:print_checks {:type :check_result
|
||||
:args {:invoice_payments {:type '(list :invoice_payment_amount)}
|
||||
:bank_account_id {:type :id}
|
||||
:type {:type :payment_type}
|
||||
:client_id {:type :id}}
|
||||
:resolve :mutation/print-checks}
|
||||
{:reject_invoices {:type '(list :id)
|
||||
:args {:invoices {:type '(list :id)}}
|
||||
:resolve :mutation/reject-invoices}
|
||||
|
||||
:approve_invoices {:type '(list :id)
|
||||
:args {:invoices {:type '(list :id)}}
|
||||
:resolve :mutation/approve-invoices}
|
||||
|
||||
:print_checks {:type :check_result
|
||||
:args {:invoice_payments {:type '(list :invoice_payment_amount)}
|
||||
:bank_account_id {:type :id}
|
||||
:type {:type :payment_type}
|
||||
:client_id {:type :id}}
|
||||
:resolve :mutation/print-checks}
|
||||
|
||||
:add_handwritten_check {:type :check_result
|
||||
:args {:invoice_id {:type :id}
|
||||
@@ -424,7 +435,7 @@
|
||||
(map
|
||||
->graphql
|
||||
(d-checks/get-graphql (assoc (<-graphql args)
|
||||
:limit Integer/MAX_VALUE))))
|
||||
:count Integer/MAX_VALUE))))
|
||||
|
||||
|
||||
|
||||
@@ -465,6 +476,8 @@
|
||||
:get-user get-user
|
||||
:mutation/add-handwritten-check gq-checks/add-handwritten-check
|
||||
:mutation/print-checks print-checks
|
||||
:mutation/reject-invoices gq-invoices/reject-invoices
|
||||
:mutation/approve-invoices gq-invoices/approve-invoices
|
||||
:mutation/edit-user gq-users/edit-user
|
||||
:mutation/add-invoice gq-invoices/add-invoice
|
||||
:mutation/edit-invoice gq-invoices/edit-invoice
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
[[:cell {:size 9 :leading 11.5} "\n\n\n\n\nMEMO"]
|
||||
[:cell {:colspan 5 :leading 11.5} (split-memo memo)
|
||||
[:line {:line-width 0.15 :color [50 50 50]}]]
|
||||
[:cell {:colspan 6 } (if (:signature-file client)
|
||||
[:cell {:colspan 6 } (if (:client/signature-file client)
|
||||
[:image { :top-margin 90 :xscale 0.30 :yscale 0.30 :align :center}
|
||||
|
||||
(:client/signature-file client)]
|
||||
|
||||
@@ -27,7 +27,20 @@
|
||||
(map
|
||||
->graphql
|
||||
(d-invoices/get-graphql (assoc (<-graphql args)
|
||||
:limit Integer/MAX_VALUE))))
|
||||
:count Integer/MAX_VALUE))))
|
||||
|
||||
(defn reject-invoices [context {:keys [invoices] :as in} value]
|
||||
(assert-admin (:id context))
|
||||
|
||||
(let [transactions (map (fn [i] [:db/retractEntity i ]) invoices)
|
||||
transaction-result @(d/transact (d/connect uri) transactions)]
|
||||
invoices))
|
||||
|
||||
(defn approve-invoices [context {:keys [invoices] :as in} value]
|
||||
(assert-admin (:id context))
|
||||
(let [transactions (map (fn [i] {:db/id i :invoice/import-status :import-status/imported}) invoices)
|
||||
transaction-result @(d/transact (d/connect uri) transactions)]
|
||||
invoices))
|
||||
|
||||
(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
|
||||
@@ -44,6 +57,7 @@
|
||||
:invoice/invoice-number invoice_number
|
||||
:invoice/client client_id
|
||||
:invoice/vendor vendor_id
|
||||
:invoice/import-status :import-status/imported
|
||||
:invoice/total total
|
||||
:invoice/outstanding-balance total
|
||||
:invoice/status :invoice-status/unpaid
|
||||
@@ -82,12 +96,15 @@
|
||||
|
||||
(defn void-invoice [context {id :invoice_id} value]
|
||||
(let [invoice (d-invoices/get-by-id id)
|
||||
_ (println invoice)
|
||||
_ (assert-can-see-client (:id context) (:db/id (:invoice/client invoice)))
|
||||
updated-invoice (d-invoices/update {:db/id id
|
||||
:invoice/total 0.0
|
||||
:invoice/outstanding-balance 0.0
|
||||
:invoice/status :invoice-status/voided})]
|
||||
;; TODO void out all expense accounts
|
||||
:invoice/status :invoice-status/voided
|
||||
:invoice/expense-accounts (map (fn [ea] {:db/id (:db/id ea)
|
||||
:invoice-expense-account/amount 0.0})
|
||||
(:invoice/expense-accounts invoice))})]
|
||||
|
||||
(-> updated-invoice
|
||||
(->graphql))))
|
||||
|
||||
@@ -11,6 +11,12 @@
|
||||
(defmulti parse-value (fn [method _ _]
|
||||
method))
|
||||
|
||||
|
||||
(defmethod parse-value :trim-commas
|
||||
[_ _ value]
|
||||
(str/replace value #"," "")
|
||||
)
|
||||
|
||||
(defmethod parse-value :clj-time
|
||||
[_ format value]
|
||||
(time/from-time-zone (f/parse (f/formatter format) value)
|
||||
@@ -30,17 +36,20 @@
|
||||
#(extract-template % (dissoc template :multi))
|
||||
(str/split text (:multi template)))
|
||||
|
||||
[(->> template
|
||||
:extract
|
||||
(reduce-kv
|
||||
(fn [result k v]
|
||||
(let [value (some-> (first (map second (re-seq v text)))
|
||||
str/trim )
|
||||
[value-parser parser-params] (-> template :parser k)]
|
||||
(assoc result k (parse-value value-parser parser-params value))))
|
||||
{:vendor-code (:vendor template)}))]))
|
||||
(when template
|
||||
[(->> template
|
||||
:extract
|
||||
(reduce-kv
|
||||
(fn [result k v]
|
||||
(let [value (some-> (first (map second (re-seq v text)))
|
||||
str/trim )
|
||||
[value-parser parser-params] (-> template :parser k)]
|
||||
(assoc result k (parse-value value-parser parser-params value))))
|
||||
{:vendor-code (:vendor template)
|
||||
:text text}))])))
|
||||
|
||||
(defn parse [text]
|
||||
(println text)
|
||||
(->> t/pdf-templates
|
||||
(filter (partial template-applies? text))
|
||||
first
|
||||
@@ -67,13 +76,24 @@
|
||||
[file filename]
|
||||
(excel/parse-file file filename))
|
||||
|
||||
(defn best-match [clients client-identifier]
|
||||
(defn best-match [clients invoice-client-name]
|
||||
(->> clients
|
||||
(map (fn [client]
|
||||
(if-let [matches (:client/matches client)]
|
||||
[client (apply min (map #(m/jaccard (.toLowerCase client-identifier) %) matches))]
|
||||
[client 1])))
|
||||
|
||||
(mapcat (fn [{:keys [:db/id :client/matches :client/name] :as client :or {matches []}}]
|
||||
(map (fn [m]
|
||||
[client (m/jaccard (.toLowerCase invoice-client-name) (.toLowerCase m))])
|
||||
(conj matches name))))
|
||||
(filter #(< (second %) 0.25))
|
||||
(sort-by second)
|
||||
|
||||
ffirst))
|
||||
|
||||
(defn best-location-match [client text]
|
||||
(or (->> client
|
||||
:client/location-matches
|
||||
(mapcat (fn [{:keys [:location-match/location :location-match/matches]}]
|
||||
(map (fn [match] [location match]) matches)))
|
||||
(filter (fn [[location match]] (re-find (re-pattern (str "(?i)" match)) text)) )
|
||||
first
|
||||
first)
|
||||
(:client/default-location client)
|
||||
(first (:client/locations client))))
|
||||
|
||||
@@ -10,13 +10,14 @@
|
||||
:invoice-number #"\s+[0-9]+/[0-9]+/[0-9]+\s+([0-9]+)"}
|
||||
:parser {:date [:clj-time "MM/dd/yyyy"]}}
|
||||
|
||||
{:vendor "GGM"
|
||||
{:vendor "Golden Gate Meat Company, Inc"
|
||||
:keywords [#"Golden Gate Meat"]
|
||||
:extract {:total #"Invoice Total\:\s+\$([\d.,]+)"
|
||||
:customer-identifier #"Bill To\s*:\s*([\w ]+)\s{2,}"
|
||||
:date #"Printed:\s+([0-9]+/[0-9]+/[0-9]+)"
|
||||
:invoice-number #"Invoice\s+[^\n]+\n[^\n]+\n\s+([0-9]+)"}
|
||||
:parser {:date [:clj-time "MM/dd/yyyy"]}}
|
||||
:parser {:date [:clj-time "MM/dd/yyyy"]
|
||||
:total [:trim-commas nil]}}
|
||||
|
||||
{:vendor "CINTAS"
|
||||
:keywords [#"CINTAS CORPORATION"]
|
||||
@@ -25,7 +26,15 @@
|
||||
:date #"INVOICE DATE\s*\n.*\s+([0-9]+/[0-9]+/[0-9]+)"
|
||||
:total #"INVOICE TOTAL\s+([0-9.]+)"}
|
||||
:parser {:date [:clj-time "MM/dd/yy"]}
|
||||
:multi #"\f\f"}])
|
||||
:multi #"\f\f"}
|
||||
|
||||
{:vendor "Carbonic Service Inc"
|
||||
:keywords [#"CARBONIC SERVICE INC"]
|
||||
:extract {:invoice-number #"Invoice #\s*\n\s*[\w\.]+\s+[\w\./]+(.*)\s*\n"
|
||||
:customer-identifier #"Bill To[^\n]+\n[^\n]*\n([\w ]+)\s{2,}"
|
||||
:date #"Invoice #\s*\n\s*[\w\.]+\s+([\w\./]+)"
|
||||
:total #"Total\s+\$([0-9.]+)"}
|
||||
:parser {:date [:clj-time "MM/dd/yy"]}}])
|
||||
|
||||
(def excel-templates
|
||||
[{:vendor "Isp Productions"
|
||||
|
||||
@@ -9,6 +9,14 @@
|
||||
(def google-client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com")
|
||||
(def google-client-secret "OC-WemHurPXYpuIw5cT-B90g")
|
||||
|
||||
(defn make-api-token []
|
||||
(jwt/sign {:user "API"
|
||||
:exp (time/plus (time/now) (time/days 700))
|
||||
:user/role "admin"
|
||||
:user/name "API"}
|
||||
(:jwt-secret env)
|
||||
{:alg :hs512}))
|
||||
|
||||
(defroutes routes
|
||||
(GET "/oauth" {{:strs [code]} :query-params :keys [scheme] :as r {:strs [host]} :headers}
|
||||
(try
|
||||
@@ -37,14 +45,14 @@
|
||||
;; TODO - these namespaces are not being transmitted/deserialized properly
|
||||
(if (and token user)
|
||||
{:status 301
|
||||
:headers {"Location" (str "/?jwt=" (jwt/sign {:user (:name profile)
|
||||
:exp (time/plus (time/now) (time/days 7))
|
||||
:user/clients (map (fn [c]
|
||||
(dissoc c :client/bank-accounts )
|
||||
)
|
||||
(:user/clients user))
|
||||
:user/role (name (:user/role user))
|
||||
:user/name (:name profile)}
|
||||
:headers {"Location" (str "/?jwt=" (jwt/sign (doto {:user (:name profile)
|
||||
:exp (time/plus (time/now) (time/days 7))
|
||||
:user/clients (map (fn [c]
|
||||
(dissoc c :client/bank-accounts ))
|
||||
(:user/clients user))
|
||||
:user/role (name (:user/role user))
|
||||
:user/name (:name profile)}
|
||||
println)
|
||||
(:jwt-secret env)
|
||||
{:alg :hs512}))}}
|
||||
{:status 401
|
||||
|
||||
@@ -23,12 +23,12 @@
|
||||
(let [query [[:all_invoices
|
||||
{:client-code (query-params "client-code")
|
||||
:original-id (query-params "original")}
|
||||
[:id :total :outstanding-balance :invoice-number :date :status
|
||||
[:payments [:amount [:payment [:check-number :memo [:bank_account [:id :name :number :bank-name :bank-code]]]]]]
|
||||
[:id :total :outstanding-balance :invoice-number :date :status :original-id
|
||||
[:payments [:amount [:payment [:check-number :memo [:bank_account [:id :name :number :bank-name :bank-code :code]]]]]]
|
||||
[:vendor [:name :id [:primary_contact [:name]] [:address [:street1 :city :state :zip]]]]
|
||||
[:expense_accounts [:amount :id :expense_account_id :location
|
||||
[:expense_account [:id :name [:parent [:id :name]]]]]]
|
||||
[:client [:name :id :locations]]]]]
|
||||
[:client [:name :id :code :locations]]]]]
|
||||
invoices (graphql/query identity (venia/graphql-query {:venia/queries (->graphql query)}))]
|
||||
|
||||
(doto (list (:all-invoices (:data invoices))) clojure.pprint/pprint)))
|
||||
@@ -37,11 +37,11 @@
|
||||
(let [query [[:all_payments
|
||||
{:client-code (query-params "client-code")
|
||||
:original-id (query-params "original")}
|
||||
[:id :check-number :amount :memo :date :status :type
|
||||
[:invoices [[:invoice [:id]] :amount]]
|
||||
[:bank-account [:number :bank-name :bank-code :id]]
|
||||
[:id :check-number :amount :memo :date :status :type :original-id
|
||||
[:invoices [[:invoice [:id :original-id]] :amount]]
|
||||
[:bank-account [:number :code :bank-name :bank-code :id]]
|
||||
[:vendor [:name :id [:primary-contact [:name :email :phone]] :default-expense-account [:address [:street1 :city :state :zip]]]]
|
||||
[:client [:id :name]]
|
||||
[:client [:id :name :code]]
|
||||
]]]
|
||||
payments (graphql/query identity (venia/graphql-query {:venia/queries (->graphql query)}))]
|
||||
(list (:all-payments (:data payments)))))
|
||||
@@ -57,7 +57,7 @@
|
||||
(assert-admin identity)
|
||||
(let [[transactions] (d-transactions/get-graphql {:client-code (query-params "client-code")
|
||||
#_#_:original-id (Integer/parseInt (query-params "original"))
|
||||
:limit Integer/MAX_VALUE})
|
||||
:count Integer/MAX_VALUE})
|
||||
]
|
||||
(map (comp ->graphql (fn [i]
|
||||
(-> i
|
||||
|
||||
@@ -114,6 +114,7 @@
|
||||
:vendor vendor-id
|
||||
:client client-id
|
||||
:default-location default-location
|
||||
:import-status :import-status/imported
|
||||
:default-expense-account default-expense-account
|
||||
:total total
|
||||
:outstanding-balance (if (= "Cash" check)
|
||||
@@ -140,7 +141,59 @@
|
||||
)]
|
||||
[invoice payment])))
|
||||
(filter identity)
|
||||
(map remove-nils)))
|
||||
(map remove-nils)
|
||||
))
|
||||
|
||||
|
||||
(defn import-uploaded-invoice [imports]
|
||||
(let [clients (d-clients/get-all)
|
||||
_ (println imports)
|
||||
|
||||
transactions (reduce (fn [result {:keys [invoice-number customer-identifier total date vendor-code text] :as info}]
|
||||
(let [[matching-vendor default-expense-account] (->> (d/query
|
||||
(cond-> {:query {:find ['?vendor '?default-expense-account]
|
||||
:in ['$ '?vendor-name]
|
||||
:where ['[?vendor :vendor/name ?vendor-name]
|
||||
'[?vendor :vendor/default-expense-account ?default-expense-account]]}
|
||||
:args [(d/db (d/connect uri)) vendor-code]}))
|
||||
first)
|
||||
matching-client (parse/best-match clients customer-identifier)
|
||||
_ (println "New invoice matches client" matching-client)
|
||||
matching-location (parse/best-location-match matching-client text )
|
||||
[existing-id existing-outstanding-balance existing-status import-status] (->> (d/query
|
||||
(cond-> {:query {:find ['?e '?outstanding-balance '?status '?import-status2]
|
||||
:in ['$ '?invoice-number '?vendor '?client]
|
||||
:where '[[?e :invoice/invoice-number ?invoice-number]
|
||||
[?e :invoice/vendor ?vendor]
|
||||
[?e :invoice/client ?client]
|
||||
[?e :invoice/outstanding-balance ?outstanding-balance]
|
||||
[?e :invoice/status ?status]
|
||||
[?e :invoice/import-status ?import-status]
|
||||
[?import-status :db/ident ?import-status2]]}
|
||||
:args [(d/db (d/connect uri)) invoice-number matching-vendor (:db/id matching-client)]}))
|
||||
first)]
|
||||
|
||||
(if (= :import-status/imported import-status)
|
||||
result
|
||||
(conj result (remove-nils #:invoice {:invoice/client (:db/id matching-client)
|
||||
:invoice/vendor matching-vendor
|
||||
:invoice/invoice-number invoice-number
|
||||
:invoice/total (Double/parseDouble total)
|
||||
:invoice/date (to-date date)
|
||||
:invoice/import-status :import-status/pending
|
||||
:invoice/outstanding-balance (or existing-outstanding-balance (Double/parseDouble total))
|
||||
:invoice/status (or existing-status :invoice-status/unpaid)
|
||||
:invoice/expense-accounts (when-not existing-id [#:invoice-expense-account {:expense-account-id default-expense-account
|
||||
:location matching-location
|
||||
:amount (Double/parseDouble total)}])
|
||||
:db/id existing-id
|
||||
})))
|
||||
))
|
||||
[]
|
||||
imports)]
|
||||
|
||||
@(d/transact (d/connect uri) transactions)
|
||||
))
|
||||
|
||||
(defroutes routes
|
||||
(wrap-routes
|
||||
@@ -183,6 +236,13 @@
|
||||
:headers {"Content-Type" "application/edn"}})))
|
||||
|
||||
(context "/invoices" []
|
||||
(POST "/upload"
|
||||
{{ files "file"} :params :as params}
|
||||
(let [{:keys [filename tempfile]} files]
|
||||
(import-uploaded-invoice (parse/parse-file (.getPath tempfile) filename))
|
||||
{:status 200
|
||||
:body (pr-str {})
|
||||
:headers {"Content-Type" "application/edn"}}))
|
||||
(POST "/upload-integreat"
|
||||
{{:keys [excel-rows]} :edn-params user :identity}
|
||||
(assert-admin user)
|
||||
|
||||
@@ -68,23 +68,23 @@
|
||||
(try
|
||||
(when client-id
|
||||
@(->> [(remove-nils #:transaction
|
||||
{:post-date (time/parse post-date "YYYY-MM-dd")
|
||||
:id (sha-256 (str id))
|
||||
:account-id account-id
|
||||
:date (coerce/to-date (time/parse date "YYYY-MM-dd"))
|
||||
:amount amount
|
||||
:description-original description-original
|
||||
:description-simple description-simple
|
||||
:type type
|
||||
:status status
|
||||
:client client-id
|
||||
:check-number check-number
|
||||
:bank-account (transaction->bank-account-id transaction)
|
||||
:payment (when check-id
|
||||
{:db/id check-id
|
||||
:payment/status :payment-status/cleared}
|
||||
)
|
||||
})]
|
||||
{:post-date (coerce/to-date (time/parse post-date "YYYY-MM-dd"))
|
||||
:id (sha-256 (str id))
|
||||
:account-id account-id
|
||||
:date (coerce/to-date (time/parse date "YYYY-MM-dd"))
|
||||
:amount (double amount)
|
||||
:description-original description-original
|
||||
:description-simple description-simple
|
||||
:type type
|
||||
:status status
|
||||
:client client-id
|
||||
:check-number check-number
|
||||
:bank-account (transaction->bank-account-id transaction)
|
||||
:payment (when check-id
|
||||
{:db/id check-id
|
||||
:payment/status :payment-status/cleared}
|
||||
)
|
||||
})]
|
||||
|
||||
|
||||
(d/transact (d/connect uri))))
|
||||
@@ -115,8 +115,8 @@
|
||||
|
||||
(defn do-import []
|
||||
(let [transactions (client/get-transactions)
|
||||
_ (println "All accounts:" (client/get-accounts))
|
||||
_ (println "ALL Transactions:" transactions)
|
||||
#_#__ (println "All accounts:" (client/get-accounts))
|
||||
#_#__ (println "ALL Transactions:" transactions)
|
||||
all-bank-accounts (mapcat (fn [c] (map
|
||||
(fn [{:keys [:db/id :bank-account/yodlee-account-id]}]
|
||||
(when (and id yodlee-account-id)
|
||||
|
||||
Reference in New Issue
Block a user