tracking companies by id

This commit is contained in:
Bryce Covert
2018-04-06 07:08:17 -07:00
parent 0baf1e0e65
commit 68964e2e2c
7 changed files with 31 additions and 18 deletions

View File

@@ -0,0 +1,6 @@
-- 1523022636 DOWN change_company_to_id
delete from invoices;
alter table invoices drop column company_id;
alter table invoices add column company varchar(255);

View File

@@ -0,0 +1,6 @@
-- 1523022636 UP change_company_to_id
delete from invoices;
alter table invoices drop column company;
alter table invoices add column company_id integer;
alter table invoices add constraint fk_invoices__company_id foreign key (company_id) references companies(id);

View File

@@ -19,10 +19,10 @@
(defn get-unpaid [company]
(if company
(map db->clj (j/query (get-conn) ["SELECT * FROM invoices WHERE imported=true AND company = ?" company]))
(map db->clj (j/query (get-conn) ["SELECT * FROM invoices WHERE imported=true AND company_id = ?" (Integer/parseInt company)]))
(map db->clj (j/query (get-conn) "SELECT * FROM invoices WHERE imported=true"))))
(defn get-pending [company]
(if company
(map db->clj (j/query (get-conn) ["SELECT * FROM invoices WHERE (imported=false or imported is null) AND company = ?" 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"))))

View File

@@ -160,7 +160,7 @@
(for [{:keys [total date invoice-number customer-identifier vendor] :as row}
(parse/parse-file (.getPath tempfile) filename)]
(assoc row
:company (:name (parse/best-match companies customer-identifier))
:company-id (:id (parse/best-match companies customer-identifier))
:imported false
:potential-duplicate (boolean (seq (filter #(and (= vendor (:vendor %))

View File

@@ -1,6 +1,7 @@
(ns auto-ap.events
(:require [re-frame.core :as re-frame]
[auto-ap.db :as db]
[auto-ap.subs :as subs]
[auto-ap.routes :as routes]
[auto-ap.effects :as effects]
[bidi.bidi :as bidi]))
@@ -48,7 +49,7 @@
(re-frame/reg-event-db
::swap-company
(fn [db [_ company]]
(assoc db :company company)))
(assoc db :company (:id company))))
(re-frame/reg-event-fx
::set-active-page
@@ -69,8 +70,8 @@
{:http {:method :post
:token (-> cofx :db :user)
:uri (str "/api/invoices/approve"
(when-let [company-name (-> cofx :db :company :name)]
(str "?company=" company-name)))
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
(str "?company=" company-id)))
:on-success [::received-invoices :pending]
}}))
@@ -81,8 +82,8 @@
:http {:method :get
:token (-> cofx :db :user)
:uri (str "/api/invoices/pending"
(when-let [company-name (-> cofx :db :company :name)]
(str "?company=" company-name)))
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
(str "?company=" company-id)))
:on-success [::received-invoices :pending]}}))
(re-frame/reg-event-fx
@@ -92,8 +93,8 @@
:http {:method :get
:token (-> cofx :db :user)
:uri (str "/api/invoices/unpaid"
(when-let [company-name (-> cofx :db :company :name)]
(str "?company=" company-name)))
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
(str "?company=" company-id)))
:on-success [::received-invoices :unpaid]}}))
(re-frame/reg-event-fx
@@ -102,8 +103,8 @@
{:http {:method :post
:token (-> cofx :db :user)
:uri (str "/api/invoices/reject"
(when-let [company-name (-> cofx :db :company :name)]
(str "?company=" company-name)))
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
(str "?company=" company-id)))
:on-success [::received-invoices :pending]
}}))
(re-frame/reg-event-db

View File

@@ -6,7 +6,7 @@
(re-frame/reg-sub
::company
(fn [db]
(:company db)))
(get (:companies db) (:company db))))
(re-frame/reg-sub
::companies

View File

@@ -25,7 +25,7 @@
:paramName "file"
:headers {"Authorization" (str "Token " @token)}
:url (str "/pdf-upload"
(when-let [company-name (-> @company :name)]
(when-let [company-name (-> @company :id)]
(str "?company=" company-name)))
:previewsContainer "#dz-hidden"
:previewTemplate "<div class='dz-hidden-preview'></div>"})))})))
@@ -56,12 +56,12 @@
[:th "Date"]
[:th "Amount"]
[:th]]]
[:tbody (for [{:keys [vendor potential-duplicate company customer-identifier invoice-number date total id] :as i} @invoices]
^{:key (str company "-" invoice-number "-" date "-" total "-" id)}
[:tbody (for [{:keys [vendor potential-duplicate company-id customer-identifier invoice-number date total id] :as i} @invoices]
^{:key (str company-id "-" invoice-number "-" date "-" total "-" id)}
[:tr
[:td vendor]
(if company
[:td company]
(if company-id
[:td company-id]
[:td [:i.icon.fa.fa-warning {:title "potential duplicate"}]
(str "'" customer-identifier "' doesn't match any known company")])
[:td invoice-number]