This commit is contained in:
Bryce Covert
2020-06-14 08:29:23 -07:00
parent ad4054d820
commit bd17cd3caa
9 changed files with 126 additions and 70 deletions

View File

@@ -67,6 +67,12 @@
'[?li :journal-entry-line/account ?a]]} '[?li :journal-entry-line/account ?a]]}
:args [(:bank-account-id args)]}) :args [(:bank-account-id args)]})
(:account-id args)
(merge-query {:query {:in ['?a2]
:where ['[?e :journal-entry/line-items ?li2]
'[?li2 :journal-entry-line/account ?a2]]}
:args [(:account-id args)]})
(:to-numeric-code args) (:to-numeric-code args)
(merge-query {:query {:in ['?to-numeric-code] (merge-query {:query {:in ['?to-numeric-code]
:where ['[?e :journal-entry/line-items ?li] :where ['[?e :journal-entry/line-items ?li]

View File

@@ -460,6 +460,7 @@
:ledger_page {:type :ledger_page :ledger_page {:type :ledger_page
:args {:client_id {:type :id} :args {:client_id {:type :id}
:vendor_id {:type :id} :vendor_id {:type :id}
:account_id {:type :id}
:bank_account_id {:type :id} :bank_account_id {:type :id}
:date_range {:type :date_range} :date_range {:type :date_range}
:location {:type 'String} :location {:type 'String}

View File

@@ -116,12 +116,14 @@
(into (into
[:cell {:colspan 9}] [:cell {:colspan 9}]
(let [{:keys [:client/name] (let [{:keys [:client/name]
{:keys [:address/street1 :address/city :address/state :address/zip ]} :client/address} client] {:keys [:address/street1 :address/street2 :address/city :address/state :address/zip ]} :client/address} client]
(list (filter identity
[:paragraph " " name] (list
[:paragraph " " street1] [:paragraph " " name]
[:paragraph " " city ", " state " " zip] [:paragraph " " street1]
))) (when (not (str/blank? street2))
[:paragraph " " street2])
[:paragraph " " city ", " state " " zip]))))
[:cell {:colspan 2 :size 13} [:cell {:colspan 2 :size 13}
check]] check]]
@@ -131,6 +133,9 @@
[:cell {:colspan 5} [:paragraph [:cell {:colspan 5} [:paragraph
" " vendor-name "\n" " " vendor-name "\n"
" " (:address/street1 (:vendor/address vendor)) "\n" " " (:address/street1 (:vendor/address vendor)) "\n"
(when (not (str/blank? (:address/street2 (:vendor/address vendor))))
(str " " (:address/street2 (:vendor/address vendor)) "\n")
)
" " (:address/city (:vendor/address vendor)) ", " (:address/state (:vendor/address vendor)) " " (:address/zip (:vendor/address vendor))]] " " (:address/city (:vendor/address vendor)) ", " (:address/state (:vendor/address vendor)) " " (:address/zip (:vendor/address vendor))]]
[:cell {:align :right} [:cell {:align :right}
"Paid to:\n" "Paid to:\n"

View File

@@ -104,8 +104,9 @@
[comparable-results] (l/get-graphql {:client-id (:client_id args) [comparable-results] (l/get-graphql {:client-id (:client_id args)
:to-date (coerce/to-date (time/minus (:date args) (time/years 1))) :date-range {:end (coerce/to-date (time/minus (:date args) (time/years 1)))}
:count Integer/MAX_VALUE})] :count Integer/MAX_VALUE})]
(println "count" (take 3 comparable-results))
(->graphql (->graphql
{:balance-sheet-accounts (roll-up client results) {:balance-sheet-accounts (roll-up client results)
:comparable-balance-sheet-accounts (roll-up client comparable-results)}))) :comparable-balance-sheet-accounts (roll-up client comparable-results)})))

View File

@@ -45,6 +45,10 @@
(comp (drop 1) (comp (drop 1)
(map (fn [row] (map (fn [row]
(into {} (map vector header row)))) (into {} (map vector header row))))
(filter (fn [row]
(and (not (str/blank? (get row "Invoice Date")))
(not (str/blank? (get row "Orig Amt")))
(not (str/blank? (get row "Inv #"))))))
(map (fn [row] (map (fn [row]
{:vendor-code nil {:vendor-code nil
:customer-identifier nil :customer-identifier nil

View File

@@ -176,15 +176,15 @@
;; Young's Market Co new statement ;; Young's Market Co new statement
{:vendor "Youngs Market" {:vendor "Youngs Market"
:keywords [#"YOUNG'S MARKET COMPANY"] :keywords [#"(YOUNG'S MARKET COMPANY|Young.*Statement)"]
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)" :extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"SHIP TO SITE: ([\w ]+)" :customer-identifier #"Customer Name +([\w ]+)"
:invoice-number #"^([0-9]+)" :invoice-number #"\s{2,}([0-9]+)"
:total #"\$([0-9\.,]+)"} :total #"\$?([0-9,]+\.[0-9]+)"}
:parser {:date [:clj-time "MM/dd/yyyy"] :parser {:date [:clj-time "MM/dd/yyyy"]
:total [:trim-commas nil]} :total [:trim-commas nil]}
:multi #"\n" :multi #"\n"
:multi-match? #"^[0-9]+"} :multi-match? #"^[0-9]+.*\$?([0-9,]+\.[0-9]+).*\$?([0-9,]+\.[0-9]+)"}
;; Young's Market Co - INVOICE ;; Young's Market Co - INVOICE
{:vendor "Youngs Market" {:vendor "Youngs Market"

View File

@@ -39,7 +39,6 @@
:<- [::side-bar/filter-params] :<- [::side-bar/filter-params]
:<- [::table/table-params] :<- [::table/table-params]
(fn [[last-params client filter-params table-params]] (fn [[last-params client filter-params table-params]]
(println "HERE?")
(let [params (cond-> {} (let [params (cond-> {}
client (assoc :client-id (:id client)) client (assoc :client-id (:id client))
(seq filter-params) (merge filter-params) (seq filter-params) (merge filter-params)
@@ -76,7 +75,8 @@
:total :total
:start :start
:end]]]} :end]]]}
:on-success [::received]}})) :on-success [::received]}
:set-uri-params (dissoc params :status :client-id)}))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::unmounted ::unmounted

View File

@@ -9,11 +9,12 @@
[cljs-time.core :as t] [cljs-time.core :as t]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
(def ranges (def ranges
{:sales [41000 48999] {:sales [40000 48999]
:cogs [51000 59999] :cogs [50000 59999]
:payroll [60100 62999] :payroll [60000 62999]
:controllable [71000 79999] :controllable [70000 79999]
:noncontrollable [81000 99999]}) :fixed-overhead [80000 89999]
:ownership-controllable [90000 99999]})
;; SUBS ;; SUBS
(re-frame/reg-sub (re-frame/reg-sub
@@ -31,7 +32,9 @@
(filter identity) (filter identity)
(set) (set)
(sort)))) (sort-by (fn [x] (if (= x "HQ" )
"ZZZZZZ"
x))))))
(re-frame/reg-sub (re-frame/reg-sub
::report ::report
@@ -78,7 +81,7 @@
(filter (fn [{:keys [account-type location numeric-code]}] (filter (fn [{:keys [account-type location numeric-code]}]
(and (or (nil? only-location) (and (or (nil? only-location)
(= only-location location)) (= only-location location))
(< (get-in ranges [type 0]) numeric-code (get-in ranges [type 1]))))) (<= (get-in ranges [type 0]) numeric-code (get-in ranges [type 1])))))
(sort-by :numeric-code)))) (sort-by :numeric-code))))
@@ -94,7 +97,7 @@
(filter (fn [{:keys [account-type location numeric-code]}] (filter (fn [{:keys [account-type location numeric-code]}]
(and (or (nil? only-location) (and (or (nil? only-location)
(= only-location location)) (= only-location location))
(< (get-in ranges [type 0]) numeric-code (get-in ranges [type 1]))))) (<= (get-in ranges [type 0]) numeric-code (get-in ranges [type 1])))))
(by :id)))) (by :id))))
(re-frame/reg-sub (re-frame/reg-sub
@@ -107,7 +110,7 @@
(filter (fn [{:keys [account-type location numeric-code]}] (filter (fn [{:keys [account-type location numeric-code]}]
(and (or (nil? only-location) (and (or (nil? only-location)
(= only-location location)) (= only-location location))
(< (get-in ranges [type 0]) numeric-code (get-in ranges [type 1]))))) (<= (get-in ranges [type 0]) numeric-code (get-in ranges [type 1])))))
(by :id)))) (by :id))))
(re-frame/reg-event-db (re-frame/reg-event-db
@@ -227,45 +230,41 @@
standard))})]})) standard))})]}))
(def groupings (def groupings
{:sales [["4000-4099 HQ Income" 4000 4099] {:sales [["40000-43999 Food Sales " 40000 43999]
["4100-4200 Food Sales" 4100 4399] ["44000-46999 Alcohol Sales" 44000 46999]
["4400-4600 Alcohol Sales" 4400 4699] ["47000 Merchandise Sales" 47000 47999]
["4700 Merchandise Sales" 4700 4799] ["48000 Other Operating Income" 48000 48999]
["4800 Other Operating Income" 4800 4999]] ["49000 Non-Business Income" 49000 49999]]
:cogs [["5000-5099 Unassigned COGS" 5000 5099] :cogs [
["5100-5200 Food Costs" 5100 5399] ["50000-54000 Food Costs" 50000 53999]
["5400-5600 Alcohol Cost" 5400 5699] ["54000-56000 Alcohol Costs" 54000 55999]
["5700 Merchandise Cost" 5700 5799] ["56000 Merchandise Costs" 56000 56999]
["5800 Other Operating Cost" 5800 5899] ["57000-60000 Other Costs of Sales" 57000 59999]]
["5900 Paper Cost" 5900 5999]] :payroll [["60000 Payroll - General" 60000 60999]
:payroll [["6010 HQ Payroll" 6000 6029] ["61000 Payroll - Management" 61000 61999]
["6030 Payroll Benefits and Taxes" 6030 6099] ["62000 Payroll - BOH" 62000 62999]
["6100 Management Payroll" 6100 6199] ["63000-66000 Payroll - FOH" 63000 65999]
["6200 Staff Payroll" 6200 6999]] ["66000-70000 Payroll - Other" 66000 69999]]
:controllable [["7100 Ops Related DirGMC Exp" 7000 7199] :controllable [["70000 72000 GM Controllable Costs - Ops Related" 70000 71999]
["7200 Customer Related DirGMC Exp" 7200 7299] ["72000 GM Controllable Costs - Customer Related" 72000 72999]
["7300 Employee Related DirGMC Exp" 7300 7399] ["73000 GM Controllable Costs - Employee Related" 73000 73999]
["7400 Building and Equipment Related DirGMC Exp" 7400 7499] ["74000 GM Controllable Costs - Building & Equipment Related" 74000 74999]
["7500 Office/ Management Related DirGMC Exp" 7500 7599] ["75000 GM Controllable Costs - Office & Management Related" 75000 75999]
["7600 Other Controllable DirGMC Exp" 7600 7999]] ["76000-80000 GM Controllable Costs - Other" 76000 79999]]
:noncontrollable [["8100 Operational" 8000 8199] :fixed-overhead [["80000-82000 Operational Costs" 80000 81999]
["8200 Occupancy Costs" 8200 8299] ["82000 Occupancy Costs" 82000 82999]
["8300 Utilities" 8300 8399] ["83000 Utility Costs" 83000 83999]
["8400 Equipment Rental" 8400 8499] ["84000 Equipment Rental" 84000 84999]
["8500-8700 Taxes and Insurance" 8500 8799] ["85000-87000 Taxes & Insurance" 85000 86999]
["8800 Depreciation" 8800 8899] ["87000-90000 Other Non-Controllable Costs" 87000 89999]]
["8900 Other Non-Controllable" 8900 8999] :ownership-controllable [["90000-93000 Research & Entertainment" 90000 92999]
["9100 Promotion and Outreach" 9000 9199] ["93000 Bank Charges & Interest" 93000 93999]
["9200 Employee Morale and Training" 9200 9299] ["94000-96000 Other Owner Controllable Costs" 94000 95999]
["9300 Operational" 9300 9499] ["96000 Depreciation" 96000 96999]
["9500 Interest and Bank Expenses" 9500 9599] ["97000 Taxes" 97000 97999]
["9600 Depreciation" 9600 9699] ["98000 Other Expenses" 98000 98999]]})
["9700 Taxes" 9700 9799]
["9800 Other Expenses" 9800 9899]
;; ["9900 Tax Only Expenses" 9900 9999] Excluded from Profit and loss
]})
@@ -509,10 +508,11 @@
(subtotal [:payroll :cogs] #{} (str location " Prime Costs") location) (subtotal [:payroll :cogs] #{} (str location " Prime Costs") location)
(subtotal [:sales :payroll :cogs] #{:payroll :cogs} (str location " Gross Profits") location) (subtotal [:sales :payroll :cogs] #{:payroll :cogs} (str location " Gross Profits") location)
(overall-grouping :controllable (str location " Controllable Expenses") location) (overall-grouping :controllable (str location " Controllable Expenses") location)
(overall-grouping :noncontrollable (str location " Noncontrallable Expenses") location) (overall-grouping :fixed-overhead (str location " Fixed Overhead") location)
(subtotal [:controllable :noncontrollable] #{} (str location " Overhead") location) (overall-grouping :ownership-controllable (str location " Ownership Controllable") location)
(subtotal [:sales :cogs :payroll :controllable :noncontrollable] #{:cogs :payroll :controllable :noncontrollable} (str location " Net Income") location) (subtotal [:controllable :fixed-overhead :ownership-controllable] #{} (str location " Overhead") location)
(subtotal [:sales :cogs :payroll :controllable :noncontrollable] #{:cogs :payroll :controllable :noncontrollable} "Net Income" nil))))]])]))) (subtotal [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable] #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable} (str location " Net Income") location)
(subtotal [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable] #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable} "Net Income" nil))))]])])))
{:component-will-mount #(re-frame/dispatch-sync [::params-change {:from-date (date->str (t/minus (local-now) (t/period :years 1)) standard) {:component-will-mount #(re-frame/dispatch-sync [::params-change {:from-date (date->str (t/minus (local-now) (t/period :years 1)) standard)
:to-date (date->str (local-now) standard)}]) })) :to-date (date->str (local-now) standard)}]) }))

View File

@@ -9,10 +9,38 @@
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
(re-frame/reg-sub (re-frame/reg-sub
::filters ::specific-filters
(fn [db ] (fn [db ]
(::filters db {}))) (::filters db {})))
(re-frame/reg-sub
::filters
:<- [::specific-filters]
:<- [::subs/vendors-by-id]
:<- [::subs/bank-accounts-by-id]
:<- [::subs/accounts-by-id]
:<- [::subs/query-params]
(fn [[specific-filters vendors-by-id bank-accounts-by-id accounts-by-id query-params] ]
(let [url-filters (-> query-params
(select-keys #{:vendor-id
:bank-account-id
:account-id
:date-range}))
url-filters {:vendor (when-let [vendor-id (:vendor-id url-filters)]
{:id (str vendor-id)
:name (get-in vendors-by-id [(str vendor-id) :name] "Loading...")})
:bank-account (when-let [bank-account-id (:bank-account-id url-filters)]
{:id (str bank-account-id)
:name (get-in bank-accounts-by-id [(str bank-account-id) :name] "Loading...")})
:account (when-let [account-id (:account-id url-filters)]
{:id (str account-id)
:numeric-code (get-in accounts-by-id [(str account-id) :numeric-code] "Loading...")
:name (get-in accounts-by-id [(str account-id) :name] "Loading...")})
:date-range (:date-range url-filters)}]
(println url-filters specific-filters)
(merge url-filters specific-filters ))))
(re-frame/reg-sub (re-frame/reg-sub
::filter ::filter
:<- [::filters] :<- [::filters]
@@ -24,6 +52,7 @@
:<- [::filters] :<- [::filters]
(fn [filters] (fn [filters]
{:vendor-id (:id (:vendor filters)) {:vendor-id (:id (:vendor filters))
:account-id (:id (:account filters))
:date-range (:date-range filters) :date-range (:date-range filters)
:bank-account-id (:id (:bank-account filters))})) :bank-account-id (:id (:bank-account filters))}))
@@ -39,7 +68,8 @@
(defn ledger-side-bar [] (defn ledger-side-bar []
(let [ap @(re-frame/subscribe [::subs/active-page]) (let [ap @(re-frame/subscribe [::subs/active-page])
user @(re-frame/subscribe [::subs/user])] user @(re-frame/subscribe [::subs/user])
accounts @(re-frame/subscribe [::subs/accounts])]
[:div [:div
[:ul.menu-list [:ul.menu-list
[:li.menu-item [:li.menu-item
@@ -69,10 +99,11 @@
[:div [:div
[:p.menu-label "Bank Account"] [:p.menu-label "Bank Account"]
[:div [:div
[bank-account-filter [typeahead-entity {:matches @(re-frame/subscribe [::subs/bank-accounts])
{:on-change-event [::filter-changed :bank-account] :match->text :name
:value @(re-frame/subscribe [::filter :bank-account]) :type "typeahead-entity"
:bank-accounts @(re-frame/subscribe [::subs/bank-accounts])}]] :on-change #(re-frame/dispatch [::filter-changed :bank-account %])
:value @(re-frame/subscribe [::filter :bank-account])}]]
[:p.menu-label "Vendor"] [:p.menu-label "Vendor"]
[:div [:div
@@ -81,6 +112,14 @@
:match->text :name :match->text :name
:type "typeahead-entity" :type "typeahead-entity"
:value @(re-frame/subscribe [::filter :vendor])}]] :value @(re-frame/subscribe [::filter :vendor])}]]
[:p.menu-label "Account"]
[:div
[typeahead-entity {:matches accounts
:match->text (fn [x ] (str (:numeric-code x) " - " (:name x)))
:type "typeahead-entity"
:on-change #(re-frame/dispatch [::filter-changed :account %])
:value @(re-frame/subscribe [::filter :account])}]]
[:p.menu-label "Date Range"] [:p.menu-label "Date Range"]
[:div [:div
[date-range-filter [date-range-filter