forked from EvergreenCrypto/docker-finance
Merge pull request #179 into master
21967e7container: lib_taxes: remove unused arg expansion, appease the linter (Aaron Fiore)08c1de5container: lib_taxes: optimize record printing, add checks and logging (Aaron Fiore)
This commit is contained in:
@@ -31,7 +31,7 @@ source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_utils.bash
|
||||
function lib_taxes::taxes()
|
||||
{
|
||||
lib_taxes::__parse_args "$@"
|
||||
lib_taxes::__taxes "$@"
|
||||
lib_taxes::__taxes
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
@@ -446,6 +446,8 @@ function lib_taxes::__taxes_print()
|
||||
printf "\n"
|
||||
}
|
||||
{
|
||||
if (!NR) { exit }
|
||||
|
||||
Date = $1
|
||||
Action = $2
|
||||
Account = $3
|
||||
@@ -625,6 +627,9 @@ function lib_taxes::__taxes_print()
|
||||
END { print prev }' \
|
||||
| gawk -M -v PREC=100 \
|
||||
'{
|
||||
# NOTE: if previous only produces OFS, this will exit
|
||||
if (!$NF) { exit }
|
||||
|
||||
# If more than triplet form, support quadruple form
|
||||
# TODO: support more than 4 if necessary
|
||||
if ($13 == $10)
|
||||
@@ -839,7 +844,7 @@ function lib_taxes::__taxes_print()
|
||||
print $0
|
||||
exit
|
||||
}
|
||||
}' | grep -vE "(,BUY,,,,USD,0,,|,,,,,,,,,,,0.000000000000000000)" # TODO: HACK
|
||||
}'
|
||||
fi
|
||||
|
||||
#
|
||||
@@ -861,6 +866,8 @@ function lib_taxes::__taxes_print()
|
||||
| sort -u \
|
||||
| gawk \
|
||||
'{
|
||||
if (!NR) { exit }
|
||||
|
||||
txid = $1; FeeCurrency = $5; Fee = $6
|
||||
a[$1]=a[$1] ? a[$1] OFS txid OFS FeeCurrency OFS Fee : $0
|
||||
} END { for(i in a) {print a[i]} }' FS=, OFS=, \
|
||||
@@ -956,12 +963,24 @@ function lib_taxes::__taxes_print()
|
||||
if (NR == 1)
|
||||
{
|
||||
Header=$0
|
||||
print Header
|
||||
}
|
||||
# Save non-header row(s)
|
||||
if ($0 != Header)
|
||||
{
|
||||
print
|
||||
Data[i++] = $0
|
||||
}
|
||||
}
|
||||
END {
|
||||
# Only print header if non-header row(s) exist
|
||||
if (length(Data))
|
||||
{
|
||||
print Header
|
||||
}
|
||||
# Print all non-header row(s)
|
||||
for (i=0; i < length(Data); i++)
|
||||
{
|
||||
print Data[i]
|
||||
}
|
||||
}' FS=, OFS=,
|
||||
# WARNING:
|
||||
# - Do not run unique (sort -ru)! There are legitimate income/trade entries
|
||||
@@ -1026,8 +1045,14 @@ function lib_taxes::__taxes_write()
|
||||
lib_utils::print_custom " \e[32m├─\e[34m\e[1;3m ${_arg_tag} (full)\e[0m\n"
|
||||
|
||||
local _base_path="${_tax_root_dir}/${_arg_tag}/${_tax_year}_${_arg_tag}"
|
||||
lib_taxes::__taxes_print "$_tax_year" "$_arg_tag" >"${_base_path}-${_ext_full}"
|
||||
local _out_file="${_base_path}-${_ext_full}"
|
||||
|
||||
lib_taxes::__taxes_print "$_tax_year" "$_arg_tag" >"${_out_file}"
|
||||
lib_utils::catch $?
|
||||
|
||||
if [[ ! -f "$_out_file" || ! -s "$_out_file" ]]; then
|
||||
lib_utils::print_warning "Nothing generated for '${_arg_tag}' (no taxable event found for the year ${global_arg_year})"
|
||||
fi
|
||||
done
|
||||
|
||||
# Patch transparent (full) reports
|
||||
@@ -1207,6 +1232,9 @@ function lib_taxes::__reports_patch()
|
||||
# Verify success of patches
|
||||
#
|
||||
|
||||
lib_utils::print_custom " \e[32m│\e[0m\t\e[37;2m ... Verifying patches (full) ...\e[0m\n"
|
||||
lib_utils::print_custom " \e[32m│\e[0m\n"
|
||||
|
||||
lib_taxes::__reports_patch_verify "$_income" "${_spends_tags[@]}" "${_trades_tags[@]}"
|
||||
lib_taxes::__reports_patch_verify "$_spends" "${_trades_tags[@]}" "${_income_tags[@]}"
|
||||
lib_taxes::__reports_patch_verify "$_trades" "${_income_tags[@]}" "${_spends_tags[@]}"
|
||||
@@ -1217,16 +1245,20 @@ function lib_taxes::__reports_patch_verify()
|
||||
local _file="$1"
|
||||
local _tags=("${@:2}")
|
||||
|
||||
[ ! -f "$_file" ] && lib_utils::die_fatal "$_file not found"
|
||||
[[ -z "$_file" || -z "${_tags[*]}" ]] && lib_utils::die_fatal
|
||||
|
||||
xsv select "Action" "$_file" \
|
||||
| sort -u \
|
||||
| tail -n +2 \
|
||||
| while read _line; do
|
||||
for _tag in "${_tags[@]}"; do
|
||||
[[ "$_line" != "$_tag" ]] || lib_utils::die_fatal "Bad entry in $_file"
|
||||
[ ! -f "$_file" ] && lib_utils::die_fatal "File not found: '${_file}'"
|
||||
|
||||
if [ -s "$_file" ]; then
|
||||
xsv select "Action" "$_file" \
|
||||
| sort -u \
|
||||
| tail -n +2 \
|
||||
| while read _line; do
|
||||
for _tag in "${_tags[@]}"; do
|
||||
[[ "$_line" != "$_tag" ]] || lib_utils::die_fatal "Bad entry in $_file"
|
||||
done
|
||||
done
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
@@ -1253,6 +1285,8 @@ function lib_taxes::__reports_obfs()
|
||||
lib_taxes::__reports_obfs_gen
|
||||
}
|
||||
|
||||
# TODO: refactor to remove shellcheck
|
||||
# shellcheck disable=SC2120
|
||||
function lib_taxes::__reports_obfs_gen()
|
||||
{
|
||||
# Temp storage
|
||||
|
||||
Reference in New Issue
Block a user