mirror of
https://github.com/chenasraf/cospend-cli.git
synced 2026-05-17 17:38:04 +00:00
feat: add total amount to list command
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user