refactoring to support grouping simply.
This commit is contained in:
@@ -32,7 +32,10 @@
|
||||
:bank_account
|
||||
{:fields {:id {:type 'Int}
|
||||
:number {:type 'String}
|
||||
:check_number {:type 'Int}}}
|
||||
:check_number {:type 'Int}
|
||||
:name {:type 'String}
|
||||
:bank_code {:type 'String}
|
||||
:bank_name {:type 'String}}}
|
||||
:vendor
|
||||
{:fields {:id {:type 'Int}
|
||||
:name {:type 'String}
|
||||
@@ -88,6 +91,8 @@
|
||||
:end {:type 'Int}}}
|
||||
:check_result {:fields {:invoices {:type '(list :invoice)}
|
||||
:pdf_url {:type 'String}}}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -112,9 +117,15 @@
|
||||
:vendor {:type '(list :vendor)
|
||||
:resolve :get-vendor}}
|
||||
|
||||
:input-objects
|
||||
{
|
||||
:invoice_payment {:fields {:invoice_id {:type 'Int}
|
||||
:amount {:type 'Float}}}
|
||||
}
|
||||
|
||||
:mutations
|
||||
{:print_checks {:type :check_result
|
||||
:args {:invoice_ids {:type '(list Int)}
|
||||
:args {:invoice_payments {:type '(list :invoice_payment)}
|
||||
:bank_account_id {:type 'Int}
|
||||
:company_id {:type 'Int}}
|
||||
:resolve :mutation/print-checks}}})
|
||||
@@ -225,7 +236,9 @@
|
||||
|
||||
(defn print-checks [context args value]
|
||||
(->graphql
|
||||
(rchecks/print-checks (:invoice_ids args)
|
||||
(rchecks/print-checks (map (fn [i] {:invoice-id (:invoice_id i)
|
||||
:amount (:amount i)})
|
||||
(:invoice_payments args))
|
||||
(:company_id args)
|
||||
(:bank_account_id args))))
|
||||
|
||||
|
||||
@@ -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