<?php
/**
* Created by PhpStorm.
*/
namespace App\Controller\Front\AbonnementPro;
use App\Entity\Abonnement;
use App\Entity\AbonnementPay;
use App\Entity\AbonnementPro;
use App\Entity\BlockPageAbonnementPro;
use App\Entity\CompteAbonnementPro;
use App\Entity\FaqB2b;
use App\Entity\Product;
use App\Services\AbonnementService;
use App\Services\CartService;
use App\Services\CheckoutService;
use App\Services\FactureService;
use App\Services\Notifications;
use App\Services\OrderService;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Twig\Environment;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Services\Liseuse;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use App\Services\Compte;
class IndexController extends AbstractController
{
private $em;
private $session;
private $params;
private $cart_service;
private $abonnement_service;
private $facture_service;
private $notifications;
private $compte;
public function __construct(Compte $compte,Notifications $notifications,FactureService $factureService,AbonnementService $abonnement_service, OrderService $order_service ,CheckoutService $checkout_service,CartService $cart_service,SessionInterface $session,AuthenticationUtils $authenticationUtils , EntityManagerInterface $em,ParameterBagInterface $params)
{
$this->em = $em;
$this->session = $session;
$this->params = $params;
$this->cart_service = $cart_service;
$this->checkout_service = $checkout_service;
$this->authenticationUtils = $authenticationUtils;
$this->order_service = $order_service;
$this->abonnement_service = $abonnement_service ;
$this->facture_service = $factureService ;
$this->notifications = $notifications ;
$this->compte = $compte ;
}
/**
* @Route("/abonnement-pro/", name="abonnementPro_index")
*/
public function index(Request $request) : Response
{
$abonnement = $this->cart_service->checkIsAbonnementPro($this->getUser());
$myAbonnement = false;
if($abonnement['is_abonnemen_pro']) {
if (($abonnement['is_abonnemen_pro'] && isset($abonnement['is_admin']) && $abonnement['is_admin'])) {
$myAbonnement = $abonnement['compte_abonnement_object'];
}
}
// $response = $this->render('front/abonnement-pro/landing-page.html.twig',
$response = $this->render('front/abonnement-pro/landing-page-2.html.twig',
[
'myAbonnement'=>$myAbonnement,
'faqs' => $this->em->getRepository(FaqB2b::class)->findActive(),
'blockPageAbonnementPro' => $this->em->getRepository(BlockPageAbonnementPro::class)->findOneBy([])
]);
return $response;
}
/**
* @Route("/abonnement-pro/offre", name="abonnementPro_offre")
*/
public function offrePage(Request $request) : Response
{
return $this->redirectToRoute('abonnementPro_adresse_facture',['typeAbonnement'=>AbonnementPro::TYPE_TEAM,'typeComptePaiement'=>1,'isFree'=>1]);
// $response = $this->render('front/abonnement-pro/offre-page.html.twig');
// return $response;
}
/**
* @Route("/abonnement-pro/edit-abonnement-to-cart/{typeAbonnement}-{typePay}", name="edit_abonnement_in_cart",options={"expose"=true})
*/
public function editAbonnementCart(Request $request, $typeAbonnement,$typePay): Response
{
$cart = $this->cart_service->getCartCurrent();
$abonnement = $this->em->getRepository(AbonnementPro::class)->findOneBy(array('typeAbonnement'=>$typeAbonnement));
$abonnementProCart = $cart->getAbonnementProCart();
if($abonnementProCart){
$abonnementProCart->setAbonnement($abonnement);
$abonnementProCart->setCart($cart);
$abonnementProCart->setAdmin($cart->getCustomer());
if($abonnementProCart->getPrixTtc() == 0){
$abonnementProCart->setTypeComptePaiement(CompteAbonnementPro::PAIEMENT_MENSUEL);
$abonnementProCart->setPrixHt(0);
$abonnementProCart->setPrixTtc(0);
}else{
$abonnementProCart->setTypeComptePaiement($typePay);
if ($typePay == CompteAbonnementPro::PAIEMENT_MENSUEL) {
$abonnementProCart->setPrixHt($abonnement->getPrixMensuelHt());
$abonnementProCart->setPrixTtc($abonnement->getPrixMensuelTtc());
}else{
$abonnementProCart->setPrixHt($abonnement->getPrixAnnuelHt());
$abonnementProCart->setPrixTtc($abonnement->getPrixAnnuelTtc());
}
}
$this->em->persist($abonnementProCart);
$this->em->flush();
$cart = $this->cart_service->updatePriceCart($cart); // update price cart
}
//return
$user = $this->getUser();
$abonnementPro = $this->cart_service->checkAbonnementToCartOrOrder($user,$cart->getId());
$blockProductPanier = $this->render('front/checkout/blockPanierMultiple.html.twig', array(
'cart' => $cart,
'abonnementPro' => $abonnementPro
));
return $blockProductPanier;
}
/**
* @Route("/tarif-abonnement", name="tarif_abonnement_page")
*/
public function tarif(Request $request) : Response
{
$response = $this->render('page/tarif-abonnement.html.twig');
return $response;
}
/**
* @Route("/newazaza", name="azezessssszzaze")
*/
public function indqsdex(Request $request) : Response
{
$response = $this->render('front/b2b/index.html.twig');
return $response;
}
}