diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index 45008d1e..fcba0730 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -44,7 +44,12 @@ namespace App\Controller; use App\DataTables\LogDataTable; use App\Entity\Parts\Category; +use App\Entity\Parts\Footprint; use App\Entity\Parts\Part; +use App\Entity\Parts\PartLot; +use App\Entity\Parts\Storelocation; +use App\Entity\Parts\Supplier; +use App\Entity\PriceInformations\Orderdetail; use App\Exceptions\AttachmentDownloadException; use App\Form\Part\PartBaseType; use App\Services\Attachments\AttachmentManager; @@ -57,6 +62,7 @@ use App\Services\Parameters\ParameterExtractor; use App\Services\PricedetailHelper; use Doctrine\ORM\EntityManagerInterface; use Omines\DataTablesBundle\DataTableFactory; +use Proxies\__CG__\App\Entity\Parts\Manufacturer; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -235,13 +241,42 @@ class PartController extends AbstractController $this->denyAccessUnlessGranted('create', $new_part); - $cid = $request->get('cid', 1); - - $category = $em->find(Category::class, $cid); + $cid = $request->get('category', null); + $category = $cid ? $em->find(Category::class, $cid) : null; if (null !== $category && null === $new_part->getCategory()) { $new_part->setCategory($category); } + $fid = $request->get('footprint', null); + $footprint = $fid ? $em->find(Footprint::class, $cid) : null; + if (null !== $footprint && null === $new_part->getFootprint()) { + $new_part->setFootprint($footprint); + } + + $mid = $request->get('manufacturer', null); + $manufacturer = $mid ? $em->find(Manufacturer::class, $mid) : null; + if (null !== $manufacturer && null === $new_part->getManufacturer()) { + $new_part->setManufacturer($manufacturer); + } + + $store_id = $request->get('storelocation', null); + $storelocation = $store_id ? $em->find(Storelocation::class, $store_id): null; + if (null !== $storelocation && $new_part->getPartLots()->isEmpty()) { + $partLot = new PartLot(); + $partLot->setStorageLocation($storelocation); + $partLot->setInstockUnknown(true); + $new_part->addPartLot($partLot); + } + + $supplier_id = $request->get('supplier', null); + $supplier = $supplier_id ? $em->find(Supplier::class, $supplier_id): null; + if (null !== $supplier && $new_part->getOrderdetails()->isEmpty()) { + $orderdetail = new Orderdetail(); + $orderdetail->setSupplier($supplier); + $new_part->addOrderdetail($orderdetail); + } + + $form = $this->createForm(PartBaseType::class, $new_part); $form->handleRequest($request); diff --git a/templates/Parts/lists/_action_bar.html.twig b/templates/Parts/lists/_action_bar.html.twig new file mode 100644 index 00000000..2bd167a5 --- /dev/null +++ b/templates/Parts/lists/_action_bar.html.twig @@ -0,0 +1,6 @@ +
+
+ + {% trans%}part.create.btn{% endtrans %} +
+
\ No newline at end of file diff --git a/templates/Parts/lists/all_list.html.twig b/templates/Parts/lists/all_list.html.twig index 82e45487..04adc60c 100644 --- a/templates/Parts/lists/all_list.html.twig +++ b/templates/Parts/lists/all_list.html.twig @@ -6,6 +6,7 @@ {% block content %} + {% include "Parts/lists/_action_bar.html.twig" with {'url_options': {}} %} {% include "Parts/lists/_parts_list.html.twig" %} {% endblock %} diff --git a/templates/Parts/lists/category_list.html.twig b/templates/Parts/lists/category_list.html.twig index e49700c5..676bba99 100644 --- a/templates/Parts/lists/category_list.html.twig +++ b/templates/Parts/lists/category_list.html.twig @@ -8,6 +8,8 @@ {% include "Parts/lists/_info_card.html.twig" with {'header_label': 'category.label'} %} + {% include "Parts/lists/_action_bar.html.twig" with {'url_options': {'category': entity.iD}} %} + {% include "Parts/lists/_parts_list.html.twig" %} {% endblock %} diff --git a/templates/Parts/lists/footprint_list.html.twig b/templates/Parts/lists/footprint_list.html.twig index b66aafed..403eff09 100644 --- a/templates/Parts/lists/footprint_list.html.twig +++ b/templates/Parts/lists/footprint_list.html.twig @@ -8,6 +8,8 @@ {% include "Parts/lists/_info_card.html.twig" with {'header_label': 'footprint.label'} %} + {% include "Parts/lists/_action_bar.html.twig" with {'url_options': {'footprint': entity.iD}} %} + {% include "Parts/lists/_parts_list.html.twig" %} {% endblock %} diff --git a/templates/Parts/lists/manufacturer_list.html.twig b/templates/Parts/lists/manufacturer_list.html.twig index de427199..9bfb4684 100644 --- a/templates/Parts/lists/manufacturer_list.html.twig +++ b/templates/Parts/lists/manufacturer_list.html.twig @@ -8,6 +8,8 @@ {% include "Parts/lists/_info_card.html.twig" with {'header_label': 'manufacturer.label'} %} + {% include "Parts/lists/_action_bar.html.twig" with {'url_options': {'manufacturer': entity.iD}} %} + {% include "Parts/lists/_parts_list.html.twig" %} {% endblock %} diff --git a/templates/Parts/lists/store_location_list.html.twig b/templates/Parts/lists/store_location_list.html.twig index 67248004..52fb0cd8 100644 --- a/templates/Parts/lists/store_location_list.html.twig +++ b/templates/Parts/lists/store_location_list.html.twig @@ -8,6 +8,8 @@ {% include "Parts/lists/_info_card.html.twig" with {'header_label': 'storelocation.label'} %} + {% include "Parts/lists/_action_bar.html.twig" with {'url_options': {'storelocation': entity.iD}} %} + {% 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 index 3b0a06bb..e7f4e70d 100644 --- a/templates/Parts/lists/supplier_list.html.twig +++ b/templates/Parts/lists/supplier_list.html.twig @@ -8,6 +8,8 @@ {% include "Parts/lists/_info_card.html.twig" with {'header_label': 'supplier.label'} %} + {% include "Parts/lists/_action_bar.html.twig" with {'url_options': {'supplier': entity.iD}} %} + {% include "Parts/lists/_parts_list.html.twig" %} {% endblock %}