2024-02-20 03:19:23 +00:00
|
|
|
(ns core
|
2024-02-21 07:08:49 +00:00
|
|
|
(:require [clojure.tools.cli :refer [parse-opts]]
|
|
|
|
[import :as import]
|
2024-02-20 03:19:23 +00:00
|
|
|
[parse :refer [parse]]
|
2024-02-21 07:08:49 +00:00
|
|
|
[lambdaisland.deep-diff2 :as dd])
|
|
|
|
(:gen-class))
|
2024-02-20 03:19:23 +00:00
|
|
|
|
2024-02-20 03:55:14 +00:00
|
|
|
;; TODO: Need some tests now it's working.
|
|
|
|
|
2024-02-20 03:19:23 +00:00
|
|
|
(defn sort-postings [transactions]
|
|
|
|
(for [t transactions]
|
|
|
|
(update t :postings
|
|
|
|
(fn [ps] (sort-by (juxt #(get-in % [:meta :entity]) :account :amount) (filter #(not (zero? (:amount %))) ps))))))
|
|
|
|
|
2024-02-21 07:08:49 +00:00
|
|
|
|
|
|
|
(def cli-options
|
|
|
|
[[nil "--csv FILE" "Pay Item Details CSV report"]
|
|
|
|
[nil "--pay-date DATE" "Date for the payroll transactions (YYYY-MM-DD)"
|
|
|
|
:validate [#(re-matches #"\d{4}-\d{2}-\d{2}" %) "Must be of format YYYY-MM-DD"]
|
|
|
|
:default "FIXME"]
|
|
|
|
[nil "--period PERIOD" "Month/year covered by the pay run eg. \"December 2023\""
|
|
|
|
:default "FIXME"]
|
|
|
|
[nil "--pay-receipt-no REFERENCE" "Payroll receipt number, eg. \"rt:111/222\""
|
|
|
|
:default "FIXME"]
|
|
|
|
[nil "--pay-invoice-no REFERENCE" "Payroll invoice number, eg. \"rt:111/222\""
|
|
|
|
:default "FIXME"]
|
|
|
|
[nil "--total-fees NUM" "Total fee charged by Paychex, eg. \"206.50\""
|
|
|
|
:default (bigdec 0)]
|
|
|
|
[nil "--fees-receipt-no REFERENCE" "Paychex fees receipt number, eg. \"rt:111/222\""
|
|
|
|
:default "FIXME"]
|
|
|
|
[nil "--fees-invoice-no REFERENCE" "Paychex fees invoice number, eg. \"rt:111/222\""
|
|
|
|
:default "FIXME"]
|
|
|
|
[nil "--retirement-date DATE" "Date for the retirement transactions (YYYY-MM-DD)"
|
|
|
|
:validate [#(re-matches #"\d{4}-\d{2}-\d{2}" %) "Must be of format YYYY-MM-DD"]
|
|
|
|
:default "FIXME"]
|
|
|
|
[nil "--retirement-receipt-no REFERENCE" "Retirement receipt number, eg. \"rt:111/222\""
|
|
|
|
:default "FIXME"]
|
|
|
|
[nil "--retirement-invoice-no REFERENCE" "Retirement receipt number, eg. \"rt:111/222\""
|
|
|
|
:default "FIXME"]
|
|
|
|
["-h" "--help"]])
|
|
|
|
|
|
|
|
(defn -main [& args]
|
|
|
|
(let [{:keys [options _arguments _errors summary]} (parse-opts args cli-options)
|
|
|
|
{:keys [pay-date period pay-receipt-no pay-invoice-no total-fees fees-receipt-no fees-invoice-no retirement-date retirement-receipt-no retirement-invoice-no]} options]
|
|
|
|
(when (:help options)
|
|
|
|
(println summary)
|
|
|
|
(System/exit 0))
|
|
|
|
(let [grouped-data (import/read-grouped-csv (:csv options))
|
|
|
|
imported (concat [(import/import-monthly-payroll pay-date period pay-receipt-no grouped-data)]
|
|
|
|
(import/import-individual-taxes pay-date period pay-receipt-no pay-invoice-no grouped-data)
|
|
|
|
[(import/import-employer-taxes pay-date period pay-receipt-no grouped-data)]
|
|
|
|
[(import/payroll-fees pay-date period fees-receipt-no fees-invoice-no total-fees grouped-data)]
|
|
|
|
[(import/import-retirement retirement-date period retirement-receipt-no retirement-invoice-no grouped-data)])]
|
|
|
|
(doseq [i imported]
|
|
|
|
(println (import/render-transaction i))))))
|
|
|
|
|
2024-02-20 03:19:23 +00:00
|
|
|
(comment
|
2024-02-20 03:55:14 +00:00
|
|
|
(require '[examples :as examples])
|
2024-02-21 07:08:49 +00:00
|
|
|
(def grouped-data (import/read-grouped-csv "/home/ben/Downloads/2023-12-27_Pay-Item-Details_2023-12-2.csv"))
|
2024-02-20 03:19:23 +00:00
|
|
|
(def imported
|
2024-02-21 07:08:49 +00:00
|
|
|
(concat [(import/import-monthly-payroll "2023-12-29" "December 2023" "rt:19462/674660" grouped-data)]
|
|
|
|
(import/import-individual-taxes "2023-12-29" "December 2023" "rt:19462/674660" "rt:19403/675431" grouped-data)
|
|
|
|
[(import/import-employer-taxes "2023-12-29" "December 2023" "rt:19462/674660" grouped-data)]
|
|
|
|
[(import/payroll-fees "2023-12-29" "December 2023" "rt:19459/675387" "rt:19459/674887" (bigdec 206.50) grouped-data)]
|
|
|
|
[(import/import-retirement "2024-01-02" "December 2023" "rt:19403/676724" "rt:19403/675431" grouped-data)]))
|
2024-02-20 03:19:23 +00:00
|
|
|
|
2024-02-20 03:55:14 +00:00
|
|
|
(dd/pretty-print
|
|
|
|
(dd/diff
|
|
|
|
(sort-postings (parse examples/human))
|
|
|
|
(sort-postings imported)))
|
2024-02-20 03:19:23 +00:00
|
|
|
|
|
|
|
(doseq [i imported]
|
|
|
|
(println (import/render-transaction i)))
|
|
|
|
|
|
|
|
)
|