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

Orders

parent dc8588b6
......@@ -72,9 +72,7 @@ public function addOrderingAction(Request $request)
$orders = new Orders();
$form = $this->createForm(OrderFormType::class, $orders);
$request = $this->getRequest();
$form->handleRequest($request);
try {
if ($form->isSubmitted() && $form->isValid()) {
......@@ -153,6 +151,50 @@ public function addOrderItemAction(Request $request)
$orderitem = new OrderItem();
$form = $this->createForm(AddOrderItemFormType::class, $orderitem);
$form->handleRequest($request);
try {
if ($form->isSubmitted() && $form->isValid()) {
$name = $form['name']->getData();
$qty = $form['qty']->getData();
$mu = $form['mu']->getData();
$unit_price = $form['unit_price']->getData();
$sum_total = $qty * $unit_price;
$em = $this->getDoctrine()->getManager();
$orderitem = new OrderItem();
$orderitem->setName( $name );
$orderitem->setQty( $qty );
$orderitem->setMu( $mu );
$orderitem->setUnitPrice($unit_price);
$orderitem->setSumTotal($unit_price);
$orders = new Orders();
$orderitem->setOrderid($orders);
$em->persist($orderitem);
$em->flush();
$this->addFlash(
'success',
'Položka objednávka bola vytvorená.'
);
return $this->redirectToRoute("homepage");
}
} catch (DBALException $e){
$this->addFlash(
'danger',
"Objednávka nebola vytvorená."
);
}
return $this->render('forms/addorderitem.html.twig', array(
'form' => $form->createView()
......
......@@ -10,6 +10,7 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormEvent;
......@@ -18,19 +19,42 @@ class AddOrderItemFormType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name',TextType::class, array( // typ Text, protože nebudeme zobrazovat políčka pro vybrání data. Načteme si 3rd party kalendář
->add('name',TextType::class, array(
'attr' => array(
'class' => 'form-control',
'class' => 'form-control',
),
'label' => 'Názov tovaru',
'mapped' => false // nebudeme kontrolovat správnost tohoto pole přes databázi, protože jde o "TextType" a ne "DateTimeType"
))
->add('qty')
->add('mu')
->add('unit_price')
->add('sum_total')
;
'mapped' => false ))
->add('qty',IntegerType::class, array(
'attr' => array(
'class' => 'form-control',
),
'label' => 'Množstvo',
'mapped' => false ))
->add('mu',TextType::class, array(
'attr' => array(
'class' => 'form-control',
),
'label' => 'Merná jednotka',
'mapped' => false ))
->add('unit_price',IntegerType::class, array(
'attr' => array(
'class' => 'form-control',
),
'label' => 'Jednotková cena',
'mapped' => false ))
->add('sum_total',IntegerType::class, array( 'attr' => array(
'class' => 'form-control',
),
'label' => 'Celkom',
'mapped' => false ))
->add('save', SubmitType::class, array(
'attr' => array(
'class' => 'btn btn-success float-right mt-3',
),
'label' => 'Save invoice',
));
}
public function configureOptions(OptionsResolver $resolver)
......
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