src/Controller/CashBox/ImageController.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Controller\CashBox;
  3. use App\Entity\FiskalyTransaction;
  4. use App\Entity\Product;
  5. use App\Entity\Receipt;
  6. use Endroid\QrCode\Builder\BuilderInterface;
  7. use Endroid\QrCode\Writer\PngWriter;
  8. use Endroid\QrCodeBundle\Response\QrCodeResponse;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  13. class ImageController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/cashboximage/{id}", name="cash_box_image")
  17.      */
  18.     public function index(Product $product): Response
  19.     {
  20.         if ($product->getImage() !== null && file_exists($this->getParameter('kernel.project_dir') . '/public/uploads/logo/' $product->getImage())) {
  21.             return new BinaryFileResponse($this->getParameter('kernel.project_dir') . '/public/uploads/logo/' $product->getImage());
  22.         } else {
  23.             return new BinaryFileResponse($this->getParameter('kernel.project_dir') . '/public/uploads/logo/noimage.png');
  24.         }
  25.     }
  26.     /**
  27.      * @Route("/receiptqrcode/{id}", name="receiptqrcode_image")
  28.      */
  29.     public function receiptQrCode(Receipt $receiptBuilderInterface $builderPngWriter $pngWriter): ?QrCodeResponse
  30.     {
  31.         $qr_code_data "";
  32.         /**
  33.          * @var FiskalyTransaction $fiskaly_transaction
  34.          */
  35.         $fiskaly_transaction $receipt->getFiskalyTransactions()->last();
  36.         if ($fiskaly_transaction !== null && $fiskaly_transaction !== false && $fiskaly_transaction->getQrCodeData() !== null) {
  37.             $qr_code_data $fiskaly_transaction->getQrCodeData();
  38.             // Pixel = dpi * mm / 25.4 mm
  39.             $pixel_to_mm_factor 25.4;
  40.             $max_paper_mm 50// 80mm receipt
  41.             $printer_dpi 203//most default Thermal-Printer dpi
  42.             $size $printer_dpi $max_paper_mm $pixel_to_mm_factor;
  43.             $result $builder
  44.                 ->writer($pngWriter)
  45.                 ->size($size)
  46.                 ->margin(0)
  47.                 ->data($qr_code_data)
  48.                 ->build();
  49.             return new QrCodeResponse($result);
  50.         }
  51.         return null;
  52.     }
  53. }