Commit a8aef681 authored by notebook's avatar notebook
Browse files

Merge origin/master into skuska

Conflicts:
	composer.lock
	config/packages/security.yaml
	src/Controller/Admin/DashboardController.php
	symfony.lock
parent a5298428
......@@ -4,6 +4,7 @@ namespace App\Controller;
use App\Entity\Orders;
use App\Form\OrderFormType;
use App\Form\detailOrderFormType;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\DBAL\DBALException;
use DateTime;
......@@ -14,85 +15,26 @@ 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');
/* $var $user User */
$user = $this->getUser();
$em = $this->getDoctrine()->getManager();
$orders = $em->getRepository('App:Orders')->findorderbyid($id);
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 = $this->createForm(detailOrderFormType::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(
return $this->render('forms/detailorder.html.twig', array(
'form' => $form->createView()
));
}
......@@ -109,20 +51,16 @@ public function addOrderingAction(Request $request)
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);
$request = $this->getRequest();
try {
......
......@@ -195,7 +195,7 @@ class User implements UserInterface
}
public function __toString()
{
return $this->getSiteNom();
return $this->getName();
}
}
......@@ -38,6 +38,7 @@ class OrderFormType extends AbstractType
'attr' => array(
'class' => 'form-control',
),
'label' => 'STATUS', ])
->add('save', SubmitType::class, array(
'attr' => array(
......@@ -46,8 +47,8 @@ class OrderFormType extends AbstractType
'label' => 'Save invoice',
));
;
}
......
<?php
namespace App\Form;
use App\Entity\Orders;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class detailOrderFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('id_orders')
->add('creation_date')
->add('delivery_date')
->add('status')
->add('user')
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Orders::class,
]);
}
}
......@@ -36,6 +36,17 @@ class OrdersRepository extends ServiceEntityRepository
;
}
*/
public function findorderbyid(int $id )
{
return $this
->createQueryBuilder("e")
->where('b.id = :u')
->setParameters(['u' => $id ])
->orderBy("e.id_orders", "DESC")
->setMaxResults(1)
->getQuery()
->getOneOrNullResult();
}
public function findLastInserted()
{
return $this
......
{% extends "base.html.twig" %}
{% block title %}Vytvorenie ojednávky{% endblock %}
{% block title %}Vytvorenie objednávky{% endblock %}
{% block body %}
<div class="panel panel-success col-sm-8">
<div class="panel-heading">
......
{% extends "base.html.twig" %}
{% block title %}Detail objednávky{% endblock %}
{% block body %}
<div class="panel panel-success col-sm-8">
<div class="panel-heading">
<h3>Detail objednávky</h3>
</div>
<div class="panel-heading">
<table>
<tr><td><span>Čislo objednávky </span></td><td><span> ssss </span></td></tr>
<tr><td><span>Dátum vytvorenia objednávky </span></td><td><span> ssss </span></td></tr>
<tr><td><span>Dátum dodania </span></td><td><span> ssss </span></td></tr>
</table>
{{ form(form) }}
</div>
{% endblock %}
\ No newline at end of file
......@@ -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>
......
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