you can now change types.
This commit is contained in:
@@ -29,3 +29,16 @@
|
||||
[:= :i.id :nonexist.invoice-id]]
|
||||
:where [:and [:= :nonexist.id nil]
|
||||
[:not= :v.default-expense-account nil]] }] })))
|
||||
|
||||
(defn replace-for-invoice [invoice-id expense-accounts]
|
||||
(j/db-do-prepared (get-conn)
|
||||
(sql/format {:delete-from [:invoices-expense-accounts :i]
|
||||
:where [:= :i.invoice-id invoice-id] }))
|
||||
|
||||
(println expense-accounts)
|
||||
(j/insert-multi! (get-conn)
|
||||
:invoices_expense_accounts
|
||||
(doto (->> expense-accounts
|
||||
(map (fn [x] (assoc x :invoice-id invoice-id)))
|
||||
(map clj->db ))
|
||||
println)) )
|
||||
|
||||
@@ -160,6 +160,11 @@
|
||||
:role {:type 'String}
|
||||
:companies {:type '(list Int)}}}
|
||||
|
||||
:edit_expense_account
|
||||
{:fields {:id {:type 'Int}
|
||||
:expense_account_id {:type 'Int}
|
||||
:amount {:type 'String}}}
|
||||
|
||||
:add_invoice
|
||||
{:fields {:id {:type 'Int}
|
||||
:invoice_number {:type 'String}
|
||||
@@ -180,7 +185,11 @@
|
||||
|
||||
:add_invoice {:type :invoice
|
||||
:args {:invoice {:type :add_invoice}}
|
||||
:resolve :mutation/add-invoice}}})
|
||||
:resolve :mutation/add-invoice}
|
||||
:edit_expense_accounts {:type :invoice
|
||||
:args {:invoice_id {:type 'Int}
|
||||
:expense_accounts {:type '(list :edit_expense_account)}}
|
||||
:resolve :mutation/edit-expense-accounts}}})
|
||||
|
||||
|
||||
|
||||
@@ -327,6 +336,7 @@
|
||||
:mutation/print-checks print-checks
|
||||
:mutation/edit-user gq-users/edit-user
|
||||
:mutation/add-invoice gq-invoices/add-invoice
|
||||
:mutation/edit-expense-accounts gq-invoices/edit-expense-accounts
|
||||
:get-vendor get-vendor
|
||||
:get-expense-account expense-accounts/get-expense-account
|
||||
:get-expense-account-parent expense-accounts/get-parent})
|
||||
|
||||
@@ -21,3 +21,12 @@
|
||||
(defn get-invoices-expense-accounts [context args value]
|
||||
(->graphql
|
||||
(invoices-expense-accounts/get-for-invoice (:id value))))
|
||||
|
||||
(defn edit-expense-accounts [context args value]
|
||||
(invoices-expense-accounts/replace-for-invoice (:invoice_id args) (map (fn [{:keys [id expense_account_id amount]}]
|
||||
{
|
||||
:expense-account-id expense_account_id
|
||||
:amount (Double/parseDouble amount)} )
|
||||
(:expense_accounts args)))
|
||||
(->graphql
|
||||
(invoices/get-by-id (:invoice_id args))))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
(ns auto-ap.subs
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.expense-accounts :refer [expense-accounts]]
|
||||
[goog.crypt.base64 :as base64]))
|
||||
|
||||
(re-frame/reg-sub
|
||||
@@ -72,3 +73,10 @@
|
||||
::new-invoice-form
|
||||
(fn [db]
|
||||
(:new-invoice db)))
|
||||
|
||||
|
||||
(re-frame/reg-sub
|
||||
::expense-accounts
|
||||
(fn [db]
|
||||
(map (fn [[k v]] (assoc v :id k))
|
||||
expense-accounts)))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
(ns auto-ap.views.components.invoice-table
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.utils :refer [date->str]]
|
||||
[auto-ap.views.utils :refer [date->str dispatch-event]]
|
||||
[auto-ap.views.components.paginator :refer [paginator]]
|
||||
[auto-ap.views.components.sorter :refer [sorted-column]]
|
||||
[reagent.core :as reagent]
|
||||
@@ -22,7 +22,7 @@
|
||||
:company-id (:id @(re-frame/subscribe [::subs/company])))
|
||||
[[:invoices [:id :total :outstanding-balance :invoice-number :date
|
||||
[:vendor [:name :id]]
|
||||
[:expense_accounts [:amount :id
|
||||
[:expense_accounts [:amount :id :expense_account_id
|
||||
[:expense_account [:id :name [:parent [:id :name]]]]]]
|
||||
[:company [:name :id]]
|
||||
[:checks [:amount [:check [:amount :s3_url :check_number ]]]]
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
|
||||
|
||||
(defn invoice-table [{:keys [id invoice-page status on-params-change vendors params check-boxes checked on-check-changed]}]
|
||||
(defn invoice-table [{:keys [id invoice-page status on-params-change vendors params check-boxes checked on-check-changed expense-event]}]
|
||||
(let [state (reagent/atom (or @params {}))
|
||||
opc (fn [p]
|
||||
(swap! state merge p)
|
||||
@@ -121,7 +121,7 @@
|
||||
[:td (gstring/format "$%.2f" outstanding-balance )]
|
||||
[:td (for [e expense-accounts]
|
||||
^{:key (:id e)}
|
||||
[:a.tag (:name (:expense-account e)) " "(gstring/format "$%.2f" (:amount e) ) ])]
|
||||
[:a.tag {:on-click (dispatch-event (conj expense-event id))} (:name (:expense-account e)) " "(gstring/format "$%.2f" (:amount e) ) ])]
|
||||
[:td (for [check checks]
|
||||
^{:key (:id check)}
|
||||
[:a.tag {:href (:s3-url (:check check)) :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " (:check-number (:check check)) " (" (gstring/format "$%.2f" (:amount check) ) ")")])]]))]]]))))
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
[auto-ap.entities.invoice :as invoice]
|
||||
[auto-ap.entities.vendors :as vendor]
|
||||
[auto-ap.views.utils :refer [dispatch-event bind-field horizontal-field]]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[auto-ap.utils :refer [by replace-if]]
|
||||
[auto-ap.views.pages.check :as check]
|
||||
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
|
||||
[auto-ap.views.components.modal :refer [modal action-modal]]
|
||||
@@ -21,11 +21,22 @@
|
||||
(fn [db]
|
||||
(-> db ::invoice-page)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::invoice
|
||||
(fn [db id]
|
||||
(println id)
|
||||
(get (by :id (-> db ::invoice-page :invoices )) id)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::advanced-print-checks
|
||||
(fn [db]
|
||||
(-> db ::advanced-print-checks)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::change-expense-accounts
|
||||
(fn [db]
|
||||
(-> db ::change-expense-accounts)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::check-results
|
||||
(fn [db]
|
||||
@@ -218,6 +229,104 @@
|
||||
is)))
|
||||
(dissoc ::new-invoice))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::change-expense-accounts
|
||||
(fn [{:keys [db]} [_ id]]
|
||||
{:dispatch [::events/modal-status ::change-expense-accounts {:visible? true}]
|
||||
:db (assoc-in db [::change-expense-accounts :invoice] (get (by :id (get-in db [::invoice-page :invoices])) id))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::change-expense-accounts-saving
|
||||
(fn [{:keys [db]} [_ id]]
|
||||
(let [{:keys [id expense-accounts]} (get-in db [::change-expense-accounts :invoice])]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "EditExpenseAccounts"}
|
||||
|
||||
:venia/queries [{:query/data [:edit-expense-accounts
|
||||
{:invoice-id id
|
||||
:expense-accounts (map (fn [ea] {:id (:id ea)
|
||||
:amount (:amount ea)
|
||||
:expense-account-id (:expense-account-id ea)})
|
||||
expense-accounts)}
|
||||
[:id :total :outstanding-balance :invoice-number :date
|
||||
[:vendor [:name :id]]
|
||||
[:expense_accounts [:amount :id :expense_account_id
|
||||
[:expense_account [:id :name [:parent [:id :name]]]]]]
|
||||
[:company [:name :id]]
|
||||
[:checks [:amount [:check [:amount :s3_url :check_number ]]]]
|
||||
]]}]}
|
||||
:on-success [::expense-accounts-updated]}})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::expense-accounts-updated
|
||||
(fn [{:keys [db]} [_ data]]
|
||||
(let [updated (:edit-expense-accounts data)]
|
||||
{:dispatch [::events/modal-completed ::change-expense-accounts]
|
||||
:db (-> db
|
||||
(update-in [::invoice-page :invoices]
|
||||
|
||||
(fn [is]
|
||||
(println "UPDATE" updated is)
|
||||
(replace-if #(= (:id %1) (:id %2)) updated is)))
|
||||
(dissoc ::change-expense-accounts))})))
|
||||
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::add-expense-account-split
|
||||
(fn [db _]
|
||||
(update-in db [::change-expense-accounts :invoice :expense-accounts]
|
||||
conj {:amount 0 :expense-account-id nil})))
|
||||
|
||||
(defn change-expense-accounts-modal []
|
||||
(let [{{:keys [expense-accounts]} :invoice :as data} @(re-frame/subscribe [::change-expense-accounts])
|
||||
change-event [::events/change-form [::change-expense-accounts]]]
|
||||
[action-modal {:id ::change-expense-accounts
|
||||
:title "Change expense accounts"
|
||||
:action-text "Save"
|
||||
:save-event [::change-expense-accounts-saving]
|
||||
#_#_:can-submit? (s/valid? ::invoice/invoice data)}
|
||||
|
||||
[:div
|
||||
[:a.button.is-primary {:on-click (dispatch-event [::add-expense-account-split])} "Add split"]]
|
||||
[:table.table
|
||||
[:thead
|
||||
[:tr
|
||||
[:th {:style {:width "500px"}} "Expense Account"]
|
||||
[:th {:style {:width "300px"}} "Amount"]
|
||||
[:th {:style {:width "5em"}}]]]
|
||||
[:tbody
|
||||
(for [[expense-account index] (map vector expense-accounts (range))]
|
||||
[:tr
|
||||
[:td [:div.control
|
||||
[bind-field
|
||||
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/expense-accounts]))
|
||||
:type "typeahead"
|
||||
:field [:invoice :expense-accounts index :expense-account-id]
|
||||
:event change-event
|
||||
:spec ::invoice/vendor-id
|
||||
:subscription data}]]]]
|
||||
|
||||
|
||||
[:td
|
||||
[:div.control
|
||||
[:div.field.has-addons.is-extended
|
||||
[:p.control [:a.button.is-static "$"]]
|
||||
[:p.control
|
||||
[bind-field
|
||||
[:input.input {:type "number"
|
||||
:field [:invoice :expense-accounts index :amount]
|
||||
:event change-event
|
||||
:subscription data
|
||||
:value (doto (get-in data [:invoice :expense-accounts index :amount]) println)
|
||||
|
||||
:max (:total data)
|
||||
:step "0.01"}]]]]]]
|
||||
[:td [:a.button [:i.fa.fa-times]]]]
|
||||
)]]]))
|
||||
|
||||
|
||||
(defn print-checks-modal []
|
||||
(let [{:keys [checked]} @(re-frame/subscribe [::invoice-page])
|
||||
{:keys [shown? invoices printing?] :as advanced-print-checks} @(re-frame/subscribe [::advanced-print-checks])
|
||||
@@ -337,6 +446,9 @@
|
||||
:spec ::invoice/total
|
||||
:step "0.01"}]]]]]]))
|
||||
|
||||
|
||||
|
||||
|
||||
(def unpaid-invoices-page
|
||||
(with-meta
|
||||
(fn []
|
||||
@@ -379,10 +491,12 @@
|
||||
:check-boxes true
|
||||
:checked checked
|
||||
:on-check-changed (fn [which]
|
||||
(re-frame/dispatch [::toggle-check which]))}]
|
||||
(re-frame/dispatch [::toggle-check which]))
|
||||
:expense-event [::change-expense-accounts]}]
|
||||
|
||||
[print-checks-modal]
|
||||
[new-invoice-modal]
|
||||
[change-expense-accounts-modal]
|
||||
(when check-results-shown?
|
||||
[modal
|
||||
{:title "Your checks are ready!"
|
||||
|
||||
@@ -105,6 +105,7 @@
|
||||
]
|
||||
(into
|
||||
[:div.field-body]
|
||||
|
||||
(with-keys (map (fn [x] [:div.field x]) controls)))])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user