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

Orders

parent e24b34aa
......@@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210323155904 extends AbstractMigration
final class Version20210324122001 extends AbstractMigration
{
public function getDescription() : string
{
......@@ -20,16 +20,20 @@ final class Version20210323155904 extends AbstractMigration
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE order_item CHANGE id_order orderid_id INT NOT NULL');
$this->addSql('CREATE TABLE order_item (id INT AUTO_INCREMENT NOT NULL, orderid_id 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, INDEX IDX_52EA1F096F90D45B (orderid_id), 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 order_item ADD CONSTRAINT FK_52EA1F096F90D45B FOREIGN KEY (orderid_id) REFERENCES orders (id)');
$this->addSql('CREATE INDEX IDX_52EA1F096F90D45B ON order_item (orderid_id)');
$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 order_item DROP FOREIGN KEY FK_52EA1F096F90D45B');
$this->addSql('DROP INDEX IDX_52EA1F096F90D45B ON order_item');
$this->addSql('ALTER TABLE order_item CHANGE orderid_id id_order INT NOT NULL');
$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');
}
}
......@@ -7,10 +7,10 @@ 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\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
......@@ -73,10 +73,9 @@ public function addOrderingAction(Request $request)
$form = $this->createForm(OrderFormType::class, $orders);
$request = $this->getRequest();
try {
dump($form->isSubmitted() );
if ($form->isSubmitted() && $form->isValid()) {
......@@ -135,7 +134,7 @@ public function addOrderingAction(Request $request)
/**
* @Route("/addOrderItem", name="addOrderItem")
*/
public function addOrderItemAction(Request $request)
public function addOrderItemAction(Request $request )
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
......@@ -154,6 +153,47 @@ public function addOrderItemAction(Request $request)
$form = $this->createForm(AddOrderItemFormType::class, $orderitem);
try {
if ($form->isSubmitted() && $form->isValid()) {
$name = $form['name']->getData();
$qty = $form['qty']->getData();
$mu = $form['mu']->getData();
$unit_price = $form['unit_price']->getData();
$em = $this->getDoctrine()->getManager();
$orderitem = new OrderItem();
$orderitem->setName( $name );
$orderitem->setQty( $qty);
$orderitem->setDeliveryDate(DateTime::createFromFormat('Y-m-d' ,$deliveryDate));
$orderitem->setSumTotal($sum_total);
$orderitem->setOrderId($orderid);
$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/addorderitem.html.twig', array(
'form' => $form->createView()
));
......
<?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,
);
}
}
......@@ -10,6 +10,8 @@ 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\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormEvent;
......@@ -18,18 +20,49 @@ 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"
'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', MoneyType::class, array(
'html5' => true ,
'scale' => 2 ,
'attr' => array(
'class' => 'form-control',
),
'label' => 'Cena za mernú jednotku',
'mapped' => false
))
->add('qty')
->add('mu')
->add('unit_price')
->add('sum_total')
->add('sum_total',TextType::class, array(
'attr' => array(
'class' => 'form-control',
),
'label' => 'Spolu',
'mapped' => false
))
->add('save', SubmitType::class, array(
'attr' => array(
'class' => 'btn btn-success float-right mt-3',
),
'label' => 'Zápis položky objednávky',
));
;
}
......
......@@ -47,9 +47,7 @@ class OrderFormType extends AbstractType
'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