Use the :let and :when modifiers for for
This commit is contained in:
parent
d0565f794f
commit
2cb7c3a3ad
1 changed files with 47 additions and 47 deletions
|
|
@ -101,11 +101,11 @@
|
||||||
(for [[k v] meta]
|
(for [[k v] meta]
|
||||||
(format " %s: \"%s\"\n" (name k) v))
|
(format " %s: \"%s\"\n" (name k) v))
|
||||||
;; Postings and posting metadata
|
;; Postings and posting metadata
|
||||||
(for [{:keys [amount account currency meta]} postings]
|
(for [{:keys [amount account currency meta]} postings
|
||||||
(when-not (zero? amount)
|
:when (not (zero? amount))]
|
||||||
(format " %-40s %10.2f %s\n%s" account amount currency
|
(format " %-40s %10.2f %s\n%s" account amount currency
|
||||||
(str/join (for [[k v] meta]
|
(str/join (for [[k v] meta]
|
||||||
(format " %s: \"%s\"\n" (name k) v)))))))))
|
(format " %s: \"%s\"\n" (name k) v))))))))
|
||||||
|
|
||||||
;; Each of the below functions returns one of the five payroll
|
;; Each of the below functions returns one of the five payroll
|
||||||
;; transaction "sections" (one or more Beancount transaction entry):
|
;; transaction "sections" (one or more Beancount transaction entry):
|
||||||
|
|
@ -144,29 +144,29 @@
|
||||||
:payroll-type "US:General"}
|
:payroll-type "US:General"}
|
||||||
:postings []}
|
:postings []}
|
||||||
postings (flatten
|
postings (flatten
|
||||||
(for [[name employee-records] (group-by :name records)]
|
(for [[name employee-records] (group-by :name records)
|
||||||
(let [total-net-pay (total-by-type "Net Pay" employee-records)
|
:let [total-net-pay (total-by-type "Net Pay" employee-records)
|
||||||
total-reimbursement (total-by-type "Reimbursement" employee-records)
|
total-reimbursement (total-by-type "Reimbursement" employee-records)
|
||||||
actual-total-net-pay (- total-net-pay total-reimbursement)]
|
actual-total-net-pay (- total-net-pay total-reimbursement)]]
|
||||||
[{:account "Expenses:Payroll:Salary"
|
[{:account "Expenses:Payroll:Salary"
|
||||||
:amount actual-total-net-pay :currency "USD"
|
:amount actual-total-net-pay :currency "USD"
|
||||||
:meta (assoc-project projects name {:entity name})}
|
:meta (assoc-project projects name {:entity name})}
|
||||||
{:account "Liabilities:Payable:Accounts"
|
{:account "Liabilities:Payable:Accounts"
|
||||||
:amount (- actual-total-net-pay) :currency "USD"
|
:amount (- actual-total-net-pay) :currency "USD"
|
||||||
:meta {:entity name}}
|
:meta {:entity name}}
|
||||||
{:account "Expenses:Hosting"
|
{:account "Expenses:Hosting"
|
||||||
:amount total-reimbursement :currency "USD"
|
:amount total-reimbursement :currency "USD"
|
||||||
:meta (assoc-project projects name {:entity name :payroll-type "US:Reimbursement"})}
|
:meta (assoc-project projects name {:entity name :payroll-type "US:Reimbursement"})}
|
||||||
{:account "Liabilities:Payable:Accounts"
|
{:account "Liabilities:Payable:Accounts"
|
||||||
:amount (- total-reimbursement) :currency "USD"
|
:amount (- total-reimbursement) :currency "USD"
|
||||||
:meta (assoc-project projects name {:entity name :tax-implication "Reimbursement"})}])))]
|
:meta (assoc-project projects name {:entity name :tax-implication "Reimbursement"})}]))]
|
||||||
[(assoc template :postings postings)]))
|
[(assoc template :postings postings)]))
|
||||||
|
|
||||||
(defn individual-taxes
|
(defn individual-taxes
|
||||||
"Return a transaction of expenses/witholding for each employee."
|
"Return a transaction of expenses/witholding for each employee."
|
||||||
[date period pay-invoice-no retirement-invoice-no projects records]
|
[date period pay-invoice-no retirement-invoice-no projects records]
|
||||||
(for [[name employee-records] (group-by :name records)]
|
(for [[name employee-records] (group-by :name records)
|
||||||
(let [template {:date date :desc (format "Monthly Payroll - %s - TAXES - %s" period name)
|
:let [template {:date date :desc (format "Monthly Payroll - %s - TAXES - %s" period name)
|
||||||
:meta (assoc-project
|
:meta (assoc-project
|
||||||
projects name
|
projects name
|
||||||
{:project "Conservancy"
|
{:project "Conservancy"
|
||||||
|
|
@ -215,8 +215,8 @@
|
||||||
withholding-postings
|
withholding-postings
|
||||||
withholding-asset-postings
|
withholding-asset-postings
|
||||||
insurance-postings
|
insurance-postings
|
||||||
insurance-asset-postings)]
|
insurance-asset-postings)]]
|
||||||
(assoc template :postings all-postings))))
|
(assoc template :postings all-postings)))
|
||||||
|
|
||||||
(defn employer-taxes
|
(defn employer-taxes
|
||||||
"Return an employer taxes transaction."
|
"Return an employer taxes transaction."
|
||||||
|
|
@ -295,11 +295,11 @@
|
||||||
:tax-implication "Retirement-Pretax"
|
:tax-implication "Retirement-Pretax"
|
||||||
:invoice invoice-no}
|
:invoice invoice-no}
|
||||||
:postings []}
|
:postings []}
|
||||||
liability-postings (for [[name employee-records] (group-by :name records)]
|
liability-postings (for [[name employee-records] (group-by :name records)
|
||||||
(let [total-retirement (total-by-type "Retirement" employee-records)]
|
:let [total-retirement (total-by-type "Retirement" employee-records)]]
|
||||||
{:account "Liabilities:Payable:Accounts"
|
{:account "Liabilities:Payable:Accounts"
|
||||||
:amount total-retirement :currency "USD"
|
:amount total-retirement :currency "USD"
|
||||||
:meta {:entity name}}))
|
:meta {:entity name}})
|
||||||
total-liabilities (total liability-postings)
|
total-liabilities (total liability-postings)
|
||||||
asset-postings [{:account "Assets:Citizens:Check1273"
|
asset-postings [{:account "Assets:Citizens:Check1273"
|
||||||
:amount (- total-liabilities) :currency "USD"}]
|
:amount (- total-liabilities) :currency "USD"}]
|
||||||
|
|
@ -319,15 +319,15 @@
|
||||||
:payroll-type "US:General"}
|
:payroll-type "US:General"}
|
||||||
:postings []}
|
:postings []}
|
||||||
employee-postings (flatten
|
employee-postings (flatten
|
||||||
(for [[name employee-records] (group-by :name records)]
|
(for [[name employee-records] (group-by :name records)
|
||||||
(let [net-pay (total-by-type "Net Pay" employee-records)
|
:let [net-pay (total-by-type "Net Pay" employee-records)
|
||||||
reimbursements (total-by-type "Reimbursement" employee-records)]
|
reimbursements (total-by-type "Reimbursement" employee-records)]]
|
||||||
[{:account "Liabilities:Payable:Accounts"
|
[{:account "Liabilities:Payable:Accounts"
|
||||||
:amount (- net-pay reimbursements) :currency "USD"
|
:amount (- net-pay reimbursements) :currency "USD"
|
||||||
:meta (assoc-project projects name {:entity name})}
|
:meta (assoc-project projects name {:entity name})}
|
||||||
{:account "Liabilities:Payable:Accounts"
|
{:account "Liabilities:Payable:Accounts"
|
||||||
:amount reimbursements :currency "USD"
|
:amount reimbursements :currency "USD"
|
||||||
:meta (assoc-project projects name {:entity name})}])))
|
:meta (assoc-project projects name {:entity name})}]))
|
||||||
total-net-pay (total-by-type "Net Pay" records)
|
total-net-pay (total-by-type "Net Pay" records)
|
||||||
total-reimbursements (total-by-type "Reimbursement" records)
|
total-reimbursements (total-by-type "Reimbursement" records)
|
||||||
total-net-pay-posting {:account "Assets:Citizens:Check1273"
|
total-net-pay-posting {:account "Assets:Citizens:Check1273"
|
||||||
|
|
@ -361,18 +361,18 @@
|
||||||
:amount (+ total-liabilities total-unemploy) :currency "USD"
|
:amount (+ total-liabilities total-unemploy) :currency "USD"
|
||||||
:meta {:entity "Paychex"}}]
|
:meta {:entity "Paychex"}}]
|
||||||
withholding-liability-postings (flatten
|
withholding-liability-postings (flatten
|
||||||
(for [[name employee-records] (group-by :name records)]
|
(for [[name employee-records] (group-by :name records)
|
||||||
(let [witholding-records (filter #(= (:type %) "Withholding") employee-records)
|
:let [witholding-records (filter #(= (:type %) "Withholding") employee-records)
|
||||||
insurance-records (filter (fn [{:keys [category type]}]
|
insurance-records (filter (fn [{:keys [category type]}]
|
||||||
(and (= type "Withholding")
|
(and (= type "Withholding")
|
||||||
(str/starts-with? category "NY Disability")))
|
(str/starts-with? category "NY Disability")))
|
||||||
employee-records)]
|
employee-records)]]
|
||||||
[{:account "Liabilities:Payable:Accounts"
|
[{:account "Liabilities:Payable:Accounts"
|
||||||
:amount (total witholding-records) :currency "USD"
|
:amount (total witholding-records) :currency "USD"
|
||||||
:meta (assoc-project projects name {:entity name})}
|
:meta (assoc-project projects name {:entity name})}
|
||||||
{:account "Liabilities:Payable:Accounts"
|
{:account "Liabilities:Payable:Accounts"
|
||||||
:amount (- (total insurance-records)) :currency "USD"
|
:amount (- (total insurance-records)) :currency "USD"
|
||||||
:meta (assoc-project projects name {:entity name})}])))
|
:meta (assoc-project projects name {:entity name})}]))
|
||||||
asset-postings [{:account "Assets:Citizens:Check1273"
|
asset-postings [{:account "Assets:Citizens:Check1273"
|
||||||
:amount (- (+ total-liabilities total-unemploy (total withholding-liability-postings))) :currency "USD"
|
:amount (- (+ total-liabilities total-unemploy (total withholding-liability-postings))) :currency "USD"
|
||||||
:meta {:entity "Paychex" :tax-implication "Tax-Payment"}}]
|
:meta {:entity "Paychex" :tax-implication "Tax-Payment"}}]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue