Allow to show parts in a storelocation or an supplier.

This commit is contained in:
Jan Böhmer 2019-09-08 17:30:58 +02:00
parent 748905c325
commit 31e89e2e36
8 changed files with 107 additions and 6 deletions

View file

@ -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

View file

@ -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);
}

View file

@ -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'] . '%');
}

View file

@ -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()]);