46 líneas
1.9KB

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