<?php
namespace App\Controller;
use App\Entity\Log;
use App\Entity\ProcessStep;
use App\Entity\StepStatus;
use App\Repository\StepStatusRepository;
use Doctrine\ORM\EntityManagerInterface;
use Knp\Snappy\Pdf;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mercure\PublisherInterface;
use Symfony\Component\Mercure\Update;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
class HomeController extends ConsoleController
{
/**
* @var Pdf
*/
private $kpnsnappy;
/**
* @var LoggerInterface
*/
private $logger;
public function __construct(
Pdf $kpnsnappy,
EntityManagerInterface $em,
LoggerInterface $logger,
MessageBusInterface $bus
)
{
parent::__construct($em,$bus);
$this->kpnsnappy = $kpnsnappy;
$this->logger = $logger;
}
/**
* @return Response
* @Route("/", name="public.index")
*/
public function PagePublicIndex(): Response
{
return ($this->redirectToRoute('private.index'));
}
/**
* @param Request $request
* @return Response
* @Route("/review/render.html", name="public.review.render")
*/
public function PagePublicReviewRender(Request $request): Response
{
//dump($request->query->get('coucou'));
if(($request->query->get('style') == null) || !is_numeric($request->query->get('style')))
$style = "default.css";
else
$style = $request->query->get('style') . ".css";
return $this->render('pages/public/review/render2.html.twig',[
'this' => $this,
'rav' => $this->reviewRepository->findXXlastBySite(5,4,"AVIS-VERIFIES"),
'rmn' => $this->reviewRepository->findXXlastBySite(5,4,"MARIAGE.NET"),
'rf' => $this->reviewRepository->findXXlastBySite(5,4,"FACEBOOK"),
'rg' => $this->reviewRepository->findXXlastBySite(5,4,"GOOGLE"),
]);
}
/**
* @return Response
* @Route("/private/", name="private.index")
*/
public function PagePrivateIndex(): Response
{
$Postes = new PostesController($this->em,$this->bus);
$moisStart = new \DateTime();
$moisEnd = new \DateTime();
$lastmonthStart = new \DateTime('first day of last month');
$lastmonthEnd = new \DateTime('last day of last month');
$Stats["CA_WEB_TODAY"] = $this->orderRepository->findStatCA($this->showroomRepository->find(1))["total"];
$Stats["CA_WEB_MONTH"] = $this->orderRepository->findStatCA($this->showroomRepository->find(1),$moisStart->format('Y-m-01'),$moisEnd->format('Y-m-t'))["total"];
$Stats["CA_WEB_MONTH_1"] = $this->orderRepository->findStatCA($this->showroomRepository->find(1),$lastmonthStart->format('Y-m-01'),$lastmonthEnd->format('Y-m-t'))["total"];
// print date('m');
for ($i = 1; $i <= 30+date('m')-1; $i++) {
$months[] = date("Y-m", strtotime( date( 'Y-m-01' )." -$i months"));
}
$Stats["ByMonth"][$i]["CA"] = /*random_int(15000,25000);*/$Stats["CA_WEB_MONTH"];
$Stats["ByMonth"][$i]["Date"] = date("Y-m", strtotime( date( 'Y-m-01' )));
$i = 1;
foreach($months as $month){
$start = new \DateTime($month."-01");
$Stats["ByMonth"][$i]["CA"] = $this->orderRepository->findStatCA($this->showroomRepository->find(1),$start->format('Y-m-01'),$start->format('Y-m-t'))["total"];
//$Stats["ByMonth"][$i]["CA"] = random_int(15000,25000);
$Stats["ByMonth"][$i]["Date"] = $month;
$i++;
}
dump($Stats["ByMonth"]);
return $this->render('pages/private/index.html.twig',[
'this' => $this,
'Stats' => $Stats,
'postes' => $Postes->getAllPostesArray()
]);
}
/**
* @return Response
* @Route("/private/test/index.html", name="private.test.index")
*/
public function PagePrivateTestIndex(PublisherInterface $publisher): Response
{
return new Response('published!');
}
/**
* @Route("/private/invoice.pdf", name="private.test.invoice")
*/
public function PageTestInvoice(): Response
{
$invoice = new InvoicePrinterController("A4","€","fr");
/* Header Settings */
$invoice->setLogo('images/logoFacture.png',300,150);
$invoice->setColor('#AA3939');
$invoice->setType('FACTURE');
$invoice->setReference('INV-55033645');
$invoice->setDate(date('d/m/Y', time()));
$invoice->setDue(date('d/m/Y', strtotime('+3 months')));
$invoice->setFrom(['Seller Name', 'Sample Company Name', '128 AA Juanita Ave', 'Glendora , CA 91740', 'United States of America']);
$invoice->setTo(['Purchaser Name', 'Sample Company Name', '128 AA Juanita Ave', 'Glendora , CA 91740', 'United States of America']);
/* Adding Items in table */
$invoice->addItem('AMD Athlon X2DC-7450', '2.4GHz/1GB/160GB/SMP-DVD/VB', 6, 0, 580, 0, 3480);
$invoice->addItem('PDC-E5300', '2.6GHz/1GB/320GB/SMP-DVD/FDD/VB', 4, 0, 645, 0, 2580);
$invoice->addItem('LG 18.5" WLCD', '2.4GHz/1GB/160GB/SMP-DVD/VB', 10, 0, 230, 0, 2300);
$invoice->addItem('HP LaserJet 5200', '2.4GHz/1GB/160GB/SMP-DVD/VB', 1, 0, 1100, 0, 1100);
/* Add totals */
$invoice->addTotal('Total', 9460);
$invoice->addTotal('TVA 20%', 1986.6);
$invoice->addTotal('Total due', 11446.6, true);
/* Set badge */
$invoice->addBadge('Invoice Copy');
$invoice->addBadge('Invoice Copy 2');
/* Add title */
$invoice->addTitle('Important Notice');
/* Add Paragraph */
$invoice->addParagraph("No item will be replaced or refunded if you don't have the invoice with you. You can refund within 2 days of purchase.");
$invoice->addTitle('Important Notice');
/* Add Paragraph */
$invoice->addParagraph("No item will be replaced or refunded if you don't have the invoice with you. You can refund within 2 days of purchase.");
/* Set footer note */
$invoice->setFooternote('My Company Name Here');
/* Render */
$invoice->render('example2.pdf', 'I'); /* I => Display on browser, D => Force Download, F => local path save, S => return document path */
exit();
//return new BinaryFileResponse($invoice->render('example2.pdf', 'S'));
}
}