示例#1
0
 public function addOrder(Order $order, Chart $chart = null)
 {
     if (!$chart) {
         $chart = new Chart();
     }
     $order->setChart($chart);
 }
示例#2
0
 public function executeSupportCreditOrder(Order $order)
 {
     $product = $order->getProduct();
     $details = $product->getDetails();
     $nbCredits = $details['nb_credits'];
     $this->creditSupportManager->addCreditsToUser($order->getChart()->getOwner(), $nbCredits);
 }
 /**
  * @EXT\Route(
  *      "/payment/workspace/submit/order/{order}/product/{product}",
  *      name="workspace_product_payment_submit"
  * )
  * @EXT\ParamConverter("authenticatedUser", options={"authenticatedUser" = true})
  * @return Response
  */
 public function addOrderToChartAction(Order $order, Product $product)
 {
     $chart = $order->getChart();
     //check it wasn't already submitted
     if (false) {
         $content = $this->renderView('FormaLibreInvoiceBundle:errors:orderAlreadySubmitedException.html.twig');
         return new Response($content);
     }
     if ($this->session->has('form_price_data')) {
         $priceSolution = $this->session->get('form_price_data');
         $this->session->remove('form_price_data');
         $priceSolution = $this->em->getRepository('FormaLibreInvoiceBundle:PriceSolution')->find($priceSolution->getId());
     }
     $form = $this->createForm(new SharedWorkspaceForm($product));
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         //do that stuff here
         if (!$this->authorization->isGranted('ROLE_USER')) {
             $this->session->set('form_price_data', $form->get('price')->getData());
             $redirectRoute = $this->router->generate('workspace_product_payment_submit', array('order' => $order->getId(), 'product' => $product->getId(), 'chart' => $chart->getId()));
             $this->session->set('redirect_route', $redirectRoute);
             $route = $this->router->generate('claro_security_login', array());
             return new RedirectResponse($route);
         }
         $priceSolution = $form->get('price')->getData();
     }
     $order->setChart($chart);
     $order->setProduct($product);
     $chart->setOwner($this->tokenStorage->getToken()->getUser());
     $chart->setIpAdress($_SERVER['REMOTE_ADDR']);
     $order->setPriceSolution($priceSolution);
     $order->setChart($chart);
     if ($this->swsManager->hasFreeTestMonth($chart->getOwner())) {
         $order->setHasDiscount(true);
         $this->swsManager->useFreeTestMonth($chart->getOwner());
     }
     $this->em->persist($chart);
     $this->em->persist($order);
     $this->em->flush();
     return new RedirectResponse($this->router->generate('chart_payment_confirm', array('chart' => $order->getChart()->getId()), true));
     throw new \Exception('Errors were found: ' . $form->getErrorsAsString());
 }
 /**
  * @EXT\Route(
  *     "/shared/workspace/create",
  *     name="formalibre_admin_shared_workspace_create",
  *     options={"expose"=true}
  * )
  * @EXT\ParamConverter("authenticatedUser", options={"authenticatedUser" = true})
  * @EXT\Template("FormaLibreInvoiceBundle:AdminSharedWorkspaces:sharedWorkspaceCreateForm.html.twig")
  */
 public function sharedWorkspaceCreateAction()
 {
     $products = $this->productManager->getProductsBy(array('type' => 'SHARED_WS'), array('code' => 'ASC'));
     $product = count($products) > 0 ? $products[0] : null;
     $workspaces = $this->sharedWorkspaceManager->getNonPersonalRemoteWorkspacesDatas();
     $sharedWorkspace = new SharedWorkspace();
     $form = $this->formFactory->create(new SharedWorkspaceType($this->translator, $product, $workspaces), $sharedWorkspace);
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $owner = $sharedWorkspace->getOwner();
         $remoteUser = $this->sharedWorkspaceManager->getRemoteUser($owner->getUsername());
         if (isset($remoteUser['error']['code'])) {
             $remoteUser = $this->sharedWorkspaceManager->createRemoteUser($owner);
         }
         $remoteWorkspaceId = $form->get('remoteWorkspace')->getData();
         if (!is_null($remoteWorkspaceId)) {
             $sharedWorkspace->setRemoteId($remoteWorkspaceId);
             $this->om->persist($sharedWorkspace);
             $datas = 'success';
         } else {
             $name = $form->get('name')->getData();
             $code = $form->get('code')->getData();
             $datas = $this->sharedWorkspaceManager->createRemoteWorkspace($sharedWorkspace, $owner, $name, $code);
         }
         if ($datas === 'success') {
             $product = $form->get('product')->getData();
             $priceSolutionId = $form->get('price')->getData();
             $priceSolutions = $product->getPriceSolutions();
             $priceSolution = $priceSolutions[$priceSolutionId];
             $chart = new Chart();
             $chart->setOwner($owner);
             $now = new \DateTime();
             $chart->setCreationDate($now);
             $chart->setValidationDate($now);
             $order = new Order();
             $order->setPriceSolution($priceSolution);
             $order->setProduct($product);
             $order->setSharedWorkspace($sharedWorkspace);
             $order->setChart($chart);
             $this->om->persist($order);
             $chart->addOrder($order);
             $this->om->persist($chart);
             $this->invoiceManager->create($chart, 'bank_transfer', true);
             return new RedirectResponse($this->router->generate('formalibre_admin_shared_workspaces_admin_tool_index'));
         } else {
             $form->addError(new FormError($this->translator->trans('probably_invalid_code', array(), 'invoice')));
         }
     }
     return array('form' => $form->createView());
 }
 /**
  * @EXT\Route(
  *      "/support/credits/products/purchase",
  *      name="formalibre_support_credits_products_purchase"
  * )
  * @EXT\Template("")
  *
  * @return Response
  */
 public function supportCreditsPurchaseAction()
 {
     $user = $this->tokenStorage->getToken()->getUser();
     $productId = null;
     if ($this->session->has('support_credit_purchase_form_product_id')) {
         $productId = $this->session->get('support_credit_purchase_form_product_id');
         $this->session->remove('support_credit_purchase_form_product_id');
     }
     $datas = $this->request->request->all();
     if (!is_null($productId) || isset($datas['support_credit_purchase_form']) && isset($datas['support_credit_purchase_form']['product'])) {
         $productId = is_null($productId) ? intval($datas['support_credit_purchase_form']['product']) : $productId;
         if (!$this->authorization->isGranted('ROLE_USER')) {
             $this->session->set('support_credit_purchase_form_product_id', $productId);
             $redirectRoute = $this->router->generate('formalibre_support_credits_products_purchase');
             $this->session->set('redirect_route', $redirectRoute);
             $route = $this->router->generate('claro_security_login', array());
             return new RedirectResponse($route);
         }
         $product = $this->productManager->getProductById($productId);
         if (is_null($product)) {
             return new RedirectResponse($this->router->generate('formalibre_support_credits_products_purchase_form'));
         }
         $priceSolutions = $product->getPriceSolutions();
         $priceSolution = $priceSolutions[0];
         $order = new Order();
         $chart = new Chart();
         $order->setChart($chart);
         $order->setProduct($product);
         $chart->setOwner($user);
         $chart->setIpAdress($_SERVER['REMOTE_ADDR']);
         $order->setPriceSolution($priceSolution);
         $order->setChart($chart);
         $this->om->persist($chart);
         $this->om->persist($order);
         $this->om->flush();
         return new RedirectResponse($this->router->generate('chart_payment_confirm', array('chart' => $chart->getId()), true));
         //            return new RedirectResponse(
         //                $this->router->generate('formalibre_support_credits_products_purchase_thanks')
         //            );
     } else {
         return new RedirectResponse($this->router->generate('formalibre_support_credits_products_purchase_form'));
     }
 }
 public function addRemoteWorkspaceExpDate(Order $order)
 {
     $sws = $order->getSharedWorkspace();
     $user = $sws->getOwner();
     $monthDuration = $order->getPriceSolution()->getMonthDuration();
     $product = $order->getProduct();
     $details = $product->getDetails();
     $workspace = $this->getWorkspaceData($sws);
     $expDate = \DateTime::createFromFormat(\DateTime::ATOM, $workspace['endDate']);
     $now = new \DateTime();
     if ($now->getTimeStamp() > $expDate->getTimeStamp()) {
         $expDate = $now;
     }
     $interval = new \DateInterval("P{$monthDuration}M");
     $expDate->add($interval);
     $workspaceType = new WorkspaceType();
     $workspaceType->enableApi();
     $form = $this->formFactory->create($workspaceType);
     $payload = $this->apiManager->formEncode($workspace, $form, $workspaceType);
     $payload['workspace_form[endDate]'] = $expDate->format('d-m-Y');
     $url = 'api/workspaces/' . $sws->getRemoteId() . '/users/' . $user->getUsername() . '.json';
     $serverOutput = $this->apiManager->url($this->targetFriend, $url, $payload, 'PUT');
     $workspace = json_decode($serverOutput, true);
     //add date here
     if ($workspace === null || isset($workspace['errors'])) {
         $this->handleError($sws, $serverOutput, $url);
     }
     if (array_key_exists('id', $workspace)) {
         $updatedDate = new \DateTime();
         $updatedDate->setTimeStamp($expDate->getTimeStamp());
         $sws->setExpDate($updatedDate);
         $this->om->persist($sws);
         $this->om->flush();
         return $sws;
     }
     $this->handleError($sws, $serverOutput, $url);
 }
 /**
  * @EXT\Route(
  *      "/free_test/{product}",
  *      name="formalibre_free_test_workspace"
  * )
  * @return Response
  */
 public function createFreeTestWorkspace(Product $product)
 {
     if (!$this->authorization->isGranted('ROLE_USER')) {
         $redirectRoute = $this->router->generate('formalibre_free_test_workspace', array('product' => $product->getId()));
         $this->session->set('redirect_route', $redirectRoute);
         $route = $this->router->generate('claro_security_login', array());
         return new RedirectResponse($route);
     }
     $user = $this->tokenStorage->getToken()->getUser();
     if (!$this->sharedWorkspaceManager->hasFreeTestMonth($user)) {
         $content = $this->renderView('FormaLibreInvoiceBundle:errors:freeTestMonthUsedException.html.twig');
         return new Response($content);
     }
     $chart = new Chart();
     $ps = $this->productManager->getPriceSolution($product, 1);
     $order = new Order();
     $chart->setOwner($user);
     $chart->setIpAdress($_SERVER['REMOTE_ADDR']);
     $order->setPriceSolution($ps);
     $order->setProduct($product);
     $chart->addOrder($order);
     $order->setChart($chart);
     $this->em->persist($order);
     $this->em->persist($chart);
     $this->sharedWorkspaceManager->useFreeTestMonth($user);
     $invoice = $this->invoiceManager->create($chart, 'free');
     $this->invoiceManager->validate($invoice);
     $invoice->setPaymentSystemName('none');
     $this->em->persist($invoice);
     $this->em->flush();
     return new RedirectResponse($this->router->generate('claro_desktop_open', array()));
 }