Skip to content

Commit

Permalink
get the budget details with the remaining and spent amount
Browse files Browse the repository at this point in the history
  • Loading branch information
ibilalkayy committed May 30, 2024
1 parent aa1dd9b commit 54fe528
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/spf13/cobra"
)

const version = "v0.1.119"
const version = "v0.1.120"

// rootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Expand Down
10 changes: 6 additions & 4 deletions framework/db/budget_db/budget_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (h MyBudgetDB) GetBudgetData(filepath, filename string) error {
return err
}

query := "SELECT categories, amounts FROM Budget"
query := "SELECT categories, amounts, spent, remaining FROM Budget"
rows, err := db.Query(query)
if err != nil {
return err
Expand All @@ -380,18 +380,20 @@ func (h MyBudgetDB) GetBudgetData(filepath, filename string) error {
writer := csv.NewWriter(file)
defer writer.Flush()

header := []string{"Category", "Amount"}
header := []string{"Category", "Amount", "Spent Amount", "Remaining Amount"}
if err := writer.Write(header); err != nil {
return err
}
for rows.Next() {
if err := rows.Scan(&bv.Category, &bv.Amount); err != nil {
if err := rows.Scan(&bv.Category, &bv.Amount, &bv.Spent, &bv.Remaining); err != nil {
return err
}

var data []string
amountStr := h.Deps.Common.IntToString(bv.Amount)
data = append(data, bv.Category, amountStr)
spentStr := h.Deps.Common.IntToString(bv.Spent)
remainingStr := h.Deps.Common.IntToString(bv.Remaining)
data = append(data, bv.Category, amountStr, spentStr, remainingStr)
if err := writer.Write(data); err != nil {
return err
}
Expand Down

0 comments on commit 54fe528

Please sign in to comment.