renamed company to client.

This commit is contained in:
Bryce Covert
2019-01-18 07:44:12 -08:00
parent 583752d740
commit 775150131e
38 changed files with 250 additions and 306 deletions

View File

@@ -1,6 +1,5 @@
(ns auto-ap.db.checks (ns auto-ap.db.checks
(:require [auto-ap.db.utils :refer [clj->db db->clj get-conn execute!] :as u] (:require [auto-ap.db.utils :refer [clj->db db->clj get-conn execute!] :as u]
[auto-ap.entities.companies :as entity]
[clojure.edn :as edn] [clojure.edn :as edn]
[clojure.java.jdbc :as j] [clojure.java.jdbc :as j]
[honeysql.core :as sql] [honeysql.core :as sql]

View File

@@ -1,6 +1,6 @@
(ns auto-ap.db.companies (ns auto-ap.db.companies
(:require [auto-ap.db.utils :refer [clj->db db->clj get-conn query execute!]] (:require [auto-ap.db.utils :refer [clj->db db->clj get-conn query execute!]]
[auto-ap.entities.companies :as entity]
[clojure.edn :as edn] [clojure.edn :as edn]
[clojure.java.jdbc :as j] [clojure.java.jdbc :as j]
[honeysql.core :as sql] [honeysql.core :as sql]

View File

@@ -4,8 +4,6 @@
[auto-ap.db.companies :as companies] [auto-ap.db.companies :as companies]
[auto-ap.db.invoices-checks :as invoices-checks] [auto-ap.db.invoices-checks :as invoices-checks]
[auto-ap.db.vendors :as vendors] [auto-ap.db.vendors :as vendors]
[auto-ap.entities.companies :as company]
[auto-ap.entities.vendors :as vendor]
[clojure.java.jdbc :as j] [clojure.java.jdbc :as j]
[clojure.string :as str] [clojure.string :as str]
[honeysql.core :as sql] [honeysql.core :as sql]
@@ -13,47 +11,6 @@
(def all-keys #{:company-id :vendor-id :imported :potential-duplicate :total :invoice-number :date :outstanding-balance :default-location :default-expense-account}) (def all-keys #{:company-id :vendor-id :imported :potential-duplicate :total :invoice-number :date :outstanding-balance :default-location :default-expense-account})
(defn insert-multi! [rows]
(j/insert-multi! (get-conn)
:invoices
(map clj->db rows)))
(defn upsert-multi! [rows]
(let [k (vec (map #(keyword (kebab->snake (name %))) [:company-id :vendor-id :invoice-number :total :date :imported :status :outstanding-balance :default-location :default-expense-account]))
column-names (str/join "," (map name k))]
(reduce
(fn [affected rows]
(concat affected
(let [[query & params] (sql/format {:with [[[:v (str "(" column-names ")")]
(helpers/values (->> rows
(map clj->db )
(map (apply juxt k))))]]
:insert-into [[:invoices k]
{:select [:v.company-id :v.vendor-id :v.invoice-number :v.total (sql/raw "cast(v.date as timestamp)") :v.imported :v.status :v.outstanding-balance :v.default-location (sql/raw "cast(v.default_expense_account as INT)")]
:from [:v]
:left-join [[:invoices :exist]
[:and
[:= :exist.invoice-number :v.invoice-number]
[:not= :exist.status "voided"]
[:= :exist.company-id :v.company-id]
[:or [:= :exist.vendor-id :v.vendor-id]
[:and
[:= :exist.vendor-id nil]
[:= :v.vendor-id nil]]]]]
:where [:= :exist.id nil] }]})
statement (j/prepare-statement
(j/get-connection (get-conn))
query
{:return-keys true})]
(j/execute!
(get-conn)
(concat [statement] params))
(->> (j/result-set-seq (.getGeneratedKeys statement))
(map db->clj)
doall))))
[]
(partition-all 2000 rows))))
(def base-query (sql/build :select :invoices.* (def base-query (sql/build :select :invoices.*
:from :invoices)) :from :invoices))

View File

@@ -1,6 +1,5 @@
(ns auto-ap.db.invoices-checks (ns auto-ap.db.invoices-checks
(:require [auto-ap.db.utils :refer [clj->db db->clj get-conn execute!] :as u] (:require [auto-ap.db.utils :refer [clj->db db->clj get-conn execute!] :as u]
[auto-ap.entities.companies :as entity]
[clojure.edn :as edn] [clojure.edn :as edn]
[clojure.java.jdbc :as j] [clojure.java.jdbc :as j]
[honeysql.core :as sql] [honeysql.core :as sql]

View File

@@ -7,7 +7,7 @@
[com.walmartlabs.lacinia.resolve :as resolve] [com.walmartlabs.lacinia.resolve :as resolve]
[buddy.auth :refer [throw-unauthorized]] [buddy.auth :refer [throw-unauthorized]]
[auto-ap.utils :refer [by]] [auto-ap.utils :refer [by]]
[auto-ap.graphql.utils :refer [assert-admin can-see-company? assert-can-see-company]] [auto-ap.graphql.utils :refer [assert-admin can-see-client? assert-can-see-client]]
[auto-ap.datomic.clients :as d-clients] [auto-ap.datomic.clients :as d-clients]
[auto-ap.datomic.checks :as d-checks] [auto-ap.datomic.checks :as d-checks]
[auto-ap.datomic.users :as d-users] [auto-ap.datomic.users :as d-users]
@@ -32,13 +32,6 @@
:serialize (schema/as-conformer #(.toString %))}} :serialize (schema/as-conformer #(.toString %))}}
:objects :objects
{ {
:company
{:fields {:id {:type 'String}
:name {:type 'String}
:email {:type 'String}
:address {:type :address}
:locations {:type '(list String)}
:bank_accounts {:type '(list :bank_account)}}}
:client :client
{:fields {:id {:type :id} {:fields {:id {:type :id}
:name {:type 'String} :name {:type 'String}
@@ -96,7 +89,6 @@
:type {:type 'String} :type {:type 'String}
:amount {:type 'String} :amount {:type 'String}
:vendor {:type :vendor} :vendor {:type :vendor}
:company {:type :company}
:date {:type 'String} :date {:type 'String}
:bank_account {:type :bank_account} :bank_account {:type :bank_account}
:memo {:type 'String} :memo {:type 'String}
@@ -168,7 +160,7 @@
:status {:type 'String} :status {:type 'String}
:expense_accounts {:type '(list :invoices_expense_accounts)} :expense_accounts {:type '(list :invoices_expense_accounts)}
:date {:type 'String} :date {:type 'String}
:company_id {:type 'Int} :client_id {:type 'Int}
:payments {:type '(list :invoice_payment)} :payments {:type '(list :invoice_payment)}
:vendor {:type :vendor} :vendor {:type :vendor}
:client {:type :client}}} :client {:type :client}}}
@@ -241,10 +233,8 @@
:resolve :get-payment-page} :resolve :get-payment-page}
:company {:type '(list :company) :client {:type '(list :client)
:resolve :get-company} :resolve :get-client}
:client {:type '(list :company)
:resolve :get-company}
:vendor {:type '(list :vendor) :vendor {:type '(list :vendor)
:resolve :get-vendor} :resolve :get-vendor}
:user {:type '(list :user) :user {:type '(list :user)
@@ -402,9 +392,9 @@
:limit Integer/MAX_VALUE)))) :limit Integer/MAX_VALUE))))
(defn get-company [context args value] (defn get-client [context args value]
(->graphql (->graphql
(filter #(can-see-company? (:id context) %) (filter #(can-see-client? (:id context) %)
(d-clients/get-all)))) (d-clients/get-all))))
(defn get-user [context args value] (defn get-user [context args value]
@@ -420,7 +410,7 @@
(defn print-checks [context args value] (defn print-checks [context args value]
(assert-can-see-company (:id context) (:client_id args)) (assert-can-see-client (:id context) (:client_id args))
(->graphql (->graphql
(gq-checks/print-checks (map (fn [i] {:invoice-id (:invoice_id i) (gq-checks/print-checks (map (fn [i] {:invoice-id (:invoice_id i)
:amount (:amount i)}) :amount (:amount i)})
@@ -439,7 +429,7 @@
:get-payment-page gq-checks/get-payment-page :get-payment-page gq-checks/get-payment-page
:get-transaction-page gq-transactions/get-transaction-page :get-transaction-page gq-transactions/get-transaction-page
:get-company get-company :get-client get-client
:get-user get-user :get-user get-user
:mutation/add-handwritten-check gq-checks/add-handwritten-check :mutation/add-handwritten-check gq-checks/add-handwritten-check
:mutation/print-checks print-checks :mutation/print-checks print-checks

View File

@@ -1,5 +1,5 @@
(ns auto-ap.graphql.checks (ns auto-ap.graphql.checks
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-company]] (:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client]]
[datomic.api :as d] [datomic.api :as d]
[clojure.edn :as edn] [clojure.edn :as edn]
[com.walmartlabs.lacinia :refer [execute]] [com.walmartlabs.lacinia :refer [execute]]
@@ -316,7 +316,7 @@
(let [invoice (d-invoices/get-by-id (:invoice_id args)) (let [invoice (d-invoices/get-by-id (:invoice_id args))
bank-account-id (:bank_account_id args) bank-account-id (:bank_account_id args)
bank-account (d-bank-accounts/get-by-id bank-account-id) bank-account (d-bank-accounts/get-by-id bank-account-id)
_ (assert-can-see-company (:id context) (:invoice/client invoice)) _ (assert-can-see-client (:id context) (:invoice/client invoice))
base-payment (base-payment [invoice] (:invoice/vendor invoice) base-payment (base-payment [invoice] (:invoice/vendor invoice)
(:invoice/client invoice) (:invoice/client invoice)
bank-account :payment-type/check 0 {(:invoice_id args) (:amount args)})] bank-account :payment-type/check 0 {(:invoice_id args) (:amount args)})]
@@ -339,7 +339,7 @@
(let [check (d-checks/get-by-id id)] (let [check (d-checks/get-by-id id)]
(assert (or (= :payment-status/pending (:payment/status check)) (assert (or (= :payment-status/pending (:payment/status check))
(#{:payment-type/cash :payment-type/debit} (:payment/type check)))) (#{:payment-type/cash :payment-type/debit} (:payment/type check))))
(assert-can-see-company (:id context) (:client-id check)) (assert-can-see-client (:id context) (:client-id check))
(let [removing-payments (mapcat (fn [x] (let [removing-payments (mapcat (fn [x]
(let [invoice (:invoice-payment/invoice x) (let [invoice (:invoice-payment/invoice x)
new-balance (+ (:invoice/outstanding-balance invoice) new-balance (+ (:invoice/outstanding-balance invoice)

View File

@@ -1,5 +1,5 @@
(ns auto-ap.graphql.invoices (ns auto-ap.graphql.invoices
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-company assert-admin]] (:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client assert-admin]]
[auto-ap.datomic.vendors :as d-vendors] [auto-ap.datomic.vendors :as d-vendors]
[auto-ap.datomic.invoices :as d-invoices] [auto-ap.datomic.invoices :as d-invoices]
@@ -34,7 +34,7 @@
:invoice/vendor vendor_id :invoice/vendor vendor_id
:invoice/client client_id})) :invoice/client client_id}))
(throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number}))) (throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number})))
(let [_ (assert-can-see-company (:id context) client_id) (let [_ (assert-can-see-client (:id context) client_id)
vendor (d-vendors/get-by-id vendor_id) vendor (d-vendors/get-by-id vendor_id)
expense-account-id (:vendor/default-expense-account vendor) expense-account-id (:vendor/default-expense-account vendor)
@@ -59,7 +59,7 @@
(->graphql)))) (->graphql))))
(defn edit-invoice [context {{:keys [id invoice_number total vendor_id date company_id] :as in} :invoice} value] (defn edit-invoice [context {{:keys [id invoice_number total vendor_id date client_id] :as in} :invoice} value]
(let [invoice (d-invoices/get-by-id id) (let [invoice (d-invoices/get-by-id id)
@@ -71,7 +71,7 @@
println)) println))
(throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number}))) (throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number})))
paid-amount (- (:invoice/total invoice) (:invoice/outstanding-balance invoice)) paid-amount (- (:invoice/total invoice) (:invoice/outstanding-balance invoice))
_ (assert-can-see-company (:id context) (:db/id (:client invoice))) _ (assert-can-see-client (:id context) (:db/id (:invoice/client invoice)))
updated-invoice (d-invoices/update {:db/id id updated-invoice (d-invoices/update {:db/id id
:invoice/invoice-number invoice_number :invoice/invoice-number invoice_number
:invoice/date (coerce/to-date (parse date iso-date)) :invoice/date (coerce/to-date (parse date iso-date))
@@ -82,7 +82,7 @@
(defn void-invoice [context {id :invoice_id} value] (defn void-invoice [context {id :invoice_id} value]
(let [invoice (d-invoices/get-by-id id) (let [invoice (d-invoices/get-by-id id)
_ (assert-can-see-company (:id context) (:company-id invoice)) _ (assert-can-see-client (:id context) (:client-id invoice))
updated-invoice (d-invoices/update {:db/id id updated-invoice (d-invoices/update {:db/id id
:invoice/total 0.0 :invoice/total 0.0
:invoice/outstanding-balance 0.0 :invoice/outstanding-balance 0.0
@@ -98,7 +98,7 @@
(defn edit-expense-accounts [context args value] (defn edit-expense-accounts [context args value]
;; TODO - Can expense account id be used as a unique field? It may compose with component, meaning ;; TODO - Can expense account id be used as a unique field? It may compose with component, meaning
;; that you don't have to figure out which ones to delete and which ones to add. Just set to 0. ;; that you don't have to figure out which ones to delete and which ones to add. Just set to 0.
(assert-can-see-company (:id context) (:db/id (:client (d-invoices/get-by-id (:invoice_id args))))) (assert-can-see-client (:id context) (:db/id (:invoice/client (d-invoices/get-by-id (:invoice_id args)))))
(let [current-expense-accounts (:invoice/expense-accounts (d-invoices/get-by-id (:invoice_id args))) (let [current-expense-accounts (:invoice/expense-accounts (d-invoices/get-by-id (:invoice_id args)))
invoice-id (:invoice_id args) invoice-id (:invoice_id args)

View File

@@ -47,14 +47,14 @@
(when-not (= "admin" (:user/role id)) (when-not (= "admin" (:user/role id))
(throw-unauthorized))) (throw-unauthorized)))
(defn can-see-company? [identity company] (defn can-see-client? [identity client]
(or (= "admin" (:user/role identity)) (or (= "admin" (:user/role identity))
((set (map :db/id (:user/clients identity))) (:db/id company)) ((set (map :db/id (:user/clients identity))) (:db/id client))
((set (map :db/id (:user/clients identity))) company))) ((set (map :db/id (:user/clients identity))) client)))
(defn assert-can-see-company [identity company] (defn assert-can-see-client [identity client]
(when-not (can-see-company? identity company) (when-not (can-see-client? identity client)
(println "IDENTITY " identity " can not see company " company) (println "IDENTITY " identity " can not see company " client)
(throw-unauthorized))) (throw-unauthorized)))
(defn limited-clients [id] (defn limited-clients [id]

View File

@@ -1,5 +1,5 @@
(ns auto-ap.graphql.vendors (ns auto-ap.graphql.vendors
(:require [auto-ap.graphql.utils :refer [->graphql assert-can-see-company]] (:require [auto-ap.graphql.utils :refer [->graphql assert-can-see-client]]
[auto-ap.datomic.vendors :as d-vendors] [auto-ap.datomic.vendors :as d-vendors]
[auto-ap.time :refer [parse iso-date]] [auto-ap.time :refer [parse iso-date]]
[datomic.api :as d] [datomic.api :as d]

View File

@@ -1,7 +1,7 @@
(ns auto-ap.handler (ns auto-ap.handler
(:require [amazonica.core :refer [defcredential]] (:require [amazonica.core :refer [defcredential]]
[auto-ap.routes.auth :as auth] [auto-ap.routes.auth :as auth]
[auto-ap.routes.companies :as companies] [auto-ap.routes.clients :as clients]
[auto-ap.routes.invoices :as invoices] [auto-ap.routes.invoices :as invoices]
[auto-ap.routes.reminders :as reminders] [auto-ap.routes.reminders :as reminders]
[auto-ap.routes.graphql :as graphql] [auto-ap.routes.graphql :as graphql]
@@ -34,7 +34,7 @@
exports/routes exports/routes
yodlee/routes yodlee/routes
invoices/routes invoices/routes
companies/routes clients/routes
reminders/routes reminders/routes
checks/routes checks/routes
graphql/routes graphql/routes

View File

@@ -67,13 +67,12 @@
[file filename] [file filename]
(excel/parse-file file filename)) (excel/parse-file file filename))
(defn best-match [companies company-identifier] (defn best-match [clients client-identifier]
(println companies) (->> clients
(->> companies (map (fn [client]
(map (fn [company] (if-let [matches (:client/matches client)]
(if-let [matches (:matches company)] [client (apply min (map #(m/jaccard (.toLowerCase client-identifier) %) matches))]
[company (apply min (map #(m/jaccard (.toLowerCase company-identifier) %) matches))] [client 1])))
[company 1])))
(filter #(< (second %) 0.25)) (filter #(< (second %) 0.25))
(sort-by second) (sort-by second)

View File

@@ -1,20 +1,20 @@
(ns auto-ap.routes.companies (ns auto-ap.routes.clients
(:require [auto-ap.datomic.clients :as clients] (:require [auto-ap.datomic.clients :as clients]
[auto-ap.graphql.utils :refer [can-see-company? assert-can-see-company]] [auto-ap.graphql.utils :refer [can-see-client? assert-can-see-client]]
[auto-ap.routes.utils :refer [wrap-secure wrap-spec]] [auto-ap.routes.utils :refer [wrap-secure wrap-spec]]
[auto-ap.entities.companies :as entity] [auto-ap.entities.clients :as entity]
[compojure.core :refer [GET PUT context defroutes [compojure.core :refer [GET PUT context defroutes
wrap-routes]])) wrap-routes]]))
(defroutes routes (defroutes routes
(wrap-routes (wrap-routes
(context "/companies" [] (context "/clients" []
#_(wrap-spec #_(wrap-spec
(PUT "/:id" {{:keys [address email locations new-bank-accounts]} :edn-params :keys [edn-params] {:keys [id ]} :route-params :as r} (PUT "/:id" {{:keys [address email locations new-bank-accounts]} :edn-params :keys [edn-params] {:keys [id ]} :route-params :as r}
(assert-can-see-company (:identity r) id) (assert-can-see-client (:identity r) id)
(let [id (Integer/parseInt id) (let [id (Integer/parseInt id)
company (companies/get-by-id id) company (d-clients/get-by-id id)
updated-company (merge company {:address address updated-company (merge company {:address address
:email email :email email
:locations locations})] :locations locations})]

View File

@@ -30,7 +30,7 @@
(if-let [id (:db/id (or (clients client-code) (if-let [id (:db/id (or (clients client-code)
(clients client)))] (clients client)))]
id id
(throw (Exception. (str "Company code '" client-code "' and company named '" client "' not found."))))) (throw (Exception. (str "Client code '" client-code "' and client named '" client "' not found.")))))
(defn parse-invoice-number [{:keys [invoice-number]}] (defn parse-invoice-number [{:keys [invoice-number]}]
(or invoice-number "")) (or invoice-number ""))
@@ -94,7 +94,7 @@
:details (str e)}))))) :details (str e)})))))
(defn parse-invoice-rows [excel-rows] (defn parse-invoice-rows [excel-rows]
(let [columns [:raw-date :vendor-name :check :location :invoice-number :amount :company :bill-entered :bill-rejected :added-on :exported-on :default-expense-account] (let [columns [:raw-date :vendor-name :check :location :invoice-number :amount :client :bill-entered :bill-rejected :added-on :exported-on :default-expense-account]
all-vendors (by :vendor/name (d-vendors/get-graphql {})) all-vendors (by :vendor/name (d-vendors/get-graphql {}))
all-clients (d-clients/get-all) all-clients (d-clients/get-all)
all-clients (merge (by :client/code all-clients) (by :client/name all-clients)) all-clients (merge (by :client/code all-clients) (by :client/name all-clients))

View File

@@ -43,7 +43,7 @@
nil)) nil))
nil)) nil))
(defn import-transactions [transactions transaction->company transaction->bank-account-id] (defn import-transactions [transactions transaction->client transaction->bank-account-id]
(doseq [transaction transactions (doseq [transaction transactions
:let [{post-date :postDate :let [{post-date :postDate
account-id :accountId account-id :accountId
@@ -62,7 +62,7 @@
(- amount) (- amount)
amount) amount)
check-number (extract-check-number transaction) check-number (extract-check-number transaction)
client-id (transaction->company transaction) client-id (transaction->client transaction)
bank-account-id (transaction->bank-account-id transaction) bank-account-id (transaction->bank-account-id transaction)
check-id (transaction->check-id transaction check-number client-id bank-account-id amount)]] check-id (transaction->check-id transaction check-number client-id bank-account-id amount)]]
(try (try
@@ -125,7 +125,7 @@
:yodlee-account-id yodlee-account-id})) :yodlee-account-id yodlee-account-id}))
(:client/bank-accounts c))) (:client/bank-accounts c)))
(d-clients/get-all)) (d-clients/get-all))
transaction->company (comp (by :yodlee-account-id :client-id all-bank-accounts) :accountId) transaction->client (comp (by :yodlee-account-id :client-id all-bank-accounts) :accountId)
transaction->bank-account-id (comp (by :yodlee-account-id :bank-account-id all-bank-accounts) :accountId)] transaction->bank-account-id (comp (by :yodlee-account-id :bank-account-id all-bank-accounts) :accountId)]
(import-transactions transactions transaction->company transaction->bank-account-id))) (import-transactions transactions transaction->client transaction->bank-account-id)))

View File

@@ -1,4 +1,4 @@
(ns auto-ap.entities.companies (ns auto-ap.entities.clients
(:require [clojure.spec.alpha :as s] (:require [clojure.spec.alpha :as s]
[auto-ap.entities.shared :as shared] [auto-ap.entities.shared :as shared]
[clojure.string :as str] [clojure.string :as str]
@@ -17,12 +17,12 @@
:is-empty #(= % ""))))) :is-empty #(= % "")))))
(s/def ::company (s/keys :req-un [::name] (s/def ::client (s/keys :req-un [::name]
:opt-un [::email :opt-un [::email
::address ::address
::locations ::locations
::id])) ::id]))
(def company-spec (apply hash-map (drop 1 (s/form ::company)))) (def client-spec (apply hash-map (drop 1 (s/form ::client))))
(def all-keys (map #(keyword (name %)) (concat (:req-un company-spec) (:opt-un company-spec)))) (def all-keys (map #(keyword (name %)) (concat (:req-un client-spec) (:opt-un client-spec))))

View File

@@ -2,12 +2,12 @@
(def default-db (def default-db
{:user (.getItem js/localStorage "jwt") {:user (.getItem js/localStorage "jwt")
:company {:name "Campbell Brewing Company"} :client {:name "Campbell Brewing Company"}
:companies [] :clients []
:invoices {:pending #{} :invoices {:pending #{}
:unpaid #{}} :unpaid #{}}
:status {:loading false} :status {:loading false}
:new-invoice {} :new-invoice {}
:menu {:company {:active? false} :menu {:client {:active? false}
:account {:active? false}} :account {:active? false}}
}) })

View File

@@ -35,7 +35,7 @@
:active-page handler :active-page handler
:user token) :user token)
:graphql {:token token :graphql {:token token
:query-obj {:venia/queries [[:company :query-obj {:venia/queries [[:client
[:id :name :locations [:bank-accounts [:id :number :check-number :name :type] ] [:id :name :locations [:bank-accounts [:id :number :check-number :name :type] ]
[:address [:street1 :street2 :city :state :zip]]]] [:address [:street1 :street2 :city :state :zip]]]]
@@ -59,7 +59,7 @@
::logged-in ::logged-in
(fn [{:keys [db]} [_ token user]] (fn [{:keys [db]} [_ token user]]
{:graphql {:token token {:graphql {:token token
:query-obj {:venia/queries [[:company :query-obj {:venia/queries [[:client
[:id :name [:bank-accounts [:id :number :check-number :name :type]]]] [:id :name [:bank-accounts [:id :number :check-number :name :type]]]]
[:vendor [:vendor
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]} [:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
@@ -69,15 +69,15 @@
(re-frame/reg-event-db (re-frame/reg-event-db
::received-initial ::received-initial
(fn [db [_ {companies :company vendors :vendor :as x}]] (fn [db [_ {clients :client vendors :vendor :as x}]]
(-> db (-> db
(assoc :companies (by :id companies) ) (assoc :clients (by :id clients) )
(assoc :vendors (by :id vendors) )))) (assoc :vendors (by :id vendors) ))))
(re-frame/reg-event-db (re-frame/reg-event-db
::swap-company ::swap-client
(fn [db [_ company]] (fn [db [_ client]]
(assoc db :company (:id company)))) (assoc db :client (:id client))))
(re-frame/reg-event-db (re-frame/reg-event-db
::change-form ::change-form
@@ -123,8 +123,8 @@
{:db (assoc-in (:db cofx) [:status :loading] true) {:db (assoc-in (:db cofx) [:status :loading] true)
:graphql {:token (-> cofx :db :user) :graphql {:token (-> cofx :db :user)
:query-obj {:venia/queries [[:invoice :query-obj {:venia/queries [[:invoice
{:imported false :company_id (:id @(re-frame/subscribe [::subs/company]))} {:imported false :client_id (:id @(re-frame/subscribe [::subs/client]))}
[:id :total :invoice-number :date [:vendor [:name :id]] [:company [:name :id]]]]]} [:id :total :invoice-number :date [:vendor [:name :id]] [:client [:name :id]]]]]}
:on-success [::received-invoices :pending]}})) :on-success [::received-invoices :pending]}}))
@@ -134,8 +134,8 @@
{:db (assoc-in (:db cofx) [:status :loading] true) {:db (assoc-in (:db cofx) [:status :loading] true)
:graphql {:token (-> cofx :db :user) :graphql {:token (-> cofx :db :user)
:query-obj {:venia/queries [[:invoice :query-obj {:venia/queries [[:invoice
{:imported true :company_id (:id @(re-frame/subscribe [::subs/company]))} {:imported true :client_id (:id @(re-frame/subscribe [::subs/client]))}
[:id :total :invoice-number :date [:vendor [:name :id]] [:company [:name :id]]]]]} [:id :total :invoice-number :date [:vendor [:name :id]] [:client [:name :id]]]]]}
:on-success [::received-invoices :unpaid]}})) :on-success [::received-invoices :unpaid]}}))
(re-frame/reg-event-db (re-frame/reg-event-db
@@ -146,7 +146,7 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
::logout ::logout
(fn [{:keys [db]} [_]] (fn [{:keys [db]} [_]]
{:db (assoc db :user nil :menu {:company {:active? false} {:db (assoc db :user nil :menu {:client {:active? false}
:account {:active? false}}) :account {:active? false}})
:redirect (bidi/path-for routes/routes :login) :redirect (bidi/path-for routes/routes :login)
:set-local-storage ["jwt" nil]})) :set-local-storage ["jwt" nil]}))

View File

@@ -1,52 +1,52 @@
(ns auto-ap.events.admin.companies (ns auto-ap.events.admin.clients
(: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.events :as events] [auto-ap.events :as events]
[auto-ap.routes :as routes] [auto-ap.routes :as routes]
[auto-ap.effects :as effects] [auto-ap.effects :as effects]
[auto-ap.entities.companies :as entity] [auto-ap.entities.clients :as entity]
[bidi.bidi :as bidi])) [bidi.bidi :as bidi]))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::edit ::edit
(fn [{:keys [db]} [_ company-id]] (fn [{:keys [db]} [_ client-id]]
{:dispatch [::events/modal-status :auto-ap.views.pages.admin.companies/edit {:visible? true}] {:dispatch [::events/modal-status :auto-ap.views.pages.admin.clients/edit {:visible? true}]
:db (assoc-in db [:admin :company] :db (assoc-in db [:admin :client]
(get (:companies db) company-id))})) (get (:clients db) client-id))}))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::save ::save
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
(let [edited-company (-> (get-in db [:admin :company]) (let [edited-client (-> (get-in db [:admin :clients])
(dissoc :location))] (dissoc :location))]
{:db (assoc-in db [:admin :company :saving?] true) {:db (assoc-in db [:admin :client :saving?] true)
:http {:method :put :http {:method :put
:token (:user db) :token (:user db)
:body (pr-str edited-company) :body (pr-str edited-client)
:headers {"Content-Type" "application/edn"} :headers {"Content-Type" "application/edn"}
:uri (str "/api/companies/" (:id edited-company)) :uri (str "/api/clients/" (:id edited-client))
:on-success [::save-complete] :on-success [::save-complete]
:on-error [::save-error]}}))) :on-error [::save-error]}})))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::save-complete ::save-complete
(fn [{:keys [db]} [_ company]] (fn [{:keys [db]} [_ client]]
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.companies/edit] {:dispatch [::events/modal-completed :auto-ap.views.pages.admin.clients/edit]
:db (-> db :db (-> db
(assoc-in [:admin :company] nil) (assoc-in [:admin :clients] nil)
(assoc-in [:companies (:id company)] company))})) (assoc-in [:clients (:id client)] client))}))
(re-frame/reg-event-db (re-frame/reg-event-db
::save-error ::save-error
(fn [db [_ company]] (fn [db [_ client]]
(-> db (-> db
(assoc-in [:admin :company :saving?] false) (assoc-in [:admin :client :saving?] false)
(assoc-in [:admin :company :error] true)))) (assoc-in [:admin :client :error] true))))
(re-frame/reg-event-db (re-frame/reg-event-db
::change ::change
(fn [db [_ path value]] (fn [db [_ path value]]
(assoc-in db (concat [:admin :company] path) (assoc-in db (concat [:admin :client] path)
value))) value)))

View File

@@ -99,8 +99,8 @@
(-> db (-> db
(update-in [:admin :vendor :relationships] #(conj (or % []) (update-in [:admin :vendor :relationships] #(conj (or % [])
{:account-number (get-in db [:admin :vendor :new-relationship-account-number]) {:account-number (get-in db [:admin :vendor :new-relationship-account-number])
:company-id (get-in db [:admin :vendor :new-relationship-company])})) :client-id (get-in db [:admin :vendor :new-relationship-client])}))
(update-in [:admin :vendor] dissoc :new-relationship-account-number :new-relationship-company)))) (update-in [:admin :vendor] dissoc :new-relationship-account-number :new-relationship-client))))
(re-frame/reg-event-db (re-frame/reg-event-db
::remove-relationship ::remove-relationship

View File

@@ -5,7 +5,7 @@
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[cljs-time.core :as c] [cljs-time.core :as c]
[goog.string :as gstring] [goog.string :as gstring]
[auto-ap.entities.companies :as company] [auto-ap.entities.clients :as clients]
[auto-ap.entities.invoice :as invoice] [auto-ap.entities.invoice :as invoice]
[auto-ap.entities.vendors :as vendor] [auto-ap.entities.vendors :as vendor]
[auto-ap.expense-accounts :as expense-accounts] [auto-ap.expense-accounts :as expense-accounts]
@@ -40,7 +40,7 @@
[:vendor [:name :id]] [:vendor [:name :id]]
[:expense_accounts [:amount :id :location :expense_account_id [:expense_accounts [:amount :id :location :expense_account_id
[:expense_account [:id :name [:parent [:id :name]]]]]] [:expense_account [:id :name [:parent [:id :name]]]]]]
[:company [:name :id :locations]] [:client [:name :id :locations]]
[:checks [:amount [:check [:amount :s3_url :check_number ]]]] [:checks [:amount [:check [:amount :s3_url :check_number ]]]]
]]}]} ]]}]}
:on-success [::expense-accounts-updated]}}))) :on-success [::expense-accounts-updated]}})))
@@ -62,7 +62,7 @@
(re-frame/reg-event-db (re-frame/reg-event-db
::add-expense-account-split ::add-expense-account-split
(fn [db _] (fn [db _]
(let [{{{:keys [locations]} :company} :invoice} @(re-frame/subscribe [::change-expense-accounts])] (let [{{{:keys [locations]} :client} :invoice} @(re-frame/subscribe [::change-expense-accounts])]
(update-in db [::change-expense-accounts :invoice :expense-accounts] (update-in db [::change-expense-accounts :invoice :expense-accounts]
conj {:amount 0 :expense-account-id nil :location (first locations)})))) conj {:amount 0 :expense-account-id nil :location (first locations)}))))

View File

@@ -6,7 +6,7 @@
"needs-activation/" :needs-activation "needs-activation/" :needs-activation
"checks/" :checks "checks/" :checks
"admin/" {"" :admin "admin/" {"" :admin
"companies" :admin-companies "clients" :admin-clients
"users" :admin-users "users" :admin-users
"reminders" :admin-reminders "reminders" :admin-reminders
"vendors" :admin-vendors "vendors" :admin-vendors

View File

@@ -5,21 +5,21 @@
[goog.crypt.base64 :as base64])) [goog.crypt.base64 :as base64]))
(re-frame/reg-sub (re-frame/reg-sub
::company ::client
(fn [db] (fn [db]
(get (:companies db) (:company db)))) (get (:clients db) (:client db))))
(re-frame/reg-sub (re-frame/reg-sub
::companies ::clients
(fn [db] (fn [db]
(when (:user db) (when (:user db)
(vals (:companies db))))) (vals (:clients db)))))
(re-frame/reg-sub (re-frame/reg-sub
::companies-by-id ::clients-by-id
(fn [db] (fn [db]
(when (:user db) (when (:user db)
(:companies db)))) (:clients db))))
(re-frame/reg-sub (re-frame/reg-sub
::menu ::menu

View File

@@ -6,7 +6,7 @@
[cljs-time.core :as c] [cljs-time.core :as c]
[goog.string :as gstring] [goog.string :as gstring]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.entities.companies :as company] [auto-ap.entities.clients :as client]
[auto-ap.entities.invoice :as invoice] [auto-ap.entities.invoice :as invoice]
[auto-ap.entities.vendors :as vendor] [auto-ap.entities.vendors :as vendor]
[auto-ap.expense-accounts :as expense-accounts] [auto-ap.expense-accounts :as expense-accounts]
@@ -73,7 +73,7 @@
(defn change-expense-accounts-modal [{:keys [updated-event]}] (defn change-expense-accounts-modal [{:keys [updated-event]}]
(let [{{:keys [expense-accounts total ] :or {expense-accounts [] total 0} {:keys [locations]} :company} :invoice :as data} @(re-frame/subscribe [::change-expense-accounts]) (let [{{:keys [expense-accounts total ] :or {expense-accounts [] total 0} {:keys [locations]} :client} :invoice :as data} @(re-frame/subscribe [::change-expense-accounts])
multi-location? (> (count locations) 1) multi-location? (> (count locations) 1)
change-event [::events/change-form [::change-expense-accounts]] change-event [::events/change-form [::change-expense-accounts]]
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts]) chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])

View File

@@ -41,7 +41,7 @@
(defn query [params] (defn query [params]
{:venia/queries [[:invoice_page {:venia/queries [[:invoice_page
(assoc params (assoc params
:client-id (:id @(re-frame/subscribe [::subs/company]))) :client-id (:id @(re-frame/subscribe [::subs/client])))
[[:invoices [:id :total :outstanding-balance :invoice-number :date [[:invoices [:id :total :outstanding-balance :invoice-number :date
[:vendor [:name :id]] [:vendor [:name :id]]
[:expense_accounts [:amount :id :expense_account_id :location [:expense_accounts [:amount :id :expense_account_id :location
@@ -59,7 +59,7 @@
(let [state (reagent/atom (or @params {})) (let [state (reagent/atom (or @params {}))
visible-checks @(re-frame/subscribe [::visible-checks]) visible-checks @(re-frame/subscribe [::visible-checks])
visible-expense-accounts @(re-frame/subscribe [::visible-expense-accounts]) visible-expense-accounts @(re-frame/subscribe [::visible-expense-accounts])
selected-company @(re-frame/subscribe [::subs/company]) selected-client @(re-frame/subscribe [::subs/client])
opc (fn [p] opc (fn [p]
(swap! state merge p) (swap! state merge p)
(on-params-change p))] (on-params-change p))]
@@ -68,8 +68,8 @@
{:keys [invoices start end count total]} @invoice-page {:keys [invoices start end count total]} @invoice-page
visible-checks @(re-frame/subscribe [::visible-checks]) visible-checks @(re-frame/subscribe [::visible-checks])
visible-expense-accounts @(re-frame/subscribe [::visible-expense-accounts]) visible-expense-accounts @(re-frame/subscribe [::visible-expense-accounts])
selected-company @(re-frame/subscribe [::subs/company]) selected-client @(re-frame/subscribe [::subs/client])
percentage-size (if selected-company "%50%" "33%") percentage-size (if selected-client "%50%" "33%")
] ]
[:div [:div
[paginator {:start start :end end :count count :total total [paginator {:start start :end end :count count :total total
@@ -83,7 +83,7 @@
(when check-boxes (when check-boxes
[:th {:style {"width" "20px"}}]) [:th {:style {"width" "20px"}}])
(when-not selected-company (when-not selected-client
[sorted-column {:on-sort opc [sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"} :style {:width percentage-size :cursor "pointer"}
:sort-key "client" :sort-key "client"
@@ -149,7 +149,7 @@
"") "")
:on-change (fn [x e] (when on-check-changed :on-change (fn [x e] (when on-check-changed
(on-check-changed id)))} ]]) (on-check-changed id)))} ]])
(when-not selected-company (when-not selected-client
[:td (:name client)]) [:td (:name client)])
[:td (:name vendor)] [:td (:name vendor)]
[:td invoice-number] [:td invoice-number]

View File

@@ -13,7 +13,7 @@
(defn vendor-dialog [{:keys [vendor save-event change-event id] {:keys [name]} :vendor}] (defn vendor-dialog [{:keys [vendor save-event change-event id] {:keys [name]} :vendor}]
(println (s/explain ::entity/vendor vendor) ) (println (s/explain ::entity/vendor vendor) )
(let [companies-by-id @(re-frame/subscribe [::subs/companies-by-id])] (let [clients-by-id @(re-frame/subscribe [::subs/clients-by-id])]
[action-modal {:id id [action-modal {:id id
:title [:span (if (:id vendor) :title [:span (if (:id vendor)
(str "Edit " (or name "<vendor>")) (str "Edit " (or name "<vendor>"))

View File

@@ -6,7 +6,7 @@
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.events :as events] [auto-ap.events :as events]
[auto-ap.views.utils :refer [active-when= login-url dispatch-event]] [auto-ap.views.utils :refer [active-when= login-url dispatch-event]]
[auto-ap.entities.companies :as company] [auto-ap.entities.clients :as clients]
[auto-ap.views.pages :as pages] [auto-ap.views.pages :as pages]
[auto-ap.views.components.vendor-dialog :refer [vendor-dialog]])) [auto-ap.views.components.vendor-dialog :refer [vendor-dialog]]))
@@ -23,7 +23,7 @@
:unpaid-invoices :left-panel :unpaid-invoices :left-panel
:paid-invoices :left-panel :paid-invoices :left-panel
:admin :admin-left-panel :admin :admin-left-panel
:admin-companies :admin-left-panel :admin-clients :admin-left-panel
:admin-users :admin-left-panel :admin-users :admin-left-panel
:admin-excel-import :admin-left-panel :admin-excel-import :admin-left-panel
:admin-vendors :admin-left-panel :admin-vendors :admin-left-panel
@@ -52,8 +52,8 @@
(defmulti layout page->layout) (defmulti layout page->layout)
(defmethod layout :admin-left-panel [ap] (defmethod layout :admin-left-panel [ap]
(let [company (re-frame/subscribe [::subs/company]) (let [client (re-frame/subscribe [::subs/client])
companies (re-frame/subscribe [::subs/companies]) clients (re-frame/subscribe [::subs/clients])
menu (re-frame/subscribe [::subs/menu])] menu (re-frame/subscribe [::subs/menu])]
[:div [:div
@@ -82,11 +82,11 @@
[:p.menu-label "Setup"] [:p.menu-label "Setup"]
[:ul.menu-list [:ul.menu-list
[:li.menu-item [:li.menu-item
[:a {:href (bidi/path-for routes/routes :admin-companies) , :class (str "item" (active-when= ap :admin-companies))} [:a {:href (bidi/path-for routes/routes :admin-clients) , :class (str "item" (active-when= ap :admin-clients))}
[:span {:class "icon"} [:span {:class "icon"}
[:i {:class "fa fa-star-o"}]] [:i {:class "fa fa-star-o"}]]
[:span {:class "name"} "Companies"]]] [:span {:class "name"} "Clients"]]]
[:li.menu-item [:li.menu-item
[:a {:href (bidi/path-for routes/routes :admin-vendors) , :class (str "item" (active-when= ap :admin-vendors))} [:a {:href (bidi/path-for routes/routes :admin-vendors) , :class (str "item" (active-when= ap :admin-vendors))}
[:span {:class "icon"} [:span {:class "icon"}
@@ -129,7 +129,7 @@
[:a {:class "button is-danger is-block is-bold" :href (bidi/path-for routes/routes :index)} [:a {:class "button is-danger is-block is-bold" :href (bidi/path-for routes/routes :index)}
[:span {:class "compose"} "Back"]]]]] [:span {:class "compose"} "Back"]]]]]
[:div {:class "column messages hero is-fullheight", :id "message-feed"} [:div {:class "column messages hero is-fullheight", :id "message-feed"}
^{:key (str "active-page-" (:name @company))} ^{:key (str "active-page-" (:name @client))}
[:div.inbox-messages [:div.inbox-messages
[pages/active-page ap]]]] [pages/active-page ap]]]]
[:footer {:class "footer"} [:footer {:class "footer"}
@@ -143,8 +143,8 @@
[:div#dz-hidden]])) [:div#dz-hidden]]))
(defmethod layout :left-panel [ap] (defmethod layout :left-panel [ap]
(let [company (re-frame/subscribe [::subs/company]) (let [client (re-frame/subscribe [::subs/client])
companies (re-frame/subscribe [::subs/companies]) clients (re-frame/subscribe [::subs/clients])
menu (re-frame/subscribe [::subs/menu])] menu (re-frame/subscribe [::subs/menu])]
[:div [:div
[:nav {:class "navbar has-shadow"} [:nav {:class "navbar has-shadow"}
@@ -153,20 +153,20 @@
[:a {:class "navbar-item", :href "../"} [:a {:class "navbar-item", :href "../"}
[:img {:src "/img/logo.png"}]]] [:img {:src "/img/logo.png"}]]]
[:div {:id "navMenu", :class "navbar-menu " [:div {:id "navMenu", :class "navbar-menu "
:on-click (fn [] (re-frame/dispatch [::events/toggle-menu :company]))} :on-click (fn [] (re-frame/dispatch [::events/toggle-menu :client]))}
[:div.navbar-start [:div.navbar-start
[:div { :class (str "navbar-item has-dropdown " (when (get-in @menu [:company :active?]) "is-active"))} [:div { :class (str "navbar-item has-dropdown " (when (get-in @menu [:client :active?]) "is-active"))}
[:a {:class "navbar-link login"} "Company: " (if @company (:name @company) [:a {:class "navbar-link login"} "Client: " (if @client (:name @client)
"All")] "All")]
[:div {:class "navbar-dropdown"} [:div {:class "navbar-dropdown"}
[:a {:class "navbar-item" [:a {:class "navbar-item"
:on-click (fn [] (re-frame/dispatch [::events/swap-company nil])) :on-click (fn [] (re-frame/dispatch [::events/swap-client nil]))
} "All"] } "All"]
[:hr {:class "navbar-divider"}] [:hr {:class "navbar-divider"}]
(for [{:keys [name id] :as company} @companies] (for [{:keys [name id] :as client} @clients]
^{:key id } ^{:key id }
[:a {:class "navbar-item" [:a {:class "navbar-item"
:on-click (fn [] (re-frame/dispatch [::events/swap-company company])) :on-click (fn [] (re-frame/dispatch [::events/swap-client client]))
} name])]]]] } name])]]]]
[:div {:class "navbar-burger burger", :data-target "navMenu"} [:div {:class "navbar-burger burger", :data-target "navMenu"}
[:span] [:span]
@@ -226,7 +226,7 @@
[:span {:class "compose"} "New Vendor"]]]]] [:span {:class "compose"} "New Vendor"]]]]]
[:div {:class "column messages hero is-fullheight", :id "message-feed"} [:div {:class "column messages hero is-fullheight", :id "message-feed"}
^{:key (str "active-page-" (:name @company))} ^{:key (str "active-page-" (:name @client))}
[:div.inbox-messages [:div.inbox-messages
[pages/active-page ap]]]] [pages/active-page ap]]]]
[:footer {:class "footer"} [:footer {:class "footer"}

View File

@@ -9,7 +9,7 @@
[auto-ap.views.pages.admin :refer [admin-page]] [auto-ap.views.pages.admin :refer [admin-page]]
[auto-ap.views.pages.needs-activation :refer [needs-activation-page]] [auto-ap.views.pages.needs-activation :refer [needs-activation-page]]
[auto-ap.views.pages.check :refer [check-page]] [auto-ap.views.pages.check :refer [check-page]]
[auto-ap.views.pages.admin.companies :refer [admin-companies-page]] [auto-ap.views.pages.admin.clients :refer [admin-clients-page]]
[auto-ap.views.pages.admin.yodlee :refer [admin-yodlee-page]] [auto-ap.views.pages.admin.yodlee :refer [admin-yodlee-page]]
[auto-ap.views.pages.admin.users :refer [admin-users-page]] [auto-ap.views.pages.admin.users :refer [admin-users-page]]
[auto-ap.views.pages.admin.vendors :refer [admin-vendors-page]] [auto-ap.views.pages.admin.vendors :refer [admin-vendors-page]]
@@ -46,8 +46,8 @@
(defmethod active-page :check [] (defmethod active-page :check []
[check-page]) [check-page])
(defmethod active-page :admin-companies [] (defmethod active-page :admin-clients []
[admin-companies-page]) [admin-clients-page])
(defmethod active-page :admin-vendors [] (defmethod active-page :admin-vendors []
[admin-vendors-page]) [admin-vendors-page])

View File

@@ -1,10 +1,10 @@
(ns auto-ap.views.pages.admin.companies (ns auto-ap.views.pages.admin.clients
(:require-macros [cljs.core.async.macros :refer [go]]) (:require-macros [cljs.core.async.macros :refer [go]])
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[reagent.core :as reagent] [reagent.core :as reagent]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.events :as events] [auto-ap.events :as events]
[auto-ap.entities.companies :as entity] [auto-ap.entities.clients :as entity]
[auto-ap.views.components.address :refer [address-field]] [auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.utils :refer [login-url dispatch-event dispatch-value-change bind-field horizontal-field]] [auto-ap.views.utils :refer [login-url dispatch-event dispatch-value-change bind-field horizontal-field]]
[auto-ap.views.components.modal :refer [action-modal]] [auto-ap.views.components.modal :refer [action-modal]]
@@ -14,105 +14,105 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
::edit ::edit
(fn [{:keys [db]} [_ company-id]] (fn [{:keys [db]} [_ client-id]]
{:dispatch [::events/modal-status :auto-ap.views.pages.admin.companies/edit {:visible? true}] {:dispatch [::events/modal-status :auto-ap.views.pages.admin.clients/edit {:visible? true}]
:db (assoc-in db [:admin :company] :db (assoc-in db [:admin :client]
(get (:companies db) company-id))})) (get (:clients db) client-id))}))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::save ::save
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
(let [edited-company (-> (get-in db [:admin :company]) (let [edited-client (-> (get-in db [:admin :client])
(dissoc :location) (dissoc :location)
(dissoc :new-account))] (dissoc :new-account))]
{:db (assoc-in db [:admin :company :saving?] true) {:db (assoc-in db [:admin :client :saving?] true)
:http {:method :put :http {:method :put
:token (:user db) :token (:user db)
:body (pr-str edited-company) :body (pr-str edited-client)
:headers {"Content-Type" "application/edn"} :headers {"Content-Type" "application/edn"}
:uri (str "/api/companies/" (:id edited-company)) :uri (str "/api/clients/" (:id edited-client))
:on-success [::save-complete] :on-success [::save-complete]
:on-error [::save-error]}}))) :on-error [::save-error]}})))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::save-complete ::save-complete
(fn [{:keys [db]} [_ company]] (fn [{:keys [db]} [_ client]]
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.companies/edit] {:dispatch [::events/modal-completed :auto-ap.views.pages.admin.clients/edit]
:db (-> db :db (-> db
(assoc-in [:admin :company] nil) (assoc-in [:admin :client] nil)
(assoc-in [:companies (:id company)] company))})) (assoc-in [:clients (:id client)] client))}))
(re-frame/reg-event-db (re-frame/reg-event-db
::save-error ::save-error
(fn [db [_ company]] (fn [db [_ client]]
(-> db (-> db
(assoc-in [:admin :company :saving?] false) (assoc-in [:admin :client :saving?] false)
(assoc-in [:admin :company :error] true)))) (assoc-in [:admin :client :error] true))))
(re-frame/reg-event-db (re-frame/reg-event-db
::change ::change
(fn [db [_ path value]] (fn [db [_ path value]]
(assoc-in db (concat [:admin :company] path) (assoc-in db (concat [:admin :client] path)
value))) value)))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::add-location ::add-location
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
(let [company (:company @(re-frame/subscribe [::subs/admin]))] (let [client (:client @(re-frame/subscribe [::subs/admin]))]
{:db (-> db {:db (-> db
(update-in [:admin :company :locations] conj (:location company)) (update-in [:admin :client :locations] conj (:location client))
(update-in [:admin :company] dissoc :location))}))) (update-in [:admin :client] dissoc :location))})))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::add-new-bank-account ::add-new-bank-account
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
(let [company (:company @(re-frame/subscribe [::subs/admin])) (let [client (:client @(re-frame/subscribe [::subs/admin]))
new-bank-account (:new-account company) new-bank-account (:new-account client)
new-bank-account (-> new-bank-account new-bank-account (-> new-bank-account
(update :check-number #(if (seq %) (js/parseInt %) nil)) (update :check-number #(if (seq %) (js/parseInt %) nil))
(update :yodlee-account-id #(if (seq %) (js/parseInt %) nil)) (update :yodlee-account-id #(if (seq %) (js/parseInt %) nil))
(assoc :is-new? true))] (assoc :is-new? true))]
{:db (-> db {:db (-> db
(update-in [:admin :company :new-bank-accounts] (fn [bank-accounts] (update-in [:admin :client :new-bank-accounts] (fn [bank-accounts]
(conj bank-accounts new-bank-account))) (conj bank-accounts new-bank-account)))
(update-in [:admin :company] dissoc :new-account))}))) (update-in [:admin :client] dissoc :new-account))})))
(re-frame/reg-event-db (re-frame/reg-event-db
::remove-new-bank-account ::remove-new-bank-account
(fn [db [_ index]] (fn [db [_ index]]
(update-in db [:admin :company :new-bank-accounts] (update-in db [:admin :client :new-bank-accounts]
(fn [bas] (fn [bas]
(vec (concat (take index bas) (vec (concat (take index bas)
(drop (inc index) bas))))))) (drop (inc index) bas)))))))
(defn companies-table [] (defn clients-table []
(let [companies (re-frame/subscribe [::subs/companies]) (let [clients (re-frame/subscribe [::subs/clients])
editing-company (:company @(re-frame/subscribe [::subs/admin]))] editing-client (:client @(re-frame/subscribe [::subs/admin]))]
[:table {:class "table", :style {:width "100%"}} [:table {:class "table", :style {:width "100%"}}
[:thead [:thead
[:tr [:tr
[:th "Name"] [:th "Name"]
[:th "Email"]]] [:th "Email"]]]
[:tbody (for [{:keys [id name email] :as c} @companies] [:tbody (for [{:keys [id name email] :as c} @clients]
^{:key (str name "-" id )} ^{:key (str name "-" id )}
[:tr {:on-click (fn [] (re-frame/dispatch [::edit id])) [:tr {:on-click (fn [] (re-frame/dispatch [::edit id]))
:style {"cursor" "pointer"}} :style {"cursor" "pointer"}}
[:td name] [:td name]
[:td email]])]])) [:td email]])]]))
(defn admin-companies-page [] (defn admin-clients-page []
[:div [:div
(let [companies (re-frame/subscribe [::subs/companies]) (let [clients (re-frame/subscribe [::subs/clients])
editing-company (:company @(re-frame/subscribe [::subs/admin]))] editing-client (:client @(re-frame/subscribe [::subs/admin]))]
[:div [:div
[:h1.title "Companies"] [:h1.title "Clients"]
[companies-table] [clients-table]
[action-modal {:id ::edit [action-modal {:id ::edit
:title (str "Edit " (:name editing-company)) :title (str "Edit " (:name editing-client))
:action-text "Save" :action-text "Save"
:save-event [::save]} :save-event [::save]}
[horizontal-field [horizontal-field
@@ -123,7 +123,7 @@
:field :name :field :name
:spec ::entity/name :spec ::entity/name
:event ::change :event ::change
:subscription editing-company}]]]] :subscription editing-client}]]]]
[horizontal-field [horizontal-field
[:label.label "Email"] [:label.label "Email"]
@@ -133,7 +133,7 @@
:field :email :field :email
:spec ::entity/name :spec ::entity/name
:event ::change :event ::change
:subscription editing-company}]]]] :subscription editing-client}]]]]
[horizontal-field [horizontal-field
[:label.label "Locations"] [:label.label "Locations"]
@@ -144,16 +144,16 @@
[:input.input {:type "text" [:input.input {:type "text"
:field :location :field :location
:event ::change :event ::change
:subscription editing-company}]]] :subscription editing-client}]]]
[:p.control [:button.button.is-primary {:on-click (dispatch-event [::add-location])} "Add"]]] [:p.control [:button.button.is-primary {:on-click (dispatch-event [::add-location])} "Add"]]]
[:ul [:ul
(for [location (:locations editing-company)] (for [location (:locations editing-client)]
^{:key location} [:li location ])]]] ^{:key location} [:li location ])]]]
[:h2.subtitle "Address"] [:h2.subtitle "Address"]
[address-field {:field [:address] [address-field {:field [:address]
:event ::change :event ::change
:subscription editing-company}] :subscription editing-client}]
[:h2.subtitle "Add account"] [:h2.subtitle "Add account"]
[horizontal-field [horizontal-field
@@ -165,7 +165,7 @@
:type "text" :type "text"
:field [:new-account :bank-name] :field [:new-account :bank-name]
:event ::change :event ::change
:subscription editing-company}]]] :subscription editing-client}]]]
[:div.control [:div.control
[bind-field [bind-field
@@ -173,7 +173,7 @@
:type "text" :type "text"
:field [:new-account :routing] :field [:new-account :routing]
:event ::change :event ::change
:subscription editing-company}]]] :subscription editing-client}]]]
[:div.control [:div.control
[bind-field [bind-field
@@ -181,7 +181,7 @@
:type "text" :type "text"
:field [:new-account :bank-code] :field [:new-account :bank-code]
:event ::change :event ::change
:subscription editing-company}]]]] :subscription editing-client}]]]]
[horizontal-field [horizontal-field
[:label.label "Account"] [:label.label "Account"]
[:div.control [:div.control
@@ -190,21 +190,21 @@
:type "text" :type "text"
:field [:new-account :name] :field [:new-account :name]
:event ::change :event ::change
:subscription editing-company}]]] :subscription editing-client}]]]
[:div.control [:div.control
[bind-field [bind-field
[:input.input {:placeholder "Acct #" [:input.input {:placeholder "Acct #"
:type "text" :type "text"
:field [:new-account :number] :field [:new-account :number]
:event ::change :event ::change
:subscription editing-company}]]] :subscription editing-client}]]]
[:div.control [:div.control
[bind-field [bind-field
[:input.input {:placeholder "Check #" [:input.input {:placeholder "Check #"
:type "text" :type "text"
:field [:new-account :check-number] :field [:new-account :check-number]
:event ::change :event ::change
:subscription editing-company}]]]] :subscription editing-client}]]]]
[horizontal-field [horizontal-field
[:label.label "Yodlee Account"] [:label.label "Yodlee Account"]
[:div.control [:div.control
@@ -213,7 +213,7 @@
:type "text" :type "text"
:field [:new-account :yodlee-account-id] :field [:new-account :yodlee-account-id]
:event ::change :event ::change
:subscription editing-company}]]] :subscription editing-client}]]]
[:div.control [:div.control
[:button.button.is-primary.is-pulled-right {:on-click (dispatch-event [::add-new-bank-account])} "Add"]]] [:button.button.is-primary.is-pulled-right {:on-click (dispatch-event [::add-new-bank-account])} "Add"]]]
@@ -225,9 +225,9 @@
[:div.control [:div.control
[:ul [:ul
(for [{:keys [name number check-number id]} (:bank-accounts editing-company)] (for [{:keys [name number check-number id]} (:bank-accounts editing-client)]
^{:key id} [:li name]) ^{:key id} [:li name])
(for [[index {:keys [name number check-number]}] (map vector (range) (:new-bank-accounts editing-company))] (for [[index {:keys [name number check-number]}] (map vector (range) (:new-bank-accounts editing-client))]
^{:key index} [:li [:strong "* " name] [:button.button {:on-click (dispatch-event [::remove-new-bank-account index])} [:span.icon [:i.fa.fa-times]]]])]]] ^{:key index} [:li [:strong "* " name] [:button.button {:on-click (dispatch-event [::remove-new-bank-account index])} [:span.icon [:i.fa.fa-times]]]])]]]
(when (:saving? editing-company) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]])]) (when (:saving? editing-client) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]])])

View File

@@ -4,8 +4,8 @@
[reagent.core :as reagent] [reagent.core :as reagent]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.events :as all-events] [auto-ap.events :as all-events]
[auto-ap.events.admin.companies :as events] [auto-ap.events.admin.clients :as events]
[auto-ap.entities.companies :as entity] [auto-ap.entities.clients :as entity]
[auto-ap.views.components.typeahead :refer [typeahead]] [auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field dispatch-event]] [auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field dispatch-event]]
@@ -182,17 +182,17 @@
[:thead [:thead
[:th "Date"] [:th "Date"]
[:th "Invoice #"] [:th "Invoice #"]
[:th "Company"] [:th "Client"]
[:th "Vendor"] [:th "Vendor"]
[:th "Amount"] [:th "Amount"]
[:th "Errors"]] [:th "Errors"]]
(for [{:keys [raw-date invoice-number company vendor-name amount] row-errors :errors} (take 100 errors)] (for [{:keys [raw-date invoice-number client vendor-name amount] row-errors :errors} (take 100 errors)]
^{:key (str raw-date invoice-number company vendor-name amount)} ^{:key (str raw-date invoice-number client vendor-name amount)}
[:tr [:tr
[:td raw-date] [:td raw-date]
[:td invoice-number] [:td invoice-number]
[:td company] [:td client]
[:td vendor-name] [:td vendor-name]
[:td amount] [:td amount]
[:td (map (fn [{:keys [info]}] ^{:key info} [:p info]) row-errors)]])]])])]) [:td (map (fn [{:keys [info]}] ^{:key info} [:p info]) row-errors)]])]])])])

View File

@@ -5,7 +5,7 @@
[clojure.string :as str] [clojure.string :as str]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.events :as events] [auto-ap.events :as events]
[auto-ap.entities.companies :as entity] [auto-ap.entities.clients :as entity]
[auto-ap.views.components.address :refer [address-field]] [auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field dispatch-event]] [auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field dispatch-event]]
[auto-ap.views.components.modal :refer [modal action-modal]] [auto-ap.views.components.modal :refer [modal action-modal]]
@@ -55,14 +55,14 @@
(dissoc db ::editing)))) (dissoc db ::editing))))
(re-frame/reg-event-db (re-frame/reg-event-db
::add-company ::add-client
(fn [db [_ d]] (fn [db [_ d]]
(let [company (get @(re-frame/subscribe [::subs/companies-by-id]) (let [client (get @(re-frame/subscribe [::subs/clients-by-id])
(get-in db [::editing :adding-company]))] (get-in db [::editing :adding-client]))]
(update-in db [::editing :user :clients] conj company)))) (update-in db [::editing :user :clients] conj client))))
(re-frame/reg-event-db (re-frame/reg-event-db
::remove-company ::remove-client
(fn [db [_ d]] (fn [db [_ d]]
(update-in db [::editing :user :clients] #(filter (fn [c] (not= (:id c) d)) %)))) (update-in db [::editing :user :clients] #(filter (fn [c] (not= (:id c) d)) %))))
@@ -116,7 +116,7 @@
(with-meta (with-meta
(fn [] (fn []
[:div [:div
(let [companies (re-frame/subscribe [::users]) (let [clients (re-frame/subscribe [::users])
editing @(re-frame/subscribe [::editing])] editing @(re-frame/subscribe [::editing])]
[:div [:div
[:h1.title "Users"] [:h1.title "Users"]
@@ -160,20 +160,20 @@
[:div.select [:div.select
[bind-field [bind-field
[:select {:type "select" [:select {:type "select"
:field [:adding-company] :field [:adding-client]
:event ::change :event ::change
:subscription editing} :subscription editing}
[:option] [:option]
(let [used-companies (set (map :id (:clients (:user editing))))] (let [used-clients (set (map :id (:clients (:user editing))))]
(for [{:keys [id name]} @(re-frame/subscribe [::subs/companies]) (for [{:keys [id name]} @(re-frame/subscribe [::subs/clients])
:when (not (used-companies id))] :when (not (used-clients id))]
^{:key id} [:option {:value id} name]))]]]] ^{:key id} [:option {:value id} name]))]]]]
[:p.control [:p.control
[:button.button.is-primary {:on-click (dispatch-event [::add-company])} "Add"]]] [:button.button.is-primary {:on-click (dispatch-event [::add-client])} "Add"]]]
[:ul [:ul
(for [{:keys [id name]} (:clients (:user editing))] (for [{:keys [id name]} (:clients (:user editing))]
^{:key id} [:li name [:a.icon {:on-click (dispatch-event [::remove-company id])} [:i.fa.fa-times ]]])]]])]])]) ^{:key id} [:li name [:a.icon {:on-click (dispatch-event [::remove-client id])} [:i.fa.fa-times ]]])]]])]])])
{:component-will-mount #(re-frame/dispatch-sync [::users-mounted {}]) })) {:component-will-mount #(re-frame/dispatch-sync [::users-mounted {}]) }))

View File

@@ -4,8 +4,8 @@
[reagent.core :as reagent] [reagent.core :as reagent]
[clojure.string :as str] [clojure.string :as str]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.events.admin.companies :as events] [auto-ap.events.admin.clients :as events]
[auto-ap.entities.companies :as entity] [auto-ap.entities.clients :as entity]
[auto-ap.views.components.address :refer [address-field]] [auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.utils :refer [login-url dispatch-event dispatch-value-change bind-field horizontal-field]] [auto-ap.views.utils :refer [login-url dispatch-event dispatch-value-change bind-field horizontal-field]]
[auto-ap.views.components.modal :refer [action-modal]] [auto-ap.views.components.modal :refer [action-modal]]

View File

@@ -18,13 +18,13 @@
(defn check-page [] (defn check-page []
(let [checks @(re-frame/subscribe [::checks])] (let [checks @(re-frame/subscribe [::checks])]
[:div [:div
(for [{:keys [vendor-name paid-to company check date amount memo]} checks (for [{:keys [vendor-name paid-to client check date amount memo]} checks
:let [amount (gstring/format "--%.2f--" amount)]] :let [amount (gstring/format "--%.2f--" amount)]]
[:div [:div
[:div.columns [:div.columns
(let [{:keys [name address1 city state zip bank]} company] (let [{:keys [name address1 city state zip bank]} client]
(list (list
[:div.column.is-4 [:div.column.is-4
[:p name] [:p name]
@@ -76,7 +76,7 @@
[:div.columns [:div.columns
[:div.column.is-2 ] [:div.column.is-2 ]
[:div.column.is-10 {:style {"font-family" "MICR" "font-size" "20pt"}} [:div.column.is-10 {:style {"font-family" "MICR" "font-size" "20pt"}}
(str "c" check "c a" (:acct-number (:bank company)) "a 10302c")]] (str "c" check "c a" (:acct-number (:bank client)) "a 10302c")]]
[:div.columns [:div.columns
@@ -94,7 +94,7 @@
[:div.columns [:div.columns
[:div.column] [:div.column]
[:div.column.is-10 [:div.column.is-10
(let [{:keys [name address1 city state zip bank]} company] (let [{:keys [name address1 city state zip bank]} client]
(list (list
[:p name] [:p name]
[:p address1] [:p address1]
@@ -154,7 +154,7 @@
[:div.column.is-5 [:div.column.is-5
[:p check] [:p check]
[:p vendor-name] [:p vendor-name]
[:p (:name (:bank company))] [:p (:name (:bank client))]
[:p paid-to] [:p paid-to]
[:p amount] [:p amount]
[:p date]]] [:p date]]]

View File

@@ -1,6 +1,6 @@
(ns auto-ap.views.pages.checks (ns auto-ap.views.pages.checks
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[auto-ap.entities.companies :as company] [auto-ap.entities.clients :as client]
[auto-ap.entities.vendors :as vendor] [auto-ap.entities.vendors :as vendor]
[reagent.core :as reagent] [reagent.core :as reagent]
[goog.string :as gstring] [goog.string :as gstring]
@@ -35,7 +35,7 @@
(assoc-in [::params] params)) (assoc-in [::params] params))
:graphql {:token (-> cofx :db :user) :graphql {:token (-> cofx :db :user)
:query-obj {:venia/queries [[:payment_page :query-obj {:venia/queries [[:payment_page
(assoc params :client-id (:id @(re-frame/subscribe [::subs/company]))) (assoc params :client-id (:id @(re-frame/subscribe [::subs/client])))
[[:payments [:id :status :amount :type :check_number :s3_url :date [:vendor [:name :id]] [:client [:name :id]]]] [[:payments [:id :status :amount :type :check_number :s3_url :date [:vendor [:name :id]] [:client [:name :id]]]]
:total :total
:start :start
@@ -80,15 +80,15 @@
(defn check-table [{:keys [id payment-page status on-params-change vendors params check-boxes checked on-check-changed expense-event]}] (defn check-table [{:keys [id payment-page status on-params-change vendors params check-boxes checked on-check-changed expense-event]}]
(let [state (reagent/atom (or @params {})) (let [state (reagent/atom (or @params {}))
selected-company @(re-frame/subscribe [::subs/company]) selected-client @(re-frame/subscribe [::subs/client])
opc (fn [p] opc (fn [p]
(swap! state merge p) (swap! state merge p)
(on-params-change p))] (on-params-change p))]
(fn [{:keys [id payment-page status on-params-change vendors checked]}] (fn [{:keys [id payment-page status on-params-change vendors checked]}]
(let [{:keys [sort-by asc]} @state (let [{:keys [sort-by asc]} @state
{:keys [payments start end count total]} @payment-page {:keys [payments start end count total]} @payment-page
selected-company @(re-frame/subscribe [::subs/company]) selected-client @(re-frame/subscribe [::subs/client])
percentage-size (if selected-company "50%" "33%")] percentage-size (if selected-client "50%" "33%")]
[:div [:div
[paginator {:start start :end end :count count :total total [paginator {:start start :end end :count count :total total
:on-change (fn [p ] :on-change (fn [p ]
@@ -100,7 +100,7 @@
[:tr [:tr
(when-not selected-company (when-not selected-client
[sorted-column {:on-sort opc [sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"} :style {:width percentage-size :cursor "pointer"}
:sort-key "client" :sort-key "client"
@@ -151,7 +151,7 @@
^{:key id} ^{:key id}
[:tr {:class (:class i)} [:tr {:class (:class i)}
(when-not selected-company (when-not selected-client
[:td (:name client)]) [:td (:name client)])
[:td (:name vendor)] [:td (:name vendor)]
[:td (cond [:td (cond
@@ -176,7 +176,7 @@
(with-meta (with-meta
(fn [] (fn []
(let [current-company @(re-frame/subscribe [::subs/company])] (let [current-client @(re-frame/subscribe [::subs/client])]
[:div [:div
[:h1.title "Checks"] [:h1.title "Checks"]
[check-table {:id :payments [check-table {:id :payments

View File

@@ -3,13 +3,13 @@
[reagent.core :as reagent] [reagent.core :as reagent]
[auto-ap.events :as events] [auto-ap.events :as events]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.entities.companies :as company] [auto-ap.entities.clients :as client]
[auto-ap.entities.vendors :as vendor] [auto-ap.entities.vendors :as vendor]
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table] [auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
[cljsjs.dropzone :as dropzone] [cljsjs.dropzone :as dropzone]
[cljs.reader :as edn])) [cljs.reader :as edn]))
(def dropzone (def dropzone
(let [company (re-frame/subscribe [::subs/company]) (let [client (re-frame/subscribe [::subs/client])
token (re-frame/subscribe [::subs/token])] token (re-frame/subscribe [::subs/token])]
(with-meta (with-meta
(fn [] (fn []
@@ -28,8 +28,8 @@
:paramName "file" :paramName "file"
:headers {"Authorization" (str "Token " @token)} :headers {"Authorization" (str "Token " @token)}
:url (str "/api/invoices/upload" :url (str "/api/invoices/upload"
(when-let [company-name (-> @company :id)] (when-let [client-name (-> @client :id)]
(str "?company=" company-name))) (str "?client=" client-name)))
:previewsContainer "#dz-hidden" :previewsContainer "#dz-hidden"
:previewTemplate "<div class='dz-hidden-preview'></div>"})))}))) :previewTemplate "<div class='dz-hidden-preview'></div>"})))})))
@@ -72,8 +72,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-id (:id @(re-frame/subscribe [::subs/company]))] (when-let [client-id (:id @(re-frame/subscribe [::subs/client]))]
(str "?company=" company-id))) (str "?client=" client-id)))
:on-success on-success :on-success on-success
}})) }}))
@@ -83,8 +83,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-id (:id @(re-frame/subscribe [::subs/company]))] (when-let [client-id (:id @(re-frame/subscribe [::subs/client]))]
(str "?company=" company-id))) (str "?client=" client-id)))
:on-success on-success :on-success on-success
}})) }}))

View File

@@ -24,10 +24,10 @@
[:div.control [:div.control
[:input.input {:type "text" [:input.input {:type "text"
:placeholder "Brown Chicken Brown Cow" :placeholder "Brown Chicken Brown Cow"
:value (:company @form-data) :value (:client @form-data)
:on-change (fn [e] :on-change (fn [e]
(re-frame/dispatch [::events/change-form-state (re-frame/dispatch [::events/change-form-state
[:new-invoice :company] [:new-invoice :client]
(.. e -target -value)]))}]]] (.. e -target -value)]))}]]]
[:div.field [:div.field
[:label.label "Invoice #"] [:label.label "Invoice #"]
@@ -61,7 +61,7 @@
(.. e -target -value)]))}]]] (.. e -target -value)]))}]]]
[:div.control [:div.control
[:submit.button.is-large.is-primary { [:submit.button.is-large.is-primary {
:disabled (if (and (:total @form-data) (:date @form-data) (:company @form-data) (:invoice-number @form-data) :disabled (if (and (:total @form-data) (:date @form-data) (:client @form-data) (:invoice-number @form-data)
(:vendor @form-data)) (:vendor @form-data))
"" ""
"disabled") "disabled")

View File

@@ -1,6 +1,6 @@
(ns auto-ap.views.pages.paid-invoices (ns auto-ap.views.pages.paid-invoices
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[auto-ap.entities.companies :as company] [auto-ap.entities.clients :as client]
[auto-ap.entities.vendors :as vendor] [auto-ap.entities.vendors :as vendor]
[auto-ap.events :as events] [auto-ap.events :as events]
[auto-ap.views.utils :refer [dispatch-event]] [auto-ap.views.utils :refer [dispatch-event]]
@@ -63,7 +63,7 @@
(with-meta (with-meta
(fn [] (fn []
(let [current-company @(re-frame/subscribe [::subs/company])] (let [current-client @(re-frame/subscribe [::subs/client])]
[:div [:div
[:h1.title "Paid invoices"] [:h1.title "Paid invoices"]

View File

@@ -1,6 +1,6 @@
(ns auto-ap.views.pages.transactions (ns auto-ap.views.pages.transactions
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[auto-ap.entities.companies :as company] [auto-ap.entities.clients :as client]
[auto-ap.entities.vendors :as vendor] [auto-ap.entities.vendors :as vendor]
[reagent.core :as reagent] [reagent.core :as reagent]
[goog.string :as gstring] [goog.string :as gstring]
@@ -33,7 +33,7 @@
(assoc-in [::params] params)) (assoc-in [::params] params))
:graphql {:token (-> cofx :db :user) :graphql {:token (-> cofx :db :user)
:query-obj {:venia/queries [[:transaction_page :query-obj {:venia/queries [[:transaction_page
(assoc params :client-id (:id @(re-frame/subscribe [::subs/company]))) (assoc params :client-id (:id @(re-frame/subscribe [::subs/client])))
[[:transactions [:id [[:transactions [:id
:amount :amount
:date :date
@@ -68,8 +68,8 @@
(fn [{:keys [id transaction-page status on-params-change vendors checked]}] (fn [{:keys [id transaction-page status on-params-change vendors checked]}]
(let [{:keys [sort-by asc]} @state (let [{:keys [sort-by asc]} @state
{:keys [transactions start end count total]} @transaction-page {:keys [transactions start end count total]} @transaction-page
selected-company @(re-frame/subscribe [::subs/company]) selected-client @(re-frame/subscribe [::subs/client])
percentage-size (if selected-company "25%" "33%")] percentage-size (if selected-client "25%" "33%")]
[:div [:div
[paginator {:start start :end end :count count :total total [paginator {:start start :end end :count count :total total
:on-change (fn [p ] :on-change (fn [p ]
@@ -79,7 +79,7 @@
[:table.table.is-fullwidth [:table.table.is-fullwidth
[:thead [:thead
[:tr [:tr
(when-not selected-company (when-not selected-client
[sorted-column {:on-sort opc [sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"} :style {:width percentage-size :cursor "pointer"}
:sort-key "client" :sort-key "client"
@@ -126,7 +126,7 @@
^{:key id} ^{:key id}
[:tr {:class (:class i)} [:tr {:class (:class i)}
(when-not selected-company (when-not selected-client
[:td (:name client)]) [:td (:name client)])
[:td description-original] [:td description-original]
[:td (date->str date) ] [:td (date->str date) ]
@@ -145,7 +145,7 @@
::manual-yodlee-import ::manual-yodlee-import
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
{:dispatch [::events/modal-status ::manual-yodlee-import {:visible? true}] {:dispatch [::events/modal-status ::manual-yodlee-import {:visible? true}]
:db (assoc-in db [::manual-yodlee-import] {:company-id (:id @(re-frame/subscribe [::subs/company])) :db (assoc-in db [::manual-yodlee-import] {:client-id (:id @(re-frame/subscribe [::subs/client]))
:data ""})})) :data ""})}))
(re-frame/reg-sub (re-frame/reg-sub
@@ -201,7 +201,7 @@
(with-meta (with-meta
(fn [] (fn []
(let [notification (re-frame/subscribe [::notification]) (let [notification (re-frame/subscribe [::notification])
current-company @(re-frame/subscribe [::subs/company]) current-client @(re-frame/subscribe [::subs/client])
user @(re-frame/subscribe [::subs/user])] user @(re-frame/subscribe [::subs/user])]
[:div [:div

View File

@@ -5,7 +5,7 @@
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[cljs-time.core :as c] [cljs-time.core :as c]
[goog.string :as gstring] [goog.string :as gstring]
[auto-ap.entities.companies :as company] [auto-ap.entities.clients :as client]
[auto-ap.entities.invoice :as invoice] [auto-ap.entities.invoice :as invoice]
[auto-ap.entities.vendors :as vendor] [auto-ap.entities.vendors :as vendor]
[auto-ap.views.components.expense-accounts-dialog :as expense-accounts-dialog] [auto-ap.views.components.expense-accounts-dialog :as expense-accounts-dialog]
@@ -105,7 +105,7 @@
(-> db (-> db
(update-in [::invoice-page :print-checks-shown?] #(not %) ) (update-in [::invoice-page :print-checks-shown?] #(not %) )
(assoc-in [::advanced-print-checks] {:shown? true (assoc-in [::advanced-print-checks] {:shown? true
:bank-account-id (:id (first (:bank-accounts @(re-frame/subscribe [::subs/company])))) :bank-account-id (:id (first (:bank-accounts @(re-frame/subscribe [::subs/clients]))))
:invoices (->> invoices :invoices (->> invoices
(filter (comp checked :id)) (filter (comp checked :id))
(map #(assoc % :amount (:outstanding-balance %))))} ))))) (map #(assoc % :amount (:outstanding-balance %))))} )))))
@@ -122,7 +122,7 @@
{:dispatch [::events/modal-status ::handwrite-checks {:visible? true}] {:dispatch [::events/modal-status ::handwrite-checks {:visible? true}]
:db (-> db :db (-> db
(update-in [::invoice-page :print-checks-shown?] #(not %) ) (update-in [::invoice-page :print-checks-shown?] #(not %) )
(assoc-in [::handwrite-checks] {:bank-account-id (:id (first (:bank-accounts @(re-frame/subscribe [::subs/company])))) (assoc-in [::handwrite-checks] {:bank-account-id (:id (first (:bank-accounts @(re-frame/subscribe [::subs/client]))))
:amount (:outstanding-balance invoice) :amount (:outstanding-balance invoice)
:invoice invoice } ))}))) :invoice invoice } ))})))
@@ -181,7 +181,7 @@
(get-in db [::invoice-page :checked])) (get-in db [::invoice-page :checked]))
bank-account-id bank-account-id
type type
(:company db)) (:client db))
:on-success [::checks-created]}}))) :on-success [::checks-created]}})))
@@ -191,7 +191,7 @@
(fn [{:keys [db]} [_ bank-account-id]] (fn [{:keys [db]} [_ bank-account-id]]
(let [invoice-amounts (by :id (comp js/parseFloat :amount) (get-in db [::advanced-print-checks :invoices])) (let [invoice-amounts (by :id (comp js/parseFloat :amount) (get-in db [::advanced-print-checks :invoices]))
bank-account-id (get-in db [::advanced-print-checks :bank-account-id]) bank-account-id (get-in db [::advanced-print-checks :bank-account-id])
type (->> @(re-frame/subscribe [::subs/company]) type (->> @(re-frame/subscribe [::subs/client])
:bank-accounts :bank-accounts
(filter #(= bank-account-id (:id %))) (filter #(= bank-account-id (:id %)))
first first
@@ -213,7 +213,7 @@
:else :else
:check) :check)
(:company db)) (:client db))
:on-success [::checks-created]}}))) :on-success [::checks-created]}})))
@@ -246,9 +246,9 @@
::new-invoice ::new-invoice
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
{:dispatch [::events/modal-status ::new-invoice {:visible? true}] {:dispatch [::events/modal-status ::new-invoice {:visible? true}]
:db (assoc-in db [::new-invoice] {:client-id (:id @(re-frame/subscribe [::subs/company])) :db (assoc-in db [::new-invoice] {:client-id (:id @(re-frame/subscribe [::subs/client]))
:date (date->str (c/now) standard) :date (date->str (c/now) standard)
:location (first (:locations @(re-frame/subscribe [::subs/company])))})})) :location (first (:locations @(re-frame/subscribe [::subs/client])))})}))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::edit-invoice ::edit-invoice
@@ -414,7 +414,7 @@
(defn print-checks-modal [] (defn print-checks-modal []
(let [{:keys [checked]} @(re-frame/subscribe [::invoice-page]) (let [{:keys [checked]} @(re-frame/subscribe [::invoice-page])
{:keys [shown? invoices printing?] :as advanced-print-checks} @(re-frame/subscribe [::advanced-print-checks]) {:keys [shown? invoices printing?] :as advanced-print-checks} @(re-frame/subscribe [::advanced-print-checks])
current-company @(re-frame/subscribe [::subs/company])] current-client @(re-frame/subscribe [::subs/client])]
(when shown? (when shown?
[modal {:title "Print Checks" [modal {:title "Print Checks"
@@ -439,7 +439,7 @@
:field :bank-account-id :field :bank-account-id
:event ::edit-payment-bank-account :event ::edit-payment-bank-account
:subscription advanced-print-checks} :subscription advanced-print-checks}
(for [{:keys [id number name]} (:bank-accounts current-company)] (for [{:keys [id number name]} (:bank-accounts current-client)]
^{:key id} [:option {:value id} name])]]]] ^{:key id} [:option {:value id} name])]]]]
[:table.table.is-fullwidth [:table.table.is-fullwidth
@@ -471,7 +471,7 @@
(let [{:keys [checked]} @(re-frame/subscribe [::invoice-page]) (let [{:keys [checked]} @(re-frame/subscribe [::invoice-page])
{:keys [invoice] :as handwrite-checks} @(re-frame/subscribe [::handwrite-checks]) {:keys [invoice] :as handwrite-checks} @(re-frame/subscribe [::handwrite-checks])
change-event [::events/change-form [::handwrite-checks]] change-event [::events/change-form [::handwrite-checks]]
current-company @(re-frame/subscribe [::subs/company])] current-client @(re-frame/subscribe [::subs/client])]
[action-modal {:id ::handwrite-checks [action-modal {:id ::handwrite-checks
:title "Handwrite Check" :title "Handwrite Check"
@@ -486,7 +486,7 @@
:field :bank-account-id :field :bank-account-id
:event change-event :event change-event
:subscription handwrite-checks} :subscription handwrite-checks}
(for [{:keys [id number name]} (:bank-accounts current-company)] (for [{:keys [id number name]} (:bank-accounts current-client)]
^{:key id} [:option {:value id} name])]]]] ^{:key id} [:option {:value id} name])]]]]
[horizontal-field [horizontal-field
@@ -521,9 +521,9 @@
:subscription handwrite-checks}]]]])) :subscription handwrite-checks}]]]]))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::change-new-invoice-company ::change-new-invoice-client
(fn [{:keys [db ]} [_ location field value]] (fn [{:keys [db ]} [_ location field value]]
(let [first-location (-> @(re-frame/subscribe [::subs/companies-by-id]) (let [first-location (-> @(re-frame/subscribe [::subs/clients-by-id])
(get-in [value :locations]) (get-in [value :locations])
first)] first)]
{:dispatch [::events/change-form location field value] {:dispatch [::events/change-form location field value]
@@ -533,7 +533,7 @@
(defn new-invoice-modal [] (defn new-invoice-modal []
(let [data @(re-frame/subscribe [::new-invoice]) (let [data @(re-frame/subscribe [::new-invoice])
change-event [::events/change-form [::new-invoice]] change-event [::events/change-form [::new-invoice]]
locations (get-in @(re-frame/subscribe [::subs/companies-by-id]) [(:client-id data) :locations]) locations (get-in @(re-frame/subscribe [::subs/clients-by-id]) [(:client-id data) :locations])
should-select-location? (and locations should-select-location? (and locations
(> (count locations) 1))] (> (count locations) 1))]
[action-modal {:id ::new-invoice [action-modal {:id ::new-invoice
@@ -542,14 +542,14 @@
:save-event [::create-invoice] :save-event [::create-invoice]
:can-submit? (s/valid? ::invoice/invoice data)} :can-submit? (s/valid? ::invoice/invoice data)}
(when-not @(re-frame/subscribe [::subs/company]) (when-not @(re-frame/subscribe [::subs/client])
[horizontal-field [horizontal-field
[:label.label "Client"] [:label.label "Client"]
[bind-field [bind-field
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/companies])) [typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/clients]))
:type "typeahead" :type "typeahead"
:field [:client-id] :field [:client-id]
:event [::change-new-invoice-company [::new-invoice]] :event [::change-new-invoice-client [::new-invoice]]
:spec ::invoice/client-id :spec ::invoice/client-id
:subscription data}]]]) :subscription data}]]])
(when should-select-location? (when should-select-location?
@@ -614,7 +614,7 @@
(defn edit-invoice-modal [] (defn edit-invoice-modal []
(let [data @(re-frame/subscribe [::edit-invoice]) (let [data @(re-frame/subscribe [::edit-invoice])
change-event [::events/change-form [::edit-invoice]] change-event [::events/change-form [::edit-invoice]]
locations (get-in @(re-frame/subscribe [::subs/companies-by-id]) [(:company-id data) :locations]) locations (get-in @(re-frame/subscribe [::subs/clients-by-id]) [(:client-id data) :locations])
min-total (- (:total (:original data)) (:outstanding-balance (:original data))) min-total (- (:total (:original data)) (:outstanding-balance (:original data)))
should-select-location? (and locations should-select-location? (and locations
@@ -670,13 +670,13 @@
(with-meta (with-meta
(fn [] (fn []
(let [{:keys [checked print-checks-shown? print-checks-loading? advanced-print-shown?]} @(re-frame/subscribe [::invoice-page]) (let [{:keys [checked print-checks-shown? print-checks-loading? advanced-print-shown?]} @(re-frame/subscribe [::invoice-page])
current-company @(re-frame/subscribe [::subs/company]) current-client @(re-frame/subscribe [::subs/client])
{check-results-shown? :shown? pdf-url :pdf-url} @(re-frame/subscribe [::check-results])] {check-results-shown? :shown? pdf-url :pdf-url} @(re-frame/subscribe [::check-results])]
[:div [:div
[:h1.title "Unpaid invoices"] [:h1.title "Unpaid invoices"]
[:div.is-pulled-right [:div.is-pulled-right
[:button.button.is-danger {:on-click (dispatch-event [::new-invoice])} "New Invoice"] [:button.button.is-danger {:on-click (dispatch-event [::new-invoice])} "New Invoice"]
(when current-company (when current-client
[:div.dropdown.is-right {:class (if print-checks-shown? [:div.dropdown.is-right {:class (if print-checks-shown?
"is-active" "is-active"
"")} "")}
@@ -696,7 +696,7 @@
[:div.dropdown-menu {:role "menu"} [:div.dropdown-menu {:role "menu"}
[:div.dropdown-content [:div.dropdown-content
(list (list
(for [{:keys [id number name type]} (:bank-accounts current-company)] (for [{:keys [id number name type]} (:bank-accounts current-client)]
(if (= :cash type) (if (= :cash type)
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :cash])} "With cash"] ^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :cash])} "With cash"]
(list (list