Skip to content

Commit b78297d

Browse files
committed
hua hai
1 parent 5f109f5 commit b78297d

1 file changed

Lines changed: 56 additions & 1 deletion

File tree

app.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def extract_itr_hybrid(text):
632632

633633
patterns = {
634634
"assessee_name": [
635-
r"(?i)(?:Name|Assessee)(?:\s+of\s+(?:the\s+)?(?:Assessee|Tax\s*Payer))?[\s:\-]*([A-Z][A-Za-z\s\.]+?)(?:\n|PAN|Father)",
635+
r"(?i)(?:Name|Assessee)(?:\s+of\s+(?:the\s+)?(?:Assessee|Tax\s*Payer))?[\s:\-]*([A-Z][A-Za-z\s\.]+?)(?:\n|PAN)",
636636
r"(?i)Name\s+as\s+per\s+PAN[\s:\-]*([A-Z][A-Za-z\s\.]+)",
637637
r"(?i)Full\s+Name[\s:\-]*([A-Z][A-Za-z\s\.]+)"
638638
],
@@ -1971,6 +1971,44 @@ def build_prefill_from_insights(qid: int) -> dict:
19711971
except Exception:
19721972
pass
19731973

1974+
# Extract monthly EMI from bank statement recurring debits
1975+
try:
1976+
uploads = list_questionnaire_uploads(qid) or []
1977+
total_monthly_emi = 0.0
1978+
emi_keywords = ["emi", "loan", "mortgage", "instalment", "installment", "repayment", "home loan", "car loan", "personal loan", "vehicle loan", "housing loan"]
1979+
for upload in uploads:
1980+
if (upload["doc_type"] or "").lower() == "bank statement":
1981+
metadata_json = upload["metadata_json"]
1982+
if metadata_json:
1983+
try:
1984+
metadata = json.loads(metadata_json)
1985+
bank_data = metadata.get("bank_data") or {}
1986+
recurring_debits = bank_data.get("recurring_debits") or []
1987+
for debit in recurring_debits:
1988+
desc = (debit.get("description") or "").lower()
1989+
amount = debit.get("amount")
1990+
freq = (debit.get("frequency") or "").lower()
1991+
# Check if this is an EMI payment
1992+
if any(kw in desc for kw in emi_keywords):
1993+
if isinstance(amount, (int, float)) and amount > 0:
1994+
# Convert to monthly if not already monthly
1995+
if freq in ("monthly", "month"):
1996+
total_monthly_emi += float(amount)
1997+
elif freq in ("quarterly", "quarter"):
1998+
total_monthly_emi += float(amount) / 3.0
1999+
elif freq in ("yearly", "annual", "year"):
2000+
total_monthly_emi += float(amount) / 12.0
2001+
else:
2002+
# Assume monthly if frequency unclear
2003+
total_monthly_emi += float(amount)
2004+
except Exception:
2005+
continue
2006+
if total_monthly_emi > 0:
2007+
lifestyle["monthly_emi"] = round(total_monthly_emi, 2)
2008+
print(f"[Prefill] Extracted monthly_emi: {lifestyle['monthly_emi']}")
2009+
except Exception as e:
2010+
print(f"[Prefill] Error extracting monthly_emi: {e}")
2011+
19742012
allocation = {}
19752013
try:
19762014
for k in ["equity", "debt", "gold", "realEstate", "insuranceLinked", "cash"]:
@@ -2202,6 +2240,23 @@ def upload_document():
22022240
_persist_metrics_for_doc(doc_id, bank_data)
22032241
except Exception as e:
22042242
print(f"Persist metrics (bank) failed: {e}")
2243+
2244+
# Save bank statement metadata including recurring debits (for EMI prefill)
2245+
if idx in upload_link_ids:
2246+
try:
2247+
bank_metadata = {
2248+
"size_bytes": len(file_bytes),
2249+
"bank_data": {
2250+
"account_summary": bank_data.get("account_summary", {}),
2251+
"recurring_debits": bank_data.get("recurring_debits", []),
2252+
"recurring_credits": bank_data.get("recurring_credits", []),
2253+
}
2254+
}
2255+
update_questionnaire_upload_metadata(upload_link_ids[idx], bank_metadata)
2256+
recurring_debits_count = len(bank_data.get("recurring_debits", []))
2257+
print(f"[Upload] Bank statement metadata saved: {recurring_debits_count} recurring debits")
2258+
except Exception as e:
2259+
print(f"Error updating Bank statement metadata: {e}")
22052260
else:
22062261
other_data = func(text)
22072262
# Merge DB-backed summaries if present (useful for CAS/Portfolio PDFs)

0 commit comments

Comments
 (0)