394 lines
19 KiB
Clojure
394 lines
19 KiB
Clojure
;; Copyright 2024 Ben Sturmfels
|
|
;; License: GPLv3-or-later
|
|
|
|
(ns import-test
|
|
(:require [import]
|
|
[clojure.java.io]
|
|
[clojure.string :as str]
|
|
[clojure.test :as t :refer [deftest is]]))
|
|
|
|
(deftest net-pay
|
|
(let [records (import/read-csv (clojure.java.io/resource "example-paychex-pay-item-details.csv"))
|
|
actual (import/net-pay "DATE" "PERIOD" "TODO-PAY-INVOICE" {} records)
|
|
expected '[{:date "DATE"
|
|
:desc "Monthly Payroll - PERIOD - Net Pay"
|
|
:meta
|
|
{:program "Conservancy:Payroll"
|
|
:project "Conservancy"
|
|
:invoice "TODO-PAY-INVOICE"
|
|
:approval
|
|
"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"
|
|
:tax-implication "W2"
|
|
:payroll-type "US:General"}
|
|
:postings
|
|
({:account "Expenses:Payroll:Salary"
|
|
:amount 4134.49M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jack"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount -4134.49M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jack"}}
|
|
{:account "Expenses:Hosting"
|
|
:amount 50M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jack" :payroll-type "US:Reimbursement"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount -50M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jack" :tax-implication "Reimbursement"}}
|
|
{:account "Expenses:Payroll:Salary"
|
|
:amount 4347.39M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jill"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount -4347.39M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jill"}}
|
|
{:account "Expenses:Hosting"
|
|
:amount 50M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jill" :payroll-type "US:Reimbursement"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount -50M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jill" :tax-implication "Reimbursement"}})}]]
|
|
(is (= actual expected))))
|
|
|
|
(deftest individual-taxes
|
|
(let [records (import/read-csv (clojure.java.io/resource "example-paychex-pay-item-details.csv"))
|
|
actual (import/individual-taxes "DATE" "PERIOD" "TODO-PAY-INVOICE" "TODO-RETIREMENT-INVOICE" {} records)
|
|
expected '({:date "DATE"
|
|
:desc "Monthly Payroll - PERIOD - TAXES - Citizen-Jack"
|
|
:meta
|
|
{:project "Conservancy"
|
|
:program "Conservancy:Payroll"
|
|
:entity "Citizen-Jack"
|
|
:invoice "TODO-PAY-INVOICE"
|
|
:approval
|
|
"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"}
|
|
:postings
|
|
({:account "Expenses:Payroll:Salary"
|
|
:amount 1000M
|
|
:currency "USD"
|
|
:meta
|
|
{:payroll-type "US:403b:Employee"
|
|
:invoice "TODO-RETIREMENT-INVOICE"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount -1000M
|
|
:currency "USD"
|
|
:meta {:invoice "TODO-RETIREMENT-INVOICE"}}
|
|
{:account "Expenses:Payroll:Salary"
|
|
:amount 470.22M
|
|
:currency "USD"
|
|
:meta {:payroll-type "US:Tax:Income"}}
|
|
{:account "Expenses:Payroll:Salary"
|
|
:amount 88M
|
|
:currency "USD"
|
|
:meta {:payroll-type "US:Tax:Medicare"}}
|
|
{:account "Expenses:Payroll:Salary"
|
|
:amount 376.28M
|
|
:currency "USD"
|
|
:meta {:payroll-type "US:Tax:SocialSecurity"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount -934.50M
|
|
:currency "USD"
|
|
:meta {:tax-implication "W2"}}
|
|
{:account "Liabilities:Payable:Accounts" :amount 0M :currency "USD"})}
|
|
{:date "DATE"
|
|
:desc "Monthly Payroll - PERIOD - TAXES - Citizen-Jill"
|
|
:meta
|
|
{:project "Conservancy"
|
|
:program "Conservancy:Payroll"
|
|
:entity "Citizen-Jill"
|
|
:invoice "TODO-PAY-INVOICE"
|
|
:approval
|
|
"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"}
|
|
:postings
|
|
({:account "Expenses:Payroll:Salary"
|
|
:amount 820M
|
|
:currency "USD"
|
|
:meta
|
|
{:payroll-type "US:403b:Employee"
|
|
:invoice "TODO-RETIREMENT-INVOICE"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount -820M
|
|
:currency "USD"
|
|
:meta {:invoice "TODO-RETIREMENT-INVOICE"}}
|
|
{:account "Expenses:Payroll:Salary"
|
|
:amount 681.01M
|
|
:currency "USD"
|
|
:meta {:payroll-type "US:Tax:Income"}}
|
|
{:account "Expenses:Payroll:Salary"
|
|
:amount 99.29M
|
|
:currency "USD"
|
|
:meta {:payroll-type "US:Tax:Medicare"}}
|
|
{:account "Expenses:Payroll:Salary"
|
|
:amount 41.08M
|
|
:currency "USD"
|
|
:meta {:payroll-type "US:OR:Disability:PFL"}}
|
|
{:account "Expenses:Payroll:Salary"
|
|
:amount 0M
|
|
:currency "USD"
|
|
:meta {:payroll-type "OR EE Work Bene"}}
|
|
{:account "Expenses:Payroll:Salary"
|
|
:amount 427.8M
|
|
:currency "USD"
|
|
:meta {:payroll-type "US:OR:Tax:Income"}}
|
|
{:account "Expenses:Payroll:Salary"
|
|
:amount 6.03M
|
|
:currency "USD"
|
|
:meta {:payroll-type "US:OR:Tax:STT"}}
|
|
{:account "Expenses:Payroll:Salary"
|
|
:amount 424.52M
|
|
:currency "USD"
|
|
:meta {:payroll-type "US:Tax:SocialSecurity"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount -1679.73M
|
|
:currency "USD"
|
|
:meta {:tax-implication "W2"}}
|
|
{:account "Liabilities:Payable:Accounts" :amount 0M :currency "USD"})})]
|
|
(is (= actual expected))))
|
|
|
|
(deftest employer-taxes
|
|
(let [records (import/read-csv (clojure.java.io/resource "example-paychex-pay-item-details.csv"))
|
|
actual (import/employer-taxes "DATE" "PERIOD" "TODO-PAY-INVOICE" {} records)
|
|
expected '[{:date "DATE"
|
|
:desc "Monthly Payroll - PERIOD - TAXES - Employer"
|
|
:meta
|
|
{:program "Conservancy:Payroll"
|
|
:project "Conservancy"
|
|
:invoice "TODO-PAY-INVOICE"
|
|
:approval
|
|
"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"}
|
|
:postings
|
|
({:account "Expenses:Payroll:Tax"
|
|
:amount 88M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jack" :payroll-type "US:Medicare"}}
|
|
{:account "Expenses:Payroll:Tax"
|
|
:amount 376.28M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jack" :payroll-type "US:SocialSecurity"}}
|
|
{:account "Expenses:Payroll:Tax"
|
|
:amount 99.28M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jill" :payroll-type "US:Medicare"}}
|
|
{:account "Expenses:Payroll:Tax"
|
|
:amount 0M
|
|
:currency "USD"
|
|
:meta
|
|
{:entity "Citizen-Jill" :payroll-type "US:OR:Disability:PFL"}}
|
|
{:account "Expenses:Payroll:Tax"
|
|
:amount 0M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jill" :payroll-type "OR ER Work Bene"}}
|
|
{:account "Expenses:Payroll:Tax"
|
|
:amount 424.52M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jill" :payroll-type "US:SocialSecurity"}}
|
|
{:account "Expenses:Payroll:Tax"
|
|
:amount 0M
|
|
:currency "USD"
|
|
:meta
|
|
{:entity "Fed"
|
|
:memo "Citizen-Jack"
|
|
:payroll-type "US:US:Unemployment"}}
|
|
{:account "Expenses:Payroll:Tax"
|
|
:amount 0M
|
|
:currency "USD"
|
|
:meta
|
|
{:entity "TN"
|
|
:memo "Citizen-Jack"
|
|
:payroll-type "US:TN Unemploy"}}
|
|
{:account "Expenses:Payroll:Tax"
|
|
:amount 0M
|
|
:currency "USD"
|
|
:meta
|
|
{:entity "Fed"
|
|
:memo "Citizen-Jill"
|
|
:payroll-type "US:US:Unemployment"}}
|
|
{:account "Expenses:Payroll:Tax"
|
|
:amount 0M
|
|
:currency "USD"
|
|
:meta
|
|
{:entity "OR"
|
|
:memo "Citizen-Jill"
|
|
:payroll-type "US:OR:Unemployment"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount -988.08M
|
|
:currency "USD"
|
|
:meta {:entity "Paychex" :tax-implication "Tax-Payment"}})}]]
|
|
(is (= actual expected))))
|
|
|
|
;; TODO: Add 2 x ACH credit tests
|
|
|
|
(deftest fees
|
|
(let [records (import/read-csv (clojure.java.io/resource "example-paychex-pay-item-details.csv"))
|
|
actual (import/fees "DATE" "PERIOD" "TODO-FEES-RECEIPT" "TODO-FEES-INVOICE" 206.51 {} records)
|
|
expected '[{: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:FR:Check2721" :amount -206.51 :currency "USD"})}]
|
|
]
|
|
(is (= actual expected))))
|
|
|
|
(deftest retirement
|
|
(let [records (import/read-csv (clojure.java.io/resource "example-paychex-pay-item-details.csv"))
|
|
actual (import/retirement "DATE" "PERIOD" "TODO-RETIREMENT-RECEIPT" "TODO-RETIREMENT-INVOICE" records)
|
|
expected '[{:date "DATE"
|
|
:desc
|
|
"ASCENSUS TRUST RET PLAN - ACH DEBIT - Vanguard 403(b) - PERIOD"
|
|
:meta
|
|
{:program "Conservancy:Payroll"
|
|
:project "Conservancy"
|
|
:receipt "TODO-RETIREMENT-RECEIPT"
|
|
:approval
|
|
"Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"
|
|
:tax-implication "Retirement-Pretax"
|
|
:invoice "TODO-RETIREMENT-INVOICE"}
|
|
:postings
|
|
({:account "Liabilities:Payable:Accounts"
|
|
:amount 1000M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jack"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount 820M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jill"}}
|
|
{:account "Assets:FR:Check1345" :amount -1820M :currency "USD"})}]]
|
|
(is (= actual expected))))
|
|
|
|
(deftest net-pay-ach-debit
|
|
(let [records (import/read-csv (clojure.java.io/resource "example-paychex-pay-item-details.csv"))
|
|
actual (import/net-pay-ach-debit "DATE" "PERIOD" "TODO-PAY-RECEIPT" "TODO-PAY-INVOICE" {} records)
|
|
expected [{:date "DATE"
|
|
:desc "Monthly Payroll - PERIOD - Net Pay - ACH debit"
|
|
:meta {:approval "Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"
|
|
:invoice "TODO-PAY-INVOICE"
|
|
:payroll-type "US:General"
|
|
:program "Conservancy:Payroll"
|
|
:project "Conservancy"
|
|
:receipt "TODO-PAY-RECEIPT"
|
|
:tax-implication "W2"}
|
|
:postings [{:account "Liabilities:Payable:Accounts"
|
|
:amount 4134.49M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jack"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount 50M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jack"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount 4347.39M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jill"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount 50M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jill"}}
|
|
{:account "Assets:FR:Check2721"
|
|
:amount -8481.88M
|
|
:currency "USD"
|
|
:meta {:entity "Paychex" :tax-implication "W2"}}
|
|
{:account "Assets:FR:Check2721"
|
|
:amount -100M
|
|
:currency "USD"
|
|
:meta {:entity "Paychex" :tax-implication "Reimbursement"}}]}]]
|
|
(is (= actual expected))))
|
|
|
|
(deftest taxes-ach-debit
|
|
(let [records (import/read-csv (clojure.java.io/resource "example-paychex-pay-item-details.csv"))
|
|
actual (import/taxes-ach-debit "DATE" "PERIOD" "TODO-PAY-RECEIPT" "TODO-PAY-INVOICE" {} records)
|
|
expected [{:date "DATE"
|
|
:desc "Monthly Payroll - PERIOD - TAXES - ACH debit"
|
|
:meta {:approval "Financial/Employment-Records/memo-re-board-approval-of-payroll.txt"
|
|
:invoice "TODO-PAY-INVOICE"
|
|
:program "Conservancy:Payroll"
|
|
:project "Conservancy"
|
|
:receipt "TODO-PAY-RECEIPT"}
|
|
:postings [{:account "Liabilities:Payable:Accounts"
|
|
:amount 934.50M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jack"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount 0M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jack"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount 1679.73M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jill"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount 0M
|
|
:currency "USD"
|
|
:meta {:entity "Citizen-Jill"}}
|
|
{:account "Liabilities:Payable:Accounts"
|
|
:amount 988.08M
|
|
:currency "USD"
|
|
:meta {:entity "Paychex"}}
|
|
{:account "Assets:FR:Check2721"
|
|
:amount -3602.31M
|
|
:currency "USD"
|
|
:meta {:entity "Paychex" :tax-implication "Tax-Payment"}}]}]]
|
|
(is (= actual expected))))
|
|
|
|
(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:FR:Check2721" :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:FR:Check2721 -206.51 USD
|
|
")]
|
|
(is (= actual expected))))
|
|
|
|
(comment
|
|
(t/run-all-tests)
|
|
)
|