outstanding balance and addresses.

This commit is contained in:
Bryce Covert
2018-05-17 19:37:50 -07:00
parent 7b7275f7a4
commit e055a1e120
19 changed files with 351 additions and 98 deletions

View File

@@ -5,6 +5,7 @@
[auto-ap.subs :as subs]
[auto-ap.events.admin.companies :as events]
[auto-ap.entities.companies :as entity]
[auto-ap.entities.address :as address]
[auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field]]
[cljs.reader :as edn]
[auto-ap.routes :as routes]
@@ -66,6 +67,61 @@
:event ::events/change
:subscription editing-company}]]]]
[:h2.subtitle "Address"]
[horizontal-field
nil
[:div.control
[:p.help "Address"]
[bind-field
[:input.input.is-expanded {:type "text"
:placeholder "1700 Pennsylvania Ave"
:field [:address :street1]
:spec ::address/street1
:event ::events/change
:subscription editing-company}]]]]
[horizontal-field
nil
[:div.control
[bind-field
[:input.input.is-expanded {:type "text"
:placeholder "Suite 400"
:field [:address :street2]
:spec ::address/street2
:event ::events/change
:subscription editing-company}]]]]
[horizontal-field
nil
[:div.control
[:p.help "City"]
[bind-field
[:input.input.is-expanded {:type "text"
:placeholder "Cupertino"
:field [:address :city]
:spec ::address/city
:event ::events/change
:subscription editing-company}]]]
[:div.control
[:p.help "State"]
[bind-field
[:input.input {:type "text"
:placeholder "CA"
:field [:address :state]
:spec ::address/state
:event ::events/change
:subscription editing-company}]]]
[:div.control
[:p.help "Zip"]
[bind-field
[:input.input {:type "text"
:field [:address :zip]
:spec ::address/zip
:event ::events/change
:subscription editing-company
:placeholder "95014"}]]]]
[horizontal-field
[:label.label "Bank Accounts"]
[:div.control

View File

@@ -1,34 +1,67 @@
(ns auto-ap.views.pages.paid-invoices
(:require [re-frame.core :as re-frame]
[auto-ap.subs :as subs]
[auto-ap.events :as events]))
[auto-ap.entities.companies :as company]
[auto-ap.entities.vendors :as vendor]
[auto-ap.events :as events]
[auto-ap.views.utils :refer [dispatch-event]]
[auto-ap.utils :refer [by]]
[auto-ap.views.pages.check :as check]
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
[auto-ap.subs :as subs]))
(re-frame/reg-sub
::invoice-page
(fn [db]
(-> db ::invoice-page)))
(re-frame/reg-sub
::params
(fn [db]
(-> db (::params {}))))
(re-frame/reg-event-fx
::params-change
(fn [cofx [_ params]]
(println "HERE")
{:db (-> (:db cofx)
(assoc-in [:status :loading] true)
(assoc-in [::params] params))
:graphql {:token (-> cofx :db :user)
:query-obj (invoice-table/query (assoc params :imported true :status "paid"))
:on-success [::received]}}))
(re-frame/reg-event-db
::received
(fn [db [_ data]]
(-> db
(assoc ::invoice-page (first (:invoice-page data)))
(assoc-in [:status :loading] false))))
(re-frame/reg-event-fx
::invalidated
(fn [cofx [_ params]]
{:dispatch [::params-change @(re-frame/subscribe [::params])]}))
(def paid-invoices-page
(with-meta
(fn []
(let [invoices (re-frame/subscribe [::subs/unpaid-invoices])
status (re-frame/subscribe [::subs/status])]
[:div
(let [current-company @(re-frame/subscribe [::subs/company])]
[:div
[:h1.title "Paid invoices"]
(if (:loading @status)
[:div
[:h1.title
[:i.fa.fa-spin.fa-spinner]]]
[:table {:class "table", :style {:width "100%"}}
[:thead
[:tr
[:th "Vendor"]
[:th "Customer"]
[:th "Invoice #"]
[:th "Date"]
[:th "Amount"]]]
[:tbody (for [{:keys [company invoice-number date total id vendor] :as i} @invoices]
^{:key (str company "-" invoice-number "-" date "-" total "-" id)}
[:tr
[:td (:name vendor)]
[:td (:name company)]
[:td invoice-number]
[:td date]
[:td total]])]])]))
{:component-will-mount #(re-frame/dispatch-sync [::events/view-unpaid-invoices]) }))
[invoice-table {:id :paid
:params (re-frame/subscribe [::params])
:invoice-page (re-frame/subscribe [::invoice-page])
:status (re-frame/subscribe [::subs/status])
:on-params-change (fn [params]
(re-frame/dispatch [::params-change params]))
:check-boxes false}]]))
{:component-will-mount #(do (println "HERE2") (re-frame/dispatch-sync [::params-change {}])) }))

View File

@@ -57,7 +57,9 @@
(fn [{:keys [db]} [_ bank-account-id]]
(let [invoice-amounts (by :id :total (get-in db [::invoice-page :invoices]))]
{
:db (assoc-in db [::invoice-page :print-checks-shown?] false )
:db (-> db
(assoc-in [::invoice-page :print-checks-shown?] false )
(assoc-in [::invoice-page :print-checks-loading?] true ))
:graphql
{:token (-> db :user)
@@ -71,7 +73,7 @@
(get-in db [::invoice-page :checked]))
:bank_account_id bank-account-id
:company_id (:company db)}
[[:invoices [:id [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]
[[:invoices [:id :outstanding-balance [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]
:pdf_url]]]}
:on-success [::checks-created]}})))
@@ -88,7 +90,8 @@
(map (fn [i]
(merge i (invoices-by-id (:id i))))
invoices)))
(assoc-in [::invoice-page :checked] nil))})))
(assoc-in [::invoice-page :checked] nil)
(assoc-in [::invoice-page :print-checks-loading?] false))})))
(re-frame/reg-event-fx
::invalidated
@@ -98,7 +101,7 @@
(def unpaid-invoices-page
(with-meta
(fn []
(let [{:keys [checked print-checks-shown?]} @(re-frame/subscribe [::invoice-page])
(let [{:keys [checked print-checks-shown? print-checks-loading?]} @(re-frame/subscribe [::invoice-page])
current-company @(re-frame/subscribe [::subs/company])]
[:div
[:h1.title "Unpaid invoices"]
@@ -108,12 +111,17 @@
"is-active"
"")}
[:div.dropdown-trigger
[:button.button {:aria-haspopup true
:on-click (dispatch-event [::print-checks-clicked ])
:disabled (if (seq checked)
""
"disabled")
} "Print checks "
[:button.button.is-success {:aria-haspopup true
:on-click (dispatch-event [::print-checks-clicked ])
:disabled (if (seq checked)
""
"disabled")
:class (if print-checks-loading?
"is-loading"
"")
}
"Print checks "
[:span.icon.is-small [:i.fa.fa-angle-down {:aria-hidden "true"}]]]]
[:div.dropdown-menu {:role "menu"}
[:div.dropdown-content