you can add vendors while creating.
This commit is contained in:
@@ -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