weekly debits/credits.

This commit is contained in:
Bryce Covert
2020-05-30 11:49:21 -07:00
parent 3101dd1fe6
commit bb2df01d89
9 changed files with 140 additions and 56 deletions

View File

@@ -67,6 +67,8 @@
{:fields {:id {:type :id} {:fields {:id {:type :id}
:name {:type 'String} :name {:type 'String}
:code {:type 'String} :code {:type 'String}
:weekly_debits {:type :money}
:weekly_credits {:type :money}
:email {:type 'String} :email {:type 'String}
:address {:type :address} :address {:type :address}
:location_matches {:type '(list :location_match)} :location_matches {:type '(list :location_match)}
@@ -520,6 +522,8 @@
:name {:type 'String} :name {:type 'String}
:code {:type 'String} :code {:type 'String}
:email {:type 'String} :email {:type 'String}
:weekly_credits {:type :money}
:weekly_debits {:type :money}
:address {:type :add_address} :address {:type :add_address}
:locations {:type '(list String)} :locations {:type '(list String)}
:matches {:type '(list String)} :matches {:type '(list String)}
@@ -900,7 +904,8 @@
(defn get-cash-flow [context {:keys [client_id]} value] (defn get-cash-flow [context {:keys [client_id]} value]
(when client_id (when client_id
(let [total-cash (reduce (let [{:client/keys [weekly-credits weekly-debits ]} (doto (d/pull (d/db (d/connect uri)) '[*] client_id ) println)
total-cash (reduce
(fn [total [credit debit]] (fn [total [credit debit]]
(- (+ total credit) (- (+ total credit)
debit)) debit))
@@ -921,7 +926,7 @@
'[?i :invoice/due ?due] '[?i :invoice/due ?due]
'[(<= ?due ?due-before)] '[(<= ?due ?due-before)]
'[?i :invoice/outstanding-balance ?outstanding]]} '[?i :invoice/outstanding-balance ?outstanding]]}
:args [(d/db (d/connect uri)) client_id (coerce/to-date (t/plus (time/local-now) (t/days 7)))]}) :args [(d/db (d/connect uri)) client_id (coerce/to-date (t/plus (time/local-now) (t/days 31)))]})
outstanding-checks (reduce outstanding-checks (reduce
+ +
0.0 0.0
@@ -933,21 +938,23 @@
'(or '(or
[?p :payment/type :payment-type/debit] [?p :payment/type :payment-type/debit]
[?p :payment/type :payment-type/check])]} [?p :payment/type :payment-type/check])]}
:args [(d/db (d/connect uri)) client_id (coerce/to-date (t/plus (auto-ap.time/local-now) (t/days 7)))]})))] :args [(d/db (d/connect uri)) client_id (coerce/to-date (t/plus (auto-ap.time/local-now) (t/days 31)))]})))]
{:beginning_balance total-cash {:beginning_balance total-cash
:outstanding_payments outstanding-checks :outstanding_payments outstanding-checks
:invoices_due_soon (mapv (fn [[due outstanding]] :invoices_due_soon (mapv (fn [[due outstanding]]
{:due (coerce/to-date-time due) {:due (coerce/to-date-time due)
:outstanding_balance outstanding}) :outstanding_balance outstanding})
bills-due-soon) bills-due-soon)
:upcoming_credits [{:amount 350000.23 :upcoming_credits (mapv
:date (coerce/to-date-time (t/plus (auto-ap.time/local-now) (t/days 0)))} (fn [date]
{:amount 105000.23 {:amount (or weekly-credits 0)
:date (coerce/to-date-time (t/plus (auto-ap.time/local-now) (t/days 3)))}] :date (coerce/to-date-time date)})
:upcoming_debits [{:amount -120000.23 (take 5 (auto-ap.time/day-of-week-seq 1)))
:date (coerce/to-date-time (t/plus (auto-ap.time/local-now) (t/days 5)))} :upcoming_debits (mapv
{:amount -35000.23 (fn [date]
:date (coerce/to-date-time (t/plus (auto-ap.time/local-now) (t/days 4)))}]}))) {:amount (- (or weekly-debits 0))
:date (coerce/to-date-time date)})
(take 5 (auto-ap.time/day-of-week-seq 1)))})))
(def schema (def schema
(-> integreat-schema (-> integreat-schema

View File

@@ -27,45 +27,47 @@
(mapv (fn [lm] [:db/retractEntity (:db/id lm)]) (:client/location-matches client)) (mapv (fn [lm] [:db/retractEntity (:db/id lm)]) (:client/location-matches client))
(mapv (fn [m] [:db/retract (:db/id client) :client/matches m]) (:client/matches client))))) (mapv (fn [m] [:db/retract (:db/id client) :client/matches m]) (:client/matches client)))))
transactions [(remove-nils {:db/id id transactions [(remove-nils {:db/id id
:client/code (if (str/blank? (:client/code client)) :client/code (if (str/blank? (:client/code client))
(:code edit_client) (:code edit_client)
(:client/code client)) (:client/code client))
:client/name (:name edit_client) :client/name (:name edit_client)
:client/matches (:matches edit_client) :client/matches (:matches edit_client)
:client/email (:email edit_client) :client/email (:email edit_client)
:client/locations (filter identity (:locations edit_client)) :client/locations (filter identity (:locations edit_client))
:client/weekly-debits (:weekly_debits edit_client)
:client/weekly-credits (:weekly_credits edit_client)
:client/location-matches (->> (:location_matches edit_client) :client/location-matches (->> (:location_matches edit_client)
(filter (fn [lm] (and (:location lm) (:match lm)))) (filter (fn [lm] (and (:location lm) (:match lm))))
(map (fn [lm] {:location-match/location (:location lm) (map (fn [lm] {:location-match/location (:location lm)
:location-match/matches [(:match lm)]}))) :location-match/matches [(:match lm)]})))
:client/address (remove-nils { :client/address (remove-nils {
:address/street1 (:street1 (:address edit_client)) :address/street1 (:street1 (:address edit_client))
:address/street2 (:street2 (:address edit_client)) :address/street2 (:street2 (:address edit_client))
:address/city (:city (:address edit_client)) :address/city (:city (:address edit_client))
:address/state (:state (:address edit_client)) :address/state (:state (:address edit_client))
:address/zip (:zip (:address edit_client))}) :address/zip (:zip (:address edit_client))})
:client/bank-accounts (map #(remove-nils :client/bank-accounts (map #(remove-nils
{:db/id (:id %) {:db/id (:id %)
:bank-account/code (:code %) :bank-account/code (:code %)
:bank-account/bank-name (:bank_name %) :bank-account/bank-name (:bank_name %)
:bank-account/bank-code (:bank_code %) :bank-account/bank-code (:bank_code %)
:bank-account/routing (:routing %) :bank-account/routing (:routing %)
:bank-account/include-in-reports (:include_in_reports %) :bank-account/include-in-reports (:include_in_reports %)
:bank-account/name (:name %) :bank-account/name (:name %)
:bank-account/visible (:visible %) :bank-account/visible (:visible %)
:bank-account/number (:number %) :bank-account/number (:number %)
:bank-account/check-number (:check_number %) :bank-account/check-number (:check_number %)
:bank-account/sort-order (:sort_order %) :bank-account/sort-order (:sort_order %)
:bank-account/locations (:locations %) :bank-account/locations (:locations %)
:bank-account/yodlee-account-id (:yodlee_account_id %) :bank-account/yodlee-account-id (:yodlee_account_id %)
:bank-account/type (keyword "bank-account-type" (name (:type %))) :bank-account/type (keyword "bank-account-type" (name (:type %)))
} }
) (:bank_accounts edit_client)) ) (:bank_accounts edit_client))
})] })]
result @(d/transact (d/connect uri) transactions)] result @(d/transact (d/connect uri) transactions)]
(println result "ID" id) (println result "ID" id)
(-> result :tempids (get id) (or id) d-clients/get-by-id (-> result :tempids (get id) (or id) d-clients/get-by-id

View File

@@ -68,7 +68,8 @@
(into {} (map vector header row)))) (into {} (map vector header row))))
(map (fn [row] (map (fn [row]
{:vendor-code nil {:vendor-code nil
:customer-identifier (get row "Ship-To Name") :customer-identifier (str (get row "Ship-To Name") " " (or (get row "Ship-To Number")
(get row "\"Ship-To Number\"")))
:invoice-number (str/trim (get row "Invoice Number")) :invoice-number (str/trim (get row "Invoice Number"))
:date (parse-date-fallover (get row "Invoice Date") ["yyyy-MM-dd"]) :date (parse-date-fallover (get row "Invoice Date") ["yyyy-MM-dd"])
:total (str/replace (get row "Original Amount") #"[,\$]" "") :total (str/replace (get row "Original Amount") #"[,\$]" "")
@@ -81,7 +82,6 @@
(defmethod parse-csv :mama-lus (defmethod parse-csv :mama-lus
[rows] [rows]
(println "MAMA LU4")
(transduce (transduce
(comp (drop 1) (comp (drop 1)
(map (fn [[_ po-number despatch-number invoice-number invoice-date customer value :as row]] (map (fn [[_ po-number despatch-number invoice-number invoice-date customer value :as row]]

View File

@@ -20,3 +20,11 @@
(f/unparse (f/formatter format) v) (f/unparse (f/formatter format) v)
(catch Exception e (catch Exception e
nil))) nil)))
(defn day-of-week-seq [day]
(let [next-day (loop [d (auto-ap.time/local-now)]
(if (= (time/day-of-week d) day)
d
(recur (time/plus d (time/days 1)))))]
(iterate #(time/plus % (time/days 7)) next-day)))

View File

@@ -34,6 +34,9 @@
:checking ::checking-bank-account :checking ::checking-bank-account
:credit ::credit-account)) :credit ::credit-account))
(s/def ::bank-accounts (s/coll-of ::bank-account)) (s/def ::bank-accounts (s/coll-of ::bank-account))
;; disabled because graphql defaults to string representation
#_(s/def ::weekly-debits (s/nilable double?))
#_(s/def ::weekly-credits (s/nilable double?))
(s/def ::location string?) (s/def ::location string?)
(s/def ::locations (s/coll-of ::location :min-count 1)) (s/def ::locations (s/coll-of ::location :min-count 1))
@@ -45,7 +48,8 @@
(s/def ::client (s/keys :req-un [::name ::code ::locations] (s/def ::client (s/keys :req-un [::name ::code ::locations]
:opt-un [::email :opt-un [::email
::address ::address
#_::weekly-debits
#_::weekely-credits
::bank-accounts ::bank-accounts
::id])) ::id]))

View File

@@ -44,7 +44,7 @@
:graphql {:token token :graphql {:token token
:query-obj {:venia/queries [[:client :query-obj {:venia/queries [[:client
[:id :name :code :email :matches :locations [:location-matches [:location :match]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id :locations :include-in-reports] ] [:id :name :code :email :matches :weekly-debits :weekly-credits :locations [:location-matches [:location :match]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id :locations :include-in-reports] ]
[:address [:street1 :street2 :city :state :zip]]]] [:address [:street1 :street2 :city :state :zip]]]]
[:vendor [:vendor
[:id :name :hidden [:default-account [:name :id :location]] [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code [:id :name :hidden [:default-account [:name :id :location]] [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code
@@ -71,7 +71,7 @@
(fn [{:keys [db]} [_ token user]] (fn [{:keys [db]} [_ token user]]
{:graphql {:token token {:graphql {:token token
:query-obj {:venia/queries [[:client :query-obj {:venia/queries [[:client
[:id :name :code :matches :locations [:location-matches [:location :match]] [: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 :locations :include-in-reports] ]]] [:id :name :code :matches :locations :weekly-debits :weekly-credits [:location-matches [:location :match]] [: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 :locations :include-in-reports] ]]]
[:vendor [:vendor
[:id :name :hidden [:default-account [:name :id :location]] [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]] [:id :name :hidden [: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 :applicability :id [:client-overrides [:name [:client [:name :id]]]]]]]} [:accounts [:numeric-code :name :location :type :account_set :applicability :id [:client-overrides [:name [:client [:name :id]]]]]]]}

View File

@@ -1,6 +1,9 @@
(ns auto-ap.views.components.invoice-table (ns auto-ap.views.components.invoice-table
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[bidi.bidi :as bidi]
[cemerick.url :as url]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.routes :as routes]
[auto-ap.views.utils :refer [date->str dispatch-event delayed-dispatch nf]] [auto-ap.views.utils :refer [date->str dispatch-event delayed-dispatch nf]]
[auto-ap.views.components.paginator :refer [paginator]] [auto-ap.views.components.paginator :refer [paginator]]
[auto-ap.views.components.sort-by-list :refer [sort-by-list]] [auto-ap.views.components.sort-by-list :refer [sort-by-list]]
@@ -145,9 +148,11 @@
} "Payments"]} } "Payments"]}
[:div [:div
(for [payment payments] (for [payment payments]
(if (:s3-url (:payment payment)) (if (:check-number (:payment payment))
^{:key (:id payment)} ^{:key (:id payment)}
[:a.dropdown-item {:href (:s3-url (:payment payment)) [:a.dropdown-item {:href (str (bidi/path-for routes/routes :payments )
"?"
(url/map->query {:check-number-like (:check-number (:payment payment))}))
:target "_new"} :target "_new"}
[:i.fa.fa-money-check] [:i.fa.fa-money-check]
[:span.icon [:i.fa.fa-money]] [:span.icon [:i.fa.fa-money]]

View File

@@ -44,7 +44,8 @@
:email (:email new-client-data) :email (:email new-client-data)
:locations (:locations new-client-data) :locations (:locations new-client-data)
:matches (vec (:matches new-client-data)) :matches (vec (:matches new-client-data))
:location-matches (:location-matches new-client-data) :location-matches (:location-matches new-client-data) :weekly-credits (:weekly-credits new-client-data)
:weekly-debits (:weekly-debits new-client-data)
:address {:street1 (:street1 (:address new-client-data)) :address {:street1 (:street1 (:address new-client-data))
:street2 (:street2 (:address new-client-data)), :street2 (:street2 (:address new-client-data)),
:city (:city (:address new-client-data)) :city (:city (:address new-client-data))
@@ -90,7 +91,10 @@
:operation/name "EditClient"} :operation/name "EditClient"}
:venia/queries [{:query/data [:edit-client :venia/queries [{:query/data [:edit-client
{:edit-client new-client-req} {:edit-client new-client-req}
[:id :name :code :email :locations :matches [:location-matches [:location :match]] [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing :type :visible :yodlee-account-id :sort-order :locations]]]]}]} [:id :name :code :email :locations :matches :weekly-debits :weekly-credits
[:location-matches [:location :match]]
[:address [:street1 :street2 :city :state :zip]]
[:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing :type :visible :yodlee-account-id :sort-order :locations]]]]}]}
:on-success [::save-complete] :on-success [::save-complete]
:on-error [::forms/save-error ::new-client]}} :on-error [::forms/save-error ::new-client]}}
{:db new-client-form})))) {:db new-client-form}))))
@@ -556,6 +560,27 @@
#_(when (:saving? new-client) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}]) #_(when (:saving? new-client) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])
#_(println (s/explain-data ::entity/client new-client)) #_(println (s/explain-data ::entity/client new-client))
[:div.field
[:p.help "Weekly credits"]
[:div.control
[bind-field
[:input.input {:type "number"
:placeholder "250.00"
:field [:weekly-credits]
:step "0.01"
:event change-event
:subscription new-client}]]]]
[:div.field
[:p.help "Weekly debits"]
[:div.control
[bind-field
[:input.input {:type "number"
:placeholder "250.00"
:field [:weekly-debits]
:step "0.01"
:event change-event
:subscription new-client}]]]]
(when error (when error
[:div.notification.is-warning.animated.fadeInUp [:div.notification.is-warning.animated.fadeInUp
error]) error])

View File

@@ -5,9 +5,10 @@
[auto-ap.routes :as routes] [auto-ap.routes :as routes]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[cljs-time.core :as t] [cljs-time.core :as t]
[auto-ap.views.utils :refer [local-now date->str standard]] [auto-ap.views.utils :refer [local-now date->str standard dispatch-event]]
[reagent.core :as r] [reagent.core :as r]
[pushy.core :as pushy])) [pushy.core :as pushy]
))
(def pie-chart (r/adapt-react-class js/Recharts.PieChart)) (def pie-chart (r/adapt-react-class js/Recharts.PieChart))
@@ -91,11 +92,22 @@
(seq cash-flow) (seq cash-flow)
(assoc ::cash-flow cash-flow))))) (assoc ::cash-flow cash-flow)))))
(re-frame/reg-event-db
::select-cash-flow-range
[(re-frame/path ::chart-options)]
(fn [chart-options [_ which]]
(assoc chart-options :cash-flow-range which)))
(re-frame/reg-sub (re-frame/reg-sub
::invoice-stats ::invoice-stats
(fn [db] (fn [db]
(::invoice-stats db))) (::invoice-stats db)))
(re-frame/reg-sub
::chart-options
(fn [db]
(merge {:cash-flow-range :seven-days} (::chart-options db))))
(re-frame/reg-sub (re-frame/reg-sub
::top-expense-categories ::top-expense-categories
(fn [db] (fn [db]
@@ -113,9 +125,16 @@
pairs)) pairs))
(re-frame/reg-sub (re-frame/reg-sub
::cash-flow ::cash-flow-data
(fn [db] (fn [db]
(let [{:keys [outstanding-payments beginning-balance invoices-due-soon upcoming-credits upcoming-debits]} (::cash-flow db) (::cash-flow db)))
(re-frame/reg-sub
::cash-flow
:<- [::chart-options]
:<- [::cash-flow-data]
(fn [[chart-options cash-flow-data]]
(let [{:keys [outstanding-payments beginning-balance invoices-due-soon upcoming-credits upcoming-debits]} cash-flow-data
invoices-due-soon (sum-by-date (map (fn [i] [(:due i) (:outstanding-balance i)]) invoices-due-soon)) invoices-due-soon (sum-by-date (map (fn [i] [(:due i) (:outstanding-balance i)]) invoices-due-soon))
upcoming-credits (sum-by-date (map (fn [i] [(:date i) (:amount i)]) upcoming-credits)) upcoming-credits (sum-by-date (map (fn [i] [(:date i) (:amount i)]) upcoming-credits))
upcoming-debits (sum-by-date (map (fn [i] [(:date i) (:amount i)]) upcoming-debits)) upcoming-debits (sum-by-date (map (fn [i] [(:date i) (:amount i)]) upcoming-debits))
@@ -148,7 +167,9 @@
:debits (upcoming-debits (date->str start-date) 0.0) :debits (upcoming-debits (date->str start-date) 0.0)
:outstanding-payments (- outstanding-payments) :outstanding-payments (- outstanding-payments)
:query-params (cemerick.url/map->query {:due-range {:end (date->str start-date standard)}})}) :query-params (cemerick.url/map->query {:due-range {:end (date->str start-date standard)}})})
(range 1 7)))))) (if (= :seven-days (:cash-flow-range chart-options))
(range 1 7)
(range 1 31)))))))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::mounted ::mounted
@@ -171,7 +192,8 @@
:on-success [::received]}})) :on-success [::received]}}))
(defn home-content [] (defn home-content []
(let [client-id (-> @(re-frame/subscribe [::subs/client]) :id)] (let [client-id (-> @(re-frame/subscribe [::subs/client]) :id)
chart-options @(re-frame/subscribe [::chart-options])]
^{:key client-id} ^{:key client-id}
[side-bar-layout {:side-bar [:div] [side-bar-layout {:side-bar [:div]
:main [:div [:h1.title "Home"] :main [:div [:h1.title "Home"]
@@ -184,6 +206,17 @@
@(re-frame/subscribe [::invoice-stats]))}) @(re-frame/subscribe [::invoice-stats]))})
[:h1.title.is-4 "Cash Flow"] [:h1.title.is-4 "Cash Flow"]
[:div.buttons.has-addons
[:a.button {:class (when (= :seven-days (:cash-flow-range chart-options))
["is-info" "is-selected"])
:on-click (dispatch-event [::select-cash-flow-range :seven-days])}
"7 days"]
[:a.button {:class (when (= :thirty-days (:cash-flow-range chart-options))
["is-info" "is-selected"])
:on-click (dispatch-event [::select-cash-flow-range :thirty-days])}
"30 days"]]
(make-cash-flow-chart {:width 800 :height 500 (make-cash-flow-chart {:width 800 :height 500
:data (clj->js @(re-frame/subscribe [::cash-flow]))})]}])) :data (clj->js @(re-frame/subscribe [::cash-flow]))})]}]))