due date exists.

This commit is contained in:
Bryce Covert
2020-04-18 09:44:42 -07:00
parent 5f309de2d4
commit b28dd64c4a
7 changed files with 35 additions and 22 deletions

View File

@@ -19,6 +19,7 @@
(defn <-datomic [x] (defn <-datomic [x]
(-> x (-> x
(update :invoice/date c/from-date) (update :invoice/date c/from-date)
(update :invoice/due c/from-date)
(update :invoice/status :db/ident) (update :invoice/status :db/ident)
(rename-keys {:invoice-payment/_invoice :invoice/payments}))) (rename-keys {:invoice-payment/_invoice :invoice/payments})))
@@ -33,6 +34,7 @@
'[?v :vendor/name ?sorter]] '[?v :vendor/name ?sorter]]
"description-original" ['[?e :transaction/description-original ?sorter]] "description-original" ['[?e :transaction/description-original ?sorter]]
"date" ['[?e :invoice/date ?sorter]] "date" ['[?e :invoice/date ?sorter]]
"due" ['[?e :invoice/due ?sorter]]
"invoice-number" ['[?e :invoice/invoice-number ?sorter]] "invoice-number" ['[?e :invoice/invoice-number ?sorter]]
"total" ['[?e :invoice/total ?sorter]] "total" ['[?e :invoice/total ?sorter]]
"outstanding" ['[?e :invoice/outstanding-balance ?sorter]]} "outstanding" ['[?e :invoice/outstanding-balance ?sorter]]}

View File

@@ -143,6 +143,10 @@
:auto-ap/add-terms {:txes [[{:db/ident :vendor/terms :auto-ap/add-terms {:txes [[{:db/ident :vendor/terms
:db/doc "How many days till you pay" :db/doc "How many days till you pay"
:db/valueType :db.type/long :db/valueType :db.type/long
:db/cardinality :db.cardinality/one}]]}
:auto-ap/add-due {:txes [[{:db/ident :invoice/due
:db/doc "When you gotta pay"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}]]}}] :db/cardinality :db.cardinality/one}]]}}]
(println "Conforming database...") (println "Conforming database...")
(c/ensure-conforms conn norms-map) (c/ensure-conforms conn norms-map)

View File

@@ -262,6 +262,7 @@
: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 'String}
:due {:type 'String}
: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,7 +542,7 @@
: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 'String}
:date {:type 'String} :date {: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}

View File

@@ -11,13 +11,13 @@
[datomic.api :as d] [datomic.api :as d]
[auto-ap.datomic :refer [uri remove-nils]] [auto-ap.datomic :refer [uri remove-nils]]
[clj-time.coerce :as coerce] [clj-time.coerce :as coerce]
[clj-time.core :as time]
[clojure.set :as set])) [clojure.set :as set]))
(defn get-invoice-page [context args value] (defn get-invoice-page [context args value]
(println "HI")
(let [args (assoc args :id (:id context)) (let [args (assoc args :id (:id context))
[invoices invoice-count] (d-invoices/get-graphql (<-graphql (assoc args :id (:id context))))] [invoices invoice-count] (d-invoices/get-graphql (<-graphql (assoc args :id (:id context))))]
(println "HELLO" (take 1 invoices ) invoice-count)
[{:invoices (map ->graphql invoices) [{:invoices (map ->graphql invoices)
:total invoice-count :total invoice-count
:count (count invoices) :count (count invoices)
@@ -57,21 +57,25 @@
: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 expense_accounts] :as in}]
(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)
_ (when-not (:db/id account) _ (when-not (:db/id account)
(throw (ex-info (str "Vendor '" (:vendor/name vendor) "' does not have a default expense acount.") {:vendor-id vendor_id} )))] (throw (ex-info (str "Vendor '" (:vendor/name vendor) "' does not have a default expense acount.") {:vendor-id vendor_id} )))]
{:db/id "invoice" (cond->
:invoice/invoice-number invoice_number {:db/id "invoice"
:invoice/client client_id :invoice/invoice-number invoice_number
:invoice/vendor vendor_id :invoice/client client_id
:invoice/import-status :import-status/imported :invoice/vendor vendor_id
:invoice/total total :invoice/import-status :import-status/imported
:invoice/outstanding-balance total :invoice/total total
:invoice/status :invoice-status/unpaid :invoice/outstanding-balance total
:invoice/date (coerce/to-date date) :invoice/status :invoice-status/unpaid
:invoice/expense-accounts (map expense-account->entity :invoice/date (coerce/to-date date)
expense_accounts)})) :invoice/expense-accounts (map expense-account->entity
expense_accounts)}
(:vendor/terms vendor) (assoc :invoice/due (coerce/to-date
(time/plus date (time/days (:vendor/terms vendor))))))))
(defn deleted-expense-accounts [invoice expense-accounts] (defn deleted-expense-accounts [invoice expense-accounts]

View File

@@ -46,7 +46,7 @@
{:venia/queries [[:invoice_page {:venia/queries [[:invoice_page
(assoc params (assoc params
:client-id (:id @(re-frame/subscribe [::subs/client]))) :client-id (:id @(re-frame/subscribe [::subs/client])))
[[:invoices [:id :total :outstanding-balance :invoice-number :date :status :client-identifier [[:invoices [:id :total :outstanding-balance :invoice-number :date :due :status :client-identifier
[:vendor [:name :id]] [:vendor [:name :id]]
[:expense_accounts [:amount :id :location [:expense_accounts [:amount :id :location
[:account [:id :name :numeric-code :location ]]]] [:account [:id :name :numeric-code :location ]]]]
@@ -108,6 +108,12 @@
:sort-by sort-by :sort-by sort-by
:asc asc} :asc asc}
"Date"] "Date"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "due"
:sort-by sort-by
:asc asc}
"Due"]
[sorted-column {:on-sort opc [sorted-column {:on-sort opc
:style {:width "5em" :cursor "pointer"} :style {:width "5em" :cursor "pointer"}
:sort-key "location" :sort-key "location"
@@ -143,7 +149,7 @@
[:td {:col-span 5} [:td {:col-span 5}
[:i.fa.fa-spin.fa-spinner]]] [:i.fa.fa-spin.fa-spinner]]]
(for [{:keys [client payments expense-accounts invoice-number date total outstanding-balance id vendor] :as i} (:invoices @invoice-page)] (for [{:keys [client payments expense-accounts invoice-number date due total outstanding-balance id vendor] :as i} (:invoices @invoice-page)]
^{:key id} ^{:key id}
[:tr {:class (:class i)} [:tr {:class (:class i)}
(when check-boxes (when check-boxes
@@ -161,6 +167,7 @@
[:td (:name vendor)] [:td (:name vendor)]
[:td invoice-number] [:td invoice-number]
[:td (date->str date) ] [:td (date->str date) ]
[:td (date->str due) ]
[:td (str/join ", " (set (map :location expense-accounts)))] [:td (str/join ", " (set (map :location expense-accounts)))]
[:td.has-text-right (nf total )] [:td.has-text-right (nf total )]

View File

@@ -1,6 +1,6 @@
(ns auto-ap.views.pages.invoices.common) (ns auto-ap.views.pages.invoices.common)
(def invoice-read [:id :total :outstanding-balance :date :invoice-number :status (def invoice-read [:id :total :outstanding-balance :date :due :invoice-number :status
[:client [:id :name :locations]] [:client [:id :name :locations]]
[:payments [:amount [:payment [:amount :s3_url :check_number ]]]] [:payments [:amount [:payment [:amount :s3_url :check_number ]]]]
[:vendor [:id :name]] [:vendor [:id :name]]

View File

@@ -80,7 +80,6 @@
(re-frame/reg-event-db (re-frame/reg-event-db
::invoice-updated ::invoice-updated
(fn [db [_ invoice]] (fn [db [_ invoice]]
(println "HERE")
(update-in db (update-in db
[::invoice-page :invoices] [::invoice-page :invoices]
replace-by :id (assoc invoice :class "live-added")))) replace-by :id (assoc invoice :class "live-added"))))
@@ -699,10 +698,6 @@
:on-check-changed (fn [which invoice] :on-check-changed (fn [which invoice]
(re-frame/dispatch [::toggle-check which invoice])) (re-frame/dispatch [::toggle-check which invoice]))
:expense-event [::expense-accounts-dialog/change-expense-accounts]}] :expense-event [::expense-accounts-dialog/change-expense-accounts]}]
])) ]))
:component-will-mount #(re-frame/dispatch-sync [::params-change params]) })) :component-will-mount #(re-frame/dispatch-sync [::params-change params]) }))