feat: implement staff management and subscription system

- Added StaffController for managing clinic staff, including listing, creating, updating, and toggling staff status.
- Created ClinicStaff entity and repository for staff data handling.
- Developed SubscriptionController to manage subscription plans and periods, including trial subscriptions.
- Introduced SubscriptionPlan, SubscriptionPeriod, and ClinicSubscription entities for subscription management.
- Implemented SubscriptionService for handling subscription logic, including trial activation and subscription creation from payments.
- Added necessary repositories for subscription entities to facilitate data access and manipulation.
This commit is contained in:
hamed
2026-06-14 22:10:28 +03:30
parent dcd631f503
commit b0244f28f5
53 changed files with 4434 additions and 40 deletions
@@ -0,0 +1,90 @@
<?php
namespace App\Patient\Repository;
use App\Auth\Entity\User;
use App\Patient\Entity\PatientRecord;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
class PatientRecordRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, PatientRecord::class);
}
public function findByUuid(string $uuid): ?PatientRecord
{
return $this->findOneBy(['uuid' => $uuid]);
}
public function findByEntityAndUser(string $entityType, int $entityId, User $user): ?PatientRecord
{
return $this->findOneBy([
'entityType' => $entityType,
'entityId' => $entityId,
'user' => $user,
]);
}
public function findByEntity(string $entityType, int $entityId, int $page = 1, int $limit = 20, ?string $search = null): array
{
$qb = $this->createQueryBuilder('r')
->join('r.user', 'u')
->where('r.entityType = :type')
->andWhere('r.entityId = :id')
->setParameter('type', $entityType)
->setParameter('id', $entityId)
->orderBy('r.id', 'DESC')
->setFirstResult(($page - 1) * $limit)
->setMaxResults($limit);
if ($search !== null && $search !== '') {
$qb->andWhere('u.realName LIKE :search OR u.mobileNumber LIKE :search')
->setParameter('search', '%' . $search . '%');
}
return $qb->getQuery()->getResult();
}
public function countByEntity(string $entityType, int $entityId, ?string $search = null): int
{
$qb = $this->createQueryBuilder('r')
->select('COUNT(r.id)')
->join('r.user', 'u')
->where('r.entityType = :type')
->andWhere('r.entityId = :id')
->setParameter('type', $entityType)
->setParameter('id', $entityId);
if ($search !== null && $search !== '') {
$qb->andWhere('u.realName LIKE :search OR u.mobileNumber LIKE :search')
->setParameter('search', '%' . $search . '%');
}
return (int) $qb->getQuery()->getSingleScalarResult();
}
public function countUnique(string $entityType, int $entityId, int $from, int $to): int
{
return (int) $this->createQueryBuilder('r')
->select('COUNT(DISTINCT r.user)')
->join('r.sessions', 's')
->where('r.entityType = :type')
->andWhere('r.entityId = :id')
->andWhere('s.createdAt BETWEEN :from AND :to')
->setParameter('type', $entityType)
->setParameter('id', $entityId)
->setParameter('from', $from)
->setParameter('to', $to)
->getQuery()
->getSingleScalarResult();
}
public function save(PatientRecord $record): void
{
$this->getEntityManager()->persist($record);
$this->getEntityManager()->flush();
}
}
@@ -0,0 +1,67 @@
<?php
namespace App\Patient\Repository;
use App\Patient\Entity\PatientRecord;
use App\Patient\Entity\PatientSession;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
class PatientSessionRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, PatientSession::class);
}
public function findByUuid(string $uuid): ?PatientSession
{
return $this->findOneBy(['uuid' => $uuid]);
}
public function findByRecord(PatientRecord $record, int $page = 1, int $limit = 20): array
{
return $this->createQueryBuilder('s')
->where('s.record = :record')
->setParameter('record', $record)
->orderBy('s.id', 'DESC')
->setFirstResult(($page - 1) * $limit)
->setMaxResults($limit)
->getQuery()
->getResult();
}
public function countByRecord(PatientRecord $record): int
{
return (int) $this->createQueryBuilder('s')
->select('COUNT(s.id)')
->where('s.record = :record')
->setParameter('record', $record)
->getQuery()
->getSingleScalarResult();
}
public function sumRevenue(string $entityType, int $entityId, int $from, int $to): int
{
$result = $this->createQueryBuilder('s')
->select('SUM(s.finalPriceRials)')
->join('s.record', 'r')
->where('r.entityType = :type')
->andWhere('r.entityId = :id')
->andWhere('s.createdAt BETWEEN :from AND :to')
->setParameter('type', $entityType)
->setParameter('id', $entityId)
->setParameter('from', $from)
->setParameter('to', $to)
->getQuery()
->getSingleScalarResult();
return (int) ($result ?? 0);
}
public function save(PatientSession $session): void
{
$this->getEntityManager()->persist($session);
$this->getEntityManager()->flush();
}
}
@@ -0,0 +1,21 @@
<?php
namespace App\Patient\Repository;
use App\Patient\Entity\SessionService;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
class SessionServiceRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, SessionService::class);
}
public function save(SessionService $service): void
{
$this->getEntityManager()->persist($service);
$this->getEntityManager()->flush();
}
}