feat(go): add --print-fio-table flag to fuj sync --dry-run
All checks were successful
Deploy to K8s / deploy (push) Successful in 7s
All checks were successful
Deploy to K8s / deploy (push) Successful in 7s
Prints an aligned tabwriter table of every Fio transaction in the look-back window, with a STATUS column showing NEW (would be appended) or DUP (already in sheet). Only fires when --dry-run is also set, so it can't affect real syncs. Refactors Sync ID computation into a single pre-pass shared by both the table printer and the row builder. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"fuj-management/go/internal/domain/synch"
|
||||
"fuj-management/go/internal/io/fio"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -27,10 +28,11 @@ type sheetsWriter interface {
|
||||
|
||||
// SyncOpts controls the date window and sort behaviour.
|
||||
type SyncOpts struct {
|
||||
Days int // look-back window when From/To are zero
|
||||
From, To time.Time // explicit window (overrides Days)
|
||||
Sort bool // sort the sheet by Date after appending
|
||||
DryRun bool // print planned writes without modifying the sheet
|
||||
Days int // look-back window when From/To are zero
|
||||
From, To time.Time // explicit window (overrides Days)
|
||||
Sort bool // sort the sheet by Date after appending
|
||||
DryRun bool // print planned writes without modifying the sheet
|
||||
PrintFioTable bool // with DryRun: print every fetched Fio txn with NEW/DUP status
|
||||
}
|
||||
|
||||
// SyncToSheets fetches Fio transactions and appends new ones to the payments sheet.
|
||||
@@ -92,14 +94,14 @@ func SyncToSheets(
|
||||
from.Format("2006-01-02"), to.Format("2006-01-02"), len(txns))
|
||||
}
|
||||
|
||||
// 4. Append new rows.
|
||||
var newRows [][]any
|
||||
for _, tx := range txns {
|
||||
// 4a. Compute Sync IDs for every fetched txn (shared by table-print and row-build).
|
||||
syncIDs := make([]string, len(txns))
|
||||
for i, tx := range txns {
|
||||
currency := tx.Currency
|
||||
if currency == "" {
|
||||
currency = "CZK"
|
||||
}
|
||||
id := synch.GenerateSyncID(synch.Transaction{
|
||||
syncIDs[i] = synch.GenerateSyncID(synch.Transaction{
|
||||
Date: tx.Date,
|
||||
Amount: tx.Amount,
|
||||
Currency: currency,
|
||||
@@ -108,13 +110,23 @@ func SyncToSheets(
|
||||
Message: tx.Message,
|
||||
BankID: tx.BankID,
|
||||
})
|
||||
if existingIDs[id] {
|
||||
}
|
||||
|
||||
// 4b. Optional debug table (dry-run only).
|
||||
if opts.DryRun && opts.PrintFioTable {
|
||||
printFioTable(os.Stdout, txns, syncIDs, existingIDs)
|
||||
}
|
||||
|
||||
// 4c. Build new rows.
|
||||
var newRows [][]any
|
||||
for i, tx := range txns {
|
||||
if existingIDs[syncIDs[i]] {
|
||||
continue
|
||||
}
|
||||
newRows = append(newRows, []any{
|
||||
tx.Date, tx.Amount,
|
||||
"", "", "", "", // manual fix, Person, Purpose, Inferred Amount
|
||||
tx.Sender, tx.VS, tx.Message, tx.BankID, id,
|
||||
tx.Sender, tx.VS, tx.Message, tx.BankID, syncIDs[i],
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user