Compare commits
2 commits
5b8951c0f0
...
3e665a4141
| Author | SHA1 | Date | |
|---|---|---|---|
| 3e665a4141 | |||
| a49880cc94 |
4 changed files with 74 additions and 62 deletions
2
deps.edn
2
deps.edn
|
|
@ -1,4 +1,4 @@
|
|||
{:paths ["src" "resources" "private"] ;; Private is not include in the build
|
||||
{:paths ["src" "resources" "private"] ;; Private is not included in the build
|
||||
:deps {
|
||||
org.clojure/clojure {:mvn/version "1.11.1"}
|
||||
org.clojure/data.csv {:mvn/version "1.0.1"}
|
||||
|
|
|
|||
45
src/core.clj
45
src/core.clj
|
|
@ -48,14 +48,34 @@
|
|||
(set/difference (set (keys projects)) (->> records (map :name) set)))
|
||||
|
||||
(def demo-options
|
||||
{:csv (io/resource "example-paychex-pay-item-details.csv")
|
||||
{:csv (io/resource "example-paychex-pay-item-details-2025.csv")
|
||||
:date "2024-01-01"
|
||||
:period "January 2024"
|
||||
:total-fees 66.67M})
|
||||
|
||||
(defn run [options]
|
||||
(let [options (if (:demo options) (merge options demo-options) options)
|
||||
{: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)
|
||||
(import/individual-taxes date period pay-invoice-no retirement-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 project 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/retirement date period retirement-receipt-no retirement-invoice-no records))
|
||||
unmatched (unmatched-employees records project)]
|
||||
(when (seq unmatched)
|
||||
(println
|
||||
(str "Could not find these employees in the payroll:\n\n"
|
||||
(str/join ", " unmatched)))
|
||||
(System/exit 1))
|
||||
(doseq [i imported]
|
||||
(println (import/render-transaction i)))))
|
||||
|
||||
(defn -main [& args]
|
||||
(let [{:keys [options errors summary]} (parse-opts args cli-options)
|
||||
options (if (:demo options) (merge options demo-options) options)]
|
||||
(let [{:keys [options errors summary]} (parse-opts args cli-options)]
|
||||
(when (:help options)
|
||||
(println summary)
|
||||
(System/exit 0))
|
||||
|
|
@ -64,24 +84,7 @@
|
|||
(str "The following errors occurred:\n\n"
|
||||
(str/join \newline errors)))
|
||||
(System/exit 1))
|
||||
(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)
|
||||
(import/individual-taxes date period pay-invoice-no retirement-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 project 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/retirement date period retirement-receipt-no retirement-invoice-no records))
|
||||
unmatched (unmatched-employees records project)]
|
||||
(when-not (empty? unmatched)
|
||||
(println
|
||||
(str "Could not find these employees in the payroll:\n\n"
|
||||
(str/join ", " unmatched)))
|
||||
(System/exit 1))
|
||||
(doseq [i imported]
|
||||
(println (import/render-transaction i))))))
|
||||
(run options)))
|
||||
|
||||
(comment
|
||||
;; Examples to exercise the importer during development.
|
||||
|
|
|
|||
8
test/core_test.clj
Normal file
8
test/core_test.clj
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(ns core-test
|
||||
(:require [core]
|
||||
[clojure.test :as t :refer [deftest is]]
|
||||
[clojure.string :as str]))
|
||||
|
||||
(deftest demo-produces-output
|
||||
(let [output (with-out-str (core/run {:demo true}))]
|
||||
(is (not (str/blank? output)))))
|
||||
|
|
@ -8,14 +8,54 @@
|
|||
[clojure.test :as t :refer [deftest is are]]))
|
||||
|
||||
|
||||
;; Run all our functions over two slightly different data examples. 2024 uses
|
||||
;; "Liability" where 2025 uses "Liability Expense".
|
||||
(def paychex-csv-2024 (->> "example-paychex-pay-item-details-2024.csv"
|
||||
clojure.java.io/resource
|
||||
import/read-csv))
|
||||
|
||||
(def paychex-csv-2025 (->> "example-paychex-pay-item-details-2025.csv"
|
||||
clojure.java.io/resource
|
||||
import/read-csv))
|
||||
|
||||
(deftest render-transaction
|
||||
(let [transaction '{:date "DATE"
|
||||
:payee "Paychex"
|
||||
:desc "Monthly Payroll - PERIOD - Fee"
|
||||
:meta
|
||||
{:program "Conservancy:Payroll"
|
||||
:project "Conservancy"
|
||||
:receipt "TODO-FEES-RECEIPT"
|
||||
:invoice "TODO-FEES-INVOICE"
|
||||
:approval
|
||||
"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"
|
||||
:tax-implication "USA-Corporation"}
|
||||
:postings
|
||||
({:account "Expenses:Payroll:Fees"
|
||||
:amount 103.26M
|
||||
:currency "USD"
|
||||
:meta {:entity "Citizen-Jack"}}
|
||||
{:account "Expenses:Payroll:Fees"
|
||||
:amount 103.25M
|
||||
:currency "USD"
|
||||
:meta {:entity "Citizen-Jill"}}
|
||||
{:account "Assets:Citizens:Check1273" :amount -206.51M :currency "USD"})}
|
||||
actual (import/render-transaction transaction)
|
||||
expected (str/triml "
|
||||
DATE txn \"Paychex\" \"Monthly Payroll - PERIOD - Fee\"
|
||||
program: \"Conservancy:Payroll\"
|
||||
project: \"Conservancy\"
|
||||
receipt: \"TODO-FEES-RECEIPT\"
|
||||
invoice: \"TODO-FEES-INVOICE\"
|
||||
approval: \"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt\"
|
||||
tax-implication: \"USA-Corporation\"
|
||||
Expenses:Payroll:Fees 103.26 USD
|
||||
entity: \"Citizen-Jack\"
|
||||
Expenses:Payroll:Fees 103.25 USD
|
||||
entity: \"Citizen-Jill\"
|
||||
Assets:Citizens:Check1273 -206.51 USD
|
||||
")]
|
||||
(is (= actual expected))))
|
||||
|
||||
(deftest net-pay
|
||||
(let [expected '[{:date "DATE"
|
||||
:desc "Monthly Payroll - PERIOD - Net Pay"
|
||||
|
|
@ -358,44 +398,5 @@
|
|||
paychex-csv-2024
|
||||
paychex-csv-2025)))
|
||||
|
||||
(deftest render-transaction
|
||||
(let [transaction '{:date "DATE"
|
||||
:payee "Paychex"
|
||||
:desc "Monthly Payroll - PERIOD - Fee"
|
||||
:meta
|
||||
{:program "Conservancy:Payroll"
|
||||
:project "Conservancy"
|
||||
:receipt "TODO-FEES-RECEIPT"
|
||||
:invoice "TODO-FEES-INVOICE"
|
||||
:approval
|
||||
"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"
|
||||
:tax-implication "USA-Corporation"}
|
||||
:postings
|
||||
({:account "Expenses:Payroll:Fees"
|
||||
:amount 103.26M
|
||||
:currency "USD"
|
||||
:meta {:entity "Citizen-Jack"}}
|
||||
{:account "Expenses:Payroll:Fees"
|
||||
:amount 103.25M
|
||||
:currency "USD"
|
||||
:meta {:entity "Citizen-Jill"}}
|
||||
{:account "Assets:Citizens:Check1273" :amount -206.51M :currency "USD"})}
|
||||
actual (import/render-transaction transaction)
|
||||
expected (str/triml "
|
||||
DATE txn \"Paychex\" \"Monthly Payroll - PERIOD - Fee\"
|
||||
program: \"Conservancy:Payroll\"
|
||||
project: \"Conservancy\"
|
||||
receipt: \"TODO-FEES-RECEIPT\"
|
||||
invoice: \"TODO-FEES-INVOICE\"
|
||||
approval: \"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt\"
|
||||
tax-implication: \"USA-Corporation\"
|
||||
Expenses:Payroll:Fees 103.26 USD
|
||||
entity: \"Citizen-Jack\"
|
||||
Expenses:Payroll:Fees 103.25 USD
|
||||
entity: \"Citizen-Jill\"
|
||||
Assets:Citizens:Check1273 -206.51 USD
|
||||
")]
|
||||
(is (= actual expected))))
|
||||
|
||||
(comment
|
||||
(t/run-all-tests))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue