invoice fixes.

This commit is contained in:
2022-01-18 16:15:14 -08:00
parent d4bd4e45fb
commit cd5b1cbb8a
4 changed files with 10 additions and 18 deletions

View File

@@ -16,6 +16,7 @@
[datomic.api :as d] [datomic.api :as d]
[mount.core :as mount] [mount.core :as mount]
[unilog.context :as lc] [unilog.context :as lc]
#_{:clj-kondo/ignore [:unused-namespace]}
[yang.scheduler :as scheduler]) [yang.scheduler :as scheduler])
(:import (:import
(java.util UUID))) (java.util UUID)))
@@ -126,7 +127,7 @@
(let [transaction (->> keys (let [transaction (->> keys
(mapcat (fn [k] (mapcat (fn [k]
(try (try
(let [invoice-key (str "invoice-files/" (UUID/randomUUID) ".csv") (let [invoice-key (str "invoice-files/" (UUID/randomUUID) ".csv") ;
invoice-url (str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/" invoice-key)] invoice-url (str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/" invoice-key)]
(s3/copy-object {:source-bucket-name (:data-bucket env) (s3/copy-object {:source-bucket-name (:data-bucket env)
:destination-bucket-name (:data-bucket env) :destination-bucket-name (:data-bucket env)

View File

@@ -263,7 +263,7 @@
(time/plus (time/days (d-vendors/terms-for-client-id vendor client-id))) (time/plus (time/days (d-vendors/terms-for-client-id vendor client-id)))
coerce/to-date)) coerce/to-date))
automatically-paid? (boolean (seq (d/q '[:find [?c ...] automatically-paid? (boolean (seq (d/q '[:find [?c ...]
:in $ ?v :in $ ?v ?c
:where [?v :vendor/automatically-paid-when-due ?c]] :where [?v :vendor/automatically-paid-when-due ?c]]
db db
vendor-id vendor-id

View File

@@ -40,7 +40,6 @@
{:vendor "Carbonic Service Inc" {:vendor "Carbonic Service Inc"
:keywords [#"CARBONIC SERVICE INC"] :keywords [#"CARBONIC SERVICE INC"]
:extract {:invoice-number #"Invoice #\s*\n\s*[\w\.]+\s+[\w\./]+(.*)\s*\n" :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\./]+)" :date #"Invoice #\s*\n\s*[\w\.]+\s+([\w\./]+)"
:total #"Total\s+\$([0-9.,]+)" :total #"Total\s+\$([0-9.,]+)"
:account-number #"Account #\s+(\d+)"} :account-number #"Account #\s+(\d+)"}
@@ -105,7 +104,6 @@
{:vendor "Southern Glazers" {:vendor "Southern Glazers"
:keywords [#"Southern Glazer's"] :keywords [#"Southern Glazer's"]
:extract {:date #"INVOICE DATE(?s:.*)(?= (?:[0-9]+/[0-9]+/[0-9]+)\s+([0-9]+/[0-9]+/[0-9]+)) " :extract {:date #"INVOICE DATE(?s:.*)(?= (?:[0-9]+/[0-9]+/[0-9]+)\s+([0-9]+/[0-9]+/[0-9]+)) "
:customer-identifier #"SOLD TO:(?:.*)(?=\n)\n(.*)(?=\s{2,})" ;; ([\S ]+)\s{2,}
:invoice-number #"INVOICE\n(?:.*?)(?=\d{4,})(\d+)" :invoice-number #"INVOICE\n(?:.*?)(?=\d{4,})(\d+)"
:total #"PAY THIS AMOUNT(?s:.*)(?= ([0-9,]+\.[0-9]{2}))" :total #"PAY THIS AMOUNT(?s:.*)(?= ([0-9,]+\.[0-9]{2}))"
:account-number #"ACCOUNT #.*\n.*\n\s+(\d+)"} :account-number #"ACCOUNT #.*\n.*\n\s+(\d+)"}
@@ -118,7 +116,6 @@
{:vendor "Golden Brands San Jose" {:vendor "Golden Brands San Jose"
:keywords [#"GOLDEN BRANDS"] :keywords [#"GOLDEN BRANDS"]
:extract {:date #"(?:.*\n){4}(.*)" ;; HOW TO GO TO SPCIFIC LINE :extract {:date #"(?:.*\n){4}(.*)" ;; HOW TO GO TO SPCIFIC LINE
:customer-identifier #"Account:(?:.*\n)(.*(?=\s{2,}))"
:account-number #"Account:\s*(.*?)\n" :account-number #"Account:\s*(.*?)\n"
:invoice-number #"Invoice#: (\d+)" :invoice-number #"Invoice#: (\d+)"
:total #"Invoice Total\s+([0-9,]+\.[0-9]{2})"} :total #"Invoice Total\s+([0-9,]+\.[0-9]{2})"}
@@ -161,7 +158,6 @@
{:vendor "Worldwide Produce" {:vendor "Worldwide Produce"
:keywords [#"WORLDWIDE PRODUCE"] :keywords [#"WORLDWIDE PRODUCE"]
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)" :extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"Bill to.*\n\s*(.*?(?=(\s{2,}|\()))"
:invoice-number #"(?:Invoice|Adjustment) No\.\s+(\d+)" :invoice-number #"(?:Invoice|Adjustment) No\.\s+(\d+)"
:total #"Total \S*\s+([0-9\.,\-]+)" :total #"Total \S*\s+([0-9\.,\-]+)"
:account-number #"Customer No.\s+(.*?)\s{2}"} :account-number #"Customer No.\s+(.*?)\s{2}"}
@@ -175,7 +171,6 @@
{:vendor "Auto-Chlor" {:vendor "Auto-Chlor"
:keywords [#"AUTO-CHLOR"] :keywords [#"AUTO-CHLOR"]
:extract {:date #"DATE : ([0-9]+/[0-9]+/[0-9]+)" :extract {:date #"DATE : ([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"(.*?)\s{2,}.*CUSTOMER#"
:invoice-number #"INVOICE# :\s+([0-9]+)" :invoice-number #"INVOICE# :\s+([0-9]+)"
:total #"TOTAL DUE :\s+\$([0-9,.]+)" :total #"TOTAL DUE :\s+\$([0-9,.]+)"
:account-number #"CUSTOMER#\s+:\s+(\d+)"} :account-number #"CUSTOMER#\s+:\s+(\d+)"}
@@ -229,7 +224,6 @@
{:vendor "General Produce Company" {:vendor "General Produce Company"
:keywords [#"1330 NORTH B"] :keywords [#"1330 NORTH B"]
:extract {:date #"DATE.*\n.*\n.*?([0-9]+/[0-9]+/[0-9]+)" :extract {:date #"DATE.*\n.*\n.*?([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"SPECIAL INSTRUCTIONS.*\n\s+(.*?)\s{2,}"
:invoice-number #"CREDIT NO.*\n.*\n.*?(\d{5,}?)\s+" :invoice-number #"CREDIT NO.*\n.*\n.*?(\d{5,}?)\s+"
:account-number #"CUST NO.*\n.*\n\s+(\d+)" :account-number #"CUST NO.*\n.*\n\s+(\d+)"
:total #"TOTAL:\s+\|\s*(.*)"} :total #"TOTAL:\s+\|\s*(.*)"}
@@ -262,7 +256,6 @@
{:vendor "Wine Warehouse" {:vendor "Wine Warehouse"
:keywords [#"WINE WAREHOUSE" #"Bottle prices include"] :keywords [#"WINE WAREHOUSE" #"Bottle prices include"]
:extract {:date #"INVOICE DATE\s+([0-9]+/[0-9]+/[0-9]+)" :extract {:date #"INVOICE DATE\s+([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"SHIP-TO-PARTY.*\n(.*?)(?=\s{2,})"
:invoice-number #"INV #\s+(\d+)" :invoice-number #"INV #\s+(\d+)"
:total #"PLEASE PAY THIS AMOUNT\s+([0-9,]+\.[0-9]{2})" :total #"PLEASE PAY THIS AMOUNT\s+([0-9,]+\.[0-9]{2})"
:account-number #"CUSTOMER NUMBER\s+(\d+)"} :account-number #"CUSTOMER NUMBER\s+(\d+)"}

View File

@@ -126,21 +126,19 @@
(defn import->invoice [{:keys [invoice-number source-url customer-identifier account-number total date vendor-code text full-text client-override vendor-override location-override]} clients] (defn import->invoice [{:keys [invoice-number source-url customer-identifier account-number total date vendor-code text full-text client-override vendor-override location-override]} clients]
(let [matching-client (or (and account-number (let [matching-client (cond
(parse/best-match clients account-number 0.0)) account-number (parse/best-match clients account-number 0.0)
(and customer-identifier customer-identifier (parse/best-match clients customer-identifier)
(parse/best-match clients customer-identifier)) client-override (first (filter (fn [c]
(when client-override (= (:db/id c) (Long/parseLong client-override)))
(first (filter (fn [c] clients)))
(= (:db/id c) (Long/parseLong client-override)))
clients))))
matching-vendor (match-vendor vendor-code vendor-override) matching-vendor (match-vendor vendor-code vendor-override)
matching-location (or (when-not (str/blank? location-override) matching-location (or (when-not (str/blank? location-override)
location-override) location-override)
(parse/best-location-match matching-client text full-text))] (parse/best-location-match matching-client text full-text))]
(remove-nils #:invoice {:invoice/client (:db/id matching-client) (remove-nils #:invoice {:invoice/client (:db/id matching-client)
:invoice/client-identifier customer-identifier :invoice/client-identifier (or account-number customer-identifier)
:invoice/vendor (:db/id matching-vendor) :invoice/vendor (:db/id matching-vendor)
:invoice/source-url source-url :invoice/source-url source-url
:invoice/invoice-number invoice-number :invoice/invoice-number invoice-number