you can choose a bank account to print.
This commit is contained in:
@@ -114,7 +114,9 @@
|
|||||||
|
|
||||||
:mutations
|
:mutations
|
||||||
{:print_checks {:type :check_result
|
{: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}}})
|
:resolve :mutation/print-checks}}})
|
||||||
|
|
||||||
(defn by [x kf]
|
(defn by [x kf]
|
||||||
@@ -223,8 +225,9 @@
|
|||||||
|
|
||||||
(defn print-checks [context args value]
|
(defn print-checks [context args value]
|
||||||
(->graphql
|
(->graphql
|
||||||
|
(rchecks/print-checks (:invoice_ids args)
|
||||||
(rchecks/print-checks (:invoice_ids args))))
|
(:company_id args)
|
||||||
|
(:bank_account_id args))))
|
||||||
|
|
||||||
(def schema
|
(def schema
|
||||||
(-> integreat-schema
|
(-> integreat-schema
|
||||||
|
|||||||
@@ -151,10 +151,10 @@
|
|||||||
:content-type "application/pdf"})
|
:content-type "application/pdf"})
|
||||||
(str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/merged-checks/" uuid ".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))
|
(let [uuid (str (UUID/randomUUID))
|
||||||
vendor (vendors vendor-id)
|
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: "
|
memo (str "Invoice #'s: "
|
||||||
(str/join ", "
|
(str/join ", "
|
||||||
(map (fn [i]
|
(map (fn [i]
|
||||||
@@ -171,7 +171,7 @@
|
|||||||
:pdf-data {:vendor vendor
|
:pdf-data {:vendor vendor
|
||||||
:paid-to (:name vendor)
|
:paid-to (:name vendor)
|
||||||
:amount (reduce + 0 (map :total invoices))
|
:amount (reduce + 0 (map :total invoices))
|
||||||
:check "1234"
|
:check (str (inc (:check-number bank-account)))
|
||||||
:memo memo
|
:memo memo
|
||||||
:date "5/10/2018"
|
:date "5/10/2018"
|
||||||
:company {:name (:name company)
|
:company {:name (:name company)
|
||||||
@@ -181,21 +181,19 @@
|
|||||||
:zip "95008"
|
:zip "95008"
|
||||||
:bank {:name "Bank of America, NA"
|
:bank {:name "Bank of America, NA"
|
||||||
:acct "11-35/2010"
|
:acct "11-35/2010"
|
||||||
:acct-number "123456789"}}}
|
:acct-number (:number bank-account)}}}
|
||||||
:invoices (map :id invoices)}))
|
: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)
|
(let [invoices (invoices/get-multi invoice-ids)
|
||||||
companies (into {}
|
company (companies/get-by-id company-id)
|
||||||
(map (fn [c] [(:id c) c])
|
|
||||||
(companies/get-all)))
|
|
||||||
vendors (into {}
|
vendors (into {}
|
||||||
(map (fn [v] [(:id v) v])
|
(map (fn [v] [(:id v) v])
|
||||||
(vendors/get-all)))
|
(vendors/get-all)))
|
||||||
invoices-grouped-by-vendor (group-by :vendor-id invoices)
|
invoices-grouped-by-vendor (group-by :vendor-id invoices)
|
||||||
checks (-> (for [[vendor-id invoices] invoices-grouped-by-vendor]
|
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)
|
doall)
|
||||||
invoice-checks (invoices-checks/insert-multi!
|
invoice-checks (invoices-checks/insert-multi!
|
||||||
(mapcat
|
(mapcat
|
||||||
|
|||||||
@@ -46,18 +46,27 @@
|
|||||||
(disj x data)
|
(disj x data)
|
||||||
(conj 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
|
(re-frame/reg-event-fx
|
||||||
::print-checks
|
::print-checks
|
||||||
(fn [{:keys [db]} [_ data]]
|
(fn [{:keys [db]} [_ bank-account-id]]
|
||||||
{:graphql
|
{
|
||||||
|
:db (assoc-in db [::invoice-page :print-checks-shown?] false )
|
||||||
|
:graphql
|
||||||
{:token (-> db :user)
|
{:token (-> db :user)
|
||||||
|
|
||||||
:query-obj {:venia/operation {:operation/type :mutation
|
:query-obj {:venia/operation {:operation/type :mutation
|
||||||
:operation/name "PrintChecks"}
|
:operation/name "PrintChecks"}
|
||||||
|
|
||||||
:venia/queries [[:print-checks
|
:venia/queries [[:print-checks
|
||||||
{:invoice_ids (vec (get-in db [::invoice-page :checked]))}
|
{:invoice_ids (vec (get-in db [::invoice-page :checked]))
|
||||||
[[:invoices [:id [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]
|
:bank_account_id bank-account-id
|
||||||
]
|
:company_id (:company db)}
|
||||||
|
[[:invoices [:id [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]
|
||||||
:pdf_url]]]}
|
:pdf_url]]]}
|
||||||
|
|
||||||
:on-success [::checks-created]}}))
|
:on-success [::checks-created]}}))
|
||||||
@@ -88,17 +97,27 @@
|
|||||||
(def unpaid-invoices-page
|
(def unpaid-invoices-page
|
||||||
(with-meta
|
(with-meta
|
||||||
(fn []
|
(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])]
|
current-company @(re-frame/subscribe [::subs/company])]
|
||||||
[:div
|
[:div
|
||||||
[:h1.title "Unpaid invoices"]
|
[:h1.title "Unpaid invoices"]
|
||||||
[:div.is-pulled-right
|
[:div.is-pulled-right
|
||||||
(when current-company
|
(when current-company
|
||||||
[:button.button.is-primary {:on-click (dispatch-event [::print-checks ])
|
[:div.dropdown {:class (if print-checks-shown?
|
||||||
:disabled (if (seq checked)
|
"is-active"
|
||||||
""
|
"")}
|
||||||
"disabled")
|
[:div.dropdown-trigger
|
||||||
} "Print check(s)"])]
|
[: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
|
[invoice-table {:id :unpaid
|
||||||
:params (re-frame/subscribe [::params])
|
:params (re-frame/subscribe [::params])
|
||||||
|
|||||||
Reference in New Issue
Block a user