This commit is contained in:
lubiana 2025-06-14 18:32:57 +02:00
parent 16533b1495
commit ab0677c463
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
14 changed files with 705 additions and 38 deletions

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Controller;
use App\Form\BulkEditDrinkTypeStockForm;
use App\Form\BulkEditDrinkTypeWantedStockForm;
use App\Repository\DrinkTypeRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -38,7 +39,7 @@ final class DrinkTypeBulkController extends AbstractController
$entityManager->flush();
$this->addFlash('success', 'Wanted stock levels updated successfully!');
$this->addFlash('success', 'Current stock levels updated successfully!');
return $this->redirectToRoute('app_drink_type_bulk_edit_stock');
}
@ -48,4 +49,38 @@ final class DrinkTypeBulkController extends AbstractController
'drinkTypes' => $drinkTypes,
]);
}
#[Route('/bulk-edit-wanted-stock', name: 'app_drink_type_bulk_edit_wanted_stock')]
public function bulkEditWantedStock(
Request $request,
DrinkTypeRepository $drinkTypeRepository,
EntityManagerInterface $entityManager
): Response {
$drinkTypes = $drinkTypeRepository->findAll();
$form = $this->createForm(BulkEditDrinkTypeWantedStockForm::class, [
'drinkTypes' => $drinkTypes,
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
foreach ($data['drinkTypes'] as $drinkType) {
$entityManager->persist($drinkType);
}
$entityManager->flush();
$this->addFlash('success', 'Wanted stock levels updated successfully!');
return $this->redirectToRoute('app_drink_type_bulk_edit_wanted_stock');
}
return $this->render('drink_type/bulk_edit_wanted_stock.html.twig', [
'form' => $form->createView(),
'drinkTypes' => $drinkTypes,
]);
}
}