Commit 2fa83981 authored by Peter Čeklovský's avatar Peter Čeklovský
Browse files

Revert "Orders"

This reverts commit 8adbcdfa.
parent 8adbcdfa
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
// if ($this->getUser()) {
// return $this->redirectToRoute('target_path');
// }
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout()
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}
<?php
namespace App\Controller;
use App\Entity\Orders;
use App\Entity\OrderItem;
use App\Form\AddOrderItemFormType;
use App\Form\OrderFormType;
use App\Form\detailOrderFormType;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\DBAL\DBALException;
use DateTime;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class UserController extends AbstractController
{
/**
* @Route("/viewOrderDetail/{id}", name="viewOrderDetail")
*/
public function viewOrderDetailAction(Request $request , $id)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
/* $var $user User */
$user = $this->getUser();
if ( !$this->isGranted('ROLE_ADMIN') ) {
return $this->redirectToRoute('/');
}
$em = $this->getDoctrine()->getManager();
$orders = $em->getRepository('App:Orders')->findOrderbyId($id);
$ordersitems = $em->getRepository('App:OrderItem')->findOrderItemsbyId($id);
return $this->render('orders/order_detail.html.twig', array(
'orders' => $orders->getQuery()->execute() , 'ordersitem' => $ordersitems->getQuery()->execute()
));
}
/**
* @Route("/addOrdering", name="addOrdering")
*/
public function addOrderingAction(Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
/* $var $user User */
$user = $this->getUser();
if ( !$this->isGranted('ROLE_ADMIN') ) {
return $this->redirectToRoute('/');
}
$orders = new Orders();
$form = $this->createForm(OrderFormType::class, $orders);
$request = $this->getRequest();
try {
if ($form->isSubmitted() && $form->isValid()) {
$creation_date = $form['creation_date']->getData();
$deliverydate = $form['delivery_date']->getData();
$creation_date = date('Y-m-d', strtotime($creation_date));
$deliveryDate = date('Y-m-d', strtotime($deliverydate));
$em = $this->getDoctrine()->getManager();
$last_orders = $em->getRepository("App:Orders")->findLastInserted();
$currentDate = date("Y-m-d");
$newindex = date('Ym', strtotime($currentDate))*10000 + 1;
if (isset($last_orders)){
$id_orders = $last_orders->getIdOrders()+1;
}else{
$id_orders = 0;
}
if($id_orders < $newindex )
{
$id_orders = $newindex;
}
$order1 = new Orders();
$order1->setIdOrders( $id_orders );
$order1->setCreationDate(DateTime::createFromFormat('Y-m-d' , $creation_date));
$order1->setDeliveryDate(DateTime::createFromFormat('Y-m-d' ,$deliveryDate));
$order1->setStatus('New');
$order1->setUser($user);
$em->persist($order1);
$em->flush();
$this->addFlash(
'success',
'Objednávka bola vytvorená.'
);
return $this->redirectToRoute("homepage");
}
} catch (DBALException $e){
$this->addFlash(
'danger',
"Objednávka nebola vytvorená."
);
}
return $this->render('forms/addorders.html.twig', array(
'form' => $form->createView()
));
}
/**
* @Route("/addOrderItem", name="addOrderItem")
*/
public function addOrderItemAction(Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
/* $var $user User */
$user = $this->getUser();
if ( !$this->isGranted('ROLE_ADMIN') ) {
return $this->redirectToRoute('/');
}
$orderitem = new OrderItem();
$form = $this->createForm(AddOrderItemFormType::class, $orderitem);
return $this->render('forms/addorderitem.html.twig', array(
'form' => $form->createView()
));
}
/**
* @Route("/", name="homepage")
*/
public function index(): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$user = $this->getUser();
$em = $this->getDoctrine()->getManager();
$orders = $em->getRepository('App:Orders')->findAll2($user);
return $this->render('orders/index.html.twig', array(
'orders' => $orders->getQuery()->execute()
));
}
}
<?php
namespace App\DataFixtures;
use App\Entity\Orders;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use DateTime;
class OrdersFixture extends Fixture implements DependentFixtureInterface
{
public function load(ObjectManager $manager) {
$user1 = $this->getReference(UserFixture::USER_USER_REFERENCE);
$user2 = $this->getReference(UserFixture::USER_ADMIN_REFERENCE);
$creation_date = new DateTime();
$deliveryDate = new DateTime();
$order1 = new Orders();
$order1->setIdOrders( "2021120001" );
$order1->setCreationDate($creation_date);
$order1->setDeliveryDate($deliveryDate);
$order1->setStatus('New');
$order1->setUser($user1);
$order2 = new Orders();
$order2->setIdOrders("2021010002");
$order2->setCreationDate($creation_date);
$order2->setDeliveryDate($deliveryDate);
$order2->setStatus('New');
$order2->setUser($user2);
$manager->persist($order1);
$manager->persist($order2);
$manager->flush();
}
public function getDependencies()
{
return array(
UserFixture::class,
);
}
}
<?php
namespace App\DataFixtures;
use App\Entity\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class UserFixture extends Fixture
{
public const USER_USER_REFERENCE = 'user-user';
public const USER_ADMIN_REFERENCE = 'user-admin';
private $encoder;
public function __construct(UserPasswordEncoderInterface $encoder)
{
$this->encoder = $encoder;
}
public function load(ObjectManager $manager)
{
$user1 = new User();
$user1->setPassword($this->encoder->encodePassword($user1, "Pepe007"));
$user1->setUsername("Admin");
$user1->setLastname("Ceklovsky");
$user1->setName("Peter");
$user1->setEmail("admin@example.com");
$user1->setRoles(["ROLE_ADMIN"]);
$user2 = new User();
$user2->setPassword($this->encoder->encodePassword($user1, "Pepe007"));
$user2->setUsername("User");
$user2->setLastname("Ceklovska");
$user2->setName("Zuzana");
$user2->setEmail("user@example.com");
$user2->setRoles(["ROLE_USER"]);
$this->addReference(self::USER_ADMIN_REFERENCE, $user1);
$this->addReference(self::USER_USER_REFERENCE, $user2);
$manager->persist($user1);
$manager->persist($user2);
$manager->flush();
}
}
<?php
namespace App\Entity;
use App\Repository\OrderItemRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=OrderItemRepository::class)
*/
class OrderItem
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="integer")
*/
private $qty;
/**
* @ORM\Column(type="string", length=10)
*/
private $mu;
/**
* @ORM\Column(type="float")
*/
private $unit_price;
/**
* @ORM\Column(type="float")
*/
private $sum_total;
/**
* @ORM\ManyToOne(targetEntity=Orders::class)
* @ORM\JoinColumn(nullable=false)
*/
private $orderid;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getQty(): ?int
{
return $this->qty;
}
public function setQty(int $qty): self
{
$this->qty = $qty;
return $this;
}
public function getMu(): ?string
{
return $this->mu;
}
public function setMu(string $mu): self
{
$this->mu = $mu;
return $this;
}
public function getUnitPrice(): ?float
{
return $this->unit_price;
}
public function setUnitPrice(float $unit_price): self
{
$this->unit_price = $unit_price;
return $this;
}
public function getSumTotal(): ?float
{
return $this->sum_total;
}
public function setSumTotal(float $sum_total): self
{
$this->sum_total = $sum_total;
return $this;
}
public function getOrderid(): ?Orders
{
return $this->orderid;
}
public function setOrderid(?Orders $orderid): self
{
$this->orderid = $orderid;
return $this;
}
}
<?php
namespace App\Entity;
use App\Repository\OrdersRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=OrdersRepository::class)
*/
class Orders
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="integer")
*/
private $id_orders;
/**
* @ORM\Column(type="date")
*/
private $creation_date;
/**
* @ORM\Column(type="date")
*/
private $delivery_date;
/**
* @ORM\Column(type="string", length=150)
*/
private $status;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="orders")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
public function __construct()
{
$this->Orders = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getIdOrders(): ?int
{
return $this->id_orders;
}
public function setIdOrders(int $id_orders): self
{
$this->id_orders = $id_orders;
return $this;
}
public function getCreationDate(): ?\DateTimeInterface
{
return $this->creation_date;
}
public function setCreationDate(\DateTimeInterface $creation_date): self
{
$this->creation_date = $creation_date;
return $this;
}
public function getDeliveryDate(): ?\DateTimeInterface
{
return $this->delivery_date;
}
public function setDeliveryDate(\DateTimeInterface $delivery_date): self
{
$this->delivery_date = $delivery_date;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function setNewIdOrder()
{
$this->user = $user;
return $this;
}
/**
* @return Collection|OrderItem[]
*/
}
<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
*/
class User implements UserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=false)