diff --git a/resources/Fratello.jpg b/resources/Fratello.jpg new file mode 100644 index 00000000..22e35fb9 Binary files /dev/null and b/resources/Fratello.jpg differ diff --git a/scratch-sessions/delete_fake_data.clj b/scratch-sessions/delete_fake_data.clj new file mode 100644 index 00000000..eb5f8d7c --- /dev/null +++ b/scratch-sessions/delete_fake_data.clj @@ -0,0 +1,11 @@ +(in-ns 'auto-ap.datomic) +(doseq [client (->> + (d/query {:query {:find '[?c] + :in '[$] + :where ['[_ :client/code ?c]]} + :args [(d/db (d/connect uri))]}) + (map first) + (filter #(clojure.string/starts-with? % "ANOT" )))] + @(d/transact (d/connect uri) + [[:db/retractEntity [:client/code client]]]) + ) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 7ab8c784..3fa7b905 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -420,13 +420,26 @@ :edit_transaction {:fields {:id {:type :id} :vendor_id {:type :id} - :account_id {:type :id}}}} + :account_id {:type :id}}} + + :edit_account + {:fields {:id {:type :id} + :type {:type :account_type} + :numeric_code {:type 'Int} + :account_set {:type 'String} + :name {:type 'String}}}} :enums {:payment_type {:values [{:enum-value :check} {:enum-value :cash} {:enum-value :debit}]} :bank_account_type {:values [{:enum-value :check} - {:enum-value :cash}]}} + {:enum-value :cash}]} + :account_type {:values [{:enum-value :dividend} + {:enum-value :expense} + {:enum-value :asset} + {:enum-value :liability} + {:enum-value :equities} + {:enum-value :revenue}]}} :mutations {:reject_invoices {:type '(list :id) :args {:invoices {:type '(list :id)}} @@ -472,6 +485,9 @@ :edit_invoice {:type :invoice :args {:invoice {:type :edit_invoice}} :resolve :mutation/edit-invoice} + :upsert_account {:type :account + :args {:account {:type :edit_account}} + :resolve :mutation/upsert-account} :edit_transaction {:type :transaction :args {:transaction {:type :edit_transaction}} :resolve :mutation/edit-transaction} @@ -647,6 +663,7 @@ :mutation/edit-transaction gq-transactions/edit-transaction :mutation/edit-client gq-clients/edit-client :mutation/upsert-vendor gq-vendors/upsert-vendor + :mutation/upsert-account gq-accounts/upsert-account :mutation/void-invoice gq-invoices/void-invoice :mutation/unvoid-invoice gq-invoices/unvoid-invoice :mutation/void-payment gq-checks/void-check diff --git a/src/clj/auto_ap/graphql/accounts.clj b/src/clj/auto_ap/graphql/accounts.clj index bb4f51b8..0c9d4e91 100644 --- a/src/clj/auto_ap/graphql/accounts.clj +++ b/src/clj/auto_ap/graphql/accounts.clj @@ -2,8 +2,20 @@ (:require [datomic.api :as d] [auto-ap.datomic.accounts :as d-accounts] [auto-ap.graphql.utils :refer [->graphql <-graphql] ] - [auto-ap.datomic :refer [uri merge-query]])) + [auto-ap.datomic :refer [uri merge-query remove-nils]])) (defn get-accounts [context args value] (->graphql (d-accounts/get-accounts (<-graphql args)))) +(defn upsert-account [context args value] + @(d/transact (d/connect uri) + [(remove-nils + {:db/id (:id (:account args)) + :account/name (:name (:account args)) + :account/type (keyword "account-type" (name (:type (:account args)))) + :account/account-set (:account_set (:account args)) + :account/numeric-code (if-not (:id (:account args)) + (:numeric_code (:account args))) + })]) + (:account args)) + diff --git a/src/cljs/auto_ap/views/pages/admin/accounts.cljs b/src/cljs/auto_ap/views/pages/admin/accounts.cljs index 9187e737..152551d0 100644 --- a/src/cljs/auto_ap/views/pages/admin/accounts.cljs +++ b/src/cljs/auto_ap/views/pages/admin/accounts.cljs @@ -1,6 +1,7 @@ (ns auto-ap.views.pages.admin.accounts (:require [auto-ap.forms :as forms] [auto-ap.subs :as subs] + [auto-ap.utils :refer [replace-by]] [auto-ap.views.components.admin.side-bar :refer [admin-side-bar]] [auto-ap.views.utils :refer [dispatch-event]] [auto-ap.views.components.layouts @@ -9,7 +10,11 @@ [auto-ap.views.pages.admin.accounts.form :as account-form] [re-frame.core :as re-frame])) - +(re-frame/reg-event-db + ::edit-completed + (fn [db [_ edit-account]] + (-> db + (update :accounts replace-by :id edit-account)))) (defn accounts-table [{:keys [accounts]} ] @@ -46,4 +51,4 @@ (let [{:keys [active?]} @(re-frame/subscribe [::forms/form ::account-form/form])] [side-bar-layout {:side-bar [admin-side-bar {}] :main [admin-accounts-content] - :right-side-bar [appearing-side-bar {:visible? active?} [account-form/form]]}])) + :right-side-bar [appearing-side-bar {:visible? active?} [account-form/form {:edit-completed [::edit-completed]}]]}])) diff --git a/src/cljs/auto_ap/views/pages/admin/accounts/form.cljs b/src/cljs/auto_ap/views/pages/admin/accounts/form.cljs index 89f3a4b9..0d1fbad2 100644 --- a/src/cljs/auto_ap/views/pages/admin/accounts/form.cljs +++ b/src/cljs/auto_ap/views/pages/admin/accounts/form.cljs @@ -1,21 +1,50 @@ (ns auto-ap.views.pages.admin.accounts.form (:require [auto-ap.forms :as forms] - [auto-ap.subs :as subs] - [auto-ap.views.components.admin.side-bar :refer [admin-side-bar]] + [clojure.string :as str] [auto-ap.views.utils :refer [bind-field dispatch-event]] - [auto-ap.views.components.layouts - :refer - [appearing-side-bar side-bar-layout]] [re-frame.core :as re-frame])) (def types [:dividend :expense :asset :liability :equities :revenue]) + +(re-frame/reg-sub + ::can-submit + (fn [db] + true)) + (re-frame/reg-event-db ::editing (fn [db [_ which]] (-> db (forms/start-form ::form which)))) -(defn form [] +(re-frame/reg-event-fx + ::edited + (fn [{:keys [db]} [_ edit-completed {:keys [upsert-account]}]] + {:db (-> db + (forms/stop-form ::form)) + :dispatch (conj edit-completed upsert-account)})) + +(re-frame/reg-event-fx + ::saving + (fn [{:keys [db]} [_ edit-completed]] + (when @(re-frame/subscribe [::can-submit]) + (let [{{:keys [id type name numeric-code account-set]} :data :as data} @(re-frame/subscribe [::forms/form ::form])] + {:db (forms/loading db ::form ) + :graphql + {:token (-> db :user) + :query-obj {:venia/operation {:operation/type :mutation + :operation/name "UpsertAccount"} + :venia/queries [{:query/data [:upsert-account + {:account {:id id + :type (keyword type) + :numeric-code numeric-code + :name name + :account-set account-set}} + [:id :type :name :account-set :numeric-code]]}]} + :on-success [::edited edit-completed] + :on-error [::forms/save-error ::form]}})))) + +(defn form [{:keys [edit-completed]}] (let [{error :error account :data } @(re-frame/subscribe [::forms/form ::form]) change-event [::forms/change ::form]] @@ -28,6 +57,9 @@ [bind-field [:input.input {:type "text" :field :numeric-code + :disabled (if (:id account) + "disabled" + "") #_:spec #_:entity/name :event change-event :subscription account}]]]] @@ -52,7 +84,9 @@ :spec (set types) :event change-event :subscription account} - (map (fn [l] [:option {:value l} (name l)]) types)]]]]] + (map (fn [l] + + [:option {:value (name l)} (str/capitalize (name l))]) types)]]]]] (when error [:div.notification.is-warning.animated.fadeInUp @@ -62,5 +96,5 @@ [:submit.button.is-large.is-primary {#_:disabled #_(if (s/valid? :entity/client @(re-frame/subscribe [::new-client-request])) "" "disabled") - :on-click (dispatch-event [::account-saving]) + :on-click (dispatch-event [::saving edit-completed]) :class (str @(re-frame/subscribe [::forms/loading-class ::form]) (when error " animated shake"))} "Save"]]]))