now invoices are by vendor and company
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
-- 1523368332 DOWN link-invoices-to-vendor
|
||||||
|
delete from invoices;
|
||||||
|
|
||||||
|
alter table invoices drop column vendor_id;
|
||||||
|
alter table invoices add column vendor varchar(255);
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
-- 1523368332 UP link-invoices-to-vendor
|
||||||
|
delete from invoices;
|
||||||
|
|
||||||
|
alter table invoices drop column vendor;
|
||||||
|
alter table invoices add column vendor_id integer;
|
||||||
|
alter table invoices add constraint fk_invoices__vendor_id foreign key (vendor_id) references vendors(id);
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
(:require [amazonica.aws.s3 :as s3]
|
(:require [amazonica.aws.s3 :as s3]
|
||||||
[amazonica.aws.sqs :as sqs]
|
[amazonica.aws.sqs :as sqs]
|
||||||
[auto-ap.db.companies :as companies]
|
[auto-ap.db.companies :as companies]
|
||||||
|
[auto-ap.db.vendors :as vendors]
|
||||||
[auto-ap.db.invoices :as invoices]
|
[auto-ap.db.invoices :as invoices]
|
||||||
[auto-ap.parse :as parse]
|
[auto-ap.parse :as parse]
|
||||||
[clojure-mail.message :as message]
|
[clojure-mail.message :as message]
|
||||||
@@ -16,7 +17,8 @@
|
|||||||
(defn process-sqs []
|
(defn process-sqs []
|
||||||
(try
|
(try
|
||||||
(println "Fetching messages from sqs...")
|
(println "Fetching messages from sqs...")
|
||||||
(let [companies (companies/get-all)]
|
(let [companies (companies/get-all)
|
||||||
|
vendors (vendors/get-all)]
|
||||||
(doseq [message (:messages (sqs/receive-message {:queue-url (:invoice-import-queue-url env)
|
(doseq [message (:messages (sqs/receive-message {:queue-url (:invoice-import-queue-url env)
|
||||||
:wait-time-seconds 5
|
:wait-time-seconds 5
|
||||||
:max-number-of-messages 10
|
:max-number-of-messages 10
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
(:require [auto-ap.db.utils :refer [clj->db db->clj get-conn]]
|
(:require [auto-ap.db.utils :refer [clj->db db->clj get-conn]]
|
||||||
[auto-ap.parse :as parse]
|
[auto-ap.parse :as parse]
|
||||||
[auto-ap.entities.companies :as company]
|
[auto-ap.entities.companies :as company]
|
||||||
|
[auto-ap.entities.vendors :as vendor]
|
||||||
[clojure.java.jdbc :as j]))
|
[clojure.java.jdbc :as j]))
|
||||||
|
|
||||||
(defn insert-multi! [rows]
|
(defn insert-multi! [rows]
|
||||||
@@ -29,12 +30,16 @@
|
|||||||
(map db->clj (j/query (get-conn) ["SELECT * FROM invoices WHERE (imported=false or imported is null) AND company_id = ?" (Integer/parseInt company)]))
|
(map db->clj (j/query (get-conn) ["SELECT * FROM invoices WHERE (imported=false or imported is null) AND company_id = ?" (Integer/parseInt company)]))
|
||||||
(map db->clj (j/query (get-conn) "SELECT * FROM invoices WHERE imported=false or imported is null"))))
|
(map db->clj (j/query (get-conn) "SELECT * FROM invoices WHERE imported=false or imported is null"))))
|
||||||
|
|
||||||
(defn import [parsed-invoices companies]
|
(defn import [parsed-invoices companies vendors]
|
||||||
(insert-multi!
|
(insert-multi!
|
||||||
(for [{:keys [total date invoice-number customer-identifier vendor] :as row} parsed-invoices]
|
(for [{:keys [total date invoice-number customer-identifier vendor-code] :as row} parsed-invoices]
|
||||||
(do
|
(do
|
||||||
|
(println "VENDORS" vendors)
|
||||||
|
(println "VENDOR" (::vendor-id (first (filter #(= (::vendor/code %) vendor-code) vendors))))
|
||||||
|
|
||||||
(assoc row
|
(dissoc (assoc row
|
||||||
:company-id (::company/id (parse/best-match companies customer-identifier))
|
:company-id (::company/id (parse/best-match companies customer-identifier))
|
||||||
:imported false
|
:vendor-id (::vendor/id (first (filter #(= (::vendor/code %) vendor-code) vendors)))
|
||||||
:potential-duplicate false)))))
|
:imported false
|
||||||
|
:potential-duplicate false)
|
||||||
|
:vendor-code)))))
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
(fn [result k v]
|
(fn [result k v]
|
||||||
(assoc result k (some-> (first (map second (re-seq v text)))
|
(assoc result k (some-> (first (map second (re-seq v text)))
|
||||||
str/trim )))
|
str/trim )))
|
||||||
{:vendor (:vendor template)}))]))
|
{:vendor-code (:vendor template)}))]))
|
||||||
|
|
||||||
(defn parse [text]
|
(defn parse [text]
|
||||||
(->> t/pdf-templates
|
(->> t/pdf-templates
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
cell-value))))
|
cell-value))))
|
||||||
first)))
|
first)))
|
||||||
{:vendor vendor}
|
{:vendor-code vendor}
|
||||||
extract))
|
extract))
|
||||||
|
|
||||||
(defn parse-file
|
(defn parse-file
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
:total [#"PAY THIS" -1 0]
|
:total [#"PAY THIS" -1 0]
|
||||||
:date [#"INVOICE DATE" 0 1]
|
:date [#"INVOICE DATE" 0 1]
|
||||||
:invoice-number [#"INVOICE NUMBER" 0 1]}}
|
:invoice-number [#"INVOICE NUMBER" 0 1]}}
|
||||||
{:vendor "Southern Wine Online"
|
{:vendor "SWO"
|
||||||
:keywords [#"Please note that the total invoice amount may"]
|
:keywords [#"Please note that the total invoice amount may"]
|
||||||
:extract {:customer-identifier [#"Customer #" 1 0]
|
:extract {:customer-identifier [#"Customer #" 1 0]
|
||||||
:total [#"Total Invoice" 0 5]
|
:total [#"Total Invoice" 0 5]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
(ns auto-ap.routes.invoices
|
(ns auto-ap.routes.invoices
|
||||||
(:require [auto-ap.db.companies :as companies]
|
(:require [auto-ap.db.companies :as companies]
|
||||||
|
[auto-ap.db.vendors :as vendors]
|
||||||
[auto-ap.db.invoices :as invoices]
|
[auto-ap.db.invoices :as invoices]
|
||||||
[auto-ap.parse :as parse]
|
[auto-ap.parse :as parse]
|
||||||
[auto-ap.routes.utils :refer [wrap-secure]]
|
[auto-ap.routes.utils :refer [wrap-secure]]
|
||||||
@@ -41,8 +42,9 @@
|
|||||||
(POST "/upload"
|
(POST "/upload"
|
||||||
{{ files "file"} :params :as params}
|
{{ files "file"} :params :as params}
|
||||||
(let [{:keys [filename tempfile]} files
|
(let [{:keys [filename tempfile]} files
|
||||||
companies (companies/get-all)]
|
companies (companies/get-all)
|
||||||
(invoices/import (parse/parse-file (.getPath tempfile) filename) companies)
|
vendors (vendors/get-all)]
|
||||||
|
(invoices/import (parse/parse-file (.getPath tempfile) filename) companies vendors)
|
||||||
{:status 200
|
{:status 200
|
||||||
:body (pr-str (invoices/get-pending ((:query-params params ) "company")))
|
:body (pr-str (invoices/get-pending ((:query-params params ) "company")))
|
||||||
:headers {"Content-Type" "application/edn"}}))
|
:headers {"Content-Type" "application/edn"}}))
|
||||||
|
|||||||
@@ -57,10 +57,10 @@
|
|||||||
[:th "Date"]
|
[:th "Date"]
|
||||||
[:th "Amount"]
|
[:th "Amount"]
|
||||||
[:th]]]
|
[:th]]]
|
||||||
[:tbody (for [{:keys [vendor potential-duplicate company-id customer-identifier invoice-number date total id] :as i} @invoices]
|
[:tbody (for [{:keys [vendor-id potential-duplicate company-id customer-identifier invoice-number date total id] :as i} @invoices]
|
||||||
^{:key (str company-id "-" invoice-number "-" date "-" total "-" id)}
|
^{:key (str company-id "-" invoice-number "-" date "-" total "-" id)}
|
||||||
[:tr
|
[:tr
|
||||||
[:td vendor]
|
[:td vendor-id]
|
||||||
(if company-id
|
(if company-id
|
||||||
[:td company-id]
|
[:td company-id]
|
||||||
[:td [:i.icon.fa.fa-warning {:title "potential duplicate"}]
|
[:td [:i.icon.fa.fa-warning {:title "potential duplicate"}]
|
||||||
|
|||||||
@@ -23,10 +23,10 @@
|
|||||||
[:th "Invoice #"]
|
[:th "Invoice #"]
|
||||||
[:th "Date"]
|
[:th "Date"]
|
||||||
[:th "Amount"]]]
|
[:th "Amount"]]]
|
||||||
[:tbody (for [{:keys [company invoice-number date total id vendor] :as i} @invoices]
|
[:tbody (for [{:keys [company invoice-number date total id vendor-id] :as i} @invoices]
|
||||||
^{:key (str company "-" invoice-number "-" date "-" total "-" id)}
|
^{:key (str company "-" invoice-number "-" date "-" total "-" id)}
|
||||||
[:tr
|
[:tr
|
||||||
[:td vendor]
|
[:td vendor-id]
|
||||||
[:td company]
|
[:td company]
|
||||||
[:td invoice-number]
|
[:td invoice-number]
|
||||||
[:td date]
|
[:td date]
|
||||||
|
|||||||
Reference in New Issue
Block a user