From cffff99014cd0d132642c2dddb1f897ee0815614 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Mon, 14 May 2018 10:22:52 -0700 Subject: [PATCH] check numbers increase with bank accounts. --- src/clj/auto_ap/routes/checks.clj | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/clj/auto_ap/routes/checks.clj b/src/clj/auto_ap/routes/checks.clj index e4ed4fd6..1c82f0f1 100644 --- a/src/clj/auto_ap/routes/checks.clj +++ b/src/clj/auto_ap/routes/checks.clj @@ -151,10 +151,11 @@ :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 company bank-account-id] +(defn check-for-invoices [invoices vendor-id vendors company bank-account-id index] (let [uuid (str (UUID/randomUUID)) vendor (vendors vendor-id) bank-account (first (filter #(= (:id %) bank-account-id) (:bank-accounts company))) + memo (str "Invoice #'s: " (str/join ", " (map (fn [i] @@ -163,7 +164,7 @@ {:s3-uuid uuid :s3-key (str "checks/" uuid ".pdf") :s3-url (str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/checks/" uuid ".pdf") - :check-number 1234 + :check-number (+ index (:check-number bank-account)) :amount (reduce + 0 (map :total invoices)) :memo memo :vendor-id (:id vendor) @@ -171,7 +172,7 @@ :pdf-data {:vendor vendor :paid-to (:name vendor) :amount (reduce + 0 (map :total invoices)) - :check (str (inc (:check-number bank-account))) + :check (str (+ index (:check-number bank-account))) :memo memo :date "5/10/2018" :company {:name (:name company) @@ -192,8 +193,8 @@ (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 company bank-account-id))]) + 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))]) doall) invoice-checks (invoices-checks/insert-multi! (mapcat @@ -204,9 +205,18 @@ :check-id (:id check) :amount (:total i)}) invoices)) - checks)) ] + checks)) + updated-company (update company :bank-accounts + (fn [bas] + (map (fn [ba] + (if (= bank-account-id (:id ba)) + (update ba :check-number + (count checks)) + ba)) + bas))) + ] (make-pdfs (map second checks)) + (companies/upsert company-id updated-company) {:invoices (mapcat first checks) :pdf-url (merge-pdfs (map (comp :s3-key second) checks))}))