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]
[mount.core :as mount]
[unilog.context :as lc]
#_{:clj-kondo/ignore [:unused-namespace]}
[yang.scheduler :as scheduler])
(:import
(java.util UUID)))
@@ -126,7 +127,7 @@
(let [transaction (->> keys
(mapcat (fn [k]
(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)]
(s3/copy-object {:source-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)))
coerce/to-date))
automatically-paid? (boolean (seq (d/q '[:find [?c ...]
:in $ ?v
:in $ ?v ?c
:where [?v :vendor/automatically-paid-when-due ?c]]
db
vendor-id

View File

@@ -40,7 +40,6 @@
{: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.,]+)"
:account-number #"Account #\s+(\d+)"}
@@ -105,7 +104,6 @@
{:vendor "Southern Glazers"
:keywords [#"Southern Glazer's"]
: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+)"
:total #"PAY THIS AMOUNT(?s:.*)(?= ([0-9,]+\.[0-9]{2}))"
:account-number #"ACCOUNT #.*\n.*\n\s+(\d+)"}
@@ -118,7 +116,6 @@
{:vendor "Golden Brands San Jose"
:keywords [#"GOLDEN BRANDS"]
:extract {:date #"(?:.*\n){4}(.*)" ;; HOW TO GO TO SPCIFIC LINE
:customer-identifier #"Account:(?:.*\n)(.*(?=\s{2,}))"
:account-number #"Account:\s*(.*?)\n"
:invoice-number #"Invoice#: (\d+)"
:total #"Invoice Total\s+([0-9,]+\.[0-9]{2})"}
@@ -161,7 +158,6 @@
{:vendor "Worldwide Produce"
:keywords [#"WORLDWIDE PRODUCE"]
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"Bill to.*\n\s*(.*?(?=(\s{2,}|\()))"
:invoice-number #"(?:Invoice|Adjustment) No\.\s+(\d+)"
:total #"Total \S*\s+([0-9\.,\-]+)"
:account-number #"Customer No.\s+(.*?)\s{2}"}
@@ -175,7 +171,6 @@
{:vendor "Auto-Chlor"
:keywords [#"AUTO-CHLOR"]
:extract {:date #"DATE : ([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"(.*?)\s{2,}.*CUSTOMER#"
:invoice-number #"INVOICE# :\s+([0-9]+)"
:total #"TOTAL DUE :\s+\$([0-9,.]+)"
:account-number #"CUSTOMER#\s+:\s+(\d+)"}
@@ -229,7 +224,6 @@
{:vendor "General Produce Company"
:keywords [#"1330 NORTH B"]
: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+"
:account-number #"CUST NO.*\n.*\n\s+(\d+)"
:total #"TOTAL:\s+\|\s*(.*)"}
@@ -262,7 +256,6 @@
{:vendor "Wine Warehouse"
:keywords [#"WINE WAREHOUSE" #"Bottle prices include"]
:extract {:date #"INVOICE DATE\s+([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"SHIP-TO-PARTY.*\n(.*?)(?=\s{2,})"
:invoice-number #"INV #\s+(\d+)"
:total #"PLEASE PAY THIS AMOUNT\s+([0-9,]+\.[0-9]{2})"
: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]
(let [matching-client (or (and account-number
(parse/best-match clients account-number 0.0))
(and customer-identifier
(parse/best-match clients customer-identifier))
(when client-override
(first (filter (fn [c]
(= (:db/id c) (Long/parseLong client-override)))
clients))))
(let [matching-client (cond
account-number (parse/best-match clients account-number 0.0)
customer-identifier (parse/best-match clients customer-identifier)
client-override (first (filter (fn [c]
(= (:db/id c) (Long/parseLong client-override)))
clients)))
matching-vendor (match-vendor vendor-code vendor-override)
matching-location (or (when-not (str/blank? location-override)
location-override)
(parse/best-location-match matching-client text full-text))]
(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/source-url source-url
:invoice/invoice-number invoice-number