EcommerceBundle/Controller/InvoiceController.php
public function showAction(Request $request, $id)
    {
        $em = $this->getDoctrine()->getManager();

        /** @var Invoice $entity */
        $invoice = $em->getRepository('EcommerceBundle:Invoice')->find($id);

        if (!$invoice) {
            throw $this->createNotFoundException('Unable to find Invoice entity.');
        }

        // download invoice
        if (!$invoice ||
            false === $this->container->get('checkout_manager')->isCurrentUserOwner($invoice->getTransaction())) {
            throw new AccessDeniedException();
        }

        /** @var CheckoutManager $checkoutManager */
        $checkoutManager = $this->container->get('checkout_manager');

        $delivery = $invoice->getTransaction()->getDelivery();
        $totals = $checkoutManager->calculateTotals($invoice->getTransaction(), $delivery);
        if ('true' === $request->get('download')) {
            $html = $this->container->get('templating')->render('EcommerceBundle:Profile:Invoice/download.html.twig', array(
                    'delivery' => $delivery,
                    'invoice'  => $invoice,
                    'totals'   => $totals,
                ));
            $html2pdf = $this->get('html2pdf_factory')->create();
            $html2pdf->WriteHTML($html);
            
            return new Response(
                $html2pdf->Output('invoice'.$invoice->getInvoiceNumber().'.pdf'),
                200,
                array(
                    'Content-Type'        => 'application/pdf',
                    'Content-Disposition' => 'attachment; filename="invoice'.$invoice->getInvoiceNumber().'.pdf"'
                )
            );
        }
        
       
        return array(
            'entity' => $invoice,
            'totals' => $totals,
        );
    }
public function showAction(Request $request, $id)
    {
        $em = $this->getDoctrine()->getManager();

        /** @var Invoice $entity */
        $invoice = $em->getRepository('EcommerceBundle:Invoice')->find($id);

        if (!$invoice) {
            throw $this->createNotFoundException('Unable to find Invoice entity.');
        }

        // download invoice
        if (!$invoice ||
            false === $this->container->get('checkout_manager')->isCurrentUserOwner($invoice->getTransaction())) {
            throw new AccessDeniedException();
        }

        /** @var CheckoutManager $checkoutManager */
        $checkoutManager = $this->container->get('checkout_manager');

        $delivery = $invoice->getTransaction()->getDelivery();
        $totals = $checkoutManager->calculateTotals($invoice->getTransaction(), $delivery);
        if ('true' === $request->get('download')) {
            $html = $this->container->get('templating')->render('EcommerceBundle:Profile:Invoice/download.html.twig', array(
                    'delivery' => $delivery,
                    'invoice'  => $invoice,
                    'totals'   => $totals,
                ));
            $html2pdf = $this->get('html2pdf_factory')->create();
            $html2pdf->WriteHTML($html);
            
            return new Response(
                $html2pdf->Output('invoice'.$invoice->getInvoiceNumber().'.pdf'),
                200,
                array(
                    'Content-Type'        => 'application/pdf',
                    'Content-Disposition' => 'attachment; filename="invoice'.$invoice->getInvoiceNumber().'.pdf"'
                )
            );
        }
        
       
        return array(
            'entity' => $invoice,
            'totals' => $totals,
        );
    }
public function showAction ( Request $ request , $ id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; /** @var Invoice $entity */ $ invoice = $ em -> getRepository ( 'EcommerceBundle:Invoice' ) -> find ( $ id ) ; if ( ! $ invoice ) { throw $ this -> createNotFoundException ( 'Unable to find Invoice entity.' ) ; } // download invoice if ( ! $ invoice || false === $ this -> container -> get ( 'checkout_manager' ) -> isCurrentUserOwner ( $ invoice -> getTransaction ( ) ) ) { throw new AccessDeniedException ( ) ; } /** @var CheckoutManager $checkoutManager */ $ checkoutManager = $ this -> container -> get ( 'checkout_manager' ) ; $ delivery = $ invoice -> getTransaction ( ) -> getDelivery ( ) ; $ totals = $ checkoutManager -> calculateTotals ( $ invoice -> getTransaction ( ) , $ delivery ) ; if ( 'true' === $ request -> get ( 'download' ) ) { $ html = $ this -> container -> get ( 'templating' ) -> render ( 'EcommerceBundle:Profile:Invoice/download.html.twig' , array ( 'delivery' => $ delivery , 'invoice' => $ invoice , 'totals' => $ totals , ) ) ; $ html2pdf = $ this -> get ( 'html2pdf_factory' ) -> create ( ) ; $ html2pdf -> WriteHTML ( $ html ) ; return new Response ( $ html2pdf -> Output ( 'invoice' . $ invoice -> getInvoiceNumber ( ) . '.pdf' ) , 200 , array ( 'Content-Type' => 'application/pdf' , 'Content-Disposition' => 'attachment; filename="invoice' . $ invoice -> getInvoiceNumber ( ) . '.pdf"' ) ) ; } return array ( 'entity' => $ invoice , 'totals' => $ totals , ) ; }
Finds and displays an Invoice entity.

@param int $id The entity id

@throws NotFoundHttpException
@return array

@Route("/{id}")
@Method("GET")
@Template()
Finds and displays an Invoice entity .