added new fields.

This commit is contained in:
2021-02-15 20:46:56 -08:00
parent 6bacf90fbb
commit e2d3acd5c6
7 changed files with 241 additions and 77 deletions

View File

@@ -7,6 +7,7 @@
[auto-ap.datomic.migrate.add-general-ledger :as add-general-ledger]
[auto-ap.datomic.migrate.ledger :as ledger]
[auto-ap.datomic.migrate.sales :as sales]
[auto-ap.datomic.migrate.vendors :as vendors]
[auto-ap.datomic.migrate.clients :as clients]
[auto-ap.datomic.migrate.audit :as audit]
[auto-ap.datomic.migrate.yodlee2 :as yodlee2]
@@ -339,7 +340,10 @@
clients/norms-map
ledger/norms-map
yodlee2/norms-map
audit/norms-map)
audit/norms-map
vendors/norms-map
)
]
(println "Conforming database...")
(c/ensure-conforms conn norms-map)

View File

@@ -0,0 +1,44 @@
(ns auto-ap.datomic.migrate.vendors
(:require [datomic.api :as d]
[auto-ap.datomic :refer [uri]]))
(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}]]}})

View File

@@ -3,6 +3,11 @@
[auto-ap.graphql.utils :refer [limited-clients ]]
[auto-ap.datomic :refer [uri conn merge-query]]))
(defn <-datomic [a]
(cond-> a
(:vendor/legal-entity-tin-type a) (update :vendor/legal-entity-tin-type :db/ident)
(:vendor/legal-entity-1099-type a) (update :vendor/legal-entity-1099-type :db/ident)))
(defn cleanse [id vendor]
(let [clients (if-let [clients (limited-clients id)]
(set (map :db/id clients))
@@ -20,6 +25,8 @@
:vendor/terms-overrides [* {:vendor-terms-override/client [:client/name :client/code :db/id]}]
:vendor/schedule-payment-dom [* {:vendor-schedule-payment-dom/client [:client/name :client/code :db/id]}]
:vendor/automatically-paid-when-due [:db/id :client/name]
:vendor/legal-entity-tin-type [:db/ident :db/id]
:vendor/legal-entity-1099-type [:db/ident :db/id]
:vendor/default-account [:db/id :account/numeric-code :account/name]}])
(defn get-usages [args]
@@ -57,12 +64,15 @@
(d/query)
(map first)
(map #(cleanse (:id args) %))
(map <-datomic)
(map #(assoc % :usage (get usages (:db/id %)))))))
(defn get-by-id [id]
(->> (d/q '[:find (pull ?e [*
{:default-account [:account/name :db/id :account/location]
:vendor/legal-entity-tin-type [:db/ident :db/id]
:vendor/legal-entity-1099-type [:db/ident :db/id]
:vendor/account-overrides [* {:vendor-account-override/client [:client/name :db/id]
:vendor-account-override/account [:account/name :account/numeric-code :db/id]}]
:vendor/terms-overrides [* {:vendor-terms-override/client [:client/name :db/id]}]
@@ -73,6 +83,7 @@
(d/db (d/connect uri))
id)
(map first)
(map <-datomic)
(first)))

View File

@@ -211,7 +211,16 @@
:address {:type :address}
:default_account {:type :account}
:invoice_reminder_schedule {:type 'String}}}
:invoice_reminder_schedule {:type 'String}
:legal_entity_first_name {:type 'String}
:legal_entity_middle_name {:type 'String}
:legal_entity_last_name {:type 'String}
:legal_entity_tin {:type 'String}
:legal_entity_tin_type {:type :tin_type}
:legal_entity_1099_type {:type :type_1099}
}}
:reminder
{:fields {:id {:type 'Int}
:email {:type 'String}
@@ -798,7 +807,15 @@
:default_account_id {:type :id}
:account_overrides {:type '(list :add_account_override)}
:schedule_payment_dom {:type '(list :add_schedule_payment_dom)}
:invoice_reminder_schedule {:type 'String}}}
:invoice_reminder_schedule {:type 'String}
:legal_entity_first_name {:type 'String}
:legal_entity_middle_name {:type 'String}
:legal_entity_last_name {:type 'String}
:legal_entity_tin {:type 'String}
:legal_entity_tin_type {:type :tin_type}
:legal_entity_1099_type {:type :type_1099}
}}
:edit_expense_account
{:fields {:id {:type :id}
@@ -873,6 +890,11 @@
:enums {:payment_type {:values [{:enum-value :check}
{:enum-value :cash}
{:enum-value :debit}]}
:tin_type {:values [{:enum-value :ein}
{:enum-value :ssn}]}
:type_1099 {:values [{:enum-value :none}
{:enum-value :misc}
{:enum-value :landlord}]}
:invoice_status {:values [{:enum-value :paid}
{:enum-value :unpaid}
{:enum-value :voided}]}

View File

@@ -1,5 +1,5 @@
(ns auto-ap.graphql.vendors
(:require [auto-ap.graphql.utils :refer [->graphql assert-can-see-client assert-admin is-admin?]]
(:require [auto-ap.graphql.utils :refer [->graphql assert-can-see-client assert-admin is-admin? enum->keyword]]
[auto-ap.datomic.vendors :as d-vendors]
[auto-ap.time :refer [parse iso-date]]
[datomic.api :as d]
@@ -40,45 +40,49 @@
(:id ao) (assoc :db/id (:id ao))))
schedule_payment_dom)
transaction (cond->
[(remove-nils #:vendor {:db/id (if id
id
"vendor")
:name name
:code code
:hidden hidden
:terms terms
:print-as print_as
:default-account default_account_id
:invoice-reminder-schedule (keyword invoice_reminder_schedule)
:address (when address
(remove-nils #:address {:db/id (if (:id address)
(:id address)
"address")
:street1 (:street1 address)
:street2 (:street2 address)
:city (:city address)
:state (:state address)
:zip (:zip address)}))
:primary-contact (when primary_contact
[(remove-nils (cond-> #:vendor {:db/id (if id
id
"vendor")
:name name
:code code
:hidden hidden
:terms terms
:print-as print_as
:default-account default_account_id
:invoice-reminder-schedule (keyword invoice_reminder_schedule)
:address (when address
(remove-nils #:address {:db/id (if (:id address)
(:id address)
"address")
:street1 (:street1 address)
:street2 (:street2 address)
:city (:city address)
:state (:state address)
:zip (:zip address)}))
:primary-contact (when primary_contact
(remove-nils #:contact {:db/id (if (:id primary_contact)
(:id primary_contact)
"primary")
:name (:name primary_contact)
:phone (:phone primary_contact)
:email (:email primary_contact)}))
:secondary-contact (when secondary_contact
(remove-nils #:contact {:db/id (if (:id primary_contact)
(:id primary_contact)
"primary")
:name (:name primary_contact)
:phone (:phone primary_contact)
:email (:email primary_contact)}))
:secondary-contact (when secondary_contact
(remove-nils #:contact {:db/id (if (:id secondary_contact)
(:id secondary_contact)
"secondary")
:name (:name secondary_contact)
:phone (:phone secondary_contact)
:email (:email secondary_contact)})
)})]
(remove-nils #:contact {:db/id (if (:id secondary_contact)
(:id secondary_contact)
"secondary")
:name (:name secondary_contact)
:phone (:phone secondary_contact)
:email (:email secondary_contact)})
)}
(is-admin? (:id context)) (assoc
:vendor/legal-entity-first-name (:legal_entity_first_name in)
:vendor/legal-entity-middle-name (:legal_entity_middle_name in)
:vendor/legal-entity-last-name (:legal_entity_last_name in)
:vendor/legal-entity-tin (:legal_entity_tin in)
:vendor/legal-entity-tin-type (enum->keyword (:legal_entity_tin_type in) "legal-entity-tin-type")
:vendor/legal-entity-1099-type (enum->keyword (:legal_entity_1099_type in) "legal-entity-1099-type"))))]
(is-admin? (:id context)) (conj [:reset (if id id "vendor") :vendor/account-overrides account-overrides])
(is-admin? (:id context)) (conj [:reset (if id id "vendor") :vendor/terms-overrides terms-overrides])
(is-admin? (:id context)) (conj [:reset (if id id "vendor") :vendor/schedule-payment-dom schedule-payment-dom])
@@ -91,9 +95,10 @@
_ (log/info "Upserting vendor" transaction)
transaction-result (audit-transact transaction (:id context))]
(-> (d-vendors/get-by-id (or (-> transaction-result :tempids (get "vendor"))
id))
(->graphql))))
(doto (-> (d-vendors/get-by-id (or (-> transaction-result :tempids (get "vendor"))
id))
(->graphql))
log/info)))
(defn merge-vendors [context {:keys [from to]} value]
(let [transaction (->> (d/query {:query {:find '[?x ?a2]