You've already forked monobank-firefly3-bot
Add auto-detection of transaction direction
All checks were successful
build docker image / docker-build (push) Successful in 1m6s
All checks were successful
build docker image / docker-build (push) Successful in 1m6s
For "description" only provided entries, auto detection doesn't work. As it searches if Source or Destenation is a monobank account by it's name
This commit is contained in:
@@ -146,7 +146,6 @@ func ImportTransaction(monobankTransaction monobank.WebHookResponse) error {
|
|||||||
Date: time.Unix(int64(monobankTransaction.Data.StatementItem.Time), 0).Add(time.Hour * time.Duration(timezoneHoursDiff)),
|
Date: time.Unix(int64(monobankTransaction.Data.StatementItem.Time), 0).Add(time.Hour * time.Duration(timezoneHoursDiff)),
|
||||||
Notes: string(monobankTransactionJson),
|
Notes: string(monobankTransactionJson),
|
||||||
Amount: strconv.Itoa(int(math.Abs(math.Round(monobankTransaction.Data.StatementItem.Amount/100))) - int(math.Abs(math.Round(monobankTransaction.Data.StatementItem.CommissionRate/100)))),
|
Amount: strconv.Itoa(int(math.Abs(math.Round(monobankTransaction.Data.StatementItem.Amount/100))) - int(math.Abs(math.Round(monobankTransaction.Data.StatementItem.CommissionRate/100)))),
|
||||||
SourceName: destAccount.Firefly3Name,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check max sum
|
// check max sum
|
||||||
@@ -154,28 +153,44 @@ func ImportTransaction(monobankTransaction monobank.WebHookResponse) error {
|
|||||||
if row.SumMax > 0 && sum > row.SumMax {
|
if row.SumMax > 0 && sum > row.SumMax {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// make transaction
|
|
||||||
switch row.Firefly3.Type {
|
transactionType := row.Firefly3.Type
|
||||||
case "withdrawal":
|
|
||||||
firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal
|
// choose transaction direction
|
||||||
break
|
switch transactionType {
|
||||||
case "deposit":
|
case "deposit":
|
||||||
firefly3Transaction.Type_ = &firefly3TransactionTypeDeposit
|
firefly3Transaction.Type_ = &firefly3TransactionTypeDeposit
|
||||||
break
|
break
|
||||||
case "transfer":
|
case "transfer":
|
||||||
firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer
|
firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer
|
||||||
break
|
break
|
||||||
|
case "withdrawal":
|
||||||
|
firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
|
transferSourceAccount := App().Config.GetAccountByMonobankId(monobankTransaction.Data.Account)
|
||||||
|
transferDestAccount := App().Config.GetAccountByFirefly3Name(row.Firefly3.Source)
|
||||||
|
|
||||||
|
if len(transferSourceAccount.Firefly3Name) > 0 && len(transferDestAccount.Firefly3Name) > 0 {
|
||||||
|
transactionType = "transfer" // set direction logic
|
||||||
|
firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer
|
||||||
|
} else if monobankTransaction.Data.StatementItem.Amount > 0 {
|
||||||
|
transactionType = "deposit" // set direction logic
|
||||||
|
firefly3Transaction.Type_ = &firefly3TransactionTypeDeposit
|
||||||
|
} else {
|
||||||
|
transactionType = "withdrawal" // set direction logic
|
||||||
firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal
|
firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
firefly3Transaction.Description = row.Firefly3.Description
|
// fmt.Println(transactionType)
|
||||||
firefly3Transaction.DestinationName = row.Firefly3.Destination
|
// return errors.New("cancel")
|
||||||
firefly3Transaction.CategoryName = row.Firefly3.Category
|
|
||||||
|
|
||||||
// swap source and destination
|
// transaction direction logic
|
||||||
if row.Firefly3.IsUseDestinationAsSource {
|
switch transactionType {
|
||||||
firefly3Transaction.SourceName, firefly3Transaction.DestinationName = firefly3Transaction.DestinationName, firefly3Transaction.SourceName
|
case "deposit", "transfer":
|
||||||
|
firefly3Transaction.SourceName = row.Firefly3.Destination
|
||||||
|
firefly3Transaction.DestinationName = destAccount.Firefly3Name
|
||||||
|
|
||||||
// when transfer between different currencies, convert
|
// when transfer between different currencies, convert
|
||||||
sourceAccount := App().Config.GetAccountByFirefly3Name(firefly3Transaction.SourceName)
|
sourceAccount := App().Config.GetAccountByFirefly3Name(firefly3Transaction.SourceName)
|
||||||
@@ -186,8 +201,15 @@ func ImportTransaction(monobankTransaction monobank.WebHookResponse) error {
|
|||||||
|
|
||||||
firefly3Transaction.ForeignCurrencyCode = destAccount.Currency
|
firefly3Transaction.ForeignCurrencyCode = destAccount.Currency
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
firefly3Transaction.SourceName = destAccount.Firefly3Name
|
||||||
|
firefly3Transaction.DestinationName = row.Firefly3.Destination
|
||||||
}
|
}
|
||||||
|
|
||||||
|
firefly3Transaction.Description = row.Firefly3.Description
|
||||||
|
firefly3Transaction.CategoryName = row.Firefly3.Category
|
||||||
|
|
||||||
firefly3Transactions = append(firefly3Transactions, firefly3Transaction)
|
firefly3Transactions = append(firefly3Transactions, firefly3Transaction)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@@ -22,8 +22,8 @@ type TransactionTypes struct {
|
|||||||
|
|
||||||
type TransactionTypeFirefly3 struct {
|
type TransactionTypeFirefly3 struct {
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
|
Source string `json:"source,omitempty"`
|
||||||
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"`
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user