you can choose a bank account to print.

This commit is contained in:
Bryce Covert
2018-05-14 10:15:01 -07:00
parent c2a5808d0c
commit 7a918e06fe
3 changed files with 43 additions and 23 deletions

View File

@@ -114,7 +114,9 @@
:mutations
{:print_checks {:type :check_result
:args {:invoice_ids {:type '(list Int)}}
:args {:invoice_ids {:type '(list Int)}
:bank_account_id {:type 'Int}
:company_id {:type 'Int}}
:resolve :mutation/print-checks}}})
(defn by [x kf]
@@ -223,8 +225,9 @@
(defn print-checks [context args value]
(->graphql
(rchecks/print-checks (:invoice_ids args))))
(rchecks/print-checks (:invoice_ids args)
(:company_id args)
(:bank_account_id args))))
(def schema
(-> integreat-schema

View File

@@ -151,10 +151,10 @@
:content-type "application/pdf"})
(str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/merged-checks/" uuid ".pdf")))
(defn check-for-invoices [invoices vendor-id vendors companies]
(defn check-for-invoices [invoices vendor-id vendors company bank-account-id]
(let [uuid (str (UUID/randomUUID))
vendor (vendors vendor-id)
company (companies (:company-id (first invoices)))
bank-account (first (filter #(= (:id %) bank-account-id) (:bank-accounts company)))
memo (str "Invoice #'s: "
(str/join ", "
(map (fn [i]
@@ -171,7 +171,7 @@
:pdf-data {:vendor vendor
:paid-to (:name vendor)
:amount (reduce + 0 (map :total invoices))
:check "1234"
:check (str (inc (:check-number bank-account)))
:memo memo
:date "5/10/2018"
:company {:name (:name company)
@@ -181,21 +181,19 @@
:zip "95008"
:bank {:name "Bank of America, NA"
:acct "11-35/2010"
:acct-number "123456789"}}}
:acct-number (:number bank-account)}}}
:invoices (map :id invoices)}))
(defn print-checks [invoice-ids]
(defn print-checks [invoice-ids company-id bank-account-id]
(let [invoices (invoices/get-multi invoice-ids)
companies (into {}
(map (fn [c] [(:id c) c])
(companies/get-all)))
company (companies/get-by-id company-id)
vendors (into {}
(map (fn [v] [(:id v) v])
(vendors/get-all)))
invoices-grouped-by-vendor (group-by :vendor-id invoices)
checks (-> (for [[vendor-id invoices] invoices-grouped-by-vendor]
[invoices (checks/insert! (check-for-invoices invoices vendor-id vendors companies))])
[invoices (checks/insert! (check-for-invoices invoices vendor-id vendors company bank-account-id))])
doall)
invoice-checks (invoices-checks/insert-multi!
(mapcat

View File

@@ -46,18 +46,27 @@
(disj x data)
(conj x data)))))))
(re-frame/reg-event-db
::print-checks-clicked
(fn [db _]
(update-in db [::invoice-page :print-checks-shown?] #(not %) )))
(re-frame/reg-event-fx
::print-checks
(fn [{:keys [db]} [_ data]]
{:graphql
(fn [{:keys [db]} [_ bank-account-id]]
{
:db (assoc-in db [::invoice-page :print-checks-shown?] false )
:graphql
{:token (-> db :user)
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "PrintChecks"}
:venia/queries [[:print-checks
{:invoice_ids (vec (get-in db [::invoice-page :checked]))}
[[:invoices [:id [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]
]
{:invoice_ids (vec (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 ]]]]]]
:pdf_url]]]}
:on-success [::checks-created]}}))
@@ -88,17 +97,27 @@
(def unpaid-invoices-page
(with-meta
(fn []
(let [checked (:checked @(re-frame/subscribe [::invoice-page]))
(let [{:keys [checked print-checks-shown?]} @(re-frame/subscribe [::invoice-page])
current-company @(re-frame/subscribe [::subs/company])]
[:div
[:h1.title "Unpaid invoices"]
[:div.is-pulled-right
(when current-company
[:button.button.is-primary {:on-click (dispatch-event [::print-checks ])
:disabled (if (seq checked)
""
"disabled")
} "Print check(s)"])]
[:div.dropdown {:class (if print-checks-shown?
"is-active"
"")}
[:div.dropdown-trigger
[:button.button {:aria-haspopup true
:on-click (dispatch-event [::print-checks-clicked ])
:disabled (if (seq checked)
""
"disabled")
} "Print checks "
[:span.icon.is-small [:i.fa.fa-angle-down {:aria-hidden "true"}]]]]
[:div.dropdown-menu {:role "menu"}
[:div.dropdown-content
(for [{:keys [id number]} (:bank-accounts current-company)]
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id])} number])]]])]
[invoice-table {:id :unpaid
:params (re-frame/subscribe [::params])