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

Orders

parent 275f79b7
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "b030b978957d89d09dcb8a86188ce00f",
"content-hash": "0d62d4422006ef0c8cbe0a6fbbee2729",
"packages": [
{
"name": "composer/package-versions-deprecated",
......
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210321132848 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE order_item (id INT AUTO_INCREMENT NOT NULL, id_order INT NOT NULL, name VARCHAR(255) NOT NULL, qty INT NOT NULL, mu VARCHAR(10) NOT NULL, unit_price DOUBLE PRECISION NOT NULL, sum_total DOUBLE PRECISION NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE orders (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, id_orders INT NOT NULL, creation_date DATE NOT NULL, delivery_date DATE NOT NULL, status VARCHAR(150) NOT NULL, INDEX IDX_E52FFDEEA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(180) NOT NULL, lastname VARCHAR(180) NOT NULL, username VARCHAR(180) NOT NULL, email VARCHAR(180) NOT NULL, roles LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\', password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649F85E0677 (username), UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE orders ADD CONSTRAINT FK_E52FFDEEA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE orders DROP FOREIGN KEY FK_E52FFDEEA76ED395');
$this->addSql('DROP TABLE order_item');
$this->addSql('DROP TABLE orders');
$this->addSql('DROP TABLE user');
}
}
......@@ -13,16 +13,15 @@ use Symfony\Component\Routing\Annotation\Route;
class UserController extends AbstractController
{
/**
* @Route("/addOrdering", name="addOrdering")
* @Route("/viewOrderDetail", name="viewOrderDetail")
*/
public function addOrderingAction(Request $request)
public function viewOrderDetailAction(Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
/* $var $user User */
$user = $this->getUser();
......@@ -41,39 +40,138 @@ public function addOrderingAction(Request $request)
$form = $this->createForm(OrderFormType::class, $orders);
$form->handleRequest($request);
try {
// pokud je validní po odeslání
if ($form->isSubmitted() && $form->isValid()) {
// vložit data z formu do proměnných
$car = $form['car']->getData(); // vrací objekt
$date_from = $form['reservation_date_from']->getData(); // 01.11.2018 22:45 den-mesic-rok h:m
$date_to = $form['reservation_date_to']->getData();
$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á.'
);
// parsování dat
$date_from = date('Y-m-d H:i:s', strtotime($date_from));
$date_to = date('Y-m-d H:i:s', strtotime($date_to));
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("/addOrdering", name="addOrdering")
*/
public function addOrderingAction(Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
// vložit data do objektu
$booking->setReservationDateFrom(DateTime::createFromFormat('Y-m-d H:i:s', $date_from));
$booking->setReservationDateTo(DateTime::createFromFormat('Y-m-d H:i:s', $date_to));
$booking->setUser($user); // rezervace od tohoto usera
/* $var $user User */
$user = $this->getUser();
if ( !$this->isGranted('ROLE_ADMIN') ) {
if (!$user->getCanReserve()) {
$this->addFlash(
'danger',
'Nemáte právo vložiť objednávku.'
);
return $this->redirectToRoute('/');
}
}
$orders = new Orders();
$form = $this->createForm(OrderFormType::class, $orders);
$form->handleRequest($request);
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();
// vložit záznam do DB
$em->persist($booking);
$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();
// zobrazit zprávu o úspěšnosti
$this->addFlash(
'success',
'Rezervace úspěšně vytvořena.'
'Objednávka bola vytvorená.'
);
return $this->redirectToRoute('myBooking');
return $this->redirectToRoute("homepage");
}
} catch (DBALException $e){
$this->addFlash(
'danger',
"Rezervace nemohla být uskutečněna. Ujistěte se, zda je volné vozidlo."
"Objednávka nebola vytvorená."
);
}
......
......@@ -115,6 +115,12 @@ class Orders
return $this;
}
public function setNewIdOrder()
{
$this->user = $user;
return $this;
}
......
......@@ -38,9 +38,16 @@ class OrderFormType extends AbstractType
'attr' => array(
'class' => 'form-control',
),
'label' => 'STATUS', ]
);
'label' => 'STATUS', ])
->add('save', SubmitType::class, array(
'attr' => array(
'class' => 'btn btn-success float-right mt-3',
),
'label' => 'Save invoice',
));
;
}
......
......@@ -36,7 +36,15 @@ class OrdersRepository extends ServiceEntityRepository
;
}
*/
public function findLastInserted()
{
return $this
->createQueryBuilder("e")
->orderBy("e.id_orders", "DESC")
->setMaxResults(1)
->getQuery()
->getOneOrNullResult();
}
public function findAll2(UserInterface $user )
{
......
......@@ -22,13 +22,11 @@
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse" id="collapsingNavbar">
{# LEFT ALIGN NAVBAR #}
<ul class="navbar-nav">
{# OBJEDNÁVKY #}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown_menu_2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="fas fa-car-alt"></span>OBJEDNÁVKY</a>
<a class="nav-link dropdown-toggle" href="#" id="dropdown_menu_2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="fas fa-file-invoice"></span>OBJEDNÁVKY</a>
<div class="dropdown-menu" aria-labelledby="dropdown_menu_2">
{% if is_granted('ROLE_ADMIN') %}
<a class="dropdown-item" href="{{ path("addOrdering") }}"><span class="fas fa-plus-circle"></span> PRIDAŤ OBJEDNÁVKY</a>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment