Adding client code.

This commit is contained in:
BC
2019-01-28 08:00:26 -08:00
parent 1b5a097508
commit 294ac40930
4 changed files with 50 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
(ns auto-ap.datomic.migrate
(:require [auto-ap.datomic :refer [uri]]
[datomic.api :as d]
[auto-ap.datomic.migrate.add-client-codes :refer [add-client-codes]]
[clojure.java.io :as io]
[io.rkn.conformity :as c])
(:import [datomic Util])
@@ -48,6 +49,7 @@
: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]}
}]
(println "Conforming database...")
(println (c/ensure-conforms conn norms-map))

View File

@@ -0,0 +1,45 @@
(ns auto-ap.datomic.migrate.add-client-codes
(:require [auto-ap.datomic :refer [uri]]
[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 {}))
)
(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]]
(conj result [:db/add id :client/code (name->code name)]))
[])
)])

View File

@@ -38,6 +38,7 @@
:client
{:fields {:id {:type :id}
:name {:type 'String}
:code {:type 'String}
:email {:type 'String}
:address {:type :address}
:locations {:type '(list String)}

View File

@@ -41,7 +41,7 @@
:graphql {:token token
:query-obj {:venia/queries [[:client
[:id :name :email :locations [:bank-accounts [:id :number :check-number :name :type] ]
[:id :name :code :email :locations [:bank-accounts [:id :number :check-number :name :type] ]
[:address [:street1 :street2 :city :state :zip]]]]
[:vendor
[: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]]
{:graphql {:token token
:query-obj {:venia/queries [[:client
[:id :name [: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 :number :check-number :name :type]]]]
[:vendor
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}