# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2021-2025 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 <https://www.gnu.org/licenses/>.

fields Asset,AccountName,Address,AddressName,Value,Symbol,Fees,FeeSymbol,InternalTransfer,TransactionID,Time_UTC,Time_ISO8601-UTC,BlockExplorer,Direction,Subaccount

date %Time_ISO8601-UTC
date-format %Y-%m-%d %H:%M:%S
description %Time_ISO8601-UTC +0000

account1 assets:coinomi:%Subaccount:%Symbol
amount %Value %Symbol

# NOTE: when tagging SPEND, if using Algorand, docker-finance must use 'Direction'
# instead of counting on 'Fees' only for OUT because Algorand (on this wallet)
# apparently take a fee for going IN...
comment url:%BlockExplorer, address:%Address, txid:%TransactionID, direction:%Direction

# See preprocess note
if %AccountName ^SKIP$
  skip

# NOTE: testnet coins will need to be filtered out of tax reports (it's not done here)

if %direction ^OUT$
  amount -%Value %Symbol

# Default equity instead of income (more likely a transfer than real income)
if %Direction ^IN$
  account2 equity:coinomi:%Subaccount:withdrawal:%Symbol

if %Direction ^OUT$
  account2 equity:coinomi:%Subaccount:deposit:%Symbol

# Default out as expenses, not equity
if %Direction ^OUT$
  account2 expenses:coinomi:%Subaccount:%Symbol

if %Direction ^OUT$
& %Fees [1-9]
  account3 assets:coinomi:%Subaccount:%FeeSymbol
  amount3 -%Fees %FeeSymbol
  account4 expenses:coinomi:%Subaccount:fees:%FeeSymbol
  amount4 %Fees %FeeSymbol
  comment url:%BlockExplorer, address:%Address, txid:%TransactionID, direction:%Direction, taxed_as:SPEND
  comment3 %Time_ISO8601-UTC +0000,SPEND,coinomi:%Subaccount,%FeeSymbol,%Fees,USD,,FEE

# Avoid fee double-spends for (ERC-20, etc.) tokens!
# Remove the ETH-only fee and change the attached fee (implied GAS) to the actual spend TX
# TODO: only ETH supported
if %Direction ^OUT$
& %Symbol ^ETH$
& %Value ^[^1-9]*$
& %Fees [1-9]
  skip

# vim: sw=2 sts=2 si ai et
