renamed company to client.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
(ns auto-ap.db.checks
|
||||
(: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.java.jdbc :as j]
|
||||
[honeysql.core :as sql]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(ns auto-ap.db.companies
|
||||
(: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.java.jdbc :as j]
|
||||
[honeysql.core :as sql]
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
[auto-ap.db.companies :as companies]
|
||||
[auto-ap.db.invoices-checks :as invoices-checks]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.entities.companies :as company]
|
||||
[auto-ap.entities.vendors :as vendor]
|
||||
[clojure.java.jdbc :as j]
|
||||
[clojure.string :as str]
|
||||
[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})
|
||||
|
||||
(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.*
|
||||
:from :invoices))
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
(ns auto-ap.db.invoices-checks
|
||||
(: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.java.jdbc :as j]
|
||||
[honeysql.core :as sql]
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
[com.walmartlabs.lacinia.resolve :as resolve]
|
||||
[buddy.auth :refer [throw-unauthorized]]
|
||||
[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.checks :as d-checks]
|
||||
[auto-ap.datomic.users :as d-users]
|
||||
@@ -32,13 +32,6 @@
|
||||
:serialize (schema/as-conformer #(.toString %))}}
|
||||
: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
|
||||
{:fields {:id {:type :id}
|
||||
:name {:type 'String}
|
||||
@@ -96,7 +89,6 @@
|
||||
:type {:type 'String}
|
||||
:amount {:type 'String}
|
||||
:vendor {:type :vendor}
|
||||
:company {:type :company}
|
||||
:date {:type 'String}
|
||||
:bank_account {:type :bank_account}
|
||||
:memo {:type 'String}
|
||||
@@ -168,7 +160,7 @@
|
||||
:status {:type 'String}
|
||||
:expense_accounts {:type '(list :invoices_expense_accounts)}
|
||||
:date {:type 'String}
|
||||
:company_id {:type 'Int}
|
||||
:client_id {:type 'Int}
|
||||
:payments {:type '(list :invoice_payment)}
|
||||
:vendor {:type :vendor}
|
||||
:client {:type :client}}}
|
||||
@@ -241,10 +233,8 @@
|
||||
|
||||
:resolve :get-payment-page}
|
||||
|
||||
:company {:type '(list :company)
|
||||
:resolve :get-company}
|
||||
:client {:type '(list :company)
|
||||
:resolve :get-company}
|
||||
:client {:type '(list :client)
|
||||
:resolve :get-client}
|
||||
:vendor {:type '(list :vendor)
|
||||
:resolve :get-vendor}
|
||||
:user {:type '(list :user)
|
||||
@@ -402,9 +392,9 @@
|
||||
:limit Integer/MAX_VALUE))))
|
||||
|
||||
|
||||
(defn get-company [context args value]
|
||||
(defn get-client [context args value]
|
||||
(->graphql
|
||||
(filter #(can-see-company? (:id context) %)
|
||||
(filter #(can-see-client? (:id context) %)
|
||||
(d-clients/get-all))))
|
||||
|
||||
(defn get-user [context args value]
|
||||
@@ -420,7 +410,7 @@
|
||||
|
||||
(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
|
||||
(gq-checks/print-checks (map (fn [i] {:invoice-id (:invoice_id i)
|
||||
:amount (:amount i)})
|
||||
@@ -439,7 +429,7 @@
|
||||
:get-payment-page gq-checks/get-payment-page
|
||||
:get-transaction-page gq-transactions/get-transaction-page
|
||||
|
||||
:get-company get-company
|
||||
:get-client get-client
|
||||
:get-user get-user
|
||||
:mutation/add-handwritten-check gq-checks/add-handwritten-check
|
||||
:mutation/print-checks print-checks
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(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]
|
||||
[clojure.edn :as edn]
|
||||
[com.walmartlabs.lacinia :refer [execute]]
|
||||
@@ -316,7 +316,7 @@
|
||||
(let [invoice (d-invoices/get-by-id (:invoice_id args))
|
||||
bank-account-id (:bank_account_id args)
|
||||
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)
|
||||
(:invoice/client invoice)
|
||||
bank-account :payment-type/check 0 {(:invoice_id args) (:amount args)})]
|
||||
@@ -339,7 +339,7 @@
|
||||
(let [check (d-checks/get-by-id id)]
|
||||
(assert (or (= :payment-status/pending (:payment/status 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 [invoice (:invoice-payment/invoice x)
|
||||
new-balance (+ (:invoice/outstanding-balance invoice)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(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.invoices :as d-invoices]
|
||||
@@ -34,7 +34,7 @@
|
||||
:invoice/vendor vendor_id
|
||||
:invoice/client client_id}))
|
||||
(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)
|
||||
|
||||
expense-account-id (:vendor/default-expense-account vendor)
|
||||
@@ -59,7 +59,7 @@
|
||||
(->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)
|
||||
@@ -71,7 +71,7 @@
|
||||
println))
|
||||
(throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number})))
|
||||
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
|
||||
:invoice/invoice-number invoice_number
|
||||
:invoice/date (coerce/to-date (parse date iso-date))
|
||||
@@ -82,7 +82,7 @@
|
||||
|
||||
(defn void-invoice [context {id :invoice_id} value]
|
||||
(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
|
||||
:invoice/total 0.0
|
||||
:invoice/outstanding-balance 0.0
|
||||
@@ -98,7 +98,7 @@
|
||||
(defn edit-expense-accounts [context args value]
|
||||
;; 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.
|
||||
(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)))
|
||||
invoice-id (:invoice_id args)
|
||||
|
||||
|
||||
@@ -47,14 +47,14 @@
|
||||
(when-not (= "admin" (:user/role id))
|
||||
(throw-unauthorized)))
|
||||
|
||||
(defn can-see-company? [identity company]
|
||||
(defn can-see-client? [identity client]
|
||||
(or (= "admin" (:user/role identity))
|
||||
((set (map :db/id (:user/clients identity))) (:db/id company))
|
||||
((set (map :db/id (:user/clients identity))) company)))
|
||||
((set (map :db/id (:user/clients identity))) (:db/id client))
|
||||
((set (map :db/id (:user/clients identity))) client)))
|
||||
|
||||
(defn assert-can-see-company [identity company]
|
||||
(when-not (can-see-company? identity company)
|
||||
(println "IDENTITY " identity " can not see company " company)
|
||||
(defn assert-can-see-client [identity client]
|
||||
(when-not (can-see-client? identity client)
|
||||
(println "IDENTITY " identity " can not see company " client)
|
||||
(throw-unauthorized)))
|
||||
|
||||
(defn limited-clients [id]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(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.time :refer [parse iso-date]]
|
||||
[datomic.api :as d]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
(ns auto-ap.handler
|
||||
(:require [amazonica.core :refer [defcredential]]
|
||||
[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.reminders :as reminders]
|
||||
[auto-ap.routes.graphql :as graphql]
|
||||
@@ -34,7 +34,7 @@
|
||||
exports/routes
|
||||
yodlee/routes
|
||||
invoices/routes
|
||||
companies/routes
|
||||
clients/routes
|
||||
reminders/routes
|
||||
checks/routes
|
||||
graphql/routes
|
||||
|
||||
@@ -67,13 +67,12 @@
|
||||
[file filename]
|
||||
(excel/parse-file file filename))
|
||||
|
||||
(defn best-match [companies company-identifier]
|
||||
(println companies)
|
||||
(->> companies
|
||||
(map (fn [company]
|
||||
(if-let [matches (:matches company)]
|
||||
[company (apply min (map #(m/jaccard (.toLowerCase company-identifier) %) matches))]
|
||||
[company 1])))
|
||||
(defn best-match [clients client-identifier]
|
||||
(->> clients
|
||||
(map (fn [client]
|
||||
(if-let [matches (:client/matches client)]
|
||||
[client (apply min (map #(m/jaccard (.toLowerCase client-identifier) %) matches))]
|
||||
[client 1])))
|
||||
(filter #(< (second %) 0.25))
|
||||
(sort-by second)
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
(ns auto-ap.routes.companies
|
||||
(ns auto-ap.routes.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.entities.companies :as entity]
|
||||
[auto-ap.entities.clients :as entity]
|
||||
[compojure.core :refer [GET PUT context defroutes
|
||||
wrap-routes]]))
|
||||
|
||||
|
||||
(defroutes routes
|
||||
(wrap-routes
|
||||
(context "/companies" []
|
||||
(context "/clients" []
|
||||
#_(wrap-spec
|
||||
(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)
|
||||
company (companies/get-by-id id)
|
||||
company (d-clients/get-by-id id)
|
||||
updated-company (merge company {:address address
|
||||
:email email
|
||||
:locations locations})]
|
||||
@@ -30,7 +30,7 @@
|
||||
(if-let [id (:db/id (or (clients client-code)
|
||||
(clients client)))]
|
||||
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]}]
|
||||
(or invoice-number ""))
|
||||
@@ -94,7 +94,7 @@
|
||||
:details (str e)})))))
|
||||
|
||||
(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-clients (d-clients/get-all)
|
||||
all-clients (merge (by :client/code all-clients) (by :client/name all-clients))
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
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
|
||||
:let [{post-date :postDate
|
||||
account-id :accountId
|
||||
@@ -62,7 +62,7 @@
|
||||
(- amount)
|
||||
amount)
|
||||
check-number (extract-check-number transaction)
|
||||
client-id (transaction->company transaction)
|
||||
client-id (transaction->client transaction)
|
||||
bank-account-id (transaction->bank-account-id transaction)
|
||||
check-id (transaction->check-id transaction check-number client-id bank-account-id amount)]]
|
||||
(try
|
||||
@@ -125,7 +125,7 @@
|
||||
:yodlee-account-id yodlee-account-id}))
|
||||
(:client/bank-accounts c)))
|
||||
(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)]
|
||||
(import-transactions transactions transaction->company transaction->bank-account-id)))
|
||||
(import-transactions transactions transaction->client transaction->bank-account-id)))
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
(ns auto-ap.entities.companies
|
||||
(ns auto-ap.entities.clients
|
||||
(:require [clojure.spec.alpha :as s]
|
||||
[auto-ap.entities.shared :as shared]
|
||||
[clojure.string :as str]
|
||||
@@ -17,12 +17,12 @@
|
||||
:is-empty #(= % "")))))
|
||||
|
||||
|
||||
(s/def ::company (s/keys :req-un [::name]
|
||||
(s/def ::client (s/keys :req-un [::name]
|
||||
:opt-un [::email
|
||||
::address
|
||||
::locations
|
||||
::id]))
|
||||
|
||||
|
||||
(def company-spec (apply hash-map (drop 1 (s/form ::company))))
|
||||
(def all-keys (map #(keyword (name %)) (concat (:req-un company-spec) (:opt-un company-spec))))
|
||||
(def client-spec (apply hash-map (drop 1 (s/form ::client))))
|
||||
(def all-keys (map #(keyword (name %)) (concat (:req-un client-spec) (:opt-un client-spec))))
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
(def default-db
|
||||
{:user (.getItem js/localStorage "jwt")
|
||||
:company {:name "Campbell Brewing Company"}
|
||||
:companies []
|
||||
:client {:name "Campbell Brewing Company"}
|
||||
:clients []
|
||||
:invoices {:pending #{}
|
||||
:unpaid #{}}
|
||||
:status {:loading false}
|
||||
:new-invoice {}
|
||||
:menu {:company {:active? false}
|
||||
:menu {:client {:active? false}
|
||||
:account {:active? false}}
|
||||
})
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
:active-page handler
|
||||
:user 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] ]
|
||||
[:address [:street1 :street2 :city :state :zip]]]]
|
||||
@@ -59,7 +59,7 @@
|
||||
::logged-in
|
||||
(fn [{:keys [db]} [_ token user]]
|
||||
{:graphql {:token token
|
||||
:query-obj {:venia/queries [[:company
|
||||
:query-obj {:venia/queries [[:client
|
||||
[:id :name [:bank-accounts [:id :number :check-number :name :type]]]]
|
||||
[:vendor
|
||||
[: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
|
||||
::received-initial
|
||||
(fn [db [_ {companies :company vendors :vendor :as x}]]
|
||||
(fn [db [_ {clients :client vendors :vendor :as x}]]
|
||||
(-> db
|
||||
(assoc :companies (by :id companies) )
|
||||
(assoc :clients (by :id clients) )
|
||||
(assoc :vendors (by :id vendors) ))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::swap-company
|
||||
(fn [db [_ company]]
|
||||
(assoc db :company (:id company))))
|
||||
::swap-client
|
||||
(fn [db [_ client]]
|
||||
(assoc db :client (:id client))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change-form
|
||||
@@ -123,8 +123,8 @@
|
||||
{:db (assoc-in (:db cofx) [:status :loading] true)
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj {:venia/queries [[:invoice
|
||||
{:imported false :company_id (:id @(re-frame/subscribe [::subs/company]))}
|
||||
[:id :total :invoice-number :date [:vendor [:name :id]] [:company [:name :id]]]]]}
|
||||
{:imported false :client_id (:id @(re-frame/subscribe [::subs/client]))}
|
||||
[:id :total :invoice-number :date [:vendor [:name :id]] [:client [:name :id]]]]]}
|
||||
|
||||
:on-success [::received-invoices :pending]}}))
|
||||
|
||||
@@ -134,8 +134,8 @@
|
||||
{:db (assoc-in (:db cofx) [:status :loading] true)
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj {:venia/queries [[:invoice
|
||||
{:imported true :company_id (:id @(re-frame/subscribe [::subs/company]))}
|
||||
[:id :total :invoice-number :date [:vendor [:name :id]] [:company [:name :id]]]]]}
|
||||
{:imported true :client_id (:id @(re-frame/subscribe [::subs/client]))}
|
||||
[:id :total :invoice-number :date [:vendor [:name :id]] [:client [:name :id]]]]]}
|
||||
:on-success [::received-invoices :unpaid]}}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
@@ -146,7 +146,7 @@
|
||||
(re-frame/reg-event-fx
|
||||
::logout
|
||||
(fn [{:keys [db]} [_]]
|
||||
{:db (assoc db :user nil :menu {:company {:active? false}
|
||||
{:db (assoc db :user nil :menu {:client {:active? false}
|
||||
:account {:active? false}})
|
||||
:redirect (bidi/path-for routes/routes :login)
|
||||
:set-local-storage ["jwt" nil]}))
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
(ns auto-ap.events.admin.companies
|
||||
(ns auto-ap.events.admin.clients
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[auto-ap.db :as db]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.routes :as routes]
|
||||
[auto-ap.effects :as effects]
|
||||
[auto-ap.entities.companies :as entity]
|
||||
[auto-ap.entities.clients :as entity]
|
||||
[bidi.bidi :as bidi]))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::edit
|
||||
(fn [{:keys [db]} [_ company-id]]
|
||||
{:dispatch [::events/modal-status :auto-ap.views.pages.admin.companies/edit {:visible? true}]
|
||||
:db (assoc-in db [:admin :company]
|
||||
(get (:companies db) company-id))}))
|
||||
(fn [{:keys [db]} [_ client-id]]
|
||||
{:dispatch [::events/modal-status :auto-ap.views.pages.admin.clients/edit {:visible? true}]
|
||||
:db (assoc-in db [:admin :client]
|
||||
(get (:clients db) client-id))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::save
|
||||
(fn [{:keys [db]} _]
|
||||
(let [edited-company (-> (get-in db [:admin :company])
|
||||
(let [edited-client (-> (get-in db [:admin :clients])
|
||||
(dissoc :location))]
|
||||
|
||||
{:db (assoc-in db [:admin :company :saving?] true)
|
||||
{:db (assoc-in db [:admin :client :saving?] true)
|
||||
:http {:method :put
|
||||
:token (:user db)
|
||||
:body (pr-str edited-company)
|
||||
:body (pr-str edited-client)
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:uri (str "/api/companies/" (:id edited-company))
|
||||
:uri (str "/api/clients/" (:id edited-client))
|
||||
:on-success [::save-complete]
|
||||
:on-error [::save-error]}})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::save-complete
|
||||
(fn [{:keys [db]} [_ company]]
|
||||
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.companies/edit]
|
||||
(fn [{:keys [db]} [_ client]]
|
||||
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.clients/edit]
|
||||
:db (-> db
|
||||
|
||||
(assoc-in [:admin :company] nil)
|
||||
(assoc-in [:companies (:id company)] company))}))
|
||||
(assoc-in [:admin :clients] nil)
|
||||
(assoc-in [:clients (:id client)] client))}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::save-error
|
||||
(fn [db [_ company]]
|
||||
(fn [db [_ client]]
|
||||
(-> db
|
||||
(assoc-in [:admin :company :saving?] false)
|
||||
(assoc-in [:admin :company :error] true))))
|
||||
(assoc-in [:admin :client :saving?] false)
|
||||
(assoc-in [:admin :client :error] true))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change
|
||||
(fn [db [_ path value]]
|
||||
(assoc-in db (concat [:admin :company] path)
|
||||
(assoc-in db (concat [:admin :client] path)
|
||||
value)))
|
||||
@@ -99,8 +99,8 @@
|
||||
(-> db
|
||||
(update-in [:admin :vendor :relationships] #(conj (or % [])
|
||||
{:account-number (get-in db [:admin :vendor :new-relationship-account-number])
|
||||
:company-id (get-in db [:admin :vendor :new-relationship-company])}))
|
||||
(update-in [:admin :vendor] dissoc :new-relationship-account-number :new-relationship-company))))
|
||||
:client-id (get-in db [:admin :vendor :new-relationship-client])}))
|
||||
(update-in [:admin :vendor] dissoc :new-relationship-account-number :new-relationship-client))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::remove-relationship
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
[clojure.spec.alpha :as s]
|
||||
[cljs-time.core :as c]
|
||||
[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.vendors :as vendor]
|
||||
[auto-ap.expense-accounts :as expense-accounts]
|
||||
@@ -40,7 +40,7 @@
|
||||
[:vendor [:name :id]]
|
||||
[:expense_accounts [:amount :id :location :expense_account_id
|
||||
[:expense_account [:id :name [:parent [:id :name]]]]]]
|
||||
[:company [:name :id :locations]]
|
||||
[:client [:name :id :locations]]
|
||||
[:checks [:amount [:check [:amount :s3_url :check_number ]]]]
|
||||
]]}]}
|
||||
:on-success [::expense-accounts-updated]}})))
|
||||
@@ -62,7 +62,7 @@
|
||||
(re-frame/reg-event-db
|
||||
::add-expense-account-split
|
||||
(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]
|
||||
conj {:amount 0 :expense-account-id nil :location (first locations)}))))
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"needs-activation/" :needs-activation
|
||||
"checks/" :checks
|
||||
"admin/" {"" :admin
|
||||
"companies" :admin-companies
|
||||
"clients" :admin-clients
|
||||
"users" :admin-users
|
||||
"reminders" :admin-reminders
|
||||
"vendors" :admin-vendors
|
||||
|
||||
@@ -5,21 +5,21 @@
|
||||
[goog.crypt.base64 :as base64]))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::company
|
||||
::client
|
||||
(fn [db]
|
||||
(get (:companies db) (:company db))))
|
||||
(get (:clients db) (:client db))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::companies
|
||||
::clients
|
||||
(fn [db]
|
||||
(when (:user db)
|
||||
(vals (:companies db)))))
|
||||
(vals (:clients db)))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::companies-by-id
|
||||
::clients-by-id
|
||||
(fn [db]
|
||||
(when (:user db)
|
||||
(:companies db))))
|
||||
(:clients db))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::menu
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
[cljs-time.core :as c]
|
||||
[goog.string :as gstring]
|
||||
[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.vendors :as vendor]
|
||||
[auto-ap.expense-accounts :as expense-accounts]
|
||||
@@ -73,7 +73,7 @@
|
||||
|
||||
|
||||
(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)
|
||||
change-event [::events/change-form [::change-expense-accounts]]
|
||||
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
(defn query [params]
|
||||
{:venia/queries [[:invoice_page
|
||||
(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
|
||||
[:vendor [:name :id]]
|
||||
[:expense_accounts [:amount :id :expense_account_id :location
|
||||
@@ -59,7 +59,7 @@
|
||||
(let [state (reagent/atom (or @params {}))
|
||||
visible-checks @(re-frame/subscribe [::visible-checks])
|
||||
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]
|
||||
(swap! state merge p)
|
||||
(on-params-change p))]
|
||||
@@ -68,8 +68,8 @@
|
||||
{:keys [invoices start end count total]} @invoice-page
|
||||
visible-checks @(re-frame/subscribe [::visible-checks])
|
||||
visible-expense-accounts @(re-frame/subscribe [::visible-expense-accounts])
|
||||
selected-company @(re-frame/subscribe [::subs/company])
|
||||
percentage-size (if selected-company "%50%" "33%")
|
||||
selected-client @(re-frame/subscribe [::subs/client])
|
||||
percentage-size (if selected-client "%50%" "33%")
|
||||
]
|
||||
[:div
|
||||
[paginator {:start start :end end :count count :total total
|
||||
@@ -83,7 +83,7 @@
|
||||
(when check-boxes
|
||||
[:th {:style {"width" "20px"}}])
|
||||
|
||||
(when-not selected-company
|
||||
(when-not selected-client
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "client"
|
||||
@@ -149,7 +149,7 @@
|
||||
"")
|
||||
:on-change (fn [x e] (when on-check-changed
|
||||
(on-check-changed id)))} ]])
|
||||
(when-not selected-company
|
||||
(when-not selected-client
|
||||
[:td (:name client)])
|
||||
[:td (:name vendor)]
|
||||
[:td invoice-number]
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
(defn vendor-dialog [{:keys [vendor save-event change-event id] {:keys [name]} :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
|
||||
:title [:span (if (:id vendor)
|
||||
(str "Edit " (or name "<vendor>"))
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.events :as events]
|
||||
[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.components.vendor-dialog :refer [vendor-dialog]]))
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
:unpaid-invoices :left-panel
|
||||
:paid-invoices :left-panel
|
||||
:admin :admin-left-panel
|
||||
:admin-companies :admin-left-panel
|
||||
:admin-clients :admin-left-panel
|
||||
:admin-users :admin-left-panel
|
||||
:admin-excel-import :admin-left-panel
|
||||
:admin-vendors :admin-left-panel
|
||||
@@ -52,8 +52,8 @@
|
||||
(defmulti layout page->layout)
|
||||
|
||||
(defmethod layout :admin-left-panel [ap]
|
||||
(let [company (re-frame/subscribe [::subs/company])
|
||||
companies (re-frame/subscribe [::subs/companies])
|
||||
(let [client (re-frame/subscribe [::subs/client])
|
||||
clients (re-frame/subscribe [::subs/clients])
|
||||
menu (re-frame/subscribe [::subs/menu])]
|
||||
|
||||
[:div
|
||||
@@ -82,11 +82,11 @@
|
||||
[:p.menu-label "Setup"]
|
||||
[:ul.menu-list
|
||||
[: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"}
|
||||
[:i {:class "fa fa-star-o"}]]
|
||||
|
||||
[:span {:class "name"} "Companies"]]]
|
||||
[:span {:class "name"} "Clients"]]]
|
||||
[:li.menu-item
|
||||
[:a {:href (bidi/path-for routes/routes :admin-vendors) , :class (str "item" (active-when= ap :admin-vendors))}
|
||||
[:span {:class "icon"}
|
||||
@@ -129,7 +129,7 @@
|
||||
[:a {:class "button is-danger is-block is-bold" :href (bidi/path-for routes/routes :index)}
|
||||
[:span {:class "compose"} "Back"]]]]]
|
||||
[: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
|
||||
[pages/active-page ap]]]]
|
||||
[:footer {:class "footer"}
|
||||
@@ -143,8 +143,8 @@
|
||||
[:div#dz-hidden]]))
|
||||
|
||||
(defmethod layout :left-panel [ap]
|
||||
(let [company (re-frame/subscribe [::subs/company])
|
||||
companies (re-frame/subscribe [::subs/companies])
|
||||
(let [client (re-frame/subscribe [::subs/client])
|
||||
clients (re-frame/subscribe [::subs/clients])
|
||||
menu (re-frame/subscribe [::subs/menu])]
|
||||
[:div
|
||||
[:nav {:class "navbar has-shadow"}
|
||||
@@ -153,20 +153,20 @@
|
||||
[:a {:class "navbar-item", :href "../"}
|
||||
[:img {:src "/img/logo.png"}]]]
|
||||
[: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 { :class (str "navbar-item has-dropdown " (when (get-in @menu [:company :active?]) "is-active"))}
|
||||
[:a {:class "navbar-link login"} "Company: " (if @company (:name @company)
|
||||
[:div { :class (str "navbar-item has-dropdown " (when (get-in @menu [:client :active?]) "is-active"))}
|
||||
[:a {:class "navbar-link login"} "Client: " (if @client (:name @client)
|
||||
"All")]
|
||||
[:div {:class "navbar-dropdown"}
|
||||
[: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"]
|
||||
[:hr {:class "navbar-divider"}]
|
||||
(for [{:keys [name id] :as company} @companies]
|
||||
(for [{:keys [name id] :as client} @clients]
|
||||
^{:key id }
|
||||
[: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])]]]]
|
||||
[:div {:class "navbar-burger burger", :data-target "navMenu"}
|
||||
[:span]
|
||||
@@ -226,7 +226,7 @@
|
||||
[:span {:class "compose"} "New Vendor"]]]]]
|
||||
|
||||
[: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
|
||||
[pages/active-page ap]]]]
|
||||
[:footer {:class "footer"}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
[auto-ap.views.pages.admin :refer [admin-page]]
|
||||
[auto-ap.views.pages.needs-activation :refer [needs-activation-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.users :refer [admin-users-page]]
|
||||
[auto-ap.views.pages.admin.vendors :refer [admin-vendors-page]]
|
||||
@@ -46,8 +46,8 @@
|
||||
(defmethod active-page :check []
|
||||
[check-page])
|
||||
|
||||
(defmethod active-page :admin-companies []
|
||||
[admin-companies-page])
|
||||
(defmethod active-page :admin-clients []
|
||||
[admin-clients-page])
|
||||
|
||||
(defmethod active-page :admin-vendors []
|
||||
[admin-vendors-page])
|
||||
|
||||
@@ -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 [re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]
|
||||
[auto-ap.subs :as subs]
|
||||
[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.utils :refer [login-url dispatch-event dispatch-value-change bind-field horizontal-field]]
|
||||
[auto-ap.views.components.modal :refer [action-modal]]
|
||||
@@ -14,105 +14,105 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::edit
|
||||
(fn [{:keys [db]} [_ company-id]]
|
||||
{:dispatch [::events/modal-status :auto-ap.views.pages.admin.companies/edit {:visible? true}]
|
||||
:db (assoc-in db [:admin :company]
|
||||
(get (:companies db) company-id))}))
|
||||
(fn [{:keys [db]} [_ client-id]]
|
||||
{:dispatch [::events/modal-status :auto-ap.views.pages.admin.clients/edit {:visible? true}]
|
||||
:db (assoc-in db [:admin :client]
|
||||
(get (:clients db) client-id))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::save
|
||||
(fn [{:keys [db]} _]
|
||||
(let [edited-company (-> (get-in db [:admin :company])
|
||||
(let [edited-client (-> (get-in db [:admin :client])
|
||||
(dissoc :location)
|
||||
(dissoc :new-account))]
|
||||
|
||||
{:db (assoc-in db [:admin :company :saving?] true)
|
||||
{:db (assoc-in db [:admin :client :saving?] true)
|
||||
:http {:method :put
|
||||
:token (:user db)
|
||||
:body (pr-str edited-company)
|
||||
:body (pr-str edited-client)
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:uri (str "/api/companies/" (:id edited-company))
|
||||
:uri (str "/api/clients/" (:id edited-client))
|
||||
:on-success [::save-complete]
|
||||
:on-error [::save-error]}})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::save-complete
|
||||
(fn [{:keys [db]} [_ company]]
|
||||
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.companies/edit]
|
||||
(fn [{:keys [db]} [_ client]]
|
||||
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.clients/edit]
|
||||
:db (-> db
|
||||
|
||||
(assoc-in [:admin :company] nil)
|
||||
(assoc-in [:companies (:id company)] company))}))
|
||||
(assoc-in [:admin :client] nil)
|
||||
(assoc-in [:clients (:id client)] client))}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::save-error
|
||||
(fn [db [_ company]]
|
||||
(fn [db [_ client]]
|
||||
(-> db
|
||||
(assoc-in [:admin :company :saving?] false)
|
||||
(assoc-in [:admin :company :error] true))))
|
||||
(assoc-in [:admin :client :saving?] false)
|
||||
(assoc-in [:admin :client :error] true))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change
|
||||
(fn [db [_ path value]]
|
||||
(assoc-in db (concat [:admin :company] path)
|
||||
(assoc-in db (concat [:admin :client] path)
|
||||
value)))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::add-location
|
||||
(fn [{:keys [db]} _]
|
||||
(let [company (:company @(re-frame/subscribe [::subs/admin]))]
|
||||
(let [client (:client @(re-frame/subscribe [::subs/admin]))]
|
||||
{:db (-> db
|
||||
(update-in [:admin :company :locations] conj (:location company))
|
||||
(update-in [:admin :company] dissoc :location))})))
|
||||
(update-in [:admin :client :locations] conj (:location client))
|
||||
(update-in [:admin :client] dissoc :location))})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::add-new-bank-account
|
||||
(fn [{:keys [db]} _]
|
||||
(let [company (:company @(re-frame/subscribe [::subs/admin]))
|
||||
new-bank-account (:new-account company)
|
||||
(let [client (:client @(re-frame/subscribe [::subs/admin]))
|
||||
new-bank-account (:new-account client)
|
||||
new-bank-account (-> new-bank-account
|
||||
(update :check-number #(if (seq %) (js/parseInt %) nil))
|
||||
(update :yodlee-account-id #(if (seq %) (js/parseInt %) nil))
|
||||
(assoc :is-new? true))]
|
||||
{: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)))
|
||||
(update-in [:admin :company] dissoc :new-account))})))
|
||||
(update-in [:admin :client] dissoc :new-account))})))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::remove-new-bank-account
|
||||
(fn [db [_ index]]
|
||||
(update-in db [:admin :company :new-bank-accounts]
|
||||
(update-in db [:admin :client :new-bank-accounts]
|
||||
(fn [bas]
|
||||
(vec (concat (take index bas)
|
||||
(drop (inc index) bas)))))))
|
||||
|
||||
(defn companies-table []
|
||||
(let [companies (re-frame/subscribe [::subs/companies])
|
||||
editing-company (:company @(re-frame/subscribe [::subs/admin]))]
|
||||
(defn clients-table []
|
||||
(let [clients (re-frame/subscribe [::subs/clients])
|
||||
editing-client (:client @(re-frame/subscribe [::subs/admin]))]
|
||||
[:table {:class "table", :style {:width "100%"}}
|
||||
[:thead
|
||||
[:tr
|
||||
[:th "Name"]
|
||||
[:th "Email"]]]
|
||||
[:tbody (for [{:keys [id name email] :as c} @companies]
|
||||
[:tbody (for [{:keys [id name email] :as c} @clients]
|
||||
^{:key (str name "-" id )}
|
||||
[:tr {:on-click (fn [] (re-frame/dispatch [::edit id]))
|
||||
:style {"cursor" "pointer"}}
|
||||
[:td name]
|
||||
[:td email]])]]))
|
||||
|
||||
(defn admin-companies-page []
|
||||
(defn admin-clients-page []
|
||||
[:div
|
||||
(let [companies (re-frame/subscribe [::subs/companies])
|
||||
editing-company (:company @(re-frame/subscribe [::subs/admin]))]
|
||||
(let [clients (re-frame/subscribe [::subs/clients])
|
||||
editing-client (:client @(re-frame/subscribe [::subs/admin]))]
|
||||
|
||||
[:div
|
||||
[:h1.title "Companies"]
|
||||
[companies-table]
|
||||
[:h1.title "Clients"]
|
||||
[clients-table]
|
||||
|
||||
[action-modal {:id ::edit
|
||||
:title (str "Edit " (:name editing-company))
|
||||
:title (str "Edit " (:name editing-client))
|
||||
:action-text "Save"
|
||||
:save-event [::save]}
|
||||
[horizontal-field
|
||||
@@ -123,7 +123,7 @@
|
||||
:field :name
|
||||
:spec ::entity/name
|
||||
:event ::change
|
||||
:subscription editing-company}]]]]
|
||||
:subscription editing-client}]]]]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Email"]
|
||||
@@ -133,7 +133,7 @@
|
||||
:field :email
|
||||
:spec ::entity/name
|
||||
:event ::change
|
||||
:subscription editing-company}]]]]
|
||||
:subscription editing-client}]]]]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Locations"]
|
||||
@@ -144,16 +144,16 @@
|
||||
[:input.input {:type "text"
|
||||
:field :location
|
||||
:event ::change
|
||||
:subscription editing-company}]]]
|
||||
:subscription editing-client}]]]
|
||||
[:p.control [:button.button.is-primary {:on-click (dispatch-event [::add-location])} "Add"]]]
|
||||
[:ul
|
||||
(for [location (:locations editing-company)]
|
||||
(for [location (:locations editing-client)]
|
||||
^{:key location} [:li location ])]]]
|
||||
[:h2.subtitle "Address"]
|
||||
|
||||
[address-field {:field [:address]
|
||||
:event ::change
|
||||
:subscription editing-company}]
|
||||
:subscription editing-client}]
|
||||
[:h2.subtitle "Add account"]
|
||||
|
||||
[horizontal-field
|
||||
@@ -165,7 +165,7 @@
|
||||
:type "text"
|
||||
:field [:new-account :bank-name]
|
||||
:event ::change
|
||||
:subscription editing-company}]]]
|
||||
:subscription editing-client}]]]
|
||||
[:div.control
|
||||
|
||||
[bind-field
|
||||
@@ -173,7 +173,7 @@
|
||||
:type "text"
|
||||
:field [:new-account :routing]
|
||||
:event ::change
|
||||
:subscription editing-company}]]]
|
||||
:subscription editing-client}]]]
|
||||
[:div.control
|
||||
|
||||
[bind-field
|
||||
@@ -181,7 +181,7 @@
|
||||
:type "text"
|
||||
:field [:new-account :bank-code]
|
||||
:event ::change
|
||||
:subscription editing-company}]]]]
|
||||
:subscription editing-client}]]]]
|
||||
[horizontal-field
|
||||
[:label.label "Account"]
|
||||
[:div.control
|
||||
@@ -190,21 +190,21 @@
|
||||
:type "text"
|
||||
:field [:new-account :name]
|
||||
:event ::change
|
||||
:subscription editing-company}]]]
|
||||
:subscription editing-client}]]]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input {:placeholder "Acct #"
|
||||
:type "text"
|
||||
:field [:new-account :number]
|
||||
:event ::change
|
||||
:subscription editing-company}]]]
|
||||
:subscription editing-client}]]]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input {:placeholder "Check #"
|
||||
:type "text"
|
||||
:field [:new-account :check-number]
|
||||
:event ::change
|
||||
:subscription editing-company}]]]]
|
||||
:subscription editing-client}]]]]
|
||||
[horizontal-field
|
||||
[:label.label "Yodlee Account"]
|
||||
[:div.control
|
||||
@@ -213,7 +213,7 @@
|
||||
:type "text"
|
||||
:field [:new-account :yodlee-account-id]
|
||||
:event ::change
|
||||
:subscription editing-company}]]]
|
||||
:subscription editing-client}]]]
|
||||
[:div.control
|
||||
[:button.button.is-primary.is-pulled-right {:on-click (dispatch-event [::add-new-bank-account])} "Add"]]]
|
||||
|
||||
@@ -225,9 +225,9 @@
|
||||
[:div.control
|
||||
[: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])
|
||||
(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]]]])]]]
|
||||
|
||||
(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)"}}])]])])
|
||||
@@ -4,8 +4,8 @@
|
||||
[reagent.core :as reagent]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.events :as all-events]
|
||||
[auto-ap.events.admin.companies :as events]
|
||||
[auto-ap.entities.companies :as entity]
|
||||
[auto-ap.events.admin.clients :as events]
|
||||
[auto-ap.entities.clients :as entity]
|
||||
|
||||
[auto-ap.views.components.typeahead :refer [typeahead]]
|
||||
[auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field dispatch-event]]
|
||||
@@ -182,17 +182,17 @@
|
||||
[:thead
|
||||
[:th "Date"]
|
||||
[:th "Invoice #"]
|
||||
[:th "Company"]
|
||||
[:th "Client"]
|
||||
[:th "Vendor"]
|
||||
[:th "Amount"]
|
||||
[:th "Errors"]]
|
||||
|
||||
(for [{:keys [raw-date invoice-number company vendor-name amount] row-errors :errors} (take 100 errors)]
|
||||
^{:key (str raw-date invoice-number company vendor-name amount)}
|
||||
(for [{:keys [raw-date invoice-number client vendor-name amount] row-errors :errors} (take 100 errors)]
|
||||
^{:key (str raw-date invoice-number client vendor-name amount)}
|
||||
[:tr
|
||||
[:td raw-date]
|
||||
[:td invoice-number]
|
||||
[:td company]
|
||||
[:td client]
|
||||
[:td vendor-name]
|
||||
[:td amount]
|
||||
[:td (map (fn [{:keys [info]}] ^{:key info} [:p info]) row-errors)]])]])])])
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
[clojure.string :as str]
|
||||
[auto-ap.subs :as subs]
|
||||
[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.utils :refer [login-url dispatch-value-change bind-field horizontal-field dispatch-event]]
|
||||
[auto-ap.views.components.modal :refer [modal action-modal]]
|
||||
@@ -55,14 +55,14 @@
|
||||
(dissoc db ::editing))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::add-company
|
||||
::add-client
|
||||
(fn [db [_ d]]
|
||||
(let [company (get @(re-frame/subscribe [::subs/companies-by-id])
|
||||
(get-in db [::editing :adding-company]))]
|
||||
(update-in db [::editing :user :clients] conj company))))
|
||||
(let [client (get @(re-frame/subscribe [::subs/clients-by-id])
|
||||
(get-in db [::editing :adding-client]))]
|
||||
(update-in db [::editing :user :clients] conj client))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::remove-company
|
||||
::remove-client
|
||||
(fn [db [_ d]]
|
||||
(update-in db [::editing :user :clients] #(filter (fn [c] (not= (:id c) d)) %))))
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
(with-meta
|
||||
(fn []
|
||||
[:div
|
||||
(let [companies (re-frame/subscribe [::users])
|
||||
(let [clients (re-frame/subscribe [::users])
|
||||
editing @(re-frame/subscribe [::editing])]
|
||||
[:div
|
||||
[:h1.title "Users"]
|
||||
@@ -160,20 +160,20 @@
|
||||
[:div.select
|
||||
[bind-field
|
||||
[:select {:type "select"
|
||||
:field [:adding-company]
|
||||
:field [:adding-client]
|
||||
:event ::change
|
||||
:subscription editing}
|
||||
[:option]
|
||||
(let [used-companies (set (map :id (:clients (:user editing))))]
|
||||
(for [{:keys [id name]} @(re-frame/subscribe [::subs/companies])
|
||||
:when (not (used-companies id))]
|
||||
(let [used-clients (set (map :id (:clients (:user editing))))]
|
||||
(for [{:keys [id name]} @(re-frame/subscribe [::subs/clients])
|
||||
:when (not (used-clients id))]
|
||||
^{:key id} [:option {:value id} name]))]]]]
|
||||
[: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
|
||||
(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 {}]) }))
|
||||
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
[reagent.core :as reagent]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.events.admin.companies :as events]
|
||||
[auto-ap.entities.companies :as entity]
|
||||
[auto-ap.events.admin.clients :as events]
|
||||
[auto-ap.entities.clients :as entity]
|
||||
[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.components.modal :refer [action-modal]]
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
(defn check-page []
|
||||
(let [checks @(re-frame/subscribe [::checks])]
|
||||
[: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)]]
|
||||
[:div
|
||||
[:div.columns
|
||||
(let [{:keys [name address1 city state zip bank]} company]
|
||||
(let [{:keys [name address1 city state zip bank]} client]
|
||||
(list
|
||||
[:div.column.is-4
|
||||
[:p name]
|
||||
@@ -76,7 +76,7 @@
|
||||
[:div.columns
|
||||
[:div.column.is-2 ]
|
||||
[: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
|
||||
@@ -94,7 +94,7 @@
|
||||
[:div.columns
|
||||
[:div.column]
|
||||
[:div.column.is-10
|
||||
(let [{:keys [name address1 city state zip bank]} company]
|
||||
(let [{:keys [name address1 city state zip bank]} client]
|
||||
(list
|
||||
[:p name]
|
||||
[:p address1]
|
||||
@@ -154,7 +154,7 @@
|
||||
[:div.column.is-5
|
||||
[:p check]
|
||||
[:p vendor-name]
|
||||
[:p (:name (:bank company))]
|
||||
[:p (:name (:bank client))]
|
||||
[:p paid-to]
|
||||
[:p amount]
|
||||
[:p date]]]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(ns auto-ap.views.pages.checks
|
||||
(: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]
|
||||
[reagent.core :as reagent]
|
||||
[goog.string :as gstring]
|
||||
@@ -35,7 +35,7 @@
|
||||
(assoc-in [::params] params))
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
: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]]]]
|
||||
:total
|
||||
: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]}]
|
||||
(let [state (reagent/atom (or @params {}))
|
||||
selected-company @(re-frame/subscribe [::subs/company])
|
||||
selected-client @(re-frame/subscribe [::subs/client])
|
||||
opc (fn [p]
|
||||
(swap! state merge p)
|
||||
(on-params-change p))]
|
||||
(fn [{:keys [id payment-page status on-params-change vendors checked]}]
|
||||
(let [{:keys [sort-by asc]} @state
|
||||
{:keys [payments start end count total]} @payment-page
|
||||
selected-company @(re-frame/subscribe [::subs/company])
|
||||
percentage-size (if selected-company "50%" "33%")]
|
||||
selected-client @(re-frame/subscribe [::subs/client])
|
||||
percentage-size (if selected-client "50%" "33%")]
|
||||
[:div
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change (fn [p ]
|
||||
@@ -100,7 +100,7 @@
|
||||
[:tr
|
||||
|
||||
|
||||
(when-not selected-company
|
||||
(when-not selected-client
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "client"
|
||||
@@ -151,7 +151,7 @@
|
||||
^{:key id}
|
||||
[:tr {:class (:class i)}
|
||||
|
||||
(when-not selected-company
|
||||
(when-not selected-client
|
||||
[:td (:name client)])
|
||||
[:td (:name vendor)]
|
||||
[:td (cond
|
||||
@@ -176,7 +176,7 @@
|
||||
|
||||
(with-meta
|
||||
(fn []
|
||||
(let [current-company @(re-frame/subscribe [::subs/company])]
|
||||
(let [current-client @(re-frame/subscribe [::subs/client])]
|
||||
[:div
|
||||
[:h1.title "Checks"]
|
||||
[check-table {:id :payments
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
[reagent.core :as reagent]
|
||||
[auto-ap.events :as events]
|
||||
[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.views.components.invoice-table :refer [invoice-table] :as invoice-table]
|
||||
[cljsjs.dropzone :as dropzone]
|
||||
[cljs.reader :as edn]))
|
||||
(def dropzone
|
||||
(let [company (re-frame/subscribe [::subs/company])
|
||||
(let [client (re-frame/subscribe [::subs/client])
|
||||
token (re-frame/subscribe [::subs/token])]
|
||||
(with-meta
|
||||
(fn []
|
||||
@@ -28,8 +28,8 @@
|
||||
:paramName "file"
|
||||
:headers {"Authorization" (str "Token " @token)}
|
||||
:url (str "/api/invoices/upload"
|
||||
(when-let [company-name (-> @company :id)]
|
||||
(str "?company=" company-name)))
|
||||
(when-let [client-name (-> @client :id)]
|
||||
(str "?client=" client-name)))
|
||||
:previewsContainer "#dz-hidden"
|
||||
:previewTemplate "<div class='dz-hidden-preview'></div>"})))})))
|
||||
|
||||
@@ -72,8 +72,8 @@
|
||||
{:http {:method :post
|
||||
:token (-> cofx :db :user)
|
||||
:uri (str "/api/invoices/reject"
|
||||
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
|
||||
(str "?company=" company-id)))
|
||||
(when-let [client-id (:id @(re-frame/subscribe [::subs/client]))]
|
||||
(str "?client=" client-id)))
|
||||
:on-success on-success
|
||||
}}))
|
||||
|
||||
@@ -83,8 +83,8 @@
|
||||
{:http {:method :post
|
||||
:token (-> cofx :db :user)
|
||||
:uri (str "/api/invoices/approve"
|
||||
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
|
||||
(str "?company=" company-id)))
|
||||
(when-let [client-id (:id @(re-frame/subscribe [::subs/client]))]
|
||||
(str "?client=" client-id)))
|
||||
:on-success on-success
|
||||
}}))
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@
|
||||
[:div.control
|
||||
[:input.input {:type "text"
|
||||
:placeholder "Brown Chicken Brown Cow"
|
||||
:value (:company @form-data)
|
||||
:value (:client @form-data)
|
||||
:on-change (fn [e]
|
||||
(re-frame/dispatch [::events/change-form-state
|
||||
[:new-invoice :company]
|
||||
[:new-invoice :client]
|
||||
(.. e -target -value)]))}]]]
|
||||
[:div.field
|
||||
[:label.label "Invoice #"]
|
||||
@@ -61,7 +61,7 @@
|
||||
(.. e -target -value)]))}]]]
|
||||
[:div.control
|
||||
[: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))
|
||||
""
|
||||
"disabled")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(ns auto-ap.views.pages.paid-invoices
|
||||
(: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.events :as events]
|
||||
[auto-ap.views.utils :refer [dispatch-event]]
|
||||
@@ -63,7 +63,7 @@
|
||||
|
||||
(with-meta
|
||||
(fn []
|
||||
(let [current-company @(re-frame/subscribe [::subs/company])]
|
||||
(let [current-client @(re-frame/subscribe [::subs/client])]
|
||||
[:div
|
||||
[:h1.title "Paid invoices"]
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(ns auto-ap.views.pages.transactions
|
||||
(: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]
|
||||
[reagent.core :as reagent]
|
||||
[goog.string :as gstring]
|
||||
@@ -33,7 +33,7 @@
|
||||
(assoc-in [::params] params))
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
: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
|
||||
:amount
|
||||
:date
|
||||
@@ -68,8 +68,8 @@
|
||||
(fn [{:keys [id transaction-page status on-params-change vendors checked]}]
|
||||
(let [{:keys [sort-by asc]} @state
|
||||
{:keys [transactions start end count total]} @transaction-page
|
||||
selected-company @(re-frame/subscribe [::subs/company])
|
||||
percentage-size (if selected-company "25%" "33%")]
|
||||
selected-client @(re-frame/subscribe [::subs/client])
|
||||
percentage-size (if selected-client "25%" "33%")]
|
||||
[:div
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change (fn [p ]
|
||||
@@ -79,7 +79,7 @@
|
||||
[:table.table.is-fullwidth
|
||||
[:thead
|
||||
[:tr
|
||||
(when-not selected-company
|
||||
(when-not selected-client
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "client"
|
||||
@@ -126,7 +126,7 @@
|
||||
^{:key id}
|
||||
[:tr {:class (:class i)}
|
||||
|
||||
(when-not selected-company
|
||||
(when-not selected-client
|
||||
[:td (:name client)])
|
||||
[:td description-original]
|
||||
[:td (date->str date) ]
|
||||
@@ -145,7 +145,7 @@
|
||||
::manual-yodlee-import
|
||||
(fn [{:keys [db]} _]
|
||||
{: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 ""})}))
|
||||
|
||||
(re-frame/reg-sub
|
||||
@@ -201,7 +201,7 @@
|
||||
(with-meta
|
||||
(fn []
|
||||
(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])]
|
||||
|
||||
[:div
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
[clojure.spec.alpha :as s]
|
||||
[cljs-time.core :as c]
|
||||
[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.vendors :as vendor]
|
||||
[auto-ap.views.components.expense-accounts-dialog :as expense-accounts-dialog]
|
||||
@@ -105,7 +105,7 @@
|
||||
(-> db
|
||||
(update-in [::invoice-page :print-checks-shown?] #(not %) )
|
||||
(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
|
||||
(filter (comp checked :id))
|
||||
(map #(assoc % :amount (:outstanding-balance %))))} )))))
|
||||
@@ -122,7 +122,7 @@
|
||||
{:dispatch [::events/modal-status ::handwrite-checks {:visible? true}]
|
||||
:db (-> db
|
||||
(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)
|
||||
:invoice invoice } ))})))
|
||||
|
||||
@@ -181,7 +181,7 @@
|
||||
(get-in db [::invoice-page :checked]))
|
||||
bank-account-id
|
||||
type
|
||||
(:company db))
|
||||
(:client db))
|
||||
:on-success [::checks-created]}})))
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@
|
||||
(fn [{:keys [db]} [_ bank-account-id]]
|
||||
(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])
|
||||
type (->> @(re-frame/subscribe [::subs/company])
|
||||
type (->> @(re-frame/subscribe [::subs/client])
|
||||
:bank-accounts
|
||||
(filter #(= bank-account-id (:id %)))
|
||||
first
|
||||
@@ -213,7 +213,7 @@
|
||||
|
||||
:else
|
||||
:check)
|
||||
(:company db))
|
||||
(:client db))
|
||||
|
||||
:on-success [::checks-created]}})))
|
||||
|
||||
@@ -246,9 +246,9 @@
|
||||
::new-invoice
|
||||
(fn [{:keys [db]} _]
|
||||
{: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)
|
||||
:location (first (:locations @(re-frame/subscribe [::subs/company])))})}))
|
||||
:location (first (:locations @(re-frame/subscribe [::subs/client])))})}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::edit-invoice
|
||||
@@ -414,7 +414,7 @@
|
||||
(defn print-checks-modal []
|
||||
(let [{:keys [checked]} @(re-frame/subscribe [::invoice-page])
|
||||
{: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?
|
||||
[modal {:title "Print Checks"
|
||||
@@ -439,7 +439,7 @@
|
||||
:field :bank-account-id
|
||||
:event ::edit-payment-bank-account
|
||||
: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])]]]]
|
||||
|
||||
[:table.table.is-fullwidth
|
||||
@@ -471,7 +471,7 @@
|
||||
(let [{:keys [checked]} @(re-frame/subscribe [::invoice-page])
|
||||
{:keys [invoice] :as handwrite-checks} @(re-frame/subscribe [::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
|
||||
:title "Handwrite Check"
|
||||
@@ -486,7 +486,7 @@
|
||||
:field :bank-account-id
|
||||
:event change-event
|
||||
: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])]]]]
|
||||
|
||||
[horizontal-field
|
||||
@@ -521,9 +521,9 @@
|
||||
:subscription handwrite-checks}]]]]))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::change-new-invoice-company
|
||||
::change-new-invoice-client
|
||||
(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])
|
||||
first)]
|
||||
{:dispatch [::events/change-form location field value]
|
||||
@@ -533,7 +533,7 @@
|
||||
(defn new-invoice-modal []
|
||||
(let [data @(re-frame/subscribe [::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
|
||||
(> (count locations) 1))]
|
||||
[action-modal {:id ::new-invoice
|
||||
@@ -542,14 +542,14 @@
|
||||
:save-event [::create-invoice]
|
||||
:can-submit? (s/valid? ::invoice/invoice data)}
|
||||
|
||||
(when-not @(re-frame/subscribe [::subs/company])
|
||||
(when-not @(re-frame/subscribe [::subs/client])
|
||||
[horizontal-field
|
||||
[:label.label "Client"]
|
||||
[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"
|
||||
:field [:client-id]
|
||||
:event [::change-new-invoice-company [::new-invoice]]
|
||||
:event [::change-new-invoice-client [::new-invoice]]
|
||||
:spec ::invoice/client-id
|
||||
:subscription data}]]])
|
||||
(when should-select-location?
|
||||
@@ -614,7 +614,7 @@
|
||||
(defn edit-invoice-modal []
|
||||
(let [data @(re-frame/subscribe [::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)))
|
||||
|
||||
should-select-location? (and locations
|
||||
@@ -670,13 +670,13 @@
|
||||
(with-meta
|
||||
(fn []
|
||||
(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])]
|
||||
[:div
|
||||
[:h1.title "Unpaid invoices"]
|
||||
[:div.is-pulled-right
|
||||
[: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?
|
||||
"is-active"
|
||||
"")}
|
||||
@@ -696,7 +696,7 @@
|
||||
[:div.dropdown-menu {:role "menu"}
|
||||
[:div.dropdown-content
|
||||
(list
|
||||
(for [{:keys [id number name type]} (:bank-accounts current-company)]
|
||||
(for [{:keys [id number name type]} (:bank-accounts current-client)]
|
||||
(if (= :cash type)
|
||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :cash])} "With cash"]
|
||||
(list
|
||||
|
||||
Reference in New Issue
Block a user