Merge branch 'add-general-ledger' of bitbucket.org:brycecovertoperations/integreat into add-general-ledger
This commit is contained in:
@@ -56,9 +56,11 @@
|
||||
(re-frame/reg-event-db
|
||||
::save-error
|
||||
(fn [db [_ form result]]
|
||||
|
||||
(-> db
|
||||
(assoc-in [::forms form :status] :error)
|
||||
(assoc-in [::forms form :error] (:message (first result))))))
|
||||
(assoc-in [::forms form :error] (or (:message (first result))
|
||||
result)))))
|
||||
|
||||
(defn side-bar-form [{:keys [form]} children]
|
||||
[:div [:a.delete.is-pulled-right {:on-click (dispatch-event [::form-closing form])}] [:div children]])
|
||||
@@ -67,3 +69,8 @@
|
||||
(-> db
|
||||
(assoc-in [::forms id :status] :loading)
|
||||
(assoc-in [::forms id :error] nil)))
|
||||
|
||||
(defn save-succeeded [db id]
|
||||
(-> db
|
||||
(assoc-in [::forms id :status] nil)
|
||||
(assoc-in [::forms id :error] nil)))
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
[auto-ap.events :as all-events]
|
||||
[auto-ap.events.admin.clients :as events]
|
||||
[auto-ap.entities.clients :as entity]
|
||||
[auto-ap.forms :as forms]
|
||||
|
||||
[auto-ap.views.components.layouts :refer [side-bar-layout]]
|
||||
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
|
||||
@@ -31,39 +32,36 @@
|
||||
(fn [db [_ field v]]
|
||||
(assoc-in db (into [::excel-import] field) v)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::edit
|
||||
(fn [db [_ field v]]
|
||||
(assoc db ::excel-import nil )
|
||||
db))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::save
|
||||
(fn [{:keys [db]}]
|
||||
(let [excel-import (::excel-import db)]
|
||||
{:http {:token (:user db)
|
||||
[(forms/in-form ::excel-import)]
|
||||
(fn [{{excel-import-data :data :as excel-import-form} :db}]
|
||||
(let [user @(re-frame/subscribe [::subs/token])]
|
||||
{:db (-> excel-import-form
|
||||
(assoc :status :loading)
|
||||
(assoc :error nil))
|
||||
:http {:token user
|
||||
:method :post
|
||||
:body (pr-str excel-import)
|
||||
:body (pr-str excel-import-data)
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:uri (str "/api/invoices/upload-integreat")
|
||||
:on-success [::save-complete]
|
||||
:on-error [::save-error]}
|
||||
:db (-> db
|
||||
(assoc-in [::excel-import :rows] nil)
|
||||
(assoc-in [::excel-import :saving?] true))})))
|
||||
:on-error [::forms/save-error ::excel-import]}})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::save-complete
|
||||
(fn [{:keys [db]} [_ rows]]
|
||||
{:dispatch [::edit nil]
|
||||
:db
|
||||
{:db
|
||||
(-> db
|
||||
(assoc-in [::excel-import :rows] rows)
|
||||
(assoc-in [::excel-import :saving?] false))}))
|
||||
(forms/save-succeeded ::excel-import)
|
||||
(assoc-in [::excel-import :rows] rows))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::save-error
|
||||
(fn [{:keys [db]}]
|
||||
(println "ERROR")
|
||||
{:dispatch [::change [:error] true]
|
||||
:db (-> db
|
||||
(assoc-in [::excel-import :rows] nil)
|
||||
@@ -82,14 +80,20 @@
|
||||
(fn [{:keys [db]}]
|
||||
(let [excel-import (::excel-import db)]
|
||||
(println (::expense-accounts db))
|
||||
{:https {:requests (map (fn [v]
|
||||
{:token (:user db)
|
||||
:method :post
|
||||
:body (pr-str {:name v :default-expense-account (-> db ::expense-accounts (get v) :default-expense-account) })
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:uri (str "/api/vendors/")})
|
||||
(doto (get-in db [::excel-import :create-vendors])
|
||||
println))
|
||||
{:graphql {:token (:user db)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "UpsertVendor"}
|
||||
|
||||
:venia/queries (map (fn [v ]
|
||||
{:query/data [:upsert-vendor
|
||||
{:vendor {:name v :default-expense-account (-> db ::expense-accounts (get v) :default-expense-account)}}
|
||||
[:id :name :default-expense-account
|
||||
[:primary-contact [:name :phone :email :id]]
|
||||
[:secondary-contact [:id :name :phone :email]]
|
||||
:print-as :invoice-reminder-schedule :code
|
||||
[:address [:street1 :street2 :city :state :zip]]]]})
|
||||
|
||||
(get-in db [::excel-import :create-vendors]))}
|
||||
:on-success [::create-vendor-complete]
|
||||
:on-error [::create-vendor-error]}
|
||||
:db (-> db
|
||||
@@ -112,9 +116,12 @@
|
||||
:or {create-vendors #{}}
|
||||
:as excel-import-data} @(re-frame/subscribe [::excel-import])
|
||||
data @(re-frame/subscribe [::expense-accounts])
|
||||
form @(re-frame/subscribe [::forms/form ::excel-import])
|
||||
|
||||
|
||||
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])
|
||||
change-event [::all-events/change-form [::expense-accounts]]]
|
||||
(println form)
|
||||
[:div
|
||||
[:h1.title "Import Invoices from Integreat Excel"]
|
||||
(when (seq vendors-not-found)
|
||||
@@ -161,13 +168,13 @@
|
||||
[:textarea.textarea {:rows "20"
|
||||
:field :excel-rows
|
||||
:type "text"
|
||||
:event ::change
|
||||
:subscription excel-import-data}]]
|
||||
:event [::forms/change ::excel-import]
|
||||
:subscription (:data form)}]]
|
||||
|
||||
[:button.button.is-large.is-pulled-right.is-primary {:on-click (dispatch-event [::save])
|
||||
:class (when (:saving? excel-import-data)
|
||||
"is-loading")
|
||||
:disabled (when (:saving? excel-import-data) "disabled")} "Import"]
|
||||
:class (str @(re-frame/subscribe [::forms/loading-class ::excel-import])
|
||||
(when (:error form) " animated shake"))
|
||||
:disabled (when (= :saving (:status form)) "disabled")} "Import"]
|
||||
|
||||
[:div.is-clearfix]
|
||||
[:div.is-clearfix
|
||||
|
||||
@@ -40,7 +40,9 @@
|
||||
(assoc-in [::params] params))
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj {:venia/queries [[:payment_page
|
||||
(assoc params :client-id (:id @(re-frame/subscribe [::subs/client])))
|
||||
(-> params
|
||||
(assoc :client-id (:id @(re-frame/subscribe [::subs/client])))
|
||||
(dissoc :check-number-like-current))
|
||||
[[:payments [:id :status :amount :type :check_number :s3_url :date [:vendor [:name :id]] [:client [:name :id]]]]
|
||||
:total
|
||||
:start
|
||||
@@ -96,6 +98,27 @@
|
||||
(assoc-in updated [::params :vendor-id] value))
|
||||
updated))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::check-number-like-current-changed
|
||||
(fn [{:keys [db]} [_ params check-like]]
|
||||
{:db (assoc-in db [::params :check-number-like-current] check-like )
|
||||
:dispatch-debounce {:event [::check-number-like-settled check-like]
|
||||
:time 500
|
||||
:key ::check-number-like}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::check-number-like-settled
|
||||
(fn [{:keys [db]} [_ check-like]]
|
||||
{:dispatch [::params-change (assoc (::params db) :check-number-like check-like :start 0) ]}))
|
||||
|
||||
(defn check-number-filter []
|
||||
(let [{:keys [check-number-like-current] :as params} @(re-frame/subscribe [::params])]
|
||||
[:div.field
|
||||
[:div.control [:input.input {:placeholder "10001"
|
||||
:value check-number-like-current
|
||||
:on-change (fn [x]
|
||||
(re-frame/dispatch [::check-number-like-current-changed params (.. x -target -value) ]))} ]]]))
|
||||
|
||||
(defn check-table [{:keys [id payment-page status on-params-change vendors params check-boxes checked on-check-changed expense-event]}]
|
||||
(let [#_#_state (reagent/atom (or @params {}))
|
||||
selected-client @(re-frame/subscribe [::subs/client])
|
||||
@@ -211,8 +234,12 @@
|
||||
(defn checks-page []
|
||||
[side-bar-layout {:side-bar
|
||||
[:div
|
||||
[:p.menu-label "Vendor"]
|
||||
[:p.menu-label "Vendor"]
|
||||
[:div [vendor-filter {:on-change-event [::change-selected-vendor]
|
||||
:value (:vendor-filter @(re-frame/subscribe [::payment-page]))
|
||||
:vendors @(re-frame/subscribe [::subs/vendors])}]]]
|
||||
:vendors @(re-frame/subscribe [::subs/vendors])}]]
|
||||
|
||||
[:p.menu-label "Check #"]
|
||||
[:div [check-number-filter]]
|
||||
]
|
||||
:main [checks-content]}])
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
(ns auto-ap.views.pages.unpaid-invoices
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[reagent.core :as r]
|
||||
[clojure.string :as str]
|
||||
[clojure.string :as str :refer [blank?]]
|
||||
[clojure.spec.alpha :as s]
|
||||
[cljs-time.core :as c]
|
||||
[goog.string :as gstring]
|
||||
@@ -35,6 +35,19 @@
|
||||
[:expense_accounts [:amount :id :expense_account_id
|
||||
:location
|
||||
[:expense_account [:id :name [:parent [:id :name]]]]]]])
|
||||
|
||||
(defn does-amount-exceed-outstanding? [amount outstanding-balance]
|
||||
(let [amount (js/parseFloat amount)
|
||||
outstanding-balance (js/parseFloat outstanding-balance)]
|
||||
(or (and (> outstanding-balance 0)
|
||||
(> amount outstanding-balance))
|
||||
(and (> outstanding-balance 0)
|
||||
(<= amount 0))
|
||||
(and (< outstanding-balance 0)
|
||||
(< amount outstanding-balance))
|
||||
(and (< outstanding-balance 0)
|
||||
(>= amount 0)))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::invoice-page
|
||||
(fn [db]
|
||||
@@ -126,18 +139,16 @@
|
||||
::handwrite-checks
|
||||
(fn [{:keys [db]} _]
|
||||
(let [{:keys [checked invoices]} (get-in db [::invoice-page])
|
||||
invoice (->> invoices
|
||||
(filter (comp checked :id))
|
||||
first)
|
||||
]
|
||||
invoices (->> checked
|
||||
vals
|
||||
(map #(assoc % :amount (:outstanding-balance %))))]
|
||||
|
||||
{:dispatch [::events/modal-status ::handwrite-checks {:visible? true}]
|
||||
:db (-> db
|
||||
(forms/stop-form ::new-invoice)
|
||||
(update-in [::invoice-page :print-checks-shown?] #(not %) )
|
||||
(assoc-in [::handwrite-checks] {:bank-account-id (:id (first @(re-frame/subscribe [::subs/bank-accounts])))
|
||||
:amount (:outstanding-balance invoice)
|
||||
:invoice invoice } ))})))
|
||||
:invoices invoices } ))})))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::cancel-advanced-print
|
||||
@@ -163,6 +174,15 @@
|
||||
(if (= which (:id i))
|
||||
(assoc-in i f v)
|
||||
i))))))
|
||||
(re-frame/reg-event-db
|
||||
::edit-handwritten-payment
|
||||
(fn [db [_ which f v]]
|
||||
(update-in db [::handwrite-checks :invoices]
|
||||
(fn [is]
|
||||
(for [i is]
|
||||
(if (= which (:id i))
|
||||
(assoc-in i f v)
|
||||
i))))))
|
||||
|
||||
(defn print-checks-query [invoice-payments bank-account-id type client-id]
|
||||
{:venia/operation {:operation/type :mutation
|
||||
@@ -310,7 +330,7 @@
|
||||
(re-frame/reg-event-fx
|
||||
::save-and-print-invoice
|
||||
(fn [{:keys [db]} [_ bank-account-id type ]]
|
||||
(println bank-account-id type)
|
||||
|
||||
(when @(re-frame/subscribe [::can-submit-edit-invoice])
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::new-invoice])]
|
||||
{:db (forms/loading db ::new-invoice)
|
||||
@@ -385,7 +405,9 @@
|
||||
(re-frame/reg-event-fx
|
||||
::handwrite-checks-save
|
||||
(fn [{:keys [db]} _]
|
||||
(let [{:keys [date invoice amount check-number bank-account-id]} @(re-frame/subscribe [::handwrite-checks])]
|
||||
(let [{:keys [date invoices check-number bank-account-id]} @(re-frame/subscribe [::handwrite-checks])
|
||||
invoice-amounts (by :id (comp js/parseFloat :amount) invoices)]
|
||||
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
@@ -393,13 +415,22 @@
|
||||
|
||||
:venia/queries [{:query/data [:add-handwritten-check
|
||||
{:date date
|
||||
:amount amount
|
||||
:invoice_payments (map (fn [x]
|
||||
{:invoice-id (:id x)
|
||||
:amount (invoice-amounts (:id x))})
|
||||
invoices)
|
||||
:check-number check-number
|
||||
:bank-account-id bank-account-id
|
||||
:invoice_id (:id invoice)
|
||||
}
|
||||
[[:invoices invoice-read]]]}]}
|
||||
:on-success [::handwrite-checks-succeeded]}})))
|
||||
:on-success [::handwrite-checks-succeeded]
|
||||
:on-error [::handwrite-checks-failed]}})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::handwrite-checks-failed
|
||||
(fn [{:keys [db]} [_ result]]
|
||||
|
||||
{:dispatch [::events/modal-failed ::handwrite-checks (:message (first result))]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::handwrite-checks-succeeded
|
||||
@@ -508,7 +539,10 @@
|
||||
:disabled (cond printing?
|
||||
"disabled"
|
||||
|
||||
(seq (filter #(> (js/parseFloat (:amount %)) (js/parseFloat (:outstanding-balance %))) invoices))
|
||||
(seq (filter
|
||||
(fn [{:keys [outstanding-balance amount]}]
|
||||
(does-amount-exceed-outstanding? amount outstanding-balance ))
|
||||
invoices))
|
||||
"disabled"
|
||||
|
||||
:else
|
||||
@@ -557,7 +591,7 @@
|
||||
::can-submit-edit-invoice
|
||||
:<- [::forms/form ::new-invoice]
|
||||
(fn [{:keys [data status]} _]
|
||||
(println (s/explain-data ::invoice/invoice data))
|
||||
|
||||
(let [min-total (if (= (:total (:original data)) (:outstanding-balance (:original data)))
|
||||
nil
|
||||
(- (:total (:original data)) (:outstanding-balance (:original data))))]
|
||||
@@ -569,15 +603,25 @@
|
||||
|
||||
(defn handwrite-checks-modal []
|
||||
(let [{:keys [checked]} @(re-frame/subscribe [::invoice-page])
|
||||
{:keys [invoice] :as handwrite-checks} @(re-frame/subscribe [::handwrite-checks])
|
||||
{:keys [invoices] :as handwrite-checks} @(re-frame/subscribe [::handwrite-checks])
|
||||
change-event [::events/change-form [::handwrite-checks]]
|
||||
current-client @(re-frame/subscribe [::subs/client])]
|
||||
|
||||
|
||||
[action-modal {:id ::handwrite-checks
|
||||
:title "Handwrite Check"
|
||||
:action-text "Save"
|
||||
:save-event [::handwrite-checks-save]
|
||||
#_#_:can-submit? (s/valid? ::invoice/invoice data)}
|
||||
:can-submit? (cond (seq (filter
|
||||
(fn [{:keys [outstanding-balance amount]}]
|
||||
(does-amount-exceed-outstanding? amount outstanding-balance ))
|
||||
invoices))
|
||||
false
|
||||
|
||||
:else
|
||||
(and (not (blank? (:check-number handwrite-checks)))
|
||||
(not (blank? (:date handwrite-checks)))))
|
||||
}
|
||||
[horizontal-field
|
||||
[:label.label "Pay using"]
|
||||
[:span.select
|
||||
@@ -589,18 +633,9 @@
|
||||
(for [{:keys [id number name]} (->> current-client :bank-accounts (filter #(= (:type %) :check)) (sort-by :sort-order))]
|
||||
^{:key id} [:option {:value id} name])]]]]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Paid amount"]
|
||||
[:div.field.has-addons.is-extended
|
||||
[:p.control [:a.button.is-static "$"]]
|
||||
[:p.control
|
||||
[bind-field
|
||||
[:input.input {:type "number"
|
||||
:field [:amount]
|
||||
:event change-event
|
||||
:subscription handwrite-checks
|
||||
:spec ::invoice/total
|
||||
:step "0.01"}]]]]]
|
||||
|
||||
|
||||
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Date"]
|
||||
@@ -627,7 +662,29 @@
|
||||
:field [:check-number]
|
||||
:event change-event
|
||||
#_#_:spec ::check/date
|
||||
:subscription handwrite-checks}]]]]))
|
||||
:subscription handwrite-checks}]]]
|
||||
[:table.table.is-fullwidth
|
||||
[:thead
|
||||
[:tr
|
||||
[:th "Invoice ID"]
|
||||
[:th {:style {"width" "10em"}} "Payment"]]]
|
||||
[:tbody
|
||||
(for [{:keys [payment outstanding-balance invoice-number id] :as i} invoices]
|
||||
^{:key id}
|
||||
[:tr
|
||||
[:td invoice-number]
|
||||
|
||||
[:td [:div.field.has-addons.is-extended
|
||||
[:p.control [:a.button.is-static "$"]]
|
||||
[:p.control
|
||||
[bind-field
|
||||
[:input.input {:type "number"
|
||||
:field :amount
|
||||
:event [::edit-handwritten-payment id]
|
||||
:subscription i
|
||||
:value payment
|
||||
#_#_:max outstanding-balance
|
||||
:step "0.01"}]]]]]])]]]))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::change-new-invoice-client
|
||||
@@ -816,7 +873,7 @@
|
||||
^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event [::save-and-print-invoice id :check])} "Print checks from " name]
|
||||
^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event [::save-and-print-invoice id :debit])} "Debit from " name]))))]]])
|
||||
[:div.column
|
||||
[:button.button.is-medium.is-primary.is-fullwidth {:disabled (if (doto @(re-frame/subscribe [::can-submit-edit-invoice]) println)
|
||||
[:button.button.is-medium.is-primary.is-fullwidth {:disabled (if @(re-frame/subscribe [::can-submit-edit-invoice])
|
||||
""
|
||||
"disabled")
|
||||
:class (str @(re-frame/subscribe [::forms/loading-class ::new-invoice])
|
||||
@@ -847,7 +904,7 @@
|
||||
{:db (assoc-in db [::params :invoice-number-like-current] invoice-like )
|
||||
:dispatch-debounce {:event [::invoice-number-like-settled invoice-like]
|
||||
:time 500
|
||||
:key ::invoice-nuber-like}}))
|
||||
:key ::invoice-number-like}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invoice-number-like-settled
|
||||
@@ -872,7 +929,7 @@
|
||||
[drop-down {:header [:button.button.is-success {:aria-haspopup true
|
||||
:on-click (dispatch-event [::events/toggle-menu ::print-checks ])
|
||||
:disabled (if (and (seq checked-invoices)
|
||||
(->> checked-invoices
|
||||
#_(->> checked-invoices
|
||||
vals
|
||||
(group-by #(get-in % [:vendor :id]))
|
||||
(reduce-kv (fn [negative? _ invoices]
|
||||
@@ -909,7 +966,7 @@
|
||||
^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :debit])} "Debit from " name])))
|
||||
^{:key "advanced-divider"} [:hr.dropdown-divider]
|
||||
|
||||
(when (= 1 (count checked-invoices))
|
||||
(when (= 1 (count (set (map (comp :id :vendor) (vals checked-invoices)))))
|
||||
^{:key "handwritten"} [:a.dropdown-item {:on-click (dispatch-event [::handwrite-checks])} "Handwritten Check..."])
|
||||
^{:key "advanced"} [:a.dropdown-item {:on-click (dispatch-event [::advanced-print-checks])} "Advanced..."])]])]]
|
||||
[:div.is-pulled-right
|
||||
|
||||
Reference in New Issue
Block a user