you can add vendors while creating.
This commit is contained in:
@@ -53,15 +53,14 @@
|
||||
:where [:= :id (if (int? id)
|
||||
id
|
||||
(Integer/parseInt id))])
|
||||
execute!)
|
||||
execute!)
|
||||
(get-by-id (if (int? id)
|
||||
id
|
||||
(Integer/parseInt id))))
|
||||
|
||||
(defn insert [data]
|
||||
(let [[id] (-> (sql/build :insert-into :vendors
|
||||
:values [(unparse data)])
|
||||
execute!)]
|
||||
|
||||
(let [[{:keys [id]}] (j/insert! (get-conn) :vendors (unparse data))]
|
||||
(println "inserted vendor: " data ", id " id)
|
||||
(get-by-id id)))
|
||||
|
||||
|
||||
@@ -192,6 +192,7 @@
|
||||
:date {:type 'String}
|
||||
:company_id {:type 'Int}
|
||||
:vendor_id {:type 'Int}
|
||||
:vendor_name {:type 'String}
|
||||
:total {:type 'Float}}}}
|
||||
|
||||
:mutations
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
(ns auto-ap.graphql.invoices
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql]]
|
||||
[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]]))
|
||||
|
||||
(defn add-invoice [context {{:keys [total invoice_number company_id vendor_id date] :as in} :invoice} value]
|
||||
(defn -create-vendor-if-necessary [vendor-id vendor-name]
|
||||
(if vendor-id
|
||||
vendor-id
|
||||
(:id (doto (vendors/insert {:name vendor-name :default-expense-account 0}) println))))
|
||||
|
||||
(-> (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)
|
||||
(->graphql)))
|
||||
(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)
|
||||
(->graphql))))
|
||||
|
||||
|
||||
(defn get-invoices-expense-accounts [context args value]
|
||||
|
||||
Reference in New Issue
Block a user