you can kind of set up more than one account in an invoice.
This commit is contained in:
@@ -406,6 +406,7 @@
|
||||
:add_invoice
|
||||
{:fields {:id {:type :id}
|
||||
:invoice_number {:type 'String}
|
||||
:expense_accounts {:type '(list :edit_expense_account)}
|
||||
:location {:type 'String}
|
||||
:date {:type 'String}
|
||||
:client_id {:type :id}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
[auto-ap.time :refer [parse iso-date]]
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[auto-ap.datomic :refer [uri remove-nils]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.set :as set]))
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
:invoice/client client_id}))
|
||||
(throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number :validation-error (str "Invoice '" invoice_number "' already exists.")}))))
|
||||
|
||||
(defn add-invoice-transaction [{:keys [total invoice_number location client_id vendor_id vendor_name date] :as in}]
|
||||
(defn add-invoice-transaction [{:keys [total invoice_number location client_id vendor_id vendor_name date expense_accounts] :as in}]
|
||||
(let [vendor (d-vendors/get-by-id vendor_id)
|
||||
account (:vendor/default-account vendor)
|
||||
_ (when-not (:db/id account)
|
||||
@@ -65,9 +65,12 @@
|
||||
:invoice/outstanding-balance total
|
||||
:invoice/status :invoice-status/unpaid
|
||||
:invoice/date (coerce/to-date date)
|
||||
:invoice/expense-accounts [{:invoice-expense-account/account (:db/id account)
|
||||
:invoice-expense-account/location (:account/location account location)
|
||||
:invoice-expense-account/amount total}]}))
|
||||
:invoice/expense-accounts (map (fn [ea]
|
||||
(remove-nils {:db/id (:id ea)
|
||||
:invoice-expense-account/account (:account_id ea)
|
||||
:invoice-expense-account/location (:location ea)
|
||||
:invoice-expense-account/amount (Double/parseDouble (:amount ea))}))
|
||||
expense_accounts)}))
|
||||
|
||||
(defn add-invoice [context {{:keys [total invoice_number location client_id vendor_id vendor_name date] :as in} :invoice} value]
|
||||
(assert-no-conflicting in)
|
||||
@@ -117,8 +120,10 @@
|
||||
:invoice/total total
|
||||
:invoice/outstanding-balance (- total paid-amount)
|
||||
:invoice/expense-accounts (map (fn [ea]
|
||||
{:db/id (:id ea)
|
||||
:invoice-expense-account/amount (Double/parseDouble (:amount ea))})
|
||||
(remove-nils {:db/id (:id ea)
|
||||
:invoice-expense-account/location (:location ea)
|
||||
:invoice-expense-account/account (:account_id ea)
|
||||
:invoice-expense-account/amount (Double/parseDouble (:amount ea))}))
|
||||
expense_accounts)})]
|
||||
(-> updated-invoice
|
||||
(->graphql))))
|
||||
|
||||
Reference in New Issue
Block a user