vendors can be updated through datomic.
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
(map (fn [ba]
|
||||
(update ba :bank-account/type :db/ident ))
|
||||
bas)))))))
|
||||
|
||||
(defn get-by-id [id]
|
||||
(->>
|
||||
(d/query (-> {:query {:find ['(pull ?e [*])]
|
||||
|
||||
@@ -21,7 +21,9 @@
|
||||
:in $ ?e
|
||||
:where [?e]]
|
||||
(d/db (d/connect uri))
|
||||
(Long/parseLong id))
|
||||
(if (string? id)
|
||||
(Long/parseLong id)
|
||||
id))
|
||||
(map first)
|
||||
(first)
|
||||
#_(map (fn [c]
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
[auto-ap.datomic.invoices :as d-invoices]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.graphql.users :as gq-users]
|
||||
[auto-ap.graphql.vendors :as gq-vendors]
|
||||
[auto-ap.graphql.checks :as gq-checks]
|
||||
[auto-ap.graphql.expense-accounts :as expense-accounts]
|
||||
[auto-ap.graphql.invoices :as gq-invoices]
|
||||
@@ -257,6 +258,31 @@
|
||||
:role {:type 'String}
|
||||
:clients {:type '(list String)}}}
|
||||
|
||||
:add_contact
|
||||
{:fields {:id {:type 'String}
|
||||
:name {:type 'String}
|
||||
:email {:type 'String}
|
||||
:phone {:type 'String}}}
|
||||
:add_address
|
||||
{:fields {:street1 {:type 'String}
|
||||
:street2 {:type 'String}
|
||||
:city {:type 'String}
|
||||
:state {:type 'String}
|
||||
:zip {:type 'String}}}
|
||||
|
||||
:add_vendor
|
||||
{:fields {:id {:type 'String}
|
||||
:name {:type 'String}
|
||||
:code {:type 'String}
|
||||
|
||||
:print_as {:type 'String}
|
||||
:primary_contact {:type :add_contact}
|
||||
:secondary_contact {:type :add_contact}
|
||||
:address {:type :add_address}
|
||||
|
||||
:default_expense_account {:type 'Int}
|
||||
:invoice_reminder_schedule {:type 'String}}}
|
||||
|
||||
:edit_expense_account
|
||||
{:fields {:id {:type 'String}
|
||||
:expense_account_id {:type 'Int}
|
||||
@@ -303,6 +329,9 @@
|
||||
:args {:edit_user {:type :edit_user}}
|
||||
:resolve :mutation/edit-user}
|
||||
|
||||
:upsert_vendor {:type :vendor
|
||||
:args {:vendor {:type :add_vendor}}
|
||||
:resolve :mutation/upsert-vendor}
|
||||
:add_invoice {:type :invoice
|
||||
:args {:invoice {:type :add_invoice}}
|
||||
:resolve :mutation/add-invoice}
|
||||
@@ -443,6 +472,7 @@
|
||||
:mutation/edit-user gq-users/edit-user
|
||||
:mutation/add-invoice gq-invoices/add-invoice
|
||||
:mutation/edit-invoice gq-invoices/edit-invoice
|
||||
:mutation/upsert-vendor gq-vendors/upsert-vendor
|
||||
:mutation/void-invoice gq-invoices/void-invoice
|
||||
:mutation/void-payment gq-checks/void-check
|
||||
:mutation/edit-expense-accounts gq-invoices/edit-expense-accounts
|
||||
|
||||
53
src/clj/auto_ap/graphql/vendors.clj
Normal file
53
src/clj/auto_ap/graphql/vendors.clj
Normal file
@@ -0,0 +1,53 @@
|
||||
(ns auto-ap.graphql.vendors
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql assert-can-see-company]]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.time :refer [parse iso-date]]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri remove-nils]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.set :as set]))
|
||||
|
||||
|
||||
(defn upsert-vendor [context {{:keys [id name code print_as primary_contact secondary_contact address default_expense_account invoice_reminder_schedule] :as in} :vendor} value]
|
||||
(let [transaction [(remove-nils #:vendor {:db/id (if id
|
||||
(Long/parseLong id)
|
||||
"vendor")
|
||||
:name name
|
||||
:code code
|
||||
:print-as print_as
|
||||
:default-expense-account default_expense_account
|
||||
:invoice-reminder-schedule (keyword invoice_reminder_schedule)
|
||||
:address (when address
|
||||
(remove-nils #:address {:db/id (if (:id address)
|
||||
(Long/parseLong (: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)
|
||||
(Long/parseLong (: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)
|
||||
(Long/parseLong (:id secondary_contact))
|
||||
"secondary")
|
||||
:name (:name secondary_contact)
|
||||
:phone (:phone secondary_contact)
|
||||
:email (:email secondary_contact)})
|
||||
)})]
|
||||
transaction-result @(d/transact (d/connect uri) transaction)]
|
||||
|
||||
(-> (d-vendors/get-by-id (or (-> transaction-result :tempids (get "vendor"))
|
||||
id))
|
||||
(->graphql))))
|
||||
|
||||
|
||||
@@ -144,19 +144,14 @@
|
||||
{{:keys [excel-rows]} :edn-params user :identity}
|
||||
(assert-admin user)
|
||||
(let [columns [:raw-date :vendor-name :check :location :invoice-number :amount :company :bill-entered :bill-rejected :added-on :exported-on :default-expense-account]
|
||||
|
||||
all-vendors (by :name (vendors/get-all))
|
||||
|
||||
all-companies (companies/get-all)
|
||||
all-companies (merge (by :code all-companies) (by :name all-companies))
|
||||
|
||||
|
||||
rows (->> (str/split excel-rows #"\n" )
|
||||
(map #(str/split % #"\t"))
|
||||
(map #(into {} (map (fn [c k] [k c] ) % columns)))
|
||||
(map reset-id)
|
||||
(map assoc-company-code)
|
||||
|
||||
(map (parse-or-error :company-id #(parse-company % all-companies)))
|
||||
(map (parse-or-error :vendor-id #(parse-vendor % all-vendors)))
|
||||
(map (parse-or-error :default-expense-account parse-default-expense-account))
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
(ns auto-ap.yodlee.import
|
||||
(:require [auto-ap.yodlee.core :as client]
|
||||
[auto-ap.db.transactions :as transactions]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri remove-nils]]
|
||||
@@ -21,7 +19,6 @@
|
||||
:amount (- amount)
|
||||
:status :payment-status/pending})
|
||||
first
|
||||
(doto println)
|
||||
:db/id)
|
||||
|
||||
(and client-id bank-account-id amount)
|
||||
|
||||
Reference in New Issue
Block a user