vendors can be updated through datomic.
This commit is contained in:
@@ -14,7 +14,6 @@
|
|||||||
(map (fn [ba]
|
(map (fn [ba]
|
||||||
(update ba :bank-account/type :db/ident ))
|
(update ba :bank-account/type :db/ident ))
|
||||||
bas)))))))
|
bas)))))))
|
||||||
|
|
||||||
(defn get-by-id [id]
|
(defn get-by-id [id]
|
||||||
(->>
|
(->>
|
||||||
(d/query (-> {:query {:find ['(pull ?e [*])]
|
(d/query (-> {:query {:find ['(pull ?e [*])]
|
||||||
|
|||||||
@@ -21,7 +21,9 @@
|
|||||||
:in $ ?e
|
:in $ ?e
|
||||||
:where [?e]]
|
:where [?e]]
|
||||||
(d/db (d/connect uri))
|
(d/db (d/connect uri))
|
||||||
(Long/parseLong id))
|
(if (string? id)
|
||||||
|
(Long/parseLong id)
|
||||||
|
id))
|
||||||
(map first)
|
(map first)
|
||||||
(first)
|
(first)
|
||||||
#_(map (fn [c]
|
#_(map (fn [c]
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
[auto-ap.datomic.invoices :as d-invoices]
|
[auto-ap.datomic.invoices :as d-invoices]
|
||||||
[auto-ap.datomic.vendors :as d-vendors]
|
[auto-ap.datomic.vendors :as d-vendors]
|
||||||
[auto-ap.graphql.users :as gq-users]
|
[auto-ap.graphql.users :as gq-users]
|
||||||
|
[auto-ap.graphql.vendors :as gq-vendors]
|
||||||
[auto-ap.graphql.checks :as gq-checks]
|
[auto-ap.graphql.checks :as gq-checks]
|
||||||
[auto-ap.graphql.expense-accounts :as expense-accounts]
|
[auto-ap.graphql.expense-accounts :as expense-accounts]
|
||||||
[auto-ap.graphql.invoices :as gq-invoices]
|
[auto-ap.graphql.invoices :as gq-invoices]
|
||||||
@@ -257,6 +258,31 @@
|
|||||||
:role {:type 'String}
|
:role {:type 'String}
|
||||||
:clients {:type '(list 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
|
:edit_expense_account
|
||||||
{:fields {:id {:type 'String}
|
{:fields {:id {:type 'String}
|
||||||
:expense_account_id {:type 'Int}
|
:expense_account_id {:type 'Int}
|
||||||
@@ -303,6 +329,9 @@
|
|||||||
:args {:edit_user {:type :edit_user}}
|
:args {:edit_user {:type :edit_user}}
|
||||||
:resolve :mutation/edit-user}
|
:resolve :mutation/edit-user}
|
||||||
|
|
||||||
|
:upsert_vendor {:type :vendor
|
||||||
|
:args {:vendor {:type :add_vendor}}
|
||||||
|
:resolve :mutation/upsert-vendor}
|
||||||
:add_invoice {:type :invoice
|
:add_invoice {:type :invoice
|
||||||
:args {:invoice {:type :add_invoice}}
|
:args {:invoice {:type :add_invoice}}
|
||||||
:resolve :mutation/add-invoice}
|
:resolve :mutation/add-invoice}
|
||||||
@@ -443,6 +472,7 @@
|
|||||||
:mutation/edit-user gq-users/edit-user
|
:mutation/edit-user gq-users/edit-user
|
||||||
:mutation/add-invoice gq-invoices/add-invoice
|
:mutation/add-invoice gq-invoices/add-invoice
|
||||||
:mutation/edit-invoice gq-invoices/edit-invoice
|
:mutation/edit-invoice gq-invoices/edit-invoice
|
||||||
|
:mutation/upsert-vendor gq-vendors/upsert-vendor
|
||||||
:mutation/void-invoice gq-invoices/void-invoice
|
:mutation/void-invoice gq-invoices/void-invoice
|
||||||
:mutation/void-payment gq-checks/void-check
|
:mutation/void-payment gq-checks/void-check
|
||||||
:mutation/edit-expense-accounts gq-invoices/edit-expense-accounts
|
: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}
|
{{:keys [excel-rows]} :edn-params user :identity}
|
||||||
(assert-admin user)
|
(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]
|
(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-vendors (by :name (vendors/get-all))
|
||||||
|
|
||||||
all-companies (companies/get-all)
|
all-companies (companies/get-all)
|
||||||
all-companies (merge (by :code all-companies) (by :name all-companies))
|
all-companies (merge (by :code all-companies) (by :name all-companies))
|
||||||
|
|
||||||
|
|
||||||
rows (->> (str/split excel-rows #"\n" )
|
rows (->> (str/split excel-rows #"\n" )
|
||||||
(map #(str/split % #"\t"))
|
(map #(str/split % #"\t"))
|
||||||
(map #(into {} (map (fn [c k] [k c] ) % columns)))
|
(map #(into {} (map (fn [c k] [k c] ) % columns)))
|
||||||
(map reset-id)
|
(map reset-id)
|
||||||
(map assoc-company-code)
|
(map assoc-company-code)
|
||||||
|
|
||||||
(map (parse-or-error :company-id #(parse-company % all-companies)))
|
(map (parse-or-error :company-id #(parse-company % all-companies)))
|
||||||
(map (parse-or-error :vendor-id #(parse-vendor % all-vendors)))
|
(map (parse-or-error :vendor-id #(parse-vendor % all-vendors)))
|
||||||
(map (parse-or-error :default-expense-account parse-default-expense-account))
|
(map (parse-or-error :default-expense-account parse-default-expense-account))
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
(ns auto-ap.yodlee.import
|
(ns auto-ap.yodlee.import
|
||||||
(:require [auto-ap.yodlee.core :as client]
|
(:require [auto-ap.yodlee.core :as client]
|
||||||
[auto-ap.db.transactions :as transactions]
|
|
||||||
[auto-ap.db.vendors :as vendors]
|
|
||||||
[auto-ap.utils :refer [by]]
|
[auto-ap.utils :refer [by]]
|
||||||
[datomic.api :as d]
|
[datomic.api :as d]
|
||||||
[auto-ap.datomic :refer [uri remove-nils]]
|
[auto-ap.datomic :refer [uri remove-nils]]
|
||||||
@@ -21,7 +19,6 @@
|
|||||||
:amount (- amount)
|
:amount (- amount)
|
||||||
:status :payment-status/pending})
|
:status :payment-status/pending})
|
||||||
first
|
first
|
||||||
(doto println)
|
|
||||||
:db/id)
|
:db/id)
|
||||||
|
|
||||||
(and client-id bank-account-id amount)
|
(and client-id bank-account-id amount)
|
||||||
|
|||||||
14
src/cljc/auto_ap/entities/contact.cljc
Normal file
14
src/cljc/auto_ap/entities/contact.cljc
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
(ns auto-ap.entities.contact
|
||||||
|
(:require [clojure.spec.alpha :as s]
|
||||||
|
[clojure.string :as str]
|
||||||
|
[auto-ap.entities.address :as address]))
|
||||||
|
|
||||||
|
(def email-regex #"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$")
|
||||||
|
|
||||||
|
(s/def ::id (s/nilable string?))
|
||||||
|
(s/def ::name (s/nilable string?))
|
||||||
|
(s/def ::email (s/nilable (s/and string? (s/or :is-email #(re-matches email-regex %)
|
||||||
|
:is-empty #(= % "")))))
|
||||||
|
(s/def ::phone (s/nilable string?))
|
||||||
|
|
||||||
|
(s/def ::contact (s/keys :opt-un [::name ::email ::phone ::id]))
|
||||||
@@ -1,28 +1,20 @@
|
|||||||
(ns auto-ap.entities.vendors
|
(ns auto-ap.entities.vendors
|
||||||
(:require [clojure.spec.alpha :as s]
|
(:require [clojure.spec.alpha :as s]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
|
[auto-ap.entities.contact :as contact]
|
||||||
[auto-ap.entities.address :as address]))
|
[auto-ap.entities.address :as address]))
|
||||||
|
|
||||||
(def email-regex #"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$")
|
(s/def ::id string?)
|
||||||
(s/def ::id int)
|
|
||||||
(s/def ::identifier (s/nilable string?)) (s/def ::required-identifier (s/and string?
|
(s/def ::identifier (s/nilable string?)) (s/def ::required-identifier (s/and string?
|
||||||
#(not (str/blank? %))))
|
#(not (str/blank? %))))
|
||||||
|
|
||||||
(s/def ::name ::required-identifier)
|
(s/def ::name ::required-identifier)
|
||||||
(s/def ::print-as (s/nilable string?))
|
(s/def ::print-as (s/nilable string?))
|
||||||
|
|
||||||
(s/def ::email (s/nilable (s/and string? (s/or :is-email #(re-matches email-regex %)
|
|
||||||
:is-empty #(= % "")))))
|
|
||||||
(s/def ::phone (s/nilable string?))
|
|
||||||
|
|
||||||
(s/def ::invoice-reminder-schedule (s/nilable #{"Weekly" "Never" nil}))
|
(s/def ::invoice-reminder-schedule (s/nilable #{"Weekly" "Never" nil}))
|
||||||
(s/def ::primary-contact (s/nilable ::identifier))
|
|
||||||
(s/def ::primary-email (s/nilable ::email))
|
|
||||||
(s/def ::primary-phone (s/nilable ::phone))
|
|
||||||
|
|
||||||
(s/def ::secondary-contact (s/nilable ::identifier))
|
(s/def ::primary-contact (s/nilable ::contact/contact))
|
||||||
(s/def ::secondary-email (s/nilable ::email))
|
(s/def ::secondary-contact (s/nilable ::contact/contact))
|
||||||
(s/def ::secondary-phone (s/nilable ::phone))
|
|
||||||
(s/def ::address (s/nilable ::address/address))
|
(s/def ::address (s/nilable ::address/address))
|
||||||
(s/def ::default-expense-account int?)
|
(s/def ::default-expense-account int?)
|
||||||
|
|
||||||
@@ -35,14 +27,8 @@
|
|||||||
::print-as
|
::print-as
|
||||||
::invoice-reminder-schedule
|
::invoice-reminder-schedule
|
||||||
::primary-contact
|
::primary-contact
|
||||||
::primary-email
|
|
||||||
::primary-phone
|
|
||||||
::secondary-contact
|
::secondary-contact
|
||||||
::secondary-email
|
::address]))
|
||||||
::secondary-phone
|
|
||||||
::address
|
|
||||||
|
|
||||||
]))
|
|
||||||
|
|
||||||
|
|
||||||
(def vendor-spec (apply hash-map (drop 1 (s/form ::vendor))))
|
(def vendor-spec (apply hash-map (drop 1 (s/form ::vendor))))
|
||||||
|
|||||||
@@ -111,17 +111,6 @@
|
|||||||
(fn [db [_ new-invoices]]
|
(fn [db [_ new-invoices]]
|
||||||
(assoc-in db [:invoices :pending] new-invoices)))
|
(assoc-in db [:invoices :pending] new-invoices)))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
|
||||||
::approve-invoices
|
|
||||||
(fn [cofx [_]]
|
|
||||||
{:http {:method :post
|
|
||||||
:token (-> cofx :db :user)
|
|
||||||
:uri (str "/api/invoices/approve"
|
|
||||||
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
|
|
||||||
(str "?company=" company-id)))
|
|
||||||
:on-success [::received-invoices :pending]
|
|
||||||
}}))
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::view-pending-invoices
|
::view-pending-invoices
|
||||||
(fn [cofx []]
|
(fn [cofx []]
|
||||||
@@ -143,16 +132,6 @@
|
|||||||
[:id :total :invoice-number :date [:vendor [:name :id]] [:company [:name :id]]]]]}
|
[:id :total :invoice-number :date [:vendor [:name :id]] [:company [:name :id]]]]]}
|
||||||
:on-success [::received-invoices :unpaid]}}))
|
:on-success [::received-invoices :unpaid]}}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
|
||||||
::reject-invoices
|
|
||||||
(fn [cofx [_]]
|
|
||||||
{:http {:method :post
|
|
||||||
:token (-> cofx :db :user)
|
|
||||||
:uri (str "/api/invoices/reject"
|
|
||||||
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
|
|
||||||
(str "?company=" company-id)))
|
|
||||||
:on-success [::received-invoices :pending]
|
|
||||||
}}))
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::submitted-new-invoice
|
::submitted-new-invoice
|
||||||
(fn [db [_ invoice]]
|
(fn [db [_ invoice]]
|
||||||
|
|||||||
@@ -6,9 +6,17 @@
|
|||||||
[auto-ap.effects :as effects]
|
[auto-ap.effects :as effects]
|
||||||
[auto-ap.entities.vendors :as entity]
|
[auto-ap.entities.vendors :as entity]
|
||||||
[auto-ap.events :as events]
|
[auto-ap.events :as events]
|
||||||
|
[auto-ap.utils :refer [by]]
|
||||||
|
|
||||||
[bidi.bidi :as bidi]))
|
[bidi.bidi :as bidi]))
|
||||||
|
|
||||||
|
(def vendor-query
|
||||||
|
[:id :name :default-expense-account
|
||||||
|
[:primary-contact [:name :phone :email :id]]
|
||||||
|
[:secondary-contact [:id :name :phone :email]]
|
||||||
|
:print-as :invoice-reminder-schedule :code
|
||||||
|
[:address [:street1 :street2 :city :state :zip]]])
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::edit
|
::edit
|
||||||
(fn [{:keys [db]} [_ vendor-id]]
|
(fn [{:keys [db]} [_ vendor-id]]
|
||||||
@@ -16,11 +24,12 @@
|
|||||||
(get (:vendors db) vendor-id))
|
(get (:vendors db) vendor-id))
|
||||||
:dispatch [::events/modal-status :auto-ap.views.pages.admin.vendors/admin-vendor {:visible? true}]}))
|
:dispatch [::events/modal-status :auto-ap.views.pages.admin.vendors/admin-vendor {:visible? true}]}))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-fx
|
||||||
::new
|
::new
|
||||||
(fn [db _]
|
(fn [{:keys [db]} _]
|
||||||
(assoc-in db [:admin :vendor]
|
{:db (assoc-in db [:admin :vendor]
|
||||||
{})))
|
{})
|
||||||
|
:dispatch [::events/modal-status :auto-ap.views.pages.admin.vendors/admin-vendor {:visible? true}]}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::save
|
::save
|
||||||
@@ -28,21 +37,16 @@
|
|||||||
(let [edited-vendor (get-in db [:admin :vendor])
|
(let [edited-vendor (get-in db [:admin :vendor])
|
||||||
fx {:db (assoc-in db [:admin :vendor :saving?] true)}]
|
fx {:db (assoc-in db [:admin :vendor :saving?] true)}]
|
||||||
(when (s/valid? ::entity/vendor edited-vendor)
|
(when (s/valid? ::entity/vendor edited-vendor)
|
||||||
(if (:id edited-vendor)
|
(assoc fx :graphql
|
||||||
(assoc fx :http {:method :put
|
{:token (-> db :user)
|
||||||
:token (:user db)
|
:query-obj {:venia/operation {:operation/type :mutation
|
||||||
:body (pr-str edited-vendor)
|
:operation/name "UpsertVendor"}
|
||||||
:headers {"Content-Type" "application/edn"}
|
|
||||||
:uri (str "/api/vendors/" (:id edited-vendor))
|
:venia/queries [{:query/data [:upsert-vendor
|
||||||
:on-success [::save-complete]
|
{:vendor edited-vendor}
|
||||||
:on-error [::save-error]})
|
vendor-query]}]}
|
||||||
(assoc fx :http {:method :post
|
:on-success [::save-complete]
|
||||||
:token (:user db)
|
:on-error [::save-error]})))))
|
||||||
:body (pr-str edited-vendor)
|
|
||||||
:headers {"Content-Type" "application/edn"}
|
|
||||||
:uri (str "/api/vendors")
|
|
||||||
:on-success [::save-complete]
|
|
||||||
:on-error [::save-error]}))))))
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::remind
|
::remind
|
||||||
@@ -69,7 +73,7 @@
|
|||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::save-complete
|
::save-complete
|
||||||
(fn [{:keys [db]} [_ vendor]]
|
(fn [{:keys [db]} [_ {vendor :upsert-vendor} ]]
|
||||||
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.vendors/admin-vendor ]
|
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.vendors/admin-vendor ]
|
||||||
:db (-> db
|
:db (-> db
|
||||||
|
|
||||||
@@ -107,15 +111,11 @@
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::mounted
|
::mounted
|
||||||
(fn [{:keys [db]} _]
|
(fn [{:keys [db]} _]
|
||||||
{:http {:method :get
|
{:graphql {:token (:user db)
|
||||||
:token (:user db)
|
:query-obj {:venia/queries [[:vendor vendor-query]]}
|
||||||
:uri "/api/vendors"
|
:on-success [::received-vendors]}}))
|
||||||
:on-success [::received-vendors]}}))
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::received-vendors
|
::received-vendors
|
||||||
(fn [db [_ vendors]]
|
(fn [db [_ vendors]]
|
||||||
(assoc db :vendors (reduce (fn [vendors vendor]
|
(assoc db :vendors (by :id (:vendor vendors )))))
|
||||||
(assoc vendors (:id vendor) vendor))
|
|
||||||
{}
|
|
||||||
vendors))))
|
|
||||||
|
|||||||
@@ -8,10 +8,11 @@
|
|||||||
[auto-ap.expense-accounts :refer [chooseable-expense-accounts]]
|
[auto-ap.expense-accounts :refer [chooseable-expense-accounts]]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[auto-ap.entities.vendors :as entity]
|
[auto-ap.entities.vendors :as entity]
|
||||||
|
[auto-ap.entities.contact :as contact]
|
||||||
[auto-ap.subs :as subs]))
|
[auto-ap.subs :as subs]))
|
||||||
|
|
||||||
(defn vendor-dialog [{:keys [vendor save-event change-event id] {:keys [name]} :vendor}]
|
(defn vendor-dialog [{:keys [vendor save-event change-event id] {:keys [name]} :vendor}]
|
||||||
|
(println (s/explain ::entity/vendor vendor) )
|
||||||
(let [companies-by-id @(re-frame/subscribe [::subs/companies-by-id])]
|
(let [companies-by-id @(re-frame/subscribe [::subs/companies-by-id])]
|
||||||
[action-modal {:id id
|
[action-modal {:id id
|
||||||
:title [:span (if (:id vendor)
|
:title [:span (if (:id vendor)
|
||||||
@@ -82,7 +83,7 @@
|
|||||||
[bind-field
|
[bind-field
|
||||||
[:input.input.is-expanded {:type "text"
|
[:input.input.is-expanded {:type "text"
|
||||||
:field [:primary-contact :name]
|
:field [:primary-contact :name]
|
||||||
:spec ::entity/primary-contact
|
:spec ::contact/name
|
||||||
:event change-event
|
:event change-event
|
||||||
:subscription vendor}]]
|
:subscription vendor}]]
|
||||||
[:span.icon.is-small.is-left
|
[:span.icon.is-small.is-left
|
||||||
@@ -94,7 +95,7 @@
|
|||||||
[bind-field
|
[bind-field
|
||||||
[:input.input {:type "email"
|
[:input.input {:type "email"
|
||||||
:field [:primary-contact :email]
|
:field [:primary-contact :email]
|
||||||
:spec ::entity/primary-email
|
:spec ::contact/email
|
||||||
:event change-event
|
:event change-event
|
||||||
:subscription vendor}]]]
|
:subscription vendor}]]]
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@
|
|||||||
[bind-field
|
[bind-field
|
||||||
[:input.input {:type "phone"
|
[:input.input {:type "phone"
|
||||||
:field [:primary-contact :phone]
|
:field [:primary-contact :phone]
|
||||||
:spec ::entity/primary-phone
|
:spec ::contact/phone
|
||||||
:event change-event
|
:event change-event
|
||||||
:subscription vendor}]]
|
:subscription vendor}]]
|
||||||
[:span.icon.is-small.is-left
|
[:span.icon.is-small.is-left
|
||||||
@@ -114,7 +115,7 @@
|
|||||||
[bind-field
|
[bind-field
|
||||||
[:input.input.is-expanded {:type "text"
|
[:input.input.is-expanded {:type "text"
|
||||||
:field [:secondary-contact :name]
|
:field [:secondary-contact :name]
|
||||||
:spec ::entity/secondary-contact
|
:spec ::contact/name
|
||||||
:event change-event
|
:event change-event
|
||||||
:subscription vendor}]]
|
:subscription vendor}]]
|
||||||
[:span.icon.is-small.is-left
|
[:span.icon.is-small.is-left
|
||||||
@@ -125,14 +126,14 @@
|
|||||||
[bind-field
|
[bind-field
|
||||||
[:input.input {:type "email"
|
[:input.input {:type "email"
|
||||||
:field [:secondary-contact :email]
|
:field [:secondary-contact :email]
|
||||||
:spec ::entity/secondary-email
|
:spec ::contact/email
|
||||||
:event change-event
|
:event change-event
|
||||||
:subscription vendor}]]]
|
:subscription vendor}]]]
|
||||||
[:div.control.has-icons-left
|
[:div.control.has-icons-left
|
||||||
[bind-field
|
[bind-field
|
||||||
[:input.input {:type "phone"
|
[:input.input {:type "phone"
|
||||||
:field [:secondary-contact :phone]
|
:field [:secondary-contact :phone]
|
||||||
:spec ::entity/secondary-phone
|
:spec ::contact/phone
|
||||||
:event change-event
|
:event change-event
|
||||||
:subscription vendor}]]
|
:subscription vendor}]]
|
||||||
[:span.icon.is-small.is-left
|
[:span.icon.is-small.is-left
|
||||||
|
|||||||
@@ -55,197 +55,6 @@
|
|||||||
(vec (concat [dom keys] rest))))
|
(vec (concat [dom keys] rest))))
|
||||||
|
|
||||||
|
|
||||||
#_(defn edit-dialog []
|
|
||||||
(let [editing-vendor (:vendor @(re-frame/subscribe [::subs/admin]))
|
|
||||||
companies-by-id @(re-frame/subscribe [::subs/companies-by-id])]
|
|
||||||
|
|
||||||
[modal {:title [:span (if (:id editing-vendor)
|
|
||||||
(str "Edit " (or (:name editing-vendor) "<vendor>"))
|
|
||||||
(str "Add " (or (:name editing-vendor) "<new vendor>")))
|
|
||||||
(when (:error editing-vendor)
|
|
||||||
[:span.icon.has-text-danger
|
|
||||||
[:i.fa.fa-exclamation-triangle]])]
|
|
||||||
:foot [:button.button.is-primary {:on-click (fn [] (re-frame/dispatch [::events/save]))
|
|
||||||
:disabled (when (not (s/valid? ::entity/vendor editing-vendor ))
|
|
||||||
"disabled")}
|
|
||||||
[:span "Save"]
|
|
||||||
(when (:saving? editing-vendor)
|
|
||||||
[:span.icon
|
|
||||||
[:i.fa.fa-spin.fa-spinner]])]
|
|
||||||
:hide-event [::events/edit nil]}
|
|
||||||
|
|
||||||
[horizontal-field
|
|
||||||
[:label.label "Name"]
|
|
||||||
[:div.control
|
|
||||||
[bind-field
|
|
||||||
[:input.input {:type "text"
|
|
||||||
:field :name
|
|
||||||
:spec ::entity/name
|
|
||||||
:event ::events/change
|
|
||||||
:subscription editing-vendor}]]]]
|
|
||||||
|
|
||||||
[horizontal-field
|
|
||||||
[:label.label "Code"]
|
|
||||||
[:div.control
|
|
||||||
|
|
||||||
[bind-field
|
|
||||||
[:input.input.is-expanded {:type "text"
|
|
||||||
:field :code
|
|
||||||
:spec ::entity/code
|
|
||||||
:event ::events/change
|
|
||||||
:subscription editing-vendor}]]
|
|
||||||
[:p.help "The vendor code is used for invoice parsing. Only one vendor at a time can use a code"]]]
|
|
||||||
|
|
||||||
[:h2.subtitle "Address"]
|
|
||||||
[address-field {:field [:address]
|
|
||||||
:event ::events/change
|
|
||||||
:subscription editing-vendor}]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[:h2.subtitle "Contact"]
|
|
||||||
[horizontal-field
|
|
||||||
[:label.label "Primary"]
|
|
||||||
[:div.control.has-icons-left
|
|
||||||
[bind-field
|
|
||||||
[:input.input.is-expanded {:type "text"
|
|
||||||
:field :primary-contact
|
|
||||||
:spec ::entity/primary-contact
|
|
||||||
:event ::events/change
|
|
||||||
:subscription editing-vendor}]]
|
|
||||||
[:span.icon.is-small.is-left
|
|
||||||
[:i.fa.fa-user]]]
|
|
||||||
|
|
||||||
[:div.control.has-icons-left
|
|
||||||
[:span.icon.is-small.is-left
|
|
||||||
[:i.fa.fa-envelope]]
|
|
||||||
[bind-field
|
|
||||||
[:input.input {:type "email"
|
|
||||||
:field :primary-email
|
|
||||||
:spec ::entity/primary-email
|
|
||||||
:event ::events/change
|
|
||||||
:subscription editing-vendor}]]]
|
|
||||||
|
|
||||||
[:div.control.has-icons-left
|
|
||||||
[bind-field
|
|
||||||
[:input.input {:type "phone"
|
|
||||||
:field :primary-phone
|
|
||||||
:spec ::entity/primary-phone
|
|
||||||
:event ::events/change
|
|
||||||
:subscription editing-vendor}]]
|
|
||||||
[:span.icon.is-small.is-left
|
|
||||||
[:i.fa.fa-phone]]]]
|
|
||||||
|
|
||||||
[horizontal-field
|
|
||||||
[:label.label "Secondary"]
|
|
||||||
[:div.control.has-icons-left
|
|
||||||
[bind-field
|
|
||||||
[:input.input.is-expanded {:type "text"
|
|
||||||
:field :secondary-contact
|
|
||||||
:spec ::entity/secondary-contact
|
|
||||||
:event ::events/change
|
|
||||||
:subscription editing-vendor}]]
|
|
||||||
[:span.icon.is-small.is-left
|
|
||||||
[:i.fa.fa-user]]]
|
|
||||||
[:div.control.has-icons-left
|
|
||||||
[:span.icon.is-small.is-left
|
|
||||||
[:i.fa.fa-envelope]]
|
|
||||||
[bind-field
|
|
||||||
[:input.input {:type "email"
|
|
||||||
:field :secondary-email
|
|
||||||
:spec ::entity/secondary-email
|
|
||||||
:event ::events/change
|
|
||||||
:subscription editing-vendor}]]]
|
|
||||||
[:div.control.has-icons-left
|
|
||||||
[bind-field
|
|
||||||
[:input.input {:type "phone"
|
|
||||||
:field :secondary-phone
|
|
||||||
:spec ::entity/secondary-phone
|
|
||||||
:event ::events/change
|
|
||||||
:subscription editing-vendor}]]
|
|
||||||
[:span.icon.is-small.is-left
|
|
||||||
[:i.fa.fa-phone]]]]
|
|
||||||
|
|
||||||
[horizontal-field
|
|
||||||
[:label.label "Invoice Reminders"]
|
|
||||||
[:div.control
|
|
||||||
[:label.radio
|
|
||||||
[bind-field
|
|
||||||
[:input {:type "radio"
|
|
||||||
:name "schedule"
|
|
||||||
:value "Weekly"
|
|
||||||
:field :invoice-reminder-schedule
|
|
||||||
:spec ::entity/invoice-reminder-schedule
|
|
||||||
:event ::events/change
|
|
||||||
:subscription editing-vendor}]]
|
|
||||||
" Send weekly"]
|
|
||||||
|
|
||||||
[:label.radio
|
|
||||||
[bind-field
|
|
||||||
[:input {:type "radio"
|
|
||||||
:name "schedule"
|
|
||||||
:value "Never"
|
|
||||||
:field :invoice-reminder-schedule
|
|
||||||
:spec ::entity/invoice-reminder-schedule
|
|
||||||
:event ::events/change
|
|
||||||
:subscription editing-vendor}]]
|
|
||||||
" Never"]]]
|
|
||||||
|
|
||||||
[:h2.subtitle "Expense Accounts"]
|
|
||||||
[horizontal-field
|
|
||||||
[:label.label "Default"]
|
|
||||||
[bind-field
|
|
||||||
[typeahead {:matches (map (fn [[k v]] [k (:name v)]) expense-accounts)
|
|
||||||
:type "typeahead"
|
|
||||||
:field [:default-expense-account]
|
|
||||||
:spec ::entity/default-expense-account
|
|
||||||
:event ::events/change
|
|
||||||
:subscription editing-vendor}]]]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#_[:h2.subtitle "Clients"]
|
|
||||||
|
|
||||||
#_[horizontal-field
|
|
||||||
nil
|
|
||||||
[:div.control@(re-frame/subscribe [::subs/exp])
|
|
||||||
[:div.select.is-expanded
|
|
||||||
[bind-field
|
|
||||||
[:select {:type "select"
|
|
||||||
:field :new-relationship-company
|
|
||||||
:event ::events/change
|
|
||||||
:subscription editing-vendor}
|
|
||||||
(for [company @(re-frame/subscribe [::subs/companies])]
|
|
||||||
[:option {:value (:id company)} (:name company)])]]]]
|
|
||||||
[:div.control
|
|
||||||
[bind-field
|
|
||||||
[:input.input {:type "text"
|
|
||||||
:field :new-relationship-account-number
|
|
||||||
:subscription editing-vendor
|
|
||||||
:event ::events/change
|
|
||||||
:placeholder "Account number"}]]]
|
|
||||||
[:div.control
|
|
||||||
[:button.button.is-primary
|
|
||||||
{:on-click (dispatch-event [::events/add-relationship])}
|
|
||||||
[:span.icon
|
|
||||||
[:i.fa.fa-plus]]]]]
|
|
||||||
#_[horizontal-field
|
|
||||||
nil
|
|
||||||
[:ul
|
|
||||||
(for [[i r] (map vector (range) (:relationships editing-vendor))]
|
|
||||||
^{:key i}
|
|
||||||
[:li
|
|
||||||
(:name (companies-by-id (js/parseInt (:company-id r)))) ": "
|
|
||||||
(:account-number r)
|
|
||||||
[:a
|
|
||||||
{:on-click (dispatch-event [::events/remove-relationship i])}
|
|
||||||
[:span.icon
|
|
||||||
[:i.fa.fa-times]]]])]]
|
|
||||||
|
|
||||||
|
|
||||||
(when (:saving? editing-vendor) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]))
|
|
||||||
|
|
||||||
(defn admin-vendors-page []
|
(defn admin-vendors-page []
|
||||||
[(with-meta
|
[(with-meta
|
||||||
(fn []
|
(fn []
|
||||||
|
|||||||
Reference in New Issue
Block a user