|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* AbstractOrdersController Méthodes communes InventoryController. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP Version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @author Quétier Laurent <[email protected]> |
|
8
|
|
|
* @copyright 2014 Dev-Int GLSR |
|
9
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
10
|
|
|
* |
|
11
|
|
|
* @version since 1.0.0 |
|
12
|
|
|
* |
|
13
|
|
|
* @link https://github.com/Dev-Int/glsr |
|
14
|
|
|
*/ |
|
15
|
|
|
namespace AppBundle\Controller; |
|
16
|
|
|
|
|
17
|
|
|
use AppBundle\Controller\AbstractController; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
19
|
|
|
|
|
20
|
|
|
use AppBundle\Entity\Orders; |
|
21
|
|
|
use AppBundle\Form\Type\OrdersType; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Abstract controller. |
|
25
|
|
|
* |
|
26
|
|
|
* @category Controller |
|
27
|
|
|
*/ |
|
28
|
|
|
class AbstractOrdersController extends AbstractController |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Create CreateForm. |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $route Route of action form |
|
34
|
|
|
* @return \Symfony\Component\Form\Form |
|
35
|
|
|
*/ |
|
36
|
|
|
protected function createCreateForm($route) |
|
37
|
|
|
{ |
|
38
|
|
|
$orders = new Orders(); |
|
39
|
|
|
return $this->createForm( |
|
40
|
|
|
OrdersType::class, |
|
41
|
|
|
$orders, |
|
42
|
|
|
['attr' => ['id' => 'create'], 'action' => $this->generateUrl($route), 'method' => 'POST',] |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Print a document.<br />Creating a `PDF` file for viewing on paper |
|
48
|
|
|
* |
|
49
|
|
|
* @param \AppBundle\Entity\Orders $orders Order item to print |
|
50
|
|
|
* @param string $from The Controller who call this action |
|
51
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
52
|
|
|
*/ |
|
53
|
|
|
protected function abstractPrintAction(Orders $orders, $from) |
|
54
|
|
|
{ |
|
55
|
|
|
$file = $from . '-' . $orders->getId() . '.pdf'; |
|
56
|
|
|
$company = $this->getDoctrine()->getManager()->getRepository('AppBundle:Company')->find(1); |
|
57
|
|
|
// Create and save the PDF file to print |
|
58
|
|
|
$html = $this->renderView( |
|
59
|
|
|
'AppBundle:' . $from . ':print.pdf.twig', |
|
60
|
|
|
['articles' => $orders->getArticles(), 'orders' => $orders, 'company' => $company, ] |
|
61
|
|
|
); |
|
62
|
|
|
return new Response( |
|
63
|
|
|
$this->get('knp_snappy.pdf')->getOutputFromHtml( |
|
64
|
|
|
$html, |
|
65
|
|
|
$this->getArray((string)date('d/m/y - H:i:s'), '') |
|
66
|
|
|
), |
|
67
|
|
|
200, |
|
68
|
|
|
array( |
|
69
|
|
|
'Content-Type' => 'application/pdf', |
|
70
|
|
|
'Content-Disposition' => 'attachment; filename="' . $file . '"' |
|
71
|
|
|
) |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|