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

Orders

parent 831b718e
......@@ -14,9 +14,9 @@ use Symfony\Component\Routing\Annotation\Route;
class UserController extends AbstractController
{
/**
* @Route("/viewOrderDetail", name="viewOrderDetail")
* @Route("/viewOrderDetail/{id}", name="viewOrderDetail")
*/
public function viewOrderDetailAction(Request $request)
public function viewOrderDetailAction(Request $request , $id)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
......@@ -24,76 +24,21 @@ public function viewOrderDetailAction(Request $request)
/* $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();
$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()
$em = $this->getDoctrine()->getManager();
$orders = $em->getRepository('App:Orders')->findOrderbyId($id);
$orders = $em->getRepository('App:OrderItem')->findOrderItembyId($id);
return $this->render('orders/order_detail.html.twig', array(
'orders' => $orders->getQuery()->execute() , 'OrdersItem' => $ordersitems->getQuery()->execute()
));
}
/**
......@@ -194,7 +139,7 @@ public function addOrderingAction(Request $request)
$orders = $em->getRepository('App:Orders')->findAll2($user);
return $this->render('orders/index.html.twig', array(
'orders' => $orders->getQuery()->execute()
));
......
......@@ -3,6 +3,8 @@
namespace App\Entity;
use App\Repository\OrdersRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
......@@ -45,6 +47,13 @@ class Orders
public function __construct()
{
$this->Orders = new ArrayCollection();
}
public function getId(): ?int
......@@ -104,11 +113,7 @@ class Orders
{
return $this->user;
}
public function __toString()
{
return $this->getSiteNom();
}
public function setUser(?User $user): self
{
$this->user = $user;
......@@ -122,6 +127,10 @@ class Orders
return $this;
}
/**
* @return Collection|OrderItem[]
*/
}
......@@ -195,7 +195,7 @@ class User implements UserInterface
}
public function __toString()
{
return $this->getSiteNom();
return $this->getUsername();
}
}
......@@ -36,6 +36,16 @@ class OrdersRepository extends ServiceEntityRepository
;
}
*/
public function findOrderbyId(int $id )
{
return $this->createQueryBuilder('b')
->where('b.id = :u')
->setParameters(['u' => $id ])
->setMaxResults(1);
}
public function findLastInserted()
{
return $this
......
......@@ -28,7 +28,7 @@
<td style="white-space:pre-wrap; word-wrap:break-word; max-width: 15%">{{ order.status }}</td>
<td style="white-space:pre-wrap; word-wrap:break-word; max-width: 15%">{{ order.creationdate | date("d.m.Y") }}</td>
<td style="white-space:pre-wrap; word-wrap:break-word; max-width: 15%">{{ order.deliverydate | date("d.m.Y") }}</td>
<td class="text-center"><a href="{{ path("viewOrderDetail") }}" class="btn btn-sm btn-danger"><span class="fas"></span>Zobraziť detail</a></td>
<td class="text-center"><a href="{{ path('viewOrderDetail', {'id': order.id }) }}" class="btn btn-sm btn-danger"><span class="fas"></span>Zobraziť detail</a></td>
</tr>
{% endfor %}
</tbody>
......
{# empty Twig template #}
{% extends "base.html.twig" %}
{% block title %}Objednávka {% endblock %}
{% block body %}
{% if orders is not empty %}
{% for order in orders %}
<div class="panel panel-info col-sm-12">
<div class="panel-heading">
<h3>Objednávka č.: {{ order.idorders}}</h3>
</div>
<table class="table table-striped table-hover table-light">
<thead>
<tr><th class="text-center">ID OBJEDNÁVKY</th><td>{{ order.idorders | upper }}</td></tr>
<tr><th><span class="fas fa-sticky-note"></span> STATUS</th><td>{{ order.status }}</td></tr>
<tr><th><span class="fas fa-calendar-alt"></span> DÁTUM</th><td>{{ order.creationdate | date("d.m.Y") }}</td></tr>
<tr><th><span class="fas fa-comment-alt"></span> DODÁVKA</th><td>{{ order.deliverydate | date("d.m.Y") }}</td></tr>
<tr><th class="text-center">AKCIA</th><td><a href="" class="btn btn-sm btn-danger"><span class="fas"></span>Zmena stavu objednávky</a></td></tr>
</thead>
<tbody>
</table>
{% endfor %}
{% endif %}
<div class="panel-heading">
<h3>Položky objednávky</h3>
</div>
<table class="table table-striped table-hover table-light" >
<thead>
<tr>
<th class="text-center">Názov</th>
<th><span class="fas fa-sticky-note"></span> Množstvo</th>
<th><span class="fas fa-calendar-alt"></span>MJ</th>
<th><span class="fas fa-comment-alt"></span>Cena</th>
<th><span class="fas fa-comment-alt"></span>Spolu</th>
<th><span class="text-center"></span>AKCIA </th>
` ` </tr>
</thead>
<tr>
<td class="text-center"></td>
<td class="text-center"></td>
<td style="white-space:pre-wrap; word-wrap:break-word; max-width: 15%"></td>
<td style="white-space:pre-wrap; word-wrap:break-word; max-width: 15%"></td>
<td style="white-space:pre-wrap; word-wrap:break-word; max-width: 15%"></td>
<td class="text-center"><a href="" class="btn btn-sm btn-danger"><span class="fas"></span>Zobraziť detail</a></td>
</tr>
</tbody>
</table>
</div>
{% endblock %}
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