Skip to content

Commit

Permalink
fix from month
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyek committed Apr 3, 2024
1 parent 0244896 commit cb5595e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion projects/scrape-txs/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
service: scrape-txs-scheduled-lambda
service: scrape-txs-scheduled
frameworkVersion: '3'

provider:
Expand Down
17 changes: 16 additions & 1 deletion projects/update-ynab/banks/banks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package banks

import (
"fmt"
"log/slog"
"slices"
"time"

"bank-bots/update-ynab/types"
Expand Down Expand Up @@ -31,11 +33,13 @@ func LoadBankTxs(db *sqlx.DB) ([]types.BankAccountWithTransactions, error) {
fromMonth = time.Now()
}

slog.Info("loading bank txs", slog.String("fromMonth", fromMonth.Format("2006-01")))

bankTxs := []dbBankTx{}
sql := `
select *
from bank_txs
where month <= $1
where month >= $1
order by bank_key asc, account_number asc, date asc, doc_no asc`
err := db.Select(&bankTxs, sql, fromMonth.Format("2006-01"))
if err != nil {
Expand Down Expand Up @@ -83,8 +87,19 @@ func LoadBankTxs(db *sqlx.DB) ([]types.BankAccountWithTransactions, error) {
bankAccount.Transactions = append(bankAccount.Transactions, slice[0])
}
}
slices.SortFunc(bankAccount.Transactions, func(a, b types.PreparedBankTx) int {
return a.Date.Compare(b.Date)
})
bankAccounts = append(bankAccounts, bankAccount)
}

slog.Info("printing found bank txs:")
for _, bankAccount := range bankAccounts {
for _, bankTx := range bankAccount.Transactions {
slog.Info(fmt.Sprintf("account: %s, date: %s, doc_no: %s, amount: %d", bankAccount.Account.Number,
bankTx.Date.Format("2006-01-02"), bankTx.DocNo, bankTx.Amount))
}
}

return bankAccounts, nil
}
2 changes: 1 addition & 1 deletion projects/update-ynab/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
service: update-ynab-lambda
service: update-ynab
frameworkVersion: '3'

provider:
Expand Down

0 comments on commit cb5595e

Please sign in to comment.