|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* TvaController controller des taux de T.V.A. |
|
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\Settings\Divers; |
|
16
|
|
|
|
|
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
18
|
|
|
use AppBundle\Controller\AbstractController; |
|
19
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
20
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
21
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
22
|
|
|
use AppBundle\Entity\Tva; |
|
23
|
|
|
use AppBundle\Form\Type\TvaType; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Tva controller. |
|
27
|
|
|
* |
|
28
|
|
|
* @category Controller |
|
29
|
|
|
* |
|
30
|
|
|
* @Route("/admin/settings/divers/rate") |
|
31
|
|
|
*/ |
|
32
|
|
View Code Duplication |
class TvaController extends AbstractController |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* Lists all Tva entities. |
|
36
|
|
|
* |
|
37
|
|
|
* @Route("/", name="admin_rate") |
|
38
|
|
|
* @Method("GET") |
|
39
|
|
|
* @Template() |
|
40
|
|
|
*/ |
|
41
|
|
|
public function indexAction() |
|
42
|
|
|
{ |
|
43
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
44
|
|
|
$entities = $em->getRepository('AppBundle:Tva')->findAll(); |
|
45
|
|
|
|
|
46
|
|
|
return array( |
|
47
|
|
|
'entities' => $entities, |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Finds and displays a Tva entity. |
|
53
|
|
|
* |
|
54
|
|
|
* @Route("/{id}/show", name="admin_rate_show", requirements={"id"="\d+"}) |
|
55
|
|
|
* @Method("GET") |
|
56
|
|
|
* @Template() |
|
57
|
|
|
*/ |
|
58
|
|
|
public function showAction(Tva $tva) |
|
59
|
|
|
{ |
|
60
|
|
|
$deleteForm = $this->createDeleteForm($tva->getId(), 'admin_rate_delete'); |
|
61
|
|
|
|
|
62
|
|
|
return array( |
|
63
|
|
|
'tva' => $tva, |
|
64
|
|
|
'delete_form' => $deleteForm->createView(), |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Displays a form to create a new Tva entity. |
|
70
|
|
|
* |
|
71
|
|
|
* @Route("/new", name="admin_rate_new") |
|
72
|
|
|
* @Method("GET") |
|
73
|
|
|
* @Template() |
|
74
|
|
|
*/ |
|
75
|
|
|
public function newAction() |
|
76
|
|
|
{ |
|
77
|
|
|
$tva = new Tva(); |
|
78
|
|
|
$form = $this->createForm(new TvaType(), $tva); |
|
79
|
|
|
|
|
80
|
|
|
return array( |
|
81
|
|
|
'tva' => $tva, |
|
82
|
|
|
'form' => $form->createView(), |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Creates a new Tva entity. |
|
88
|
|
|
* |
|
89
|
|
|
* @Route("/create", name="admin_rate_create") |
|
90
|
|
|
* @Method("POST") |
|
91
|
|
|
* @Template("AppBundle:Tva:new.html.twig") |
|
92
|
|
|
*/ |
|
93
|
|
|
public function createAction(Request $request) |
|
94
|
|
|
{ |
|
95
|
|
|
$tva = new Tva(); |
|
96
|
|
|
$form = $this->createForm(new TvaType(), $tva); |
|
97
|
|
|
if ($form->handleRequest($request)->isValid()) { |
|
98
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
99
|
|
|
$em->persist($tva); |
|
100
|
|
|
$em->flush(); |
|
101
|
|
|
|
|
102
|
|
|
if ($form->get('save')->isSubmitted()) { |
|
103
|
|
|
$url = $this->redirectToRoute('admin_rate_show', array('id' => $tva->getId())); |
|
104
|
|
|
} elseif ($form->get('addmore')->isSubmitted()) { |
|
105
|
|
|
$this->addFlash('info', 'gestock.settings.add_ok'); |
|
106
|
|
|
$url = $this->redirectToRoute('admin_rate_new'); |
|
107
|
|
|
} |
|
108
|
|
|
return $url; |
|
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
return array( |
|
112
|
|
|
'tva' => $tva, |
|
113
|
|
|
'form' => $form->createView(), |
|
114
|
|
|
); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Displays a form to edit an existing Tva entity. |
|
119
|
|
|
* |
|
120
|
|
|
* @Route("/{id}/edit", name="admin_rate_edit", requirements={"id"="\d+"}) |
|
121
|
|
|
* @Method("GET") |
|
122
|
|
|
* @Template() |
|
123
|
|
|
*/ |
|
124
|
|
|
public function editAction(Tva $tva = null) |
|
125
|
|
|
{ |
|
126
|
|
|
$editForm = $this->createForm(new TvaType(), $tva, array( |
|
127
|
|
|
'action' => $this->generateUrl('admin_rate_update', array('id' => $tva->getId())), |
|
|
|
|
|
|
128
|
|
|
'method' => 'PUT', |
|
129
|
|
|
)); |
|
130
|
|
|
$deleteForm = $this->createDeleteForm($tva->getId(), 'admin_rate_delete'); |
|
131
|
|
|
|
|
132
|
|
|
return array( |
|
133
|
|
|
'tva' => $tva, |
|
134
|
|
|
'edit_form' => $editForm->createView(), |
|
135
|
|
|
'delete_form' => $deleteForm->createView(), |
|
136
|
|
|
); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Edits an existing Tva entity. |
|
141
|
|
|
* |
|
142
|
|
|
* @Route("/{id}/update", name="admin_rate_update", requirements={"id"="\d+"}) |
|
143
|
|
|
* @Method("PUT") |
|
144
|
|
|
* @Template("AppBundle:Tva:edit.html.twig") |
|
145
|
|
|
*/ |
|
146
|
|
|
public function updateAction(Request $request, Tva $tva = null) |
|
147
|
|
|
{ |
|
148
|
|
|
$editForm = $this->createForm(new TvaType(), $tva, array( |
|
149
|
|
|
'action' => $this->generateUrl('admin_rate_update', array('id' => $tva->getId())), |
|
|
|
|
|
|
150
|
|
|
'method' => 'PUT', |
|
151
|
|
|
)); |
|
152
|
|
|
if ($editForm->handleRequest($request)->isValid()) { |
|
153
|
|
|
$this->getDoctrine()->getManager()->flush(); |
|
154
|
|
|
$this->addFlash('info', 'gestock.settings.edit_ok'); |
|
155
|
|
|
|
|
156
|
|
|
return $this->redirectToRoute('admin_rate_edit', array('id' => $tva->getId())); |
|
157
|
|
|
} |
|
158
|
|
|
$deleteForm = $this->createDeleteForm($tva->getId(), 'admin_rate_delete'); |
|
159
|
|
|
|
|
160
|
|
|
return array( |
|
161
|
|
|
'tva' => $tva, |
|
162
|
|
|
'edit_form' => $editForm->createView(), |
|
163
|
|
|
'delete_form' => $deleteForm->createView(), |
|
164
|
|
|
); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Deletes a Tva entity. |
|
169
|
|
|
* |
|
170
|
|
|
* @Route("/{id}/delete", name="admin_rate_delete", requirements={"id"="\d+"}) |
|
171
|
|
|
* @Method("DELETE") |
|
172
|
|
|
*/ |
|
173
|
|
|
public function deleteAction(Request $request, Tva $tva = null) |
|
174
|
|
|
{ |
|
175
|
|
|
$form = $this->createDeleteForm($tva->getId(), 'admin_rate_delete'); |
|
|
|
|
|
|
176
|
|
|
if ($form->handleRequest($request)->isValid()) { |
|
177
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
178
|
|
|
$em->remove($tva); |
|
179
|
|
|
$em->flush(); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
return $this->redirectToRoute('admin_rate'); |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.