From a545b7e347504727103dce1c4a90a44c38acc011 Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Tue, 3 Feb 2026 16:17:04 +0200 Subject: [PATCH] feat: add total amount to list command --- cmd/list.go | 4 +++- cmd/list_test.go | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/list.go b/cmd/list.go index 6f62e8d..5828b0a 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -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) } diff --git a/cmd/list_test.go b/cmd/list_test.go index 906bf42..1cee24f 100644 --- a/cmd/list_test.go +++ b/cmd/list_test.go @@ -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") } }