Advertisement
Guest User

asdsdd

a guest
May 24th, 2015
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.67 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppBundle\Controller;
  4.  
  5. use AppBundle\Entity\Cliente;
  6. use AppBundle\Entity\Expediente;
  7. use AppBundle\Entity\Usuario;
  8. use AppBundle\Entity\Contacto;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  14. use AppBundle\Entity\Recepcion;
  15. use AppBundle\Form\RecepcionType;
  16. use Symfony\Component\HttpFoundation\Response;
  17.  
  18. /**
  19. * Recepcion controller.
  20. *
  21. * @Route("/recepcion")
  22. */
  23. class RecepcionController extends Controller
  24. {
  25.  
  26.  
  27.  
  28. /**
  29. * @Route("/grid")
  30. * @Template()
  31. */
  32. public function gridAction() {
  33.  
  34. return array();
  35. }
  36.  
  37.  
  38. /**
  39. * @Route("/gridContent", name="_grid_content")
  40. */
  41. public function contenidoDelGridAction() {
  42. $renglones = array();
  43. $renglones[] = array('id'=>1, 'Item'=>'dcf','Descripcion'=>'Mesa','Cantidad'=>'100','Nro Expediente'=>'1 - 100');
  44. $renglones[] = array('id'=>2, 'Item'=>'ddc','Descripcion'=>'Silla','Cantidad'=>'23','Nro Expediente'=>'100 - 200');
  45.  
  46. $contenidoParaJqGrid = array(
  47. 'total'=>1,
  48. 'page'=>1,
  49. 'records'=>1,
  50. 'rows'=>$renglones
  51. );
  52. return new \Symfony\Component\HttpFoundation\Response(
  53. json_encode($contenidoParaJqGrid)
  54. , 200
  55. , array('content-type'=>'application/json')
  56. );
  57. }
  58.  
  59.  
  60.  
  61. /**
  62. * Lists all Recepcion entities.
  63. *
  64. * @Route("/", name="recepcion")
  65. * @Method("GET")
  66. * @Template()
  67. */
  68. public function indexAction()
  69. {
  70. $em = $this->getDoctrine()->getManager();
  71.  
  72. $entities = $em->getRepository('AppBundle:Recepcion')->findAll();
  73.  
  74. return array(
  75. 'entities' => $entities,
  76. );
  77. }
  78. /**
  79. * Creates a new Recepcion entity.
  80. *
  81. * @Route("/", name="recepcion_create")
  82. * @Method("POST")
  83. * @Template("AppBundle:Recepcion:new.html.twig")
  84. */
  85. public function createAction(Request $request)
  86. {
  87. $entity = new Recepcion();
  88. $form = $this->createCreateForm($entity);
  89. $form->handleRequest($request);
  90.  
  91. if ($form->isValid()) {
  92. $em = $this->getDoctrine()->getManager();
  93. $em->persist($entity);
  94. $em->flush();
  95.  
  96. return $this->redirect($this->generateUrl('recepcion_show', array('id' => $entity->getIdRecepcion())));
  97. }
  98.  
  99. return array(
  100. 'entity' => $entity,
  101. 'form' => $form->createView(),
  102. );
  103. }
  104.  
  105. /**
  106. * Creates a form to create a Recepcion entity.
  107. *
  108. * @param Recepcion $entity The entity
  109. *
  110. * @return \Symfony\Component\Form\Form The form
  111. */
  112. private function createCreateForm(Recepcion $entity)
  113. {
  114. // $form = $this->createForm()
  115. $form = $this->createForm(new RecepcionType(), $entity, array(
  116. 'action' => $this->generateUrl('recepcion_create'),
  117. 'method' => 'POST',
  118. ));
  119.  
  120. $form->add('submit', 'submit', array('label' => 'Crear','attr' => array('class' => 'btn btn-success')));
  121.  
  122. return $form;
  123. }
  124.  
  125. /**
  126. * Displays a form to create a new Recepcion entity.
  127. *
  128. * @Route("/gridData", name = "recepcion_postaction")
  129. * @Method("POST")
  130. */
  131. public function gridDataAction(Request $request)
  132. {
  133.  
  134. $jsonGrid = $request->request->get('localGridData');
  135. $recepcion_info = $request->request->get('infoRecepcion');
  136.  
  137. $em = $this->getDoctrine()->getManager();
  138.  
  139.  
  140. // Extraccion de Informacion de Recepcion
  141. for($x = 0; $x < sizeof($recepcion_info); $x++) {
  142. if($recepcion_info[$x]['name'] == 'appbundle_recepcion[fechaRecepcion]')
  143. $fecha_recepcion = $recepcion_info[$x]['value'];
  144. if($recepcion_info[$x]['name'] == 'appbundle_recepcion[id]')
  145. $encargado_recepcion = $recepcion_info[$x]['value'];
  146. if($recepcion_info[$x]['name'] == 'appbundle_recepcion[idCliente]')
  147. $cliente_recepcion = $recepcion_info[$x]['value'];
  148. if($recepcion_info[$x]['name'] == 'appbundle_recepcion[idContacto]')
  149. $contacto_recepcion = $recepcion_info[$x]['value'];
  150. }
  151.  
  152.  
  153. $encargado_recepcion = $em->getRepository('AppBundle:Usuario')->find($encargado_recepcion);
  154. $cliente_recepcion = $em->getRepository('AppBundle:Cliente')->find($cliente_recepcion);
  155. $contacto_recepcion = $em->getRepository('AppBundle:Contacto')->find($contacto_recepcion);
  156. $fecha_recepcion = new \DateTime($fecha_recepcion,null);
  157.  
  158. $row = new Recepcion();
  159. $row->setFechaRecepcion($fecha_recepcion);
  160. $row->setId($encargado_recepcion);
  161. $row->setIdCliente($cliente_recepcion);
  162. $row->setIdContacto($contacto_recepcion);
  163. $em->persist($row);
  164. $em->flush();
  165.  
  166.  
  167. //Extraccion de Informacion del grid1
  168. for($x = 0; $x < sizeof($jsonGrid); $x++) {
  169. $item = $jsonGrid[$x]['Item'];
  170. $descripcion = $jsonGrid[$x]['Descripcion'];
  171. $cantidad = $jsonGrid[$x]['Cantidad'];
  172.  
  173.  
  174. }
  175.  
  176.  
  177.  
  178.  
  179.  
  180. // var_dump($fecha_recepcion,$encargado_recepcion,$cliente_recepcion,$contacto_recepcion);
  181.  
  182.  
  183. //var_dump($recepcion_info[0]['value']);
  184. //
  185. //
  186.  
  187. //var_dump($cantidad);
  188.  
  189. // $arrayGrid = json_decode($jsonGrid,true);
  190. //
  191. // foreach($arrayGrid AS $prop => $val){
  192. // echo '<br/>'.'-'.$val;
  193. // }
  194.  
  195.  
  196. // $uid = $_POST['Descripcion'];
  197. // $uiadd = json_decode($uid);
  198. // echo $uiadd;
  199.  
  200. // if (isset($_POST["grid-pager"])) {
  201. // echo $_POST["grid-pager"];
  202. // }
  203. $response = new Response(json_encode(array('jsonGrid' => $jsonGrid, 'recepcion_info' => $recepcion_info )));
  204. $response->headers->set("Content-type", "application/json");
  205.  
  206. return $response;
  207.  
  208. }
  209.  
  210. /**
  211. * Displays a form to create a new Recepcion entity.
  212. *
  213. * @Route("/nroExpedienteSeq", name = "recepcion_nroexpseq")
  214. * @Method("POST")
  215. */
  216. public function nroExpedienteSeqAction(Request $request)
  217. {
  218. $qty = $request->request->get("Cantidad");
  219. var_dump($request->request);
  220. $minVal = 1; //reemplazar por un query para saber el siguiente valor de la secuencia
  221. $seq = range($minVal,$minVal-1+$qty);
  222. $response = new Response(json_encode(array("seq"=> $seq)));
  223. $response->headers->set("Content-type", "application/json");
  224.  
  225. return $response;
  226.  
  227. }
  228.  
  229.  
  230. /**
  231. * Displays a form to create a new Recepcion entity.
  232. *
  233. * @Route("/new", name="recepcion_new")
  234. * @Method("GET")
  235. * @Template()
  236. */
  237. public function newAction()
  238. {
  239.  
  240. $entity = new Recepcion();
  241. $form = $this->createCreateForm($entity);
  242.  
  243. $em = $this->getDoctrine()->getManager();
  244.  
  245. $clientes = $em->getRepository('AppBundle:Cliente')->findAll();
  246.  
  247.  
  248. return array(
  249. 'entity' => $entity,
  250. 'form' => $form->createView(),
  251. 'clientes' => $clientes,
  252. );
  253. }
  254.  
  255. /**
  256. * Finds and displays a Recepcion entity.
  257. *
  258. * @Route("/{id}", name="recepcion_show")
  259. * @Method("GET")
  260. * @Template()
  261. */
  262. public function showAction($id)
  263. {
  264. $em = $this->getDoctrine()->getManager();
  265.  
  266. $entity = $em->getRepository('AppBundle:Recepcion')->find($id);
  267.  
  268. if (!$entity) {
  269. throw $this->createNotFoundException('No se pudo encontrar la entidad Recepcion.');
  270. }
  271.  
  272. $deleteForm = $this->createDeleteForm($id);
  273.  
  274. return array(
  275. 'entity' => $entity,
  276. 'delete_form' => $deleteForm->createView(),
  277. );
  278. }
  279.  
  280. /**
  281. * Displays a form to edit an existing Recepcion entity.
  282. *
  283. * @Route("/{id}/edit", name="recepcion_edit")
  284. * @Method("GET")
  285. * @Template()
  286. */
  287. public function editAction($id)
  288. {
  289. $em = $this->getDoctrine()->getManager();
  290.  
  291. $entity = $em->getRepository('AppBundle:Recepcion')->find($id);
  292.  
  293. if (!$entity) {
  294. throw $this->createNotFoundException('No se pudo encontrar la entidad Recepcion.');
  295. }
  296.  
  297. $editForm = $this->createEditForm($entity);
  298. $deleteForm = $this->createDeleteForm($id);
  299.  
  300. return array(
  301. 'entity' => $entity,
  302. 'edit_form' => $editForm->createView(),
  303. 'delete_form' => $deleteForm->createView(),
  304. );
  305. }
  306.  
  307. /**
  308. * Creates a form to edit a Recepcion entity.
  309. *
  310. * @param Recepcion $entity The entity
  311. *
  312. * @return \Symfony\Component\Form\Form The form
  313. */
  314. private function createEditForm(Recepcion $entity)
  315. {
  316. $form = $this->createForm(new RecepcionType(), $entity, array(
  317. 'action' => $this->generateUrl('recepcion_update', array('id' => $entity->getIdRecepcion())),
  318. 'method' => 'PUT',
  319. ));
  320.  
  321. $form->add('submit', 'submit', array('label' => 'Actualizar','attr' => array('class' => 'btn btn-info')));
  322.  
  323. return $form;
  324. }
  325. /**
  326. * Edits an existing Recepcion entity.
  327. *
  328. * @Route("/{id}", name="recepcion_update")
  329. * @Method("PUT")
  330. * @Template("AppBundle:Recepcion:edit.html.twig")
  331. */
  332. public function updateAction(Request $request, $id)
  333. {
  334. $em = $this->getDoctrine()->getManager();
  335.  
  336. $entity = $em->getRepository('AppBundle:Recepcion')->find($id);
  337.  
  338. if (!$entity) {
  339. throw $this->createNotFoundException('No se pudo encontrar la entidad Recepcion.');
  340. }
  341.  
  342. $deleteForm = $this->createDeleteForm($id);
  343. $editForm = $this->createEditForm($entity);
  344. $editForm->handleRequest($request);
  345.  
  346. if ($editForm->isValid()) {
  347. $em->flush();
  348.  
  349. return $this->redirect($this->generateUrl('recepcion_edit', array('id' => $id)));
  350. }
  351.  
  352. return array(
  353. 'entity' => $entity,
  354. 'edit_form' => $editForm->createView(),
  355. 'delete_form' => $deleteForm->createView(),
  356. );
  357. }
  358. /**
  359. * Deletes a Recepcion entity.
  360. *
  361. * @Route("/{id}", name="recepcion_delete")
  362. * @Method("DELETE")
  363. */
  364. public function deleteAction(Request $request, $id)
  365. {
  366. $form = $this->createDeleteForm($id);
  367. $form->handleRequest($request);
  368.  
  369. if ($form->isValid()) {
  370. $em = $this->getDoctrine()->getManager();
  371. $entity = $em->getRepository('AppBundle:Recepcion')->find($id);
  372.  
  373. if (!$entity) {
  374. throw $this->createNotFoundException('No se pudo encontrar la entidad Recepcion.');
  375. }
  376.  
  377. $em->remove($entity);
  378. $em->flush();
  379. }
  380.  
  381. return $this->redirect($this->generateUrl('recepcion'));
  382. }
  383.  
  384. /**
  385. * Creates a form to delete a Recepcion entity by id.
  386. *
  387. * @param mixed $id The entity id
  388. *
  389. * @return \Symfony\Component\Form\Form The form
  390. */
  391. private function createDeleteForm($id)
  392. {
  393. return $this->createFormBuilder()
  394. ->setAction($this->generateUrl('recepcion_delete', array('id' => $id)))
  395. ->setMethod('DELETE')
  396. ->add('submit', 'submit', array('label' => 'Borrar','attr' => array('class' => 'btn btn-danger')))
  397. ->getForm()
  398. ;
  399. }
  400. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement