added start date.
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
(ns auto-ap.datomic.clients
|
(ns auto-ap.datomic.clients
|
||||||
(:require [datomic.api :as d]
|
(:require [datomic.api :as d]
|
||||||
[auto-ap.datomic :refer [uri]]
|
[auto-ap.datomic :refer [uri]]
|
||||||
[clojure.tools.logging :as log]))
|
[clojure.tools.logging :as log]
|
||||||
|
[clj-time.coerce :as coerce]))
|
||||||
|
|
||||||
(defn cleanse [e]
|
(defn cleanse [e]
|
||||||
(-> e
|
(-> e
|
||||||
@@ -13,6 +14,7 @@
|
|||||||
(map (fn [i ba]
|
(map (fn [i ba]
|
||||||
(-> ba
|
(-> ba
|
||||||
(update :bank-account/type :db/ident )
|
(update :bank-account/type :db/ident )
|
||||||
|
(update :bank-account/start-date #(some-> % (coerce/to-date-time)))
|
||||||
(update :bank-account/sort-order (fn [so] (or so i)))))
|
(update :bank-account/sort-order (fn [so] (or so i)))))
|
||||||
(range) bas)))))
|
(range) bas)))))
|
||||||
(defn get-all []
|
(defn get-all []
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
[auto-ap.datomic.migrate.invoice-converter :refer [add-import-status-existing-invoices]]
|
[auto-ap.datomic.migrate.invoice-converter :refer [add-import-status-existing-invoices]]
|
||||||
[auto-ap.datomic.migrate.add-general-ledger :as add-general-ledger]
|
[auto-ap.datomic.migrate.add-general-ledger :as add-general-ledger]
|
||||||
[auto-ap.datomic.migrate.sales :as sales]
|
[auto-ap.datomic.migrate.sales :as sales]
|
||||||
|
[auto-ap.datomic.migrate.clients :as clients]
|
||||||
|
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[io.rkn.conformity :as c])
|
[io.rkn.conformity :as c])
|
||||||
@@ -94,7 +95,7 @@
|
|||||||
|
|
||||||
(let [
|
(let [
|
||||||
conn (d/connect uri)
|
conn (d/connect uri)
|
||||||
norms-map {:auto-ap/base-schema {:txes auto-ap.datomic/base-schema}
|
norms-map (merge {:auto-ap/base-schema {:txes auto-ap.datomic/base-schema}
|
||||||
:auto-ap/functions {:txes-fn 'auto-ap.datomic.migrate/functions
|
:auto-ap/functions {:txes-fn 'auto-ap.datomic.migrate/functions
|
||||||
:requires [:auto-ap/base-schema]}
|
:requires [:auto-ap/base-schema]}
|
||||||
:auto-ap/fx-pay-function-2 {:txes-fn 'auto-ap.datomic.migrate/fix-pay-function
|
:auto-ap/fx-pay-function-2 {:txes-fn 'auto-ap.datomic.migrate/fix-pay-function
|
||||||
@@ -312,10 +313,11 @@
|
|||||||
:db/valueType :db.type/boolean
|
:db/valueType :db.type/boolean
|
||||||
:db/cardinality :db.cardinality/one}]]}
|
:db/cardinality :db.cardinality/one}]]}
|
||||||
:auto-ap/fix-reset-rels {:txes-fn `reset-function}}
|
:auto-ap/fix-reset-rels {:txes-fn `reset-function}}
|
||||||
|
sales/norms-map
|
||||||
|
clients/norms-map)
|
||||||
]
|
]
|
||||||
(println "Conforming database...")
|
(println "Conforming database...")
|
||||||
(c/ensure-conforms conn norms-map)
|
(c/ensure-conforms conn norms-map)
|
||||||
(c/ensure-conforms conn sales/norms-map)
|
|
||||||
(when (not (seq args))
|
(when (not (seq args))
|
||||||
(d/release conn))
|
(d/release conn))
|
||||||
(println "Done")))
|
(println "Done")))
|
||||||
|
|||||||
@@ -95,6 +95,7 @@
|
|||||||
:bank_account
|
:bank_account
|
||||||
{:fields {:id {:type :id }
|
{:fields {:id {:type :id }
|
||||||
:type {:type :ident}
|
:type {:type :ident}
|
||||||
|
:start_date {:type :iso_date}
|
||||||
:number {:type 'String}
|
:number {:type 'String}
|
||||||
:sort_order {:type 'Int}
|
:sort_order {:type 'Int}
|
||||||
:visible {:type 'Boolean}
|
:visible {:type 'Boolean}
|
||||||
@@ -625,6 +626,7 @@
|
|||||||
{:fields {:id {:type :id }
|
{:fields {:id {:type :id }
|
||||||
:code {:type 'String}
|
:code {:type 'String}
|
||||||
:type {:type :bank_account_type}
|
:type {:type :bank_account_type}
|
||||||
|
:start_date {:type :iso_date}
|
||||||
:number {:type 'String}
|
:number {:type 'String}
|
||||||
:check_number {:type 'Int}
|
:check_number {:type 'Int}
|
||||||
:visible {:type 'Boolean}
|
:visible {:type 'Boolean}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
[auto-ap.datomic :refer [uri remove-nils]]
|
[auto-ap.datomic :refer [uri remove-nils]]
|
||||||
[auto-ap.graphql.utils :refer [->graphql assert-admin can-see-client?]]
|
[auto-ap.graphql.utils :refer [->graphql assert-admin can-see-client?]]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[clojure.tools.logging :as log]))
|
[clojure.tools.logging :as log]
|
||||||
|
[clj-time.coerce :as coerce]))
|
||||||
|
|
||||||
(defn assert-client-code-is-unique [code]
|
(defn assert-client-code-is-unique [code]
|
||||||
(when (seq (d/query {:query {:find '[?id]
|
(when (seq (d/query {:query {:find '[?id]
|
||||||
@@ -54,6 +55,7 @@
|
|||||||
:bank-account/code (:code %)
|
:bank-account/code (:code %)
|
||||||
:bank-account/bank-name (:bank_name %)
|
:bank-account/bank-name (:bank_name %)
|
||||||
:bank-account/bank-code (:bank_code %)
|
:bank-account/bank-code (:bank_code %)
|
||||||
|
:bank-account/start-date (-> (:start_date %) (coerce/to-date))
|
||||||
:bank-account/routing (:routing %)
|
:bank-account/routing (:routing %)
|
||||||
:bank-account/include-in-reports (:include_in_reports %)
|
:bank-account/include-in-reports (:include_in_reports %)
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,8 @@
|
|||||||
[auto-ap.rule-matching :as rm]
|
[auto-ap.rule-matching :as rm]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[unilog.context :as lc]
|
[unilog.context :as lc]
|
||||||
[clojure.tools.logging :as log]))
|
[clojure.tools.logging :as log]
|
||||||
|
[clj-time.core :as t]))
|
||||||
|
|
||||||
|
|
||||||
(defn rough-match [client-id bank-account-id amount]
|
(defn rough-match [client-id bank-account-id amount]
|
||||||
@@ -89,17 +90,21 @@
|
|||||||
client (:client/_bank-accounts bank-account)
|
client (:client/_bank-accounts bank-account)
|
||||||
client-id (:db/id client)
|
client-id (:db/id client)
|
||||||
valid-locations (or (:bank-account/locations bank-account) (:client/locations client))
|
valid-locations (or (:bank-account/locations bank-account) (:client/locations client))
|
||||||
check (transaction->payment transaction check-number client-id bank-account-id amount id)]
|
check (transaction->payment transaction check-number client-id bank-account-id amount id)
|
||||||
|
date (time/parse date "YYYY-MM-dd")]
|
||||||
:when (and client-id
|
:when (and client-id
|
||||||
(not (existing (sha-256 (str id))))
|
(not (existing (sha-256 (str id))))
|
||||||
(= "POSTED" status)
|
(= "POSTED" status)
|
||||||
|
|
||||||
|
(or (not (:start-date bank-account))
|
||||||
|
(t/after? date (:start-date bank-account)))
|
||||||
)]
|
)]
|
||||||
(->
|
(->
|
||||||
#:transaction
|
#:transaction
|
||||||
{:post-date (coerce/to-date (time/parse post-date "YYYY-MM-dd"))
|
{:post-date (coerce/to-date (time/parse post-date "YYYY-MM-dd"))
|
||||||
:id (sha-256 (str id))
|
:id (sha-256 (str id))
|
||||||
:account-id account-id
|
:account-id account-id
|
||||||
:date (coerce/to-date (time/parse date "YYYY-MM-dd"))
|
:date (coerce/to-date date)
|
||||||
:amount (double amount)
|
:amount (double amount)
|
||||||
:description-original (some-> description-original (str/replace #"\s+" " "))
|
:description-original (some-> description-original (str/replace #"\s+" " "))
|
||||||
:description-simple (some-> description-simple (str/replace #"\s+" " "))
|
:description-simple (some-> description-simple (str/replace #"\s+" " "))
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
:graphql {:token token
|
:graphql {:token token
|
||||||
:query-obj {:venia/queries [[:client
|
:query-obj {:venia/queries [[:client
|
||||||
|
|
||||||
[:id :name :code :email :matches :week-a-debits :week-a-credits :week-b-debits :week-b-credits :locations [:location-matches [:id :location :match]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id :locations :include-in-reports] ]
|
[:id :name :code :email :matches :week-a-debits :week-a-credits :week-b-debits :week-b-credits :locations [:location-matches [:id :location :match]] [:bank-accounts [:id :start-date :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id :locations :include-in-reports] ]
|
||||||
[:address [:street1 :street2 :city :state :zip]]
|
[:address [:street1 :street2 :city :state :zip]]
|
||||||
[:forecasted-transactions [:id :amount :identifier :day-of-month]]]]
|
[:forecasted-transactions [:id :amount :identifier :day-of-month]]]]
|
||||||
[:vendor
|
[:vendor
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
:query-obj {:venia/queries [[:client
|
:query-obj {:venia/queries [[:client
|
||||||
[:id :name :code :matches :locations :week-a-debits :week-a-credits :week-b-debits :week-b-credits [:location-matches [:id :location :match]]
|
[:id :name :code :matches :locations :week-a-debits :week-a-credits :week-b-debits :week-b-credits [:location-matches [:id :location :match]]
|
||||||
[:address [:street1 :street2 :city :state :zip]]
|
[:address [:street1 :street2 :city :state :zip]]
|
||||||
[:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id :locations :include-in-reports] ]
|
[:bank-accounts [:id :start-date :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id :locations :include-in-reports] ]
|
||||||
[:forecasted-transactions [:id :amount :identifier :day-of-month]]]]
|
[:forecasted-transactions [:id :amount :identifier :day-of-month]]]]
|
||||||
[:vendor
|
[:vendor
|
||||||
vendor-query]
|
vendor-query]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
[auto-ap.subs :as subs]
|
[auto-ap.subs :as subs]
|
||||||
[auto-ap.views.components.address :refer [address-field]]
|
[auto-ap.views.components.address :refer [address-field]]
|
||||||
[auto-ap.views.components.layouts :refer [side-bar]]
|
[auto-ap.views.components.layouts :refer [side-bar]]
|
||||||
[auto-ap.views.utils :refer [dispatch-event horizontal-field nf multi-field]]
|
[auto-ap.views.utils :refer [dispatch-event horizontal-field nf multi-field date-picker standard date->str]]
|
||||||
[cljs-time.coerce :as coerce]
|
[cljs-time.coerce :as coerce]
|
||||||
[cljs-time.core :as t]
|
[cljs-time.core :as t]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
@@ -44,11 +44,20 @@
|
|||||||
:identifier identifier
|
:identifier identifier
|
||||||
:amount amount})
|
:amount amount})
|
||||||
(:forecasted-transactions new-client-data))
|
(:forecasted-transactions new-client-data))
|
||||||
:bank-accounts (map (fn [{:keys [number name check-number include-in-reports type id code bank-name routing bank-code new? sort-order visible yodlee-account-id locations]}]
|
:bank-accounts (map (fn [{:keys [number name check-number include-in-reports type id code start-date bank-name routing bank-code new? sort-order visible yodlee-account-id locations]}]
|
||||||
{:number number
|
{:number number
|
||||||
:name name
|
:name name
|
||||||
:check-number check-number
|
:check-number check-number
|
||||||
:include-in-reports include-in-reports
|
:include-in-reports include-in-reports
|
||||||
|
:start-date (cond (not start-date)
|
||||||
|
nil
|
||||||
|
|
||||||
|
(instance? goog.date.Date start-date)
|
||||||
|
(date->str start-date standard)
|
||||||
|
|
||||||
|
:else
|
||||||
|
start-date
|
||||||
|
)
|
||||||
:type type
|
:type type
|
||||||
:id id
|
:id id
|
||||||
:sort-order sort-order
|
:sort-order sort-order
|
||||||
@@ -101,7 +110,7 @@
|
|||||||
[:location-matches [:location :match :id]]
|
[:location-matches [:location :match :id]]
|
||||||
[:address [:street1 :street2 :city :state :zip]]
|
[:address [:street1 :street2 :city :state :zip]]
|
||||||
[:forecasted-transactions [:id :amount :identifier :day-of-month]]
|
[:forecasted-transactions [:id :amount :identifier :day-of-month]]
|
||||||
[:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing :type :visible :yodlee-account-id :sort-order :locations]]]]}]}
|
[:bank-accounts [:id :number :start-date :check-number :name :code :bank-code :bank-name :routing :type :visible :yodlee-account-id :sort-order :locations]]]]}]}
|
||||||
:on-success [::save-complete]
|
:on-success [::save-complete]
|
||||||
:on-error [::forms/save-error ::form]}})))
|
:on-error [::forms/save-error ::form]}})))
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
@@ -231,7 +240,17 @@
|
|||||||
[field "Nickname"
|
[field "Nickname"
|
||||||
[:input.input {:placeholder "BOA Checking #1"
|
[:input.input {:placeholder "BOA Checking #1"
|
||||||
:type "text"
|
:type "text"
|
||||||
:field [:bank-accounts sort-order :name]}]]]
|
:field [:bank-accounts sort-order :name]}]]
|
||||||
|
[field "Start date"
|
||||||
|
[date-picker {:class-name "input"
|
||||||
|
:class "input"
|
||||||
|
:format-week-number (fn [] "")
|
||||||
|
:previous-month-button-label ""
|
||||||
|
:placeholder "mm/dd/yyyy"
|
||||||
|
:next-month-button-label ""
|
||||||
|
:next-month-label ""
|
||||||
|
:type "date"
|
||||||
|
:field [:bank-accounts sort-order :start-date]}]]]
|
||||||
(when (#{:check ":check"} type )
|
(when (#{:check ":check"} type )
|
||||||
[:div
|
[:div
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
:merchant {:id "123"
|
:merchant {:id "123"
|
||||||
:name "456"}
|
:name "456"}
|
||||||
:baseType "DEBIT"
|
:baseType "DEBIT"
|
||||||
:status "PENDING"
|
:status "POSTED"
|
||||||
|
|
||||||
:bank-account {:db/id 456
|
:bank-account {:db/id 456
|
||||||
:client/_bank-accounts {:db/id 123
|
:client/_bank-accounts {:db/id 123
|
||||||
@@ -49,14 +49,22 @@
|
|||||||
:post-date #inst "2014-01-04T08:00:00.000-00:00"
|
:post-date #inst "2014-01-04T08:00:00.000-00:00"
|
||||||
:account-id 1234
|
:account-id 1234
|
||||||
:description-original "original-description"
|
:description-original "original-description"
|
||||||
:yodlee-merchant #:yodlee-merchant {:yodlee-id "123"
|
:status "POSTED"
|
||||||
:name "456"}
|
|
||||||
:status "PENDING"
|
|
||||||
:id "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b"
|
:id "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b"
|
||||||
:approval-status :transaction-approval-status/unapproved
|
:approval-status :transaction-approval-status/unapproved
|
||||||
:description-simple "simple-description"}]
|
:description-simple "simple-description"}]
|
||||||
result))))
|
result))))
|
||||||
|
|
||||||
|
(t/testing "Should exclude a transaction before start date"
|
||||||
|
(let [result (sut/transactions->txs [(assoc-in base-transaction
|
||||||
|
[:bank-account :start-date]
|
||||||
|
(clj-time.coerce/to-date-time #inst "2020-01-01"))]
|
||||||
|
:bank-account
|
||||||
|
noop-rule
|
||||||
|
#{})]
|
||||||
|
(t/is (= []
|
||||||
|
result))))
|
||||||
|
|
||||||
(t/testing "Should not reimport an existing transaction"
|
(t/testing "Should not reimport an existing transaction"
|
||||||
(let [result (sut/transactions->txs [base-transaction]
|
(let [result (sut/transactions->txs [base-transaction]
|
||||||
:bank-account
|
:bank-account
|
||||||
@@ -207,23 +215,28 @@
|
|||||||
:transaction-rule/transaction-approval-status :transaction-approval-status/approved
|
:transaction-rule/transaction-approval-status :transaction-approval-status/approved
|
||||||
:transaction-rule/vendor {:db/id 123}}])]
|
:transaction-rule/vendor {:db/id 123}}])]
|
||||||
(t/is (= 123
|
(t/is (= 123
|
||||||
(-> {:transaction/date #inst "2019-01-04T00:00:00.000-08:00"}
|
(-> {:transaction/date #inst "2019-01-04T00:00:00.000-08:00"
|
||||||
|
:transaction/amount 1.0}
|
||||||
(apply-rules [])
|
(apply-rules [])
|
||||||
:transaction/matched-rule)))
|
:transaction/matched-rule)))
|
||||||
(t/is (= 123
|
(t/is (= 123
|
||||||
(-> {:transaction/date #inst "2019-01-03T00:00:00.000-08:00"}
|
(-> {:transaction/date #inst "2019-01-03T00:00:00.000-08:00"
|
||||||
|
:transaction/amount 1.0}
|
||||||
(apply-rules [])
|
(apply-rules [])
|
||||||
:transaction/matched-rule)))
|
:transaction/matched-rule)))
|
||||||
(t/is (= 123
|
(t/is (= 123
|
||||||
(-> {:transaction/date #inst "2019-01-09T00:00:00.000-08:00"}
|
(-> {:transaction/date #inst "2019-01-09T00:00:00.000-08:00"
|
||||||
|
:transaction/amount 1.0}
|
||||||
(apply-rules [])
|
(apply-rules [])
|
||||||
:transaction/matched-rule)))
|
:transaction/matched-rule)))
|
||||||
(t/is (nil?
|
(t/is (nil?
|
||||||
(-> {:transaction/date #inst "2019-01-01T00:00:00.000-08:00"}
|
(-> {:transaction/date #inst "2019-01-01T00:00:00.000-08:00"
|
||||||
|
:transaction/amount 1.0}
|
||||||
(apply-rules [])
|
(apply-rules [])
|
||||||
:transaction/matched-rule)))
|
:transaction/matched-rule)))
|
||||||
(t/is (nil?
|
(t/is (nil?
|
||||||
(-> {:transaction/date #inst "2019-01-10T00:00:00.000-08:00"}
|
(-> {:transaction/date #inst "2019-01-10T00:00:00.000-08:00"
|
||||||
|
:transaction/amount 1.0}
|
||||||
(apply-rules [])
|
(apply-rules [])
|
||||||
:transaction/matched-rule)))))
|
:transaction/matched-rule)))))
|
||||||
|
|
||||||
@@ -232,6 +245,8 @@
|
|||||||
:transaction-rule/amount-gte 3.0
|
:transaction-rule/amount-gte 3.0
|
||||||
:transaction-rule/amount-lte 9.0
|
:transaction-rule/amount-lte 9.0
|
||||||
:transaction-rule/transaction-approval-status :transaction-approval-status/approved
|
:transaction-rule/transaction-approval-status :transaction-approval-status/approved
|
||||||
|
:transaction-rule/accounts [#:transaction-rule-account {:percentage 1.0
|
||||||
|
:locatoin "HQ"}]
|
||||||
:transaction-rule/vendor {:db/id 123}}])]
|
:transaction-rule/vendor {:db/id 123}}])]
|
||||||
(t/is (= 123
|
(t/is (= 123
|
||||||
(-> {:transaction/amount 4.0}
|
(-> {:transaction/amount 4.0}
|
||||||
@@ -258,22 +273,26 @@
|
|||||||
(let [apply-rules (rm/rule-applying-fn [{:db/id 123
|
(let [apply-rules (rm/rule-applying-fn [{:db/id 123
|
||||||
:transaction-rule/client {:db/id 456}}])]
|
:transaction-rule/client {:db/id 456}}])]
|
||||||
(t/is (= 123
|
(t/is (= 123
|
||||||
(-> {:transaction/client 456}
|
(-> {:transaction/client 456
|
||||||
|
:transaction/amount 1.0}
|
||||||
(apply-rules [])
|
(apply-rules [])
|
||||||
:transaction/matched-rule)))
|
:transaction/matched-rule)))
|
||||||
(t/is (nil?
|
(t/is (nil?
|
||||||
(-> {:transaction/client 89}
|
(-> {:transaction/client 89
|
||||||
|
:transaction/amount 1.0}
|
||||||
(apply-rules [])
|
(apply-rules [])
|
||||||
:transaction/matched-rule)))))
|
:transaction/matched-rule)))))
|
||||||
(t/testing "Should match if bank-account matches"
|
(t/testing "Should match if bank-account matches"
|
||||||
(let [apply-rules (rm/rule-applying-fn [{:db/id 123
|
(let [apply-rules (rm/rule-applying-fn [{:db/id 123
|
||||||
:transaction-rule/bank-account {:db/id 456}}])]
|
:transaction-rule/bank-account {:db/id 456}}])]
|
||||||
(t/is (= 123
|
(t/is (= 123
|
||||||
(-> {:transaction/bank-account 456}
|
(-> {:transaction/bank-account 456
|
||||||
|
:transaction/amount 1.0}
|
||||||
(apply-rules [])
|
(apply-rules [])
|
||||||
:transaction/matched-rule)))
|
:transaction/matched-rule)))
|
||||||
(t/is (nil?
|
(t/is (nil?
|
||||||
(-> {:transaction/bank-account 89}
|
(-> {:transaction/bank-account 89
|
||||||
|
:transaction/amount 1.0}
|
||||||
(apply-rules [])
|
(apply-rules [])
|
||||||
:transaction/matched-rule)))))
|
:transaction/matched-rule)))))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user