Add support for swap source&destination

This commit is contained in:
Illya Marchenko 2024-03-29 22:42:44 +02:00
parent b5d81243e0
commit de4369997d
Signed by: stuzer05
GPG Key ID: A6ABAAA9268F9F4F
3 changed files with 51 additions and 44 deletions

@ -29,6 +29,7 @@ type ConfigTransactionTypeFirefly3 struct {
Destination string `json:"destination,omitempty"` Destination string `json:"destination,omitempty"`
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
Category string `json:"category,omitempty"` Category string `json:"category,omitempty"`
IsUseDestinationAsSource bool `json:"is_use_destination_as_source,omitempty"`
} }
func ReadConfig(path string) (Config, error) { func ReadConfig(path string) (Config, error) {

@ -52,6 +52,15 @@
"destination": "Mono White" "destination": "Mono White"
} }
}, },
{
"names": ["Термінал EasyPay", "City24", "Термінал City24"],
"firefly3": {
"type": "transfer",
"description": "Transfer between accounts",
"destination": "Wallet cash (UAH)",
"is_use_destination_as_source": true
}
},
{ {
"names": ["Novapay"], "names": ["Novapay"],
"firefly3": { "firefly3": {

@ -72,14 +72,7 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
SourceId: account.Firefly3Id, SourceId: account.Firefly3Id,
} }
// Special transaction cases // match transaction with config
if slices.Contains([]string{"Термінал EasyPay", "City24", "Термінал City24"}, monobankTransaction.Data.StatementItem.Description) {
firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer
firefly3Transaction.Description = "Transfer between accounts"
firefly3Transaction.SourceName = "Wallet cash (UAH)" // test
firefly3Transaction.DestinationId = account.Firefly3Id // test
firefly3Transactions = append(firefly3Transactions, firefly3Transaction)
} else {
for _, row := range config.TransactionTypes { for _, row := range config.TransactionTypes {
// check name & mcc // check name & mcc
if !(slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description) || slices.Contains(row.MccCodes, monobankTransaction.Data.StatementItem.Mcc)) { if !(slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description) || slices.Contains(row.MccCodes, monobankTransaction.Data.StatementItem.Mcc)) {
@ -111,8 +104,12 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
firefly3Transaction.DestinationName = row.Firefly3.Destination firefly3Transaction.DestinationName = row.Firefly3.Destination
firefly3Transaction.CategoryName = row.Firefly3.Category firefly3Transaction.CategoryName = row.Firefly3.Category
firefly3Transactions = append(firefly3Transactions, firefly3Transaction) firefly3Transactions = append(firefly3Transactions, firefly3Transaction)
break
// swap source and destination
if row.Firefly3.IsUseDestinationAsSource {
firefly3Transaction.SourceName, firefly3Transaction.DestinationName = firefly3Transaction.DestinationName, firefly3Transaction.SourceName
} }
break
} }
// record transfer fee // record transfer fee