Supporting new action.
This commit is contained in:
@@ -6,22 +6,16 @@
|
||||
[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.datomic.checks :as d-checks]
|
||||
[auto-ap.datomic.invoices :as d-invoices]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.datomic.bank-accounts :as d-bank-accounts]
|
||||
[auto-ap.db.invoices-checks :as invoices-checks]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.db.invoices :as invoices]
|
||||
[auto-ap.db.utils :refer [query]]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[auto-ap.numeric :refer [num->words]]
|
||||
[config.core :refer [env]]
|
||||
[auto-ap.db.companies :as companies]
|
||||
[auto-ap.time :refer [parse normal-date iso-date local-now]]
|
||||
[amazonica.aws.s3 :as s3]
|
||||
[clojure.string :as str]
|
||||
@@ -265,6 +259,7 @@
|
||||
(conj [:inc (:db/id bank-account) :bank-account/check-number 1])
|
||||
(into (invoice-payments invoices invoice-amounts)))))
|
||||
|
||||
|
||||
(defmethod invoices->entities :payment-type/debit [invoices vendor client bank-account type index invoice-amounts]
|
||||
(let [payment (assoc (base-payment invoices vendor client bank-account type index invoice-amounts)
|
||||
:payment/type :payment-type/debit
|
||||
@@ -323,26 +318,22 @@
|
||||
:end (+ (:start args 0) (count payments))}]))
|
||||
|
||||
(defn add-handwritten-check [context args value]
|
||||
(let [invoice (invoices/get-by-id (:invoice_id args))
|
||||
(let [invoice (d-invoices/get-by-id (:invoice_id args))
|
||||
bank-account-id (Long/parseLong (:bank_account_id args))
|
||||
bank-account (d-bank-accounts/get-by-id bank-account-id)
|
||||
_ (assert-can-see-company (:id context) (:company-id invoice))
|
||||
check (checks/insert! {:s3-uuid nil
|
||||
:s3-key nil
|
||||
:s3-url nil
|
||||
:check-number (:check_number args)
|
||||
:date (parse (:date args) iso-date)
|
||||
: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))
|
||||
base-payment (base-payment [invoice] (:invoice/vendor invoice)
|
||||
(:invoice/client invoice)
|
||||
bank-account :payment-type/check 0 {(Long/parseLong (:invoice_id args)) (:amount args)})]
|
||||
@(d/transact (d/connect uri)
|
||||
[(assoc base-payment
|
||||
:payment/check-number (:check_number args)
|
||||
:payment/date (c/to-date (parse (:date args) iso-date))
|
||||
:payment/amount (:amount args))
|
||||
[:pay (:db/id invoice) (:amount args)]])
|
||||
(->graphql
|
||||
{:s3-url nil
|
||||
:invoices [(invoices/get-by-id (:invoice_id args))]})))
|
||||
:invoices [(d-invoices/get-by-id (:invoice_id args))]})))
|
||||
|
||||
|
||||
(defn void-check [context {id :payment_id} value]
|
||||
|
||||
@@ -70,14 +70,16 @@
|
||||
(->graphql))))
|
||||
|
||||
(defn void-invoice [context {id :invoice_id} value]
|
||||
(let [invoice (d-invoices/get-by-id id)
|
||||
_ (assert-can-see-company (:id context) (:company-id invoice))
|
||||
updated-invoice (d-invoices/update {:db/id (Long/parseLong id)
|
||||
:invoice/total 0.0
|
||||
:invoice/outstanding-balance 0.0
|
||||
:invoice/status :invoice-status/voided})]
|
||||
(-> updated-invoice
|
||||
(->graphql))))
|
||||
(let [invoice (d-invoices/get-by-id id)
|
||||
_ (assert-can-see-company (:id context) (:company-id invoice))
|
||||
updated-invoice (d-invoices/update {:db/id (Long/parseLong id)
|
||||
:invoice/total 0.0
|
||||
:invoice/outstanding-balance 0.0
|
||||
:invoice/status :invoice-status/voided})]
|
||||
;; TODO void out all expense accounts
|
||||
|
||||
(-> updated-invoice
|
||||
(->graphql))))
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -47,7 +47,8 @@
|
||||
|
||||
(defn can-see-company? [identity company]
|
||||
(or (= "admin" (:role identity))
|
||||
((set (map :db/id (:user/companies identity))) (:db/id company))))
|
||||
((set (map :db/id (:user/companies identity))) (:db/id company))
|
||||
((set (map :db/id (:user/companies identity))) company)))
|
||||
|
||||
(defn assert-can-see-company [identity company]
|
||||
(when-not (can-see-company? identity company)
|
||||
|
||||
Reference in New Issue
Block a user