A video clearly illustrating the Cause of the Issue …
When an Entity is changed When a Ticket which contains partial Payments is Closed, the [Payments] table in the Database has NULL values written into:
,p.[AccountTransaction_Id]
,p.[AccountTransaction_AccountTransactionDocumentId]
SELECT
p.[Id]
,p.[TicketId]
,t.[TicketNumber]
,t.[IsLocked]
,t.[IsClosed]
--,te.[EntityTypeId]
,et.[Name] as [EntityType]
--,te.[EntityId]
,te.[EntityName]
--,p.[Date]
--,p.[Description]
,p.[Name]
,p.[Amount]
,p.[AccountTransaction_Id] as [TxId]
,p.[AccountTransaction_AccountTransactionDocumentId] as [DocId]
,tt.[Name] as [TxType]
,tv.[Name] as [TxName]
,tx.[Name] as [TxName2]
,dt.[Name] as [DocType]
,doc.[Name] as [DocName]
--,p.[PaymentTypeId]
--,p.[DepartmentId]
--,p.[AccountTransactionId]
--,p.[TenderedAmount]
--,p.[UserId]
--,p.[TerminalId]
--,p.[Description]
--,p.[ExchangeRate]
FROM [Payments] p
JOIN [Tickets] t on t.[Id] = p.[TicketId]
LEFT JOIN [AccountTransactionValues] tv on tv.[Id] = p.[AccountTransaction_Id]
LEFT JOIN [AccountTransactions] tx on tx.[Id] = tv.[AccountTransactionId]
LEFT JOIN [AccountTransactionDocumentTypes] dt on dt.[Id] = tv.[AccountTransactionDocumentId]
LEFT JOIN [AccountTransactionTypes] tt on tt.[Id] = tv.[AccountTransactionTypeId]
LEFT JOIN [AccountTransactionDocuments] doc on doc.[Id] = p.[AccountTransaction_AccountTransactionDocumentId]
LEFT JOIN [TicketEntities] te on te.[Ticket_Id] = t.[Id]
LEFT JOIN [Entities] e on e.[Id] = te.[EntityId]
LEFT JOIN [EntityTypes] et on et.[Id] = te.[EntityTypeId]
WHERE 1=1
--AND p.[Id] > 34789
ORDER BY p.[Id]

