<?php
/**
* Created by PhpStorm.
* User: Slim Sayari
* Date: 10/07/2019
* Time: 13:43
*/
namespace App\Controller\Front;
use App\Entity\AbonnementPro;
use App\Entity\Accessoire;
use App\Entity\Adresse;
use App\Entity\Attribut;
use App\Entity\CartDetail;
use App\Entity\CompteAbonnementProCommandesFactures;
use App\Entity\CompteAbonnementProFacture;
use App\Entity\CompteAbonnementProFactureUtilisateur;
use App\Entity\Orders;
use App\Entity\PriceProduct;
use App\Entity\Product;
use App\Entity\ProductAttribute;
use App\Entity\RecapVirement;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
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 Spatie\PdfToImage\Pdf;
use Imagick;
use App\Services\ProductService;
use App\Services\CartService;
use App\Entity\Cart;
class CartController extends AbstractController
{
private $em;
private $liseuse_service;
private $session;
private $params;
private $product_service;
private $cart_service;
public function __construct(SessionInterface $session ,Liseuse $liseuse_service , EntityManagerInterface $em,CartService $cart_service, ProductService $product_service,ParameterBagInterface $params)
{
$this->em = $em;
$this->liseuse_service = $liseuse_service;
$this->session = $session;
$this->params = $params;
$this->product_service = $product_service;
$this->cart_service = $cart_service;
}
/**
* @Route("/panier/block", name="panier_block",options={"expose"=true})
*/
public function getBlock(Request $request) : Response
{
$tokenCart = $this->session->get('token_cart');
$cart = null;
if($tokenCart){
$cart = $this->em->getRepository(Cart::class)->findOneBy(array('token'=>$tokenCart)); // cart
}
//check abonnementPro
$user = $this->getUser();
$cartId = 0;
if($cart)
$cartId = $cart->getId();
$checkPanierVide = $this->cart_service->checkPanierVide($cart);
if($checkPanierVide){
$response = $this->render('front/panier/cart_vide.html.twig');
}else {
$abonnementPro = $this->cart_service->checkAbonnementToCartOrOrder($user, $cartId);
$response = $this->render('front/panier/cart_header.html.twig', [
'cart' => $cart,
'abonnementPro' => $abonnementPro
]);
}
return $response;
}
/**
* @Route("/get-price-panier-abonnement/{tokenCart}-{type}", name="get_price_panier_abonnement",options={"expose"=true})
*/
public function getPricePanierAbonnement(Request $request,$tokenCart,$type) : Response
{
$cart = $this->em->getRepository(Cart::class)->findOneBy(array('token'=>$tokenCart)); // cart
if($type == Adresse::TYPE_COMPTE_ENTREPRISE){
$price = $this->cart_service->gePriceCartWithAbonnementPro( AbonnementPro::TYPE_PRO,$cart);
$prixHt = $price['prixHtTotal'];
$prixTtc = '<span class="contour_jaune">'.$price['prixTtcTotal'].'€</span>';
$textAbonnementCheckoutPanier = 'A partir de 47,99€ /mois, économisez une multifonction et un graphiste! Des coûts d’impressions fixes vous faisant économiser jusqu’à 50%, la livraison illimitée et gratuite, un dashboard partagé pour vos salariés, un prélèvement à 30 jours et une multitude de nouveaux services comme un(e) graphiste dédiée !';
$lien = $this->generateUrl('abonnementPro_offre');
$nameLien = 'Voir nos abonnements pro';
}else{
$price = $this->cart_service->gePriceCartWithAbonnementPlus( $cart);
$prixHt = $price['prixHtTotal'];
$prixTtc = '<span class="contour_jaune">'.$price['prixTtcTotal'].'€</span>';
$textAbonnementCheckoutPanier = 'Pour 4,99€/mois résiliable à tout moment en 1 clic, 10% d’économie sur tous vos achats + livraison gratuite illimitée.';
$lien = $this->generateUrl('checkout_abonnement');
$nameLien = 'Abonnez-vous ';
}
$array = [
'prixHt'=> $prixHt,
'prixTtc'=> $prixTtc,
'textAbonnementCheckoutPanier'=> $textAbonnementCheckoutPanier,
'lien'=> $lien,
'nameLien'=> $nameLien,
];
$response = new Response();
$response->setContent(json_encode($array));
return $response;
}
/**
* @Route("/edit-doc-page-2", name="edit_pdf_page2")
*/
public function editPDFPage2(Request $request) : Response
{
$response = $this->render('front/liseuse-papier/edit-doc-page.html.twig');
return $response;
}
/**
* @Route("/edit-doc-page", name="edit_pdf_page")
*/
public function editPDFPage(Request $request) : Response
{
$response = $this->render('front/liseuse-papier/edit-doc-page-2.html.twig');
return $response;
}
/**
* @Route("/get-invoice-order/{id}/{token}", name="get_invoice_order")
* @IsGranted("ROLE_USER")
*/
public function getInvoiceOrder(Request $request,$id,$token=null) : Response
{
$response = new Response();
if($token){
$order = $this->em->getRepository(Orders::class)->findOneBy(['id' => $id,'tokenOrder' => $token]);
}else{
$order = $this->em->getRepository(Orders::class)->find($id);
if($order && $order->getTokenOrder()){
$response->setContent(0);
return $response;
}
}
if ($order) {
$pathFacture = $this->params->get('uploads_directory') . '/facture/' . $order->getPathFacture();
$response->setContent(file_get_contents($pathFacture));
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-disposition', 'filename=invoice-order.pdf');
$response->setStatusCode(200);
return $response;
}
$response->setContent(0);
return $response;
}
/**
* @Route("/get-invoice-virement/{id}/{token}", name="get_invoice_virement")
* @IsGranted("ROLE_USER")
*/
public function getInvoiceVirement(Request $request,$id,$token=null) : Response
{
$response = new Response();
$response = new Response();
if($token){
$order = $this->em->getRepository(Orders::class)->findOneBy(['id' => $id,'tokenOrder' => $token]);
}else{
$order = $this->em->getRepository(Orders::class)->find($id);
if($order && $order->getTokenOrder()){
$response->setContent(0);
return $response;
}
}
if ($order && $order->getPathFactureVirement()) {
$pathFacture = $this->params->get('uploads_directory') . '/facture/' . $order->getPathFactureVirement();
$response->setContent(file_get_contents($pathFacture));
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-disposition', 'filename=invoice-virement-order.pdf');
$response->setStatusCode(200);
return $response;
}
$response->setContent(0);
return $response;
}
/**
* @Route("/get-invoice-abonnement-pro/{id}-{idCompteAbonnementPro}", name="get_invoice_abonnement_pro")
* @IsGranted("ROLE_USER")
*/
public function getInvoiceAbonnementPro(Request $request,$id,$idCompteAbonnementPro) : Response
{
$facture = $this->em->getRepository(CompteAbonnementProFacture::class)->findOneBy(['id'=>$id,'compteAbonnementPro'=>$idCompteAbonnementPro]);
$response = new Response();
if($facture){
if ($facture->getPathFacture()) {
$pathFacture = $this->params->get('uploads_directory') . '/facture/' . $facture->getPathFacture();
$response->setContent(file_get_contents($pathFacture));
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-disposition', 'filename=invoice-abonnement-pro.pdf');
$response->setStatusCode(200);
return $response;
}
}
$response->setContent(0);
return $response;
}
/**
* @Route("/get-invoice-abonnement-pro-commande/{id}-{idCompteAbonnementPro}", name="get_invoice_abonnement_pro_commande")
* @IsGranted("ROLE_USER")
*/
public function getInvoiceAbonnementProCommande(Request $request,$id,$idCompteAbonnementPro) : Response
{
$facture = $this->em->getRepository(CompteAbonnementProCommandesFactures::class)->findOneBy(['id'=>$id,'compteAbonnementPro'=>$idCompteAbonnementPro]);
$response = new Response();
if($facture){
if ($facture->getPathFacture()) {
$pathFacture = $this->params->get('uploads_directory') . '/facture/' . $facture->getPathFacture();
$response->setContent(file_get_contents($pathFacture));
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-disposition', 'filename=invoice-abonnement-pro-orders.pdf');
$response->setStatusCode(200);
return $response;
}
}
$response->setContent(0);
return $response;
}
/**
* @Route("/get-invoice-abonnement-pro-utilisateur/{id}-{idCompteAbonnementPro}", name="get_invoice_abonnement_pro_utilisateur")
* @IsGranted("ROLE_USER")
*/
public function getInvoiceAbonnementProUtilisateur(Request $request,$id,$idCompteAbonnementPro) : Response
{
$facture = $this->em->getRepository(CompteAbonnementProFactureUtilisateur::class)->findOneBy(['id'=>$id,'compteAbonenemntPro'=>$idCompteAbonnementPro]);
$response = new Response();
if($facture){
if ($facture->getPathFacture()) {
$pathFacture = $this->params->get('uploads_directory') . '/facture/' . $facture->getPathFacture();
$response->setContent(file_get_contents($pathFacture));
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-disposition', 'filename=invoice-abonnement-pro-utilisateur.pdf');
$response->setStatusCode(200);
return $response;
}
}
$response->setContent(0);
return $response;
}
/**
* @Route("/get-recap-virement/{id}", name="get_recap_virement")
* @IsGranted("ROLE_USER")
*/
public function getRecapVirement(Request $request,$id) : Response
{
$order = $this->em->getRepository(RecapVirement::class)->find(['id'=>$id]);
$response = new Response();
if($order && $order->getPdfRecap()){
$pathFacture = $this->params->get('uploads_directory') . '/facture/' .$order->getPdfRecap();
$response->setContent(file_get_contents($pathFacture));
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-disposition', 'filename=recap-virement.pdf');
$response->setStatusCode(200);
return $response;
}
$response->setContent(0);
return $response;
}
}