reimplemented import
This commit is contained in:
@@ -214,8 +214,7 @@
|
|||||||
:db/doc "Current check number"}
|
:db/doc "Current check number"}
|
||||||
|
|
||||||
{:db/ident :bank-account-type/check}
|
{:db/ident :bank-account-type/check}
|
||||||
{:db/ident :bank-account-type/cash}
|
{:db/ident :bank-account-type/cash}])
|
||||||
])
|
|
||||||
|
|
||||||
(def invoice-schema
|
(def invoice-schema
|
||||||
[{:db/ident :invoice/original-id
|
[{:db/ident :invoice/original-id
|
||||||
@@ -750,6 +749,3 @@
|
|||||||
|
|
||||||
(defn migrate-users [conn]
|
(defn migrate-users [conn]
|
||||||
[(load-users (users/get-all))])
|
[(load-users (users/get-all))])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,9 @@
|
|||||||
|
|
||||||
(:client-id args) (add-arg '?client-id (:client-id args)
|
(:client-id args) (add-arg '?client-id (:client-id args)
|
||||||
'[?e :payment/client ?client-id])
|
'[?e :payment/client ?client-id])
|
||||||
|
(:client-code args) (add-arg '?client-code (:client-code args)
|
||||||
|
'[?e :payment/client ?client-id]
|
||||||
|
'[?client-id :client/code ?client-code] )
|
||||||
(:vendor-id args) (add-arg '?vendor-id (:vendor-id args)
|
(:vendor-id args) (add-arg '?vendor-id (:vendor-id args)
|
||||||
'[?e :payment/vendor ?vendor-id])
|
'[?e :payment/vendor ?vendor-id])
|
||||||
(:original-id args) (add-arg '?original-id (cond-> (:original-id args) (string? (:original-id args)) Long/parseLong )
|
(:original-id args) (add-arg '?original-id (cond-> (:original-id args) (string? (:original-id args)) Long/parseLong )
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
{:invoice/vendor [:vendor/name :db/id]}
|
{:invoice/vendor [:vendor/name :db/id]}
|
||||||
{:invoice/status [:db/ident]}
|
{:invoice/status [:db/ident]}
|
||||||
{:invoice-payment/_invoice [* {:invoice-payment/payment [* {:payment/status [*]}
|
{:invoice-payment/_invoice [* {:invoice-payment/payment [* {:payment/status [*]}
|
||||||
|
{:payment/bank-account [*]}
|
||||||
{:transaction/_payment [*]}]}]}]))
|
{:transaction/_payment [*]}]}]}]))
|
||||||
|
|
||||||
(defn <-datomic [x]
|
(defn <-datomic [x]
|
||||||
@@ -41,6 +42,10 @@
|
|||||||
(:client-id args) (add-arg '?client-id (:client-id args)
|
(:client-id args) (add-arg '?client-id (:client-id args)
|
||||||
'[?e :invoice/client ?client-id])
|
'[?e :invoice/client ?client-id])
|
||||||
|
|
||||||
|
(:client-code args) (add-arg '?client-code (:client-code args)
|
||||||
|
'[?e :invoice/client ?client-id]
|
||||||
|
'[?client-id :client/code ?client-code])
|
||||||
|
|
||||||
(:original-id args) (add-arg '?original-id (cond-> (:original-id args) (string? (:original-id args)) Long/parseLong )
|
(:original-id args) (add-arg '?original-id (cond-> (:original-id args) (string? (:original-id args)) Long/parseLong )
|
||||||
'[?e :invoice/client ?c]
|
'[?e :invoice/client ?c]
|
||||||
'[?c :client/original-id ?original-id])
|
'[?c :client/original-id ?original-id])
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
(:require [auto-ap.datomic :refer [uri]]
|
(:require [auto-ap.datomic :refer [uri]]
|
||||||
[datomic.api :as d]
|
[datomic.api :as d]
|
||||||
[auto-ap.datomic.migrate.add-client-codes :refer [add-client-codes]]
|
[auto-ap.datomic.migrate.add-client-codes :refer [add-client-codes]]
|
||||||
|
[auto-ap.datomic.migrate.add-bank-account-codes :refer [add-bank-account-codes]]
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[io.rkn.conformity :as c])
|
[io.rkn.conformity :as c])
|
||||||
(:import [datomic Util])
|
(:import [datomic Util])
|
||||||
@@ -50,6 +51,8 @@
|
|||||||
:auto-ap/migrate-invoices-expense-accounts {:txes-fn 'auto-ap.datomic/migrate-invoices-expense-accounts :requires [:auto-ap/migrate-invoices-payments]}
|
:auto-ap/migrate-invoices-expense-accounts {:txes-fn 'auto-ap.datomic/migrate-invoices-expense-accounts :requires [:auto-ap/migrate-invoices-payments]}
|
||||||
:auto-ap/migrate-transactions {:txes-fn 'auto-ap.datomic/migrate-transactions :requires [:auto-ap/migrate-invoices-expense-accounts]}
|
:auto-ap/migrate-transactions {:txes-fn 'auto-ap.datomic/migrate-transactions :requires [:auto-ap/migrate-invoices-expense-accounts]}
|
||||||
:auto-ap/add-client-codes {:txes-fn 'auto-ap.datomic.migrate.add-client-codes/add-client-codes :requires [:auto-ap/migrate-transactions]}
|
:auto-ap/add-client-codes {:txes-fn 'auto-ap.datomic.migrate.add-client-codes/add-client-codes :requires [:auto-ap/migrate-transactions]}
|
||||||
|
:auto-ap/add-bank-account-codes-schema {:txes-fn 'auto-ap.datomic.migrate.add-bank-account-codes/add-bank-account-codes-schema :requires [:auto-ap/add-client-codes]}
|
||||||
|
:auto-ap/add-bank-account-codes {:txes-fn 'auto-ap.datomic.migrate.add-bank-account-codes/add-bank-account-codes :requires [:auto-ap/add-bank-account-codes-schema]}
|
||||||
}]
|
}]
|
||||||
(println "Conforming database...")
|
(println "Conforming database...")
|
||||||
(println (c/ensure-conforms conn norms-map))
|
(println (c/ensure-conforms conn norms-map))
|
||||||
|
|||||||
28
src/clj/auto_ap/datomic/migrate/add_bank_account_codes.clj
Normal file
28
src/clj/auto_ap/datomic/migrate/add_bank_account_codes.clj
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
(ns auto-ap.datomic.migrate.add-bank-account-codes
|
||||||
|
(:require [datomic.api :as d]
|
||||||
|
[auto-ap.datomic :refer [uri]]
|
||||||
|
[clojure.string :as str]))
|
||||||
|
|
||||||
|
(defn add-bank-account-codes-schema [conn]
|
||||||
|
[[{:db/ident :bank-account/code
|
||||||
|
:db/valueType :db.type/string
|
||||||
|
:db/unique :db.unique/identity
|
||||||
|
:db/cardinality :db.cardinality/one
|
||||||
|
:db/doc "A bank account's computer-friendly name"}]])
|
||||||
|
|
||||||
|
|
||||||
|
(defn add-bank-account-codes [conn]
|
||||||
|
(let [db (d/db conn)
|
||||||
|
all-bank-accounts (d/query {:query {:find ['?b '?original-id '?client-code]
|
||||||
|
:in ['$]
|
||||||
|
:where ['[?c :client/code ?client-code]
|
||||||
|
'[?c :client/bank-accounts ?b]
|
||||||
|
'[?b :bank-account/original-id ?original-id]]}
|
||||||
|
:args [db]})]
|
||||||
|
[(mapv (fn [[bank-account-id bank-account-code client-code ]]
|
||||||
|
(let [[_ bank-account-code] (str/split bank-account-code #"-" )]
|
||||||
|
{:db/id bank-account-id
|
||||||
|
:bank-account/code (str client-code "-" bank-account-code)}))
|
||||||
|
all-bank-accounts)]))
|
||||||
|
|
||||||
|
#_(add-bank-account-codes (d/connect uri))
|
||||||
@@ -84,6 +84,11 @@
|
|||||||
:where ['[?e :transaction/client ?client-id]]}
|
:where ['[?e :transaction/client ?client-id]]}
|
||||||
:args [(:client-id args)]})
|
:args [(:client-id args)]})
|
||||||
|
|
||||||
|
(:client-code args)
|
||||||
|
(merge-query {:query {:in ['?client-code]
|
||||||
|
:where ['[?e :transaction/client ?client-id]
|
||||||
|
'[?client-id :client/code ?client-code]]}
|
||||||
|
:args [(:client-code args)]})
|
||||||
|
|
||||||
(:original-id args)
|
(:original-id args)
|
||||||
(merge-query {:query {:in ['?original-id]
|
(merge-query {:query {:in ['?original-id]
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
{:fields {:id {:type :id }
|
{:fields {:id {:type :id }
|
||||||
:type {:type :bank_account_type}
|
:type {:type :bank_account_type}
|
||||||
:number {:type 'String}
|
:number {:type 'String}
|
||||||
|
:code {:type 'String}
|
||||||
:check_number {:type 'Int}
|
:check_number {:type 'Int}
|
||||||
:name {:type 'String}
|
:name {:type 'String}
|
||||||
:bank_code {:type 'String}
|
:bank_code {:type 'String}
|
||||||
@@ -214,12 +215,14 @@
|
|||||||
|
|
||||||
:all_invoices {:type '(list :invoice)
|
:all_invoices {:type '(list :invoice)
|
||||||
:args {:client_id {:type :id}
|
:args {:client_id {:type :id}
|
||||||
|
:client_code {:type 'String}
|
||||||
:original_id {:type 'Int}
|
:original_id {:type 'Int}
|
||||||
:statuses {:type '(list String)}}
|
:statuses {:type '(list String)}}
|
||||||
:resolve :get-all-invoices}
|
:resolve :get-all-invoices}
|
||||||
|
|
||||||
:all_payments {:type '(list :payment)
|
:all_payments {:type '(list :payment)
|
||||||
:args {:client_id {:type :id}
|
:args {:client_id {:type :id}
|
||||||
|
:client_code {:type 'String}
|
||||||
:original_id {:type 'Int}
|
:original_id {:type 'Int}
|
||||||
:statuses {:type '(list String)}}
|
:statuses {:type '(list String)}}
|
||||||
:resolve :get-all-payments}
|
:resolve :get-all-payments}
|
||||||
@@ -263,6 +266,7 @@
|
|||||||
:bank_accounts {:type '(list :edit_bank_account)}}}
|
:bank_accounts {:type '(list :edit_bank_account)}}}
|
||||||
:edit_bank_account
|
:edit_bank_account
|
||||||
{:fields {:id {:type :id }
|
{:fields {:id {:type :id }
|
||||||
|
:code {:type 'String}
|
||||||
:type {:type :bank_account_type}
|
:type {:type :bank_account_type}
|
||||||
:number {:type 'String}
|
:number {:type 'String}
|
||||||
:check_number {:type 'Int}
|
:check_number {:type 'Int}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
:client/bank-accounts (map #(remove-nils
|
:client/bank-accounts (map #(remove-nils
|
||||||
{:db/id (:id %)
|
{:db/id (:id %)
|
||||||
|
: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/routing (:routing %)
|
:bank-account/routing (:routing %)
|
||||||
|
|||||||
@@ -21,20 +21,21 @@
|
|||||||
(GET "/invoices/export" {:keys [query-params identity] :as request}
|
(GET "/invoices/export" {:keys [query-params identity] :as request}
|
||||||
(assert-admin identity)
|
(assert-admin identity)
|
||||||
(let [query [[:all_invoices
|
(let [query [[:all_invoices
|
||||||
{:client-id (query-params "client")
|
{:client-code (query-params "client-code")
|
||||||
:original-id (query-params "original")}
|
:original-id (query-params "original")}
|
||||||
[:id :total :outstanding-balance :invoice-number :date :status
|
[:id :total :outstanding-balance :invoice-number :date :status
|
||||||
[:payments [:amount [:payment [:check-number :memo [:bank_account [:id :number :bank-name :bank-code]]]]]]
|
[:payments [:amount [:payment [:check-number :memo [:bank_account [:id :name :number :bank-name :bank-code]]]]]]
|
||||||
[:vendor [:name :id [:primary_contact [:name]] [:address [:street1 :city :state :zip]]]]
|
[:vendor [:name :id [:primary_contact [:name]] [:address [:street1 :city :state :zip]]]]
|
||||||
[:expense_accounts [:amount :id :expense_account_id :location
|
[:expense_accounts [:amount :id :expense_account_id :location
|
||||||
[:expense_account [:id :name [:parent [:id :name]]]]]]
|
[:expense_account [:id :name [:parent [:id :name]]]]]]
|
||||||
[:client [:name :id :locations]]]]]
|
[:client [:name :id :locations]]]]]
|
||||||
invoices (graphql/query identity (venia/graphql-query {:venia/queries (->graphql query)}))]
|
invoices (graphql/query identity (venia/graphql-query {:venia/queries (->graphql query)}))]
|
||||||
(list (:all-invoices (:data invoices)))))
|
|
||||||
|
(doto (list (:all-invoices (:data invoices))) clojure.pprint/pprint)))
|
||||||
(GET "/payments/export" {:keys [query-params identity]}
|
(GET "/payments/export" {:keys [query-params identity]}
|
||||||
(assert-admin identity)
|
(assert-admin identity)
|
||||||
(let [query [[:all_payments
|
(let [query [[:all_payments
|
||||||
{:client-id (query-params "client")
|
{:client-code (query-params "client-code")
|
||||||
:original-id (query-params "original")}
|
:original-id (query-params "original")}
|
||||||
[:id :check-number :amount :memo :date :status :type
|
[:id :check-number :amount :memo :date :status :type
|
||||||
[:invoices [[:invoice [:id]] :amount]]
|
[:invoices [[:invoice [:id]] :amount]]
|
||||||
@@ -54,7 +55,7 @@
|
|||||||
(map <-graphql (d-vendors/get-graphql {})))
|
(map <-graphql (d-vendors/get-graphql {})))
|
||||||
(GET "/transactions/export" {:keys [query-params identity]}
|
(GET "/transactions/export" {:keys [query-params identity]}
|
||||||
(assert-admin identity)
|
(assert-admin identity)
|
||||||
(let [[transactions] (d-transactions/get-graphql {:client-id (Long/parseLong (query-params "client"))
|
(let [[transactions] (d-transactions/get-graphql {:client-code (query-params "client-code")
|
||||||
#_#_:original-id (Integer/parseInt (query-params "original"))
|
#_#_:original-id (Integer/parseInt (query-params "original"))
|
||||||
:limit Integer/MAX_VALUE})
|
:limit Integer/MAX_VALUE})
|
||||||
transactions (map <-graphql transactions)]
|
transactions (map <-graphql transactions)]
|
||||||
|
|||||||
@@ -72,12 +72,7 @@
|
|||||||
(catch Exception e
|
(catch Exception e
|
||||||
(throw (Exception. (str "Could not parse account from value '" (:bank-account-id i) "'") e)))))
|
(throw (Exception. (str "Could not parse account from value '" (:bank-account-id i) "'") e)))))
|
||||||
|
|
||||||
(defn parse-client-id [i]
|
|
||||||
(try
|
|
||||||
(Long/parseLong (second
|
|
||||||
(re-matches #"[^0-9,\\-]*([0-9,\\-]+)[^0-9,]*" (:client-id i))))
|
|
||||||
(catch Exception e
|
|
||||||
(throw (Exception. (str "Could not parse client from value '" (:client-id i) "'") e)))))
|
|
||||||
|
|
||||||
(defn parse-date [{:keys [raw-date]}]
|
(defn parse-date [{:keys [raw-date]}]
|
||||||
(try
|
(try
|
||||||
@@ -94,7 +89,7 @@
|
|||||||
:details (str e)})))))
|
:details (str e)})))))
|
||||||
|
|
||||||
(defn parse-invoice-rows [excel-rows]
|
(defn parse-invoice-rows [excel-rows]
|
||||||
(let [columns [:raw-date :vendor-name :check :location :invoice-number :amount :client :bill-entered :bill-rejected :added-on :exported-on :default-expense-account]
|
(let [columns [:raw-date :vendor-name :check :location :invoice-number :amount :client-name :bill-entered :bill-rejected :added-on :exported-on :default-expense-account]
|
||||||
all-vendors (by :vendor/name (d-vendors/get-graphql {}))
|
all-vendors (by :vendor/name (d-vendors/get-graphql {}))
|
||||||
all-clients (d-clients/get-all)
|
all-clients (d-clients/get-all)
|
||||||
all-clients (merge (by :client/code all-clients) (by :client/name all-clients))
|
all-clients (merge (by :client/code all-clients) (by :client/name all-clients))
|
||||||
@@ -154,29 +149,31 @@
|
|||||||
(POST "/batch-upload"
|
(POST "/batch-upload"
|
||||||
{{:keys [data]} :edn-params user :identity}
|
{{:keys [data]} :edn-params user :identity}
|
||||||
(assert-admin user)
|
(assert-admin user)
|
||||||
(let [columns [:status :raw-date :description-original :high-level-category nil nil :amount nil nil nil nil nil :bank-account-id :client-id]
|
(let [columns [:status :raw-date :description-original :high-level-category nil nil :amount nil nil nil nil nil :bank-account-code :client-code]
|
||||||
|
all-clients (d-clients/get-all)
|
||||||
|
all-bank-accounts (mapcat :client/bank-accounts all-clients)
|
||||||
|
all-clients (merge (by :client/code all-clients) (by :client/name all-clients))
|
||||||
|
all-bank-accounts (merge (by :bank-account/code all-bank-accounts))
|
||||||
rows (->> (str/split data #"\n" )
|
rows (->> (str/split data #"\n" )
|
||||||
(drop 1)
|
(drop 1)
|
||||||
(map #(str/split % #"\t"))
|
(map #(str/split % #"\t"))
|
||||||
(map #(into {} (filter identity (map (fn [c k] [k c] ) % columns))))
|
(map #(into {} (filter identity (map (fn [c k] [k c] ) % columns))))
|
||||||
|
|
||||||
(map (parse-or-error :amount parse-amount))
|
(map (parse-or-error :amount parse-amount))
|
||||||
(map (parse-or-error :bank-account-id parse-account-id))
|
|
||||||
(map (parse-or-error :client-id parse-client-id))
|
|
||||||
(map (parse-or-error :date parse-date)))
|
(map (parse-or-error :date parse-date)))
|
||||||
error-rows (filter :errors rows)
|
error-rows (filter :errors rows)
|
||||||
_ (println "importing raw transactions" rows)
|
_ (println "importing raw transactions" rows)
|
||||||
|
|
||||||
raw-transactions (vec (->> rows
|
raw-transactions (vec (->> rows
|
||||||
(filter #(not (seq (:errors %))) )
|
(filter #(not (seq (:errors %))) )
|
||||||
(map (fn [{:keys [description-original client-id status high-level-category amount bank-account-id date]}]
|
(map (fn [{:keys [description-original client-code status high-level-category amount bank-account-code date]}]
|
||||||
{:description-original description-original
|
{:description-original description-original
|
||||||
:date date
|
:date date
|
||||||
:status status
|
:status status
|
||||||
:high-level-category high-level-category
|
:high-level-category high-level-category
|
||||||
:amount amount
|
:amount amount
|
||||||
:client-id client-id
|
:client-id (:db/id (all-clients client-code))
|
||||||
:bank-account-id bank-account-id}))))]
|
:bank-account-id (:db/id (all-bank-accounts bank-account-code))}))))]
|
||||||
|
|
||||||
(manual-import raw-transactions)
|
(manual-import raw-transactions)
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,20 @@
|
|||||||
|
|
||||||
(s/def ::name ::shared/required-identifier)
|
(s/def ::name ::shared/required-identifier)
|
||||||
(s/def ::code (s/and ::shared/required-identifier
|
(s/def ::code (s/and ::shared/required-identifier
|
||||||
#(re-matches #"[A-Z0-9]+" %)))
|
#(re-matches #"[A-Z0-9\-]+" %)))
|
||||||
(s/def ::address (s/nilable ::address/address))
|
(s/def ::address (s/nilable ::address/address))
|
||||||
|
|
||||||
|
(s/def ::bank-name ::shared/required-identifier)
|
||||||
|
(s/def ::bank-code ::shared/required-identifier)
|
||||||
|
(s/def ::routing ::shared/required-identifier)
|
||||||
|
(s/def ::number ::shared/required-identifier)
|
||||||
|
(s/def ::type keyword?)
|
||||||
|
(s/def ::number string?)
|
||||||
|
(s/def ::yodlee-account-id string?)
|
||||||
|
|
||||||
|
(s/def ::bank-account (s/keys :req-un [::code ::name ::bank-name ::bank-code ::routing ::number]))
|
||||||
|
(s/def ::bank-accounts (s/coll-of ::bank-account))
|
||||||
|
|
||||||
(s/def ::location string?)
|
(s/def ::location string?)
|
||||||
(s/def ::locations (s/coll-of ::location))
|
(s/def ::locations (s/coll-of ::location))
|
||||||
|
|
||||||
@@ -23,6 +34,7 @@
|
|||||||
:opt-un [::email
|
:opt-un [::email
|
||||||
::address
|
::address
|
||||||
::locations
|
::locations
|
||||||
|
::bank-accounts
|
||||||
::id]))
|
::id]))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
:graphql {:token token
|
:graphql {:token token
|
||||||
:query-obj {:venia/queries [[:client
|
:query-obj {:venia/queries [[:client
|
||||||
|
|
||||||
[:id :name :code :email :locations [:bank-accounts [:id :number :check-number :name :type] ]
|
[:id :name :code :email :locations [:bank-accounts [:id :code :number :check-number :name :type] ]
|
||||||
[:address [:street1 :street2 :city :state :zip]]]]
|
[:address [:street1 :street2 :city :state :zip]]]]
|
||||||
[:vendor
|
[:vendor
|
||||||
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
|
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
(fn [{:keys [db]} [_ token user]]
|
(fn [{:keys [db]} [_ token user]]
|
||||||
{:graphql {:token token
|
{:graphql {:token token
|
||||||
:query-obj {:venia/queries [[:client
|
:query-obj {:venia/queries [[:client
|
||||||
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :type]]]]
|
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :check-number :name :type]]]]
|
||||||
[:vendor
|
[:vendor
|
||||||
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
|
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
[clojure.string :as str])
|
[clojure.string :as str])
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as re-frame]
|
||||||
[reagent.core :as reagent]
|
[reagent.core :as reagent]
|
||||||
|
[clojure.spec.alpha :as s]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[auto-ap.subs :as subs]
|
[auto-ap.subs :as subs]
|
||||||
[auto-ap.events :as events]
|
[auto-ap.events :as events]
|
||||||
@@ -40,7 +41,7 @@
|
|||||||
(update :bank-accounts #(into % (map (fn [ba] (dissoc ba :is-new?)) (:new-bank-accounts edited-client))))
|
(update :bank-accounts #(into % (map (fn [ba] (dissoc ba :is-new?)) (:new-bank-accounts edited-client))))
|
||||||
(dissoc :new-bank-accounts))
|
(dissoc :new-bank-accounts))
|
||||||
}
|
}
|
||||||
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name]]]
|
[:id :name :code :email [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing]]]
|
||||||
]}]}
|
]}]}
|
||||||
:on-success [::save-complete]
|
:on-success [::save-complete]
|
||||||
:on-error [::save-error]}})))
|
:on-error [::save-error]}})))
|
||||||
@@ -81,8 +82,10 @@
|
|||||||
::add-new-bank-account
|
::add-new-bank-account
|
||||||
(fn [{:keys [db]} _]
|
(fn [{:keys [db]} _]
|
||||||
(let [client (:client @(re-frame/subscribe [::subs/admin]))
|
(let [client (:client @(re-frame/subscribe [::subs/admin]))
|
||||||
|
_ (println (s/explain-data ::entity/bank-account (:new-account client)))
|
||||||
new-bank-account (:new-account client)
|
new-bank-account (:new-account client)
|
||||||
new-bank-account (-> new-bank-account
|
new-bank-account (-> new-bank-account
|
||||||
|
(update :code #(str (:code client) "-" %))
|
||||||
(update :check-number #(if (seq %) (js/parseInt %) nil))
|
(update :check-number #(if (seq %) (js/parseInt %) nil))
|
||||||
(update :yodlee-account-id #(if (seq %) (js/parseInt %) nil))
|
(update :yodlee-account-id #(if (seq %) (js/parseInt %) nil))
|
||||||
(assoc :is-new? true))]
|
(assoc :is-new? true))]
|
||||||
@@ -180,6 +183,18 @@
|
|||||||
:event ::change
|
:event ::change
|
||||||
:subscription editing-client}]
|
:subscription editing-client}]
|
||||||
[:h2.subtitle "Add account"]
|
[:h2.subtitle "Add account"]
|
||||||
|
[horizontal-field
|
||||||
|
[:label.label "Acct code"]
|
||||||
|
[:div.control
|
||||||
|
[:div.field.has-addons.is-extended
|
||||||
|
[:p.control [:a.button.is-static (:code editing-client) "-" ]]
|
||||||
|
[:p.control
|
||||||
|
[bind-field
|
||||||
|
[:input.input {:type "code"
|
||||||
|
:field [:new-account :code]
|
||||||
|
:spec ::entity/code
|
||||||
|
:event ::change
|
||||||
|
:subscription editing-client}]]]]]]
|
||||||
|
|
||||||
[horizontal-field
|
[horizontal-field
|
||||||
[:label.label "Bank"]
|
[:label.label "Bank"]
|
||||||
@@ -240,7 +255,12 @@
|
|||||||
:event ::change
|
:event ::change
|
||||||
:subscription editing-client}]]]
|
:subscription editing-client}]]]
|
||||||
[:div.control
|
[:div.control
|
||||||
[:button.button.is-primary.is-pulled-right {:on-click (dispatch-event [::add-new-bank-account])} "Add"]]]
|
[:button.button.is-primary.is-pulled-right {:on-click (dispatch-event [::add-new-bank-account])
|
||||||
|
:disabled (if (and (s/valid? ::entity/bank-account (:new-account editing-client))
|
||||||
|
(not ((set (map :code (:bank-accounts editing-client)))
|
||||||
|
(str (:code editing-client) "-" (-> editing-client :new-account :code)))))
|
||||||
|
""
|
||||||
|
"disabled")} "Add"]]]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -250,10 +270,10 @@
|
|||||||
[:div.control
|
[:div.control
|
||||||
[:ul
|
[:ul
|
||||||
|
|
||||||
(for [{:keys [name number check-number id]} (:bank-accounts editing-client)]
|
(for [{:keys [code name number check-number id]} (:bank-accounts editing-client)]
|
||||||
^{:key id} [:li name])
|
^{:key id} [:li code ": " name])
|
||||||
(for [[index {:keys [name number check-number]}] (map vector (range) (:new-bank-accounts editing-client))]
|
(for [[index {:keys [name code number check-number]}] (map vector (range) (:new-bank-accounts editing-client))]
|
||||||
^{:key index} [:li [:strong "* " name] [:button.button {:on-click (dispatch-event [::remove-new-bank-account index])} [:span.icon [:i.fa.fa-times]]]])]]]
|
^{:key index} [:li [:strong "* " code ": " name] [:button.button {:on-click (dispatch-event [::remove-new-bank-account index])} [:span.icon [:i.fa.fa-times]]]])]]]
|
||||||
|
|
||||||
(when (:saving? editing-client) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])])))
|
(when (:saving? editing-client) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])])))
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user