Should fix bad client

This commit is contained in:
2023-03-19 23:19:07 -07:00
parent 8104506988
commit 9c65751b21
20 changed files with 0 additions and 2072 deletions

View File

@@ -8,14 +8,6 @@
:dependencies [[com.google.guava/guava "31.1-jre"]
[org.clojure/clojure "1.10.1"]
[com.datomic/datomic-pro "0.9.5783"
:exclusions [com.google.guava/guava
org.apache.httpcomponents/httpclient
org.slf4j/jul-to-slf4j
org.slf4j/log4j-over-slf4j
org.slf4j/slf4j-nop
org.slf4j/slf4j-log4j12]]
[com.unbounce/clojure-dogstatsd-client "0.7.0"]
[com.cognitect/hmac-authn "0.1.210"]
[com.datomic/client-cloud "1.0.123"]

View File

@@ -1,609 +0,0 @@
(ns auto-ap.datomic.migrate
(:gen-class)
(:require
[auto-ap.datomic :refer [conn]]
[auto-ap.datomic.migrate.add-bank-account-codes]
[auto-ap.datomic.migrate.add-client-codes]
[auto-ap.datomic.migrate.add-general-ledger :as add-general-ledger]
[auto-ap.datomic.migrate.integrations :as integrations]
[auto-ap.datomic.migrate.audit :as audit]
[auto-ap.datomic.migrate.clients :as clients]
[auto-ap.datomic.migrate.reports :as reports]
[auto-ap.datomic.migrate.invoice-converter]
[auto-ap.datomic.migrate.ledger :as ledger]
[auto-ap.datomic.migrate.queries :as queries]
[auto-ap.datomic.migrate.plaid :as plaid]
[auto-ap.datomic.migrate.sales :as sales]
[auto-ap.datomic.migrate.vendors :as vendors]
[auto-ap.datomic.migrate.yodlee2 :as yodlee2]
[clojure.java.io :as io]
[datomic.api :as d]
[io.rkn.conformity :as c]
[mount.core :as mount])
(:import
(datomic Util)))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn read-dtm
"Reads a dtm file (i.e., an edn file with datomic tags in it) from the classpath
and returns a vector of all forms contained within."
[filename]
(-> (io/resource filename) (io/reader) (Util/readAll)))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn functions [_]
[[{:db/ident :pay
:db/doc "Data function that increments value of attribute a by amount."
:db/fn (d/function '{:lang "clojure"
:params [db e amount]
:code (let [current-outstanding-balance (-> (d/entity db e) :invoice/outstanding-balance)
new-outstanding-balance (- current-outstanding-balance amount)]
[[:db/add e :invoice/outstanding-balance new-outstanding-balance]
[:db/add e :invoice/status (if (> new-outstanding-balance 0)
:invoice-status/unpaid
:invoice-status/paid)]])})}
{:db/ident :inc
:db/doc "Data function that increments value of attribute a by amount."
:db/fn (d/function '{:lang "clojure"
:params [db e a amount]
:code [[:db/add e a
(-> (d/entity db e) a (+ amount))]] })}]] )
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn fix-pay-function [_]
[[{:db/ident :pay
:db/doc "Data function that increments value of attribute a by amount."
:db/fn (d/function '{:lang "clojure"
:params [db e amount]
:code (let [invoice (-> (d/entity db e))
current-outstanding-balance (-> invoice :invoice/outstanding-balance)
new-outstanding-balance (- current-outstanding-balance amount)]
(when (= (:invoice/status invoice)
:invoice-status/paid)
(throw (ex-info "This invoice has already been paid" {:validation-message "This invoice has already been paid."
:status (:invoice/status invoice)
:id (:db/id invoice)})))
[[:db/add e :invoice/outstanding-balance new-outstanding-balance]
[:db/add e :invoice/status (if (< -0.001 new-outstanding-balance 0.001)
:invoice-status/paid
:invoice-status/unpaid)]])})}]] )
(def add-client-identifier
[[{:db/ident :invoice/client-identifier
:db/doc "An identifier found in an uploaded invoice"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]])
(defn reset-function [_]
[[{:db/ident :reset
:db/doc "Resets a relationship to the values specified "
:db/fn (d/function '{:lang "clojure"
:params [db e a vs]
:code (let [ids (when-not (string? e)
(->> (d/query {:query {:find ['?z]
:in ['$ '?e '?a]
:where [['?e '?a '?z]]}
:args [db e a]})
(map first)))
new-id-set (set (map :db/id vs))
retract-ids (filter (complement new-id-set) ids)]
(cond-> []
true (into (map (fn [i] [:db/retract e a i ]) retract-ids))
(seq vs) (conj {:db/id e
a vs})))})}]])
(defn propose-invoice-fn [_]
[[{:db/ident :propose-invoice
:db/doc "Adds an invoice if it's not found"
:db/fn (d/function '{:lang "clojure"
:params [db invoice]
:code (let [existing? (boolean (seq (d/query {:query {:find ['?i]
:in ['$ '?invoice-number '?client '?vendor]
:where ['[?i :invoice/invoice-number ?invoice-number]
'[?i :invoice/client ?client]
'[?i :invoice/vendor ?vendor]
'(not [?i :invoice/status :invoice-status/voided])
]}
:args [db (:invoice/invoice-number invoice) (:invoice/client invoice) (:invoice/vendor invoice)]})))]
(if existing?
[]
[invoice]))})}]])
(defn add-include-in-reports [conn]
(let [existing-accounts (->> (d/query {:query {:find ['?e]
:in ['$]
:where ['[?e :bank-account/name]]}
:args [(d/db conn)]})
(transduce
(comp
(map first)
(map (fn [bank-account]
{:db/id bank-account :bank-account/include-in-reports true})))
conj
[]))]
[existing-accounts]))
(defn apply-idents-to-well-known [conn]
(let [[ccp-square] (d/q '[:find [?v]
:where [?v :vendor/name "CCP Square"]]
(d/db conn))
[receipts-split] (d/q '[:find [?a]
:where [?a :account/numeric-code 12990]]
(d/db conn))
[ccp] (d/q '[:find [?a]
:where [?a :account/numeric-code 12100]]
(d/db conn))
[accounts-payable] (d/q '[:find [?a]
:where [?a :account/numeric-code 21000]]
(d/db conn))]
[[{:db/id ccp :db/ident :account/ccp}]
[{:db/id ccp-square
:db/ident :vendor/ccp-square
:vendor/name "CCP Square"
:vendor/default-account :account/ccp}
{:db/id receipts-split
:db/ident :account/receipts-split}
{:db/id accounts-payable
:db/ident :account/accounts-payable}]]))
(defn add-account-search-terms [conn]
[(->> (d/q '[:find ?i ?n
:in $
:where [?i :account/name ?n]]
(d/db conn))
(map (fn [[i n]]
{:db/id i
:account/search-terms n})))
(->> (d/q '[:find ?i ?n
:in $
:where [?i :account-client-override/name ?n]]
(d/db conn))
(map (fn [[i n]]
{:db/id i
:account-client-override/search-terms n})))])
(defn backfill-account-options [conn]
[(->> (d/q '[:find [?a ...]
:in $
:where [?a :account/name]]
(d/db conn))
(map (fn [i]
{:db/id i
:account/invoice-allowance :allowance/allowed})))
])
(defn backfill-account-options2 [conn]
[(->> (d/q '[:find [?a ...]
:in $
:where [?a :account/name]]
(d/db conn))
(map (fn [i]
{:db/id i
:account/vendor-allowance :allowance/allowed
:account/default-allowance :allowance/allowed})))
])
(defn migrate [conn]
(let [norms-map (merge {:auto-ap/base-schema {:txes auto-ap.datomic/base-schema}
:auto-ap/functions {:txes-fn 'auto-ap.datomic.migrate/functions
:requires [:auto-ap/base-schema]}
:auto-ap/fx-pay-function-10 {:txes-fn 'auto-ap.datomic.migrate/fix-pay-function
:requires [:auto-ap/functions]}
:auto-ap/migrate-vendors {:txes-fn 'auto-ap.datomic/migrate-vendors
:requires [:auto-ap/base-schema]}
:auto-ap/migrate-clients {:txes-fn 'auto-ap.datomic/migrate-clients
:requires [:auto-ap/migrate-vendors]}
:auto-ap/migrate-users {:txes-fn 'auto-ap.datomic/migrate-users
:requires [:auto-ap/migrate-clients]}
:auto-ap/migrate-invoices {:txes-fn 'auto-ap.datomic/migrate-invoices
:requires [:auto-ap/migrate-vendors :auto-ap/migrate-clients]}
:auto-ap/migrate-payments {:txes-fn 'auto-ap.datomic/migrate-payments
:requires [:auto-ap/migrate-invoices]}
:auto-ap/migrate-invoices-payments {:txes-fn 'auto-ap.datomic/migrate-invoices-payments
:requires [:auto-ap/migrate-payments :auto-ap/migrate-invoices]}
: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/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]}
:auto-ap/add-nick-the-greek {:txes [[{:client/name "Nick the Greek" :client/code "NGAK" :client/locations ["MH"] :client/bank-accounts [{:bank-account/code "NGAK-0" :bank-account/type :bank-account-type/cash :bank-account/name "Cash"}]}]]
:requires [:auto-ap/add-bank-account-codes]}
:auto-ap/rename-codes-1 {:txes-fn 'auto-ap.datomic.migrate.rename-codes/rename-codes-1
:requires [:auto-ap/add-nick-the-greek]}
:auto-ap/invoice-converter {:txes auto-ap.datomic.migrate.invoice-converter/add-matches
:requires [:auto-ap/rename-codes-1]}
:auto-ap/starter {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-starter
:requires [:auto-ap/invoice-converter]}
:auto-ap/add-default-location {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-default-location
:requires [:auto-ap/invoice-converter]}
:auto-ap/add-default-location-2 {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-default-location-2
:requires [:auto-ap/add-default-location]}
:auto-ap/add-import-status {:txes auto-ap.datomic.migrate.invoice-converter/add-import-status
:requires [:auto-ap/add-default-location-2]}
:auto-ap/add-import-status-existing-invoices {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-import-status-existing-invoices
:requires [:auto-ap/add-import-status]}
:auto-ap/fix-check-numbers {:txes-fn 'auto-ap.datomic.migrate.check-numbers/fix-check-numbers
:requires [:auto-ap/add-import-status-existing-invoices]}
:auto-ap/add-account-visibility-fields {:txes-fn 'auto-ap.datomic.migrate.account-sorting/add-account-visibility-fields
:requires [:auto-ap/fix-check-numbers]}
:auto-ap/make-every-account-visible {:txes-fn 'auto-ap.datomic.migrate.account-sorting/make-every-account-visible
:requires [:auto-ap/add-account-visibility-fields]}
:auto-ap/add-general-ledger6 {:txes add-general-ledger/add-general-ledger
:requires [:auto-ap/make-every-account-visible]}
:auto-ap/add-general-ledger-fns2 {:txes-fn 'auto-ap.datomic.migrate.add-general-ledger/add-general-ledger-fns
:requires [:auto-ap/add-general-ledger6]}
:auto-ap/add-accounts {:txes auto-ap.datomic.migrate.add-general-ledger/add-accounts
:requires [:auto-ap/add-general-ledger-fns2]}
:auto-ap/add-transaction-account {:txes auto-ap.datomic.migrate.add-general-ledger/add-transaction-account
:requires [:auto-ap/add-accounts]}
:auto-ap/change-expense-account-to-entity {:txes auto-ap.datomic.migrate.add-general-ledger/change-expense-account-to-entity
:requires [:auto-ap/add-transaction-account]}
:auto-ap/add-account-to-vendor {:txes auto-ap.datomic.migrate.add-general-ledger/add-account-to-vendor
:requires [:auto-ap/change-expense-account-to-entity]}
:auto-ap/add-location-to-transaction {:txes add-general-ledger/add-location-to-transaction
:requires [:auto-ap/add-account-to-vendor]}
:auto-ap/add-credit-bank-account {:txes add-general-ledger/add-credit-bank-account
:requires [:auto-ap/add-location-to-transaction]}
:auto-ap/add-hidden-to-vendor {:txes-fn `add-general-ledger/add-hidden-to-vendor :requires [:auto-ap/add-credit-bank-account]}
#_#_:auto-ap/convert-vendors {:txes-fn `add-general-ledger/convert-vendors
:requires [:auto-ap/add-hidden-to-vendor]}
#_#_:auto-ap/convert-invoices {:txes-fn `add-general-ledger/convert-invoices
:requires [:auto-ap/convert-vendors]}
:auto-ap/add-yodlee-merchant2 {:txes add-general-ledger/add-yodlee-merchant }
:auto-ap/add-external-id-to-ledger {:txes add-general-ledger/add-external-id-to-ledger :requires [:auto-ap/add-yodlee-merchant2]}
:auto-ap/add-exclude-to-transaction {:txes add-general-ledger/add-exclude-to-transaction :requires [:auto-ap/add-external-id-to-ledger]}
:auto-ap/add-client-identifier2 {:txes add-client-identifier :requires [:auto-ap/make-every-account-visible]}
:auto-ap/add-transaction-rules {:txes add-general-ledger/add-transaction-rules :requires [:auto-ap/add-exclude-to-transaction]}
:auto-ap/add-bank-account-locations {:txes add-general-ledger/add-bank-account-locations :requires [:auto-ap/add-transaction-rules]}
;; should not be needed.
#_#_:auto-ap/convert-transactions {:txes-fn `add-general-ledger/convert-transactions :requires [:auto-ap/add-bank-account-locations]}
:auto-ap/add-exclude-to-invoice {:txes add-general-ledger/add-exclude-to-invoice }
:auto-ap/add-terms {:txes [[{:db/ident :vendor/terms
:db/doc "How many days till you pay"
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}]]}
:auto-ap/add-due {:txes [[{:db/ident :invoice/due
:db/doc "When you gotta pay"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}]]}
:auto-ap/add-vendor-overrides {:txes [[{:db/ident :vendor-account-override/account
:db/doc "the account for invoices"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :vendor-account-override/client
:db/doc "How many days till you pay"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :vendor-terms-override/terms
:db/doc "How many days till you pay"
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}
{:db/ident :vendor-terms-override/client
:db/doc "How many days till you pay"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :vendor/terms-overrides
:db/doc "Overrides per-client"
:db/isComponent true
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}
{:db/ident :vendor/account-overrides
:db/isComponent true
:db/doc "Overrides per-client"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}]]}
:auto-ap/add-reset-rels {:txes-fn `reset-function}
:auto-ap/add-account-overrides {:txes [[{:db/ident :account/applicability
:db/doc ":global, :optional :customized"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :account-applicability/global
:db/doc "The account applies to all cutsomers"}
{:db/ident :account-applicability/optional
:db/doc "This account is optional"}
{:db/ident :account-applicability/customized
:db/doc "This account is customized per-customer"}
{:db/ident :account/client-overrides
:db/doc "Customizations per customer"
:db/valueType :db.type/ref
:db/isComponent true
:db/cardinality :db.cardinality/many}
{:db/ident :account-client-override/client
:db/doc "The client for the override"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :account-client-override/enabled
:db/doc "Does this apply?"
:db/valueType :db.type/boolean
:db/cardinality :db.cardinality/one}
{:db/ident :account-client-override/name
:db/doc "client override"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]]
:requires [:auto-ap/base-schema]}
: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}]]}
:auto-ap/add-cash-flow-schema {:txes [[{:db/ident :client/weekly-debits
:db/doc "How much money gets debited each week"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :client/weekly-credits
:db/doc "How much money gets credited each week"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :client/forecasted-transactions
:db/doc "Regular, planned transactions"
:db/valueType :db.type/ref
:db/isComponent true
:db/cardinality :db.cardinality/many}
{:db/ident :forecasted-transaction/amount
:db/doc "Amount of a forcested transaction"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :forecasted-transaction/day-of-month
:db/doc "Which day the transaction occurs"
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}
{:db/ident :forecasted-transaction/identifier
:db/doc "An identifier for this forcasted transaction, e.g., 'RENT'"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]]}
:auto-ap/add-manager-schema {:txes [[{:db/ident :user-role/manager}]]}
:auto-ap/add-include-in-reports1 {:txes [[{:db/ident :bank-account/include-in-reports
:db/doc "Whether to include this bank account in balance sheet, etc."
:db/valueType :db.type/boolean
:db/cardinality :db.cardinality/one}]]
:requires [:auto-ap/add-manager-schema]}
:auto-ap/migrate-include-in-reports {:txes-fn `add-include-in-reports :requires [:auto-ap/add-include-in-reports1] }
:auto-ap/add-forecasted-transaction-match {:txes [[{:db/ident :transaction/forecast-match
:db/doc "Which forecast this transaction matches, for cashflow"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}]]}
:auto-ap/add-week-a-and-b {:txes [[{:db/ident :client/week-a-debits
:db/doc "How much money gets debited each week"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :client/week-a-credits
:db/doc "How much money gets credited each week"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :client/week-b-debits
:db/doc "How much money gets debited each week"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :client/week-b-credits
:db/doc "How much money gets credited each week"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}]]}
:auto-ap/auto-pay {:txes [[{:db/ident :vendor/automatically-paid-when-due
:db/doc "The clients for which invoices will automatically be paid."
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}
{:db/ident :invoice/automatically-paid-when-due
:db/doc "Whether this invoice should be marked as paid when it's due"
:db/valueType :db.type/boolean
:db/cardinality :db.cardinality/one}]]}
:auto-ap/fix-reset-rels {:txes-fn `reset-function}
:auto-ap/add-scheduled-payment {:txes [[{:db/ident :invoice/scheduled-payment
:db/doc "When an invoice gets marked as paid"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}]]}
:auto-ap/add-scheduled-payment-dom {:txes [[{:db/ident :vendor/schedule-payment-dom
:db/doc "When an invoice gets marked as paid"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db/isComponent true}
{:db/ident :vendor-schedule-payment-dom/client
:db/doc "Which client the override is for"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :vendor-schedule-payment-dom/dom
:db/doc "What day of the month"
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}]]}
:auto-ap/add-power-user-schema {:txes [[{:db/ident :user-role/power-user}]]}
:auto-ap/add-transaction-date-index {:txes [[{:db/ident :transaction/date
:db/index true}]]
:requires [:auto-ap/add-general-ledger6]}
:auto-ap/add-invoice-index {:txes [[{:db/ident :invoice/invoice-number
:db/index true}]]
:requires [:auto-ap/base-schema]}
:auto-ap/add-propose-invoice {:txes-fn `propose-invoice-fn
:requires [:auto-ap/base-schema]}
:auto-ap/add-intuit-banks-4 {:txes [[{:db/ident :intuit-bank-account/external-id
:db/doc "Id of the intui bank"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
{:db/ident :intuit-bank-account/name
:db/doc "Name of intuit bank"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
{:db/ident :bank-account/intuit-bank-account
:db/doc "intuit external bank account"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :transaction/raw-id
:db/doc "An unhashed version of the id"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]]
:requires [:auto-ap/add-general-ledger6]}
:auto-ap/add-transaction-import2 {:txes [[{:db/ident :import-batch/external-id
:db/doc "An identifier for the import batch"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
{:db/ident :import-batch/entry
:db/doc "Links to everything that was imported"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}
{:db/ident :import-batch/imported
:db/doc "How many entries were imported"
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}
{:db/ident :import-batch/extant
:db/doc "How many entries were already present"
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}
{:db/ident :import-batch/suppressed
:db/doc "How many entries were explicitly ignored"
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}
{:db/ident :import-batch/date
:db/doc "The date the import occurred"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}
{:db/ident :import-batch/source
:db/doc "What system triggered the import"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :import-batch/status
:db/doc "What system triggered the import"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :import-source/intuit}
{:db/ident :import-source/manual}
{:db/ident :import-source/yodlee}
{:db/ident :import-source/yodlee2}
{:db/ident :import-status/started}
{:db/ident :import-status/completed}
{:db/ident :import-batch/user-name
:db/doc "Who triggred this import"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]]
:requires [:auto-ap/add-general-ledger6]}
:auto-ap/add-suppression {:txes [[{:db/ident :transaction-approval-status/suppressed}
{:db/ident :transaction/approval-status
:db/index true}]]
:requires [:auto-ap/add-transaction-rules]}
:auto-ap/add-other-statuses {:txes [[{:db/ident :import-batch/error
:db/doc "How many entries were an error "
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}
{:db/ident :import-batch/not-ready
:db/doc "How many entries were before a start date "
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}
{:db/ident :import-batch/error-message
:db/doc "error message for a failed job"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]]
:requires [:auto-ap/add-transaction-import2]}
:auto-ap/apply-idents-to-well-known {:txes-fn `apply-idents-to-well-known
:requires [:auto-ap/add-general-ledger6
:auto-ap/add-account-to-vendor]}
:auto-ap/add-invoice-link {:txes [[{:db/ident :invoice/source-url
:db/doc "An s3 location for the invoice"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :invoice/location
:db/doc "The location to code the invoice as"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]]}
:auto-ap/add-invoice-similarity {:txes [[{:db/ident :invoice/similarity
:db/doc "How close an invoice matches its import"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}]]}
:auto-ap/add-source-url-admin-only {:txes [[{:db/ident :invoice/source-url-admin-only
:db/doc "Can only admins see this invoice?"
:db/valueType :db.type/boolean
:db/cardinality :db.cardinality/one}]]}
:auto-ap/add-payment-type-credit {:txes [[{:db/ident :payment-type/credit
:db/doc "Credit for negative invoices"}]]}
:auto-ap/add-payment-type-balance-credit {:txes [[{:db/ident :payment-type/balance-credit
:db/doc "Used for paying invoices from statement credits."}]]}
:auto-ap/fulltext-accounts {:txes [[{:db/ident :account/search-terms
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "a name search for accounts"
:db/fulltext true}
{:db/ident :account-client-override/search-terms
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "a name search for accounts"
:db/fulltext true}]]
:requires [:auto-ap/add-account-overrides :auto-ap/base-schema]}
:auto-ap/add-search-terms-accounts {:txes-fn `add-account-search-terms
:first-time-only true
:requires [:auto-ap/fulltext-accounts :auto-ap/base-schema :auto-ap/add-accounts]}
:auto-ap/add-account-options {:txes [[{:db/ident :account/invoice-allowance
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "Whether this account can be used for invoices"}
{:db/ident :allowance/allowed
:db/doc "Allowed to be used"}
{:db/ident :allowance/denied
:db/doc "Denied usage"}
{:db/ident :allowance/warn
:db/doc "Warn on usage"}
{:db/ident :allowance/admin-only
:db/doc "Only admins can use it"}]]
:requires [:auto-ap/add-search-terms-accounts :auto-ap/add-accounts]}
:auto-ap/backfill-account-options {:txes-fn `backfill-account-options
:first-time-only true
:requires [:auto-ap/add-account-options :auto-ap/add-accounts]}
:auto-ap/add-vendor-account-options2 {:txes [[{:db/ident :account/vendor-allowance
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "Whether this account can be used for vendors"}
{:db/ident :account/default-allowance
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "Whether this account can be used generally"}
]]
:requires [:auto-ap/backfill-account-options :auto-ap/add-accounts]}
:auto-ap/backfill-account-options3 {:txes-fn `backfill-account-options2
:first-time-only true
:requires [:auto-ap/add-vendor-account-options2 :auto-ap/add-accounts]}}
sales/norms-map
clients/norms-map
ledger/norms-map
yodlee2/norms-map
integrations/norms-map
reports/norms-map
plaid/norms-map
audit/norms-map
vendors/norms-map
queries/norms-map)]
(println "Conforming database...")
(c/ensure-conforms conn norms-map)
#_(when (not (seq args))
(d/release conn))
(println "Done")))
(defn -main [& _]
(mount/start (mount/only #{#'conn}))
(migrate conn)
(mount/stop))

View File

@@ -1,29 +0,0 @@
(ns auto-ap.datomic.migrate.account-sorting
(:require [datomic.api :as d]))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn add-account-visibility-fields [_]
[[
{:db/ident :bank-account/visible
:db/valueType :db.type/boolean
:db/cardinality :db.cardinality/one
:db/doc "Whether this bank account is visible"}
{:db/ident :bank-account/sort-order
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one
:db/doc "The sort order of the bank account"}]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn make-every-account-visible [conn]
(let [all-account-ids (d/query
{:query {:find ['?e]
:in ['$]
:where ['[?e :bank-account/code]]}
:args [(d/db conn)]}
)]
[(map
(fn [[account-id]]
{:db/id account-id :bank-account/visible true}
)
all-account-ids)]))

View File

@@ -1,30 +0,0 @@
(ns auto-ap.datomic.migrate.add-bank-account-codes
(:require
[clojure.string :as str]
[datomic.api :as d]))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn add-bank-account-codes-schema [_]
[[{: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"}]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(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))

View File

@@ -1,46 +0,0 @@
(ns auto-ap.datomic.migrate.add-client-codes
(:require
[datomic.api :as d]))
(def name->code
(->>
[["Moscini Pizza Inc" "MPI"]
["Frost Cupcake Factory" "FCF"]
["Sorelle Italian Bistro" "SIB"]
["Brian & Erin Skarbek" "BES"]
["Shared CBC-IBC Expenses" "IBCBC"]
["Integreat" "INT"]
["Mama Mia's" "MAM"]
["Mio Saratoga" "MVSG"]
["Be Steak A" "BSA"]
["Jason Skarbek" "JS"]
["Lefty's East Coast Pizzeria" "LFT"]
["Orale's" "ORA"]
["Brown Chicken Brown Cow" "BCBC"]
["Hiro Mura" "HM"]
["Mama Lu's Foods" "MLF"]
["Bella Saratoga" "BSG"]
["Willow Glen Creamery" "WGC"]
["Skarbek Law Offices" "SLO"]
["Mio Vicino - Santa Clara" "MV"]
["Campbell Brewing Co" "CBC"]
["Warm Elements" "WE"]
["Savory Kitchen" "SK"]
["Demo account" "DEMO"]
["Roberto's Cantina Inc" "RCI"]
["Fratello" "FRA"]
["Whirlygig" "WHG"]
["Iguanas Burritozilla" "IBC"]]
(into {}))
)
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn add-client-codes [a]
[(->> (d/query {:query {:find '[?name ?e]
:in ['$]
:where ['[?e :client/name ?name]]}
:args [(d/db a)]})
(reduce (fn [result [name id]]
(if (name->code name)
(conj result [:db/add id :client/code (name->code name)])
result))
[]))])

View File

@@ -1,435 +0,0 @@
(ns auto-ap.datomic.migrate.add-general-ledger
(:require
[auto-ap.datomic :refer [remove-nils]]
[auto-ap.datomic.accounts :as accounts]
[auto-ap.expense-accounts :as expense-accounts]
[auto-ap.ledger :as ledger]
[datomic.api :as d]))
(def add-general-ledger
[[{:db/ident :journal-entry/source
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The type of entity that created this entry"}
{:db/ident :journal-entry/client
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The client for the ledger"}
{:db/ident :journal-entry/date
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one
:db/doc "The time for this entry"}
{:db/ident :journal-entry/original-entity
:db/valueType :db.type/ref
:db/unique :db.unique/identity
:db/cardinality :db.cardinality/one
:db/doc "The thing that created this entry"}
{:db/ident :journal-entry/vendor
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The vendor for the ledger entry"}
{:db/ident :journal-entry/amount
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one
:db/doc "The amount for the entry"}
{:db/ident :journal-entry/line-items
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db/isComponent true
:db/doc "Each of the line items in the general ledger"}
{:db/ident :journal-entry/cleared
:db/valueType :db.type/boolean
:db/cardinality :db.cardinality/one
:db/doc "Has this cleared?"}
{:db/ident :journal-entry/cleared-against
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "Cleared against"}
{:db/ident :journal-entry/note
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "notes about this journal-entry"}
{:db/ident :journal-entry-line/expense-account
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one
:db/doc "The expense account being changed"}
{:db/ident :journal-entry-line/account
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The other type of account being changed"}
{:db/ident :journal-entry-line/debit
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one
:db/doc "The amount to debit"}
{:db/ident :journal-entry-line/credit
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one
:db/doc "The amount to credit"}
{:db/ident :journal-entry-line/location
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "Location of the entry"}
]
]
)
(def add-transaction-account
[[{:db/ident :transaction/accounts
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db/isComponent true
:db/doc "The debit(s)/credit(s) for this transaction"}
{:db/ident :transaction-account/account
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "Which account to debit/credit for this transaction"}
{:db/ident :transaction-account/location
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "Location for this expense account"}
{:db/ident :transaction-account/amount
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one
:db/doc "How much to debit/credit - must be positive"}]])
(def add-yodlee-merchant
[[{:db/ident :yodlee-merchant/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The yodlee merchant name"}
{:db/ident :yodlee-merchant/yodlee-id
:db/valueType :db.type/string
:db/unique :db.unique/identity
:db/cardinality :db.cardinality/one
:db/doc "The yodlee merchant id"}
{:db/ident :transaction/yodlee-merchant
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The yodlee merchant"}]])
(def add-accounts
[[
{:db/ident :account/code
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The code for the expense account (e.g., A1123)"}
{:db/ident :account/numeric-code
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one
:db/doc "The numeric-only for the expense account (e.g., 5150)"}
{:db/ident :account/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The name of the code (e.g., \"Telephone - HQ\")"}
{:db/ident :account/location
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "A forced location for this code, e.g., HQ."}
{:db/ident :account/account-set
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The set of accounts this entry belongs to. Allows customization."}
{:db/ident :account/type
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The type of account, (e.g., :account-type/expense :account-type/liability)"}
{:db/ident :account-type/expense}
{:db/ident :account-type/liability}
{:db/ident :account-type/revenue}
{:db/ident :account-type/dividend}
{:db/ident :account-type/asset}
{:db/ident :account-type/equity}]
(->> expense-accounts/chooseable-expense-accounts
(filter (fn [[numeric]]
(not (#{0 2100 5800 9600 1300 8200 7400 8500 2400 8800 1400 2500 7200 1200 1600 1500 3300 9800 9200 2800 1100 5700 2600 9300 9500 8100 7500 7100 2700} numeric))))
(mapv
(fn [[numeric {:keys [name location]}]]
(remove-nils
{:account/type (cond (<= 1000 numeric 1999)
:account-type/asset
(<= 2000 numeric 2999)
:account-type/liability
(<= 3000 numeric 3999)
:account-type/equity
(<= 4000 numeric 4999)
:account-type/revenue
:else
:account-type/expense)
:account/numeric-code numeric
:account/code (str numeric)
:account/name name
:account/location location
:account/account-set "default"}))))])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn add-general-ledger-fns [_]
[[{:db/ident :replace-general-ledger
:db/doc "Deletes the general ledger entries for an entity"
:db/fn (d/function '{:lang "clojure"
:params [db origin]
:code (let [ids (->> (d/query {:query {:find ['?e]
:in ['$ '?origin]
:where [['?e :journal-entry/original-entity '?origin]]}
:args [db origin]})
(map first))]
(into []
(map (fn [i] [:db/retractEntity i ]) ids)))})}]] )
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn bulk-load-invoice-ledger [conn]
(let [invoice-ids (map first (d/query {:query {:find '[?e]
:in '[$]
:where ['[?e :invoice/total]]}
:args [(d/db conn)]}))
z (->> invoice-ids
(map #(ledger/entity-change->ledger (d/db conn) [:invoice %]))
(partition-all 100))]
z))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn bulk-load-transaction-ledger [conn]
(let [transaction-ids (map first (d/query {:query {:find '[?e]
:in '[$]
:where ['[?e :transaction/id]]}
:args [(d/db conn)]}))
z (->> transaction-ids
(map #(ledger/entity-change->ledger (d/db conn) [:transaction %]))
(filter identity)
(partition-all 100)
#_(mapv #(vector %)))]
z))
#_(test-run (bulk-load-transaction-ledger (d/connect auto-ap.datomic/uri)))
#_(test-run (bulk-load-invoice-ledger (d/connect auto-ap.datomic/uri)))
#_(test-run (reset-ledger (d/connect auto-ap.datomic/uri)))
#_(do (doseq [tran (convert-transactions (d/connect auto-ap.datomic/uri))]
@(d/transact (d/connect auto-ap.datomic/uri) tran))
(println "done."))
#_(do @(d/transact (d/connect auto-ap.datomic/uri)
(bulk-load-transaction-ledger (d/connect auto-ap.datomic/uri)))
(println "test"))
(def change-expense-account-to-entity
[[{:db/ident :invoice-expense-account/account
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The account entity that this expense is for"}]])
(def add-account-to-vendor
[[{:db/ident :vendor/default-account
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The account will be used when a bill is created."}]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn convert-vendors [conn]
(let [vendors (d/query {:query {:find '[?v ?expense-account-id]
:in '[$]
:where ['[?v :vendor/default-expense-account ?expense-account-id]]}
:args [(d/db conn)]})]
[(mapv
(fn [[v expense-account-id]]
(remove-nils {:db/id v
:vendor/default-account (accounts/get-account-by-numeric-code-and-sets expense-account-id ["default"])}))
vendors)]))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn convert-invoices [conn]
(let [invoice-expense-accounts (d/query {:query {:find '[?iea ?expense-account-id]
:in '[$]
:where ['[?iea :invoice-expense-account/expense-account-id ?expense-account-id]]}
:args [(d/db conn)]})]
[(mapv
(fn [[iea expense-account-id]]
(remove-nils {:db/id iea
:invoice-expense-account/account (accounts/get-account-by-numeric-code-and-sets expense-account-id ["default"])}))
invoice-expense-accounts)]))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn convert-transactions [_]
(println "here")
(let [matched-transactions (d/query {:query {:find '[?transaction ?v ?amount]
:in '[$]
:where ['[?transaction :transaction/payment ?payment]
'[?transaction :transaction/amount ?amount]
'[?payment :payment/invoices ?i]
'[?i :invoice/vendor ?v]]}
:args [(d/db (d/connect auto-ap.datomic/uri))]})]
[(mapv
(fn [[transaction-id vendor-id amount]]
(remove-nils {:db/id transaction-id
:transaction/vendor vendor-id
:transaction/location "A"
:transaction/approval-status :transaction-approval-status/excluded
:transaction/accounts [#:transaction-account {:account (:db/id (accounts/get-account-by-numeric-code-and-sets 2110 ["default"]))
:location "A"
:amount (Math/abs amount)}]
}))
matched-transactions)]))
(def add-location-to-transaction
[[{:db/ident :transaction/location
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "Location of the transaction's target"}]])
(def add-external-id-to-ledger
[[{:db/ident :journal-entry/external-id
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity
:db/doc "For externally imported id"}]])
(def add-exclude-to-transaction
[[{:db/ident :transaction/exclude-from-ledger
:db/valueType :db.type/boolean
:db/cardinality :db.cardinality/one
:db/doc "Whether to exclude from the ledger"}]])
(def add-exclude-to-invoice
[[{:db/ident :invoice/exclude-from-ledger
:db/valueType :db.type/boolean
:db/cardinality :db.cardinality/one
:db/doc "Whether to exclude from the ledger"}]])
(def add-transaction-rules
[[{:db/ident :transaction-rule/client
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The specific client this rule is for"}
{:db/ident :transaction-rule/bank-account
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The specific bank account this rule is for"}
{:db/ident :transaction-rule/yodlee-merchant
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "Apply this rule if the yodlee merchant matches"}
{:db/ident :transaction-rule/description
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "A description to match this rule against"}
{:db/ident :transaction-rule/note
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "A friendly description for this rule (internal)"}
{:db/ident :transaction-rule/amount-lte
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one
:db/doc "Amount has to be less than or equal to this"}
{:db/ident :transaction-rule/amount-gte
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one
:db/doc "Amount has to be greater than or equal to this"}
{:db/ident :transaction-rule/dom-lte
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one
:db/doc "Day of month has to be less than or equal to this"}
{:db/ident :transaction-rule/dom-gte
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one
:db/doc "Day of month has to be greater than or equal to this"}
{:db/ident :transaction-rule/vendor
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The vendor to assign"}
{:db/ident :transaction-rule-account/percentage
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one
:db/doc "How much should go to this account"}
{:db/ident :transaction-rule-account/location
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The location this split is for"}
{:db/ident :transaction-rule-account/account
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The account of this split"}
{:db/ident :transaction-rule/accounts
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db/isComponent true
:db/doc "The outcome split"}
{:db/ident :transaction/approval-status
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "Status of a transaction"}
{:db/ident :transaction/matched-rule
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The rule that this transaction matched"}
{:db/ident :transaction-rule/transaction-approval-status
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "Status of a transaction"}
{:db/ident :transaction-approval-status/approved}
{:db/ident :transaction-approval-status/unapproved}
{:db/ident :transaction-approval-status/requires-feedback}
{:db/ident :transaction-approval-status/excluded}
]])
(def add-bank-account-locations
[[{:db/ident :bank-account/locations
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db/doc "Which bank accounts this bank account is valid for"}]])
(def add-credit-bank-account
[[{:db/ident :bank-account-type/credit}]])
(defn add-hidden-to-vendor [conn]
[[{:db/ident :vendor/hidden
:db/valueType :db.type/boolean
:db/cardinality :db.cardinality/one
:db/doc "Whether or not to exclude the vendor"}]
(let [vendors (d/query {:query {:find '[?v]
:in '[$]
:where ['[?v :vendor/name]]}
:args [(d/db conn)]})]
(mapv
(fn [[v ]]
{:db/id v
:vendor/hidden false})
vendors))])

View File

@@ -1,3 +0,0 @@
(ns auto-ap.datomic.migrate.add-new-vendors)

View File

@@ -1,12 +0,0 @@
(ns auto-ap.datomic.migrate.audit)
(def norms-map {::add-audit-fields
{:txes [[{:db/ident :audit/user
:db/doc "Which user commited this transaction"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :audit/batch
:db/doc "Which batch was this part of"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]]}})

View File

@@ -1,9 +0,0 @@
(ns auto-ap.datomic.migrate.check-numbers
(:require [datomic.api :as d]))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn fix-check-numbers [conn]
(let [max-check-numbers (d/query {:query {:find '[?e ?check-number (max ?d)] :in ['$] :where ['[?e :bank-account/check-number ?check-number] '[?c :payment/bank-account ?e] '[?c :payment/check-number ?d]]} :args [(d/db conn)]})]
[(for [[bank-account check-number max-check _] max-check-numbers
:when (>= max-check check-number)]
{:db/id bank-account :payment/check-number (inc max-check)})]))

View File

@@ -1,80 +0,0 @@
(ns auto-ap.datomic.migrate.clients
(:require [datomic.api :as d]))
(defn migrate-bank-account-numeric-codes [conn]
(let [existing-accounts (->> (d/query {:query {:find ['?c '?t2 '?e]
:in ['$]
:where ['[?c :client/bank-accounts ?e]
'[?e :bank-account/type ?t]
'[?t :db/ident ?t2]
'(not [?e :bank-account/numeric-code])]}
:args [(d/db conn)]})
(group-by (fn [[client type]]
[client type]))
(map second)
(mapcat (fn [account-set]
(map (fn [[_ type bank-account] idx]
[bank-account (+ (condp = type
:bank-account-type/check 11300
:bank-account-type/cash 11100
:bank-account-type/credit 20100)
1
idx)])
account-set (range))
))
(mapv (fn [[bank-account numeric-code]]
{:db/id bank-account
:bank-account/numeric-code numeric-code}))
)]
[existing-accounts])
)
(def norms-map {::add-bank-account-start-date
{:txes [[{:db/ident :bank-account/start-date
:db/doc "Setting this date prevents older transactions from being imported"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}]]}
::add-bank-account-current-balance
{:txes [[{:db/ident :bank-account/current-balance
:db/doc "A precomputed balance for the account"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one
:db/noHistory true}]]}
::add-bank-account-numeric-codes
{:txes [[{:db/ident :bank-account/numeric-code
:db/doc "The numeric code for the balance sheet"
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}]]}
::migrate-bank-account-numeric-codes
{:txes-fn `migrate-bank-account-numeric-codes
:requires [::add-bank-account-current-balance
::add-bank-account-numeric-codes]}
::add-locked-until
{:txes [[{:db/ident :client/locked-until
:db/doc "No new data before this date can be added/changed"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}]]}
::add-email-contacts
{:txes [[{:db/ident :email-contact/email
:db/doc "Email contact's email"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :email-contact/description
:db/doc "Manager, Owner, etc"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :client/emails
:db/doc "collection of email contacts"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}]]}
::add-use-date
{:txes [[{:db/ident :bank-account/use-date-instead-of-post-date?
:db/doc "Yodlee amex works weird"
:db/valueType :db.type/boolean
:db/cardinality :db.cardinality/one}]]}
})

View File

@@ -1,102 +0,0 @@
(ns auto-ap.datomic.migrate.integrations)
(def norms-map {::add-integration-status3
{:txes [[{:db/ident :bank-account/integration-status
:db/doc "A status for integration for the bank account"
:db/valueType :db.type/ref
:db/isComponent true
:db/cardinality :db.cardinality/one}
{:db/ident :client/square-integration-status
:db/doc "Square's integration status"
:db/valueType :db.type/ref
:db/isComponent true
:db/cardinality :db.cardinality/one}
{:db/ident :integration-status/last-updated
:db/doc "When was this integration updated"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one
:db/noHistory true}
{:db/ident :integration-status/last-attempt
:db/doc "When was this integration attempted."
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one
:db/noHistory true}
{:db/ident :integration-status/state
:db/doc "A status for the integration"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :integration-status/message
:db/doc "A message from the last attempt"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :integration-state/failed}
{:db/ident :integration-state/success}
{:db/ident :integration-state/unauthorized}]]}
::add-ezcater-base7
{:txes [[{:db/ident :ezcater-integration/subscriber-uuid
:db/doc "The subscriber uuid"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
{:db/ident :ezcater-integration/api-key
:db/doc "The API key that can be used for requests"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
{:db/ident :ezcater-integration/subscriber-secret
:db/doc "Used to validate events"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :ezcater-integration/integration-status
:db/doc "The status for this integration"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/isComponent true}
{:db/ident :ezcater-integration/caterers
:db/doc "All caterers for this integration"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db/isComponent true}
{:db/ident :ezcater-caterer/uuid
:db/doc "Id of the caterer"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
{:db/ident :ezcater-caterer/name
:db/doc "Name of the caterer"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :ezcater-caterer/search-terms
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "a name search for caterer"
:db/fulltext true}
{:db/ident :client/ezcater-locations
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db/isComponent true}
{:db/ident :ezcater-location/location
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :ezcater-location/caterer
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}]
[{:ezcater-integration/api-key "bmlrdHNpZ2FyaXNAZ21haWwuY29tOmQwMzQwMjYzOWI2ODQxNmVkMjdmZWYxMWFhZTk3YzU1MDlmNTcyNjYwMDAzOTA5MDE2OGMzODllNDBjNTVkZGE"
:ezcater-integration/subscriber-uuid "007d4353-fbb8-4725-9c0a-81bbd565dbe5"
:ezcater-integration/subscriber-secret "3dccc547f6c4d9b3cbed15ab81d3748d2a34be7fdb9b8edfdc9abd6c75a821fe"}]]
:requires [::add-integration-status3]}})

View File

@@ -1,72 +0,0 @@
(ns auto-ap.datomic.migrate.invoice-converter
(:require [datomic.api :as d]))
(def add-matches
[[{:db/ident :client/matches
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db/doc "The strings that match the client"}
{:db/ident :client/location-matches
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db/isComponent true
:db/doc "The mapping from string to location"}
{:db/ident :location-match/matches
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db/doc "The strings that match the location"}
{:db/ident :location-match/location
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The location of the location match"}
]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn add-starter [conn]
(if (seq (d/query {:query {:find '[?e]
:in ['$]
:where ['[?e :client/code "CBC"]]}
:args [(d/db conn)]}))
[[{:db/id [:client/code "CBC"]
:client/matches ["campbell brewing company"]
:client/location-matches [{:location-match/location "CB"
:location-match/matches ["campbell brewing company"]}]}]]
[[]]))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn add-default-location [_]
[[{:db/ident :client/default-location
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The default location if one can't be found"}]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn add-default-location-2 [conn]
(if (seq (d/query {:query {:find '[?e]
:in ['$]
:where ['[?e :client/code "CBC"]]}
:args [(d/db conn)]}))
[[{:db/id [:client/code "CBC"]
:client/default-location "CB"}]]
[[]]))
(def add-import-status
[[{:db/ident :invoice/import-status
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The status of importing the transaction"}
{:db/ident :import-status/pending}
{:db/ident :import-status/imported}]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn add-import-status-existing-invoices [conn]
(let [existing-invoices (->> (d/query {:query {:find ['?e]
:in ['$]
:where ['[?e :invoice/invoice-number]]}
:args [(d/db conn)]}))]
[(map (fn [i] {:db/id (first i)
:invoice/import-status :import-status/imported})
existing-invoices)]))

View File

@@ -1,6 +0,0 @@
(ns auto-ap.datomic.migrate.ledger)
(def norms-map {::add-alternat-description {:txes [[{:db/ident :journal-entry/alternate-description
:db/doc "The description if there is no vendor"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]]}})

View File

@@ -1,55 +0,0 @@
(ns auto-ap.datomic.migrate.plaid)
(def norms-map {::add-plaid
{:txes [[{:db/ident :plaid-item/external-id
:db/doc "Plaid Item ID"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
{:db/ident :plaid-item/access-token
:db/doc "Used to authenticate to plaid"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :plaid-item/client
:db/doc "Which client the plaid item is for"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :plaid-item/accounts
:db/doc "Individual bank accounts"
:db/isComponent true
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}
{:db/ident :plaid-item/status
:db/doc "Current status"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :plaid-item/last-updated
:db/doc "Last updated date"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one
:db/noHistory true}
{:db/ident :plaid-account/external-id
:db/doc "plaid account id"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
{:db/ident :plaid-account/name
:db/doc "account name"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :plaid-account/number
:db/doc "account number"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :plaid-account/balance
:db/doc "Available Balance"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :bank-account/plaid-account
:db/doc "Yodlee account for the bank account"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :import-source/plaid}]]}})

View File

@@ -1,29 +0,0 @@
(ns auto-ap.datomic.migrate.queries)
(def norms-map {::add-queries
{:txes [[{:db/ident :saved-query/guid
:db/doc "The ID that is used for fetching data"
:db/valueType :db.type/string
:db/unique :db.unique/identity
:db/cardinality :db.cardinality/one}
{:db/ident :saved-query/client
:db/doc "The client for the saved query"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :saved-query/key
:db/doc "The key for the query text in s3"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :saved-query/description
:db/doc "A descriptor for the query for the user interface"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :saved-query/lookup-key
:db/doc "A unique key for looking up queries"
:db/valueType :db.type/string
:db/unique :db.unique/identity
:db/cardinality :db.cardinality/one}]]}})

View File

@@ -1,42 +0,0 @@
(ns auto-ap.datomic.migrate.rename-codes
(:require [datomic.api :as d]
[auto-ap.datomic :refer [uri]]
[clojure.string :as str]))
(defn rename [old-code new-code conn ]
(let [results (->> (d/query {:query {:find ['?e '?b '?bc]
:in ['$ '?old-code]
:where ['[?e :client/code ?old-code]
'[?e :client/bank-accounts ?b]
'[?b :bank-account/code ?bc]]}
:args [(d/db conn) old-code]})
(group-by first))
#_#_[[id]] results]
(for [[id change] results
[_ ba-id ba-code] change]
[{:db/id id
:client/code new-code}
{:db/id ba-id
:bank-account/code (str/replace ba-code #"^.*-" (str new-code "-"))}])
#_[{:db/id id
:client/code new-code
#_#_:client/bank-accounts (map)}]
)
)
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn rename-codes-1 [_]
(let [result (apply concat [(rename "WE" "WME" (d/connect uri))
(rename "HM" "HIM" (d/connect uri))
(rename "BES" "SBE" (d/connect uri))
(rename "BES" "SBE" (d/connect uri))
(rename "ORA" "OMG" (d/connect uri))
(rename "INT" "IGC" (d/connect uri))
(rename "MV" "MVSC" (d/connect uri))])]
(if (seq (seq result))
result
[[]]))
)

View File

@@ -1,31 +0,0 @@
(ns auto-ap.datomic.migrate.reports)
(def norms-map {::add-reports
{:txes [[{:db/ident :report/client
:db/doc "Which client(s) this is for"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}
{:db/ident :report/name
:db/doc "A description for the report"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :report/key
:db/doc "The s3 key for the report"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :report/created
:db/doc "When this report was created"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}
{:db/ident :report/url
:db/doc "Where to download the report"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]]}
::add-creator {:txes [[{:db/ident :report/creator
:db/doc "Creator of the report's name"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]]}})

View File

@@ -1,334 +0,0 @@
(ns auto-ap.datomic.migrate.sales
(:require [datomic.api :as d]))
(defn backfill-status [conn]
(let [db (d/db conn)
pendings (->>
(d/q '[:find [?ed ...]
:where [?ed :expected-deposit/date]
(not [_ :transaction/expected-deposit ?ed])
(not [?ed :expected-deposit/status])]
db)
(map (fn [ed]
{:db/id ed
:expected-deposit/status :expected-deposit-status/pending})))
cleared (->>
(d/q '[:find [?ed ...]
:where [?ed :expected-deposit/date]
[_ :transaction/expected-deposit ?ed]
(not [?ed :expected-deposit/status])]
db)
(map (fn [ed]
{:db/id ed
:expected-deposit/status :expected-deposit-status/cleared})))]
[(into pendings cleared)]))
(def norms-map {:add-orders {:txes [[{:db/ident :sales-order/external-id
:db/doc "The client for the sale"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
{:db/ident :sales-order/client
:db/doc "The client for the sale"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :sales-order/location
:db/doc "The location of the sale"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :sales-order/date
:db/doc "The date the order was placed"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}
{:db/ident :sales-order/total
:db/doc "The total amount on the sale"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :sales-order/tax
:db/doc "The tax on the sale"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :sales-order/tip
:db/doc "The tip on the sale"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :sales-order/charges
:db/doc "How the sale was paid"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db/isComponent true}
{:db/ident :sales-order/line-items
:db/doc "What the person ordered"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db/isComponent true}
{:db/ident :charge/type-name
:db/doc "The type of the charge"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :charge/total
:db/doc "The total amount on the charge"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :charge/tax
:db/doc "The tax on the charge"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :charge/tip
:db/doc "The tip on the charge"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :order-line-item/item-name
:db/doc "The type of the item"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :order-line-item/total
:db/doc "The total cost on the item"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :order-line-item/tax
:db/doc "The tax on the item"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :order-line-item/tip
:db/doc "The tip on the item"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
]]}
:add-expected-deposits {:txes [[{:db/ident :expected-deposit/external-id
:db/doc "The external id for the deposit"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
{:db/ident :expected-deposit/client
:db/doc "The client for the deposit"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :expected-deposit/location
:db/doc "The location of the sale"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :expected-deposit/date
:db/doc "The date the deposit was initiated"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}
{:db/ident :expected-deposit/total
:db/doc "The total amount on the deposit"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :expected-deposit/fee
:db/doc "The total fee on the deposit"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}]]}
:add-discounts {:txes [[{:db/ident :sales-order/discount
:db/doc "The total amount on the sale"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :order-line-item/discount
:db/doc "The total cost on the item"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}]]}
:add-category {:txes [[{:db/ident :order-line-item/category
:db/doc "The item category"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]]}
:add-other-types {:txes [[{:db/ident :sales-order/returns
:db/doc "The returned amount on the sale"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :sales-order/service-charge
:db/doc "The total cost on the item"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}]]}
:add-food-apps {:txes [[{:db/ident :ccp-processor/doordash
:db/doc "Doordash identifier"}
{:db/ident :ccp-processor/grubhub
:db/doc "Grubhub identifier"}
{:db/ident :ccp-processor/uber-eats
:db/doc "Uber eats processor"}
{:db/ident :ccp-processor/na
:db/doc "No specific ccp processor"}
{:db/ident :charge/processor
:db/doc "Which food app processed this order"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}]]}
:add-refunds {:txes [[{:db/ident :sales-refund/external-id
:db/doc "The external id for the refund"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
{:db/ident :sales-refund/client
:db/doc "The client for the refund"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :sales-refund/location
:db/doc "The location of the refund"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :sales-refund/date
:db/doc "The date the refund was initiated"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}
{:db/ident :sales-refund/total
:db/doc "The total amount on the deposit"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :sales-refund/fee
:db/doc "The total fee on the refund"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}]]}
:add-sales-date {:txes [[{:db/ident :expected-deposit/sales-date
:db/doc "The date of sales the deposit was for"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}]]}
:add-expected-deposit-status {:txes [[{:db/ident :expected-deposit/status
:db/doc "Whether the deposit has been cleared"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :expected-deposit-status/pending}
{:db/ident :expected-deposit-status/cleared}
{:db/ident :transaction/expected-deposit
:db/doc "If this transaction is a deposit, the deposit that we anticipated"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}]]}
:add-vendor-for-sales-stuff {:txes [[{:db/ident :expected-deposit/vendor
:db/doc "Which vendor is this deposit for? CCP Square?"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :sales-order/vendor
:db/doc "Which vendor is this sales-order for? CCP Square?"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :sales-refund/vendor
:db/doc "Which vendor is this refund for? CCP Square?"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}]]}
:backfill-status {:txes-fn `backfill-status
:requires [:add-expected-deposit-status
:add-expected-deposits
:add-sales-date
:add-vendor-for-sales-stuff
:add-orders]}
:add-charge-id2 {:txes [[{:db/ident :charge/external-id
:db/doc "The client for the sale"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}]]}
:add-line-item-id2 {:txes [[{:db/ident :order-line-item/external-id
:db/doc "An Id that links to square etc"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}]]}
:add-expected-depsoit-link {:txes [[{:db/ident :expected-deposit/charges
:db/doc "charges for the deposit"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}]]}
:add-refund-type {:txes [[{:db/ident :sales-refund/type
:db/doc "The type of refund"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]]
:requires [:add-refunds]}
:add-square-locations-3 {:txes [[{:db/ident :client/square-auth-token
:db/doc "A token that can be used to authenticate with square"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :client/square-locations
:db/doc "Locations in square"
:db/valueType :db.type/ref
:db/isComponent true
:db/cardinality :db.cardinality/many}
{:db/ident :square-location/square-id
:db/doc "An id for a location in square"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :square-location/name
:db/doc "Name of the location in square e.g. Woodland Hills"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :square-location/client-location
:db/doc "The client location that this location should match to. e.g. WH"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]]}
:add-indices {:txes [[{:db/ident :sales-order/date
:db/index true}
{:db/ident :sales-order/client
:db/index true}]]
:requires [:add-orders]}
:add-ezcater-vendor {:txes [[{:db/ident :vendor/ccp-ezcater
:vendor/name "EZCater CCP"}]]}
:add-charge-client {:txes [[{:db/ident :charge/client
:db/doc "The client for the sale"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :charge/location
:db/doc "The location of the sale"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]]}
:add-charge-date {:txes [[{:db/ident :charge/date
:db/doc "The date for the payment"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}]]}
:add-ezcater-processor {:txes [[{:db/ident :ccp-processor/ezcater
:db/doc "ezcater processor"}]]}
:add-koala-processor {:txes [[{:db/ident :ccp-processor/koala
:db/doc "koala processor"}]]}
:add-square-processor {:txes [[{:db/ident :ccp-processor/square
:db/doc "square processor"}]]}
:add-reference-link3 {:txes [[{:db/ident :sales-order/reference-link
:db/cardinality :db.cardinality/one
:db/valueType :db.type/string
:db/doc "A link someone can go to to look at the order"}
{:db/ident :charge/reference-link
:db/cardinality :db.cardinality/one
:db/valueType :db.type/string
:db/doc "A link someone can go to to look at the charge"}]]}
:add-source-field2 {:txes [[{:db/ident :sales-order/source
:db/cardinality :db.cardinality/one
:db/valueType :db.type/string
:db/doc "Where the POS says the order is from"}
{:db/ident :charge/note
:db/cardinality :db.cardinality/one
:db/valueType :db.type/string
:db/doc "A custom note"}]]}
:add-feature-flags {:txes [[{:db/ident :client/feature-flags
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many}]]}})

View File

@@ -1,84 +0,0 @@
(ns auto-ap.datomic.migrate.vendors
(:require [datomic.api :as d]))
(defn add-vendor-search-terms [conn]
[(->> (d/q '[:find ?i ?n
:in $
:where [?i :vendor/name ?n]]
(d/db conn))
(map (fn [[i n]]
{:db/id i
:vendor/search-terms n})))])
(def norms-map {:add-1099-stuff {:txes [[{:db/ident :vendor/legal-entity-first-name
:db/doc "The first name for the legal entity"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :vendor/legal-entity-middle-name
:db/doc "The first name for the legal entity"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :vendor/legal-entity-last-name
:db/doc "The first name for the legal entity"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :vendor/legal-entity-tin
:db/doc "The ssn or ein for the legal entity"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :vendor/legal-entity-tin-type
:db/doc "The ssn or ein for the legal entity"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :vendor/legal-entity-1099-type
:db/doc "The ssn or ein for the legal entity"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}]]}
:add-1099-enums {:txes [[{:db/ident :legal-entity-tin-type/ssn}
{:db/ident :legal-entity-tin-type/ein}
{:db/ident :legal-entity-1099-type/none}
{:db/ident :legal-entity-1099-type/misc}
{:db/ident :legal-entity-1099-type/landlord}]]}
:add-vendor-usages {:txes [[{:db/ident :vendor-usage/key
:db/doc "A key to find this by, normally vendor (db:/id)-client(:db/id)"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
{:db/ident :vendor-usage/vendor
:db/doc "Which vendor this usage is for"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :vendor-usage/client
:db/doc "Which client this usage is for"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :vendor-usage/count
:db/doc "How many times does this client use this vendor"
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one
:db/noHistory true}]
]}
::make-fulltext-search {:txes [[{:db/ident :vendor/search-terms
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db/doc "a name search for vendors"
:db/fulltext true}]]
:requires [:auto-ap/base-schema]}
::add-vendor-search-terms {:txes-fn `add-vendor-search-terms
:requires [::make-fulltext-search]}
::add-legal-entity-name {:txes [[{:db/ident :vendor/legal-entity-name
:db/doc "If not a person, the legal entity naame"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]]}})

View File

@@ -1,56 +0,0 @@
(ns auto-ap.datomic.migrate.yodlee2)
(def norms-map {::add-yodlee-view
{:txes [[{:db/ident :yodlee-provider-account/id
:db/doc "Yodlee Provider ACcount Id"
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
{:db/ident :yodlee-provider-account/client
:db/doc "Which client the provider account is for"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :yodlee-provider-account/accounts
:db/doc "Individual bank accounts"
:db/isComponent true
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}
{:db/ident :yodlee-provider-account/status
:db/doc "Current status"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :yodlee-provider-account/detailed-status
:db/doc "Current status (detail)"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :yodlee-provider-account/last-updated
:db/doc "Last updated date"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}
{:db/ident :yodlee-account/id
:db/doc "Yodlee account id"
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
{:db/ident :yodlee-account/name
:db/doc "account name"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :yodlee-account/number
:db/doc "account number"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :yodlee-account/status
:db/doc "Current status"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :yodlee-account/available-balance
:db/doc "Available Balance"
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one}
{:db/ident :bank-account/yodlee-account
:db/doc "Yodlee account for the bank account"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}]]}})