diff --git a/server.py b/server.py index 7de21ff..4751d87 100644 --- a/server.py +++ b/server.py @@ -1355,6 +1355,45 @@ def get_asset(asset_id: int): except Exception: pass # Extraction DB might not be available, silently skip + # Enrich with customer account details from extraction DB + try: + ext = _get_extraction_db() + if ext: + cur_ext = ext.cursor() + asset_company = result.get("company", "") + asset_place = result.get("place", "") + if asset_company: + # Try exact match first, then LIKE + cur_ext.execute(""" + SELECT name, address1_line1, address1_city, address1_stateorprovince, + address1_postalcode, address1_country, telephone1, emailaddress1, + websiteurl, fax, address1_latitude, address1_longitude, + "hsl_managementcompany!name" AS management_company, + "hsl_csm!name" AS csm + FROM account + WHERE name = ? + """, (asset_company,)) + acct = cur_ext.fetchone() + if not acct: + # Try fuzzy match + cur_ext.execute(""" + SELECT name, address1_line1, address1_city, address1_stateorprovince, + address1_postalcode, address1_country, telephone1, emailaddress1, + websiteurl, fax, address1_latitude, address1_longitude, + "hsl_managementcompany!name" AS management_company, + "hsl_csm!name" AS csm + FROM account + WHERE name LIKE ? LIMIT 1 + """, (f"%{asset_company[:30]}%",)) + acct = cur_ext.fetchone() + if acct: + ca = dict(acct) + # Clean None values + result["customer_account"] = {k: v for k, v in ca.items() if v is not None} + ext.close() + except Exception: + pass + # Enrich with Seed data (from mycantaloupe.com) seed_row = conn.execute( "SELECT raw_data, imported_at FROM seed_data WHERE asset_id = ?", diff --git a/static/index.html b/static/index.html index a93280a..b2394c7 100644 --- a/static/index.html +++ b/static/index.html @@ -1498,6 +1498,12 @@
+ + +
Check-in History
@@ -5492,6 +5498,32 @@ rwoCard.style.display = 'none'; } + // Customer Account details from Dynamics 365 + const acctCard = document.getElementById('detailAccountCard'); + const acctFields = document.getElementById('detailAccountFields'); + if (a.customer_account) { + acctCard.style.display = 'block'; + const ac = a.customer_account; + var addrParts = []; + if (ac.address1_line1) addrParts.push(esc(ac.address1_line1)); + if (ac.address1_city) addrParts.push(esc(ac.address1_city)); + if (ac.address1_stateorprovince) addrParts.push(esc(ac.address1_stateorprovince)); + if (ac.address1_postalcode) addrParts.push(esc(ac.address1_postalcode)); + acctFields.innerHTML = [ + df('Name', esc(ac.name)), + df('Address', addrParts.join(', ')), + (ac.telephone1 ? df('Phone', esc(ac.telephone1)) : ''), + (ac.emailaddress1 ? df('Email', esc(ac.emailaddress1)) : ''), + (ac.websiteurl ? df('Website', esc(ac.websiteurl)) : ''), + (ac.management_company ? df('Management Co.', esc(ac.management_company)) : ''), + (ac.csm ? df('Account Manager', esc(ac.csm)) : ''), + (ac.fax ? df('Fax', esc(ac.fax)) : ''), + (ac.address1_country ? df('Country', esc(ac.address1_country)) : ''), + ].filter(Boolean).join(''); + } else { + acctCard.style.display = 'none'; + } + await loadCheckinHistory(id); } catch (e) { showToast(e.message, true);