Added an button to parts tables to directly add a new part in the selected category.

This commit is contained in:
Jan Böhmer 2020-04-01 18:02:56 +02:00
parent a4ee46fed4
commit 6ad24aa9f8
8 changed files with 55 additions and 3 deletions

View file

@ -44,7 +44,12 @@ namespace App\Controller;
use App\DataTables\LogDataTable; use App\DataTables\LogDataTable;
use App\Entity\Parts\Category; use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Part; 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\Exceptions\AttachmentDownloadException;
use App\Form\Part\PartBaseType; use App\Form\Part\PartBaseType;
use App\Services\Attachments\AttachmentManager; use App\Services\Attachments\AttachmentManager;
@ -57,6 +62,7 @@ use App\Services\Parameters\ParameterExtractor;
use App\Services\PricedetailHelper; use App\Services\PricedetailHelper;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Omines\DataTablesBundle\DataTableFactory; use Omines\DataTablesBundle\DataTableFactory;
use Proxies\__CG__\App\Entity\Parts\Manufacturer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
@ -235,13 +241,42 @@ class PartController extends AbstractController
$this->denyAccessUnlessGranted('create', $new_part); $this->denyAccessUnlessGranted('create', $new_part);
$cid = $request->get('cid', 1); $cid = $request->get('category', null);
$category = $cid ? $em->find(Category::class, $cid) : null;
$category = $em->find(Category::class, $cid);
if (null !== $category && null === $new_part->getCategory()) { if (null !== $category && null === $new_part->getCategory()) {
$new_part->setCategory($category); $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 = $this->createForm(PartBaseType::class, $new_part);
$form->handleRequest($request); $form->handleRequest($request);

View file

@ -0,0 +1,6 @@
<div class="row mb-3">
<div class="col">
<a href="{{ url('part_new', url_options) }}" class="btn btn-success float-left"><i class="fas fa-plus-square fa-fw"></i>
{% trans%}part.create.btn{% endtrans %}</a>
</div>
</div>

View file

@ -6,6 +6,7 @@
{% block content %} {% block content %}
{% include "Parts/lists/_action_bar.html.twig" with {'url_options': {}} %}
{% include "Parts/lists/_parts_list.html.twig" %} {% include "Parts/lists/_parts_list.html.twig" %}
{% endblock %} {% endblock %}

View file

@ -8,6 +8,8 @@
{% include "Parts/lists/_info_card.html.twig" with {'header_label': 'category.label'} %} {% 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" %} {% include "Parts/lists/_parts_list.html.twig" %}
{% endblock %} {% endblock %}

View file

@ -8,6 +8,8 @@
{% include "Parts/lists/_info_card.html.twig" with {'header_label': 'footprint.label'} %} {% 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" %} {% include "Parts/lists/_parts_list.html.twig" %}
{% endblock %} {% endblock %}

View file

@ -8,6 +8,8 @@
{% include "Parts/lists/_info_card.html.twig" with {'header_label': 'manufacturer.label'} %} {% 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" %} {% include "Parts/lists/_parts_list.html.twig" %}
{% endblock %} {% endblock %}

View file

@ -8,6 +8,8 @@
{% include "Parts/lists/_info_card.html.twig" with {'header_label': 'storelocation.label'} %} {% 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" %} {% include "Parts/lists/_parts_list.html.twig" %}
{% endblock %} {% endblock %}

View file

@ -8,6 +8,8 @@
{% include "Parts/lists/_info_card.html.twig" with {'header_label': 'supplier.label'} %} {% 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" %} {% include "Parts/lists/_parts_list.html.twig" %}
{% endblock %} {% endblock %}