feat: Implement logging for Mietinkasso and Kündigung actions in CVmhMietverhltnis service

This commit is contained in:
2026-01-25 18:39:26 +01:00
parent a4df1aac14
commit ec2c55d058
2 changed files with 39 additions and 4 deletions

View File

@@ -4,6 +4,8 @@ namespace Espo\Custom\Services;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\NotFound;
use Espo\Tools\Stream\Service as StreamService;
use Espo\Entities\Note;
class CVmhMietverhltnis extends \Espo\Services\Record
{
@@ -189,7 +191,10 @@ class CVmhMietverhltnis extends \Espo\Services\Record
->relate($contact);
}
// 12. Commit transaction
// 12. Log to stream
$this->logToStream($mietverhaeltnis, 'CVmhMietverhltnis', $mietinkasso->getId(), 'CMietinkasso', 'Mietinkasso erstellen');
// 13. Commit transaction
$this->entityManager->getTransactionManager()->commit();
return [
@@ -330,7 +335,10 @@ class CVmhMietverhltnis extends \Espo\Services\Record
->relate($contact);
}
// 11. Commit transaction
// 11. Log to stream
$this->logToStream($mietverhaeltnis, 'CVmhMietverhltnis', $kuendigung->getId(), 'CKuendigung', 'Kündigung erstellen');
// 12. Commit transaction
$this->entityManager->getTransactionManager()->commit();
return [
@@ -343,4 +351,31 @@ class CVmhMietverhltnis extends \Espo\Services\Record
throw $e;
}
}
/**
* Log action to source entity stream
*
* @param object $sourceEntity Source entity (Mietverhältnis)
* @param string $sourceEntityType Entity type
* @param string $createdEntityId Created entity ID
* @param string $createdEntityType Created entity type
* @param string $actionLabel Label for the action
*/
private function logToStream($sourceEntity, string $sourceEntityType, string $createdEntityId, string $createdEntityType, string $actionLabel): void
{
// Create Note entity manually for custom message
$note = $this->entityManager->getEntity('Note');
$note->set([
'type' => Note::TYPE_CREATE_RELATED,
'parentType' => $sourceEntityType,
'parentId' => $sourceEntity->getId(),
'relatedType' => $createdEntityType,
'relatedId' => $createdEntityId,
'data' => [
'actionLabel' => $actionLabel
]
]);
$this->entityManager->saveEntity($note);
}
}