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