Statistik-Bereich um Tab für Projekte/Baugruppen erweitern

This commit is contained in:
Marcel Diegelmann 2026-02-12 12:46:59 +01:00
parent 74513b748d
commit d67e93064c
18 changed files with 754 additions and 1 deletions

View file

@ -42,7 +42,10 @@ declare(strict_types=1);
namespace App\Controller;
use App\Services\Tools\StatisticsHelper;
use App\Entity\AssemblySystem\AssemblyBOMEntry;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
@ -57,4 +60,33 @@ class StatisticsController extends AbstractController
'helper' => $helper,
]);
}
#[Route(path: '/statistics/cleanup-assembly-bom-entries', name: 'statistics_cleanup_assembly_bom_entries', methods: ['POST'])]
public function cleanupAssemblyBOMEntries(EntityManagerInterface $em): JsonResponse
{
$this->denyAccessUnlessGranted('@tools.statistics');
$qb = $em->createQueryBuilder();
$qb->select('be', 'IDENTITY(be.part) AS part_id')
->from(AssemblyBOMEntry::class, 'be')
->leftJoin('be.part', 'p')
->where('be.part IS NOT NULL')
->andWhere('p.id IS NULL');
$results = $qb->getQuery()->getResult();
$count = count($results);
foreach ($results as $result) {
/** @var AssemblyBOMEntry $entry */
$entry = $result[0];
$part_id = $result['part_id'] ?? 'unknown';
$entry->setPart(null);
$entry->setName(sprintf('part-id=%s not found', $part_id));
}
$em->flush();
return new JsonResponse(['success' => true, 'count' => $count]);
}
}

View file

@ -41,8 +41,10 @@ declare(strict_types=1);
namespace App\Services\Tools;
use App\Entity\AssemblySystem\AssemblyBOMEntry;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType;
use App\Entity\AssemblySystem\Assembly;
use App\Entity\ProjectSystem\Project;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
@ -79,6 +81,14 @@ class StatisticsHelper
return $this->part_repo->count([]);
}
/**
* Returns the count of distinct projects.
*/
public function getDistinctProjectsCount(): int
{
return $this->em->getRepository(Project::class)->count([]);
}
/**
* Returns the summed instocked over all parts (only parts without a measurement unit).
*
@ -116,6 +126,7 @@ class StatisticsHelper
'storelocation' => StorageLocation::class,
'supplier' => Supplier::class,
'currency' => Currency::class,
'assembly' => Assembly::class,
];
if (!isset($arr[$type])) {
@ -164,4 +175,19 @@ class StatisticsHelper
{
return $this->attachment_repo->getUserUploadedAttachments();
}
/**
* Returns the count of BOM entries which point to a non-existent part ID.
*/
public function getInvalidPartBOMEntriesCount(): int
{
$qb = $this->em->createQueryBuilder();
$qb->select('COUNT(be.id)')
->from(AssemblyBOMEntry::class, 'be')
->leftJoin('be.part', 'p')
->where('be.part IS NOT NULL')
->andWhere('p.id IS NULL');
return (int) $qb->getQuery()->getSingleScalarResult();
}
}