From f90d0f37f43996e62ba2361646edc66b3ceca969 Mon Sep 17 00:00:00 2001 From: kernchen-brc Date: Fri, 24 Apr 2026 08:14:37 +0200 Subject: [PATCH] Add 'Add stock' button to part stock info page --- config/reference.php | 2 +- src/Controller/PartController.php | 41 +++++++++++++++++ templates/parts/info/_add_lot_modal.html.twig | 46 +++++++++++++++++++ templates/parts/info/_part_lots.html.twig | 8 ++++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 templates/parts/info/_add_lot_modal.html.twig diff --git a/config/reference.php b/config/reference.php index 77a5d432..38ad8241 100644 --- a/config/reference.php +++ b/config/reference.php @@ -1712,7 +1712,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param; * length?: scalar|Param|null, // Default: 5 * width?: scalar|Param|null, // Default: 130 * height?: scalar|Param|null, // Default: 50 - * font?: scalar|Param|null, // Default: "/home/jan/php/Part-DB-server/vendor/gregwar/captcha-bundle/DependencyInjection/../Generator/Font/captcha.ttf" + * font?: scalar|Param|null, // Default: "/home/user/documents/Part-DB-server/vendor/gregwar/captcha-bundle/DependencyInjection/../Generator/Font/captcha.ttf" * keep_value?: scalar|Param|null, // Default: false * charset?: scalar|Param|null, // Default: "abcdefhjkmnprstuvwxyz23456789" * as_file?: scalar|Param|null, // Default: false diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index eb80d9bc..a7781fe6 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -36,6 +36,7 @@ use App\Entity\PriceInformations\Orderdetail; use App\Entity\ProjectSystem\Project; use App\Exceptions\AttachmentDownloadException; use App\Form\Part\PartBaseType; +use App\Form\Part\PartLotType; use App\Services\Attachments\AttachmentSubmitHandler; use App\Services\Attachments\PartPreviewGenerator; use App\Services\EntityMergers\Mergers\PartMerger; @@ -127,6 +128,17 @@ final class PartController extends AbstractController $table = null; } + // Build the add-lot form for the INFO page modal (only when not in time-travel mode) + $addLotForm = null; + if ($timeTravel_timestamp === null && $this->isGranted('edit', $part)) { + $newLot = new PartLot(); + $newLot->setPart($part); + $addLotForm = $this->createForm(PartLotType::class, $newLot, [ + 'measurement_unit' => $part->getPartUnit(), + 'action' => $this->generateUrl('part_lot_add', ['id' => $part->getID()]), + ]); + } + return $this->render( 'parts/info/show_part_info.html.twig', [ @@ -139,10 +151,39 @@ final class PartController extends AbstractController 'comment_params' => $this->partInfoSettings->extractParamsFromNotes ? $parameterExtractor->extractParameters($part->getComment()) : [], 'withdraw_add_helper' => $withdrawAddHelper, 'highlightLotId' => $request->query->getInt('highlightLot', 0), + 'add_lot_form' => $addLotForm, ] ); } + #[Route(path: '/{id}/add_lot', name: 'part_lot_add', methods: ['POST'])] + public function addLot(Part $part, Request $request, EntityManagerInterface $em): Response + { + $this->denyAccessUnlessGranted('edit', $part); + + $newLot = new PartLot(); + $newLot->setPart($part); + + $form = $this->createForm(PartLotType::class, $newLot, [ + 'measurement_unit' => $part->getPartUnit(), + ]); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em->persist($newLot); + $em->flush(); + $this->addFlash('success', 'part.edited_flash'); + return $this->redirectToRoute('part_info', [ + 'id' => $part->getID(), + 'highlightLot' => $newLot->getID(), + ]); + } + + $this->addFlash('error', 'part.created_flash.invalid'); + return $this->redirectToRoute('part_info', ['id' => $part->getID()]); + } + #[Route(path: '/{id}/edit', name: 'part_edit')] public function edit(Part $part, Request $request): Response { diff --git a/templates/parts/info/_add_lot_modal.html.twig b/templates/parts/info/_add_lot_modal.html.twig new file mode 100644 index 00000000..b31f368f --- /dev/null +++ b/templates/parts/info/_add_lot_modal.html.twig @@ -0,0 +1,46 @@ +{% if add_lot_form is not null %} +{% form_theme add_lot_form 'form/extended_bootstrap_layout.html.twig' %} + + +{% endif %} diff --git a/templates/parts/info/_part_lots.html.twig b/templates/parts/info/_part_lots.html.twig index 70e5dc4e..6c7487c2 100644 --- a/templates/parts/info/_part_lots.html.twig +++ b/templates/parts/info/_part_lots.html.twig @@ -3,6 +3,7 @@ {% include "parts/info/_withdraw_modal.html.twig" %} {% include "parts/info/_stocktake_modal.html.twig" %} +{% include "parts/info/_add_lot_modal.html.twig" %}
@@ -126,3 +127,10 @@
+ +{% if add_lot_form is not null %} + +{% endif %}