Add Customer Account card to asset detail view — live from Dynamics 365 extraction DB. Shows name, address, phone, email, management company, account manager.
This commit is contained in:
@@ -1355,6 +1355,45 @@ def get_asset(asset_id: int):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass # Extraction DB might not be available, silently skip
|
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)
|
# Enrich with Seed data (from mycantaloupe.com)
|
||||||
seed_row = conn.execute(
|
seed_row = conn.execute(
|
||||||
"SELECT raw_data, imported_at FROM seed_data WHERE asset_id = ?",
|
"SELECT raw_data, imported_at FROM seed_data WHERE asset_id = ?",
|
||||||
|
|||||||
@@ -1498,6 +1498,12 @@
|
|||||||
<div id="detailRelatedWOList"></div>
|
<div id="detailRelatedWOList"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Customer Account (from Dynamics 365) -->
|
||||||
|
<div class="card" id="detailAccountCard" style="display:none;">
|
||||||
|
<div class="card-title"><svg class="gi" aria-hidden="true"><use href="#gi-factory"/></svg> Customer Account</div>
|
||||||
|
<div id="detailAccountFields"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Check-in History -->
|
<!-- Check-in History -->
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-title">Check-in History <span id="checkinCount" style="color:var(--accent2);"></span></div>
|
<div class="card-title">Check-in History <span id="checkinCount" style="color:var(--accent2);"></span></div>
|
||||||
@@ -5492,6 +5498,32 @@
|
|||||||
rwoCard.style.display = 'none';
|
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);
|
await loadCheckinHistory(id);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showToast(e.message, true);
|
showToast(e.message, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user