Пример #1
0
 /**
  * Host Order creation form
  * @param Request $request Submitted form request
  * @return \Symfony\Component\HttpFoundation\Response
  * @throws \Exception
  */
 public function createAction(Request $request)
 {
     $hostOrder = new Host_order();
     //Prefilling the form with some data
     //Assigning hostOrder to the user
     $userObject = $this->get("security.token_storage")->getToken()->getUser();
     $hostOrder->setUsersId($userObject);
     $hostOrder->setCloseDate(new \DateTime("now"));
     $form = $this->createForm(new Host_orderType(), $hostOrder);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($hostOrder);
         // Creating User_order for the host user
         $userOrder = new User_order();
         $userOrder->setHostOrderId($hostOrder);
         $userOrder->setUsersId($userObject);
         $em->persist($userOrder);
         $em->flush();
         $notificationMessage = $this->get('translator')->trans('order.summary.successCreate');
         $this->get('session')->getFlashBag()->add('success', $notificationMessage);
         return $this->redirectToRoute('host_order_summary', ['id' => $hostOrder->getId()]);
     }
     return $this->render("IlluminatiOrderBundle:Default:orderCreation.html.twig", ["form" => $form->createView(), 'pageTitle' => 'order.create']);
 }
Пример #2
0
 public function load(ObjectManager $manager)
 {
     for ($i = 1; $i <= 5; $i++) {
         $date = new \DateTime("12/1{$i}/2015");
         $hostOrder = new Host_order();
         $hostOrder->setUsersId($this->getReference("user{$i}"));
         $hostOrder->setTitle("Awesome order{$i}");
         $hostOrder->setCloseDate($date);
         $hostOrder->setDescription('Awesome order for awesome people');
         $hostOrder->setSupplierId($this->getReference('supplier'));
         $this->addReference("hostOrder{$i}", $hostOrder);
         $manager->persist($hostOrder);
         $manager->flush();
     }
 }
 /**
  * Generates PDF with hosted order's products and participants
  *
  * @param \Illuminati\OrderBundle\Entity\Host_Order $hostOrder
  */
 public function generate(Host_order $hostOrder)
 {
     $repo = $this->em->getRepository('IlluminatiOrderBundle:Host_order');
     $hostedOrderHost = $hostOrder->getUsersId();
     $products = $repo->findOrderedProducts($hostOrder->getId());
     $participants = $repo->findUserOrders($hostOrder->getId());
     $overallPriceSum = 0;
     $this->AliasNbPages();
     $this->newOrderPage($hostOrder->getTitle(), "Ordered Products:");
     // Generating Product Table;
     if (!empty($products)) {
         // Column widths
         $w = [120, 25, 45];
         $this->Cell($w[0], 6, "Product", 1, 0);
         $this->Cell($w[1], 6, "Quantity", 1, 0, "R");
         $this->Cell($w[2], 6, "Price", 1, 0, "R");
         $this->Ln();
         foreach ($products as $product) {
             $this->Cell($w[0], 6, $product['title'], 'LR');
             $this->Cell($w[1], 6, $product['quantity'], 'LR', 0, "R");
             $this->Cell($w[2], 6, $product['sum'] . " " . $product['currency'], 'LR', 0, "R");
             $this->Ln();
             $overallPriceSum += $product['sum'];
         }
         $this->Cell($w[0], 1, '', 'T');
         $this->Cell($w[1], 6, "Sum", 1, 0, "R");
         $this->Cell($w[2], 6, $overallPriceSum . " " . $products[0]['currency'], 1, 0, "R");
     }
     //Generating particiapnts table;
     $this->newOrderPage($hostOrder->getTitle(), "Order Participants: ");
     if (!empty($participants)) {
         $counter = 1;
         $w = [10, 155, 25];
         $this->Cell($w[0], 6, "Nr.", 1, 0);
         $this->Cell($w[1], 6, "Participant", 1, 0);
         $this->Cell($w[2], 6, "Prepaid", 1, 0, "R");
         $this->Ln();
         foreach ($participants as $participant) {
             // We skip the host of the order in the list
             if ($participant->getUsersId() == $hostedOrderHost) {
                 continue;
             }
             $this->Cell($w[0], 6, "{$counter}.", "LR", 0, "C");
             $this->Cell($w[1], 6, "{$participant->getUsersId()->getName()} " . "{$participant->getUsersId()->getSurname()} " . "( {$participant->getUsersId()->getEmail()} )", "LR");
             $prepaid = $participant->getPayed() == 0 ? "No" : "Yes";
             $this->Cell($w[2], 6, $prepaid, "LR", 0, "R");
             $this->Ln();
             $counter++;
         }
         $this->Cell(array_sum($w), 1, '', 'T');
     }
 }
Пример #4
0
 /**
  * Deletes participant from the hosted order
  *
  * @param Host_order $hostOrder Host order Object
  * @param integer $userId    User Id
  *
  * @return int
  * @throws \Doctrine\DBAL\ConnectionException
  */
 public function deleteParticipant(Host_order $hostOrder, $userId)
 {
     $conn = $this->getEntityManager()->getConnection();
     $conn->beginTransaction();
     try {
         $conn->executeQuery('UPDATE user_order
             SET deleted = 1
             WHERE host_order_id = ? AND users_id = ?  AND deleted = 0;', [$hostOrder->getId(), $userId]);
         // checking if the user is the host of the group order
         // if yes, we close the group order
         if ($hostOrder->getUsersId()->getId() == $userId) {
             $conn->executeQuery('UPDATE host_order
                 SET deleted = 1
                 WHERE id = ?', [$hostOrder->getId()]);
         }
         $conn->executeQuery('DELETE FROM user_order_details
             WHERE host_order_id = ? AND user_id = ?;', [$hostOrder->getId(), $userId]);
         $conn->commit();
     } catch (\Exception $e) {
         $conn->rollBack();
         $conn->close();
         return false;
     }
     $conn->close();
     return true;
 }