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,29 +81,37 @@ 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
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
}
} }
// check max sum
sum, _ := strconv.Atoi(firefly3Transaction.Amount)
if row.SumMax > 0 && sum > row.SumMax {
continue
}
// make transaction
switch row.Firefly3.Type {
case "withdrawal":
firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal
break
case "deposit":
firefly3Transaction.Type_ = &firefly3TransactionTypeDeposit
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
} }
} }