From 9a04c8deb2e3210c571ec6d7808116824dfa56d1 Mon Sep 17 00:00:00 2001 From: stuzer05 Date: Fri, 29 Mar 2024 22:05:27 +0200 Subject: [PATCH] Add sum_max config property --- config.go | 1 + config.json.example | 7 +++++++ webhook.go | 35 ++++++++++++++++++++--------------- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/config.go b/config.go index 605c6e7..3b42489 100644 --- a/config.go +++ b/config.go @@ -21,6 +21,7 @@ type ConfigTransactionTypes struct { Names []string `json:"names,omitempty"` MccCodes []int `json:"mcc_codes,omitempty"` Firefly3 ConfigTransactionTypeFirefly3 `json:"firefly3,omitempty"` + SumMax int `json:"sum_max,omitempty"` } type ConfigTransactionTypeFirefly3 struct { diff --git a/config.json.example b/config.json.example index db2422b..b76479a 100644 --- a/config.json.example +++ b/config.json.example @@ -52,5 +52,12 @@ "destination": "Mono White" } }, + { + "names": ["Novapay"], + "firefly3": { + "description": "NovaPoshta: delivery" + }, + "sum_max": 150 + } ] } \ No newline at end of file diff --git a/webhook.go b/webhook.go index e1d8a01..034c4b5 100644 --- a/webhook.go +++ b/webhook.go @@ -81,22 +81,27 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) { } else { for _, row := range config.TransactionTypes { if slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description) || slices.Contains(row.MccCodes, monobankTransaction.Data.StatementItem.Mcc) { - switch row.Firefly3.Type { - case "withdrawal": - firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal - break - case "transfer": - firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer - break - default: - firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal - } + sum, _ := strconv.Atoi(firefly3Transaction.Amount) - firefly3Transaction.Description = row.Firefly3.Description - firefly3Transaction.DestinationName = row.Firefly3.Destination - firefly3Transaction.CategoryName = row.Firefly3.Category - firefly3Transactions = append(firefly3Transactions, firefly3Transaction) - break + // check max sum + if row.SumMax == 0 || sum <= row.SumMax { + switch row.Firefly3.Type { + case "withdrawal": + firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal + break + case "transfer": + firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer + break + default: + firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal + } + + firefly3Transaction.Description = row.Firefly3.Description + firefly3Transaction.DestinationName = row.Firefly3.Destination + firefly3Transaction.CategoryName = row.Firefly3.Category + firefly3Transactions = append(firefly3Transactions, firefly3Transaction) + break + } } } }