you can now create cash payments.

This commit is contained in:
Bryce Covert
2018-07-27 16:39:44 -07:00
parent 4a0f7d7f77
commit 4069f731e9
10 changed files with 75 additions and 32 deletions

View File

@@ -50,10 +50,9 @@
(map db->clj)
(map data->fields)))
(def all-keys #{:company-id :vendor-id :id :status :date :s3-uuid :s3-key :s3-url :check-number :memo :amount :paid-to :bank-account-id})
(def all-keys #{:company-id :vendor-id :id :status :date :s3-uuid :s3-key :s3-url :check-number :memo :amount :paid-to :bank-account-id :type})
(defn add-sort-by [q sort-by asc]
(println sort-by)
(let [sort-by-key (keyword sort-by)]
(cond (nil? sort-by)
(helpers/merge-order-by q [:date])

View File

@@ -41,6 +41,7 @@
:bank_account
{:fields {:id {:type 'Int}
:type {:type 'String}
:number {:type 'String}
:check_number {:type 'Int}
:name {:type 'String}
@@ -84,6 +85,7 @@
:check {:fields {:id {:type 'Int}
:type {:type 'String}
:amount {:type 'String}
:vendor {:type :vendor
:resolve :get-vendor-for-check}

View File

@@ -175,10 +175,15 @@
: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 index invoice-amounts]
(defmulti check-for-invoices (fn [invoices vendor-id vendors company bank-account index invoice-amounts]
(:type bank-account)))
(defmethod check-for-invoices "check" [invoices vendor-id vendors company bank-account index invoice-amounts]
(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 ", "
@@ -189,7 +194,8 @@
: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 (+ index (:check-number bank-account))
:bank-account-id bank-account-id
:type "check"
:bank-account-id (:id bank-account)
:amount (reduce + 0 (map (comp invoice-amounts :id) invoices))
:memo memo
:vendor-id (:id vendor)
@@ -208,8 +214,20 @@
:acct (:bank-code bank-account)
:routing (:routing bank-account)
:acct-number (:number bank-account)}}}
:invoices (map :id invoices)}))
(defmethod check-for-invoices "cash" [invoices vendor-id vendors company bank-account index invoice-amounts]
(let [vendor (vendors vendor-id)]
{:type "cash"
:bank-account-id (:id bank-account)
:amount (reduce + 0 (map (comp invoice-amounts :id) invoices))
:status "cleared"
:memo "Cash"
:vendor-id (:id vendor)
:company-id (:id company)
:date (time/now)
:invoices (map :id invoices)}))
(defn print-checks [invoice-payments company-id bank-account-id]
(let [invoices (invoices/get-multi (map :invoice-id invoice-payments))
@@ -217,8 +235,9 @@
vendors (by :id (vendors/get-all))
invoice-amounts (by :invoice-id :amount invoice-payments)
invoices-grouped-by-vendor (group-by :vendor-id invoices)
bank-account (first (filter #(= (:id %) bank-account-id) (:bank-accounts company)))
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 invoice-amounts))])
[invoices (checks/insert! (check-for-invoices invoices vendor-id vendors company bank-account index invoice-amounts))])
doall)
invoice-checks (invoices-checks/insert-multi!
(mapcat
@@ -230,20 +249,25 @@
:amount (invoice-amounts (:id i))})
invoices))
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)))]
updated-company (if (= (:type bank-account) "cash" )
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)
(when (not= (:type bank-account) "cash")
(make-pdfs (map second checks))
(companies/upsert company-id updated-company))
(doseq [{:keys [invoice-id amount]} invoice-payments]
(invoices/apply-payment invoice-id amount))
{:invoices (invoices/get-multi (map :id (mapcat first checks)))
:pdf-url (merge-pdfs (map (comp :s3-key second) checks))}))
:pdf-url (if (= (:type bank-account) "cash")
nil
(merge-pdfs (map (comp :s3-key second) checks)))}))
(defroutes routes