This commit is contained in:
Illya Marchenko 2024-03-29 22:18:37 +02:00
parent 9a04c8deb2
commit b5d81243e0
Signed by: stuzer05
GPG Key ID: A6ABAAA9268F9F4F

@ -17,6 +17,7 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
var err error var err error
firefly3TransactionTypeWithdrawal := firefly3.WITHDRAWAL_TransactionTypeProperty firefly3TransactionTypeWithdrawal := firefly3.WITHDRAWAL_TransactionTypeProperty
firefly3TransactionTypeDeposit := firefly3.DEPOSIT_TransactionTypeProperty
firefly3TransactionTypeTransfer := firefly3.TRANSFER_TransactionTypeProperty firefly3TransactionTypeTransfer := firefly3.TRANSFER_TransactionTypeProperty
// read request // read request
@ -80,15 +81,25 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
firefly3Transactions = append(firefly3Transactions, firefly3Transaction) firefly3Transactions = append(firefly3Transactions, firefly3Transaction)
} else { } else {
for _, row := range config.TransactionTypes { for _, row := range config.TransactionTypes {
if slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description) || slices.Contains(row.MccCodes, monobankTransaction.Data.StatementItem.Mcc) { // check name & mcc
sum, _ := strconv.Atoi(firefly3Transaction.Amount) if !(slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description) || slices.Contains(row.MccCodes, monobankTransaction.Data.StatementItem.Mcc)) {
continue
}
// check max sum // check max sum
if row.SumMax == 0 || sum <= row.SumMax { sum, _ := strconv.Atoi(firefly3Transaction.Amount)
if row.SumMax > 0 && sum > row.SumMax {
continue
}
// make transaction
switch row.Firefly3.Type { switch row.Firefly3.Type {
case "withdrawal": case "withdrawal":
firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal
break break
case "deposit":
firefly3Transaction.Type_ = &firefly3TransactionTypeDeposit
break
case "transfer": case "transfer":
firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer
break break
@ -103,8 +114,6 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
break break
} }
} }
}
}
// record transfer fee // record transfer fee
if monobankTransaction.Data.StatementItem.CommissionRate > 0 { if monobankTransaction.Data.StatementItem.CommissionRate > 0 {