src/Controller/IndexController.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Company;
  4. use App\Entity\CompanyGroup;
  5. use App\Entity\Product;
  6. use App\Form\Filter\AppGraphFilterType;
  7. use App\Repository\CompanyRepository;
  8. use App\Repository\OrderRepository;
  9. use App\Repository\ProductRepository;
  10. use App\Services\GalosoftGraphsFactory;
  11. use App\Services\GalosoftMailer;
  12. use App\Services\GalosoftMailerInterface;
  13. use Gotenberg\Gotenberg;
  14. use Gotenberg\Stream;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\HttpFoundation\Session\Session;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. class IndexController extends AbstractController
  21. {
  22.     const DASHBOARD_COLUMN 'dashboard_column';
  23.     const DASHBOARD_DATEFROM 'dashboard_datefrom';
  24.     const DASHBOARD_DATETO 'dashboard_dateto';
  25.     /**
  26.      * @Route("/", name="app_homepage")
  27.      */
  28.     public function index(
  29.         Session $session,
  30.         CompanyRepository $companyRepository,
  31.         GalosoftGraphsFactory $galosoftGraphsFactory,
  32.         OrderRepository $orderRepository
  33.     ): Response
  34.     {
  35.         $selectedColumn $session->get(self::DASHBOARD_COLUMN3);
  36.         $dateFrom $session->get(self::DASHBOARD_DATEFROM, new \DateTime('now-12months'));
  37.         $dateTo $session->get(self::DASHBOARD_DATETO, new \DateTime('now'));
  38.         $qb $companyRepository->createQueryBuilder('qc');
  39.         $qb->leftJoin('qc.companyFiles''companyFiles');
  40.         $qb->andWhere($qb->expr()->isInstanceOf('qc'CompanyGroup::class));
  41.         //$qb->andWhere($qb->expr()->neq('companyFiles.showOnWebsite', false));
  42.         $companies $qb->getQuery()->getResult();
  43.         // CURRENT USER
  44.         $graphMyProduction $galosoftGraphsFactory->create();
  45.         $gmp $galosoftGraphsFactory->createLine();
  46.         if($this->isGranted('ROLE_COMPANY_ADMIN') || $this->isGranted('ROLE_COMPANY_USER')){
  47.             // company admin
  48.             $dataMyProduction $orderRepository->ordersByCompanyGroupByDays($dateFrom$dateTo$this->getUser(), $selectedColumn);
  49.         }elseif ($this->isGranted('ROLE_MERCHANT')){
  50.             // merchant
  51.             $dataMyProduction $orderRepository->orderCountByDays($dateFrom$dateTo$this->getUser(), $selectedColumn);
  52.         }
  53.         foreach ($dataMyProduction as $row) {
  54.             $gmp->createPoint($row['den'], $row['total']);
  55.         }
  56.         $graphMyProduction->addLine($gmp);
  57.         // BY Companies
  58.         $graphMyProductionByCompanies $galosoftGraphsFactory->create();
  59.         $dataMyProduction $orderRepository->orderCountByCompaniesByDays($dateFrom$dateTo$this->getUser(), $selectedColumn);
  60.         $lines = [];
  61.         foreach ($dataMyProduction as $row) {
  62.             if(!isset($lines[$row['company_group_id']])){
  63.                 $lines[$row['company_group_id']] = $galosoftGraphsFactory->createLine($row['company_label']);
  64.             }
  65.             $lines[$row['company_group_id']]->createPoint($row['den'], $row['total']);
  66.         }
  67.         foreach ($lines as $line) {
  68.             $graphMyProductionByCompanies->addLine($line);
  69.         }
  70.         // BY EMITENTS
  71.         $graphMyProductionByProducts $galosoftGraphsFactory->create();
  72.         if($this->isGranted('ROLE_COMPANY_ADMIN') || $this->isGranted('ROLE_COMPANY_USER')){
  73.             // comapny admin
  74.             $dataMyProduction $orderRepository->orderByCompanyGroupByProductsByDays($dateFrom$dateTo$this->getUser(), $selectedColumn);
  75.         }elseif($this->isGranted('ROLE_MERCHANT')){
  76.             // merchant
  77.             $dataMyProduction $orderRepository->orderCountByProductsByDays($dateFrom$dateTo$this->getUser(), $selectedColumn);
  78.         }
  79.         $lines = [];
  80.         foreach ($dataMyProduction as $row) {
  81.             if(!isset($lines[$row['product_id']])){
  82.                 $lines[$row['product_id']] = $galosoftGraphsFactory->createLine($row['product_label']);
  83.             }
  84.             $lines[$row['product_id']]->createPoint($row['den'], $row['total']);
  85.         }
  86.         foreach ($lines as $line) {
  87.             $graphMyProductionByProducts->addLine($line);
  88.         }
  89.         $graphMyProductionByNetworks $galosoftGraphsFactory->create();
  90.         $dataOtherProduction $orderRepository->orderByAffilCode($dateFrom$dateTo$this->getUser(), $selectedColumn);
  91.         $filter $this->createForm(AppGraphFilterType::class);
  92.         return $this->render('index/emitents.html.twig', [
  93.             'companies' => $companies,
  94.             'graphMyProduction' => $graphMyProduction,
  95.             'graphMyProductionByCompanies' => $graphMyProductionByCompanies,
  96.             'graphMyProductionByProducts' => $graphMyProductionByProducts,
  97.             'graphMyProductionByNetworks' => $graphMyProductionByNetworks,
  98.             'tableOtherProduction' => $dataOtherProduction,
  99.             'selectedColumn' => $selectedColumn,
  100.             'dateFrom' => $dateFrom->format('j.n.Y'),
  101.             'dateTo' => $dateTo->format('j.n.Y'),
  102.             'form' => $filter->createView()
  103.         ]);
  104.     }
  105.     /**
  106.      * @Route("/dashboard/settings", name="app_dashboard_settings")
  107.      */
  108.     public function saveDashboardColumn(Request $requestSession $session){
  109.         $dashboardColumn $request->request->get('dashboard_column');
  110.         $appGraphFilter $request->request->get('app_graph_filter');
  111.         $session->set(self::DASHBOARD_COLUMN$dashboardColumn);
  112.         $session->set(self::DASHBOARD_DATEFROM\DateTime::createFromFormat('j.n.Y'$appGraphFilter['dateFrom']));
  113.         $session->set(self::DASHBOARD_DATETO\DateTime::createFromFormat('j.n.Y'$appGraphFilter['dateTo']));
  114.         return $this->forward(IndexController::class. '::index');
  115.     }
  116.     /**
  117.      * @Route("/emitent/{emitent}", name="app_emitent_detail")
  118.      */
  119.     public function emitentDetail(
  120.         Company $emitent,
  121.         ProductRepository $productRepository,
  122.         CompanyRepository $companyRepository
  123.     ): Response
  124.     {
  125.         $companyIds = [$emitent->getId()];
  126.         $companies $companyRepository->findBy(['companyGroup' => $emitent->getId()]);
  127.         foreach ($companies as $company) {
  128.             $companyIds[] = $company->getId();
  129.         }
  130.         $qbpr $productRepository->createQueryBuilder('pr');
  131.         $qbpr
  132.             ->andWhere($qbpr->expr()->gt('pr.webOrder'0))
  133.             ->andWhere($qbpr->expr()->isNotNull('pr.webOrder'))
  134.             ->andWhere($qbpr->expr()->in('pr.company'$companyIds))
  135.             ->addOrderBy('pr.webOrder''ASC');
  136.         $products $qbpr->getQuery()->getResult();
  137.         return $this->render('index/emitent.html.twig', [
  138.             'emitent' => $emitent,
  139.             'products' => $products
  140.         ]);
  141.     }
  142.     /**
  143.      * @Route("/kontakty", name="app_index_kontakty")
  144.      */
  145.     public function kontakty(){
  146.         $bossUsers $this->getUser()->getBosses();
  147.         return $this->render('index/contact.html.twig', [
  148.             'bossRelationFirstLine' => $bossUsers
  149.         ]);
  150.     }
  151.     /**
  152.      * @Route("/eshop-bak", name="app_index_eshop")
  153.      */
  154.     public function eshop(){
  155.         return $this->render('index/eshop.html.twig');
  156.     }
  157.     /**
  158.      * @Route("/basket-1", name="app_index_basket_1")
  159.      */
  160.     public function basket1(){
  161.         return $this->render('index/basket1.html.twig');
  162.     }
  163.     /**
  164.      * @Route("/basket-2", name="app_index_basket_2")
  165.      */
  166.     public function basket2(){
  167.         return $this->render('index/basket2.html.twig');
  168.     }
  169.     /**
  170.      * @Route("/basket-3", name="app_index_basket_3")
  171.      */
  172.     public function basket3(){
  173.         return $this->render('index/basket3.html.twig');
  174.     }
  175.     /**
  176.      * @Route("/basket-4", name="app_index_basket_4")
  177.      */
  178.     public function basket4(){
  179.         return $this->render('index/basket4.html.twig');
  180.     }
  181.     /**
  182.      * @Route("/basket-5", name="app_index_basket_5")
  183.      */
  184.     public function basket5(){
  185.         return $this->render('basket/basket5.html.twig');
  186.     }
  187.     /**
  188.      * @Route("/kalendar-akci", name="app_index_calendar")
  189.      */
  190.     public function calendar(){
  191.         return $this->render('index/calendar.html.twig');
  192.     }
  193.     /**
  194.      * @Route("/invoice", name="app_index_invoice")
  195.      */
  196.     public function invoice(GalosoftMailerInterface $mailer){
  197.         $data = [
  198.             "id" => "123",
  199.             "variable" => "123",
  200.             "issued" => date("j.n.Y"strtotime("10.8.2023")),
  201.             "due" => date("j.n.Y"strtotime("12.8.2023")),
  202.             "name" => "ABC s.r.o.",
  203.             "surname" => "",
  204.             "street" => "Ulice 123",
  205.             "postal" => "123 00",
  206.             "town" => "Město",
  207.             "ic" => "123456789",
  208.             "dic" => "CZ123456789",
  209.             "totalPriceExclVat" => number_format(2002","" "),
  210.             "totalPriceVat" => number_format(422","" "),
  211.             "totalPriceInclVat" => number_format(2422","" "),
  212.             "items" => [
  213.                 => [
  214.                     "name" => "Zlatý slitek 1 Oz Argor Heraeus",
  215.                     "count" => number_format(1,0""""),
  216.                     "vat" => number_format(210""""),
  217.                     "priceExclVat" => number_format(1002","" "),
  218.                     "priceVat" => number_format(212","" "),
  219.                     "priceInclVat" => number_format(1212","" "),
  220.                     "totalPriceExclVat" => number_format(1002","" "),
  221.                     "totalPriceVat" => number_format(212","" "),
  222.                     "totalPriceInclVat" => number_format(1212","" "),
  223.                 ],
  224.                 => [
  225.                     "name" => "Zlatý slitek 1 Oz Argor Heraeus",
  226.                     "count" => number_format(1,0""""),
  227.                     "vat" => number_format(210""""),
  228.                     "priceExclVat" => number_format(1002","" "),
  229.                     "priceVat" => number_format(212","" "),
  230.                     "priceInclVat" => number_format(1212","" "),
  231.                     "totalPriceExclVat" => number_format(1002","" "),
  232.                     "totalPriceVat" => number_format(212","" "),
  233.                     "totalPriceInclVat" => number_format(1212","" "),
  234.                 ]
  235.             ],
  236.         ];
  237.         $urlPreffix '../public/files/temp';
  238.         if (!is_dir($urlPreffix)) mkdir($urlPreffix);
  239.         $html $this->render('index/invoice.html.twig', ["data" => $data])->getContent();
  240.         $request Gotenberg::chromium("gotenberg:3000")
  241.             ->html(Stream::string('my.html',$html));
  242.         $file Gotenberg::save($request$urlPreffix);
  243.         $mailer->send([
  244.             "template_id" => "d-ac95fa387b2f4ab486b4940fa53578ff",
  245.             "from" => array(
  246.                 "name" => "EFS",
  247.                 "email" => "info@efsgroup.cz"
  248.             ),
  249.             "personalizations" => array(
  250.                 array(
  251.                     "dynamic_template_data" => $data,
  252.                     "to" => array(
  253.                         array(
  254.                             "email" => "kohout@galosoft.cz"
  255.                         ),
  256.                     )
  257.                 )
  258.             ),
  259.             "attachments" => [
  260.                 [
  261.                     //TODO - cesta k souboru bude /public/files/contracts/ID/HASH.pdf
  262.                     //TODO - pristup k ni bude take ze zalozky dokumenty v detailu objednavky viz prejmenovani zalozky dle EFS-159
  263.                     "content" => base64_encode(file_get_contents($urlPreffix."/".$file)),
  264.                     "type" => "pdf",
  265.                     "filename" => "Zálohová faktura č." $data["id"] . ".pdf"
  266.                 ]
  267.             ]
  268.         ]);
  269.         return $this->render('index/invoice.html.twig', ["data" => $data]);
  270.     }
  271. }