<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace CmBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use CmBundle\Entity\CostosInscripcion;
use CmBundle\Entity\CostoTramites;

date_default_timezone_set('America/Mexico_City');

/**
 * Description of CostosController
 *
 * @author omar
 */
class CostosController extends Controller {

    //put your code here

    public function cInscripcionAction(Request $request) {
        $session = $request->getSession();
        if ($session->has("idEmpleado") && ($session->get("rol") == 2 || $session->get("rol") == 1)) {
            $session->set("vista", "alumno");
            if ($request->getMethod() == "POST") {

                $em = $this->getDoctrine()->getManager();

                $cveLic = $em->getRepository('CmBundle:Licenciaturas')
                        ->findOneBy(array('ideLic' => $request->get('grado')));

                $monto = $request->get('monto');

                $ci = new CostosInscripcion();
                $ci->setCveLic($cveLic);
                $ci->setMonto($monto);
                $ci->setCveUsu($session->get('identificador'));
                $ci->setEstatus(1);
                $ci->setFecMov(new \DateTime(date('Y-m-d')));

                $em->persist($ci);
                $em->flush();

                return $this->redirect($this->generateUrl('alta_costo_inscripcion'));
            } else {
                // Renderizar formulario de Niveles Académicos
                $em = $this->getDoctrine()->getManager();

                $licenciaturas = $em->getRepository('CmBundle:Licenciaturas')->findAll();
                $costos = $em->getRepository('CmBundle:CostosInscripcion')->findAll();

                return $this->render('CmBundle:Costos:alta-c-inscripcion.html.twig', array('grados' => $licenciaturas,
                            'costos' => $costos));
            }
        } else {
            return $this->render('CmBundle:Seguridad:login.html.twig');
        }
    }

    public function altaOtrosAction(Request $request) {
        $session = $request->getSession();
        if ($session->has("idEmpleado") && ($session->get("rol") == 2 || $session->get("rol") == 1 || $session->get("rol") == 3)) {
            $session->set("vista", "alumno");
            if ($request->getMethod() == "POST") {

                $em = $this->getDoctrine()->getManager();
                $desTra = $request->get('desTra');
                $monto = $request->get('monto');

                $cT = new CostoTramites();
                $cT->setContador(1);
                $cT->setCveTra("x");
                $cT->setCveUsu($session->get('identificador'));
                $cT->setDesTra($desTra);
                $cT->setMonto($monto);
                $cT->setFecMov( new \DateTime(date('Y-m-d')) );

                $em->persist($cT);
                $em->flush();

                return $this->redirect($this->generateUrl('alta_otros_conceptos'));
            } else {
                // Renderizar formulario de Niveles Académicos
                $em = $this->getDoctrine()->getManager();

                $cT = $em->getRepository('CmBundle:CostoTramites')
                        ->findBy(array(),array('cveTra' => 'ASC','desTra' => 'ASC'));

                return $this->render('CmBundle:Costos:alta-c-t.html.twig', array('cT' => $cT));
            }
        } else {
            return $this->render('CmBundle:Seguridad:login.html.twig');
        }
    }

}
