mirror of
https://github.com/Sea-Haven-Industries/afterhours-shift-manager.git
synced 2026-10-05 01:22:05 +00:00
DM pay reports to admin, rename email to Bonus Pay Summary
- Pay summary sent as DM to designated user instead of channel - Email shows only per-person totals, no shift breakdown - Renamed email subject/header to "Bonus Pay Summary"
This commit is contained in:
parent
a570a96311
commit
9e2eab6953
2 changed files with 16 additions and 22 deletions
|
|
@ -77,14 +77,6 @@ def _calculate_weekly_pay(schedule: ShiftSchedule, week_start: datetime) -> dict
|
||||||
|
|
||||||
def _build_pay_email_html(week_label: str, pay_record: dict) -> str:
|
def _build_pay_email_html(week_label: str, pay_record: dict) -> str:
|
||||||
"""Build an HTML email body for the weekly pay summary."""
|
"""Build an HTML email body for the weekly pay summary."""
|
||||||
rows = ""
|
|
||||||
for entry in pay_record["breakdown"]:
|
|
||||||
rows += (
|
|
||||||
f"<tr><td>{entry['day']}</td><td>{entry['date_label']}</td>"
|
|
||||||
f"<td>{entry['name']}</td><td>Ext {entry['extension']}</td>"
|
|
||||||
f"<td>${entry['rate']:.2f}</td></tr>\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
totals_rows = ""
|
totals_rows = ""
|
||||||
for name, info in sorted(pay_record["totals"].items()):
|
for name, info in sorted(pay_record["totals"].items()):
|
||||||
totals_rows += (
|
totals_rows += (
|
||||||
|
|
@ -94,14 +86,8 @@ def _build_pay_email_html(week_label: str, pay_record: dict) -> str:
|
||||||
|
|
||||||
return f"""<html>
|
return f"""<html>
|
||||||
<body style="font-family: Arial, sans-serif; color: #333;">
|
<body style="font-family: Arial, sans-serif; color: #333;">
|
||||||
<h2>After-Hours Pay Summary — {week_label}</h2>
|
<h2>Bonus Pay Summary — {week_label}</h2>
|
||||||
|
|
||||||
<h3>Shift Breakdown</h3>
|
|
||||||
<table border="1" cellpadding="6" cellspacing="0" style="border-collapse: collapse;">
|
|
||||||
<tr style="background: #f0f0f0;"><th>Day</th><th>Date</th><th>Name</th><th>Extension</th><th>Rate</th></tr>
|
|
||||||
{rows}</table>
|
|
||||||
|
|
||||||
<h3>Totals by Person</h3>
|
|
||||||
<table border="1" cellpadding="6" cellspacing="0" style="border-collapse: collapse;">
|
<table border="1" cellpadding="6" cellspacing="0" style="border-collapse: collapse;">
|
||||||
<tr style="background: #f0f0f0;"><th>Name</th><th>Shifts</th><th>Rate</th><th>Total</th></tr>
|
<tr style="background: #f0f0f0;"><th>Name</th><th>Shifts</th><th>Rate</th><th>Total</th></tr>
|
||||||
{totals_rows}</table>
|
{totals_rows}</table>
|
||||||
|
|
@ -128,7 +114,7 @@ def _send_pay_email(week_label: str, pay_record: dict) -> None:
|
||||||
Source=sender,
|
Source=sender,
|
||||||
Destination={"ToAddresses": recipients},
|
Destination={"ToAddresses": recipients},
|
||||||
Message={
|
Message={
|
||||||
"Subject": {"Data": f"After-Hours Pay Summary — {week_label}"},
|
"Subject": {"Data": f"Bonus Pay Summary — {week_label}"},
|
||||||
"Body": {"Html": {"Data": html_body}},
|
"Body": {"Html": {"Data": html_body}},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
@ -160,6 +146,8 @@ def handler(event, context):
|
||||||
prev_monday = prev_monday.replace(hour=0, minute=0, second=0, microsecond=0)
|
prev_monday = prev_monday.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
pay_record = _calculate_weekly_pay(schedule, prev_monday)
|
pay_record = _calculate_weekly_pay(schedule, prev_monday)
|
||||||
|
|
||||||
|
pay_dm_user = os.environ.get("PAY_REPORT_USER")
|
||||||
|
|
||||||
if pay_record["breakdown"]:
|
if pay_record["breakdown"]:
|
||||||
week_key = prev_monday.strftime("%Y-%m-%d")
|
week_key = prev_monday.strftime("%Y-%m-%d")
|
||||||
schedule.save_pay_record(week_key, pay_record)
|
schedule.save_pay_record(week_key, pay_record)
|
||||||
|
|
@ -169,12 +157,17 @@ def handler(event, context):
|
||||||
pay_blocks = build_pay_summary_blocks(
|
pay_blocks = build_pay_summary_blocks(
|
||||||
week_label, pay_record["breakdown"], pay_record["totals"]
|
week_label, pay_record["breakdown"], pay_record["totals"]
|
||||||
)
|
)
|
||||||
slack.chat_postMessage(
|
|
||||||
channel=channel_id,
|
# DM pay report to designated user instead of channel
|
||||||
blocks=pay_blocks,
|
if pay_dm_user:
|
||||||
text=f"After-Hours Pay — {week_label}",
|
slack.chat_postMessage(
|
||||||
)
|
channel=pay_dm_user,
|
||||||
logger.info("Posted pay summary for week of %s", week_key)
|
blocks=pay_blocks,
|
||||||
|
text=f"After-Hours Pay — {week_label}",
|
||||||
|
)
|
||||||
|
logger.info("Sent pay summary DM to %s for week of %s", pay_dm_user, week_key)
|
||||||
|
else:
|
||||||
|
logger.warning("PAY_REPORT_USER not set — skipping Slack pay summary")
|
||||||
|
|
||||||
# Email pay summary to payroll
|
# Email pay summary to payroll
|
||||||
_send_pay_email(week_label, pay_record)
|
_send_pay_email(week_label, pay_record)
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,7 @@ Resources:
|
||||||
SHIFT_CHANNEL_PARAM: /afterhours-shift-manager/channel-id
|
SHIFT_CHANNEL_PARAM: /afterhours-shift-manager/channel-id
|
||||||
SES_SENDER: noreply@seahaven.com
|
SES_SENDER: noreply@seahaven.com
|
||||||
PAYROLL_RECIPIENTS: adam@seahaven.com
|
PAYROLL_RECIPIENTS: adam@seahaven.com
|
||||||
|
PAY_REPORT_USER: U0A3SC48T47
|
||||||
TZ: !Ref Timezone
|
TZ: !Ref Timezone
|
||||||
Policies:
|
Policies:
|
||||||
- DynamoDBCrudPolicy:
|
- DynamoDBCrudPolicy:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue