huge number of changes to start making all usages of expense accounts dynamic.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
{:invoice/client [:client/name :db/id :client/locations :client/code]}
|
||||
{:invoice/vendor [* {:vendor/address [*]}]}
|
||||
{:invoice/status [:db/ident]}
|
||||
{:invoice/expense-accounts [* {:invoice-expense-account/account [*]}]}
|
||||
{:invoice-payment/_invoice [* {:invoice-payment/payment [* {:payment/status [*]}
|
||||
{:payment/bank-account [*]}
|
||||
{:transaction/_payment [*]}]}]}]))
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
:auto-ap/add-general-ledger-fns2 {:txes-fn 'auto-ap.datomic.migrate.add-general-ledger/add-general-ledger-fns :requires [:auto-ap/add-general-ledger6]}
|
||||
:auto-ap/add-accounts {:txes auto-ap.datomic.migrate.add-general-ledger/add-accounts :requires [:auto-ap/add-general-ledger-fns2]}
|
||||
:auto-ap/add-transaction-account {:txes auto-ap.datomic.migrate.add-general-ledger/add-transaction-account :requires [:auto-ap/add-general-ledger-fns2]}
|
||||
:auto-ap/change-expense-account-to-entity {:txes auto-ap.datomic.migrate.add-general-ledger/change-expense-account-to-entity :requires [:auto-ap/add-transaction-account]}
|
||||
:auto-ap/add-account-to-vendor {:txes auto-ap.datomic.migrate.add-general-ledger/add-account-to-vendor :requires [:auto-ap/add-transaction-account]}
|
||||
#_#_:auto-ap/bulk-load-invoice-ledger2 {:txes-fn 'auto-ap.datomic.migrate.add-general-ledger/bulk-load-invoice-ledger :requires [:auto-ap/make-entity-not-unique]}
|
||||
|
||||
}]
|
||||
|
||||
@@ -145,6 +145,16 @@
|
||||
|
||||
#_(bulk-load-invoice-ledger (d/connect auto-ap.datomic/uri))
|
||||
|
||||
(def change-expense-account-to-entity
|
||||
[[{:db/ident :invoice-expense-account/account
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "The account entity that this expense is for"}]])
|
||||
|
||||
|
||||
|
||||
(def add-account-to-vendor
|
||||
[[{:db/ident :vendor/default-account
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "The account will be used when a bill is created."}]])
|
||||
|
||||
@@ -23,16 +23,11 @@
|
||||
|
||||
(defn get-by-id [id]
|
||||
|
||||
(->> (d/q '[:find (pull ?e [*])
|
||||
(->> (d/q '[:find (pull ?e [* {:default-account [:account/name :db/id :account/location]}])
|
||||
:in $ ?e
|
||||
:where [?e]]
|
||||
(d/db (d/connect uri))
|
||||
id)
|
||||
(map first)
|
||||
(first)
|
||||
#_(map (fn [c]
|
||||
(update c :client/bank-accounts
|
||||
(fn [bas]
|
||||
(map (fn [ba]
|
||||
(update ba :bank-account/type :db/ident ))
|
||||
bas)))))))
|
||||
))
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
:secondary_contact {:type :contact}
|
||||
:address {:type :address}
|
||||
|
||||
:default_expense_account {:type 'Int}
|
||||
:default_account {:type :account}
|
||||
:invoice_reminder_schedule {:type 'String}}}
|
||||
:reminder
|
||||
{:fields {:id {:type 'Int}
|
||||
@@ -196,6 +196,7 @@
|
||||
:invoices_expense_accounts
|
||||
{:fields {:id {:type :id}
|
||||
:invoice_id {:type 'String}
|
||||
:account {:type :account}
|
||||
:expense_account_id {:type 'Int}
|
||||
:location {:type 'String}
|
||||
:expense_account {:type :expense_account
|
||||
@@ -250,8 +251,7 @@
|
||||
:check_result {:fields {:invoices {:type '(list :invoice)}
|
||||
:pdf_url {:type 'String}}}
|
||||
|
||||
:expense_account_stat {:fields {:expense_account_id {:type 'Int}
|
||||
:expense_account_name {:type 'String}
|
||||
:expense_account_stat {:fields {:account {:type :account}
|
||||
:total {:type 'String}}}
|
||||
|
||||
:invoice_stat {:fields {:name {:type 'String}
|
||||
@@ -392,12 +392,12 @@
|
||||
:secondary_contact {:type :add_contact}
|
||||
:address {:type :add_address}
|
||||
|
||||
:default_expense_account {:type 'Int}
|
||||
:default_account_id {:type :id}
|
||||
:invoice_reminder_schedule {:type 'String}}}
|
||||
|
||||
:edit_expense_account
|
||||
{:fields {:id {:type :id}
|
||||
:expense_account_id {:type 'Int}
|
||||
:account_id {:type :id}
|
||||
:location {:type 'String}
|
||||
:amount {:type 'String}}}
|
||||
|
||||
@@ -581,7 +581,7 @@
|
||||
(:type args))))
|
||||
|
||||
(defn get-expense-account-stats [context {:keys [client_id] } value]
|
||||
(let [result (cond-> {:query {:find ['?expense-account-id '(sum ?amount)]
|
||||
(let [result (cond-> {:query {:find ['?account '?account-name '(sum ?amount)]
|
||||
:in ['$]
|
||||
:where []}
|
||||
:args [(d/db (d/connect uri)) client_id]}
|
||||
@@ -592,13 +592,13 @@
|
||||
|
||||
true (merge-query {:query {:where ['[?i :invoice/client ?c]
|
||||
'[?i :invoice/expense-accounts ?expense-account]
|
||||
'[?expense-account :invoice-expense-account/expense-account-id ?expense-account-id]
|
||||
'[?expense-account :invoice-expense-account/account ?account]
|
||||
'[?account :account/name ?account-name]
|
||||
'[?expense-account :invoice-expense-account/amount ?amount]]}})
|
||||
true (doto println)
|
||||
|
||||
true (d/query ))]
|
||||
(for [[expense-account-id total] result]
|
||||
{:expense_account_id expense-account-id :total total :expense_account_name (-> expense-account-id e-expense-accounts/expense-accounts :name)})))
|
||||
(for [[account-id account-name total] result]
|
||||
{:account {:id account-id :name account-name} :total total })))
|
||||
|
||||
(defn categorize [x]
|
||||
(cond (<= x 0) :due
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.datomic.invoices :as d-invoices]
|
||||
[auto-ap.datomic.accounts :as d-accounts]
|
||||
[auto-ap.expense-accounts :as expense-accounts]
|
||||
[auto-ap.graphql.checks :as gq-checks]
|
||||
[auto-ap.time :refer [parse iso-date]]
|
||||
@@ -53,8 +54,8 @@
|
||||
|
||||
(defn add-invoice-transaction [{:keys [total invoice_number location client_id vendor_id vendor_name date] :as in}]
|
||||
(let [vendor (d-vendors/get-by-id vendor_id)
|
||||
expense-account-id (:vendor/default-expense-account vendor)
|
||||
_ (when-not expense-account-id
|
||||
account (:vendor/default-account vendor)
|
||||
_ (when-not (:db/id account)
|
||||
(throw (ex-info (str "Vendor '" (:vendor/name vendor) "' does not have a default expense acount.") {:vendor-id vendor_id} )))]
|
||||
{:db/id "invoice"
|
||||
:invoice/invoice-number invoice_number
|
||||
@@ -65,8 +66,8 @@
|
||||
:invoice/outstanding-balance total
|
||||
:invoice/status :invoice-status/unpaid
|
||||
:invoice/date (coerce/to-date date)
|
||||
:invoice/expense-accounts [{:invoice-expense-account/expense-account-id expense-account-id
|
||||
:invoice-expense-account/location (get-in expense-accounts/expense-accounts [expense-account-id :location] location)
|
||||
:invoice/expense-accounts [{:invoice-expense-account/account (:db/id account)
|
||||
:invoice-expense-account/location (:account/location account location)
|
||||
:invoice-expense-account/amount total}]}))
|
||||
|
||||
(defn add-invoice [context {{:keys [total invoice_number location client_id vendor_id vendor_name date] :as in} :invoice} value]
|
||||
@@ -188,12 +189,12 @@
|
||||
|
||||
deleted (set/difference existing-ids specified-ids)
|
||||
updated (map
|
||||
(fn [{:keys [id expense_account_id amount location]}]
|
||||
(fn [{:keys [id account_id amount location]}]
|
||||
{:db/id invoice-id
|
||||
:invoice/expense-accounts [#:invoice-expense-account {
|
||||
:amount (Double/parseDouble amount)
|
||||
:db/id id
|
||||
:expense-account-id expense_account_id
|
||||
:account account_id
|
||||
:location location}
|
||||
]}
|
||||
)
|
||||
|
||||
@@ -8,14 +8,15 @@
|
||||
[clojure.set :as set]))
|
||||
|
||||
|
||||
(defn upsert-vendor [context {{:keys [id name code print_as primary_contact secondary_contact address default_expense_account invoice_reminder_schedule] :as in} :vendor} value]
|
||||
(let [transaction [(remove-nils #:vendor {:db/id (if id
|
||||
(defn upsert-vendor [context {{:keys [id name code print_as primary_contact secondary_contact address default_account_id invoice_reminder_schedule] :as in} :vendor} value]
|
||||
(let [_ (println default_account_id)
|
||||
transaction [(remove-nils #:vendor {:db/id (if id
|
||||
id
|
||||
"vendor")
|
||||
:name name
|
||||
:code code
|
||||
:print-as print_as
|
||||
:default-expense-account default_expense_account
|
||||
:default-account default_account_id
|
||||
:invoice-reminder-schedule (keyword invoice_reminder_schedule)
|
||||
:address (when address
|
||||
(remove-nils #:address {:db/id (if (:id address)
|
||||
|
||||
@@ -45,14 +45,11 @@
|
||||
:journal-entry/line-items (into [{:journal-entry-line/account (a/get-account-by-numeric-code-and-sets 2110 ["default"])
|
||||
:journal-entry-line/credit (:invoice/total entity)}]
|
||||
(map (fn [ea]
|
||||
{:journal-entry-line/account (a/get-account-by-numeric-code-and-sets
|
||||
(:invoice-expense-account/expense-account-id ea)
|
||||
["default"])
|
||||
{:journal-entry-line/account (:db/id (:invoice-expense-account/account ea))
|
||||
:journal-entry-line/location (:invoice-expense-account/location ea)
|
||||
:journal-entry-line/debit (:invoice-expense-account/amount ea)})
|
||||
(:invoice/expense-accounts entity)))
|
||||
#_#_:general-ledger/from-expense-account 2110
|
||||
#_#_:general-ledger/to-expense-account (:invoice-expense-account/expense-account-id ea)
|
||||
|
||||
:journal-entry/cleared (and (< (:invoice/outstanding-balance entity) 0.01)
|
||||
(every? #(= :payment-status/cleared (:payment/status %)) (:invoice/payments entity))
|
||||
)})))
|
||||
@@ -76,8 +73,7 @@
|
||||
:journal-entry-line/location "HQ"
|
||||
:journal-entry-line/credit (Math/abs (:transaction/amount entity))}
|
||||
]
|
||||
#_#_:general-ledger/from-expense-account 2110
|
||||
#_#_:general-ledger/to-expense-account (:invoice-expense-account/expense-account-id ea)
|
||||
|
||||
:journal-entry/cleared true})))
|
||||
|
||||
(defmethod entity-change->ledger :invoice-expense-account
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
[auto-ap.entities.shared :as shared]))
|
||||
|
||||
(s/def ::vendor-id string?)
|
||||
(s/def ::expense-account-id int?)
|
||||
(s/def ::account-id string?)
|
||||
(s/def ::amount ::shared/money)
|
||||
(s/def ::location string?)
|
||||
|
||||
(s/def ::invoices-expense-account (s/keys :opt-un [::vendor-id ::expense-account-id ::amount ::location]))
|
||||
(s/def ::invoices-expense-account (s/keys :opt-un [::vendor-id ::account-id ::amount ::location]))
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
(s/def ::primary-contact (s/nilable ::contact/contact))
|
||||
(s/def ::secondary-contact (s/nilable ::contact/contact))
|
||||
(s/def ::address (s/nilable ::address/address))
|
||||
(s/def ::default-expense-account int?)
|
||||
(s/def ::default-account-id string?)
|
||||
|
||||
(s/def ::code (s/nilable string?))
|
||||
|
||||
(s/def ::vendor (s/keys :req-un [::name
|
||||
::default-expense-account]
|
||||
::default-account-id]
|
||||
:opt-un [::code
|
||||
::id
|
||||
::print-as
|
||||
|
||||
@@ -45,11 +45,11 @@
|
||||
[:id :name :code :email :locations [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id] ]
|
||||
[:address [:street1 :street2 :city :state :zip]]]]
|
||||
[:vendor
|
||||
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]
|
||||
[:accounts [:numeric-code :name :type :account_set :id]]]}
|
||||
[:id :name [:default-account [:name :id :location]] [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]
|
||||
[:accounts [:numeric-code :location :name :type :account_set :id]]]}
|
||||
:on-success [::received-initial]}}))))
|
||||
(def vendor-query
|
||||
[:id :name :default-expense-account
|
||||
[:id :name [:default-account [:name :id :location]]
|
||||
[:primary-contact [:name :phone :email :id]]
|
||||
[:secondary-contact [:id :name :phone :email]]
|
||||
:print-as :invoice-reminder-schedule :code
|
||||
@@ -67,8 +67,8 @@
|
||||
:query-obj {:venia/queries [[:client
|
||||
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id] ]]]
|
||||
[:vendor
|
||||
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]
|
||||
[:accounts [:numeric-code :name :type :account_set :id]]]}
|
||||
[:id :name [:default-account [:name :id :location]] [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]
|
||||
[:accounts [:numeric-code :name :location :type :account_set :id]]]}
|
||||
|
||||
:on-success [::received-initial]}
|
||||
:db (assoc db :user (assoc user :token token))}))
|
||||
|
||||
@@ -10,18 +10,14 @@
|
||||
|
||||
[bidi.bidi :as bidi]))
|
||||
|
||||
(def vendor-query
|
||||
[:id :name :default-expense-account
|
||||
[:primary-contact [:name :phone :email :id]]
|
||||
[:secondary-contact [:id :name :phone :email]]
|
||||
:print-as :invoice-reminder-schedule :code
|
||||
[:address [:street1 :street2 :city :state :zip]]])
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::edit
|
||||
(fn [{:keys [db]} [_ vendor-id]]
|
||||
{:db (assoc-in db [:admin :vendor]
|
||||
(get (:vendors db) vendor-id))
|
||||
(-> (get (:vendors db) vendor-id)
|
||||
(assoc :default-account-id (:id (:default-account (get (:vendors db) vendor-id))))))
|
||||
:dispatch [::events/modal-status :auto-ap.views.pages.admin.vendors/admin-vendor {:visible? true}]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
@@ -35,7 +31,8 @@
|
||||
::save
|
||||
(fn [{:keys [db]} _]
|
||||
(let [edited-vendor (get-in db [:admin :vendor])
|
||||
fx {:db (assoc-in db [:admin :vendor :saving?] true)}]
|
||||
fx {:db (assoc-in db [:admin :vendor :saving?] true)}
|
||||
_ (println "EDITED" edited-vendor)]
|
||||
(when (s/valid? ::entity/vendor edited-vendor)
|
||||
(assoc fx :graphql
|
||||
{:token (-> db :user)
|
||||
@@ -43,8 +40,9 @@
|
||||
:operation/name "UpsertVendor"}
|
||||
|
||||
:venia/queries [{:query/data [:upsert-vendor
|
||||
{:vendor edited-vendor}
|
||||
vendor-query]}]}
|
||||
{:vendor (-> edited-vendor
|
||||
(dissoc :default-account))}
|
||||
events/vendor-query]}]}
|
||||
:on-success [::save-complete]
|
||||
:on-error [::save-error]})))))
|
||||
|
||||
@@ -90,6 +88,7 @@
|
||||
(re-frame/reg-event-db
|
||||
::change
|
||||
(fn [db [_ path value]]
|
||||
(println path value)
|
||||
(assoc-in db (concat [:admin :vendor] path)
|
||||
value)))
|
||||
|
||||
@@ -112,7 +111,7 @@
|
||||
::mounted
|
||||
(fn [{:keys [db]} _]
|
||||
{:graphql {:token (:user db)
|
||||
:query-obj {:venia/queries [[:vendor vendor-query]]}
|
||||
:query-obj {:venia/queries [[:vendor events/vendor-query]]}
|
||||
:on-success [::received-vendors]}}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
(ns auto-ap.events.expense-accounts
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[reagent.core :as r]
|
||||
[clojure.string :as str]
|
||||
[clojure.spec.alpha :as s]
|
||||
[cljs-time.core :as c]
|
||||
[goog.string :as gstring]
|
||||
[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]
|
||||
[auto-ap.entities.invoices-expense-accounts :as invoices-expense-accounts]
|
||||
[auto-ap.views.utils :refer [dispatch-event bind-field horizontal-field date->str str->date pretty standard]]
|
||||
[auto-ap.utils :refer [by replace-if]]
|
||||
[auto-ap.events :as events]))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::change-expense-accounts
|
||||
(fn [{:keys [db]} [_ id]]
|
||||
{:dispatch [::events/modal-status ::change-expense-accounts {:visible? true}]
|
||||
:db (assoc-in db [::change-expense-accounts :invoice] (get (by :id (get-in db [::invoice-page :invoices])) id))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::change-expense-accounts-saving
|
||||
(fn [{:keys [db]} [_ id]]
|
||||
(let [{:keys [id expense-accounts]} (get-in db [::change-expense-accounts :invoice])]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "EditExpenseAccounts"}
|
||||
|
||||
:venia/queries [{:query/data [:edit-expense-accounts
|
||||
{:invoice-id id
|
||||
:expense-accounts (map (fn [ea] {:id (:id ea)
|
||||
:amount (:amount ea)
|
||||
:location (:location ea)
|
||||
:expense-account-id (:expense-account-id ea)})
|
||||
expense-accounts)}
|
||||
[:id :total :outstanding-balance :invoice-number :date
|
||||
[:vendor [:name :id]]
|
||||
[:expense_accounts [:amount :id :location :expense_account_id
|
||||
[:expense_account [:id :name [:parent [:id :name]]]]]]
|
||||
[:client [:name :id :locations]]
|
||||
[:checks [:amount [:check [:amount :s3_url :check_number ]]]]
|
||||
]]}]}
|
||||
:on-success [::expense-accounts-updated]}})))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::expense-accounts-updated
|
||||
(fn [{:keys [db]} [_ data]]
|
||||
(let [updated (:edit-expense-accounts data)]
|
||||
{:dispatch [::events/modal-completed ::change-expense-accounts]
|
||||
:db (-> db
|
||||
(update-in [::invoice-page :invoices]
|
||||
|
||||
(fn [is]
|
||||
|
||||
(replace-if #(= (:id %1) (:id %2)) updated is)))
|
||||
(dissoc ::change-expense-accounts))})))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::add-expense-account-split
|
||||
(fn [db _]
|
||||
(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)}))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::remove-expense-account-split
|
||||
(fn [db [_ index]]
|
||||
(update-in db [::change-expense-accounts :invoice :expense-accounts]
|
||||
(fn [expense-accounts]
|
||||
(vec (concat (take index expense-accounts)
|
||||
(drop (inc index) expense-accounts)))))))
|
||||
@@ -20,11 +20,25 @@
|
||||
(fn [db]
|
||||
(:accounts db)))
|
||||
|
||||
|
||||
(re-frame/reg-sub
|
||||
::account
|
||||
:<- [::accounts]
|
||||
(fn [as [_ i]]
|
||||
(first (filter
|
||||
#(= (:id %) i)
|
||||
as))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::accounts-for-client
|
||||
(fn [db client]
|
||||
(:accounts db)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::accounts-for-current-client
|
||||
(fn [db]
|
||||
(:accounts db)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::bank-accounts
|
||||
:<- [::clients]
|
||||
@@ -132,9 +146,9 @@
|
||||
|
||||
(re-frame/reg-sub
|
||||
::chooseable-expense-accounts
|
||||
(fn [db]
|
||||
(map (fn [[k v]] (assoc v :id k))
|
||||
chooseable-expense-accounts)))
|
||||
:<- [::accounts-for-current-client]
|
||||
(fn [accounts]
|
||||
accounts))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::page-failure
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
(re-frame/reg-sub
|
||||
::expense-account
|
||||
:<- [::change-expense-accounts]
|
||||
(fn [{{:keys [expense-accounts] :or {expense-accounts [] }} :invoice} [_ expense-account-id]]
|
||||
(first (filter #(= expense-account-id (:id %)) expense-accounts))))
|
||||
(fn [{{:keys [expense-accounts] :or {expense-accounts [] }} :invoice} [_ invoice-expense-account-id]]
|
||||
(first (filter #(= invoice-expense-account-id (:id %)) expense-accounts))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::change-expense-accounts
|
||||
@@ -89,12 +89,12 @@
|
||||
)
|
||||
:amount (:new-amount ea)
|
||||
:location (:location ea)
|
||||
:expense-account-id (:expense-account-id ea)})
|
||||
:account-id (:id (:account ea))})
|
||||
expense-accounts)}
|
||||
[:id :total :outstanding-balance :invoice-number :date :status
|
||||
[:vendor [:name :id]]
|
||||
[:expense_accounts [:amount :id :location :expense_account_id
|
||||
[:expense_account [:id :name [:parent [:id :name]]]]]]
|
||||
[:account [:id :name :numeric-code :location]]]]
|
||||
[:client [:name :id :locations]]
|
||||
[:payments [:amount :id [:payment [:amount :s3_url :check_number ]]]]]]}]}
|
||||
:on-success on-success}})))
|
||||
@@ -104,7 +104,7 @@
|
||||
(fn [db _]
|
||||
(let [{{{:keys [locations]} :client} :invoice} @(re-frame/subscribe [::change-expense-accounts])]
|
||||
(update-in db [::change-expense-accounts :invoice :expense-accounts]
|
||||
conj {:amount "0.0" :id (str "new-" (random-uuid)) :expense-account-id {} :location (first locations)}))))
|
||||
conj {:amount "0.0" :id (str "new-" (random-uuid)) :account {} :location (first locations)}))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::remove-expense-account-split
|
||||
@@ -148,21 +148,22 @@
|
||||
[:th {:style {:width "5em"}}]]]
|
||||
[:tbody
|
||||
(doall (for [{:keys [id] :as expense-account} expense-accounts
|
||||
:let [sub @(re-frame/subscribe [::expense-account (:id expense-account)])]]
|
||||
:let [sub @(re-frame/subscribe [::expense-account (:id expense-account)])
|
||||
_ (println "SUBB" sub)]]
|
||||
^{:key id}
|
||||
[:tr
|
||||
[:td.expandable [:div.control
|
||||
[bind-field
|
||||
[typeahead {:matches (map (fn [x] [(:id x) (str (:id x) " - " (:name x))]) chooseable-expense-accounts)
|
||||
[typeahead {:matches (map (fn [x] [(:id x) (str (:numeric-code x) " - " (:name x))]) chooseable-expense-accounts)
|
||||
:type "typeahead"
|
||||
:field [:expense-account-id]
|
||||
:field [:account :id]
|
||||
:event [::change id]
|
||||
:spec ::invoices-expense-accounts/expense-account-id
|
||||
:spec ::invoices-expense-accounts/account-id
|
||||
:subscription sub}]]]]
|
||||
|
||||
(when multi-location?
|
||||
[:td
|
||||
(if-let [forced-location (-> expense-account :expense-account-id expense-accounts/expense-accounts :location)]
|
||||
(if-let [forced-location (:location @(re-frame/subscribe [::subs/account (-> sub :account :id )]))]
|
||||
[:div.select
|
||||
[:select {:disabled "disabled" :value forced-location} [:option {:value forced-location} forced-location]]]
|
||||
[:div.select
|
||||
|
||||
@@ -49,8 +49,8 @@
|
||||
:client-id (:id @(re-frame/subscribe [::subs/client])))
|
||||
[[:invoices [:id :total :outstanding-balance :invoice-number :date :status
|
||||
[:vendor [:name :id]]
|
||||
[:expense_accounts [:amount :id :expense_account_id :location
|
||||
[:expense_account [:id :name :location [:parent [:id :name]]]]]]
|
||||
[:expense_accounts [:amount :id :location
|
||||
[:account [:id :name :numeric-code :location ]]]]
|
||||
[:client [:name :id :locations]]
|
||||
[:payments [:amount :id [:payment [:id :status :amount :s3_url :check_number
|
||||
[:transaction [:post_date]]]]]]]]
|
||||
@@ -182,7 +182,7 @@
|
||||
[:div
|
||||
(for [e expense-accounts]
|
||||
^{:key (:id e)}
|
||||
[:span.dropdown-item (:name (:expense-account e)) " " (gstring/format "$%.2f" (:amount e) ) ])
|
||||
[:span.dropdown-item (:name (:account e)) " " (gstring/format "$%.2f" (:amount e) ) ])
|
||||
|
||||
[:hr.dropdown-divider]
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
[auto-ap.subs :as subs]))
|
||||
|
||||
(defn vendor-dialog [{:keys [vendor save-event change-event id] {:keys [name]} :vendor}]
|
||||
(println (s/explain ::entity/vendor vendor) )
|
||||
(let [clients-by-id @(re-frame/subscribe [::subs/clients-by-id])]
|
||||
(let [clients-by-id @(re-frame/subscribe [::subs/clients-by-id])
|
||||
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts]) ]
|
||||
[action-modal {:id id
|
||||
:title [:span (if (:id vendor)
|
||||
(str "Edit " (or name "<vendor>"))
|
||||
@@ -51,23 +51,12 @@
|
||||
[horizontal-field
|
||||
[:label.label "Default"]
|
||||
[bind-field
|
||||
[typeahead {:matches (map (fn [[k v]] [k (:name v)]) chooseable-expense-accounts)
|
||||
[typeahead {:matches (map (fn [x] [(:id x) (str (:numeric-code x) " - " (:name x))]) chooseable-expense-accounts)
|
||||
:type "typeahead"
|
||||
:field [:default-expense-account]
|
||||
:spec ::entity/default-expense-account
|
||||
:field [:default-account-id]
|
||||
:event change-event
|
||||
:subscription vendor}]]]
|
||||
#_[horizontal-field
|
||||
[:label.label "Code"]
|
||||
[:div.control
|
||||
|
||||
[bind-field
|
||||
[:input.input.is-expanded {:type "text"
|
||||
:field :code
|
||||
:spec ::entity/code
|
||||
:event change-event
|
||||
:subscription vendor}]]
|
||||
[:p.help "The vendor code is used for invoice parsing. Only one vendor at a time can use a code"]]]
|
||||
|
||||
|
||||
[:h2.subtitle "Address"]
|
||||
[address-field {:field [:address]
|
||||
@@ -163,11 +152,4 @@
|
||||
:event change-event
|
||||
:subscription vendor}]]
|
||||
" Never"]]]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(when (:saving? vendor) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]))
|
||||
|
||||
@@ -54,17 +54,13 @@
|
||||
(take 5))
|
||||
top-5 (vec (take 5 expense-account-stats))
|
||||
rest (drop 5 expense-account-stats)
|
||||
other {:expense-account-id 0 :expense-account-name "Other" :total (reduce + 0 (map :total rest))}]
|
||||
other {:account {:id 0 :name "Other"} :total (reduce + 0 (map :total rest))}]
|
||||
(cond-> db
|
||||
(seq top-5)
|
||||
(assoc ::top-expense-categories (conj top-5 other))
|
||||
|
||||
(seq invoice-stats)
|
||||
(assoc ::invoice-stats invoice-stats)
|
||||
|
||||
|
||||
)
|
||||
)))
|
||||
(assoc ::invoice-stats invoice-stats)))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::invoice-stats
|
||||
@@ -84,7 +80,7 @@
|
||||
:graphql {:token (-> db :user)
|
||||
:query-obj {:venia/queries [[:expense_account_stats
|
||||
{:client-id (:id @(re-frame/subscribe [::subs/client]))}
|
||||
[:expense-account-id :total :expense-account-name]]
|
||||
[[:account [:id :name]] :total]]
|
||||
[:invoice_stats
|
||||
{:client-id (:id @(re-frame/subscribe [::subs/client]))}
|
||||
[:name :paid :unpaid]]]}
|
||||
@@ -98,7 +94,7 @@
|
||||
[:h1.title.is-4 "Top expense categories"]
|
||||
(let [expense-categories @(re-frame/subscribe [::top-expense-categories])]
|
||||
(make-pie-chart {:width 800 :height 500 :data (clj->js
|
||||
(map (fn [x] {:name (:expense-account-name x) :value (:total x)}) expense-categories))}))
|
||||
(map (fn [x] {:name (:name (:account x)) :value (:total x)}) expense-categories))}))
|
||||
[:h1.title.is-4 "Upcoming Bills"]
|
||||
(make-bar-chart {:width 800 :height 500 :data (clj->js
|
||||
@(re-frame/subscribe [::invoice-stats]))})]}]))
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
(on-params-change (merge @params p)))}]
|
||||
"Showing " (inc start) "-" end "/" total
|
||||
|
||||
[:table.table.is-fullwidth
|
||||
[:table.table.is-fullwidth.compact
|
||||
[:thead
|
||||
[:tr
|
||||
(when-not selected-client
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
(fn [{:keys [db]} [_ edit-completed]]
|
||||
(when @(re-frame/subscribe [::can-submit])
|
||||
(let [{{:keys [id vendor-id account-id]} :data :as data} @(re-frame/subscribe [::forms/form ::edit-transaction])]
|
||||
(println "DATA" data)
|
||||
{:db (forms/loading db ::edit-transaction )
|
||||
:graphql
|
||||
{:token (-> db :user)
|
||||
|
||||
@@ -32,9 +32,9 @@
|
||||
[:client [:id :name :locations]]
|
||||
[:payments [:amount [:payment [:amount :s3_url :check_number ]]]]
|
||||
[:vendor [:id :name]]
|
||||
[:expense_accounts [:amount :id :expense_account_id
|
||||
[:expense_accounts [:amount :id
|
||||
:location
|
||||
[:expense_account [:id :name [:parent [:id :name]]]]]]])
|
||||
[:account [:id :numeric-code :name :location]]]]])
|
||||
|
||||
(defn does-amount-exceed-outstanding? [amount outstanding-balance]
|
||||
(let [amount (js/parseFloat amount)
|
||||
@@ -819,10 +819,10 @@
|
||||
[:div
|
||||
[:h2.subtitle "Expense Accounts"]
|
||||
|
||||
(for [[index {:keys [id location expense-account-id] :as expense-account}] (map vector (range) (:expense-accounts data))]
|
||||
(for [[index {:keys [id location] :as expense-account {account-id :id account-numeric-code :numeric-code account-name :name} :account}] (map vector (range) (:expense-accounts data))]
|
||||
^{:key id}
|
||||
[:div.columns
|
||||
[:div.column expense-account-id " - "(-> expense-account-id expense-accounts/expense-accounts :name)]
|
||||
[:div.column account-numeric-code " - " account-name]
|
||||
|
||||
(when multi-location?
|
||||
[:div.column location])
|
||||
|
||||
Reference in New Issue
Block a user