api.asp: archive stale PC->equipment relationships on new PC self-registration
When a new PC POSTs updateCompleteAsset for a machine number, the previous PC's "Controls" relationship to that equipment is now soft-archived (isactive=0) before the new relationship is created. Prevents duplicate active relationships when PCs are replaced floor-wide. Display pages already filter on isactive=1 so archived rows just disappear from inventory views (history preserved). displaymachine.asp: added Controller field populated via the controllertypes join. displaypc.asp: fixed top-bar search bug - searching a machine number was returning the PC row instead of the machine. Three lookup queries now scope to pctypeid IS NOT NULL. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
21
api.asp
21
api.asp
@@ -1816,9 +1816,28 @@ Function CreatePCMachineRelationship(pcMachineid, machineNumber)
|
||||
rsResult.Close
|
||||
Set rsResult = Nothing
|
||||
|
||||
' Archive any existing active "Controls" relationships from OTHER PCs to
|
||||
' this equipment. When a new PC self-registers for a machine number, the
|
||||
' previous PC's relationship is stale (PC was replaced). Soft-archive via
|
||||
' isactive=0 keeps history but excludes from active inventory views (the
|
||||
' display pages already filter on isactive=1).
|
||||
Dim archiveSQL
|
||||
archiveSQL = "UPDATE machinerelationships " & _
|
||||
"SET isactive = 0, lastupdated = NOW() " & _
|
||||
"WHERE machineid = " & CLng(equipmentMachineid) & _
|
||||
" AND related_machineid <> " & CLng(pcMachineid) & _
|
||||
" AND relationshiptypeid = " & CLng(relationshiptypeid) & _
|
||||
" AND isactive = 1"
|
||||
LogToFile "CreatePCMachineRelationship: Archiving stale relationships: " & archiveSQL
|
||||
objConn.Execute archiveSQL
|
||||
If Err.Number <> 0 Then
|
||||
LogToFile "CreatePCMachineRelationship: WARNING archive failed: " & Err.Description
|
||||
Err.Clear
|
||||
End If
|
||||
|
||||
' Check if relationship already exists (Equipment -> PC, matching existing data pattern)
|
||||
strSQL = "SELECT relationshipid FROM machinerelationships " & _
|
||||
"WHERE machineid = " & CLng(equipmentMachineid) & " AND related_machineid = " & CLng(pcMachineid) & " AND relationshiptypeid = " & CLng(relationshiptypeid)
|
||||
"WHERE machineid = " & CLng(equipmentMachineid) & " AND related_machineid = " & CLng(pcMachineid) & " AND relationshiptypeid = " & CLng(relationshiptypeid) & " AND isactive = 1"
|
||||
LogToFile "CreatePCMachineRelationship: Checking for duplicate: " & strSQL
|
||||
Set rsResult = objConn.Execute(strSQL)
|
||||
|
||||
|
||||
@@ -89,12 +89,14 @@
|
||||
"businessunits.businessunit, " & _
|
||||
"functionalaccounts.functionalaccount, functionalaccounts.functionalaccountid, " & _
|
||||
"vendors.vendor, vendors.vendorid, " & _
|
||||
"controllertypes.controllertype, " & _
|
||||
"printers.ipaddress AS printerip, " & _
|
||||
"printers.printercsfname, printers.printerwindowsname, " & _
|
||||
"machinestatus.machinestatus " & _
|
||||
"FROM machines " & _
|
||||
"LEFT JOIN models ON machines.modelnumberid = models.modelnumberid " & _
|
||||
"LEFT JOIN machinetypes ON models.machinetypeid = machinetypes.machinetypeid " & _
|
||||
"LEFT JOIN controllertypes ON machines.controllertypeid = controllertypes.controllertypeid " & _
|
||||
"LEFT JOIN businessunits ON machines.businessunitid = businessunits.businessunitid " & _
|
||||
"LEFT JOIN functionalaccounts ON machinetypes.functionalaccountid = functionalaccounts.functionalaccountid " & _
|
||||
"LEFT JOIN vendors ON models.vendorid = vendors.vendorid " & _
|
||||
@@ -191,6 +193,7 @@
|
||||
<p class="mb-2"><strong>Model:</strong></p>
|
||||
<p class="mb-2"><strong>Function:</strong></p>
|
||||
<p class="mb-2"><strong>BU:</strong></p>
|
||||
<p class="mb-2"><strong>Controller:</strong></p>
|
||||
<p class="mb-2"><strong>IP Address:</strong></p>
|
||||
<p class="mb-2"><strong>MAC Address:</strong></p>
|
||||
<p class="mb-2"><strong>FQDN:</strong></p>
|
||||
@@ -202,7 +205,7 @@
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<%
|
||||
Dim machineNumVal, vendorValM, modelValM, machineTypeVal, buVal, statusValM
|
||||
Dim machineNumVal, vendorValM, modelValM, machineTypeVal, buVal, statusValM, controllerVal
|
||||
|
||||
' Get values and default to N/A if empty
|
||||
machineNumVal = rs("machinenumber") & ""
|
||||
@@ -222,6 +225,9 @@ If machineTypeVal = "" Then machineTypeVal = "N/A"
|
||||
|
||||
buVal = rs("businessunit") & ""
|
||||
If buVal = "" Then buVal = "N/A"
|
||||
|
||||
controllerVal = rs("controllertype") & ""
|
||||
If controllerVal = "" Then controllerVal = "N/A"
|
||||
%>
|
||||
<p class="mb-2">
|
||||
<%
|
||||
@@ -241,6 +247,7 @@ End If
|
||||
<p class="mb-2"><%=Server.HTMLEncode(modelValM)%></p>
|
||||
<p class="mb-2"><%=Server.HTMLEncode(machineTypeVal)%></p>
|
||||
<p class="mb-2"><%=Server.HTMLEncode(buVal)%></p>
|
||||
<p class="mb-2"><%=Server.HTMLEncode(controllerVal)%></p>
|
||||
<%
|
||||
' Get primary communication (IP and MAC) from communications table
|
||||
Dim rsPrimaryCom, strPrimaryComSQL, primaryIP, primaryMAC
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
IF machinenumber <> "" THEN
|
||||
' Look up machineid by machinenumber
|
||||
Dim rsLookup, strLookupSQL
|
||||
strLookupSQL = "SELECT machineid FROM machines WHERE machinenumber = ? AND isactive = 1"
|
||||
strLookupSQL = "SELECT machineid FROM machines WHERE machinenumber = ? AND isactive = 1 AND pctypeid IS NOT NULL"
|
||||
Set rsLookup = ExecuteParameterizedQuery(objConn, strLookupSQL, Array(machinenumber))
|
||||
IF NOT rsLookup.EOF THEN
|
||||
machineid = rsLookup("machineid")
|
||||
@@ -49,13 +49,13 @@
|
||||
' We have a machineid, but it might actually be a machine number
|
||||
' Try to look it up as a machineid first
|
||||
Dim rsCheck
|
||||
strLookupSQL = "SELECT machineid FROM machines WHERE machineid = ? AND isactive = 1"
|
||||
strLookupSQL = "SELECT machineid FROM machines WHERE machineid = ? AND isactive = 1 AND pctypeid IS NOT NULL"
|
||||
Set rsCheck = ExecuteParameterizedQuery(objConn, strLookupSQL, Array(machineid))
|
||||
|
||||
' If no machine found with that machineid, try treating it as a machine number
|
||||
IF rsCheck.EOF THEN
|
||||
rsCheck.Close
|
||||
strLookupSQL = "SELECT machineid FROM machines WHERE machinenumber = ? AND isactive = 1"
|
||||
strLookupSQL = "SELECT machineid FROM machines WHERE machinenumber = ? AND isactive = 1 AND pctypeid IS NOT NULL"
|
||||
Set rsCheck = ExecuteParameterizedQuery(objConn, strLookupSQL, Array(CStr(machineid)))
|
||||
IF NOT rsCheck.EOF THEN
|
||||
machineid = rsCheck("machineid")
|
||||
|
||||
Reference in New Issue
Block a user