<commit_before><?php

namespace Nossis\NossisBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Nossis\NossisBundle\Entity\Retiro;
use Nossis\NossisBundle\Form\RetiroType;
use Nossis\NossisBundle\Entity\RetiroStock;
use Symfony\Component\HttpFoundation\Response;
use APY\DataGridBundle\Grid\Source\Entity;
use APY\DataGridBundle\Grid\Action\RowAction;
use Ps\PdfBundle\Annotation\Pdf;
use Nossis\NossisBundle\Entity\EstadoStock;
use Nossis\NossisBundle\Entity\Repositorio\ClienteRepository;
use Symfony\Component\HttpFoundation\RedirectResponse;

class RetiroController extends Controller
{
       
    public function indexAction()
    {
        $retiro = new Retiro;
        $form = $this->get('form.factory')->create(
                new RetiroType(),
                $retiro
         );        
         return $this->render('NossisBundle:Retiro:index.html.twig',
                array('form' => $form->createView()));
    }
    
    public function newAction()
    {
        $retiro = new Retiro;
        $form = $this->get('form.factory')->create(
                new RetiroType(),
                $retiro
         );
        $request = $this->get('request');
        $form->bind($request);
            $retiro = $form->getData();
            $retiro->setFechaSalida(new \DateTime('NOW'));
            $retiro->setConfirmado(false);
            $em = $this->get('doctrine')->getManager();
            $em->persist($retiro);
            $em->flush();
            
            return new RedirectResponse($this->generateUrl('edit_retiro', array('id' => $retiro->getId())));
                
        
    }
    
    public function editAction($id)
    {
        $em = $this->get('doctrine')->getManager();
        $retiro = $em->getRepository('NossisBundle:Retiro')->find($id);
            $formStock = $this->getFormStock($retiro);
            $request = $this->get('request');
            if ($request->getMethod() == 'POST'){
                $formStock->bind($request);
                $datos = $formStock->getData();
                if (($stock = $em->getRepository('NossisBundle:Stock')->findOneBy(array('codigo' => $datos['codigo']))) != null){
                    if ($stock->getArea()->getSalida()){
                        if (($retirostock = $em->getRepository('NossisBundle:RetiroStock')->findOneBy(array('retiro' => $retiro->getId(), 'stock' => $stock->getId()))) == null){
                            if ($this->comprobarSinConfirmar($stock)){
                                $retirostock = new RetiroStock;
                                $retirostock->setStock($stock);
                                $retirostock->setRetiro($retiro);
                                $retirostock->setCantidad($stock->getActual());
                                $retiro->addStock($retirostock);
                                //$cantidad = $stock->getIngresado() - $retirostock->getCantidad();
                                $stock->retirar($retirostock->getCantidad());
                                $em->persist($stock);
                            }else{
                                $this->get('session')->getFlashBag()->add(
                                    'notice',
                                'No se puede agregar por que el articulo se encuentra en un Despacho, sin confirmar'
                        );
                            }

                        }
                    }else{
                        $this->get('session')->getFlashBag()->add(
                            'notice',
                            'El articulo se encuentra en un area de no salida'
                        );
                    }                    
                    
                    <commit_msg>Ahora se puede enviar un palet a varios clientes<commit_after><?php

namespace Nossis\NossisBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Nossis\NossisBundle\Entity\Retiro;
use Nossis\NossisBundle\Form\RetiroType;
use Nossis\NossisBundle\Entity\RetiroStock;
use Symfony\Component\HttpFoundation\Response;
use APY\DataGridBundle\Grid\Source\Entity;
use APY\DataGridBundle\Grid\Action\RowAction;
use Ps\PdfBundle\Annotation\Pdf;
use Nossis\NossisBundle\Entity\EstadoStock;
use Nossis\NossisBundle\Entity\Repositorio\ClienteRepository;
use Symfony\Component\HttpFoundation\RedirectResponse;

class RetiroController extends Controller
{
       
    public function indexAction()
    {
        $retiro = new Retiro;
        $form = $this->get('form.factory')->create(
                new RetiroType(),
                $retiro
         );        
         return $this->render('NossisBundle:Retiro:index.html.twig',
                array('form' => $form->createView()));
    }
    
    public function newAction()
    {
        $retiro = new Retiro;
        $form = $this->get('form.factory')->create(
                new RetiroType(),
                $retiro
         );
        $request = $this->get('request');
        $form->bind($request);
            $retiro = $form->getData();
            $retiro->setFechaSalida(new \DateTime('NOW'));
            $retiro->setConfirmado(false);
            $em = $this->get('doctrine')->getManager();
            $em->persist($retiro);
            $em->flush();
            
            return new RedirectResponse($this->generateUrl('edit_retiro', array('id' => $retiro->getId())));
                
        
    }
    
    public function editAction($id)
    {
        $em = $this->get('doctrine')->getManager();
        $retiro = $em->getRepository('NossisBundle:Retiro')->find($id);
            $formStock = $this->getFormStock($retiro);
            $request = $this->get('request');
            if ($request->getMethod() == 'POST'){
                $formStock->bind($request);
                $datos = $formStock->getData();
                if (($stock = $em->getRepository('NossisBundle:Stock')->findOneBy(array('codigo' => $datos['codigo']))) != null){
                    if ($stock->getArea()->getSalida()){
                                $retirostock = new RetiroStock;
                                $retirostock->setStock($stock);
                                $retirostock->setRetiro($retiro);
                                $retirostock->setCantidad($stock->getActual());
                                $retiro->addStock($retirostock);
                                //$cantidad = $stock->getIngresado() - $retirostock->getCantidad();
                                $stock->retirar($retirostock->getCantidad());
                                $em->persist($stock);
                            
                    }else{
                        $this->get('session')->getFlashBag()->add(
                            'notice',
                            'El articulo se encuentra en un area de no salida'
                        );
                    }                    
                    
                    
{'fraction_non_alphanumeric': 0.13774777362826773, 'fraction_numerical': 0.0, 'mean_word_length': 1.6166854565952649, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '976631', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1864, 'n_words': 277}