diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php
index 6708ed4c..b9f6c775 100644
--- a/src/Controller/PartController.php
+++ b/src/Controller/PartController.php
@@ -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
{
diff --git a/src/Services/EntityURLGenerator.php b/src/Services/EntityURLGenerator.php
index 78db06f0..4a2d6425 100644
--- a/src/Services/EntityURLGenerator.php
+++ b/src/Services/EntityURLGenerator.php
@@ -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)) {
diff --git a/templates/parts/info/_tools.html.twig b/templates/parts/info/_tools.html.twig
index 455d51b7..0c9fe7cb 100644
--- a/templates/parts/info/_tools.html.twig
+++ b/templates/parts/info/_tools.html.twig
@@ -39,6 +39,14 @@
{% endif %}
+{% if is_granted('edit', part) %}
+
+
+
+ {% trans %}part.delivered.btn{% endtrans %}
+
+{% endif %}
+