Add a demo mode

Use with `--demo`.
This commit is contained in:
Ben Sturmfels 2024-03-15 17:17:41 +11:00
parent 11626fb3d4
commit ea57f67f7c
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0
5 changed files with 30 additions and 12 deletions

2
.gitignore vendored
View file

@ -1,4 +1,4 @@
/src/examples.clj /private/
/.cpcache/ /.cpcache/
/target/ /target/
/.nrepl-port /.nrepl-port

View file

@ -7,13 +7,19 @@ intricate Beancount bookkeeping data.
## Usage ## Usage
Run with: See a demo with:
java -jar import-0.0.8-standalone.jar --csv resources/example-paychex-pay-item-details.csv --date 2023-12-29 --period 'December 2023' --total-fees 206.50 --pay-receipt-no rt:19462/674660 --pay-invoice-no rt:19403/675431 --fees-receipt-no rt:19459/675387 --fees-invoice-no rt:19459/674887 --retirement-receipt-no rt:19403/676724 --retirement-invoice-no rt:19403/675431 java -jar import-x.x.x-standalone.jar --demo
Or simpler (missing options will be replaced by "TODO" in the output): Provide your own payroll data with:
java -jar import-0.0.8-standalone.jar --csv resources/example-paychex-pay-item-details.csv --total-fees 206.50 java -jar import-x.x.x-standalone.jar --csv resources/example-paychex-pay-item-details.csv --total-fees 206.50
In the above, various values such as the date, time period covered and
receipt/invoice values will be replace with "TODO" placeholders. You can
alternatively provide any/all of these explicitly:
java -jar import-x.x.x-standalone.jar --csv resources/example-paychex-pay-item-details.csv --date 2023-12-29 --period 'December 2023' --total-fees 206.50 --pay-receipt-no rt:19462/674660 --pay-invoice-no rt:19403/675431 --fees-receipt-no rt:19459/675387 --fees-invoice-no rt:19459/674887 --retirement-receipt-no rt:19403/676724 --retirement-invoice-no rt:19403/675431
You can test the output in Beancount by adding the following header entries to define the accounts: You can test the output in Beancount by adding the following header entries to define the accounts:

View file

@ -14,7 +14,9 @@
(defn uber [_] (defn uber [_]
(clean nil) (clean nil)
(b/copy-dir {:src-dirs ["src"] (b/copy-dir {:src-dirs ["src" "resources"]
:target-dir class-dir})
(b/copy-dir {:src-dirs ["src" "resources"]
:target-dir class-dir}) :target-dir class-dir})
(b/compile-clj {:basis @basis (b/compile-clj {:basis @basis
:ns-compile '[core] :ns-compile '[core]

View file

@ -1,4 +1,4 @@
{:paths ["src" "resources"] {:paths ["src" "resources" "private"] ;; Private is not include in the build
:deps { :deps {
org.clojure/clojure {:mvn/version "1.11.1"} org.clojure/clojure {:mvn/version "1.11.1"}
org.clojure/data.csv {:mvn/version "1.0.1"} org.clojure/data.csv {:mvn/version "1.0.1"}

View file

@ -3,7 +3,8 @@
(ns core (ns core
"Beancount importer for Paychex Pay Item Details report." "Beancount importer for Paychex Pay Item Details report."
(:require [clojure.set :as set] (:require [clojure.java.io :as io]
[clojure.set :as set]
[clojure.string :as str] [clojure.string :as str]
[clojure.tools.cli :refer [parse-opts]] [clojure.tools.cli :refer [parse-opts]]
[import :as import]) [import :as import])
@ -37,6 +38,7 @@
:parse-fn #(str/split % #":") :parse-fn #(str/split % #":")
:default {} :default {}
:assoc-fn (fn [m k [name proj]] (assoc-in m [k name] proj))] :assoc-fn (fn [m k [name proj]] (assoc-in m [k name] proj))]
[nil "--demo" "Produce demo output based made-up payroll data. Useful for documentation."]
["-h" "--help"]]) ["-h" "--help"]])
(defn unmatched-employees (defn unmatched-employees
@ -44,9 +46,15 @@
[records projects] [records projects]
(set/difference (set (keys projects)) (->> records (map :name) set))) (set/difference (set (keys projects)) (->> records (map :name) set)))
(def demo-options
{:csv (io/resource "example-paychex-pay-item-details.csv")
:date "2024-01-01"
:period "January 2024"
:total-fees 66.67M})
(defn -main [& args] (defn -main [& args]
(let [{:keys [options errors summary]} (parse-opts args cli-options) (let [{:keys [options errors summary]} (parse-opts args cli-options)
{:keys [date period pay-receipt-no pay-invoice-no total-fees fees-receipt-no fees-invoice-no retirement-receipt-no retirement-invoice-no project]} options] options (if (:demo options) (merge options demo-options) options)]
(when (:help options) (when (:help options)
(println summary) (println summary)
(System/exit 0)) (System/exit 0))
@ -55,12 +63,14 @@
(str "The following errors occurred while parsing your command:\n\n" (str "The following errors occurred while parsing your command:\n\n"
(str/join \newline errors))) (str/join \newline errors)))
(System/exit 1)) (System/exit 1))
(let [records (import/read-csv (:csv options)) (let [{:keys [date period pay-receipt-no pay-invoice-no total-fees project]} options
{:keys [fees-receipt-no fees-invoice-no retirement-receipt-no retirement-invoice-no]} options
records (import/read-csv (:csv options))
imported (concat (import/net-pay date period pay-invoice-no project records) imported (concat (import/net-pay date period pay-invoice-no project records)
(import/individual-taxes date period pay-invoice-no retirement-invoice-no project records) (import/individual-taxes date period pay-invoice-no retirement-invoice-no project records)
(import/employer-taxes date period pay-invoice-no project records) (import/employer-taxes date period pay-invoice-no project records)
(import/net-pay-ach-debit date period pay-receipt-no pay-invoice-no {} records) (import/net-pay-ach-debit date period pay-receipt-no pay-invoice-no project records)
(import/taxes-ach-debit date period pay-receipt-no pay-invoice-no {} records) (import/taxes-ach-debit date period pay-receipt-no pay-invoice-no project records)
(import/fees date period fees-receipt-no fees-invoice-no total-fees project records) (import/fees date period fees-receipt-no fees-invoice-no total-fees project records)
(import/retirement date period retirement-receipt-no retirement-invoice-no records)) (import/retirement date period retirement-receipt-no retirement-invoice-no records))
unmatched (unmatched-employees records project)] unmatched (unmatched-employees records project)]