|
| 1 | +from decimal import Decimal |
1 | 2 | import json |
2 | 3 | import re |
3 | 4 | import sys |
@@ -40,37 +41,53 @@ def print_summary(data): |
40 | 41 | fmt_value = fmt_value[:37] + "..." |
41 | 42 | click.echo(f"{key:>40s}: {fmt_value}") |
42 | 43 | click.echo("") |
43 | | - table = texttable.Texttable(max_width=100) |
44 | | - table.set_cols_align(["l", "r", "r", "r", "r", "c"]) |
45 | | - table.set_cols_valign(["m", "m", "m", "m", "m", "m"]) |
46 | | - table.add_row( |
47 | | - ["Scheme", "Open", "Close\nReported", "Close\nCalculated", "Transactions", "Status"] |
48 | | - ) |
| 44 | + table = texttable.Texttable(max_width=120) |
| 45 | + header = [ |
| 46 | + "Scheme", |
| 47 | + "Open", |
| 48 | + "Close\nReported", |
| 49 | + "Close\nCalculated", |
| 50 | + f"Value\n({data['statement_period']['to']})", |
| 51 | + "Transactions", |
| 52 | + "Status", |
| 53 | + ] |
| 54 | + table.add_row(header) |
| 55 | + table.set_cols_align(["l"] + ["r"] * (len(header) - 2) + ["c"]) |
| 56 | + table.set_cols_valign(["m"] * len(header)) |
49 | 57 | current_amc = None |
| 58 | + value = Decimal(0) |
50 | 59 | for folio in data["folios"]: |
51 | 60 | if current_amc != folio.get("amc", ""): |
52 | 61 | current_amc = folio["amc"] |
53 | | - table.add_row([current_amc] + [""] * 5) |
| 62 | + table.add_row([current_amc] + [""] * 6) |
54 | 63 | for scheme in folio["schemes"]: |
55 | 64 | calc_close = scheme["open"] + sum([x["units"] for x in scheme["transactions"]]) |
| 65 | + valuation = scheme["valuation"] |
56 | 66 | if calc_close != scheme["close"]: |
57 | 67 | err += 1 |
58 | 68 | status = "❗️" |
59 | 69 | else: |
60 | 70 | status = "️✅" |
61 | 71 | scheme_name = f"{scheme['scheme']}\nFolio: {folio['folio']}" |
| 72 | + value += valuation["value"] |
62 | 73 | table.add_row( |
63 | 74 | [ |
64 | 75 | scheme_name, |
65 | 76 | scheme["open"], |
66 | 77 | scheme["close"], |
67 | 78 | calc_close, |
| 79 | + f"₹{valuation['value']:,.2f}", |
68 | 80 | len(scheme["transactions"]), |
69 | 81 | status, |
70 | 82 | ] |
71 | 83 | ) |
72 | 84 | count += 1 |
73 | 85 | click.echo(table.draw()) |
| 86 | + click.echo( |
| 87 | + "Portfolio Valuation : " |
| 88 | + + click.style(f"₹{value:,.2f}", fg="green", bold=True) |
| 89 | + + f" [As of {data['statement_period']['to']}]" |
| 90 | + ) |
74 | 91 | click.secho("Summary", bold=True) |
75 | 92 | click.echo("Total : " + click.style(f"{count:4d}", fg="white", bold=True) + " schemes") |
76 | 93 | click.echo("Matched : " + click.style(f"{count - err:4d}", fg="green", bold=True) + " schemes") |
|
0 commit comments