Skip to content

Commit

Permalink
Write asset summary report to file
Browse files Browse the repository at this point in the history
  • Loading branch information
thinktwice13 committed Jun 10, 2022
1 parent 76f95f9 commit e146ebe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func main() {
PrettyPrint(tr)

r := NewReport("Portfolio Report")
summaries.WriteTo(r)
tr.WriteTo(r)
r.Save()
}
Expand Down
1 change: 1 addition & 0 deletions report_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (r *Report) WriteRows(sheet string, rows [][]interface{}) error {
}

func (r *Report) Save() error {
r.f.DeleteSheet("Sheet1")
err := r.f.SaveAs(r.filename)
if err != nil {
return err
Expand Down
48 changes: 35 additions & 13 deletions summaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ func (s *SummaryReport) Title() string {
return "Summary"
}

func (s *SummaryReport) HeaderRow() []interface{} {
return []interface{}{
"Symbols",
"Category",
"Year",
"Profit/Loss",
"Taxable PL",
"Fees",
"Dividends",
"Withholding Tax",
}
}

type Rater interface {
Rate(string, int) float64
}
Expand Down Expand Up @@ -195,3 +182,38 @@ func tradeAsset(ts []Trade) ([]Sale, []Transaction, []Trade) {
func taxableDeadline(since time.Time) time.Time {
return since.AddDate(2, 0, 0)
}

func (s *SummaryReport) WriteTo(rw RowWriter) error {
srows := make([][]interface{}, 0, len(*s))
srows = append(srows, []interface{}{
"Asset",
"Category",
"Year",
"Profit/Loss",
"Taxable PL",
"Fees",
"Dividends",
"Withholding Tax",
})

for _, a := range *s {
for _, y := range a.Years {
srows = append(srows, []interface{}{
a.Symbols,
a.Category,
y.Year,
y.Pl,
y.Taxable,
y.Fees,
y.Dividends,
y.WithholdingTax,
})
}
}

err := rw.WriteRows("Summary", srows)
if err != nil {
return err
}
return nil
}

0 comments on commit e146ebe

Please sign in to comment.