you can check off individual invoices

This commit is contained in:
Bryce Covert
2018-05-10 21:30:50 -07:00
parent 5fb5b2d412
commit 7d5ae173f3
3 changed files with 176 additions and 161 deletions

View File

@@ -13,9 +13,38 @@
(wrap-routes (wrap-routes
(context "/checks" [] (context "/checks" []
(POST "/" {:keys [edn-params]} (POST "/" {:keys [edn-params]}
(invoices/get-multi (:invoice-ids edn-params)) (let [invoices (invoices/get-multi (:invoice-ids edn-params))
companies (into {}
(map (fn [c] [(:id c) c])
(companies/get-all)))
vendors (into {}
(map (fn [v] [(:id v) v])
(vendors/get-all)))
invoices-grouped-by-vendor (group-by :vendor-id invoices)]
{:status 200 {:status 200
:body (pr-str (invoices/get-multi (:invoice-ids edn-params))) :body (pr-str (for [[vendor-id invoices] invoices-grouped-by-vendor
:headers {"Content-Type" "application/edn"}})) :let [vendor (vendors vendor-id)
company (companies (:company-id (first invoices)))
memo (str "Invoice #'s: "
(str/join ", "
(map (fn [i]
(str (:invoice-number i) "(" (:total i) ")"))
invoices)
))]]
{:vendor-name (:name vendor)
:paid-to (:name company)
:amount (reduce + 0 (map :total invoices))
:check "1234"
:memo memo
:date "5/10/2018"
:company {:name (:name company)
:address1 "123 main st"
:city "Campbell"
:state "CA"
:zip "95008"
:bank {:name "Bank of America, NA"
:acct "11-35/2010"
:acct-number "123456789"}}}))
:headers {"Content-Type" "application/edn"}})))
wrap-secure)) wrap-secure))

View File

@@ -10,38 +10,16 @@
[bidi.bidi :as bidi] [bidi.bidi :as bidi]
[goog.string :as gstring])) [goog.string :as gstring]))
(defn check-page [] (re-frame/reg-sub
[:div ::checks
(for [{:keys [vendor-name paid-to company check date amount memo]} (fn [db]
[{:vendor-name "Covert Affairs, INC" (-> db ::checks)))
:paid-to "Covert Affairs, INC"
:amount 1234.56 (defn check-page []
:check "1234" (let [checks @(re-frame/subscribe [::checks])]
:memo "Invoice #'s: 870034 ($400.34), 77335 ($732.55), 76668 ($101.67)" [:div
:date "5/10/2018" (for [{:keys [vendor-name paid-to company check date amount memo]} checks
:company {:name "Campbell Brewing Company LLC"
:address1 "200 E Campbell Ave"
:city "Campbell"
:state "CA"
:zip "95008"
:bank {:name "Bank of America, NA"
:acct "11-35/2010"
:acct-number "123456789"}}}
{:vendor-name "Good meat, INC"
:paid-to "Good meat, INC"
:amount 973.45
:check "1235"
:memo "Invoice #'s: 070034 ($400.34), 77335 ($732.55), 76668 ($101.67)"
:date "5/10/2018"
:company {:name "Campbell Brewing Company LLC"
:address1 "200 E Campbell Ave"
:city "Campbell"
:state "CA"
:zip "95008"
:bank {:name "Bank of America, NA"
:acct "11-35/2010"
:acct-number "123456789"}}}]
:let [amount (gstring/format "--%.2f--" amount)]] :let [amount (gstring/format "--%.2f--" amount)]]
[:div [:div
@@ -184,4 +162,4 @@
[:div.column "MEMO"] [:div.column "MEMO"]
[:div.column.is-11 [:div.column.is-11
memo]] memo]]
[:footer]])]) [:footer]])]))

View File

@@ -4,6 +4,7 @@
[auto-ap.entities.vendors :as vendor] [auto-ap.entities.vendors :as vendor]
[auto-ap.events :as events] [auto-ap.events :as events]
[auto-ap.views.utils :refer [dispatch-event]] [auto-ap.views.utils :refer [dispatch-event]]
[auto-ap.views.pages.check :as check]
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table] [auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.events :as events])) [auto-ap.events :as events]))
@@ -54,9 +55,16 @@
:body (pr-str {:invoice-ids (get-in db [::invoice-page :checked])}) :body (pr-str {:invoice-ids (get-in db [::invoice-page :checked])})
:headers {"Content-Type" "application/edn"} :headers {"Content-Type" "application/edn"}
:uri (str "/api/checks/") :uri (str "/api/checks/")
:on-success [::save-complete] :on-success [::checks-created]
:on-error [::save-error]}})) :on-error [::save-error]}}))
(re-frame/reg-event-fx
::checks-created
(fn [{:keys [db]} [_ data]]
{:dispatch [:auto-ap.events/set-active-page :check]
:db (-> db
(assoc ::check/checks data))}))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::invalidated ::invalidated
(fn [cofx [_ params]] (fn [cofx [_ params]]