made invoice import back to working, mostly
This commit is contained in:
@@ -337,12 +337,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}
|
||||
@@ -467,6 +475,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
|
||||
|
||||
@@ -29,6 +29,19 @@
|
||||
(d-invoices/get-graphql (assoc (<-graphql args)
|
||||
: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
|
||||
:invoice/vendor vendor_id
|
||||
|
||||
@@ -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,16 +36,17 @@
|
||||
#(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)
|
||||
:text text}))]))
|
||||
(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)
|
||||
@@ -72,11 +79,10 @@
|
||||
(defn best-match [clients invoice-client-name]
|
||||
(->> clients
|
||||
|
||||
(mapcat (fn [{:keys [:db/id :client/matches] :as client :or {matches []}}]
|
||||
(println matches)
|
||||
(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))])
|
||||
matches)))
|
||||
(conj matches name))))
|
||||
(filter #(< (second %) 0.25))
|
||||
(sort-by second)
|
||||
ffirst))
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -158,20 +158,21 @@
|
||||
: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 )
|
||||
_ (println "LOCATION" matching-location)
|
||||
|
||||
[existing-id existing-outstanding-balance existing-status import-status] (->> (d/query
|
||||
(cond-> {:query {:find ['?e '?outstanding-balance '?status '?import-status]
|
||||
(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]]}
|
||||
[?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)
|
||||
@@ -190,7 +191,7 @@
|
||||
))
|
||||
[]
|
||||
imports)]
|
||||
(println transactions)
|
||||
|
||||
@(d/transact (d/connect uri) transactions)
|
||||
))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user