# 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 tx_completed,tx_initiated,tx_type,pid,amount_requested,tid_code,status_,payment_asset,payment_exchange_rate,subtotal_crypto,subtotal_fiat,fee_asset,fee_exchange_rate,coinbase_fee_crypto,coinbase_fee_fiat,network_fee_crypto,network_fee_fiat,conversion_status,conversion_exchange_rate,conversion_fiat_value,receiver_address,eth_homestead,metadata,system_id,txid,direction,subaccount

date %tx_initiated
date-format %Y-%m-%d %H:%M:%S

account1 assets:coinbase-commerce:%subaccount:%payment_asset
amount %subtotal_crypto %payment_asset

description %tx_initiated +0000
comment type:%tx_type, pid:%pid, system_id:%system_id, txid:%txid, direction:%direction

# All deposits are considered income (if different, apply in custom rules)
if %direction ^IN$
  account2 income:coinbase-commerce:%subaccount:%payment_asset
  amount %subtotal_crypto %payment_asset
  comment type:%tx_type, pid:%pid, system_id:%system_id, subtotal_fiat:%subtotal_fiat, direction:%direction
  comment2 %tx_initiated +0000,INCOME,coinbase-commerce:%subaccount,%payment_asset,%subtotal_crypto,USD,%subtotal_fiat,PAYMENT

if %direction ^OUT$
  amount -%subtotal_crypto %payment_asset
  account2 expenses:coinbase-commerce:%subaccount:withdrawals:%payment_asset
  comment type:%tx_type, txid:%txid, direction:%direction

# NOTE: there will (should) always be coinbase and network fees for withdrawals
# NOTE: Coinbase's (non-network) fees will always be deducted from the expense account, not assets
if %direction ^OUT$
& %coinbase_fee_crypto [1-9]
  amount3 -%coinbase_fee_crypto %fee_asset
  account3 expenses:coinbase-commerce:%subaccount:withdrawals:%fee_asset
  amount4 %coinbase_fee_crypto %fee_asset
  account4 expenses:coinbase-commerce:%subaccount:fees:coinbase:%fee_asset
  comment2 %tx_initiated +0000,SPEND,coinbase-commerce:%subaccount,%fee_asset,%coinbase_fee_crypto,USD,,BANK_FEE

if %direction ^OUT$
& %network_fee_crypto [1-9]
  amount5 -%network_fee_crypto %fee_asset
  account5 assets:coinbase-commerce:%subaccount:%fee_asset
  amount6 %network_fee_crypto %fee_asset
  account6 expenses:coinbase-commerce:%subaccount:fees:network:%fee_asset
  comment type:%tx_type, txid:%txid, direction:%direction, taxed_as:SPEND
  comment3 %tx_initiated +0000,SPEND,coinbase-commerce:%subaccount,%fee_asset,%network_fee_crypto,USD,,FEE

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