Merge branch 'master' of bitbucket.org:brycecovertoperations/integreat
This commit is contained in:
@@ -19,7 +19,9 @@
|
||||
(-> x
|
||||
(assoc-in [:data :bank-accounts] (:bank-accounts x))
|
||||
(assoc-in [:data :address] (:address x))
|
||||
(assoc-in [:data :locations] (:locations x))
|
||||
(dissoc :bank-accounts)
|
||||
(dissoc :locations)
|
||||
(dissoc :address)))
|
||||
|
||||
(defn get-all []
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
{:fields {:id {:type 'Int}
|
||||
:name {:type 'String}
|
||||
:email {:type 'String}
|
||||
:locations {:type '(list String)}
|
||||
:bank_accounts {:type '(list :bank_account)}}}
|
||||
|
||||
:bank_account
|
||||
@@ -106,6 +107,7 @@
|
||||
{:fields {:id {:type 'Int}
|
||||
:invoice_id {:type 'Int}
|
||||
:expense_account_id {:type 'Int}
|
||||
:location {:type 'String}
|
||||
:expense_account {:type :expense_account
|
||||
:resolve :get-expense-account}
|
||||
:amount {:type 'String}}}
|
||||
@@ -212,6 +214,7 @@
|
||||
:edit_expense_account
|
||||
{:fields {:id {:type 'Int}
|
||||
:expense_account_id {:type 'Int}
|
||||
:location {:type 'String}
|
||||
:amount {:type 'String}}}
|
||||
|
||||
:add_invoice
|
||||
|
||||
@@ -34,9 +34,10 @@
|
||||
(invoices-expense-accounts/get-for-invoice (:id value))))
|
||||
|
||||
(defn edit-expense-accounts [context args value]
|
||||
(invoices-expense-accounts/replace-for-invoice (:invoice_id args) (map (fn [{:keys [id expense_account_id amount]}]
|
||||
(invoices-expense-accounts/replace-for-invoice (:invoice_id args) (map (fn [{:keys [id expense_account_id amount location]}]
|
||||
{
|
||||
:expense-account-id expense_account_id
|
||||
:location location
|
||||
:amount (Double/parseDouble amount)} )
|
||||
(:expense_accounts args)))
|
||||
(->graphql
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
(s/def ::name ::shared/required-identifier)
|
||||
(s/def ::address ::address/address)
|
||||
|
||||
(s/def ::location string?)
|
||||
(s/def ::locations (s/coll-of ::location))
|
||||
|
||||
(s/def ::email (s/nilable (s/and string? (s/or :is-email #(re-matches email-regex %)
|
||||
:is-empty #(= % "")))))
|
||||
|
||||
@@ -17,6 +20,7 @@
|
||||
(s/def ::company (s/keys :req-un [::name]
|
||||
:opt-un [::email
|
||||
::address
|
||||
::locations
|
||||
::id]))
|
||||
|
||||
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
(s/def ::vendor-id int?)
|
||||
(s/def ::expense-account-id int?)
|
||||
(s/def ::amount ::shared/money)
|
||||
(s/def ::location string?)
|
||||
|
||||
(s/def ::invoices-expense-account (s/keys :opt-un [::vendor-id ::expense-account-id ::amount]))
|
||||
(s/def ::invoices-expense-account (s/keys :opt-un [::vendor-id ::expense-account-id ::amount ::location]))
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
:user token)
|
||||
:graphql {:token token
|
||||
:query-obj {:venia/queries [[:company
|
||||
[:id :name [:bank-accounts [:id :number :check-number :name]]]]
|
||||
|
||||
[:id :name :locations [:bank-accounts [:id :number :check-number :name] ]]]
|
||||
[:vendor
|
||||
[:id :name :default-expense-account]]]}
|
||||
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
(ns auto-ap.events.admin.companies
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[auto-ap.db :as db]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.routes :as routes]
|
||||
[auto-ap.effects :as effects]
|
||||
[auto-ap.entities.companies :as entity]
|
||||
[bidi.bidi :as bidi]))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
(re-frame/reg-event-fx
|
||||
::edit
|
||||
(fn [db [_ company-id]]
|
||||
(assoc-in db [:admin :company]
|
||||
(get (:companies db) company-id))))
|
||||
(fn [{:keys [db]} [_ company-id]]
|
||||
{:dispatch [::events/modal-status :auto-ap.views.pages.admin.companies/edit {:visible? true}]
|
||||
:db (assoc-in db [:admin :company]
|
||||
(get (:companies db) company-id))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::save
|
||||
(fn [{:keys [db]} _]
|
||||
(let [edited-company (get-in db [:admin :company])]
|
||||
(let [edited-company (-> (get-in db [:admin :company])
|
||||
(dissoc :location))]
|
||||
|
||||
{:db (assoc-in db [:admin :company :saving?] true)
|
||||
:http {:method :put
|
||||
:token (:user db)
|
||||
@@ -25,13 +29,14 @@
|
||||
:on-success [::save-complete]
|
||||
:on-error [::save-error]}})))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
(re-frame/reg-event-fx
|
||||
::save-complete
|
||||
(fn [db [_ company]]
|
||||
(-> db
|
||||
|
||||
(assoc-in [:admin :company] nil)
|
||||
(assoc-in [:companies (:id company)] company))))
|
||||
(fn [{:keys [db]} [_ company]]
|
||||
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.companies/edit]
|
||||
:db (-> db
|
||||
|
||||
(assoc-in [:admin :company] nil)
|
||||
(assoc-in [:companies (:id company)] company))}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::save-error
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
:company-id (:id @(re-frame/subscribe [::subs/company])))
|
||||
[[:invoices [:id :total :outstanding-balance :invoice-number :date
|
||||
[:vendor [:name :id]]
|
||||
[:expense_accounts [:amount :id :expense_account_id
|
||||
[:expense_accounts [:amount :id :expense_account_id :location
|
||||
[:expense_account [:id :name [:parent [:id :name]]]]]]
|
||||
[:company [:name :id]]
|
||||
[:company [:name :id :locations]]
|
||||
[:checks [:amount [:check [:amount :s3_url :check_number ]]]]
|
||||
]]
|
||||
:total
|
||||
@@ -76,6 +76,12 @@
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
"Date"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "location"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
"Location"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "total"
|
||||
@@ -116,6 +122,7 @@
|
||||
[:td (:name company)]
|
||||
[:td invoice-number]
|
||||
[:td (date->str date) ]
|
||||
[:td (str/join ", " (set (map :location expense-accounts)))]
|
||||
|
||||
[:td (gstring/format "$%.2f" total )]
|
||||
[:td (gstring/format "$%.2f" outstanding-balance )]
|
||||
|
||||
@@ -6,11 +6,20 @@
|
||||
[auto-ap.events.admin.companies :as events]
|
||||
[auto-ap.entities.companies :as entity]
|
||||
[auto-ap.views.components.address :refer [address-field]]
|
||||
[auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field]]
|
||||
[auto-ap.views.components.modal :refer [modal]]
|
||||
[auto-ap.views.utils :refer [login-url dispatch-event dispatch-value-change bind-field horizontal-field]]
|
||||
[auto-ap.views.components.modal :refer [action-modal]]
|
||||
[cljs.reader :as edn]
|
||||
[auto-ap.routes :as routes]
|
||||
[bidi.bidi :as bidi]))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::add-location
|
||||
(fn [{:keys [db]} _]
|
||||
(let [company (:company @(re-frame/subscribe [::subs/admin]))]
|
||||
{:db (-> db
|
||||
(update-in [:admin :company :locations] conj (:location company))
|
||||
(update-in [:admin :company] dissoc :location))})))
|
||||
|
||||
(defn companies-table []
|
||||
(let [companies (re-frame/subscribe [::subs/companies])
|
||||
editing-company (:company @(re-frame/subscribe [::subs/admin]))]
|
||||
@@ -35,46 +44,57 @@
|
||||
[:h1.title "Companies"]
|
||||
[companies-table]
|
||||
|
||||
(when editing-company
|
||||
[modal {:title (str "Edit " (:name editing-company))
|
||||
:foot [:a.button.is-primary {:on-click (fn [] (re-frame/dispatch [::events/save]))}
|
||||
[:span "Save"]
|
||||
(when (:saving? editing-company)
|
||||
[:span.icon
|
||||
[:i.fa.fa-spin.fa-spinner]])]
|
||||
:hide-event [::events/edit nil]}
|
||||
[horizontal-field
|
||||
[:label.label "Name"]
|
||||
[:div.control
|
||||
[action-modal {:id ::edit
|
||||
:title (str "Edit " (:name editing-company))
|
||||
:action-text "Save"
|
||||
:save-event [::events/save]}
|
||||
[horizontal-field
|
||||
[:label.label "Name"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field :name
|
||||
:spec ::entity/name
|
||||
:event ::events/change
|
||||
:subscription editing-company}]]]]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Email"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input {:type "email"
|
||||
:field :email
|
||||
:spec ::entity/name
|
||||
:event ::events/change
|
||||
:subscription editing-company}]]]]
|
||||
|
||||
[:h2.subtitle "Address"]
|
||||
|
||||
[address-field {:field [:address]
|
||||
:event ::events/change
|
||||
:subscription editing-company}]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Bank Accounts"]
|
||||
[:div.control
|
||||
[:ul
|
||||
(for [{:keys [number check-number id]} (:bank-accounts editing-company)]
|
||||
^{:key id} [:li number " - " check-number])]]]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Locations"]
|
||||
[:div.control
|
||||
[:div.field.has-addons
|
||||
[:p.control
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field :name
|
||||
:spec ::entity/name
|
||||
:field :location
|
||||
:event ::events/change
|
||||
:subscription editing-company}]]]]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Email"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input {:type "email"
|
||||
:field :email
|
||||
:spec ::entity/name
|
||||
:event ::events/change
|
||||
:subscription editing-company}]]]]
|
||||
|
||||
[:h2.subtitle "Address"]
|
||||
|
||||
[address-field {:field [:address]
|
||||
:event ::events/change
|
||||
:subscription editing-company}]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Bank Accounts"]
|
||||
[:div.control
|
||||
[:ul
|
||||
(for [{:keys [number check-number id]} (:bank-accounts editing-company)]
|
||||
^{:key id} [:li number " - " check-number])]]]
|
||||
|
||||
|
||||
(when (:saving? editing-company) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])])])])
|
||||
:subscription editing-company}]]]
|
||||
[:p.control [:button.button.is-primary {:on-click (dispatch-event [::add-location])} "Add"]]]
|
||||
[:ul
|
||||
(for [location (:locations editing-company)]
|
||||
^{:key location} [:li location ])]]]
|
||||
|
||||
|
||||
(when (:saving? editing-company) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]])])
|
||||
|
||||
@@ -251,13 +251,14 @@
|
||||
{:invoice-id id
|
||||
:expense-accounts (map (fn [ea] {:id (:id ea)
|
||||
:amount (:amount ea)
|
||||
:location (:location ea)
|
||||
:expense-account-id (:expense-account-id ea)})
|
||||
expense-accounts)}
|
||||
[:id :total :outstanding-balance :invoice-number :date
|
||||
[:vendor [:name :id]]
|
||||
[:expense_accounts [:amount :id :expense_account_id
|
||||
[:expense_accounts [:amount :id :location :expense_account_id
|
||||
[:expense_account [:id :name [:parent [:id :name]]]]]]
|
||||
[:company [:name :id]]
|
||||
[:company [:name :id :locations]]
|
||||
[:checks [:amount [:check [:amount :s3_url :check_number ]]]]
|
||||
]]}]}
|
||||
:on-success [::expense-accounts-updated]}})))
|
||||
@@ -291,7 +292,8 @@
|
||||
(drop (inc index) expense-accounts))))))
|
||||
|
||||
(defn change-expense-accounts-modal []
|
||||
(let [{{:keys [expense-accounts total] :or {expense-accounts [] total 0}} :invoice :as data} @(re-frame/subscribe [::change-expense-accounts])
|
||||
(let [{{:keys [expense-accounts total ] :or {expense-accounts [] total 0} {:keys [locations]} :company} :invoice :as data} @(re-frame/subscribe [::change-expense-accounts])
|
||||
should-select-location? (> (count locations) 1)
|
||||
change-event [::events/change-form [::change-expense-accounts]]
|
||||
expense-accounts-total (->> expense-accounts
|
||||
(map :amount)
|
||||
@@ -312,6 +314,8 @@
|
||||
[:thead
|
||||
[:tr
|
||||
[:th {:style {:width "500px"}} "Expense Account"]
|
||||
(when should-select-location?
|
||||
[:th {:style {:width "500px"}} "Location"])
|
||||
[:th {:style {:width "300px"}} "Amount"]
|
||||
[:th {:style {:width "5em"}}]]]
|
||||
[:tbody
|
||||
@@ -326,6 +330,17 @@
|
||||
:spec ::invoice/vendor-id
|
||||
:subscription data}]]]]
|
||||
|
||||
(when should-select-location?
|
||||
[:td
|
||||
[:div.select
|
||||
[bind-field
|
||||
[:select {:type "select"
|
||||
:field [:invoice :expense-accounts index :location]
|
||||
:spec (set locations)
|
||||
:event change-event
|
||||
:subscription data}
|
||||
(map (fn [l] [:option {:value l} l]) locations)]]]
|
||||
])
|
||||
|
||||
[:td
|
||||
[:div.control
|
||||
|
||||
Reference in New Issue
Block a user