refactoring to support grouping simply.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
(:require [auto-ap.db.companies :as companies]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.db.invoices :as invoices]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[auto-ap.db.checks :as checks]
|
||||
[auto-ap.db.invoices-checks :as invoices-checks]
|
||||
[auto-ap.db.utils :refer [query]]
|
||||
@@ -186,12 +187,11 @@
|
||||
:invoices (map :id invoices)}))
|
||||
|
||||
|
||||
(defn print-checks [invoice-ids company-id bank-account-id]
|
||||
(let [invoices (invoices/get-multi invoice-ids)
|
||||
(defn print-checks [invoice-payments company-id bank-account-id]
|
||||
(let [invoices (invoices/get-multi (map :invoice-id invoice-payments))
|
||||
company (companies/get-by-id company-id)
|
||||
vendors (into {}
|
||||
(map (fn [v] [(:id v) v])
|
||||
(vendors/get-all)))
|
||||
vendors (by :id (vendors/get-all))
|
||||
invoice-amounts (by :invoice-id :amount invoice-payments)
|
||||
invoices-grouped-by-vendor (group-by :vendor-id invoices)
|
||||
checks (-> (for [[[vendor-id invoices] index] (map vector invoices-grouped-by-vendor (range))]
|
||||
[invoices (checks/insert! (check-for-invoices invoices vendor-id vendors company bank-account-id index))])
|
||||
@@ -203,7 +203,7 @@
|
||||
(fn [i]
|
||||
{:invoice-id (:id i)
|
||||
:check-id (:id check)
|
||||
:amount (:total i)})
|
||||
:amount (invoice-amounts (:id i))})
|
||||
invoices))
|
||||
checks))
|
||||
updated-company (update company :bank-accounts
|
||||
@@ -212,8 +212,7 @@
|
||||
(if (= bank-account-id (:id ba))
|
||||
(update ba :check-number + (count checks))
|
||||
ba))
|
||||
bas)))
|
||||
]
|
||||
bas)))]
|
||||
|
||||
(make-pdfs (map second checks))
|
||||
(companies/upsert company-id updated-company)
|
||||
|
||||
Reference in New Issue
Block a user