feat: port inventory (انبارداری) page from tauri to admin dashboard

Add a per-tenant (doctor/clinic) Inventory domain and admin page, ported
from clinic-pro-tauri /inventory (which was static/mock) into a real feature.

Backend (src/Inventory/):
- Entities InventoryItem, InventoryPackage, InventoryPackageItem, scoped via
  entity_type/entity_id like TenantTag. Item status is derived, package total
  and availability derived at read time.
- InventoryService (stats, package assembly, availability), thin
  InventoryController with CRUD for items and packages + categories endpoint.
- Migration + docs/api/inventory.md + functional tests (10 tests, 42 assertions).

Frontend (assets/admin/):
- InventoryPage with two tabs (کالاهای مصرفی / پکیج), stat cards, items table
  (desktop + mobile cards), packages accordion, add/edit item and package
  modals, search + category filter — pixel-matched to the tauri source.
- useInventory hook (TanStack Query), route + sidebar link for doctor/clinic.
- Vitest coverage (real data, empty state, modal, packages tab).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-07-15 13:48:29 +03:30
co-authored by Claude Opus 4.8
parent f1e9129a2c
commit 519bc8d7f6
23 changed files with 2124 additions and 0 deletions
@@ -0,0 +1,65 @@
<?php
namespace App\Inventory\Repository;
use App\Inventory\Entity\InventoryItem;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
class InventoryItemRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, InventoryItem::class);
}
public function findByUuid(string $uuid): ?InventoryItem
{
return $this->findOneBy(['uuid' => $uuid]);
}
/** @return InventoryItem[] */
public function findByEntity(string $entityType, int $entityId): array
{
return $this->createQueryBuilder('i')
->where('i.entityType = :type AND i.entityId = :id')
->setParameter('type', $entityType)
->setParameter('id', $entityId)
->orderBy('i.name', 'ASC')
->getQuery()
->getResult();
}
/**
* Distinct non-empty "consumable" values for the tenant — powers the
* category filter dropdown on the inventory page.
*
* @return string[]
*/
public function findConsumables(string $entityType, int $entityId): array
{
$rows = $this->createQueryBuilder('i')
->select('DISTINCT i.consumable AS consumable')
->where('i.entityType = :type AND i.entityId = :id AND i.consumable IS NOT NULL AND i.consumable != :empty')
->setParameter('type', $entityType)
->setParameter('id', $entityId)
->setParameter('empty', '')
->orderBy('i.consumable', 'ASC')
->getQuery()
->getArrayResult();
return array_map(static fn(array $r): string => $r['consumable'], $rows);
}
public function save(InventoryItem $item): void
{
$this->getEntityManager()->persist($item);
$this->getEntityManager()->flush();
}
public function remove(InventoryItem $item): void
{
$this->getEntityManager()->remove($item);
$this->getEntityManager()->flush();
}
}