Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

50 lines
2.1KB

  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\StreamedResponse;
  13. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  14. use Symfony\Component\Security\Core\Security;
  15. use Symfony\Contracts\Translation\TranslatorInterface;
  16. class DocumentController extends AdminController
  17. {
  18. protected $documentRepository ;
  19. public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, MailjetTransport $mailjetTransport, UtilsManager $utilsManager, TranslatorInterface $translator)
  20. {
  21. parent::__construct($security, $userManager, $em, $mailjetTransport, $utilsManager, $translator);
  22. $this->documentRepository = $this->em->getRepository($this->em->getClassMetadata(DocumentInterface::class)->getName()) ;
  23. }
  24. public function downloadInvoiceAction()
  25. {
  26. $idDocument = $this->request->get('id') ;
  27. $document = $this->documentRepository->find($idDocument) ;
  28. $orderShop = null ;
  29. if($document) {
  30. $orderShops = $document->getOrderShops() ;
  31. $orderShop = (isset($orderShops[0])) ? $orderShops[0] : null ;
  32. }
  33. if($document && $orderShop) {
  34. return new StreamedResponse(function () use ($orderShop) {
  35. $this->orderUtils->generateDocumentInvoiceOrderShop($orderShop, 'download') ;
  36. });
  37. }
  38. else {
  39. throw new NotFoundHttpException('Document introuvable') ;
  40. }
  41. }
  42. }