updateeeeee
This commit is contained in:
parent
0c758749e0
commit
ca9819a436
12 changed files with 214 additions and 156 deletions
|
@ -6,7 +6,11 @@ namespace App\Controller;
|
|||
|
||||
use App\Entity\DrinkType;
|
||||
use App\Form\DrinkTypeForm;
|
||||
use App\Form\DrinkTypeFormCurrentStockForm;
|
||||
use App\Repository\DrinkTypeRepository;
|
||||
use App\Repository\PropertyChangeLogRepository;
|
||||
use App\Service\DrinkType\GetStockHistory;
|
||||
use App\Service\DrinkType\GetWantedHistory;
|
||||
use App\Service\InventoryService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
@ -18,10 +22,10 @@ use Symfony\Component\Routing\Attribute\Route;
|
|||
final class DrinkTypeController extends AbstractController
|
||||
{
|
||||
#[Route(name: 'app_drink_type_index', methods: ['GET'])]
|
||||
public function index(InventoryService $inventoryService): Response
|
||||
public function index(DrinkTypeRepository $drinkTypeRepository): Response
|
||||
{
|
||||
return $this->render('drink_type/index.html.twig', [
|
||||
'drink_stocks' => $inventoryService->getAllDrinkTypesWithStockLevels(true),
|
||||
'drink_types' => $drinkTypeRepository->findAll(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -46,28 +50,20 @@ final class DrinkTypeController extends AbstractController
|
|||
}
|
||||
|
||||
#[Route(path: '/{id}', name: 'app_drink_type_show', methods: ['GET'])]
|
||||
public function show(DrinkType $drinkType, PropertyChangeLogRepository $propertyChangeLogRepository): Response
|
||||
public function show(
|
||||
DrinkType $drinkType,
|
||||
GetStockHistory $getStockHistory,
|
||||
GetWantedHistory $getWantedHistory,
|
||||
): Response
|
||||
{
|
||||
// Get orders that contain this drink type
|
||||
$orderItems = $drinkType->getOrderItems();
|
||||
|
||||
// Get inventory history for this drink type
|
||||
$inventoryRecords = $drinkType->getInventoryRecords();
|
||||
|
||||
// Get desired stock history from PropertyChangeLog
|
||||
$desiredStockHistory = $propertyChangeLogRepository->findBy([
|
||||
'entityClass' => DrinkType::class,
|
||||
'propertyName' => 'desiredStock',
|
||||
'entityId' => $drinkType->getId(),
|
||||
], [
|
||||
'changeDate' => 'DESC',
|
||||
]);
|
||||
|
||||
return $this->render('drink_type/show.html.twig', [
|
||||
'drink_type' => $drinkType,
|
||||
'order_items' => $orderItems,
|
||||
'inventory_records' => $inventoryRecords,
|
||||
'desired_stock_history' => $desiredStockHistory,
|
||||
'stock_history' => $getStockHistory($drinkType),
|
||||
'wanted_history' => $getWantedHistory($drinkType),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -89,6 +85,24 @@ final class DrinkTypeController extends AbstractController
|
|||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/{id}/update-stock', name: 'app_drink_type_update_stock', methods: ['GET', 'POST'])]
|
||||
public function updateStock(Request $request, DrinkType $drinkType, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$form = $this->createForm(DrinkTypeFormCurrentStockForm::class, $drinkType);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_index', [], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
|
||||
return $this->render('drink_type/edit.html.twig', [
|
||||
'drink_type' => $drinkType,
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/{id}', name: 'app_drink_type_delete', methods: ['POST'])]
|
||||
public function delete(Request $request, DrinkType $drinkType, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Repository\DrinkTypeRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
@ -11,8 +12,11 @@ use Symfony\Component\Routing\Attribute\Route;
|
|||
#[Route(path: '/', name: 'app_index')]
|
||||
final class Index extends AbstractController
|
||||
{
|
||||
public function __invoke(): Response
|
||||
public function __invoke(DrinkTypeRepository $drinkTypeRepository): Response
|
||||
{
|
||||
return new Response('<h1>Hello World!</h1>');
|
||||
return $this->render('index.html.twig', [
|
||||
'drinkTypes' => $drinkTypeRepository->findWanted(),
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue