feat: update representation management to use city_id instead of city and add city filtering

This commit is contained in:
hamed
2026-06-10 10:03:46 +03:30
parent d33d67b921
commit c7ae591e49
7 changed files with 148 additions and 42 deletions
+12 -3
View File
@@ -4,6 +4,7 @@ namespace App\Admin\Controller;
use App\Appointment\Entity\Appointment;
use App\Auth\Entity\User;
use App\Category\Entity\Category;
use App\Clinic\Entity\Clinic;
use App\Doctor\Entity\Doctor;
use App\Payment\Entity\Payment;
@@ -169,17 +170,24 @@ class AdminApiController extends BaseController
$page = max(1, (int) $request->query->get('page', 1));
$limit = min(100, max(1, (int) $request->query->get('limit', 15)));
$search = trim((string) $request->query->get('search', ''));
$cityId = $request->query->get('city_id');
$qb = $this->em->createQueryBuilder()
->select('r.uuid, r.fullName, r.mobileNumber, r.city, r.commissionPercent, r.active, r.createdAt')
->select('r.uuid, r.fullName, r.mobileNumber, r.cityId, r.commissionPercent, r.active, r.createdAt, c.label as city_name')
->from(Representation::class, 'r')
->leftJoin(Category::class, 'c', 'WITH', 'c.id = r.cityId')
->orderBy('r.createdAt', 'DESC');
if ($search !== '') {
$qb->andWhere('r.fullName LIKE :s OR r.city LIKE :s')
$qb->andWhere('r.fullName LIKE :s OR r.mobileNumber LIKE :s')
->setParameter('s', '%' . $search . '%');
}
if ($cityId !== null && $cityId !== '') {
$qb->andWhere('r.cityId = :cityId')
->setParameter('cityId', (int) $cityId);
}
$total = (clone $qb)->select('COUNT(r.id)')->getQuery()->getSingleScalarResult();
$rows = $qb->setFirstResult(($page - 1) * $limit)->setMaxResults($limit)
@@ -190,7 +198,8 @@ class AdminApiController extends BaseController
'domain' => $r['fullName'],
'full_name' => $r['fullName'],
'mobile_number' => $r['mobileNumber'],
'city' => $r['city'] ?? '',
'city_id' => $r['cityId'],
'city' => $r['city_name'] ?? null,
'commission_percent' => (float) $r['commissionPercent'],
'wallet_balance' => 0,
'is_active' => (bool) $r['active'],
@@ -53,7 +53,7 @@ class RepresentationController extends BaseController
}
$rep = new Representation($user, $fullName);
if (!empty($data['city'])) $rep->setCity($data['city']);
if (isset($data['city_id'])) $rep->setCityId($data['city_id'] ? (int)$data['city_id'] : null);
if (!empty($data['commission_percent'])) $rep->setCommissionPercent((string)$data['commission_percent']);
if (!empty($data['bank_account'])) $rep->setBankAccount($data['bank_account']);
@@ -91,7 +91,7 @@ class RepresentationController extends BaseController
$data = json_decode($request->getContent(), true) ?? [];
if (array_key_exists('full_name', $data)) $rep->setFullName($data['full_name']);
if (array_key_exists('city', $data)) $rep->setCity($data['city']);
if (array_key_exists('city_id', $data)) $rep->setCityId($data['city_id'] ? (int)$data['city_id'] : null);
if (array_key_exists('bank_account', $data)) $rep->setBankAccount($data['bank_account']);
if (array_key_exists('commission_percent', $data)) $rep->setCommissionPercent((string)$data['commission_percent']);
if (array_key_exists('active', $data)) $rep->setActive((bool)$data['active']);
+11 -11
View File
@@ -28,8 +28,8 @@ class Representation
#[ORM\Column(type: 'string', length: 20, nullable: true)]
private ?string $mobileNumber = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $city = null;
#[ORM\Column(name: 'city_id', type: 'integer', nullable: true)]
private ?int $cityId = null;
#[ORM\Column(name: 'commission_percent', type: 'decimal', precision: 5, scale: 2)]
private string $commissionPercent = '10.00';
@@ -55,19 +55,19 @@ class Representation
$this->updatedAt = time();
}
public function getId(): ?int { return $this->id; }
public function getUuid(): string { return $this->uuid; }
public function getUser(): User { return $this->user; }
public function getFullName(): string { return $this->fullName; }
public function getId(): ?int { return $this->id; }
public function getUuid(): string { return $this->uuid; }
public function getUser(): User { return $this->user; }
public function getFullName(): string { return $this->fullName; }
public function getMobileNumber(): ?string { return $this->mobileNumber; }
public function getCity(): ?string { return $this->city; }
public function getCityId(): ?int { return $this->cityId; }
public function getCommissionPercent(): string { return $this->commissionPercent; }
public function getBankAccount(): ?array { return $this->bankAccount; }
public function isActive(): bool { return $this->active; }
public function getBankAccount(): ?array { return $this->bankAccount; }
public function isActive(): bool { return $this->active; }
public function setFullName(string $v): self { $this->fullName = $v; $this->touch(); return $this; }
public function setMobileNumber(?string $v): self { $this->mobileNumber = $v; $this->touch(); return $this; }
public function setCity(?string $v): self { $this->city = $v; $this->touch(); return $this; }
public function setCityId(?int $v): self { $this->cityId = $v; $this->touch(); return $this; }
public function setCommissionPercent(string $v): self { $this->commissionPercent = $v; $this->touch(); return $this; }
public function setBankAccount(?array $v): self { $this->bankAccount = $v; $this->touch(); return $this; }
public function setActive(bool $v): self { $this->active = $v; $this->touch(); return $this; }
@@ -80,7 +80,7 @@ class Representation
'uuid' => $this->uuid,
'full_name' => $this->fullName,
'mobile_number' => $this->mobileNumber,
'city' => $this->city,
'city_id' => $this->cityId,
'commission_percent' => $this->commissionPercent,
'bank_account' => $this->bankAccount,
'active' => $this->active,