aboutsummaryrefslogtreecommitdiffstats
path: root/python/report_ops/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/report_ops/utils.py')
-rw-r--r--python/report_ops/utils.py59
1 files changed, 56 insertions, 3 deletions
diff --git a/python/report_ops/utils.py b/python/report_ops/utils.py
index 1360f102..325a4179 100644
--- a/python/report_ops/utils.py
+++ b/python/report_ops/utils.py
@@ -15,14 +15,14 @@ from decimal import Decimal
import math
import re
from zoneinfo import ZoneInfo
-from .misc import _recipients, _cc_recipients
+from .misc import _recipients, _cc_recipients, _settlement_recipients
from tabulate import tabulate
logger = logging.getLogger(__name__)
def next_business_days(date, offset):
- for i in range(offset):
+ for i in range(offset + 1):
date = next_business_day(date)
return date
@@ -65,6 +65,20 @@ def round_up(n, decimals=0):
return math.ceil(n * multiplier) / multiplier
+def notify_payment_settlements(date, fund, conn):
+ end_date = next_business_days(date, 2)
+ with conn.cursor() as c:
+ c.execute(
+ "SELECT * from payment_settlements WHERE settle_date BETWEEN %s AND %s AND fund= %s AND asset_class in ('SPOT', 'SWAPTION', 'TRANCHE') ORDER BY settle_date asc",
+ (date, end_date, fund),
+ )
+ for row in c:
+ d = row._asdict()
+ d["settlement_amount"] = d["payment_amount"]
+ PaymentMonitor.stage(row._asdict())
+ PaymentMonitor.email(fund)
+
+
@dataclass
class CitcoSubmission(Deal, deal_type=None, table_name="citco_submission2"):
id: int = field(init=False, metadata={"insert": False})
@@ -320,7 +334,7 @@ class SettlementMonitor(
</style>
</head>
<body>
- Good morning,<br><br>We see a projected overdraft on the below dates. Please move to cover:<br><br>{cls.to_tabulate()}
+ Hello,<br><br>We see a projected overdraft on the below dates. Please move to cover:<br><br>{cls.to_tabulate()}
</body>
</html>"""
),
@@ -329,6 +343,45 @@ class SettlementMonitor(
)
+class PaymentMonitor(
+ Monitor,
+ headers=(
+ "settle_date",
+ "account",
+ "name",
+ "cp_code",
+ "settlement_amount",
+ "currency",
+ "asset_class",
+ "ids",
+ ),
+ num_format=[("{0:,.2f}", 4)],
+):
+ @classmethod
+ def email(cls, fund):
+ if not cls._insert_queue:
+ return
+ cls._em.send_email(
+ f"Projected Settlements: {fund}",
+ HTMLBody(
+ f"""
+<html>
+ <head>
+ <style>
+ table, th, td {{ border: 1px solid black; border-collapse: collapse;}}
+ th, td {{ padding: 5px; }}
+ </style>
+ </head>
+ <body>
+ Hello,<br><br>We see the below settlements in the next two days (Positive=Receive, Negative=Pay):<br><br>{cls.to_tabulate()}
+ </body>
+</html>"""
+ ),
+ to_recipients=_settlement_recipients[fund],
+ cc_recipients=_cc_recipients[fund],
+ )
+
+
@dataclass
class EmailOps:
_em = ExchangeMessage()