Added the ability to import invoices again
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
(ns auto-ap.datomic.invoices
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[auto-ap.datomic :refer [uri remove-nils]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[auto-ap.parse :as parse]
|
||||
[clj-time.coerce :as c]
|
||||
[clojure.set :refer [rename-keys]]
|
||||
[clojure.string :as str]))
|
||||
@@ -49,6 +50,8 @@
|
||||
(:original-id args) (add-arg '?original-id (cond-> (:original-id args) (string? (:original-id args)) Long/parseLong )
|
||||
'[?e :invoice/client ?c]
|
||||
'[?c :client/original-id ?original-id])
|
||||
(:import-status args) (add-arg '?import-status (keyword "import-status" (:import-status args))
|
||||
'[?e :invoice/import-status ?import-status])
|
||||
(:status args) (add-arg '?status (keyword "invoice-status" (:status args))
|
||||
'[?e :invoice/status ?status])
|
||||
(:vendor-id args) (add-arg '?vendor-id (:vendor-id args)
|
||||
@@ -127,3 +130,5 @@
|
||||
(map first)
|
||||
|
||||
(<-datomic)))
|
||||
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
(defn -main [& args]
|
||||
(println "Creating database...")
|
||||
#_(d/delete-database uri)
|
||||
(d/delete-database uri)
|
||||
(d/create-database uri)
|
||||
|
||||
(let [
|
||||
@@ -55,6 +55,12 @@
|
||||
: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 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]}
|
||||
}]
|
||||
(println "Conforming database...")
|
||||
(println (c/ensure-conforms conn norms-map))
|
||||
|
||||
58
src/clj/auto_ap/datomic/migrate/invoice_converter.clj
Normal file
58
src/clj/auto_ap/datomic/migrate/invoice_converter.clj
Normal file
@@ -0,0 +1,58 @@
|
||||
(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"}
|
||||
]])
|
||||
|
||||
(def add-starter
|
||||
[[{:db/id [:client/code "CBC"]
|
||||
:client/matches ["campbell brewing company"]
|
||||
:client/location-matches [{:location-match/location "CB"
|
||||
:location-match/matches ["campbell brewing company"]}]}]])
|
||||
|
||||
(defn add-default-location [conn]
|
||||
[[{: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"}]])
|
||||
|
||||
(defn add-default-location-2 [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}]])
|
||||
|
||||
(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)]))
|
||||
@@ -27,11 +27,15 @@
|
||||
)
|
||||
|
||||
(defn rename-codes-1 [conn]
|
||||
(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))]))
|
||||
(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
|
||||
[[]]))
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user