feat: add total amount to list command

This commit is contained in:
2026-02-03 16:17:04 +02:00
parent 9c5eda351b
commit a545b7e347
2 changed files with 5 additions and 3 deletions

View File

@@ -295,7 +295,9 @@ func printBillsTable(cmd *cobra.Command, project *api.Project, bills []api.BillR
table := NewTable("ID", "DATE", "NAME", "AMOUNT", "PAID BY", "PAID FOR", "CATEGORY", "METHOD")
var totalAmount float64
for _, bill := range bills {
totalAmount += bill.Amount
// Get payer name
payerName := memberNames[bill.PayerID]
if payerName == "" {
@@ -351,5 +353,5 @@ func printBillsTable(cmd *cobra.Command, project *api.Project, bills []api.BillR
out := cmd.OutOrStdout()
table.Render(out)
_, _ = fmt.Fprintf(out, "\nTotal: %d bill(s)\n", len(bills))
_, _ = fmt.Fprintf(out, "\nTotal: %d bill(s), %.2f\n", len(bills), totalAmount)
}

View File

@@ -186,8 +186,8 @@ func TestPrintBillsTable(t *testing.T) {
if !bytes.Contains([]byte(output), []byte("50.00")) {
t.Error("Output should contain amount '50.00'")
}
if !bytes.Contains([]byte(output), []byte("Total: 1 bill(s)")) {
t.Error("Output should contain total count")
if !bytes.Contains([]byte(output), []byte("Total: 1 bill(s), 50.00")) {
t.Error("Output should contain total count and amount")
}
}