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 was merged in pull request #179.
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()
|
function lib_taxes::taxes()
|
||||||
{
|
{
|
||||||
lib_taxes::__parse_args "$@"
|
lib_taxes::__parse_args "$@"
|
||||||
lib_taxes::__taxes "$@"
|
lib_taxes::__taxes
|
||||||
lib_utils::catch $?
|
lib_utils::catch $?
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,6 +446,8 @@ function lib_taxes::__taxes_print()
|
|||||||
printf "\n"
|
printf "\n"
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
if (!NR) { exit }
|
||||||
|
|
||||||
Date = $1
|
Date = $1
|
||||||
Action = $2
|
Action = $2
|
||||||
Account = $3
|
Account = $3
|
||||||
@@ -625,6 +627,9 @@ function lib_taxes::__taxes_print()
|
|||||||
END { print prev }' \
|
END { print prev }' \
|
||||||
| gawk -M -v PREC=100 \
|
| 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
|
# If more than triplet form, support quadruple form
|
||||||
# TODO: support more than 4 if necessary
|
# TODO: support more than 4 if necessary
|
||||||
if ($13 == $10)
|
if ($13 == $10)
|
||||||
@@ -839,7 +844,7 @@ function lib_taxes::__taxes_print()
|
|||||||
print $0
|
print $0
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
}' | grep -vE "(,BUY,,,,USD,0,,|,,,,,,,,,,,0.000000000000000000)" # TODO: HACK
|
}'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -861,6 +866,8 @@ function lib_taxes::__taxes_print()
|
|||||||
| sort -u \
|
| sort -u \
|
||||||
| gawk \
|
| gawk \
|
||||||
'{
|
'{
|
||||||
|
if (!NR) { exit }
|
||||||
|
|
||||||
txid = $1; FeeCurrency = $5; Fee = $6
|
txid = $1; FeeCurrency = $5; Fee = $6
|
||||||
a[$1]=a[$1] ? a[$1] OFS txid OFS FeeCurrency OFS Fee : $0
|
a[$1]=a[$1] ? a[$1] OFS txid OFS FeeCurrency OFS Fee : $0
|
||||||
} END { for(i in a) {print a[i]} }' FS=, OFS=, \
|
} END { for(i in a) {print a[i]} }' FS=, OFS=, \
|
||||||
@@ -956,12 +963,24 @@ function lib_taxes::__taxes_print()
|
|||||||
if (NR == 1)
|
if (NR == 1)
|
||||||
{
|
{
|
||||||
Header=$0
|
Header=$0
|
||||||
print Header
|
|
||||||
}
|
}
|
||||||
|
# Save non-header row(s)
|
||||||
if ($0 != Header)
|
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=,
|
}' FS=, OFS=,
|
||||||
# WARNING:
|
# WARNING:
|
||||||
# - Do not run unique (sort -ru)! There are legitimate income/trade entries
|
# - 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"
|
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}"
|
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 $?
|
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
|
done
|
||||||
|
|
||||||
# Patch transparent (full) reports
|
# Patch transparent (full) reports
|
||||||
@@ -1207,6 +1232,9 @@ function lib_taxes::__reports_patch()
|
|||||||
# Verify success of patches
|
# 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 "$_income" "${_spends_tags[@]}" "${_trades_tags[@]}"
|
||||||
lib_taxes::__reports_patch_verify "$_spends" "${_trades_tags[@]}" "${_income_tags[@]}"
|
lib_taxes::__reports_patch_verify "$_spends" "${_trades_tags[@]}" "${_income_tags[@]}"
|
||||||
lib_taxes::__reports_patch_verify "$_trades" "${_income_tags[@]}" "${_spends_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 _file="$1"
|
||||||
local _tags=("${@:2}")
|
local _tags=("${@:2}")
|
||||||
|
|
||||||
[ ! -f "$_file" ] && lib_utils::die_fatal "$_file not found"
|
[[ -z "$_file" || -z "${_tags[*]}" ]] && lib_utils::die_fatal
|
||||||
|
|
||||||
xsv select "Action" "$_file" \
|
[ ! -f "$_file" ] && lib_utils::die_fatal "File not found: '${_file}'"
|
||||||
| sort -u \
|
|
||||||
| tail -n +2 \
|
if [ -s "$_file" ]; then
|
||||||
| while read _line; do
|
xsv select "Action" "$_file" \
|
||||||
for _tag in "${_tags[@]}"; do
|
| sort -u \
|
||||||
[[ "$_line" != "$_tag" ]] || lib_utils::die_fatal "Bad entry in $_file"
|
| 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
|
||||||
done
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -1253,6 +1285,8 @@ function lib_taxes::__reports_obfs()
|
|||||||
lib_taxes::__reports_obfs_gen
|
lib_taxes::__reports_obfs_gen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# TODO: refactor to remove shellcheck
|
||||||
|
# shellcheck disable=SC2120
|
||||||
function lib_taxes::__reports_obfs_gen()
|
function lib_taxes::__reports_obfs_gen()
|
||||||
{
|
{
|
||||||
# Temp storage
|
# Temp storage
|
||||||
|
|||||||
Reference in New Issue
Block a user