caisse-bliss/src/Controller/DefaultController.php
2025-02-17 17:51:01 +01:00

223 lines
7.2 KiB
PHP

<?php
namespace App\Controller;
use App\Entity\Festival;
use App\Entity\Selling;
use App\Entity\GroupOfProducts;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
final class DefaultController extends AbstractController
{
#[Route('/', name: 'app_default')]
public function index(): Response
{
return $this->render('default/main-screen.html.twig', [
'controller_name' => 'DefaultController',
]);
}
#[Route('/accueil', name: 'app_home')]
public function accueil(): Response
{
return $this->render('default/main-screen.html.twig', [
'controller_name' => 'DefaultController',
]);
}
#[Route('/dashboard', name: 'dashboard')]
public function dashboard(): Response
{
return $this->render('logged/dashboard.html.twig', [
'controller_name' => 'DefaultController',
]);
}
#[Route('/export_all', name: 'export_all')]
public function export_all(): Response
{
return $this->render('logged/export_all.html.twig', [
'controller_name' => 'DefaultController',
]);
}
#[Route('/previsionnel', name: 'previsionnel')]
public function previsionnel(): Response
{
return $this->render('logged/previsionnel.html.twig', [
'controller_name' => 'DefaultController',
]);
}
// export_all_json
#[Route('/export_all_json', name: 'export_all_json')]
public function export_all_json(): Response
{
return $this->render('logged/export_all_json.html.twig', [
'controller_name' => 'DefaultController',
]);
}
#[Route('/history', name: 'history')]
public function history(): Response
{
return $this->render('logged/history.html.twig', [
'controller_name' => 'DefaultController',
'chiffreAffaires' => 10000,
'statisticsSoldProducts' => [
[
'name' => 'mock 1',
'count' => 10,
'value' => 10,
], [
'name' => 'mock 2',
'count' => 1,
'value' => 20,
],
],
'activeFestival' => [
'fondDeCaisseAvant' => 10,
'chiffreAffaire' => 10,
'clientsCount' => 10,
'name' => 'demo festival mock dans default controller',
],
'allSellings' => 12,
'recentSellings' => [],
'recentSells' => [
[
'id' => '1234',
'date' => date_create('now'),
'comment' => 'blah',
'amount' => 52,
'productsSold' => [
'name' => 'un truc de démo aussi làààà'
],
],
],
'activeSelling' => [],
// 'sellingComment' => [],
'statisticsFestivals' => 'todo',
'recentSells' => ''
]);
}
#[Route('/logged/get-my-products', name: 'get_my_products')]
public function get_my_products(): JsonResponse
{
// TODO: replace this with actual logic to get products of the logged user
// récupérer les produits de l'user connecté
$user = $this->getUser();
// $products = $this->getUser()->getProducts();
return $this->json([
'categories' => $user->getGroupOfProducts(),
'products' => $user->getProducts(),
// mock land
'lastFestival' => ['id' => 1,
'name' => 'le festival de mock',
'dateCreation' => '2025-02-16',
'commentaire' => 'MOCK: hop le commentaire de festival',
'chiffreAffaire' => '1234',
'fondDeCaisseAvant' => '100',
'fondDeCaisseAprès' => '150',
'sold' => 123
],
'history' => [],
]);
}
#[Route('/logged/import', name: 'import')]
public function import(): Response
{
// prendre en compte l'ajout de nouveaux produits si on a une valeur dans le POST
return $this->render('logged/import.html.twig', []);
}
#[Route('/logged/mass_create', name: 'mass_create')]
public function mass_create(): Response
{
// prendre en compte l'ajout de nouveaux produits si on a une valeur dans le POST
return $this->render('logged/import.html.twig', []);
}
#[Route('/logged/add-selling', name: 'add_selling')]
public function add_selling(): JsonResponse
{
// créer un nouveau Selling et retourner une réponse
//
// $loggedUser = $this->getUser();
// // Prendre les informations en POST et créer une vente avec.
// $request = Request::createFromGlobals();
// $data = json_decode($request->getContent(), true);
//
// $dataOfNewSelling = $data['activeSelling'];
//
// $newSelling = new Selling();
//
// // si l'utilisateur courant n'a pas de festival actuel, en créer un
//
// $currentFestival = $loggedUser->getCurrentFestival();
// if (!$currentFestival) {
//
// $currentFestival = new Festival();
// $currentFestival
// ->setName('festival auto créé')
// ->setClientsCount(1);
// } else {
// $currentFestival->setClientsCount($currentFestival->getClientsCount() + 1);
// }
// $currentFestival->addSelling($newSelling);
//
// // prendre les identifiants des produits en base et les ajouter aux produits de ce Selling
//// $dataOfNewSelling['activeSelling']['id'];
//
//
// // Récupérer l'EntityManager
// $entityManager = $this->getDoctrine()->getManager();
//
// // Récupérer les produits à partir des identifiants
// foreach ($dataOfNewSelling['products']['id'] as $productId) {
//
// $product = $entityManager->getRepository(Product::class)->find($productId);
//
// if ($product) {
// $newSelling->addProduct($product);
// $product->addSelling($newSelling);
// $entityManager->persist($product);
// }
// }
//
//
// $newSelling
// ->setPaidByCustomer($dataOfNewSelling['paidByClient'])
// ->setCustomerInfo($dataOfNewSelling['comment'])
// ->setDate(new \DateTime($data['date']))
// ->setOwner($loggedUser);
//
// $entityManager = $this->getDoctrine()->getManager();
// $entityManager->persist($newSelling);
//
// $entityManager->flush();
// $newSelling = new Selling();
// $newSelling->setOwner($loggedUser);
$response = [
// 'message' => 'yes',
// 'newChiffreAffaire' => $currentFestival->getChiffreAffaire(),
// 'clientsCount' => $currentFestival->getClientsCount(),
// 'activeFestival' => $currentFestival,
];
// prendre en compte l'ajout de nouveaux produits si on a une valeur dans le POST
return $this->json($response);
}
}