Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions backend/ui/static/js/specialSitTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -1107,14 +1107,25 @@ function updateSSDivData(symbol, field, value) {
// Allow it to fall through to saving logic below
}
if (field === 'expected_amount') {
// Strip out non-numeric chars in case they edited formatting
// Check if they effectively reverted to the original backend value
let originalItemHtml = (item.expected_amount ? `${parseFloat(item.expected_amount).toFixed(2)} <span style="font-size: 0.8em; color: #aaa;">(${item.expected_type || 'Interim'})</span>` : '-').replace(/<[^>]*>?/gm, '').trim();
let cleanedVal = value.replace(/<[^>]*>?/gm, '').replace(/\*/g, '').trim(); // Remove tags and our own asterisk
let num = value.replace(/[^0-9.]/g, '');
if (num) {
item.expected_amount = parseFloat(num);
item._edited_expected_amount = value; // Store raw HTML for rendering

if (cleanedVal === originalItemHtml || cleanedVal === (item.expected_amount ? parseFloat(item.expected_amount).toFixed(2) : '-')) {
// Reverted to original, clear override
delete item._edited_expected_amount;
if (num) {
item.expected_amount = parseFloat(num);
}
} else {
item.expected_amount = null;
item._edited_expected_amount = value;
if (num) {
item.expected_amount = parseFloat(num);
item._edited_expected_amount = value.replace(/\*/g, '').trim(); // Store raw HTML for rendering, remove asterisk
} else {
item.expected_amount = null;
item._edited_expected_amount = value.replace(/\*/g, '').trim();
}
}
} else {
if (field === 'expected_highly_likely' && typeof value === 'string') {
Expand Down Expand Up @@ -1341,7 +1352,7 @@ function renderSSDividends() {
let expectedAmountHTML = item._edited_expected_amount || (item.expected_amount ? `${parseFloat(item.expected_amount).toFixed(2)} <span style="font-size: 0.8em; color: #aaa;">(${item.expected_type || 'Interim'})</span>` : '-');

if (isOverridden) {
expectedAmountHTML = `${expectedAmountHTML} <span style="color: #ffeb3b; font-size: 0.8em;" title="Manually Edited">*</span>`;
expectedAmountHTML = `${expectedAmountHTML} <span style="color: #ffeb3b; font-size: 1.2em; font-weight: bold; margin-left: 4px;" title="Manually Edited">*</span>`;
} else if (item.expected_amount && item.expected_amount_compare) {
let numExpected = parseFloat(item.expected_amount);
let numLast = parseFloat(item.expected_amount_compare);
Expand Down
11 changes: 6 additions & 5 deletions backend/web/api/data/derivatives_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,10 +812,11 @@ def get_marketwatch(date: str = None, custom_symbols: str = None, db: Session =
for bm in bm_records:
if bm.purpose and ('dividend' in bm.purpose.lower() or 'financial' in bm.purpose.lower()):
if bm.extracted_dividend_amount:
# User case 2: "Div- Rs 2.40, ex-dayt not yet announced"
ca_map[bm.symbol.upper()] = f"Div- Rs {bm.extracted_dividend_amount}, ex-date not yet announced"
# User case: "Div- Rs 5, ex-date not announced (Expected: Jan)"
expected_month = bm.meeting_date.strftime('%b') if bm.meeting_date else ""
ca_map[bm.symbol.upper()] = f"Div- Rs {bm.extracted_dividend_amount}, ex-date not announced (Expected: {expected_month})"
else:
# User case 1: "Boardmeeting, date"
# User case: "Boardmeeting, date"
date_str = bm.meeting_date.strftime('%d-%m-%Y') if bm.meeting_date else ""
ca_map[bm.symbol.upper()] = f"Boardmeeting, date-{date_str}"

Expand All @@ -832,8 +833,8 @@ def get_marketwatch(date: str = None, custom_symbols: str = None, db: Session =
).all()
for r in ca_records:
date_str = r.ex_date.strftime('%d-%m-%Y') if r.ex_date else ""
# According to user: case 3. div - 5.25, Ex-date 11-05-2026
ca_map[r.symbol.upper()] = f"div - {r.parsed_dividend_amount}, Ex-date {date_str}"
# User case: "div - 5, Ex-date 15-01-2024 (Confirmed)"
ca_map[r.symbol.upper()] = f"div - {r.parsed_dividend_amount}, Ex-date {date_str} (Confirmed)"
except Exception as e:
import traceback
traceback.print_exc()
Expand Down
16 changes: 14 additions & 2 deletions backend/web/api/data/special_sit_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ def circ_diff(d1, d2):
# before or during market hours, we MUST use the previous day's closing price
price_query = price_query.filter(BhavcopyEQ.trade_date < ref_date.date())
else:
# As per user instruction, if we are unsure of the exact time, check the previous day price
if hasattr(ref_date, "date"):
price_query = price_query.filter(BhavcopyEQ.trade_date < ref_date.date())
else:
Expand Down Expand Up @@ -303,7 +304,17 @@ def circ_diff(d1, d2):
last_type = last['dividend_type'] or '-'
last_ex_date = last['ex_date'] or '-'
last_amount = last['amount']
is_above_2_percent = last.get('is_above_2_percent', False)

# User reported that dividends with past ex-dates are incorrectly triggering the extra-ordinary = yes flag for future forecasts.
# Only set it for the main row if it's the latest event AND the ex_date hasn't passed yet or is today.
# If it's a past event, the main row shouldn't inherit its >2% flag, as we are looking ahead.
latest_ex_date_obj = last.get('ex_date_obj')
if latest_ex_date_obj and latest_ex_date_obj >= today:
is_above_2_percent = last.get('is_above_2_percent', False)
elif not latest_ex_date_obj: # e.g. "Record date not yet declared"
is_above_2_percent = last.get('is_above_2_percent', False)
else:
is_above_2_percent = False

# Sort ascending for cycle processing
history_asc = sorted(history, key=lambda x: x['ex_date_obj'] if x['ex_date_obj'] else datetime.date.min)
Expand Down Expand Up @@ -424,7 +435,8 @@ def circ_diff(d1, d2):

# Add note to check for >2% if forecasted amount is high
if spot and expected_amount and (expected_amount / spot) >= 0.02:
expected_less_likely = "extra ordinary"
expected_less_likely = "<span style='color: red;'>check for extra-ordinary</span>"
is_above_2_percent = True

expected_highly_likely = f"Forecasted: {next_cycle['next_date'].strftime('%d-%m-%Y')}"
if not expected_less_likely:
Expand Down
Loading