# 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 date,description_,type,status_,currency_,amount_,from_email,to_email,txid,phone,note,balance_impact,direction,subaccount

# TODO: it's always localtime
date-format %m/%d/%Y %H:%M:%S
description %date

account1 assets:paypal-business:%subaccount:%currency_
amount %amount_ %currency_

#
# Comments
#

comment description:%description_, type:%type, balance_impact:%balance_impact, status:%status_, txid:%txid, direction:%direction

# w/ email

if %from_email [a-z0-9]
  comment description:%description_, type:%type, balance_impact:%balance_impact, status:%status_, from_email:%from_email, txid:%txid, direction:%direction

if %to_email [a-z0-9]
  comment description:%description_, type:%type, balance_impact:%balance_impact, status:%status_, to_email:%to_email, txid:%txid, direction:%direction

if %from_email [a-z0-9]
& %to_email [a-z0-9]
  comment description:%description_, type:%type, balance_impact:%balance_impact, status:%status_, from_email:%from_email, to_email:%to_email, txid:%txid, direction:%direction

# w/out email

if %note [a-z0-9]
  comment description:%description_, type:%type, balance_impact:%balance_impact, status:%status_, note:%note, txid:%txid, direction:%direction

if %phone [0-9]
  comment description:%description_, type:%type, balance_impact:%balance_impact, status:%status_, phone:%phone, txid:%txid, direction:%direction

if %note [a-z0-9]
& %phone [0-9]
  comment description:%description_, type:%type, balance_impact:%balance_impact, status:%status_, note:%note, phone:%phone, txid:%txid, direction:%direction

#  both w/ note

if %from_email [a-z0-9]
& %note [a-z0-9]
  comment description:%description_, type:%type, balance_impact:%balance_impact, status:%status_, from_email:%from_email, note:%note, txid:%txid, direction:%direction

if %to_email [a-z0-9]
& %note [a-z0-9]
  comment description:%description_, type:%type, balance_impact:%balance_impact, status:%status_, to_email:%to_email, note:%note, txid:%txid, direction:%direction

if %from_email [a-z0-9]
& %to_email [a-z0-9]
& %note [a-z0-9]
  comment description:%description_, type:%type, balance_impact:%balance_impact, status:%status_, from_email:%from_email, to_email:%to_email, note:%note, txid:%txid, direction:%direction

# both w/ phone

if %from_email [a-z0-9]
& %phone [0-9]
  comment description:%description_, type:%type, balance_impact:%balance_impact, status:%status_, from_email:%from_email, phone:%phone, txid:%txid, direction:%direction

if %to_email [a-z0-9]
& %phone [0-9]
  comment description:%description_, type:%type, balance_impact:%balance_impact, status:%status_, to_email:%to_email, phone:%phone, txid:%txid, direction:%direction

if %from_email [a-z0-9]
& %to_email [a-z0-9]
& %phone [0-9]
  comment description:%description_, type:%type, balance_impact:%balance_impact, status:%status_, from_email:%from_email, to_email:%to_email, phone:%phone, txid:%txid, direction:%direction

# all

if %from_email [a-z0-9]
& %to_email [a-z0-9]
& %note [a-z0-9]
& %phone [0-9]
  comment description:%description_, type:%type, balance_impact:%balance_impact, status:%status_, from_email:%from_email, to_email:%to_email, note:%note, phone:%phone, txid:%txid, direction:%direction

# ---------------------------------------------------------------------------- #
#                                     In                                       #
# ---------------------------------------------------------------------------- #

if %direction ^IN$
  account2 income:paypal-business:%subaccount:%currency_

if %direction ^IN$
& %type ^Debit Card Cash Back Bonus$
  account2 income:paypal-business:%subaccount:rebate:%currency_
  comment type:%type, balance_impact:%balance_impact, status:%status_, to_email:%to_email, txid:%txid, direction:%direction, taxed_as:REBATE

# All non-income considered capital contributions (use custom rules as needed)
if %direction ^IN$
& %note (Equity transfer|Capital contribution)
  account2 equity:paypal-business:%subaccount:withdrawal:contributions:%currency_

if %direction ^IN$
& %type ^Bank Deposit to PP Account$
  account2 equity:paypal-business:%subaccount:withdrawal:contributions:%currency_

# ---------------------------------------------------------------------------- #
#                                    Out                                       #
# ---------------------------------------------------------------------------- #

if %direction ^OUT$
  amount -%amount_ %currency_
  account2 expenses:paypal-business:%subaccount:%currency_

if %direction ^OUT$
& %description_ [0-9a-z]
  account2 expenses:paypal-business:%subaccount:%description_:%currency_

if %status_ Reversed
  amount -%amount_ %currency_

if %direction ^OUT$
& %note (Equity transfer|Capital contribution)
  account2 equity:paypal-business:%subaccount:deposit:%currency_

# ---------------------------------------------------------------------------- #
#                                    In/Out                                    #
# ---------------------------------------------------------------------------- #

if %type Account Hold
  account2 assets:paypal-business:%subaccount:payable:account_hold:%currency_

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