Advertisement
Guest User

asd

a guest
May 25th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.74 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. var_dump($jsonGrid);
  140. var_dump($recepcion_info);
  141.  
  142. // Extraccion de Informacion de Recepcion
  143. for($x = 0; $x < sizeof($recepcion_info); $x++) {
  144. if($recepcion_info[$x]['name'] == 'appbundle_recepcion[fechaRecepcion]')
  145. $fecha_recepcion = $recepcion_info[$x]['value'];
  146. if($recepcion_info[$x]['name'] == 'appbundle_recepcion[id]')
  147. $encargado_recepcion = $recepcion_info[$x]['value'];
  148. if($recepcion_info[$x]['name'] == 'appbundle_recepcion[idCliente]')
  149. $cliente_recepcion = $recepcion_info[$x]['value'];
  150. if($recepcion_info[$x]['name'] == 'appbundle_recepcion[idContacto]')
  151. $contacto_recepcion = $recepcion_info[$x]['value'];
  152. }
  153.  
  154.  
  155. $encargado_recepcion = $em->getRepository('AppBundle:Usuario')->find($encargado_recepcion);
  156. $cliente_recepcion = $em->getRepository('AppBundle:Cliente')->find($cliente_recepcion);
  157. $contacto_recepcion = $em->getRepository('AppBundle:Contacto')->find($contacto_recepcion);
  158. $fecha_recepcion = new \DateTime($fecha_recepcion,null);
  159.  
  160. $row = new Recepcion();
  161. $row->setFechaRecepcion($fecha_recepcion);
  162. $row->setId($encargado_recepcion);
  163. $row->setIdCliente($cliente_recepcion);
  164. $row->setIdContacto($contacto_recepcion);
  165. $em->persist($row);
  166. $em->flush();
  167.  
  168.  
  169. //Extraccion de Informacion del grid1
  170. for($x = 0; $x < sizeof($jsonGrid); $x++) {
  171. $item = $jsonGrid[$x]['Item'];
  172. $descripcion = $jsonGrid[$x]['Descripcion'];
  173. $cantidad = $jsonGrid[$x]['Cantidad'];
  174.  
  175.  
  176. }
  177.  
  178.  
  179.  
  180.  
  181.  
  182. // var_dump($fecha_recepcion,$encargado_recepcion,$cliente_recepcion,$contacto_recepcion);
  183.  
  184.  
  185. //var_dump($recepcion_info[0]['value']);
  186. //
  187. //
  188.  
  189. //var_dump($cantidad);
  190.  
  191. // $arrayGrid = json_decode($jsonGrid,true);
  192. //
  193. // foreach($arrayGrid AS $prop => $val){
  194. // echo '<br/>'.'-'.$val;
  195. // }
  196.  
  197.  
  198. // $uid = $_POST['Descripcion'];
  199. // $uiadd = json_decode($uid);
  200. // echo $uiadd;
  201.  
  202. // if (isset($_POST["grid-pager"])) {
  203. // echo $_POST["grid-pager"];
  204. // }
  205. $response = new Response(json_encode(array('jsonGrid' => $jsonGrid, 'recepcion_info' => $recepcion_info )));
  206. $response->headers->set("Content-type", "application/json");
  207.  
  208. return $response;
  209.  
  210. }
  211.  
  212. /**
  213. * Displays a form to create a new Recepcion entity.
  214. *
  215. * @Route("/nroExpedienteSeq", name = "recepcion_nroexpseq")
  216. * @Method("POST")
  217. */
  218. public function nroExpedienteSeqAction(Request $request)
  219. {
  220. $qty = $request->request->get("Cantidad");
  221. var_dump($request->request);
  222. $minVal = 1; //reemplazar por un query para saber el siguiente valor de la secuencia
  223. $seq = range($minVal,$minVal-1+$qty);
  224. $response = new Response(json_encode(array("seq"=> $seq)));
  225. $response->headers->set("Content-type", "application/json");
  226.  
  227. return $response;
  228.  
  229. }
  230.  
  231.  
  232. /**
  233. * Displays a form to create a new Recepcion entity.
  234. *
  235. * @Route("/new", name="recepcion_new")
  236. * @Method("GET")
  237. * @Template()
  238. */
  239. public function newAction()
  240. {
  241.  
  242. $entity = new Recepcion();
  243. $form = $this->createCreateForm($entity);
  244.  
  245. $em = $this->getDoctrine()->getManager();
  246.  
  247. $clientes = $em->getRepository('AppBundle:Cliente')->findAll();
  248.  
  249.  
  250. return array(
  251. 'entity' => $entity,
  252. 'form' => $form->createView(),
  253. 'clientes' => $clientes,
  254. );
  255. }
  256.  
  257. /**
  258. * Finds and displays a Recepcion entity.
  259. *
  260. * @Route("/{id}", name="recepcion_show")
  261. * @Method("GET")
  262. * @Template()
  263. */
  264. public function showAction($id)
  265. {
  266. $em = $this->getDoctrine()->getManager();
  267.  
  268. $entity = $em->getRepository('AppBundle:Recepcion')->find($id);
  269.  
  270. if (!$entity) {
  271. throw $this->createNotFoundException('No se pudo encontrar la entidad Recepcion.');
  272. }
  273.  
  274. $deleteForm = $this->createDeleteForm($id);
  275.  
  276. return array(
  277. 'entity' => $entity,
  278. 'delete_form' => $deleteForm->createView(),
  279. );
  280. }
  281.  
  282. /**
  283. * Displays a form to edit an existing Recepcion entity.
  284. *
  285. * @Route("/{id}/edit", name="recepcion_edit")
  286. * @Method("GET")
  287. * @Template()
  288. */
  289. public function editAction($id)
  290. {
  291. $em = $this->getDoctrine()->getManager();
  292.  
  293. $entity = $em->getRepository('AppBundle:Recepcion')->find($id);
  294.  
  295. if (!$entity) {
  296. throw $this->createNotFoundException('No se pudo encontrar la entidad Recepcion.');
  297. }
  298.  
  299. $editForm = $this->createEditForm($entity);
  300. $deleteForm = $this->createDeleteForm($id);
  301.  
  302. return array(
  303. 'entity' => $entity,
  304. 'edit_form' => $editForm->createView(),
  305. 'delete_form' => $deleteForm->createView(),
  306. );
  307. }
  308.  
  309. /**
  310. * Creates a form to edit a Recepcion entity.
  311. *
  312. * @param Recepcion $entity The entity
  313. *
  314. * @return \Symfony\Component\Form\Form The form
  315. */
  316. private function createEditForm(Recepcion $entity)
  317. {
  318. $form = $this->createForm(new RecepcionType(), $entity, array(
  319. 'action' => $this->generateUrl('recepcion_update', array('id' => $entity->getIdRecepcion())),
  320. 'method' => 'PUT',
  321. ));
  322.  
  323. $form->add('submit', 'submit', array('label' => 'Actualizar','attr' => array('class' => 'btn btn-info')));
  324.  
  325. return $form;
  326. }
  327. /**
  328. * Edits an existing Recepcion entity.
  329. *
  330. * @Route("/{id}", name="recepcion_update")
  331. * @Method("PUT")
  332. * @Template("AppBundle:Recepcion:edit.html.twig")
  333. */
  334. public function updateAction(Request $request, $id)
  335. {
  336. $em = $this->getDoctrine()->getManager();
  337.  
  338. $entity = $em->getRepository('AppBundle:Recepcion')->find($id);
  339.  
  340. if (!$entity) {
  341. throw $this->createNotFoundException('No se pudo encontrar la entidad Recepcion.');
  342. }
  343.  
  344. $deleteForm = $this->createDeleteForm($id);
  345. $editForm = $this->createEditForm($entity);
  346. $editForm->handleRequest($request);
  347.  
  348. if ($editForm->isValid()) {
  349. $em->flush();
  350.  
  351. return $this->redirect($this->generateUrl('recepcion_edit', array('id' => $id)));
  352. }
  353.  
  354. return array(
  355. 'entity' => $entity,
  356. 'edit_form' => $editForm->createView(),
  357. 'delete_form' => $deleteForm->createView(),
  358. );
  359. }
  360. /**
  361. * Deletes a Recepcion entity.
  362. *
  363. * @Route("/{id}", name="recepcion_delete")
  364. * @Method("DELETE")
  365. */
  366. public function deleteAction(Request $request, $id)
  367. {
  368. $form = $this->createDeleteForm($id);
  369. $form->handleRequest($request);
  370.  
  371. if ($form->isValid()) {
  372. $em = $this->getDoctrine()->getManager();
  373. $entity = $em->getRepository('AppBundle:Recepcion')->find($id);
  374.  
  375. if (!$entity) {
  376. throw $this->createNotFoundException('No se pudo encontrar la entidad Recepcion.');
  377. }
  378.  
  379. $em->remove($entity);
  380. $em->flush();
  381. }
  382.  
  383. return $this->redirect($this->generateUrl('recepcion'));
  384. }
  385.  
  386. /**
  387. * Creates a form to delete a Recepcion entity by id.
  388. *
  389. * @param mixed $id The entity id
  390. *
  391. * @return \Symfony\Component\Form\Form The form
  392. */
  393. private function createDeleteForm($id)
  394. {
  395. return $this->createFormBuilder()
  396. ->setAction($this->generateUrl('recepcion_delete', array('id' => $id)))
  397. ->setMethod('DELETE')
  398. ->add('submit', 'submit', array('label' => 'Borrar','attr' => array('class' => 'btn btn-danger')))
  399. ->getForm()
  400. ;
  401. }
  402. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement