fixes for some issues found

This commit is contained in:
Bryce Covert
2021-01-04 18:57:52 -08:00
parent 65db253593
commit 0f7a5c1f00
5 changed files with 115 additions and 113 deletions

View File

@@ -41,11 +41,14 @@
:iso_date {:parse #(time/parse % time/iso-date)
:serialize #(time/unparse % time/iso-date)}
:money {:parse #(do
(log/info "parsing money...")
(cond (and (string? %)
(not (str/blank? %)))
(Double/parseDouble %)
(and (string? %)
(str/blank? %))
0.0
(int? %)
(double %)
@@ -681,14 +684,14 @@
:import_ledger_line_item {:fields {:account_identifier {:type 'String}
:location {:type 'String}
:debit {:type 'String}
:credit {:type 'String}}}
:debit {:type :money}
:credit {:type :money}}}
:import_ledger_entry {:fields {:source {:type 'String}
:external_id {:type 'String}
:client_code {:type 'String}
:date {:type 'String}
:vendor_name {:type 'String}
:amount {:type 'String}
:amount {:type :money}
:note {:type 'String}
:cleared_against {:type 'String}
:line_items {:type '(list :import_ledger_line_item)}}}

View File

@@ -204,6 +204,7 @@
(try
(f entry)
(catch Exception e
(log/warn e)
(assoc entry :error (.getMessage e)
:status (or (:status (ex-data e))
:error))))))
@@ -267,16 +268,6 @@
all-accounts (transduce (map (comp str :account/numeric-code)) conj #{} (a/get-accounts))
transaction (doall (map
(assoc-error (fn [entry]
(let [entry (-> entry
(update :amount #(Double/parseDouble %))
(update :line_items
(fn [lis]
(mapv
(fn [li ]
(-> li
(update :debit #(Double/parseDouble (if (str/blank? %) "0" %)))
(update :credit #(Double/parseDouble (if (str/blank? %) "0" %)))))
lis))))]
(let [vendor (all-vendors (:vendor_name entry))]
(when-not (all-clients (:client_code entry))
(throw (ex-info (str "Client '" (:client_code entry )"' not found.") {:status :error}) ))
@@ -360,7 +351,7 @@
(not matching-account) (assoc :journal-entry-line/account [:bank-account/code (:account_identifier ea)])))))
(:line_items entry))
:journal-entry/cleared true}))))))
:journal-entry/cleared true})))))
(:entries args)))
errors (filter #(= (:status %) :error) transaction)
ignored (filter #(= (:status %) :ignored) transaction)

View File

@@ -12,7 +12,7 @@
(defn make-api-token []
(jwt/sign {:user "API"
:exp (time/plus (time/now) (time/days 700))
:exp (time/plus (time/now) (time/days 1000))
:user/role "admin"
:user/name "API"}
(:jwt-secret env)

View File

@@ -24,7 +24,7 @@
:location (if (clojure.string/blank? location)
nil
location)
:numeric-code numeric-code
:numeric-code (js/parseInt numeric-code)
:name name
:account-set account-set
:client-overrides (map (fn [client-override]

View File

@@ -11,7 +11,8 @@
[cljs-time.core :as t]
[re-frame.core :as re-frame]
[reagent.core :as r]
[clojure.string :as str]))
[clojure.string :as str]
[auto-ap.status :as status]))
@@ -63,7 +64,8 @@
(let [successful-set (set (map :external-id (:successful (:import-ledger result))))
error-set (into {} (map (juxt :external-id :error) (:errors (:import-ledger result))))
existing-set (set (map :external-id (:existing (:import-ledger result))))
ignored-set (set (map :external-id (:ignored (:import-ledger result))))]
ignored-set (set (map :external-id (:ignored (:import-ledger result))))
seen-set (atom #{})]
{:db (-> (forms/save-succeeded db ::form )
(assoc-in [::forms/forms ::form :result] {:errors error-set :success successful-set :existing existing-set :ignored ignored-set})
@@ -80,7 +82,10 @@
(existing-set (line->id %))
""
(error-set (line->id %))
(and (error-set (line->id %))
(not (@seen-set (line->id %))))
(do
(swap! seen-set conj (line->id %))
[drop-down {:id [::ledger-import-line (line->id %) ]
:is-right? true
:header [:a.button {:aria-haspopup true
@@ -89,7 +94,7 @@
[:span.is-warning.icon {:title (error-set (line->id %))} [:i.fa.fa-exclamation-triangle]]]}
[drop-down-contents
[:div
[:span.dropdown-item (error-set (line->id %)) ]]]]
[:span.dropdown-item (error-set (line->id %)) ]]]])
)
:status-category
(cond (successful-set (line->id %))
@@ -110,9 +115,9 @@
::importing
(fn [{:keys [db]} _]
(when @(re-frame/subscribe [::can-submit])
{:db (forms/loading db ::form )
:graphql
{:graphql
{:token (-> db :user)
:owns-state {:single ::import}
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "ImportLedger"}
:venia/queries [{:query/data [:import-ledger
@@ -137,7 +142,7 @@
[:form.form
(if value
[:div
[:table.table
[:table.table {:style {:width "100%"}}
[:thead
[:tr
(list
@@ -190,22 +195,25 @@
(fn []
(let [current-client @(re-frame/subscribe [::subs/client])
user @(re-frame/subscribe [::subs/user])
status @(re-frame/subscribe [::status/single ::import])
{:keys [data result active? error id]} @(re-frame/subscribe [::forms/form ::form]) ]
[:div
[:div.level
[:div.level-left
[:h1.title "Eternal Import"]]
[:div.level-right
[:button.button.is-primary.is-pulled-right.is-large {:disabled (not data)
:on-click (dispatch-event [::importing])} "Import"]]]
[status/status-notification {:statuses [[::status/single ::import]]} ]
(when result
[:div.notification
"Imported with "
(count (:errors result)) " errors, "
(count (:ignored result)) " ignored, "
(count (:success result)) " successful."])
(if @(re-frame/subscribe [::forms/is-loading? ::form])
[:div [:i.icon.fa.fa-spin.fa-spinner]]
(if (= :loading (:state status ))
[status/big-loader status]
[:div
[:div.is-clearfix
[:div.is-pulled-right