fixed dates.
This commit is contained in:
@@ -59,7 +59,6 @@
|
||||
(Integer/parseInt id))))
|
||||
|
||||
(defn insert [data]
|
||||
|
||||
(let [[{:keys [id]}] (j/insert! (get-conn) :vendors (unparse data))]
|
||||
(println "inserted vendor: " data ", id " id)
|
||||
(get-by-id id)))
|
||||
|
||||
@@ -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))))
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
(time/to-time-zone (time/now) (time/time-zone-for-id "America/Los_Angeles")))
|
||||
|
||||
(def normal-date "MM/dd/yyyy")
|
||||
(def iso-date "yyyy-MM-dd")
|
||||
|
||||
(defn parse [v format]
|
||||
(try
|
||||
|
||||
@@ -38,8 +38,7 @@
|
||||
status :status}
|
||||
transaction
|
||||
company-id (account->company-id account-id)
|
||||
vendor-id (transaction->vendor-id transaction)]
|
||||
]
|
||||
vendor-id (transaction->vendor-id transaction)]]
|
||||
|
||||
(try
|
||||
(transactions/upsert!
|
||||
|
||||
Reference in New Issue
Block a user