Now you can add manual checks.

This commit is contained in:
BC
2018-06-28 23:24:01 -07:00
parent 5f6bc5beea
commit a23975f9cf
10 changed files with 171 additions and 11 deletions

View File

@@ -68,9 +68,10 @@
:else
q)))
(defn base-graphql [{:keys [company-id vendor-id check-number]}]
(defn base-graphql [{:keys [company-id vendor-id check-number bank-account-id]}]
(cond-> base-query
(not (nil? company-id)) (helpers/merge-where [:= :company-id company-id])
(not (nil? bank-account-id)) (helpers/merge-where [:= :bank-account-id bank-account-id])
(not (nil? vendor-id)) (helpers/merge-where [:= :vendor-id vendor-id])
(not (nil? check-number)) (helpers/merge-where [:= :check-number check-number])))

View File

@@ -232,6 +232,14 @@
:bank_account_id {:type 'Int}
:company_id {:type 'Int}}
:resolve :mutation/print-checks}
:add_handwritten_check {:type :check_result
:args {:invoice_id {:type 'Int}
:amount {:type 'Float}
:date {:type 'String}
:check_number {:type 'Int}
:bank_account_id {:type 'Int}}
:resolve :mutation/add-handwritten-check}
:edit_user {:type :user
:args {:edit_user {:type :edit_user}}
:resolve :mutation/edit-user}
@@ -398,6 +406,7 @@
:get-company get-company
:get-user get-user
:get-user-companies get-user-companies
:mutation/add-handwritten-check gq-checks/add-handwritten-check
:mutation/print-checks print-checks
:mutation/edit-user gq-users/edit-user
:mutation/add-invoice gq-invoices/add-invoice

View File

@@ -4,8 +4,10 @@
[com.walmartlabs.lacinia :refer [execute]]
[com.walmartlabs.lacinia.executor :as executor]
[com.walmartlabs.lacinia.resolve :as resolve]
[auto-ap.db.invoices-checks :as invoices-checks]
[auto-ap.db.checks :as checks]
[auto-ap.db.vendors :as vendors]
[auto-ap.db.invoices :as invoices]
[auto-ap.utils :refer [by]]
[auto-ap.db.companies :as companies]
[auto-ap.time :refer [parse normal-date]]))
@@ -39,6 +41,26 @@
:start (:start args 0)
:end (+ (:start args 0) (count checks))}] extra-context)))
(defn add-handwritten-check [context args value]
(let [invoice (invoices/get-by-id (:invoice_id args))
check (checks/insert! {:s3-uuid nil
:s3-key nil
:s3-url nil
:check-number (:check_number args)
:amount (:amount args)
:bank-account-id (:bank_account_id args)
:vendor-id (:vendor-id invoice)
:company-id (:company-id invoice)
:invoices [(:invoice_id args)]})]
(invoices-checks/insert-multi! [{:invoice-id (:invoice_id args)
:check-id (:id check)
:amount (:amount args)}])
(invoices/apply-payment (:invoice_id args) (:amount args))
(->graphql
{:s3-url nil
:invoices [(invoices/get-by-id (:invoice_id args))]})))

View File

@@ -176,6 +176,7 @@
: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
:amount (reduce + 0 (map (comp invoice-amounts :id) invoices))
:memo memo
:vendor-id (:id vendor)

View File

@@ -13,9 +13,10 @@
first
:id))
(defn transaction->check-id [_ check-number company-id vendor-id]
(defn transaction->check-id [_ check-number company-id bank-account-id vendor-id]
(when check-number
(-> (checks/get-graphql {:company-id company-id
:bank-account-id bank-account-id
:check-number check-number})
first
:id)))
@@ -54,11 +55,12 @@
status :status}
transaction
transaction (if (= 0 (rand-int 3))
(assoc-in transaction [:description :original] (str "check xxx" (rand-nth ["6789" "1234" "6790"])))
(assoc-in transaction [:description :original] (str "check xxx1236"))
transaction)
check-number (extract-check-number transaction)
company-id (account->company account-id)
vendor-id (transaction->vendor-id transaction)]]
vendor-id (transaction->vendor-id transaction)
bank-account-id (yodlee-account-id->bank-account-id account-id)]]
(try
(transactions/upsert!
@@ -74,8 +76,8 @@
:company-id company-id
:vendor-id vendor-id
:check-number check-number
:bank-account-id (yodlee-account-id->bank-account-id account-id)
:check-id (transaction->check-id transaction check-number company-id vendor-id)
:bank-account-id bank-account-id
:check-id (transaction->check-id transaction check-number company-id bank-account-id vendor-id)
})
(catch Exception e
(println e))))))