fixed dates.

This commit is contained in:
BC
2018-06-16 18:57:33 -07:00
parent f9c0e55b01
commit b0f401e87b
13 changed files with 49 additions and 68 deletions

View File

@@ -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)))

View File

@@ -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))))

View File

@@ -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

View File

@@ -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!