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