container: hledger-flow: capital-one: add uniform quotes

- Allows undesirable characters in variable-text columns
- Related refactoring
This commit is contained in:
2026-02-13 10:36:55 -08:00
parent 7f4e739f9d
commit d81210bb8a

View File

@@ -2,7 +2,7 @@
# docker-finance | modern accounting for the power-user # docker-finance | modern accounting for the power-user
# #
# Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC) # Copyright (C) 2021-2026 Aaron Fiore (Founder, Evergreen Crypto LLC)
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -38,7 +38,9 @@ function parse_credit()
{ {
lib_preprocess::assert_header "Transaction Date,Posted Date,Card No.,Description,Category,Debit,Credit" lib_preprocess::assert_header "Transaction Date,Posted Date,Card No.,Description,Category,Debit,Credit"
gawk -v global_year="$global_year" -v global_subaccount="$global_subaccount" \ gawk --csv \
-v global_year="$global_year" \
-v global_subaccount="$global_subaccount" \
'{ '{
if (NR<2 || !NF || $1 !~ global_year) if (NR<2 || !NF || $1 !~ global_year)
next next
@@ -47,31 +49,35 @@ function parse_credit()
printf $2 OFS # Posted Date printf $2 OFS # Posted Date
printf $3 OFS # Card No. printf $3 OFS # Card No.
# Description
sub(/%/, "%%", $4) sub(/%/, "%%", $4)
printf $4 OFS # Description gsub(/"/, "", $4)
printf "\"" $4 "\"" OFS
printf $5 OFS # Category printf "\"" $5 "\"" OFS # Category
# Debit = OUT, Credit = IN # Debit = OUT, Credit = IN
direction=($6 ~ /[1-9]/ ? "OUT" : "IN") direction=($6 ~ /[1-9]/ ? "OUT" : "IN")
# Amount # Amount
if (direction == "OUT") {printf $6 FS} # Debit if (direction == "OUT") {printf $6 OFS} # Debit
else {printf $7 FS} # Credit else {printf $7 OFS} # Credit
printf direction OFS printf direction OFS
printf global_subaccount printf global_subaccount
printf "\n" printf "\n"
}' FS=, OFS=, "$global_in_path" >"$global_out_path" }' OFS=, "$global_in_path" >"$global_out_path"
} }
function parse_bank() function parse_bank()
{ {
lib_preprocess::assert_header "Account Number,Transaction Description,Transaction Date,Transaction Type,Transaction Amount,Balance" lib_preprocess::assert_header "Account Number,Transaction Description,Transaction Date,Transaction Type,Transaction Amount,Balance"
gawk -v global_year="$global_year" -v global_subaccount="$global_subaccount" \ gawk --csv \
-v global_year="$global_year" \
-v global_subaccount="$global_subaccount" \
'{ '{
if (NR>1 || NF) if (NR>1 || NF)
{ {
@@ -88,11 +94,13 @@ function parse_bank()
printf $1 OFS # Account Number printf $1 OFS # Account Number
# Transaction Description
sub(/%/, "%%", $2) sub(/%/, "%%", $2)
printf $2 OFS # Transaction Description gsub(/"/, "", $2)
printf "\"" $2 "\"" OFS
printf $3 OFS # Transaction Date printf $3 OFS # Transaction Date
printf $4 OFS # Transaction Type printf "\"" $4 "\"" OFS # Transaction Type
printf $5 OFS # Transaction Amount printf $5 OFS # Transaction Amount
printf $6 OFS # Balance printf $6 OFS # Balance
@@ -104,7 +112,7 @@ function parse_bank()
printf "\n" printf "\n"
} }
}' FS=, OFS=, "$global_in_path" >"$global_out_path" }' OFS=, "$global_in_path" >"$global_out_path"
} }
function main() function main()