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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user