From a16922f87aed5c5419c9df923bdd27c67c60f4f9 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Tue, 3 Sep 2024 21:19:18 -0700 Subject: [PATCH] container: hledger-flow: add Vultr support This addition is treading a fine line between finance and other accounting, as Vultr cloud service is related to DevOps and is also not a financial entity. However, financial information is provided; so this addition is useful. With this commit, a precedent is set for other cloud services to be added to the repository (services that provide CSV financial accounting data) and I believe that they could (should) be added as needed. NOTE: there are several upstream CSV issues: - Only expenses are given * Transfers must be added manually (manual import or custom rules) - Sales tax is not included * Sales tax expenses must be added manually --- .../accounts/vultr/template/vultr-shared.bash | 23 +++++ .../vultr/template/vultr-shared.rules | 20 +++++ .../1-in/mockup/2022/invoice_12345678.csv | 2 + .../1-in/mockup/2023/invoice_12345678.csv | 2 + .../1-in/mockup/2024/invoice_12345678.csv | 2 + .../vultr/template/vultr/credits/preprocess | 1 + .../vultr/credits/vultr-credits.rules | 20 +++++ .../accounts/vultr/vultr-shared.bash | 88 +++++++++++++++++++ .../accounts/vultr/vultr-shared.rules | 30 +++++++ 9 files changed, 188 insertions(+) create mode 100755 container/src/hledger-flow/accounts/vultr/template/vultr-shared.bash create mode 100644 container/src/hledger-flow/accounts/vultr/template/vultr-shared.rules create mode 100644 container/src/hledger-flow/accounts/vultr/template/vultr/credits/1-in/mockup/2022/invoice_12345678.csv create mode 100644 container/src/hledger-flow/accounts/vultr/template/vultr/credits/1-in/mockup/2023/invoice_12345678.csv create mode 100644 container/src/hledger-flow/accounts/vultr/template/vultr/credits/1-in/mockup/2024/invoice_12345678.csv create mode 120000 container/src/hledger-flow/accounts/vultr/template/vultr/credits/preprocess create mode 100644 container/src/hledger-flow/accounts/vultr/template/vultr/credits/vultr-credits.rules create mode 100755 container/src/hledger-flow/accounts/vultr/vultr-shared.bash create mode 100644 container/src/hledger-flow/accounts/vultr/vultr-shared.rules diff --git a/container/src/hledger-flow/accounts/vultr/template/vultr-shared.bash b/container/src/hledger-flow/accounts/vultr/template/vultr-shared.bash new file mode 100755 index 0000000..4f34bfa --- /dev/null +++ b/container/src/hledger-flow/accounts/vultr/template/vultr-shared.bash @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# docker-finance | modern accounting for the power-user +# +# Copyright (C) 2024 Aaron Fiore (Founder, Evergreen Crypto LLC) +# +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +[ -z "$DOCKER_FINANCE_CONTAINER_REPO" ] && exit 1 +source "${DOCKER_FINANCE_CONTAINER_REPO}/src/hledger-flow/accounts/vultr/vultr-shared.bash" + +# vim: sw=2 sts=2 si ai et diff --git a/container/src/hledger-flow/accounts/vultr/template/vultr-shared.rules b/container/src/hledger-flow/accounts/vultr/template/vultr-shared.rules new file mode 100644 index 0000000..7380334 --- /dev/null +++ b/container/src/hledger-flow/accounts/vultr/template/vultr-shared.rules @@ -0,0 +1,20 @@ +# docker-finance | modern accounting for the power-user +# +# Copyright (C) 2024 Aaron Fiore (Founder, Evergreen Crypto LLC) +# +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +include ../../../../../src/accounts/vultr/vultr-shared.rules + +# vim: sw=2 sts=2 si ai et diff --git a/container/src/hledger-flow/accounts/vultr/template/vultr/credits/1-in/mockup/2022/invoice_12345678.csv b/container/src/hledger-flow/accounts/vultr/template/vultr/credits/1-in/mockup/2022/invoice_12345678.csv new file mode 100644 index 0000000..b1dfcd8 --- /dev/null +++ b/container/src/hledger-flow/accounts/vultr/template/vultr/credits/1-in/mockup/2022/invoice_12345678.csv @@ -0,0 +1,2 @@ +"2024-01-01 01:01","2024-02-01 01:01","123.123.123.123 (4096 MB) [abc123.domain]","0.00","456","12.34" +"2024-01-01 01:01","2024-02-01 01:01","Backup Service for 123.123.123.123","0.00","123","1.23" diff --git a/container/src/hledger-flow/accounts/vultr/template/vultr/credits/1-in/mockup/2023/invoice_12345678.csv b/container/src/hledger-flow/accounts/vultr/template/vultr/credits/1-in/mockup/2023/invoice_12345678.csv new file mode 100644 index 0000000..b1dfcd8 --- /dev/null +++ b/container/src/hledger-flow/accounts/vultr/template/vultr/credits/1-in/mockup/2023/invoice_12345678.csv @@ -0,0 +1,2 @@ +"2024-01-01 01:01","2024-02-01 01:01","123.123.123.123 (4096 MB) [abc123.domain]","0.00","456","12.34" +"2024-01-01 01:01","2024-02-01 01:01","Backup Service for 123.123.123.123","0.00","123","1.23" diff --git a/container/src/hledger-flow/accounts/vultr/template/vultr/credits/1-in/mockup/2024/invoice_12345678.csv b/container/src/hledger-flow/accounts/vultr/template/vultr/credits/1-in/mockup/2024/invoice_12345678.csv new file mode 100644 index 0000000..b1dfcd8 --- /dev/null +++ b/container/src/hledger-flow/accounts/vultr/template/vultr/credits/1-in/mockup/2024/invoice_12345678.csv @@ -0,0 +1,2 @@ +"2024-01-01 01:01","2024-02-01 01:01","123.123.123.123 (4096 MB) [abc123.domain]","0.00","456","12.34" +"2024-01-01 01:01","2024-02-01 01:01","Backup Service for 123.123.123.123","0.00","123","1.23" diff --git a/container/src/hledger-flow/accounts/vultr/template/vultr/credits/preprocess b/container/src/hledger-flow/accounts/vultr/template/vultr/credits/preprocess new file mode 120000 index 0000000..891c52a --- /dev/null +++ b/container/src/hledger-flow/accounts/vultr/template/vultr/credits/preprocess @@ -0,0 +1 @@ +../../vultr-shared.bash \ No newline at end of file diff --git a/container/src/hledger-flow/accounts/vultr/template/vultr/credits/vultr-credits.rules b/container/src/hledger-flow/accounts/vultr/template/vultr/credits/vultr-credits.rules new file mode 100644 index 0000000..3a54a09 --- /dev/null +++ b/container/src/hledger-flow/accounts/vultr/template/vultr/credits/vultr-credits.rules @@ -0,0 +1,20 @@ +# docker-finance | modern accounting for the power-user +# +# Copyright (C) 2024 Aaron Fiore (Founder, Evergreen Crypto LLC) +# +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +include ../../vultr-shared.rules + +# vim: sw=2 sts=2 si ai et diff --git a/container/src/hledger-flow/accounts/vultr/vultr-shared.bash b/container/src/hledger-flow/accounts/vultr/vultr-shared.bash new file mode 100755 index 0000000..8d08d23 --- /dev/null +++ b/container/src/hledger-flow/accounts/vultr/vultr-shared.bash @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +# docker-finance | modern accounting for the power-user +# +# Copyright (C) 2024 Aaron Fiore (Founder, Evergreen Crypto LLC) +# +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# +# "Libraries" +# + +[ -z "$DOCKER_FINANCE_CONTAINER_REPO" ] && exit 1 +source "${DOCKER_FINANCE_CONTAINER_REPO}/src/hledger-flow/lib/lib_preprocess.bash" "$1" "$2" + +# +# Implementation +# + +function parse() +{ + [ -z "$global_year" ] && exit 1 + [ -z "$global_subaccount" ] && exit 1 + + [ -z "$global_in_path" ] && exit 1 + [ -z "$global_out_path" ] && exit 1 + + # + # NOTE: + # + # - Upstream does not provide CSV header + # + # - Invoice number is provided as filename + # * invoice_12345678.csv + # + + [ -z "$global_in_filename" ] && exit 1 + local -r _invoice="${global_in_filename:8:8}" + + gawk \ + -v global_year="$global_year" \ + -v global_subaccount="$global_subaccount" \ + -v invoice="$_invoice" \ + '{ + if ($2 !~ global_year) + next + + # Skip $1 # start date + + printf $2 OFS # end date (date) + printf $3 OFS # description + + # Skip $4 + + printf $5 OFS # quantity + printf $6 OFS # amount + + printf invoice OFS # invoice number + + # NOTE: Vultr currently only provides expenses w/out sales tax + direction="OUT" + printf direction OFS + + printf global_subaccount + + printf "\n" + }' FS=, OFS=, "$global_in_path" >"$global_out_path" +} + +function main() +{ + parse +} + +main "$@" + +# vim: sw=2 sts=2 si ai et diff --git a/container/src/hledger-flow/accounts/vultr/vultr-shared.rules b/container/src/hledger-flow/accounts/vultr/vultr-shared.rules new file mode 100644 index 0000000..4c827d3 --- /dev/null +++ b/container/src/hledger-flow/accounts/vultr/vultr-shared.rules @@ -0,0 +1,30 @@ +# docker-finance | modern accounting for the power-user +# +# Copyright (C) 2024 Aaron Fiore (Founder, Evergreen Crypto LLC) +# +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +fields date,description,quantity,amount_,invoice,direction,subaccount + +date-format %Y-%m-%d %H:%M + +account1 assets:vultr:%subaccount:USD +amount -%amount_ USD + +comment invoice:%invoice, quantity:%quantity, direction:%direction + +# NOTE: Vultr currently only provides expenses w/out sales tax +account2 expenses:vultr:%subaccount:USD + +# vim: sw=2 sts=2 si ai et