Moved to biweekly

This commit is contained in:
Bryce Covert
2020-07-16 07:44:07 -07:00
parent 08f12b8107
commit e0b636c2fa
6 changed files with 84 additions and 26 deletions

View File

@@ -67,8 +67,10 @@
{:fields {:id {:type :id}
:name {:type 'String}
:code {:type 'String}
:weekly_debits {:type :money}
:weekly_credits {:type :money}
:week_a_debits {:type :money}
:week_a_credits {:type :money}
:week_b_debits {:type :money}
:week_b_credits {:type :money}
:email {:type 'String}
:address {:type :address}
:location_matches {:type '(list :location_match)}
@@ -539,8 +541,10 @@
:name {:type 'String}
:code {:type 'String}
:email {:type 'String}
:weekly_credits {:type :money}
:weekly_debits {:type :money}
:week_a_credits {:type :money}
:week_a_debits {:type :money}
:week_b_credits {:type :money}
:week_b_debits {:type :money}
:address {:type :add_address}
:locations {:type '(list String)}
:matches {:type '(list String)}
@@ -933,12 +937,13 @@
(<= (t/in-days (apply t/interval (sort [date potential-date]))) 10)))))
conj
[]
recent-fulfillments))
)
recent-fulfillments)))
(def first-week-a (coerce/to-date-time #inst "1999-12-27T00:00:00.000-07:00"))
(defn get-cash-flow [context {:keys [client_id]} value]
(when client_id
(let [{:client/keys [weekly-credits weekly-debits forecasted-transactions ]} (d/pull (d/db (d/connect uri)) '[*] client_id )
(let [{:client/keys [week-a-credits week-a-debits week-b-credits week-b-debits forecasted-transactions ]} (d/pull (d/db (d/connect uri)) '[*] client_id )
total-cash (reduce
(fn [total [credit debit]]
(- (+ total credit)
@@ -990,8 +995,11 @@
:when (not (has-fulfilled? id next recent-fulfillments))]
{:identifier identifier
:amount amount
:date (coerce/to-date-time next)})]
(println "RECENT" forecasted-transactions)
:date (coerce/to-date-time next)})
is-week-a? (fn [d]
(println d)
(= 0 (mod (t/in-weeks (t/interval first-week-a d)) 2)))]
{:beginning_balance total-cash
:outstanding_payments outstanding-checks
:invoices_due_soon (mapv (fn [[due outstanding]]
@@ -1000,13 +1008,17 @@
bills-due-soon)
:upcoming_credits (into (mapv
(fn [date]
{:amount (or weekly-credits 0)
{:amount (if (is-week-a? (coerce/to-date-time date))
(or week-a-credits 0)
(or week-b-credits 0))
:date (coerce/to-date-time date)})
(take 5 (time/day-of-week-seq 1)))
(filter #(>= (:amount %) 0) forecasted-transactions))
:upcoming_debits (into (mapv
(fn [date]
{:amount (- (or weekly-debits 0))
{:amount (- (if (is-week-a? (coerce/to-date-time date))
(or week-a-debits 0)
(or week-b-debits 0)))
:date (coerce/to-date-time date)})
(take 5 (time/day-of-week-seq 1)))
(filter #(< (:amount %) 0) forecasted-transactions))