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