adding ability to choose location

This commit is contained in:
Bryce Covert
2018-07-23 13:36:02 -07:00
parent ecc5dc7d77
commit 695cd38227
6 changed files with 34 additions and 6 deletions

View File

@@ -0,0 +1 @@
-- 1532360781 DOWN add-iguanas-bank-accounts

View File

@@ -0,0 +1,2 @@
-- 1532360781 UP add-iguanas-bank-accounts
update companies set data = '{:locations ["DT" "EG" "SC" "EG" "SG" "CB" "BH"] :bank-accounts [{:number "000158443280" :id 1 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1120 BofA Exp and Main - 3280" :yodlee-account-id 16279663} {:number "" :id 2 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1122 BofA Squirrel - 5255" :yodlee-account-id 16279666} {:number "000158743279" :id 3 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1121 BofA Tax & SLO - 3279" :yodlee-account-id 16279664} {:number "" :id 4 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1123 BofA Paychecks - 5250" :yodlee-account-id 16279665} {:number "" :id 5 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1125 BofA EG Exp - 5598" :yodlee-account-id 16279667} {:number "" :id 6 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1126 BofA SC Exp - 5318" :yodlee-account-id 16279668} {:number "" :id 7 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1127 BofA SG Exp - 8407" :yodlee-account-id 16279669} {:number "" :id 8 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1124 BofA DT Exp - 8279" :yodlee-account-id 16279670} {:number "" :id 9 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1128 BofA CB Exp - 2495" :yodlee-account-id 16279671} {:number "" :id 10 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1129 BofA BH Exp - 1665" :yodlee-account-id 16279672}]}' where id = 39;

View File

@@ -253,6 +253,7 @@
:add_invoice
{:fields {:id {:type 'Int}
:invoice_number {:type 'String}
:location {:type 'String}
:date {:type 'String}
:company_id {:type 'Int}
:vendor_id {:type 'Int}

View File

@@ -11,7 +11,7 @@
(vendors/get-by-id vendor-id)
(vendors/insert {:name vendor-name :default-expense-account 0})))
(defn add-invoice [context {{:keys [total invoice_number company_id vendor_id vendor_name date] :as in} :invoice} value]
(defn add-invoice [context {{:keys [total invoice_number location company_id vendor_id vendor_name date] :as in} :invoice} value]
(let [vendor (-create-or-get-vendor vendor_id vendor_name)
_ (assert-can-see-company (:id context) company_id)
company (companies/get-by-id company_id)
@@ -27,7 +27,7 @@
)]
(invoices-expense-accounts/replace-for-invoice
(:id invoice) [{:expense-account-id (:default-expense-account vendor)
:location (first (:locations company))
:location location
:amount total}] )
(-> invoice
(->graphql))))

View File

@@ -75,10 +75,9 @@
(re-frame/reg-event-db
::change-form
(fn [db [_ location field value]]
(println location field value)
(if value
(assoc-in db (into location field) value)
(update-in db location dissoc field))))
(update-in db (into location (butlast field)) dissoc (last field)))))
(re-frame/reg-event-db
::modal-status

View File

@@ -239,6 +239,7 @@
[:company [:id :name :locations]]
[:vendor [:id :name]]
[:expense_accounts [:amount :id :expense_account_id
:location
[:expense_account [:id :name [:parent [:id :name]]]]]]
]]}]}
:on-success [::invoice-created]}})))
@@ -519,15 +520,28 @@
#_#_:spec ::check/date
:subscription handwrite-checks}]]]]))
(re-frame/reg-event-fx
::change-new-invoice-company
(fn [{:keys [db ]} [_ location field value]]
(let [first-location (-> @(re-frame/subscribe [::subs/companies-by-id])
(get-in [value :locations])
first)]
{:dispatch [::events/change-form location field value]
:db (-> db
(assoc-in [::new-invoice :location] first-location))})))
(defn new-invoice-modal []
(let [data @(re-frame/subscribe [::new-invoice])
change-event [::events/change-form [::new-invoice]]]
change-event [::events/change-form [::new-invoice]]
locations (get-in @(re-frame/subscribe [::subs/companies-by-id]) [(:company-id data) :locations])
should-select-location? (and locations
(> (count locations) 1))]
[action-modal {:id ::new-invoice
:title "New Invoice"
:action-text "Create"
:save-event [::create-invoice]
:can-submit? (s/valid? ::invoice/invoice data)}
(when-not @(re-frame/subscribe [::subs/company])
[horizontal-field
[:label.label "Company"]
@@ -535,9 +549,20 @@
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/companies]))
:type "typeahead"
:field [:company-id]
:event change-event
:event [::change-new-invoice-company [::new-invoice]]
:spec ::invoice/company-id
:subscription data}]]])
(when should-select-location?
[horizontal-field
[:label.label "Location"]
[:div.select
[bind-field
[:select {:type "select"
:field [:location]
:spec (set locations)
:event change-event
:subscription data}
(map (fn [l] [:option {:value l} l]) locations)]]]])
[horizontal-field
[:label.label "Vendor"]