feat: add optional inventory package association to service items and implement audit logging

- Added `inventory_package_uuid` and `inventory_package_title` fields to the `ServiceItem` interface.
- Updated API documentation to reflect new fields in service item responses.
- Implemented methods in `ClinicServiceController` to handle inventory package associations.
- Created `ServiceItemAuditLog` entity and repository for tracking changes to service items.
- Added functionality to log changes to service items, including inventory package associations.
- Implemented tests for attaching/detaching inventory packages and auditing changes.
- Created database migrations for new fields and audit log table.
This commit is contained in:
hamed
2026-07-18 12:26:15 +03:30
parent 42d9ad26c5
commit c4a661b542
14 changed files with 885 additions and 24 deletions
@@ -0,0 +1,42 @@
<?php
namespace App\ClinicService\Repository;
use App\ClinicService\Entity\ServiceItem;
use App\ClinicService\Entity\ServiceItemAuditLog;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
class ServiceItemAuditLogRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, ServiceItemAuditLog::class);
}
public function save(ServiceItemAuditLog $log, bool $flush = true): void
{
$this->getEntityManager()->persist($log);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function flush(): void
{
$this->getEntityManager()->flush();
}
/** @return ServiceItemAuditLog[] تازه‌ترین رویداد اول. */
public function findByItem(ServiceItem $item, int $limit = 100): array
{
return $this->createQueryBuilder('l')
->where('l.serviceItem = :item')
->setParameter('item', $item)
->orderBy('l.createdAt', 'DESC')
->addOrderBy('l.id', 'DESC')
->setMaxResults($limit)
->getQuery()
->getResult();
}
}