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