supports terms.
This commit is contained in:
@@ -261,8 +261,8 @@
|
||||
:invoice_number {:type 'String}
|
||||
:status {:type 'String}
|
||||
:expense_accounts {:type '(list :invoices_expense_accounts)}
|
||||
:date {:type 'String}
|
||||
:due {:type 'String}
|
||||
:date {:type :iso_date}
|
||||
:due {:type :iso_date}
|
||||
:client_id {:type 'Int}
|
||||
:payments {:type '(list :invoice_payment)}
|
||||
:vendor {:type :vendor}
|
||||
@@ -541,8 +541,9 @@
|
||||
{:fields {:id {:type :id}
|
||||
:invoice_number {:type 'String}
|
||||
:expense_accounts {:type '(list :edit_expense_account)}
|
||||
:location {:type 'String}
|
||||
:location {:type :iso_date}
|
||||
:date {:type :iso_date}
|
||||
:due {:type :iso_date}
|
||||
:client_id {:type :id}
|
||||
:vendor_id {:type :id}
|
||||
:vendor_name {:type 'String}
|
||||
@@ -552,7 +553,8 @@
|
||||
{:fields {:id {:type :id}
|
||||
:invoice_number {:type 'String}
|
||||
:expense_accounts {:type '(list :edit_expense_account)}
|
||||
:date {:type 'String}
|
||||
:date {:type :iso_date}
|
||||
:due {:type :iso_date}
|
||||
:total {:type 'Float}}}
|
||||
:edit_transaction
|
||||
{:fields {:id {:type :id}
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
:account account_id
|
||||
:location location}))
|
||||
|
||||
(defn add-invoice-transaction [{:keys [total invoice_number location client_id vendor_id vendor_name date expense_accounts] :as in}]
|
||||
(defn add-invoice-transaction [{:keys [total invoice_number location client_id vendor_id vendor_name date due expense_accounts] :as in}]
|
||||
(println date)
|
||||
(let [vendor (d-vendors/get-by-id vendor_id)
|
||||
account (:vendor/default-account vendor)
|
||||
@@ -75,7 +75,8 @@
|
||||
:invoice/expense-accounts (map expense-account->entity
|
||||
expense_accounts)}
|
||||
(:vendor/terms vendor) (assoc :invoice/due (coerce/to-date
|
||||
(time/plus date (time/days (:vendor/terms vendor))))))))
|
||||
(time/plus date (time/days (:vendor/terms vendor)))))
|
||||
due (assoc :invoice/due (doto (coerce/to-date due) println)))))
|
||||
|
||||
|
||||
(defn deleted-expense-accounts [invoice expense-accounts]
|
||||
@@ -114,7 +115,7 @@
|
||||
->graphql)))
|
||||
|
||||
|
||||
(defn edit-invoice [context {{:keys [id invoice_number total vendor_id date client_id expense_accounts] :as in} :invoice} value]
|
||||
(defn edit-invoice [context {{:keys [id due invoice_number total vendor_id date client_id expense_accounts] :as in} :invoice} value]
|
||||
(let [invoice (d-invoices/get-by-id id)
|
||||
_ (when (seq (doto (d-invoices/find-conflicting {:db/id id
|
||||
:invoice/invoice-number invoice_number
|
||||
@@ -131,13 +132,14 @@
|
||||
_ (assert-can-see-client (:id context) (:db/id (:invoice/client invoice)))
|
||||
deleted (deleted-expense-accounts invoice expense_accounts)
|
||||
|
||||
updated-invoice {:db/id id
|
||||
:invoice/invoice-number invoice_number
|
||||
:invoice/date (coerce/to-date (parse date iso-date))
|
||||
:invoice/total total
|
||||
:invoice/outstanding-balance (- total paid-amount)
|
||||
:invoice/expense-accounts (map expense-account->entity
|
||||
expense_accounts)}]
|
||||
updated-invoice (cond-> {:db/id id
|
||||
:invoice/invoice-number invoice_number
|
||||
:invoice/date (coerce/to-date date)
|
||||
:invoice/total total
|
||||
:invoice/outstanding-balance (- total paid-amount)
|
||||
:invoice/expense-accounts (map expense-account->entity
|
||||
expense_accounts)}
|
||||
due (assoc :invoice/due (coerce/to-date due)))]
|
||||
@(d/transact (d/connect uri) (concat [updated-invoice]
|
||||
(map (fn [d] [:db/retract id :invoice/expense-accounts d]) deleted)))
|
||||
(-> (d-invoices/get-by-id id)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
(s/def ::client map?)
|
||||
(s/def ::invoice-number ::shared/required-identifier)
|
||||
(s/def ::date ::shared/date)
|
||||
(s/def ::due (s/nilable ::shared/date))
|
||||
(s/def ::total ::shared/money)
|
||||
(s/def ::vendor-id ::shared/identifier)
|
||||
|
||||
@@ -15,4 +16,6 @@
|
||||
::date
|
||||
::vendor
|
||||
::total]
|
||||
:opt-un [::vendor-name]))
|
||||
:opt-un [::vendor-name
|
||||
::due
|
||||
]))
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
;; 2017-09-19T07:00:00.000Z
|
||||
(def is-8601 #"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$")
|
||||
|
||||
(def is-year-month-day #"^\d{4}-\d{2}-\d{2}$")
|
||||
|
||||
|
||||
(defn dates->date-times [x]
|
||||
(walk/postwalk
|
||||
@@ -42,6 +44,10 @@
|
||||
(re-matches is-8601 node))
|
||||
(format/parse (format/formatters :date-time) node)
|
||||
|
||||
(and (string? node)
|
||||
(re-matches is-year-month-day node))
|
||||
(time/from-default-time-zone (format/parse (format/formatters :year-month-day) node))
|
||||
|
||||
(instance? js/Date node)
|
||||
(time/to-default-time-zone (c/from-date node))
|
||||
|
||||
|
||||
@@ -34,11 +34,12 @@
|
||||
(re-frame/reg-sub
|
||||
::create-query
|
||||
:<- [::forms/form ::form]
|
||||
(fn [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor client]} :data}]
|
||||
(fn [{:keys [data] {:keys [id invoice-number date due location total expense-accounts vendor client]} :data}]
|
||||
{:venia/operation {:operation/type :mutation
|
||||
:operation/name "AddInvoice"}
|
||||
:venia/queries [{:query/data [:add-invoice
|
||||
{:invoice {:date date
|
||||
:due due
|
||||
:vendor-id (:id vendor)
|
||||
:client-id (:id client)
|
||||
:invoice-number invoice-number
|
||||
@@ -56,13 +57,14 @@
|
||||
(re-frame/reg-sub
|
||||
::edit-query
|
||||
:<- [::forms/form ::form]
|
||||
(fn [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor client]} :data}]
|
||||
(fn [{:keys [data] {:keys [id invoice-number date due location total expense-accounts vendor client]} :data}]
|
||||
{:venia/operation {:operation/type :mutation
|
||||
:operation/name "EditInvoice"}
|
||||
:venia/queries [{:query/data [:edit-invoice
|
||||
{:invoice {:id id
|
||||
:invoice-number invoice-number
|
||||
:date date
|
||||
:due due
|
||||
:total total
|
||||
:expense-accounts (map (fn [ea]
|
||||
{:id (when-not (str/starts-with? (:id ea) "new-")
|
||||
@@ -113,12 +115,14 @@
|
||||
::editing
|
||||
(fn [db [_ which]]
|
||||
(let [edit-invoice (update which :date #(date->str % standard))
|
||||
edit-invoice (update edit-invoice :due #(date->str % standard))
|
||||
edit-invoice (assoc edit-invoice :original edit-invoice)
|
||||
locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])]
|
||||
(-> db
|
||||
(forms/start-form ::form {:id (:id edit-invoice)
|
||||
:status (:status edit-invoice)
|
||||
:date (:date edit-invoice)
|
||||
:due (:due edit-invoice)
|
||||
:invoice-number (:invoice-number edit-invoice)
|
||||
:total (:total edit-invoice)
|
||||
:original edit-invoice
|
||||
@@ -243,6 +247,18 @@
|
||||
:field [:date]
|
||||
:spec ::invoice/date}]]
|
||||
|
||||
[field "Due (optional)"
|
||||
[date-picker {:class-name "input"
|
||||
:class "input"
|
||||
:format-week-number (fn [] "")
|
||||
:previous-month-button-label ""
|
||||
:placeholder "mm/dd/yyyy"
|
||||
:next-month-button-label ""
|
||||
:next-month-label ""
|
||||
:type "date"
|
||||
:field [:due]
|
||||
:spec ::invoice/due}]]
|
||||
|
||||
[field "Invoice #"
|
||||
[:input.input {:type "text"
|
||||
:field [:invoice-number]
|
||||
|
||||
Reference in New Issue
Block a user