set active festival button
This commit is contained in:
parent
19cdb12d28
commit
9885d6f937
|
@ -3,16 +3,16 @@
|
|||
let introJs = require('intro.js');
|
||||
var $ = require('jquery');
|
||||
$(document).ready(function () {
|
||||
let massimportExample = 'catégorie: livre\n' +
|
||||
' les moutaines;5€\n' +
|
||||
' la laine des moutons;6€\n' +
|
||||
' star wars spécial noël;7€\n' +
|
||||
'catégorie: poster\n' +
|
||||
' super bannière A2;10€\n' +
|
||||
' Sébastien Chabal sexy;10€\n' +
|
||||
'catégorie: dessin à la demande\n' +
|
||||
' dessin A4 crayon;20€\n' +
|
||||
' dessin A4 aquarelle;150€';
|
||||
let massimportExample = `catégorie: livre
|
||||
les moutaines;5€
|
||||
la laine des moutons;6€
|
||||
star wars spécial noël;7€
|
||||
catégorie: poster
|
||||
super bannière A2;10€
|
||||
Sébastien Chabal sexy;10€
|
||||
catégorie: dessin à la demande
|
||||
dessin A4 crayon;20€
|
||||
dessin A4 aquarelle;150€`;
|
||||
|
||||
// $('[data-toggle="popover"]').popover();
|
||||
$('#menu_button').on('click', function () {
|
||||
|
|
|
@ -3,12 +3,14 @@
|
|||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Festival;
|
||||
use App\Entity\Selling;
|
||||
use App\Entity\GroupOfProducts;
|
||||
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use App\Entity\Product;
|
||||
use App\Entity\Selling;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class DefaultController extends AbstractController
|
||||
|
@ -141,83 +143,160 @@ final class DefaultController extends AbstractController
|
|||
}
|
||||
|
||||
#[Route('/logged/mass_create', name: 'mass_create')]
|
||||
public function mass_create(): Response
|
||||
public function mass_create(Request $request, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
// prendre en compte l'ajout de nouveaux produits si on a une valeur dans le POST
|
||||
return $this->render('logged/import.html.twig', []);
|
||||
// TODO prendre en compte l'ajout de nouveaux produits si on a une valeur dans le POST
|
||||
$request = Request::createFromGlobals();
|
||||
$data = json_decode($request->getContent(), true);
|
||||
|
||||
// les imports listent des catégories de produits et des noms de produits avec leur prix comme ceci:
|
||||
// catégorie: livre
|
||||
// les moutaines;5€
|
||||
// la laine des moutons;6€
|
||||
// star wars spécial noël;7€
|
||||
//catégorie: poster
|
||||
// super bannière A2;10€
|
||||
// Sébastien Chabal sexy;10€
|
||||
|
||||
// Vérifiez si une requête POST a été faite
|
||||
if ($request->isMethod('POST')) {
|
||||
$data = $request->getContent();
|
||||
$lines = explode("\n", $data); // Séparez les lignes
|
||||
|
||||
$currentCategory = null;
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if (empty($line)) {
|
||||
continue; // Ignorez les lignes vides
|
||||
}
|
||||
|
||||
// Vérifiez si la ligne commence par un nom de catégorie
|
||||
if (preg_match('/^(.*):$/', $line, $matches)) {
|
||||
$currentCategory = new GroupOfProducts();
|
||||
$currentCategory->setName(trim($matches[1]));
|
||||
$entityManager->persist($currentCategory);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Vérifiez si la ligne contient un produit
|
||||
if ($currentCategory && preg_match('/^(.*); ([0-9]+(?:\.[0-9]+)?)$/', $line, $matches)) {
|
||||
$productName = trim($matches[1]);
|
||||
$productPrice = (float)trim($matches[2]);
|
||||
|
||||
// Créez un nouvel objet Product
|
||||
$product = new Product();
|
||||
$product->setName($productName);
|
||||
$product->setPrice($productPrice);
|
||||
|
||||
// Ajoutez le produit à la catégorie
|
||||
$currentCategory->addProduct($product);
|
||||
$entityManager->persist($product);
|
||||
}
|
||||
}
|
||||
|
||||
// Enregistrez tous les changements dans la base de données
|
||||
$entityManager->flush();
|
||||
|
||||
return new Response('Produits importés avec succès.', Response::HTTP_CREATED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[Route('/logged/add-selling', name: 'add_selling')]
|
||||
public function add_selling(): JsonResponse
|
||||
public function add_selling(EntityManagerInterface $entityManager): 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);
|
||||
|
||||
$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;
|
||||
|
||||
// return $this->json($dataOfNewSelling);
|
||||
|
||||
$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éé')
|
||||
->setUser($loggedUser)
|
||||
->setDateCreation(new \DateTime())
|
||||
->setDateStart(new \DateTime())
|
||||
->setDateEnd((new \DateTime())->modify('+1 year'))
|
||||
->setClientsCount(1);
|
||||
|
||||
$entityManager->persist($currentFestival);
|
||||
} else {
|
||||
$currentFestival->setClientsCount($currentFestival->getClientsCount() + 1);
|
||||
}
|
||||
$currentFestival->addSelling($newSelling);
|
||||
|
||||
// prendre les identifiants des produits en base et les ajouter aux produits de ce Selling
|
||||
// Récupérer les produits à partir des identifiants
|
||||
$sum = 0;
|
||||
foreach ($dataOfNewSelling['activeSelling'] as $product) {
|
||||
|
||||
$productFound = $entityManager->getRepository(Product::class)->findOneById($product['id']);
|
||||
|
||||
$sum += $product['price'] * 1;
|
||||
|
||||
if ($productFound) {
|
||||
$newSelling->addProduct($productFound);
|
||||
$productFound->addSelling($newSelling);
|
||||
$entityManager->persist($productFound);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$newSelling
|
||||
->setSum($sum)
|
||||
->setPaidByCustomer($dataOfNewSelling['paidByClient'])
|
||||
->setCustomerInfo($dataOfNewSelling['sellingComment'])
|
||||
->setDate(new \DateTime())
|
||||
->setOwner($loggedUser);
|
||||
|
||||
|
||||
$entityManager->persist($newSelling);
|
||||
|
||||
|
||||
$newSelling->setOwner($loggedUser);
|
||||
$entityManager->persist($loggedUser);
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
$response = [
|
||||
// 'message' => 'yes',
|
||||
// 'newChiffreAffaire' => $currentFestival->getChiffreAffaire(),
|
||||
// 'clientsCount' => $currentFestival->getClientsCount(),
|
||||
// 'activeFestival' => $currentFestival,
|
||||
'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);
|
||||
}
|
||||
|
||||
// TODO set_active_festival
|
||||
|
||||
#[Route('/logged/set-active-festival/{id}', name: 'app_set_active_festival')]
|
||||
public function set_active_festival(EntityManagerInterface $entityManager, $id): Response
|
||||
{
|
||||
$festival = $entityManager->getRepository(Festival::class)->find($id);
|
||||
if ($festival && $festival->getUser() === $this->getUser()) {
|
||||
$this->getUser()->setActiveFestival($festival);
|
||||
$entityManager->persist($this->getUser());
|
||||
$entityManager->flush();
|
||||
}
|
||||
return $this->redirectToRoute('app_festival_index');
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Entity;
|
|||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
|
@ -49,11 +50,15 @@ class Selling
|
|||
#[ORM\ManyToOne(inversedBy: 'sellings')]
|
||||
private ?User $owner = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
||||
private ?\DateTimeInterface $date = null;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->groupOfProducts = new ArrayCollection();
|
||||
$this->products = new ArrayCollection();
|
||||
$this->setDate(new \DateTime());
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
|
@ -200,5 +205,17 @@ class Selling
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getDate(): ?\DateTimeInterface
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function setDate(\DateTimeInterface $date): static
|
||||
{
|
||||
$this->date = $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* les séries de festival réunissent des évènements similaires dans le temps
|
||||
* typiquement plusieurs éditions d'un ensemble
|
||||
* cela permet d'avoir des informations statistiques groupées
|
||||
*/
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\SerieFestivalRepository;
|
||||
|
|
|
@ -23,7 +23,12 @@
|
|||
{% for festival in festivals %}
|
||||
<tr>
|
||||
<td>{{ festival.id }}</td>
|
||||
<td>{{ festival.name }}</td>
|
||||
<td
|
||||
{% if app.user.activeFestival and app.user.activeFestival.id == festival.id %}
|
||||
class="text-bg-success p-3"
|
||||
{% endif %}>
|
||||
{{ festival.name }}
|
||||
</td>
|
||||
<td>{{ festival.dateStart ? festival.dateStart|date('Y-m-d') : '' }}</td>
|
||||
<td>{{ festival.dateEnd ? festival.dateEnd|date('Y-m-d') : '' }}</td>
|
||||
<td>{{ festival.fraisInscription }}</td>
|
||||
|
@ -33,6 +38,7 @@
|
|||
<td>
|
||||
<a href="{{ path('app_festival_show', {'id': festival.id}) }}">show</a>
|
||||
<a href="{{ path('app_festival_edit', {'id': festival.id}) }}">edit</a>
|
||||
<a href="{{ path('app_set_active_festival', {'id': festival.id}) }}">Set as active</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
|
|
Loading…
Reference in New Issue