<commit_before><?php

namespace Nossis\NossisBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Nossis\NossisBundle\Entity\Stock;
use Nossis\NossisBundle\Form\StockType;
use Nossis\NossisBundle\Form\StockEditType;
use Symfony\Component\HttpFoundation\Response;
use Nossis\NossisBundle\Entity\Trazlado;
use Nossis\NossisBundle\Form\TrazladoType;
use \DateTime;
use APY\DataGridBundle\Grid\Source\Entity;
use APY\DataGridBundle\Grid\Action\RowAction;
use PHPPdf\Core\Node\Barcode as Barcode;
use Zend\Barcode\Object;
use Nossis\NossisBundle\Entity\EstadoStock;

class StockController extends Controller
{
    public function ingresarAction($nuevo = false)
    {
         $em = $this->get('doctrine')->getManager();
         $stock = new Stock;
         $form = $this->get('form.factory')->create(
                new StockType(),
                $stock
         );
         $ultimosStock = $em->getRepository('NossisBundle:Stock')->findLast();
         
         return $this->render('NossisBundle:Stock:ingresar.html.twig',
                array( 'form' => $form->createView(), 'ultimos' => $ultimosStock,
                    'first' => $nuevo
                ));         
    }
    
    public function agregarAction()
    {
        $em = $this->get('doctrine')->getManager();
        $stock = new Stock;
        $form = $this->get('form.factory')->create(
                new StockType(),
                $stock
         );
        $request = $this->get('request');
        $form->bind($request);
        if ($form->isValid()){

            $stock = $form->getData();
            $stock->setFechaIngreso(new \DateTime('NOW'));
            $stock->setCodigo(0);
            $stock->setActual($stock->getIngresado());
            
            $estado = $em->getRepository('NossisBundle:Estado')->findOneBy(array('nombre' => 'Ingresado'));
            $estadoStock = new EstadoStock;
            $estadoStock->setEstado($estado);
            $estadoStock->setStock($stock);
            $estadoStock->setDescripcion("Ingresado al area ". $stock->getArea()->getNombre());
            $estadoStock->setFecha(new \DateTime('NOW'));
            
            $em->persist($stock);
            $em->persist($estadoStock);
            $em->flush();
            $stock->setCodigo($this->getCodigoBarra($stock));
            $stock->setNumero($stock->getId(). '/'. $estadoStock->getFecha()->format('y'));
            $em->persist($stock);
            $em->flush();
            
           
            return $this->ingresarAction(true); 
                
        }
    }
    
    private function getCodigoBarra($stock){
        $codigo = $stock->getLote();
        $codigo = $codigo. $stock->getPalet();
        $codigo = $codigo. $stock->getTurno();
        $codigo = $codigo. $stock->getId();
        return $codigo;
    }
    
    public function indexAction(){
        $form = $this->createFormBuilder()
            ->add('codigo')
            ->getForm();
        $request = $this->get('request');
        $form->bind($request);
        $datos = $form->getData();
        $em = $this->get('doctrine')->getManager();
        $stock = $em->getRepository('NossisBundle:Stock')->findOneBy(array('codigo' => $datos['codigo']));
        if ($stock == null){
            return $this->redirect($this->generateUrl('nossis_homepage'));
        }else{
            return $this->showAction($stock->getId());
        }
             
        
    }
    
    public function showAction($id){
        $em = $this->get('doctrine')->getManager();
        $stock = $em->getRepository('NossisBundle:Stock')->find($id);
        
        $bmanager = $this->container->get('mopa_barcode.barcode_service');<commit_msg>Se agrego busqueda por Numero<commit_after><?php

namespace Nossis\NossisBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Nossis\NossisBundle\Entity\Stock;
use Nossis\NossisBundle\Form\StockType;
use Nossis\NossisBundle\Form\StockEditType;
use Symfony\Component\HttpFoundation\Response;
use Nossis\NossisBundle\Entity\Trazlado;
use Nossis\NossisBundle\Form\TrazladoType;
use \DateTime;
use APY\DataGridBundle\Grid\Source\Entity;
use APY\DataGridBundle\Grid\Action\RowAction;
use PHPPdf\Core\Node\Barcode as Barcode;
use Zend\Barcode\Object;
use Nossis\NossisBundle\Entity\EstadoStock;

class StockController extends Controller
{
    public function ingresarAction($nuevo = false)
    {
         $em = $this->get('doctrine')->getManager();
         $stock = new Stock;
         $form = $this->get('form.factory')->create(
                new StockType(),
                $stock
         );
         $ultimosStock = $em->getRepository('NossisBundle:Stock')->findLast();
         
         return $this->render('NossisBundle:Stock:ingresar.html.twig',
                array( 'form' => $form->createView(), 'ultimos' => $ultimosStock,
                    'first' => $nuevo
                ));         
    }
    
    public function agregarAction()
    {
        $em = $this->get('doctrine')->getManager();
        $stock = new Stock;
        $form = $this->get('form.factory')->create(
                new StockType(),
                $stock
         );
        $request = $this->get('request');
        $form->bind($request);
        if ($form->isValid()){

            $stock = $form->getData();
            $stock->setFechaIngreso(new \DateTime('NOW'));
            $stock->setCodigo(0);
            $stock->setActual($stock->getIngresado());
            
            $estado = $em->getRepository('NossisBundle:Estado')->findOneBy(array('nombre' => 'Ingresado'));
            $estadoStock = new EstadoStock;
            $estadoStock->setEstado($estado);
            $estadoStock->setStock($stock);
            $estadoStock->setDescripcion("Ingresado al area ". $stock->getArea()->getNombre());
            $estadoStock->setFecha(new \DateTime('NOW'));
            
            $em->persist($stock);
            $em->persist($estadoStock);
            $em->flush();
            $stock->setCodigo($this->getCodigoBarra($stock));
            $stock->setNumero($stock->getId(). '/'. $estadoStock->getFecha()->format('y'));
            $em->persist($stock);
            $em->flush();
            
           
            return $this->ingresarAction(true); 
                
        }
    }
    
    private function getCodigoBarra($stock){
        $codigo = $stock->getLote();
        $codigo = $codigo. $stock->getPalet();
        $codigo = $codigo. $stock->getTurno();
        $codigo = $codigo. $stock->getId();
        return $codigo;
    }
    
    public function indexAction(){
        $form = $this->createFormBuilder()
            ->add('codigo')
            ->getForm();
        $request = $this->get('request');
        $form->bind($request);
        $datos = $form->getData();
        $em = $this->get('doctrine')->getManager();
        $stock = $em->getRepository('NossisBundle:Stock')->findOneBy(array('codigo' => $datos['codigo']));
        if ($stock == null){
            $stock = $em->getRepository('NossisBundle:Stock')->findOneBy(array('numero' => $datos['codigo']));
        }
        if ($stock == null){
            return $this->redirect($this->generateUrl('nossis_homepage'));
        }else{
            return $this->showAction($stock->getId());
        }
             
        
    }
    
    public function showAction($id){
        $em = $this->get('doctrine')->getManager();
        $stock = $em->getRepository('NossisBundle:Stock')->find($id);
        
        $bmanager = $this->container->get('mopa_barcode.barcode_service');
{'fraction_non_alphanumeric': 0.16600946372239747, 'fraction_numerical': 0.0002628811777076761, 'mean_word_length': 2.264264264264264, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 144, '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': '975999', 'n_tokens_mistral': 2356, 'n_tokens_neox': 2312, 'n_words': 325}