tracking companies by id
This commit is contained in:
@@ -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);
|
||||||
@@ -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);
|
||||||
@@ -19,10 +19,10 @@
|
|||||||
|
|
||||||
(defn get-unpaid [company]
|
(defn get-unpaid [company]
|
||||||
(if 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"))))
|
(map db->clj (j/query (get-conn) "SELECT * FROM invoices WHERE imported=true"))))
|
||||||
|
|
||||||
(defn get-pending [company]
|
(defn get-pending [company]
|
||||||
(if 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"))))
|
(map db->clj (j/query (get-conn) "SELECT * FROM invoices WHERE imported=false or imported is null"))))
|
||||||
|
|||||||
@@ -160,7 +160,7 @@
|
|||||||
(for [{:keys [total date invoice-number customer-identifier vendor] :as row}
|
(for [{:keys [total date invoice-number customer-identifier vendor] :as row}
|
||||||
(parse/parse-file (.getPath tempfile) filename)]
|
(parse/parse-file (.getPath tempfile) filename)]
|
||||||
(assoc row
|
(assoc row
|
||||||
:company (:name (parse/best-match companies customer-identifier))
|
:company-id (:id (parse/best-match companies customer-identifier))
|
||||||
|
|
||||||
:imported false
|
:imported false
|
||||||
:potential-duplicate (boolean (seq (filter #(and (= vendor (:vendor %))
|
:potential-duplicate (boolean (seq (filter #(and (= vendor (:vendor %))
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
(ns auto-ap.events
|
(ns auto-ap.events
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as re-frame]
|
||||||
[auto-ap.db :as db]
|
[auto-ap.db :as db]
|
||||||
|
[auto-ap.subs :as subs]
|
||||||
[auto-ap.routes :as routes]
|
[auto-ap.routes :as routes]
|
||||||
[auto-ap.effects :as effects]
|
[auto-ap.effects :as effects]
|
||||||
[bidi.bidi :as bidi]))
|
[bidi.bidi :as bidi]))
|
||||||
@@ -48,7 +49,7 @@
|
|||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::swap-company
|
::swap-company
|
||||||
(fn [db [_ company]]
|
(fn [db [_ company]]
|
||||||
(assoc db :company company)))
|
(assoc db :company (:id company))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::set-active-page
|
::set-active-page
|
||||||
@@ -69,8 +70,8 @@
|
|||||||
{:http {:method :post
|
{:http {:method :post
|
||||||
:token (-> cofx :db :user)
|
:token (-> cofx :db :user)
|
||||||
:uri (str "/api/invoices/approve"
|
:uri (str "/api/invoices/approve"
|
||||||
(when-let [company-name (-> cofx :db :company :name)]
|
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
|
||||||
(str "?company=" company-name)))
|
(str "?company=" company-id)))
|
||||||
:on-success [::received-invoices :pending]
|
:on-success [::received-invoices :pending]
|
||||||
}}))
|
}}))
|
||||||
|
|
||||||
@@ -81,8 +82,8 @@
|
|||||||
:http {:method :get
|
:http {:method :get
|
||||||
:token (-> cofx :db :user)
|
:token (-> cofx :db :user)
|
||||||
:uri (str "/api/invoices/pending"
|
:uri (str "/api/invoices/pending"
|
||||||
(when-let [company-name (-> cofx :db :company :name)]
|
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
|
||||||
(str "?company=" company-name)))
|
(str "?company=" company-id)))
|
||||||
:on-success [::received-invoices :pending]}}))
|
:on-success [::received-invoices :pending]}}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
@@ -92,8 +93,8 @@
|
|||||||
:http {:method :get
|
:http {:method :get
|
||||||
:token (-> cofx :db :user)
|
:token (-> cofx :db :user)
|
||||||
:uri (str "/api/invoices/unpaid"
|
:uri (str "/api/invoices/unpaid"
|
||||||
(when-let [company-name (-> cofx :db :company :name)]
|
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
|
||||||
(str "?company=" company-name)))
|
(str "?company=" company-id)))
|
||||||
:on-success [::received-invoices :unpaid]}}))
|
:on-success [::received-invoices :unpaid]}}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
@@ -102,8 +103,8 @@
|
|||||||
{:http {:method :post
|
{:http {:method :post
|
||||||
:token (-> cofx :db :user)
|
:token (-> cofx :db :user)
|
||||||
:uri (str "/api/invoices/reject"
|
:uri (str "/api/invoices/reject"
|
||||||
(when-let [company-name (-> cofx :db :company :name)]
|
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
|
||||||
(str "?company=" company-name)))
|
(str "?company=" company-id)))
|
||||||
:on-success [::received-invoices :pending]
|
:on-success [::received-invoices :pending]
|
||||||
}}))
|
}}))
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::company
|
::company
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(:company db)))
|
(get (:companies db) (:company db))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::companies
|
::companies
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
:paramName "file"
|
:paramName "file"
|
||||||
:headers {"Authorization" (str "Token " @token)}
|
:headers {"Authorization" (str "Token " @token)}
|
||||||
:url (str "/pdf-upload"
|
:url (str "/pdf-upload"
|
||||||
(when-let [company-name (-> @company :name)]
|
(when-let [company-name (-> @company :id)]
|
||||||
(str "?company=" company-name)))
|
(str "?company=" company-name)))
|
||||||
:previewsContainer "#dz-hidden"
|
:previewsContainer "#dz-hidden"
|
||||||
:previewTemplate "<div class='dz-hidden-preview'></div>"})))})))
|
:previewTemplate "<div class='dz-hidden-preview'></div>"})))})))
|
||||||
@@ -56,12 +56,12 @@
|
|||||||
[:th "Date"]
|
[:th "Date"]
|
||||||
[:th "Amount"]
|
[:th "Amount"]
|
||||||
[:th]]]
|
[:th]]]
|
||||||
[:tbody (for [{:keys [vendor potential-duplicate company customer-identifier invoice-number date total id] :as i} @invoices]
|
[:tbody (for [{:keys [vendor potential-duplicate company-id customer-identifier invoice-number date total id] :as i} @invoices]
|
||||||
^{:key (str company "-" invoice-number "-" date "-" total "-" id)}
|
^{:key (str company-id "-" invoice-number "-" date "-" total "-" id)}
|
||||||
[:tr
|
[:tr
|
||||||
[:td vendor]
|
[:td vendor]
|
||||||
(if company
|
(if company-id
|
||||||
[:td company]
|
[:td company-id]
|
||||||
[:td [:i.icon.fa.fa-warning {:title "potential duplicate"}]
|
[:td [:i.icon.fa.fa-warning {:title "potential duplicate"}]
|
||||||
(str "'" customer-identifier "' doesn't match any known company")])
|
(str "'" customer-identifier "' doesn't match any known company")])
|
||||||
[:td invoice-number]
|
[:td invoice-number]
|
||||||
|
|||||||
Reference in New Issue
Block a user