mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-10 15:12:12 +00:00
Add 'Add stock' button to part stock info page (#1352)
* Add 'Add stock' button to part stock info page * Use outline-success style for new stock button on part info page --------- Co-authored-by: Jan Böhmer <mail@jan-boehmer.de>
This commit is contained in:
parent
1d1e3008aa
commit
83074a2403
4 changed files with 96 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
@ -128,6 +129,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',
|
||||
[
|
||||
|
|
@ -140,10 +152,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
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue