Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

52 rindas
2.2KB

  1. <?php
  2. namespace Lc\ShopBundle\Controller\Backend;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use FOS\UserBundle\Model\UserManagerInterface;
  5. use Lc\ShopBundle\Context\DocumentInterface;
  6. use Lc\ShopBundle\Context\MerchantUtilsInterface;
  7. use Lc\ShopBundle\Context\OrderUtilsInterface;
  8. use Lc\ShopBundle\Services\Utils;
  9. use Lc\ShopBundle\Services\UtilsManager;
  10. use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
  11. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  12. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  13. use Symfony\Component\HttpFoundation\StreamedResponse;
  14. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  15. use Symfony\Component\Security\Core\Security;
  16. use Symfony\Contracts\Translation\TranslatorInterface;
  17. class DocumentController extends AdminController
  18. {
  19. protected $documentRepository ;
  20. public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, MailjetTransport $mailjetTransport, UtilsManager $utilsManager, TranslatorInterface $translator, SessionInterface $session)
  21. {
  22. parent::__construct($security, $userManager, $em, $mailjetTransport, $utilsManager, $translator, $session);
  23. $this->documentRepository = $this->em->getRepository($this->em->getClassMetadata(DocumentInterface::class)->getName()) ;
  24. }
  25. public function downloadInvoiceAction()
  26. {
  27. $idDocument = $this->request->get('id') ;
  28. $document = $this->documentRepository->find($idDocument) ;
  29. $orderShop = null ;
  30. if($document) {
  31. $orderShops = $document->getOrderShops() ;
  32. $orderShop = (isset($orderShops[0])) ? $orderShops[0] : null ;
  33. }
  34. if($document && $orderShop) {
  35. return new StreamedResponse(function () use ($orderShop) {
  36. $this->orderUtils->generateDocumentInvoiceOrderShop($orderShop, 'download') ;
  37. });
  38. }
  39. else {
  40. throw new NotFoundHttpException('Document introuvable') ;
  41. }
  42. }
  43. }