made the invoice form work like the other one.
This commit is contained in:
@@ -2,17 +2,17 @@
|
|||||||
(:require [clojure.spec.alpha :as s]
|
(:require [clojure.spec.alpha :as s]
|
||||||
[auto-ap.entities.shared :as shared]))
|
[auto-ap.entities.shared :as shared]))
|
||||||
|
|
||||||
(s/def ::vendor-id string?)
|
(s/def ::vendor map?)
|
||||||
(s/def ::vendor-name string?)
|
(s/def ::vendor-name string?)
|
||||||
(s/def ::client-id string?)
|
(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 ::total ::shared/money)
|
(s/def ::total ::shared/money)
|
||||||
|
|
||||||
(s/def ::invoice (s/keys :req-un [::client-id
|
(s/def ::invoice (s/keys :req-un [::client
|
||||||
::invoice-number
|
::invoice-number
|
||||||
::date
|
::date
|
||||||
::vendor-id
|
::vendor
|
||||||
::total]
|
::total]
|
||||||
:opt-un [
|
:opt-un [
|
||||||
::vendor-name]))
|
::vendor-name]))
|
||||||
|
|||||||
@@ -5,23 +5,24 @@
|
|||||||
[auto-ap.forms :as forms]
|
[auto-ap.forms :as forms]
|
||||||
[auto-ap.subs :as subs]
|
[auto-ap.subs :as subs]
|
||||||
[auto-ap.views.components.dropdown :refer [drop-down]]
|
[auto-ap.views.components.dropdown :refer [drop-down]]
|
||||||
[auto-ap.views.components.typeahead :refer [typeahead]]
|
[auto-ap.views.components.typeahead :refer [typeahead typeahead-entity]]
|
||||||
[auto-ap.views.components.expense-accounts-field :refer [expense-accounts-field recalculate-amounts] :as expense-accounts-field]
|
[auto-ap.views.components.expense-accounts-field :refer [expense-accounts-field recalculate-amounts] :as expense-accounts-field]
|
||||||
[auto-ap.views.pages.invoices.common :refer [invoice-read]]
|
[auto-ap.views.pages.invoices.common :refer [invoice-read]]
|
||||||
[auto-ap.views.utils
|
[auto-ap.views.utils
|
||||||
:refer
|
:refer
|
||||||
[bind-field date->str date-picker dispatch-event standard]]
|
[bind-field date->str date-picker dispatch-event standard with-user]]
|
||||||
[cljs-time.core :as c]
|
[cljs-time.core :as c]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[goog.string :as gstring]))
|
[goog.string :as gstring]
|
||||||
|
[auto-ap.views.components.layouts :as layouts]))
|
||||||
|
|
||||||
;; SUBS
|
;; SUBS
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::can-submit-edit-invoice
|
::can-submit
|
||||||
:<- [::forms/form ::form]
|
:<- [::forms/form ::form]
|
||||||
(fn [{:keys [data status]} _]
|
(fn [{:keys [data status]} _]
|
||||||
(let [min-total (if (= (:total (:original data)) (:outstanding-balance (:original data)))
|
(let [min-total (if (= (:total (:original data)) (:outstanding-balance (:original data)))
|
||||||
@@ -33,79 +34,80 @@
|
|||||||
(or (not (:id data))
|
(or (not (:id data))
|
||||||
(dollars= (js/parseFloat (:total data)) (reduce + 0 (map (fn [ea] (js/parseFloat (:amount ea))) (:expense-accounts data)))))))))
|
(dollars= (js/parseFloat (:total data)) (reduce + 0 (map (fn [ea] (js/parseFloat (:amount ea))) (:expense-accounts data)))))))))
|
||||||
|
|
||||||
(defmulti submit-query (fn [_ [_ command]]
|
(re-frame/reg-sub
|
||||||
command))
|
::create-query
|
||||||
|
:<- [::forms/form ::form]
|
||||||
(defmethod submit-query :create [db]
|
(fn [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor client]} :data}]
|
||||||
(let [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor-id client-id]} :data} @(re-frame/subscribe [::forms/form ::form])]
|
{: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
|
:vendor-id (:id vendor)
|
||||||
:vendor-id vendor-id
|
:client-id (:id client)
|
||||||
:client-id client-id
|
:invoice-number invoice-number
|
||||||
:invoice-number invoice-number
|
:location location
|
||||||
:location location
|
: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-")
|
(:id ea))
|
||||||
(:id ea))
|
:account_id (:id (:account ea))
|
||||||
:account_id (:id (:account ea))
|
:location (:location ea)
|
||||||
:location (:location ea)
|
:amount (:amount ea)})
|
||||||
:amount (:amount ea)})
|
expense-accounts)}}
|
||||||
expense-accounts)}}
|
invoice-read]}]}))
|
||||||
invoice-read]}]}))
|
|
||||||
|
|
||||||
(defmethod submit-query :edit [db]
|
|
||||||
(let [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor-id client-id]} :data} @(re-frame/subscribe [::forms/form ::form])]
|
|
||||||
{:venia/operation {:operation/type :mutation
|
|
||||||
:operation/name "EditInvoice"}
|
|
||||||
:venia/queries [{:query/data [:edit-invoice
|
|
||||||
{:invoice {:id id
|
|
||||||
:invoice-number invoice-number
|
|
||||||
:date date
|
|
||||||
:total total
|
|
||||||
:expense-accounts (map (fn [ea]
|
|
||||||
{:id (when-not (str/starts-with? (:id ea) "new-")
|
|
||||||
(:id ea))
|
|
||||||
:account_id (:id (:account ea))
|
|
||||||
:location (:location ea)
|
|
||||||
:amount (:amount ea)})
|
|
||||||
expense-accounts)}}
|
|
||||||
invoice-read]}]}))
|
|
||||||
|
|
||||||
(defmethod submit-query :add-and-print [db [_ _ bank-account-id type]]
|
|
||||||
(let [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor-id client-id]} :data} @(re-frame/subscribe [::forms/form ::form])]
|
|
||||||
{:venia/operation {:operation/type :mutation
|
|
||||||
:operation/name "AddAndPrintInvoice"}
|
|
||||||
:venia/queries [{:query/data [:add-and-print-invoice
|
|
||||||
{:invoice {:date date
|
|
||||||
:vendor-id vendor-id
|
|
||||||
:client-id client-id
|
|
||||||
:invoice-number invoice-number
|
|
||||||
:location location
|
|
||||||
:total total
|
|
||||||
:expense-accounts (map (fn [ea]
|
|
||||||
{:id (when-not (str/starts-with? (:id ea) "new-")
|
|
||||||
(:id ea))
|
|
||||||
:account_id (:id (:account ea))
|
|
||||||
:location (:location ea)
|
|
||||||
:amount (:amount ea)})
|
|
||||||
expense-accounts)}
|
|
||||||
:bank-account-id bank-account-id
|
|
||||||
:type type}
|
|
||||||
[:pdf-url [:invoices invoice-read]]]}]}))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::submit-query
|
::edit-query
|
||||||
submit-query)
|
:<- [::forms/form ::form]
|
||||||
|
(fn [{:keys [data] {:keys [id invoice-number date 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
|
||||||
|
:total total
|
||||||
|
:expense-accounts (map (fn [ea]
|
||||||
|
{:id (when-not (str/starts-with? (:id ea) "new-")
|
||||||
|
(:id ea))
|
||||||
|
:account_id (:id (:account ea))
|
||||||
|
:location (:location ea)
|
||||||
|
:amount (:amount ea)})
|
||||||
|
expense-accounts)}}
|
||||||
|
invoice-read]}]}))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::add-and-print-query
|
||||||
|
(fn [db [_ bank-account-id type]]
|
||||||
|
(let [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor client]} :data} @(re-frame/subscribe [::forms/form ::form])]
|
||||||
|
{:venia/operation {:operation/type :mutation
|
||||||
|
:operation/name "AddAndPrintInvoice"}
|
||||||
|
:venia/queries [{:query/data [:add-and-print-invoice
|
||||||
|
{:invoice {:date date
|
||||||
|
:vendor-id (:id vendor)
|
||||||
|
:client-id (:id client)
|
||||||
|
:invoice-number invoice-number
|
||||||
|
:location location
|
||||||
|
:total total
|
||||||
|
:expense-accounts (map (fn [ea]
|
||||||
|
{:id (when-not (str/starts-with? (:id ea) "new-")
|
||||||
|
(:id ea))
|
||||||
|
:account_id (:id (:account ea))
|
||||||
|
:location (:location ea)
|
||||||
|
:amount (:amount ea)})
|
||||||
|
expense-accounts)}
|
||||||
|
:bank-account-id bank-account-id
|
||||||
|
:type type}
|
||||||
|
[:pdf-url [:invoices invoice-read]]]}]})))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; EVENTS
|
;; EVENTS
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::adding
|
::adding
|
||||||
(fn [db [_ new]]
|
(fn [db [_ new]]
|
||||||
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:client-id new)])]
|
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:client new)])]
|
||||||
(-> db (forms/start-form ::form (assoc new :expense-accounts
|
(-> db (forms/start-form ::form (assoc new :expense-accounts
|
||||||
(expense-accounts-field/from-graphql (:expense-accounts new)
|
(expense-accounts-field/from-graphql (:expense-accounts new)
|
||||||
0.0
|
0.0
|
||||||
@@ -123,65 +125,60 @@
|
|||||||
: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
|
||||||
:vendor-id (:id (:vendor edit-invoice))
|
:vendor (:vendor edit-invoice)
|
||||||
:vendor-name (:name (:vendor edit-invoice))
|
:client (:client edit-invoice)
|
||||||
:client-id (:id (:client edit-invoice))
|
|
||||||
:expense-accounts (expense-accounts-field/from-graphql (:expense-accounts which)
|
:expense-accounts (expense-accounts-field/from-graphql (:expense-accounts which)
|
||||||
(:amount which)
|
(:amount which)
|
||||||
locations)
|
locations)})))))
|
||||||
:client-name (:name (:client edit-invoice))})))))
|
|
||||||
|
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::changed
|
||||||
|
(forms/change-handler ::form
|
||||||
|
(fn [data field value]
|
||||||
|
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))])]
|
||||||
|
(cond (and (= [:vendor] field)
|
||||||
|
value
|
||||||
|
(expense-accounts-field/can-replace-with-default? (:expense-accounts data)))
|
||||||
|
[[:expense-accounts] (expense-accounts-field/default-account (:expense-accounts data)
|
||||||
|
@(re-frame/subscribe [::subs/vendor-default-account value])
|
||||||
|
(:total data)
|
||||||
|
locations)]
|
||||||
|
|
||||||
|
(= [:total] field)
|
||||||
|
[[:expense-accounts] (recalculate-amounts (:expense-accounts data) value)]
|
||||||
|
|
||||||
|
:else
|
||||||
|
[])))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::change-new-invoice-client
|
::add-and-print
|
||||||
(fn [{:keys [db ]} [_ location field value]]
|
[with-user (forms/triggers-loading ::form) (forms/in-form ::form)]
|
||||||
(let [first-location (-> @(re-frame/subscribe [::subs/clients-by-id])
|
(fn [{:keys [user] {:keys [data]} :db} [_ params bank-account-id type]]
|
||||||
(get-in [value :locations])
|
{:graphql
|
||||||
first)]
|
{:token user
|
||||||
{:dispatch [::forms/change ::form
|
:query-obj @(re-frame/subscribe [::add-and-print-query bank-account-id type])
|
||||||
[:client-id] value
|
:on-success [::succeeded params :add-and-print]
|
||||||
[:location] first-location]})))
|
:on-error [::forms/save-error ::form]}}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::change-amount
|
::saving
|
||||||
[(forms/in-form ::form)]
|
[with-user (forms/triggers-loading ::form) (forms/in-form ::form)]
|
||||||
(fn [{{:keys [data]} :db} [_ field value]]
|
(fn [{:keys [user] {:keys [data]} :db} [_ params]]
|
||||||
(print field value (:expense-accounts data))
|
(let [command (if (:id data)
|
||||||
{:dispatch [::forms/change ::form
|
:edit
|
||||||
field value
|
:create)]
|
||||||
[:expense-accounts] (recalculate-amounts (:expense-accounts data) value)]}))
|
{:graphql
|
||||||
|
{:token user
|
||||||
|
:query-obj @(re-frame/subscribe (if (:id data)
|
||||||
(re-frame/reg-event-fx
|
@(re-frame/subscribe [::edit-query])
|
||||||
::change-vendor
|
@(re-frame/subscribe [::create-query])))
|
||||||
[(forms/in-form ::form)]
|
:on-success [::succeeded params command]
|
||||||
(fn [{{:keys [data]} :db} [_ field value]]
|
:on-error [::forms/save-error ::form]}})))
|
||||||
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:client-id data)])]
|
|
||||||
(if (and value (expense-accounts-field/can-replace-with-default? (:expense-accounts data)))
|
|
||||||
{:dispatch [::forms/change ::form
|
|
||||||
field value
|
|
||||||
[:expense-accounts] (expense-accounts-field/default-account (:expense-accounts data)
|
|
||||||
@(re-frame/subscribe [::subs/vendor-default-account value])
|
|
||||||
(:amount data)
|
|
||||||
locations)]}
|
|
||||||
{:dispatch [::forms/change ::form field value]}))))
|
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
|
||||||
::submitted
|
|
||||||
(fn [{:keys [db]} [_ params command bank-account-id type]]
|
|
||||||
(when @(re-frame/subscribe [::can-submit-edit-invoice])
|
|
||||||
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])]
|
|
||||||
{:db (forms/loading db ::form)
|
|
||||||
:graphql
|
|
||||||
{:token (-> db :user)
|
|
||||||
:query-obj @(re-frame/subscribe [::submit-query command bank-account-id type])
|
|
||||||
:on-success [::succeeded params command]
|
|
||||||
:on-error [::forms/save-error ::form]}}))))
|
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::succeeded
|
::succeeded
|
||||||
|
[(forms/triggers-stop ::form)]
|
||||||
(fn [{:keys [db]} [_ {:keys [invoice-created invoice-printed]} command result]]
|
(fn [{:keys [db]} [_ {:keys [invoice-created invoice-printed]} command result]]
|
||||||
(let [invoice (condp = command
|
(let [invoice (condp = command
|
||||||
:edit (:edit-invoice result)
|
:edit (:edit-invoice result)
|
||||||
@@ -191,12 +188,9 @@
|
|||||||
:add-and-print (first (:invoices (:add-and-print-invoice result))))]
|
:add-and-print (first (:invoices (:add-and-print-invoice result))))]
|
||||||
|
|
||||||
{:db (cond-> db
|
{:db (cond-> db
|
||||||
true (forms/stop-form ::form)
|
(#{:create :add-and-print} command) (forms/start-form ::form {:client @(re-frame/subscribe [::subs/client])
|
||||||
|
|
||||||
(#{:create :add-and-print} command) (forms/start-form ::form {:client-id (:id @(re-frame/subscribe [::subs/client]))
|
|
||||||
:status :unpaid
|
:status :unpaid
|
||||||
:date (date->str (c/now) standard)
|
:date (date->str (c/now) standard)}))
|
||||||
:location (first (:locations @(re-frame/subscribe [::subs/client])))}))
|
|
||||||
:dispatch-n (cond-> [(conj invoice-created invoice)]
|
:dispatch-n (cond-> [(conj invoice-created invoice)]
|
||||||
(= :add-and-print command) (conj (conj invoice-printed (:pdf-url (:add-and-print-invoice result)))))})))
|
(= :add-and-print command) (conj (conj invoice-printed (:pdf-url (:add-and-print-invoice result)))))})))
|
||||||
|
|
||||||
@@ -204,119 +198,78 @@
|
|||||||
|
|
||||||
;; VIEWS
|
;; VIEWS
|
||||||
|
|
||||||
|
(def invoice-form (forms/vertical-form {:can-submit [::can-submit]
|
||||||
|
:change-event [::changed]
|
||||||
|
:submit-event [::saving ]
|
||||||
|
:id ::form}))
|
||||||
|
|
||||||
(defn form [{:keys [can-change-amount?] :as params}]
|
(defn form [{:keys [can-change-amount?] :as params}]
|
||||||
[forms/side-bar-form {:form ::form }
|
[layouts/side-bar {:on-close (dispatch-event [::forms/form-closing ::form ])}
|
||||||
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form])
|
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form])
|
||||||
|
{:keys [form field raw-field error-notification submit-button ]} invoice-form
|
||||||
exists? (:id data)
|
exists? (:id data)
|
||||||
current-client @(re-frame/subscribe [::subs/client])
|
|
||||||
can-change-amount? (#{:unpaid ":unpaid"} (:status data))
|
can-change-amount? (#{:unpaid ":unpaid"} (:status data))
|
||||||
change-event [::forms/change ::form]
|
|
||||||
locations (get-in @(re-frame/subscribe [::subs/clients-by-id]) [(:client-id data) :locations])
|
|
||||||
multi-location? (> (count locations) 1)
|
|
||||||
|
|
||||||
min-total (if (= (:total (:original data)) (:outstanding-balance (:original data)))
|
min-total (if (= (:total (:original data)) (:outstanding-balance (:original data)))
|
||||||
nil
|
nil
|
||||||
(- (:total (:original data)) (:outstanding-balance (:original data))))
|
(- (:total (:original data)) (:outstanding-balance (:original data))))
|
||||||
should-select-location? (and locations
|
|
||||||
(> (count locations) 1))
|
|
||||||
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])
|
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])
|
||||||
accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])]
|
accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])]
|
||||||
^{:key id}
|
^{:key id}
|
||||||
[:form { :on-submit (fn [e]
|
[form (assoc params :title "New Invoice")
|
||||||
(when (.-stopPropagation e)
|
|
||||||
(.stopPropagation e)
|
|
||||||
(.preventDefault e))
|
|
||||||
(if exists?
|
|
||||||
(re-frame/dispatch-sync [::submitted params :edit])
|
|
||||||
(re-frame/dispatch-sync [::submitted params :create])))}
|
|
||||||
[:h1.title.is-2 "New Invoice"]
|
|
||||||
(when-not @(re-frame/subscribe [::subs/client])
|
(when-not @(re-frame/subscribe [::subs/client])
|
||||||
[:div.field
|
[field "Client"
|
||||||
[:p.help "Client"]
|
[typeahead-entity {:matches @(re-frame/subscribe [::subs/clients])
|
||||||
[:div.control
|
:match->text :name
|
||||||
[bind-field
|
:type "typeahead"
|
||||||
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/clients]))
|
:auto-focus (if @(re-frame/subscribe [::subs/client]) false true)
|
||||||
:type "typeahead"
|
:field [:client]
|
||||||
:auto-focus (if @(re-frame/subscribe [::subs/client]) false true)
|
:disabled exists?
|
||||||
:field [:client-id]
|
:spec ::invoice/client}]])
|
||||||
:disabled exists?
|
|
||||||
:event [::change-new-invoice-client [::form]]
|
|
||||||
:spec ::invoice/client-id
|
|
||||||
:subscription data}]]]])
|
|
||||||
|
|
||||||
[:div.field
|
|
||||||
[:p.help "Vendor"]
|
|
||||||
[:div.control
|
|
||||||
[bind-field
|
|
||||||
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/vendors]))
|
|
||||||
:type "typeahead"
|
|
||||||
:disabled exists?
|
|
||||||
:auto-focus (if @(re-frame/subscribe [::subs/client]) true false)
|
|
||||||
:field [:vendor-id]
|
|
||||||
:text-event change-event
|
|
||||||
:event [::change-vendor]
|
|
||||||
:spec (s/nilable ::invoice/vendor-id)
|
|
||||||
:subscription data}]]]]
|
|
||||||
|
|
||||||
[:div.field
|
[field "Vendor"
|
||||||
[:p.help "Date"]
|
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
|
||||||
[:div.control
|
:match->text :name
|
||||||
[bind-field
|
:type "typeahead"
|
||||||
[date-picker {:class-name "input"
|
:disabled exists?
|
||||||
:class "input"
|
:auto-focus (if @(re-frame/subscribe [::subs/client]) true false)
|
||||||
:format-week-number (fn [] "")
|
:field [:vendor]}]]
|
||||||
:previous-month-button-label ""
|
|
||||||
:placeholder "mm/dd/yyyy"
|
|
||||||
:next-month-button-label ""
|
|
||||||
:next-month-label ""
|
|
||||||
:type "date"
|
|
||||||
:field [:date]
|
|
||||||
:event change-event
|
|
||||||
:spec ::invoice/date
|
|
||||||
:subscription data}]]]]
|
|
||||||
|
|
||||||
[:div.field
|
[field "Date"
|
||||||
[:p.help "Invoice #"]
|
[date-picker {:class-name "input"
|
||||||
[:div.control
|
:class "input"
|
||||||
[bind-field
|
:format-week-number (fn [] "")
|
||||||
[:input.input {:type "text"
|
:previous-month-button-label ""
|
||||||
:field [:invoice-number]
|
:placeholder "mm/dd/yyyy"
|
||||||
:event change-event
|
:next-month-button-label ""
|
||||||
:spec ::invoice/invoice-number
|
:next-month-label ""
|
||||||
:subscription data}]]]]
|
:type "date"
|
||||||
|
:field [:date]
|
||||||
|
:spec ::invoice/date}]]
|
||||||
|
|
||||||
[:div.field
|
[field "Invoice #"
|
||||||
[:p.help "Total"]
|
[:input.input {:type "text"
|
||||||
[:div.control
|
:field [:invoice-number]
|
||||||
[:div.field.has-addons.is-extended
|
:spec ::invoice/invoice-number}]]
|
||||||
[:p.control [:a.button.is-static "$"]]
|
|
||||||
[:p.control
|
|
||||||
[bind-field
|
|
||||||
[:input.input {:type "number"
|
|
||||||
:field [:total]
|
|
||||||
:disabled (if can-change-amount? "" "disabled")
|
|
||||||
:event [::change-amount]
|
|
||||||
:min min-total
|
|
||||||
:subscription data
|
|
||||||
:spec ::invoice/total
|
|
||||||
:step "0.01"}]]]]]]
|
|
||||||
|
|
||||||
[:div.field
|
|
||||||
[bind-field
|
[field "Total"
|
||||||
[expense-accounts-field {:subscription data
|
[:input.input {:type "number"
|
||||||
:type "expense-accounts"
|
:field [:total]
|
||||||
:descriptor "expense account"
|
:disabled (if can-change-amount? "" "disabled")
|
||||||
:event change-event
|
:min min-total
|
||||||
:locations locations
|
:spec ::invoice/total
|
||||||
:max (:total data)
|
:step "0.01"}]]
|
||||||
:field [:expense-accounts]}]]]
|
|
||||||
|
[field nil
|
||||||
|
[expense-accounts-field {:type "expense-accounts"
|
||||||
|
:descriptor "expense account"
|
||||||
|
:locations (:locations (:client data))
|
||||||
|
:max (:total data)
|
||||||
|
:field [:expense-accounts]}]]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(when error
|
[error-notification]
|
||||||
^{:key error} [:div.notification.is-warning.animated.fadeInUp
|
|
||||||
error])
|
|
||||||
|
|
||||||
[:div.columns
|
[:div.columns
|
||||||
(when-not exists?
|
(when-not exists?
|
||||||
@@ -324,7 +277,7 @@
|
|||||||
[drop-down {:header [:button.button.is-info.is-outlined.is-medium.is-fullwidth {:aria-haspopup true
|
[drop-down {:header [:button.button.is-info.is-outlined.is-medium.is-fullwidth {:aria-haspopup true
|
||||||
:type "button"
|
:type "button"
|
||||||
:on-click (dispatch-event [::events/toggle-menu ::add-and-print-invoice ])
|
:on-click (dispatch-event [::events/toggle-menu ::add-and-print-invoice ])
|
||||||
:disabled (if @(re-frame/subscribe [::can-submit-edit-invoice])
|
:disabled (if @(re-frame/subscribe [::can-submit])
|
||||||
""
|
""
|
||||||
"disabled")
|
"disabled")
|
||||||
|
|
||||||
@@ -338,15 +291,12 @@
|
|||||||
:id ::add-and-print-invoice}
|
:id ::add-and-print-invoice}
|
||||||
[:div
|
[:div
|
||||||
(list
|
(list
|
||||||
(for [{:keys [id number name type]} (->> (:bank-accounts current-client) (filter :visible) (sort-by :sort-order))]
|
(for [{:keys [id number name type]} (->> (:bank-accounts (:client data)) (filter :visible) (sort-by :sort-order))]
|
||||||
(if (= :cash type)
|
(if (= :cash type)
|
||||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::submitted params id :cash])} "With cash"]
|
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::add-and-print params id :cash])} "With cash"]
|
||||||
(list
|
(list
|
||||||
^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event [::submitted params :add-and-print id :check])} "Print checks from " name]
|
^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event [::add-and-print params id :check])} "Print checks from " name]
|
||||||
^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event [::submitted params :add-and-print id :debit])} "Debit from " name]))))]]])
|
^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event [::add-and-print params id :debit])} "Debit from " name]))))]]])
|
||||||
[:div.column
|
[:div.column
|
||||||
[:button.button.is-medium.is-primary.is-fullwidth {:disabled (if @(re-frame/subscribe [::can-submit-edit-invoice])
|
|
||||||
""
|
[submit-button "Save"]]]])])
|
||||||
"disabled")
|
|
||||||
:class (str @(re-frame/subscribe [::forms/loading-class ::form])
|
|
||||||
(when error " animated shake"))} "Save"]] ]])])
|
|
||||||
|
|||||||
@@ -281,7 +281,7 @@
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::new-invoice-clicked
|
::new-invoice-clicked
|
||||||
(fn [{:keys [db]} _]
|
(fn [{:keys [db]} _]
|
||||||
{:dispatch [::form/adding {:client-id (:id @(re-frame/subscribe [::subs/client]))
|
{:dispatch [::form/adding {:client @(re-frame/subscribe [::subs/client])
|
||||||
:status :unpaid
|
:status :unpaid
|
||||||
#_#_:date (date->str (c/now) standard)
|
#_#_:date (date->str (c/now) standard)
|
||||||
:location (first (:locations @(re-frame/subscribe [::subs/client])))}]}))
|
:location (first (:locations @(re-frame/subscribe [::subs/client])))}]}))
|
||||||
|
|||||||
Reference in New Issue
Block a user