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

@@ -9,9 +9,7 @@
[cljs-time.format :as format]
[goog.string :as gstring]))
;; TODO show busy
;; TODO partial payments
;; TODO invoice status = paid when complete
;; TODO performance
;; TODO refactor graphql
@@ -21,7 +19,7 @@
{:venia/queries [[:invoice_page
(assoc params
:company-id (:id @(re-frame/subscribe [::subs/company])))
[[:invoices [:id :total :invoice-number :date [:vendor [:name :id]] [:company [:name :id]] [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]
[[:invoices [:id :total :outstanding-balance :invoice-number :date [:vendor [:name :id]] [:company [:name :id]] [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]
:total
:start
:end]]]})
@@ -46,44 +44,50 @@
[:thead
[:tr
(when check-boxes
[:th])
[:th {:style {"width" "20px"}}])
[sorted-column {:on-sort opc
:style {:width "23%" :cursor "pointer"}
:style {:width "33%" :cursor "pointer"}
:sort-key "vendor"
:sort-by sort-by
:asc asc}
"Vendor"]
[sorted-column {:on-sort opc
:style {:width "23%" :cursor "pointer"}
:style {:width "33%" :cursor "pointer"}
:sort-key "company"
:sort-by sort-by
:asc asc}
"Company"]
[sorted-column {:on-sort opc
:style {:width "16%" :cursor "pointer"}
:style {:width "33%" :cursor "pointer"}
:sort-key "invoice-number"
:sort-by sort-by
:asc asc}
"Invoice #"]
[sorted-column {:on-sort opc
:style {:width "14%" :cursor "pointer"}
:style {:width "8em" :cursor "pointer"}
:sort-key "date"
:sort-by sort-by
:asc asc}
"Date"]
[sorted-column {:on-sort opc
:style {:width "14%" :cursor "pointer"}
:style {:width "8em" :cursor "pointer"}
:sort-key "total"
:sort-by sort-by
:asc asc}
"Amount"]
[:th {:style {:width "10%"}} "" ]]]
[sorted-column {:on-sort opc
:style {:width "10em" :cursor "pointer"}
:sort-key "outstanding"
:sort-by sort-by
:asc asc}
"Outstanding"]
[:th {:style {:width "10em"}} "" ]]]
[:tbody
(if (:loading @status)
[:tr
[:td {:col-span 5}
[:i.fa.fa-spin.fa-spinner]]]
(for [{:keys [company checks invoice-number date total id vendor] :as i} (:invoices @invoice-page)]
(for [{:keys [company checks invoice-number date total outstanding-balance id vendor] :as i} (:invoices @invoice-page)]
^{:key id}
[:tr
(when check-boxes
@@ -99,6 +103,7 @@
[:td (date->str date) ]
[:td (gstring/format "$%.2f" total )]
[:td (gstring/format "$%.2f" outstanding-balance )]
[:td (for [check checks]
^{:key (:id check)}
[:a.tag {:href (:s3-url (:check check)) :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " (:check-number (:check check)) " (" (gstring/format "$%.2f" (:amount check) ) ")")])]]))]]]))))

View File

@@ -50,12 +50,11 @@
(defmethod active-page :admin-excel-import []
[admin-excel-import-page])
(defmethod active-page :unpaid-invoices []
[unpaid-invoices-page])
(defmethod active-page :paid-invoices []
paid-invoices-page)
[paid-invoices-page])
(defmethod active-page :invoices []
[(with-meta

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

View File

@@ -38,32 +38,35 @@
type))
(defmethod do-bind "select" [dom {:keys [field subscription event class value spec] :as keys} & rest]
(let [keys (assoc keys
:on-change (dispatch-value-change [event [field]])
(let [field (if (keyword? field) [field] field)
keys (assoc keys
:on-change (dispatch-value-change [event field])
:class (str class
(when (and spec (not (s/valid? spec (field subscription))))
(when (and spec (not (s/valid? spec (get-in subscription field))))
" is-danger")))
keys (dissoc keys :field :subscription :event :spec)]
(vec (concat [dom keys] rest))))
(defmethod do-bind "radio" [dom {:keys [field subscription event class value spec] :as keys} & rest]
(let [keys (assoc keys
:on-change (dispatch-value-change [event [field]])
:checked (= (field subscription) value)
(let [field (if (keyword? field) [field] field)
keys (assoc keys
:on-change (dispatch-value-change [event field])
:checked (= (get-in subscription field) value)
:class (str class
(when (and spec (not (s/valid? spec (field subscription))))
(when (and spec (not (s/valid? spec (get-in subscription field ))))
" is-danger")))
keys (dissoc keys :field :subscription :event :spec)]
(vec (concat [dom keys] rest))))
(defmethod do-bind :default [dom {:keys [field event subscription class spec] :as keys} & rest]
(let [keys (assoc keys
:on-change (dispatch-value-change [event [field]])
:value (field subscription)
(let [field (if (keyword? field) [field] field)
keys (assoc keys
:on-change (dispatch-value-change [event field])
:value (get-in subscription field)
:class (str class
(when (and spec (not (s/valid? spec (field subscription))))
(when (and spec (not (s/valid? spec (get-in subscription field))))
" is-danger")))
keys (dissoc keys :field :subscription :event :spec)]
(vec (concat [dom keys] rest))))