Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Billing\Entity\Invoice;
|
||||
use App\Billing\Service\InvoicePaymentStatus;
|
||||
use App\Patient\Entity\PatientRecord;
|
||||
use App\Patient\Entity\SessionPayment;
|
||||
use App\UserProfile\Entity\UserProfile;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
@@ -41,7 +42,7 @@ class InvoiceRepository extends ServiceEntityRepository
|
||||
$rows = $this->tenantInvoicesQuery($entityType, $entityId, $filters)
|
||||
->select(
|
||||
'i.uuid AS invoice_uuid', 'r.uuid AS patient_uuid', 'u.realName AS patient_name',
|
||||
'u.nationalCode AS national_code', 'i.issuedAt AS issued_at',
|
||||
'COALESCE(p.nationalCode, u.nationalCode) AS national_code', 'i.issuedAt AS issued_at',
|
||||
'i.patientRials AS amount_rials',
|
||||
sprintf('%s AS paid_rials', self::paidSumDql('sp_row')),
|
||||
)
|
||||
@@ -198,6 +199,9 @@ class InvoiceRepository extends ServiceEntityRepository
|
||||
$qb = $this->createQueryBuilder('i')
|
||||
->innerJoin(PatientRecord::class, 'r', Join::WITH, 'r.id = i.patientRecordId')
|
||||
->innerJoin('r.user', 'u')
|
||||
// کد ملی روی پروفایل ذخیره میشود (profiles.national_code)؛ users.national_code
|
||||
// برای بیمارانِ ساختهشده در نوبتدهی خالی میماند.
|
||||
->leftJoin(UserProfile::class, 'p', Join::WITH, 'p.user = u')
|
||||
->where('i.entityType = :type')
|
||||
->andWhere('i.entityId = :id')
|
||||
->andWhere('i.status IN (:active)')
|
||||
@@ -206,7 +210,8 @@ class InvoiceRepository extends ServiceEntityRepository
|
||||
->setParameter('active', [Invoice::STATUS_FINALIZED, Invoice::STATUS_PAID]);
|
||||
|
||||
if (!empty($filters['national_code'])) {
|
||||
$qb->andWhere('u.nationalCode LIKE :nc')->setParameter('nc', '%' . $filters['national_code'] . '%');
|
||||
$qb->andWhere('(p.nationalCode LIKE :nc OR u.nationalCode LIKE :nc)')
|
||||
->setParameter('nc', '%' . $filters['national_code'] . '%');
|
||||
}
|
||||
if (!empty($filters['from'])) {
|
||||
$qb->andWhere('i.issuedAt >= :from')->setParameter('from', (int) $filters['from']);
|
||||
|
||||
Reference in New Issue
Block a user