Skip to content

Commit

Permalink
work on the functionality to show the total spent and total remaining…
Browse files Browse the repository at this point in the history
… in the budget
  • Loading branch information
ibilalkayy committed May 29, 2024
1 parent 370bb4c commit c8d3ff8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 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.117"
const version = "v0.1.118"

// rootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Expand Down
6 changes: 5 additions & 1 deletion framework/db/budget_db/budget_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ func (h MyBudgetDB) ViewBudget(category string) ([5]interface{}, error) {

// Initialize total amount
totalAmount := 0
spentAmount := 0
remainingAmount := 0

// Query the database based on the provided category
var rows *sql.Rows
Expand All @@ -105,11 +107,13 @@ func (h MyBudgetDB) ViewBudget(category string) ([5]interface{}, error) {
tw.AppendRow([]interface{}{bv.Category, bv.Amount, bv.Spent, bv.Remaining})
tw.AppendSeparator()
totalAmount += bv.Amount
spentAmount += bv.Spent
remainingAmount += bv.Remaining
}
}

// Add total amount row to the table
tw.AppendFooter(table.Row{"Total Amount", totalAmount})
tw.AppendFooter(table.Row{"Total Amount", totalAmount, spentAmount, remainingAmount})

// Render the table
tableRender := "Budget Data\n" + tw.Render()
Expand Down

0 comments on commit c8d3ff8

Please sign in to comment.