last round fixes.
This commit is contained in:
@@ -45,7 +45,10 @@
|
|||||||
(Double/parseDouble %)
|
(Double/parseDouble %)
|
||||||
|
|
||||||
(and (string? %)
|
(and (string? %)
|
||||||
(str/blank? %))
|
(str/blank? (str/trim %)))
|
||||||
|
0.0
|
||||||
|
|
||||||
|
(nil? %)
|
||||||
0.0
|
0.0
|
||||||
|
|
||||||
(int? %)
|
(int? %)
|
||||||
|
|||||||
@@ -275,15 +275,15 @@
|
|||||||
(throw (ex-info (str "Vendor '" (:vendor_name entry) "' not found.") {:status :error})))
|
(throw (ex-info (str "Vendor '" (:vendor_name entry) "' not found.") {:status :error})))
|
||||||
(when-not (re-find #"\d{1,2}/\d{1,2}/\d{4}" (:date entry))
|
(when-not (re-find #"\d{1,2}/\d{1,2}/\d{4}" (:date entry))
|
||||||
(throw (ex-info (str "Date must be MM/dd/yyyy") {:status :error})))
|
(throw (ex-info (str "Date must be MM/dd/yyyy") {:status :error})))
|
||||||
(when-not (dollars= (reduce + 0.0 (map :debit (:line_items entry)))
|
(when-not (dollars= (reduce (fnil + 0.0 0.0) 0.0 (map :debit (:line_items entry)))
|
||||||
(reduce + 0.0 (map :credit (:line_items entry))))
|
(reduce (fnil + 0.0 0.0) 0.0 (map :credit (:line_items entry))))
|
||||||
(throw (ex-info (str "Debits '"
|
(throw (ex-info (str "Debits '"
|
||||||
(reduce + 0 (map :debit (:line_items entry)))
|
(reduce (fnil + 0.0 0.0) 0 (map :debit (:line_items entry)))
|
||||||
"' and credits '"
|
"' and credits '"
|
||||||
(reduce + 0 (map :credit (:line_items entry)))
|
(reduce (fnil + 0.0 0.0) 0 (map :credit (:line_items entry)))
|
||||||
"' do not add up.")
|
"' do not add up.")
|
||||||
{:status :error})))
|
{:status :error})))
|
||||||
(when (dollars= (reduce + 0.0 (map :debit (:line_items entry)))
|
(when (dollars= (reduce (fnil + 0.0 0.0) 0.0 (map :debit (:line_items entry)))
|
||||||
0.0)
|
0.0)
|
||||||
(throw (ex-info (str "Cannot have ledger entries that total $0.00")
|
(throw (ex-info (str "Cannot have ledger entries that total $0.00")
|
||||||
{:status :ignored})))
|
{:status :ignored})))
|
||||||
@@ -302,53 +302,55 @@
|
|||||||
|
|
||||||
:journal-entry/line-items
|
:journal-entry/line-items
|
||||||
(mapv (fn [ea]
|
(mapv (fn [ea]
|
||||||
(when (and (not (get
|
(let [debit (or (:debit ea) 0.0)
|
||||||
(get all-client-locations (:client_code entry))
|
credit (or (:credit ea) 0.0)]
|
||||||
(:location ea)))
|
(when (and (not (get
|
||||||
(not= "A" (:location ea)))
|
(get all-client-locations (:client_code entry))
|
||||||
(throw (ex-info (str "Location '" (:location ea) "' not found.")
|
|
||||||
{:status :error})))
|
|
||||||
(when (and (<= (:debit ea 0.0) 0.0)
|
|
||||||
(<= (:credit ea 0.0) 0.0))
|
|
||||||
(throw (ex-info (str "Line item amount " (or (:debit ea) (:credit ea)) " must be greater than 0.")
|
|
||||||
{:status :error})))
|
|
||||||
(when (and (not (all-accounts (:account_identifier ea)))
|
|
||||||
(not (get
|
|
||||||
(get all-client-bank-accounts (:client_code entry))
|
|
||||||
(:account_identifier ea))))
|
|
||||||
(throw (ex-info (str "Account '" (:account_identifier ea) "' not found.")
|
|
||||||
{:status :error})))
|
|
||||||
(let [matching-account (when (re-matches #"^[0-9]+$" (:account_identifier ea))
|
|
||||||
(a/get-account-by-numeric-code-and-sets (Integer/parseInt (:account_identifier ea)) ["default"]))]
|
|
||||||
(when (and matching-account
|
|
||||||
(:account/location matching-account)
|
|
||||||
(not= (:account/location matching-account)
|
|
||||||
(:location ea)))
|
(:location ea)))
|
||||||
(throw (ex-info (str "Account '"
|
(not= "A" (:location ea)))
|
||||||
(:account/numeric-code matching-account)
|
(throw (ex-info (str "Location '" (:location ea) "' not found.")
|
||||||
"' requires location '"
|
|
||||||
(:account/location matching-account)
|
|
||||||
"' but got '"
|
|
||||||
(:location ea)
|
|
||||||
"'")
|
|
||||||
{:status :error})))
|
{:status :error})))
|
||||||
|
(when (and (<= debit 0.0)
|
||||||
|
(<= credit 0.0))
|
||||||
|
(throw (ex-info (str "Line item amount " (or debit credit) " must be greater than 0.")
|
||||||
|
{:status :error})))
|
||||||
|
(when (and (not (all-accounts (:account_identifier ea)))
|
||||||
|
(not (get
|
||||||
|
(get all-client-bank-accounts (:client_code entry))
|
||||||
|
(:account_identifier ea))))
|
||||||
|
(throw (ex-info (str "Account '" (:account_identifier ea) "' not found.")
|
||||||
|
{:status :error})))
|
||||||
|
(let [matching-account (when (re-matches #"^[0-9]+$" (:account_identifier ea))
|
||||||
|
(a/get-account-by-numeric-code-and-sets (Integer/parseInt (:account_identifier ea)) ["default"]))]
|
||||||
|
(when (and matching-account
|
||||||
|
(:account/location matching-account)
|
||||||
|
(not= (:account/location matching-account)
|
||||||
|
(:location ea)))
|
||||||
|
(throw (ex-info (str "Account '"
|
||||||
|
(:account/numeric-code matching-account)
|
||||||
|
"' requires location '"
|
||||||
|
(:account/location matching-account)
|
||||||
|
"' but got '"
|
||||||
|
(:location ea)
|
||||||
|
"'")
|
||||||
|
{:status :error})))
|
||||||
|
|
||||||
(when (and matching-account
|
(when (and matching-account
|
||||||
(not (:account/location matching-account))
|
(not (:account/location matching-account))
|
||||||
(= "A" (:location ea)))
|
(= "A" (:location ea)))
|
||||||
(throw (ex-info (str "Account '"
|
(throw (ex-info (str "Account '"
|
||||||
(:account/numeric-code matching-account)
|
(:account/numeric-code matching-account)
|
||||||
"' cannot use location '"
|
"' cannot use location '"
|
||||||
(:location ea)
|
(:location ea)
|
||||||
"'")
|
"'")
|
||||||
{:status :error})))
|
{:status :error})))
|
||||||
(remove-nils (cond-> {:journal-entry-line/location (:location ea)
|
(remove-nils (cond-> {:journal-entry-line/location (:location ea)
|
||||||
:journal-entry-line/debit (when (> (:debit ea) 0)
|
:journal-entry-line/debit (when (> debit 0)
|
||||||
(:debit ea))
|
debit)
|
||||||
:journal-entry-line/credit (when (> (:credit ea) 0)
|
:journal-entry-line/credit (when (> credit 0)
|
||||||
(:credit ea))}
|
credit)}
|
||||||
matching-account (assoc :journal-entry-line/account (:db/id matching-account))
|
matching-account (assoc :journal-entry-line/account (:db/id matching-account))
|
||||||
(not matching-account) (assoc :journal-entry-line/account [:bank-account/code (:account_identifier ea)])))))
|
(not matching-account) (assoc :journal-entry-line/account [:bank-account/code (:account_identifier ea)]))))))
|
||||||
(:line_items entry))
|
(:line_items entry))
|
||||||
|
|
||||||
:journal-entry/cleared true})))))
|
:journal-entry/cleared true})))))
|
||||||
|
|||||||
@@ -1,22 +1,18 @@
|
|||||||
(ns auto-ap.routes.exports
|
(ns auto-ap.routes.exports
|
||||||
(:require
|
(:require [auto-ap.datomic :refer [conn]]
|
||||||
[auto-ap.datomic.clients :as d-clients]
|
[auto-ap.datomic.clients :as d-clients]
|
||||||
[auto-ap.datomic.vendors :as d-vendors]
|
[auto-ap.datomic.ledger :as d-ledger]
|
||||||
[auto-ap.datomic.ledger :as d-ledger]
|
[auto-ap.datomic.transactions :as d-transactions]
|
||||||
[auto-ap.datomic.transactions :as d-transactions]
|
[auto-ap.datomic.vendors :as d-vendors]
|
||||||
[auto-ap.utils :refer [by]]
|
[auto-ap.graphql :as graphql]
|
||||||
[auto-ap.parse :as parse]
|
[auto-ap.graphql.utils :refer [->graphql <-graphql assert-admin]]
|
||||||
[auto-ap.graphql :as graphql]
|
[auto-ap.routes.utils :refer [wrap-secure]]
|
||||||
[auto-ap.graphql.utils :refer [<-graphql ->graphql assert-admin]]
|
[clj-time.coerce :as coerce :refer [to-date]]
|
||||||
[auto-ap.routes.utils :refer [wrap-secure]]
|
[clj-time.core :as time]
|
||||||
[clj-time.coerce :refer [to-date]]
|
[compojure.core :refer [context defroutes GET wrap-routes]]
|
||||||
[ring.middleware.json :refer [wrap-json-response]]
|
[datomic.api :as d]
|
||||||
[compojure.core :refer [GET POST context defroutes wrap-routes]]
|
[ring.middleware.json :refer [wrap-json-response]]
|
||||||
[clojure.string :as str]
|
[venia.core :as venia]))
|
||||||
[venia.core :as venia]
|
|
||||||
[clojure.tools.logging :as log]
|
|
||||||
[clj-time.core :as time]
|
|
||||||
[clj-time.coerce :as coerce]))
|
|
||||||
|
|
||||||
(defroutes routes
|
(defroutes routes
|
||||||
(wrap-routes
|
(wrap-routes
|
||||||
@@ -168,14 +164,41 @@
|
|||||||
(GET "/transactions/export" {:keys [query-params identity]}
|
(GET "/transactions/export" {:keys [query-params identity]}
|
||||||
(assert-admin identity)
|
(assert-admin identity)
|
||||||
(let [[transactions] (d-transactions/get-graphql {:client-code (query-params "client-code")
|
(let [[transactions] (d-transactions/get-graphql {:client-code (query-params "client-code")
|
||||||
#_#_:original-id (Integer/parseInt (query-params "original"))
|
#_#_:original-id (Integer/parseInt (query-params "original"))
|
||||||
:count Integer/MAX_VALUE})
|
:count Integer/MAX_VALUE})]
|
||||||
]
|
|
||||||
|
|
||||||
(map (comp ->graphql (fn [i]
|
(map (comp ->graphql (fn [i]
|
||||||
(-> i
|
(-> i
|
||||||
(update :transaction/date to-date)
|
(update :transaction/date to-date)
|
||||||
(update :transaction/post-date to-date))))
|
(update :transaction/post-date to-date))))
|
||||||
transactions))))
|
transactions)))
|
||||||
|
|
||||||
|
(GET "/transactions/export2" {:keys [query-params identity]}
|
||||||
|
(assert-admin identity)
|
||||||
|
(let [db (d/db conn)]
|
||||||
|
(->>
|
||||||
|
(d/query {:query {:find ['?e]
|
||||||
|
:in ['$ '?client-code]
|
||||||
|
:where ['[?e :transaction/client ?client-code]]}
|
||||||
|
:args [db [:client/code (query-params "client-code")]]})
|
||||||
|
(map first)
|
||||||
|
(map (fn [e]
|
||||||
|
(let [e (d/entity db e)
|
||||||
|
client (:transaction/client e)
|
||||||
|
bank-account (:transaction/bank-account e)]
|
||||||
|
{:id (:db/id e)
|
||||||
|
:date (:transaction/date e)
|
||||||
|
:post_date (:transaction/post-date e)
|
||||||
|
:client { :code (:client/code client)
|
||||||
|
:id (:db/id client)
|
||||||
|
:name (:client/name client)}
|
||||||
|
:amount (:transaction/amount e)
|
||||||
|
:description_original (:transaction/description-original e)
|
||||||
|
:approval_status (:transaction/approval-status e)
|
||||||
|
:bank_account {:name (:bank-account/name bank-account)
|
||||||
|
:code (:bank-account/code bank-account)
|
||||||
|
:id (:db/id bank-account)}})))))))
|
||||||
|
|
||||||
|
|
||||||
wrap-secure)
|
wrap-secure)
|
||||||
|
|||||||
@@ -356,6 +356,7 @@
|
|||||||
:owns-state {:single ::page}
|
:owns-state {:single ::page}
|
||||||
:query-obj {:venia/queries [[:yodlee-provider-account-page {:client-id (:id @(re-frame/subscribe [::subs/client]))}
|
:query-obj {:venia/queries [[:yodlee-provider-account-page {:client-id (:id @(re-frame/subscribe [::subs/client]))}
|
||||||
[[:yodlee-provider-accounts [:id :last-updated :status :detailed-status
|
[[:yodlee-provider-accounts [:id :last-updated :status :detailed-status
|
||||||
|
[:client [:id]]
|
||||||
[:accounts [:id :name :number :available-balance]]]]
|
[:accounts [:id :name :number :available-balance]]]]
|
||||||
:count]]]}
|
:count]]]}
|
||||||
:on-success [::received]}}))
|
:on-success [::received]}}))
|
||||||
|
|||||||
@@ -19,14 +19,14 @@
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::request-refresh
|
::request-refresh
|
||||||
[with-user ]
|
[with-user ]
|
||||||
(fn [{:keys [user db]} [_ provider-account ]]
|
(fn [{:keys [user db]} [_ provider-account client-id ]]
|
||||||
{:http {:token user
|
{:http {:token user
|
||||||
:method :post
|
:method :post
|
||||||
:headers {"Content-Type" "application/edn"}
|
:headers {"Content-Type" "application/edn"}
|
||||||
:uri (str "/api/yodlee2/provider-accounts/refresh/")
|
:uri (str "/api/yodlee2/provider-accounts/refresh/")
|
||||||
:owns-state {:multi ::refresh
|
:owns-state {:multi ::refresh
|
||||||
:which provider-account}
|
:which provider-account}
|
||||||
:body {:client-id (:id @(re-frame/subscribe [::subs/client]))
|
:body {:client-id client-id
|
||||||
:provider-account-id provider-account}
|
:provider-account-id provider-account}
|
||||||
:on-success [::refreshed provider-account]}}))
|
:on-success [::refreshed provider-account]}}))
|
||||||
|
|
||||||
@@ -94,23 +94,25 @@
|
|||||||
[grid/header-cell {:style {:width (action-cell-width 3)}} ]]]
|
[grid/header-cell {:style {:width (action-cell-width 3)}} ]]]
|
||||||
[grid/body
|
[grid/body
|
||||||
(for [{:keys [id name accounts status detailed-status last-updated clients] :as c} (:data page)]
|
(for [{:keys [id name accounts status detailed-status last-updated clients] :as c} (:data page)]
|
||||||
^{:key (str name "-" id )}
|
(do
|
||||||
[grid/row {:class (:class c) :id id}
|
(println c)
|
||||||
[grid/cell {} id]
|
^{:key (str name "-" id )}
|
||||||
[grid/cell {} status]
|
[grid/row {:class (:class c) :id id}
|
||||||
[grid/cell {} detailed-status]
|
[grid/cell {} id]
|
||||||
[grid/cell {} (date->str last-updated)]
|
[grid/cell {} status]
|
||||||
[grid/cell {}
|
[grid/cell {} detailed-status]
|
||||||
[:ul
|
[grid/cell {} (date->str last-updated)]
|
||||||
(for [a accounts]
|
[grid/cell {}
|
||||||
^{:key (:id a)}
|
[:ul
|
||||||
[:li (:name a) " - " (:number a) [:div.tag (->$ (:available-balance a))]])]]
|
(for [a accounts]
|
||||||
[grid/cell {}
|
^{:key (:id a)}
|
||||||
[:div.buttons
|
[:li (:name a) " - " (:number a) [:div.tag (->$ (:available-balance a))]])]]
|
||||||
[buttons/fa-icon {:event [::form/editing c]
|
[grid/cell {}
|
||||||
:icon "fa-pencil"}]
|
[:div.buttons
|
||||||
[buttons/fa-icon {:event [::request-refresh (:id c)]
|
[buttons/fa-icon {:event [::form/editing c]
|
||||||
:class (status/class-for (get statuses (:id c)))
|
:icon "fa-pencil"}]
|
||||||
:icon "fa-refresh"}]
|
[buttons/fa-icon {:event [::request-refresh (:id c) (:id (:client c))]
|
||||||
[buttons/fa-icon {:event [::delete-requested (:id c)]
|
:class (status/class-for (get statuses (:id c)))
|
||||||
:icon "fa-times"}]]]])]]]))
|
:icon "fa-refresh"}]
|
||||||
|
[buttons/fa-icon {:event [::delete-requested (:id c)]
|
||||||
|
:icon "fa-times"}]]]]))]]]))
|
||||||
|
|||||||
Reference in New Issue
Block a user