invoice fixups.

This commit is contained in:
2021-12-10 07:42:50 -08:00
parent 4a7215a74b
commit 35e7dda7af
4 changed files with 60 additions and 41 deletions

View File

@@ -214,7 +214,7 @@
(try (try
(f entry) (f entry)
(catch Exception e (catch Exception e
(log/warn e) (log/warn (.getMessage e))
(assoc entry :error (.getMessage e) (assoc entry :error (.getMessage e)
:status (or (:status (ex-data e)) :status (or (:status (ex-data e))
:error)))))) :error))))))
@@ -371,6 +371,7 @@
retraction (mapv (fn [x] [:db/retractEntity [:journal-entry/external-id (:external_id x)]]) retraction (mapv (fn [x] [:db/retractEntity [:journal-entry/external-id (:external_id x)]])
success)] success)]
(log/info "manual ledger import has " (count success) " new rows") (log/info "manual ledger import has " (count success) " new rows")
(log/info errors)
(audit-transact-batch retraction (:id context)) (audit-transact-batch retraction (:id context))

View File

@@ -166,7 +166,10 @@
:total #"Total\s+([0-9\.,]+)" :total #"Total\s+([0-9\.,]+)"
:account-number #"Customer No.\s+(.*?)\s{2}"} :account-number #"Customer No.\s+(.*?)\s{2}"}
:parser {:date [:clj-time "MM/dd/yy"] :parser {:date [:clj-time "MM/dd/yy"]
:total [:trim-commas nil]}} :total [:trim-commas nil]}
:multi (. java.util.regex.Pattern (compile (-> \formfeed str) java.util.regex.Pattern/CASE_INSENSITIVE))
:multi-match? #"Customer No\."
}
;; AUTO-CHLOR ;; AUTO-CHLOR
{:vendor "Auto-Chlor" {:vendor "Auto-Chlor"
@@ -211,6 +214,18 @@
:parser {:date [:clj-time "MM/dd/yy"] :parser {:date [:clj-time "MM/dd/yy"]
:total [:trim-commas-and-negate nil]}} :total [:trim-commas-and-negate nil]}}
;;; credits don't have the same format
{:vendor "General Produce Company"
:keywords [#"1330 NORTH B"]
:extract {:date #"DATE.*\n.*\n.*?([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"SPECIAL INSTRUCTIONS.*\n\s+(.*?)\s{2,}"
:invoice-number #"CREDIT NO.*\n.*\n.*?(\d{5,}?)\s+"
:account-number #"CUST NO.*\n.*\n\s+(\d+)"
:total #"TOTAL:\s+\|\s*(.*)"}
:parser {:date [:clj-time "MM/dd/yy"]
:total [:trim-commas-and-negate nil]}}
;; Young's Market Co new statement ;; Young's Market Co new statement
{:vendor "Youngs Market" {:vendor "Youngs Market"
:keywords [#"(YOUNG'S MARKET COMPANY|Young.*Statement)"] :keywords [#"(YOUNG'S MARKET COMPANY|Young.*Statement)"]

View File

@@ -367,8 +367,8 @@
(log/info "COUNT" (count (transactions->txs transactions transaction->bank-account (rm/rule-applying-fn all-rules) (get-existing)))) (log/info "COUNT" (count (transactions->txs transactions transaction->bank-account (rm/rule-applying-fn all-rules) (get-existing))))
(doseq [tx (transactions->txs transactions transaction->bank-account (rm/rule-applying-fn all-rules) (get-existing))] (doseq [tx (transactions->txs transactions transaction->bank-account (rm/rule-applying-fn all-rules) (get-existing))]
(log/info "transacting" tx)
(audit-transact tx {:user/name "Yodlee import" (audit-transact tx {:user/name "Yodlee import2"
:user/role ":admin"}))))))) :user/role ":admin"})))))))

View File

@@ -646,70 +646,73 @@
[(Long/parseLong k) [(Long/parseLong k)
(reduce + 0.0 (reduce + 0.0
(->> values (->> values
(map (fn [[_ _ amount]] (map (fn [[_ _ _ _ amount]]
(- (Double/parseDouble amount)))))) (- (Double/parseDouble amount))))))
])) ]))
(into {}))] (into {}))]
(->> (->>
(for [[invoice-id expense-account-id amount expense-account location] (drop 1 data) (for [[invoice-id invoice-expense-account-id target-account _ amount expense-account location] (drop 1 data)
:let [ :let [
invoice-id (Long/parseLong invoice-id) invoice-id (Long/parseLong invoice-id)
invoice (d/entity db invoice-id) invoice (d/entity db invoice-id)
current-total (:invoice/total invoice) current-total (:invoice/total invoice)
target-total (invoice-totals invoice-id) target-total (invoice-totals invoice-id) ;; TODO should include expense accounts not visible
new-account? (not (boolean (or (some-> invoice-expense-account-id not-empty Long/parseLong)
(:db/id (first (:invoice/expense-accounts invoice))))))
expense-account-id (Long/parseLong expense-account-id) invoice-expense-account-id (or (some-> invoice-expense-account-id not-empty Long/parseLong)
current-expense-account-code (:account/numeric-code (:invoice-expense-account/account (d/entity db expense-account-id))) (:db/id (first (:invoice/expense-accounts invoice)))
target-expense-account-code (Long/parseLong (str/trim expense-account)) (d/tempid :db.part/user))
[[target-expense-account-id]] (vec (d/q invoice-expense-account (when-not new-account?
'[:find ?a (d/entity db invoice-expense-account-id))
:in $ ?c current-account-id (:db/id (:invoice-expense-account/account invoice-expense-account))
:where [?a :account/numeric-code ?c] target-account-id (Long/parseLong (str/trim target-account))
]
db target-expense-account-code))
current-expense-account-amount (:invoice-expense-account/amount (d/entity db expense-account-id)) current-expense-account-amount (:invoice-expense-account/amount invoice-expense-account)
target-expense-account-amount (- (Double/parseDouble amount)) target-expense-account-amount (- (Double/parseDouble amount))
current-expense-account-location (:invoice-expense-account/location (d/entity db expense-account-id)) current-expense-account-location (:invoice-expense-account/location invoice-expense-account)
target-expense-account-location location target-expense-account-location location
[[payment-id payment-amount]] (vec (d/q [[payment-id payment-amount invoice-payment]] (vec (d/q
'[:find ?p ?a '[:find ?p ?a ?ip
:in $ ?i :in $ ?i
:where [?ip :invoice-payment/invoice ?i] :where [?ip :invoice-payment/invoice ?i]
[?ip :invoice-payment/amount ?a] [?ip :invoice-payment/amount ?a]
[?ip :invoice-payment/payment ?p] [?ip :invoice-payment/payment ?p]
] ]
db invoice-id))]] db invoice-id))]]
[ [
(when (not (auto-ap.utils/dollars= current-total target-total)) (when (not (auto-ap.utils/dollars= current-total target-total))
(if payment-id {:db/id invoice-id
(println "Cannot update" invoice-id " of " current-total "to be" target-total "because it has a payment (" payment-id ") of" payment-amount ) :invoice/total target-total})
{:db/id invoice-id
:invoice/total target-total}))
(when (and (not (auto-ap.utils/dollars= current-expense-account-amount target-expense-account-amount)) {:db/id invoice-id
(or (auto-ap.utils/dollars= current-total target-total) :invoice/expense-accounts invoice-expense-account-id}
(not payment-id)))
{:db/id expense-account-id (when (and
(not (auto-ap.utils/dollars= current-total target-total))
invoice-payment)
[:db/retractEntity invoice-payment])
(when (or new-account?
(not (auto-ap.utils/dollars= current-expense-account-amount target-expense-account-amount)))
{:db/id invoice-expense-account-id
:invoice-expense-account/amount target-expense-account-amount}) :invoice-expense-account/amount target-expense-account-amount})
(when (not= current-expense-account-location (when (not= current-expense-account-location
target-expense-account-location) target-expense-account-location)
{:db/id expense-account-id {:db/id invoice-expense-account-id
:invoice-expense-account/location target-expense-account-location}) :invoice-expense-account/location target-expense-account-location})
(when (not= target-expense-account-code current-expense-account-code ) (when (not= current-account-id target-account-id )
{:db/id expense-account-id {:db/id invoice-expense-account-id
:invoice-expense-account/account target-expense-account-id})] :invoice-expense-account/account target-account-id})])
#_(println (auto-ap.utils/dollars= current-total amount) current-total amount current-expense-account-code expense-account-code)
)
(mapcat identity) (mapcat identity)
(filter identity) (filter identity)
vec))) vec)))