several fixes.
This commit is contained in:
@@ -228,7 +228,10 @@
|
|||||||
:db/doc "client override"
|
:db/doc "client override"
|
||||||
:db/valueType :db.type/string
|
:db/valueType :db.type/string
|
||||||
:db/cardinality :db.cardinality/one}]]}
|
:db/cardinality :db.cardinality/one}]]}
|
||||||
}]
|
:auto-ap/add-cleared-against {:txes [[{:db/ident :transaction/cleared-against
|
||||||
|
:db/doc "which entitiy it was cleared against"
|
||||||
|
:db/valueType :db.type/string
|
||||||
|
:db/cardinality :db.cardinality/one}]]}}]
|
||||||
(println "Conforming database...")
|
(println "Conforming database...")
|
||||||
(c/ensure-conforms conn norms-map)
|
(c/ensure-conforms conn norms-map)
|
||||||
(when (not (seq args))
|
(when (not (seq args))
|
||||||
|
|||||||
@@ -15,7 +15,9 @@
|
|||||||
@(d/transact (d/connect auto-ap.datomic/uri)
|
@(d/transact (d/connect auto-ap.datomic/uri)
|
||||||
tx)
|
tx)
|
||||||
(when (= 0 (mod i 100))
|
(when (= 0 (mod i 100))
|
||||||
(println "processed " i))))
|
(println "processed " i)
|
||||||
|
(println "sample: " (first tx))
|
||||||
|
)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,7 @@
|
|||||||
:journal-entry/original-entity (:db/id entity)
|
:journal-entry/original-entity (:db/id entity)
|
||||||
:journal-entry/vendor (:db/id (:transaction/vendor entity))
|
:journal-entry/vendor (:db/id (:transaction/vendor entity))
|
||||||
:journal-entry/amount (Math/abs (:transaction/amount entity))
|
:journal-entry/amount (Math/abs (:transaction/amount entity))
|
||||||
|
:journal-entry/cleared-against (:transaction/cleared-against entity)
|
||||||
|
|
||||||
:journal-entry/line-items (into [(remove-nils {:journal-entry-line/account (:db/id (:transaction/bank-account entity))
|
:journal-entry/line-items (into [(remove-nils {:journal-entry-line/account (:db/id (:transaction/bank-account entity))
|
||||||
:journal-entry-line/location "A"
|
:journal-entry-line/location "A"
|
||||||
|
|||||||
@@ -17,7 +17,9 @@
|
|||||||
[ring.middleware.json :refer [wrap-json-response]]
|
[ring.middleware.json :refer [wrap-json-response]]
|
||||||
[compojure.core :refer [GET POST context defroutes
|
[compojure.core :refer [GET POST context defroutes
|
||||||
wrap-routes]]
|
wrap-routes]]
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]
|
||||||
|
[clojure.java.io :as io]
|
||||||
|
[clojure.data.csv :as csv]))
|
||||||
|
|
||||||
(defn reset-id [i]
|
(defn reset-id [i]
|
||||||
(update i :invoice-number
|
(update i :invoice-number
|
||||||
@@ -273,6 +275,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(defn import-transactions-cleared-against [file]
|
||||||
|
(let [[header & rows] (-> file (io/reader) csv/read-csv)
|
||||||
|
txes (transduce
|
||||||
|
(comp
|
||||||
|
(filter (fn [[transaction-id cleared-against]]
|
||||||
|
(d/pull (d/db (d/connect uri)) '[:transaction/amount] (Long/parseLong transaction-id))))
|
||||||
|
(map (fn [[transaction-id cleared-against]]
|
||||||
|
{:db/id (Long/parseLong transaction-id)
|
||||||
|
:transaction/cleared-against cleared-against})))
|
||||||
|
conj
|
||||||
|
[]
|
||||||
|
rows)]
|
||||||
|
@(d/transact (d/connect uri) txes)))
|
||||||
|
|
||||||
(defroutes routes
|
(defroutes routes
|
||||||
(wrap-routes
|
(wrap-routes
|
||||||
(context "/" []
|
(context "/" []
|
||||||
@@ -346,8 +362,8 @@
|
|||||||
:body (pr-str {:message (.getMessage e)
|
:body (pr-str {:message (.getMessage e)
|
||||||
:error (.toString e)
|
:error (.toString e)
|
||||||
:data (ex-data e)})
|
:data (ex-data e)})
|
||||||
:headers {"Content-Type" "application/edn"}}))
|
:headers {"Content-Type" "application/edn"}}))))
|
||||||
))
|
|
||||||
(POST "/upload-integreat"
|
(POST "/upload-integreat"
|
||||||
{{:keys [excel-rows]} :edn-params user :identity}
|
{{:keys [excel-rows]} :edn-params user :identity}
|
||||||
(assert-admin user)
|
(assert-admin user)
|
||||||
@@ -369,20 +385,36 @@
|
|||||||
:else
|
:else
|
||||||
:new))
|
:new))
|
||||||
parsed-invoice-rows)
|
parsed-invoice-rows)
|
||||||
|
|
||||||
|
|
||||||
vendors-not-found (->> parsed-invoice-rows
|
vendors-not-found (->> parsed-invoice-rows
|
||||||
(filter #(and (nil? (:vendor-id %))
|
(filter #(and (nil? (:vendor-id %))
|
||||||
(not= "Cash" (:check %))))
|
(not= "Cash" (:check %))))
|
||||||
(map :vendor-name)
|
(map :vendor-name)
|
||||||
set)
|
set)
|
||||||
|
|
||||||
inserted-rows @(d/transact (d/connect uri) (invoice-rows->transaction (:new grouped-rows)))]
|
inserted-rows @(d/transact (d/connect uri) (invoice-rows->transaction (:new grouped-rows)))]
|
||||||
|
|
||||||
{:status 200
|
{:status 200
|
||||||
:body (pr-str {:imported (count (:new grouped-rows))
|
:body (pr-str {:imported (count (:new grouped-rows))
|
||||||
:already-imported (count (:exists grouped-rows))
|
:already-imported (count (:exists grouped-rows))
|
||||||
:vendors-not-found vendors-not-found
|
:vendors-not-found vendors-not-found
|
||||||
:errors (map #(dissoc % :date) (:error grouped-rows))})
|
:errors (map #(dissoc % :date) (:error grouped-rows))})
|
||||||
:headers {"Content-Type" "application/edn"}}))))
|
:headers {"Content-Type" "application/edn"}})))
|
||||||
|
(POST "/transactions/cleared-against"
|
||||||
|
{{files :file
|
||||||
|
files-2 "file"} :params :as params
|
||||||
|
user :identity}
|
||||||
|
(let [files (or files files-2)
|
||||||
|
_ (println files)
|
||||||
|
{:keys [filename tempfile]} files]
|
||||||
|
(assert-admin user)
|
||||||
|
(try
|
||||||
|
(import-transactions-cleared-against (.getPath tempfile))
|
||||||
|
{:status 200
|
||||||
|
:body (pr-str {})
|
||||||
|
:headers {"Content-Type" "application/edn"}}
|
||||||
|
(catch Exception e
|
||||||
|
(println e)
|
||||||
|
{:status 500
|
||||||
|
:body (pr-str {:message (.getMessage e)
|
||||||
|
:error (.toString e)
|
||||||
|
:data (ex-data e)})
|
||||||
|
:headers {"Content-Type" "application/edn"}})))))
|
||||||
wrap-secure))
|
wrap-secure))
|
||||||
|
|||||||
@@ -165,8 +165,8 @@
|
|||||||
(range)
|
(range)
|
||||||
transaction-group))))
|
transaction-group))))
|
||||||
all-rules (tr/get-all)
|
all-rules (tr/get-all)
|
||||||
all-bank-accounts (get-all-bank-accounts)
|
all-bank-accounts (by :db/id (get-all-bank-accounts))
|
||||||
transaction->bank-account (comp (by :db/id all-bank-accounts) :bank-account-id)]
|
transaction->bank-account (comp all-bank-accounts :bank-account-id)]
|
||||||
(println "importing manual transactions" transformed-transactions)
|
(println "importing manual transactions" transformed-transactions)
|
||||||
(batch-transact
|
(batch-transact
|
||||||
(transactions->txs transformed-transactions transaction->bank-account (rm/rule-applying-fn all-rules) (get-existing)))))
|
(transactions->txs transformed-transactions transaction->bank-account (rm/rule-applying-fn all-rules) (get-existing)))))
|
||||||
|
|||||||
@@ -225,3 +225,31 @@
|
|||||||
[]
|
[]
|
||||||
rows)]
|
rows)]
|
||||||
@(d/transact conn txes)))
|
@(d/transact conn txes)))
|
||||||
|
|
||||||
|
(defn cash-flow-simple []
|
||||||
|
(->> (d/query {:query {:find '[?account-type-ident ?date ?debit ?credit]
|
||||||
|
:in '[$ ?client]
|
||||||
|
:where ['[?j :journal-entry/line-items ?je]
|
||||||
|
'[?j :journal-entry/date ?date]
|
||||||
|
'[?je :journal-entry-line/account ?a]
|
||||||
|
'[(get-else $ ?je :journal-entry-line/debit 0.0) ?debit]
|
||||||
|
'[(get-else $ ?je :journal-entry-line/credit 0.0) ?credit]
|
||||||
|
'[?a :account/type ?account-type]
|
||||||
|
'[?account-type :db/ident ?account-type-ident]]}
|
||||||
|
:args [(d/db (d/connect uri)) "CBC"]})
|
||||||
|
|
||||||
|
(reduce
|
||||||
|
(fn [result [account-type date debit credit]]
|
||||||
|
(let [date (clj-time.coerce/from-date date)]
|
||||||
|
(let [year-month (str (clj-time.core/year date) "-" (clj-time.core/month date))]
|
||||||
|
(-> result
|
||||||
|
(update-in [year-month account-type :debit]
|
||||||
|
(fn [existing-debit]
|
||||||
|
(+ (or existing-debit 0.0)
|
||||||
|
debit)))
|
||||||
|
(update-in [year-month account-type :credit]
|
||||||
|
(fn [existing-credit]
|
||||||
|
(+ (or existing-credit 0.0)
|
||||||
|
credit)))
|
||||||
|
(update-in [year-month account-type :count] #(inc (or % 0)))))))
|
||||||
|
{})))
|
||||||
|
|||||||
@@ -94,6 +94,12 @@
|
|||||||
[]
|
[]
|
||||||
clients))))
|
clients))))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::bank-accounts-by-id
|
||||||
|
:<- [::bank-accounts]
|
||||||
|
(fn [as]
|
||||||
|
(by :id as)))
|
||||||
|
|
||||||
;; Bank accounts only, not including cash
|
;; Bank accounts only, not including cash
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::real-bank-accounts
|
::real-bank-accounts
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
[reagent.core :as reagent]
|
[reagent.core :as reagent]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[cljs-time.format :as format]
|
[cljs-time.format :as format]
|
||||||
|
[cljs-time.core :as t]
|
||||||
[goog.string :as gstring]
|
[goog.string :as gstring]
|
||||||
[goog.i18n.NumberFormat.Format])
|
[goog.i18n.NumberFormat.Format])
|
||||||
)
|
)
|
||||||
@@ -86,8 +87,18 @@
|
|||||||
(:name client))])
|
(:name client))])
|
||||||
[:td (:name vendor)]
|
[:td (:name vendor)]
|
||||||
[:td invoice-number]
|
[:td invoice-number]
|
||||||
[:td (date->str date) ]
|
[:td (date->str date) ]
|
||||||
[:td (date->str due) ]
|
[:td
|
||||||
|
(when due
|
||||||
|
(let [today (t/at-midnight (t/now))
|
||||||
|
due (t/at-midnight due)
|
||||||
|
due-in (if (t/after? today due)
|
||||||
|
(- (t/in-days (t/interval (t/minus due (t/days 1)) today)))
|
||||||
|
(t/in-days (t/interval today due )))]
|
||||||
|
(if (> due-in 0)
|
||||||
|
[:span.has-text-success due-in " days"]
|
||||||
|
[:span.has-text-danger due-in " days"])
|
||||||
|
))]
|
||||||
[:td (str/join ", " (set (map :location expense-accounts)))]
|
[:td (str/join ", " (set (map :location expense-accounts)))]
|
||||||
|
|
||||||
[:td.has-text-right (nf total )]
|
[:td.has-text-right (nf total )]
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
{:keys [journal-entries start end count total]} @ledger-page
|
{:keys [journal-entries start end count total]} @ledger-page
|
||||||
selected-client @(re-frame/subscribe [::subs/client])
|
selected-client @(re-frame/subscribe [::subs/client])
|
||||||
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id selected-client])
|
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id selected-client])
|
||||||
|
bank-accounts-by-id @(re-frame/subscribe [::subs/bank-accounts-by-id])
|
||||||
percentage-size (if selected-client "25%" "33%")
|
percentage-size (if selected-client "25%" "33%")
|
||||||
opc (fn [e]
|
opc (fn [e]
|
||||||
(re-frame/dispatch [::params-changed e]))]
|
(re-frame/dispatch [::params-changed e]))]
|
||||||
@@ -115,7 +116,8 @@
|
|||||||
(when status?
|
(when status?
|
||||||
[:td status])]]
|
[:td status])]]
|
||||||
(for [{:keys [debit credit location account id]} line-items
|
(for [{:keys [debit credit location account id]} line-items
|
||||||
:let [account (accounts-by-id (:id account))]]
|
:let [account (or (accounts-by-id (:id account))
|
||||||
|
(bank-accounts-by-id (:id account)))]]
|
||||||
^{:key id}
|
^{:key id}
|
||||||
[:tr {:class (:class i)}
|
[:tr {:class (:class i)}
|
||||||
(when-not selected-client
|
(when-not selected-client
|
||||||
|
|||||||
Reference in New Issue
Block a user