fixed dates.
This commit is contained in:
@@ -3,24 +3,29 @@
|
||||
[auto-ap.db.invoices :as invoices]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.db.invoices-expense-accounts :as invoices-expense-accounts]
|
||||
[auto-ap.time :refer [parse normal-date]]))
|
||||
[auto-ap.time :refer [parse iso-date]]))
|
||||
|
||||
(defn -create-vendor-if-necessary [vendor-id vendor-name]
|
||||
(defn -create-or-get-vendor [vendor-id vendor-name]
|
||||
(if vendor-id
|
||||
vendor-id
|
||||
(:id (vendors/insert {:name vendor-name :default-expense-account 0}))))
|
||||
(vendors/get-by-id vendor-id)
|
||||
(vendors/insert {:name vendor-name :default-expense-account 0})))
|
||||
|
||||
(defn add-invoice [context {{:keys [total invoice_number company_id vendor_id vendor_name date] :as in} :invoice} value]
|
||||
(let [vendor_id (-create-vendor-if-necessary vendor_id vendor_name)]
|
||||
(-> (invoices/insert-multi! [{:invoice-number invoice_number
|
||||
:company-id company_id
|
||||
:vendor-id vendor_id
|
||||
:total total
|
||||
:outstanding-balance total
|
||||
:status "unpaid"
|
||||
:imported true
|
||||
:date (parse date normal-date)}])
|
||||
(first)
|
||||
(let [vendor (-create-or-get-vendor vendor_id vendor_name)
|
||||
|
||||
[invoice] (invoices/insert-multi! [{:invoice-number invoice_number
|
||||
:company-id company_id
|
||||
:vendor-id (:id vendor)
|
||||
:total total
|
||||
:outstanding-balance total
|
||||
:status "unpaid"
|
||||
:imported true
|
||||
:date (parse date iso-date)}]
|
||||
)]
|
||||
(invoices-expense-accounts/replace-for-invoice
|
||||
(:id invoice) [{:expense-account-id (:default-expense-account vendor)
|
||||
:amount total}] )
|
||||
(-> invoice
|
||||
(->graphql))))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user