several fixes.
This commit is contained in:
@@ -228,7 +228,10 @@
|
||||
:db/doc "client override"
|
||||
:db/valueType :db.type/string
|
||||
: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...")
|
||||
(c/ensure-conforms conn norms-map)
|
||||
(when (not (seq args))
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
@(d/transact (d/connect auto-ap.datomic/uri)
|
||||
tx)
|
||||
(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/vendor (:db/id (:transaction/vendor 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/location "A"
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
[ring.middleware.json :refer [wrap-json-response]]
|
||||
[compojure.core :refer [GET POST context defroutes
|
||||
wrap-routes]]
|
||||
[clojure.string :as str]))
|
||||
[clojure.string :as str]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.data.csv :as csv]))
|
||||
|
||||
(defn reset-id [i]
|
||||
(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
|
||||
(wrap-routes
|
||||
(context "/" []
|
||||
@@ -346,8 +362,8 @@
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)
|
||||
:data (ex-data e)})
|
||||
:headers {"Content-Type" "application/edn"}}))
|
||||
))
|
||||
:headers {"Content-Type" "application/edn"}}))))
|
||||
|
||||
(POST "/upload-integreat"
|
||||
{{:keys [excel-rows]} :edn-params user :identity}
|
||||
(assert-admin user)
|
||||
@@ -369,20 +385,36 @@
|
||||
:else
|
||||
:new))
|
||||
parsed-invoice-rows)
|
||||
|
||||
|
||||
vendors-not-found (->> parsed-invoice-rows
|
||||
(filter #(and (nil? (:vendor-id %))
|
||||
(not= "Cash" (:check %))))
|
||||
(map :vendor-name)
|
||||
set)
|
||||
|
||||
inserted-rows @(d/transact (d/connect uri) (invoice-rows->transaction (:new grouped-rows)))]
|
||||
|
||||
{:status 200
|
||||
:body (pr-str {:imported (count (:new grouped-rows))
|
||||
:already-imported (count (:exists grouped-rows))
|
||||
:vendors-not-found vendors-not-found
|
||||
: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))
|
||||
|
||||
@@ -165,8 +165,8 @@
|
||||
(range)
|
||||
transaction-group))))
|
||||
all-rules (tr/get-all)
|
||||
all-bank-accounts (get-all-bank-accounts)
|
||||
transaction->bank-account (comp (by :db/id all-bank-accounts) :bank-account-id)]
|
||||
all-bank-accounts (by :db/id (get-all-bank-accounts))
|
||||
transaction->bank-account (comp all-bank-accounts :bank-account-id)]
|
||||
(println "importing manual transactions" transformed-transactions)
|
||||
(batch-transact
|
||||
(transactions->txs transformed-transactions transaction->bank-account (rm/rule-applying-fn all-rules) (get-existing)))))
|
||||
|
||||
@@ -225,3 +225,31 @@
|
||||
[]
|
||||
rows)]
|
||||
@(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)))))))
|
||||
{})))
|
||||
|
||||
Reference in New Issue
Block a user