diff --git a/src/Controller/PartListsController.php b/src/Controller/PartListsController.php index a52c15b8..a703dc0f 100644 --- a/src/Controller/PartListsController.php +++ b/src/Controller/PartListsController.php @@ -33,6 +33,8 @@ use App\DataTables\PartsDataTable; use App\Entity\Parts\Category; use App\Entity\Parts\Footprint; use App\Entity\Parts\Manufacturer; +use App\Entity\Parts\Storelocation; +use App\Entity\Parts\Supplier; use Omines\DataTablesBundle\DataTableFactory; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; @@ -106,6 +108,51 @@ class PartListsController extends AbstractController ]); } + /** + * @Route("/store_location/{id}/parts", name="part_list_store_location") + * + * @param $id int The id of the category + * + * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response + */ + public function showStorelocation(Storelocation $storelocation, Request $request, DataTableFactory $dataTable) + { + $table = $dataTable->createFromType(PartsDataTable::class, ['storelocation' => $storelocation]) + ->handleRequest($request); + + if ($table->isCallback()) { + return $table->getResponse(); + } + + return $this->render('Parts/lists/store_location_list.html.twig', [ + 'datatable' => $table, + 'entity' => $storelocation + ]); + } + + /** + * @Route("/supplier/{id}/parts", name="part_list_supplier") + * + * @param $id int The id of the category + * + * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response + */ + public function showSupplier(Supplier $supplier, Request $request, DataTableFactory $dataTable) + { + $table = $dataTable->createFromType(PartsDataTable::class, ['supplier' => $supplier]) + ->handleRequest($request); + + if ($table->isCallback()) { + return $table->getResponse(); + } + + return $this->render('Parts/lists/supplier_list.html.twig', [ + 'datatable' => $table, + 'entity' => $supplier + ]); + } + + /** * @Route("/parts/by_tag/{tag}", name="part_list_tags") * @param string $tag diff --git a/src/Controller/TreeController.php b/src/Controller/TreeController.php index c5605cf5..383ca244 100644 --- a/src/Controller/TreeController.php +++ b/src/Controller/TreeController.php @@ -99,7 +99,7 @@ class TreeController extends AbstractController if ($location !== null) { $tree[] = $builder->elementToTreeNode($location); } else { - $tree = $builder->typeToTree(Storelocation::class, null); + $tree = $builder->typeToTree(Storelocation::class); } @@ -131,7 +131,7 @@ class TreeController extends AbstractController if ($supplier !== null) { $tree[] = $builder->elementToTreeNode($supplier); } else { - $tree = $builder->typeToTree(Supplier::class, null); + $tree = $builder->typeToTree(Supplier::class); } diff --git a/src/DataTables/PartsDataTable.php b/src/DataTables/PartsDataTable.php index 49a59679..958af905 100644 --- a/src/DataTables/PartsDataTable.php +++ b/src/DataTables/PartsDataTable.php @@ -35,6 +35,8 @@ use App\Entity\Parts\Category; use App\Entity\Parts\Footprint; use App\Entity\Parts\Manufacturer; use App\Entity\Parts\Part; +use App\Entity\Parts\Storelocation; +use App\Entity\Parts\Supplier; use App\Services\EntityURLGenerator; use Doctrine\ORM\QueryBuilder; use Omines\DataTablesBundle\Adapter\Doctrine\ORM\SearchCriteriaProvider; @@ -63,15 +65,17 @@ class PartsDataTable implements DataTableTypeInterface protected function getQuery(QueryBuilder $builder) { - $builder->select('part') + $builder->distinct()->select('part') ->addSelect('category') ->addSelect('footprint') ->addSelect('manufacturer') ->addSelect('partUnit') ->from(Part::class, 'part') ->leftJoin('part.category', 'category') + ->leftJoin('part.partLots', 'partLots') ->leftJoin('part.footprint', 'footprint') ->leftJoin('part.manufacturer', 'manufacturer') + ->leftJoin('part.orderdetails', 'orderdetails') ->leftJoin('part.partUnit', 'partUnit'); } @@ -106,6 +110,24 @@ class PartsDataTable implements DataTableTypeInterface $builder->andWhere('part.manufacturer IN (:cid)')->setParameter('cid', $list); } + if (isset($options['storelocation'])) { + $location = $options['storelocation']; + $repo = $em->getRepository(Storelocation::class); + $list = $repo->toNodesList($location); + $list[] = $location; + + $builder->andWhere('partLots.storage_location IN (:cid)')->setParameter('cid', $list); + } + + if (isset($options['supplier'])) { + $location = $options['supplier']; + $repo = $em->getRepository(Supplier::class); + $list = $repo->toNodesList($location); + $list[] = $location; + + $builder->andWhere('orderdetails.supplier IN (:cid)')->setParameter('cid', $list); + } + if (isset($options['tag'])) { $builder->andWhere('part.tags LIKE :tag')->setParameter('tag', '%' . $options['tag'] . '%'); } diff --git a/src/Services/EntityURLGenerator.php b/src/Services/EntityURLGenerator.php index 04a8f143..a9ef1eb8 100644 --- a/src/Services/EntityURLGenerator.php +++ b/src/Services/EntityURLGenerator.php @@ -257,7 +257,9 @@ class EntityURLGenerator $map = [ Category::class => 'part_list_category', Footprint::class => 'part_list_footprint', - Manufacturer::class => 'part_list_manufacturer' + Manufacturer::class => 'part_list_manufacturer', + Supplier::class => 'part_list_supplier', + Storelocation::class => 'part_list_store_location' ]; return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]); diff --git a/templates/Parts/info/_order_infos.html.twig b/templates/Parts/info/_order_infos.html.twig index 47935f56..657a4db1 100644 --- a/templates/Parts/info/_order_infos.html.twig +++ b/templates/Parts/info/_order_infos.html.twig @@ -11,7 +11,9 @@
{% for order in part.orderdetails %}{{ lot.description }} | {% if lot.storageLocation %} - {{ lot.storageLocation.fullPath }} + {{ helper.structural_entity_link(lot.storageLocation) }} {% else %} {% trans %}part_lots.location_unknown{% endtrans %} diff --git a/templates/Parts/lists/store_location_list.html.twig b/templates/Parts/lists/store_location_list.html.twig new file mode 100644 index 00000000..67248004 --- /dev/null +++ b/templates/Parts/lists/store_location_list.html.twig @@ -0,0 +1,13 @@ +{% extends "base.html.twig" %} + +{% block title %} + {% trans %}parts_list.storelocation.title{% endtrans %} {{ entity.name }} +{% endblock %} + +{% block content %} + + {% include "Parts/lists/_info_card.html.twig" with {'header_label': 'storelocation.label'} %} + + {% include "Parts/lists/_parts_list.html.twig" %} + +{% endblock %} diff --git a/templates/Parts/lists/supplier_list.html.twig b/templates/Parts/lists/supplier_list.html.twig new file mode 100644 index 00000000..3b0a06bb --- /dev/null +++ b/templates/Parts/lists/supplier_list.html.twig @@ -0,0 +1,13 @@ +{% extends "base.html.twig" %} + +{% block title %} + {% trans %}parts_list.supplier.title{% endtrans %} {{ entity.name }} +{% endblock %} + +{% block content %} + + {% include "Parts/lists/_info_card.html.twig" with {'header_label': 'supplier.label'} %} + + {% include "Parts/lists/_parts_list.html.twig" %} + +{% endblock %} |