Add a button to automatically add the ordered amount once delivered

This commit is contained in:
Fabian Wunsch 2025-09-16 08:21:55 +02:00
parent b62d4aaeb7
commit e6b1b533a8
5 changed files with 47 additions and 0 deletions

View file

@ -135,6 +135,27 @@ class PartController extends AbstractController
return $this->renderPartForm('edit', $request, $part);
}
#[Route(path: '/{id}/delivered', name: 'part_delivered')]
public function delivered(Part $part, Request $request): Response
{
$this->denyAccessUnlessGranted('edit', $part);
$partLot = $part->getPartLots()[0] ?? null;
if (!$partLot instanceof PartLot) {
$this->addFlash('error', 'part.delivered.error.no_lot');
return $this->redirectToRoute('part_info', ['id' => $part->getID()]);
}
$partLot->setAmount($partLot->getAmount() + $part->getOrderAmount());
$part->setOrderAmount(0);
$part->setOrderDelivery(null);
$this->em->persist($part);
$this->em->flush();
return $this->redirectToRoute('part_info', ['id' => $part->getID()]);
}
#[Route(path: '/{id}/delete', name: 'part_delete', methods: ['DELETE'])]
public function delete(Request $request, Part $part): RedirectResponse
{

View file

@ -83,6 +83,7 @@ class EntityURLGenerator
'delete' => $this->deleteURL($entity),
'file_download' => $this->downloadURL($entity),
'file_view' => $this->viewURL($entity),
'delivered' => $this->deliveredURL($entity),
default => throw new InvalidArgumentException('Method is not supported!'),
};
}
@ -169,6 +170,11 @@ class EntityURLGenerator
throw new \RuntimeException('Attachment has no internal nor external path!');
}
public function deliveredURL(Part $entity): string
{
return $this->urlGenerator->generate('part_delivered', ['id' => $entity->getID()]);
}
public function downloadURL($entity): string
{
if (!($entity instanceof Attachment)) {