Add sum_max config property

This commit is contained in:
Illya Marchenko 2024-03-29 22:05:27 +02:00
parent 774ca114dd
commit 9a04c8deb2
Signed by: stuzer05
GPG Key ID: A6ABAAA9268F9F4F
3 changed files with 28 additions and 15 deletions

@ -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 {

@ -52,5 +52,12 @@
"destination": "Mono White"
}
},
{
"names": ["Novapay"],
"firefly3": {
"description": "NovaPoshta: delivery"
},
"sum_max": 150
}
]
}

@ -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
}
}
}
}