<commit_before><?php

namespace fm\erpBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use fm\erpBundle\Entity\factura;
use fm\erpBundle\Form\facturaType;
use fm\erpBundle\Form\grabarfacturaType;
use Ps\PdfBundle\Annotation\Pdf;



/**
 * factura controller.
 *
 * @Route("/facturas")
 */
class facturaController extends Controller
{

    /**
     * Lists all factura entities.
     *
     * @Route("/", name="factura")
     * @Method("GET")
     * @Template()
     */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getManager();

        $entities = $em->getRepository('erpBundle:factura')->findby(array("estado" => 1));

        $grabadas = $em->getRepository('erpBundle:factura')->findby(array("estado" => 2));

        $conceptosunicos = $em->getRepository('erpBundle:conceptounico')->findAll();


        return array(
            'entities' => $entities,
            'grabadas' => $grabadas,
            'id_direccion' => false,
            'conceptosunicos' => $conceptosunicos
        );
    }


    /**
     *
     * @Route("/{id}/tooglepagado", name="factura_toogle_pagado")
     * @Method("GET")
     */
    public function tooglePagadoAction($id){
         $em = $this->getDoctrine()->getManager();
         $entity = $em->getRepository('erpBundle:factura')->find($id);

         if($entity->getFechaPagado() == null ){
          $estado = "atendida";
          $entity->setFechaPagado(new \DateTime());
         }else{
            $estado = "pendiente";
            $entity->setFechaPagado(null);
         }
            $em->persist($entity);
            $em->flush();

             $this->get('session')->getFlashBag()->add(
                 'notice',
                'La factura '.$entity->getCodFactura().' ha sido marcada como '.$estado.'!'
             );


            return $this->redirect($this->generateUrl('erp_homepage'));

    }


    /**
     *
     * @Route("/{id}/clone", name="factura_clone")
     * @Method("GET")
     */
    public function cloneAction($id){
         $em = $this->getDoctrine()->getManager();
         $entity = $em->getRepository('erpBundle:factura')->find($id);


         $new_entity = clone $entity;

         $new_entity->setSerie($em->getReference('erpBundle:series',1));
     

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

            $this->get('session')->getFlashBag()->add(
                 'notice',
                'Se ha generado nueva factura de venta pendiente de grabar a partir de la factura '.$entity->getCodFactura()
             );


        $entity->setFechaPagado(new \DateTime());
        $em->persist($entity);
        $em->flush();

             $this->get('session')->getFlashBag()->add(
                 'notice',
                'La factura '.$entity->getCodFactura().' ha sido marcada como Atendida!'
             );


            return $this->redirect($this->generateUrl('factura'));

    }

    /**
     *
     * @Route("/{id}/send", name="factura_enviar")
     * @Method("GET")
     * @Template()
     */
    public function sendAction($id, Request $request){
         $em = $this->getDoctrine()->getManager();
         $entity = $em->getRepository('erpBundle:factura')->find($id);

         $id_direccion = $request->get('id_direccion');
         $conceptounico = $request->get('conceptounico');

         $data = $this->forward('erpBundle:factura:show', 
            array( 'id' => $id, '_format' => 'pdf', 'id_direccion' => $id_direccion,
                'conceptounico' => $conceptounico,
                ));


        $message = \Swift_Message::newInstance()
            ->setSubject(strtoupper($entity->getTipo()).' FURGOMANIA '.$entity->getCodfactura())
            ->setFrom('<EMAIL>')
            ->setTo($entity->getCliente()->getEmail())
            ->setCc(array('<EMAIL>', '<EMAIL>','<EMAIL>'))
            ->setBody(
                $this->renderView(
                    'erpBundle:factura:email.html.twig',
                    array( 'entity'=> $entity)
                ), 'text/html'
            )<commit_msg>envio facturas solo a contacto<commit_after><?php

namespace fm\erpBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use fm\erpBundle\Entity\factura;
use fm\erpBundle\Form\facturaType;
use fm\erpBundle\Form\grabarfacturaType;
use Ps\PdfBundle\Annotation\Pdf;



/**
 * factura controller.
 *
 * @Route("/facturas")
 */
class facturaController extends Controller
{

    /**
     * Lists all factura entities.
     *
     * @Route("/", name="factura")
     * @Method("GET")
     * @Template()
     */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getManager();

        $entities = $em->getRepository('erpBundle:factura')->findby(array("estado" => 1));

        $grabadas = $em->getRepository('erpBundle:factura')->findby(array("estado" => 2));

        $conceptosunicos = $em->getRepository('erpBundle:conceptounico')->findAll();


        return array(
            'entities' => $entities,
            'grabadas' => $grabadas,
            'id_direccion' => false,
            'conceptosunicos' => $conceptosunicos
        );
    }


    /**
     *
     * @Route("/{id}/tooglepagado", name="factura_toogle_pagado")
     * @Method("GET")
     */
    public function tooglePagadoAction($id){
         $em = $this->getDoctrine()->getManager();
         $entity = $em->getRepository('erpBundle:factura')->find($id);

         if($entity->getFechaPagado() == null ){
          $estado = "atendida";
          $entity->setFechaPagado(new \DateTime());
         }else{
            $estado = "pendiente";
            $entity->setFechaPagado(null);
         }
            $em->persist($entity);
            $em->flush();

             $this->get('session')->getFlashBag()->add(
                 'notice',
                'La factura '.$entity->getCodFactura().' ha sido marcada como '.$estado.'!'
             );


            return $this->redirect($this->generateUrl('erp_homepage'));

    }


    /**
     *
     * @Route("/{id}/clone", name="factura_clone")
     * @Method("GET")
     */
    public function cloneAction($id){
         $em = $this->getDoctrine()->getManager();
         $entity = $em->getRepository('erpBundle:factura')->find($id);


         $new_entity = clone $entity;

         $new_entity->setSerie($em->getReference('erpBundle:series',1));
     

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

            $this->get('session')->getFlashBag()->add(
                 'notice',
                'Se ha generado nueva factura de venta pendiente de grabar a partir de la factura '.$entity->getCodFactura()
             );


        $entity->setFechaPagado(new \DateTime());
        $em->persist($entity);
        $em->flush();

             $this->get('session')->getFlashBag()->add(
                 'notice',
                'La factura '.$entity->getCodFactura().' ha sido marcada como Atendida!'
             );


            return $this->redirect($this->generateUrl('factura'));

    }

    /**
     *
     * @Route("/{id}/send", name="factura_enviar")
     * @Method("GET")
     * @Template()
     */
    public function sendAction($id, Request $request){
         $em = $this->getDoctrine()->getManager();
         $entity = $em->getRepository('erpBundle:factura')->find($id);

         $id_direccion = $request->get('id_direccion');
         $conceptounico = $request->get('conceptounico');

         $data = $this->forward('erpBundle:factura:show', 
            array( 'id' => $id, '_format' => 'pdf', 'id_direccion' => $id_direccion,
                'conceptounico' => $conceptounico,
                ));


        $message = \Swift_Message::newInstance()
            ->setSubject(strtoupper($entity->getTipo()).' FURGOMANIA '.$entity->getCodfactura())
            ->setFrom('<EMAIL>')
            ->setTo($entity->getCliente()->getEmail())
            ->setCc(array('<EMAIL>'))
           // ->setCc(array('<EMAIL>', '<EMAIL>','<EMAIL>'))
            ->setBody(
                $this->renderView(
                    'erpBundle:factura:email.html.twig',
                    array( 'entity'=> $entity)
                ), 'text/html'
            )
{'fraction_non_alphanumeric': 0.17494525757750373, 'fraction_numerical': 0.0006914832315316353, 'mean_word_length': 2.3084254670224933, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 157, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1454603', 'n_tokens_mistral': 2722, 'n_tokens_neox': 2606, 'n_words': 379}