src/Controller/gmao/MouvementStockController.php line 55

Open in your IDE?
  1. <?php
  2. namespace App\Controller\gmao;
  3. use App\Entity\gmao\MouvementStock;
  4. use App\Entity\gmao\FamilleArticle;
  5. use App\Entity\gmao\Article;
  6. use App\Entity\gmao\Marque;
  7. use Symfony\Component\Validator\Constraints\Range;
  8. use App\Entity\gmao\TypeStock;
  9. use App\Form\gmao\MouvementStockType;
  10. use Doctrine\ORM\EntityRepository;
  11. use App\Repository\gmao\MouvementStockRepository;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  17. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  18. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  19. use Symfony\Component\Form\Extension\Core\Type\TextType;
  20. use App\Traits\gmao\EtatElementTrait;
  21. use App\Repository\gmao\ArticleRepository;
  22. use App\ControllerModel\user\paramUtilTrait;
  23. /**
  24.  * @Route("/mouvement/stock")
  25.  */
  26. class MouvementStockController extends AbstractController
  27. {
  28.     use EtatElementTrait;use paramUtilTrait;
  29.     
  30.     
  31.     private $response;
  32.     
  33.     public function __construct() {
  34.         $this->response = new Response();
  35.         $this->response->headers->addCacheControlDirective('no-cache'true);
  36.         $this->response->headers->addCacheControlDirective('max-age'0);
  37.         $this->response->headers->addCacheControlDirective('must-revalidate'true);
  38.         $this->response->headers->addCacheControlDirective('no-store'true);
  39.     }
  40.     
  41.     /**
  42.      * @Route("/liste", name="mvtstock_liste", methods="GET")
  43.      */
  44.     public function index(MouvementStockRepository $mouvementStockRepository): Response
  45.     {
  46.         return $this->render($this->gmaoBundleSlash($sessionData['typePresentation']). 'mouvement_stock/index.html.twig', ['mouvement_stocks' => $mouvementStockRepository->findAll()]);
  47.     }
  48.     /**
  49.      * @Route("/operation/{cas}", name="mvstock_new", methods="GET|POST" , requirements={"cas" = "\d+"})
  50.      */
  51.     public function mgstock_operation(Request $requestint $cas 0ArticleRepository $repoArtMouvementStockRepository $repoMvt ): Response
  52.     {
  53.         $this->data = array(); 
  54.     
  55.         
  56.         //var_dump( $repoArt->findArticleAjax(4,16,13)); exit;;
  57.         $form $this->createFormStock($cas);
  58.         $form->handleRequest($request);
  59.         
  60.         $this->data['form'] = $form->createView();
  61.         $this->data['cas'] = $cas;
  62.    
  63.         if ($form->isSubmitted()) {
  64.             if ($form->isValid()){
  65.                 
  66.                 $em $this->getDoctrine()->getManager();
  67.                 
  68.                 $data $form->getData();
  69.                 $article  =  ($data)?  $data['article']: NULL ;
  70.                 $nbre = (int) $data['nbre'];
  71.                 
  72.                 if ($cas>0){
  73.                     $livr $data['refliv'];
  74.                     $cmde $data['refcmde'];
  75.                 }
  76.                 
  77.                 $mrq $data['marque'];            
  78.                 
  79.                 if ($article instanceof Article){
  80.                     $mvt = new MouvementStock();
  81.                     $d = new \DateTime();
  82.                     $mvt->setHorodatage($d);
  83.                     ($cas 0)? $mvt->setQteEntree($nbre): $mvt->setQteSortie($nbre);
  84.                     $mvt->setRefMouvement($repoMvt->setMouvement());
  85.                     ($cas 0)? $lib =' Approvisionnement '.$article->getNomArticle() : $lib =' Retrait '.$article->getNomArticle();
  86.                     $mvt->setLibelle($lib);
  87.                     if ($cas>0){
  88.                     $mvt->setRefCmde($repoMvt->setCommande());
  89.                     $mvt->setRefLivr($repoMvt->setLivraison());
  90.                     }
  91.                     $mvt->setEtat(1);
  92.                     $mvt->setArticle($article);
  93.                     $em->persist($mvt);
  94.                     $em->flush();
  95.                 }
  96.                 
  97.             }else{
  98.                 
  99.             }
  100.             return $this->redirectToRoute('mvtstock_liste');
  101.             
  102.         }
  103.         
  104.         return $this->render($this->gmaoBundleSlash($sessionData['typePresentation']). 'mouvement_stock/new.html.twig'$this->data,$this->response);
  105.     }
  106.     /**
  107.      * @Route("details/{id}", name="mvtstock_details", methods="GET|POST" , requirements={"cas" = "\d+"})
  108.      */
  109.     public function mgstock_details(Request $request): Response //, MouvementStock $mouvementStock
  110.     {
  111.         return $this->render($this->gmaoBundleSlash($sessionData['typePresentation']). 'mouvement_stock/show.html.twig', ['mouvement_stock' => $mouvementStock]);
  112.     }
  113.     /**
  114.      * @Route("annule/{id}", name="mvtstock_annule", methods="GET|POST" , requirements={"cas" = "\d+"})
  115.      */
  116.     public function mgstock_annule(Request $request): Response //, MouvementStock $mouvementStock
  117.     {
  118.         $form $this->createForm(MouvementStockType::class, $mouvementStock);
  119.         $form->handleRequest($request);
  120.         if ($form->isSubmitted() && $form->isValid()) {
  121.             $this->getDoctrine()->getManager()->flush();
  122.             return $this->redirectToRoute('mouvement_stock_edit', ['id' => $mouvementStock->getId()]);
  123.         }
  124.         return $this->render($this->gmaoBundleSlash($sessionData['typePresentation']). 'mouvement_stock/edit.html.twig', [
  125.             'mouvement_stock' => $mouvementStock,
  126.             'form' => $form->createView(),
  127.         ]);
  128.     }
  129.    
  130.     
  131.     
  132.     protected function createFormStock($cas 0){
  133.         
  134.         ($cas 0)? $tab = ['Approvisionnement Equipements' => 1] : $tab = ['Sortie Equipements' => 0] ;
  135.               
  136.         $builder $this->createFormBuilder();   
  137.         
  138.         $builder->add(  'typestock'EntityType::class, array(
  139.                         'class' => TypeStock::class,
  140.                         'choice_label' => 'nomTypeStock',
  141.                         'multiple' => false,
  142.                         'expanded' => false
  143.                         'query_builder' => function (EntityRepository $rep) {
  144.                                 return $rep->createQueryBuilder('t')
  145.                                             ->AndWhere(' t.etat = 1');
  146.                         },                       
  147.                       'required' => FALSE,
  148.                       'attr' => array('required' => FALSE,'class' => 'form-control custom-select mouv typstock' ,'id'=>'client'))                    
  149.                     )     
  150.                                            
  151.                 ->add(  'famille'EntityType::class, array(
  152.                         'class' => FamilleArticle::class,
  153.                         'choice_label' => 'nomFamille',
  154.                         'multiple' => false,
  155.                         'expanded' => false
  156.                         'query_builder' => function (EntityRepository $rep) {
  157.                                 return $rep->createQueryBuilder('f')
  158.                                             ->AndWhere(' f.etat = 1');
  159.                         },
  160.                         'empty_data'=>'Veuillez sélectionner la famille',
  161.                         'required' => FALSE,
  162.                         'attr' => array('required' => TRUE'class' => 'form-control custom-select mouv famille' ,'id'=>'technic'))                    
  163.                     )                            
  164.                     
  165.                 ->add(  'marque'EntityType::class, array(
  166.                         'class' => Marque::class,
  167.                         'choice_label' => 'marqueLib',
  168.                         'multiple' => false,
  169.                         'expanded' => false,
  170.                         'empty_data'=>'Veuillez sélectionner la marque',
  171.                         'query_builder' => function (EntityRepository $rep) {
  172.                                 return $rep->createQueryBuilder('m')
  173.                                             ->AndWhere(' m.etat = 1');
  174.                         },
  175.                         
  176.                         'required' => FALSE,
  177.                         'attr' => array('required' => TRUE,'class' => 'form-control custom-select mouv marque' ,'id'=>'technic'))                    
  178.                     ) 
  179.                                 
  180. //                  ->add( 'article', EntityType::class, array(
  181. //                        'class' => Article::class,
  182. //                        'choice_label' => 'nomArticle',
  183. //                        'multiple' => false,
  184. //                        'expanded' => false,    
  185. //                        'empty_data'=>"Veuillez sélectionner l'article",
  186. //                        'required' => FALSE,
  187. //                        'attr' => array('required' => TRUE, 'class' => 'form-control custom-select mouv marque' ,'id'=>'article'))                    
  188. //                    ) 
  189. //                                
  190.  
  191.                  ->add(  'article'ChoiceType::class, array(
  192.                         'label' => 'Type Operation',  
  193.                         'attr' => array('class' => 'form-control'
  194.                                         'name' => 'typeopertion'
  195.                                         'disabled' => false,
  196.                                         'placeholder' => '''autocomplete'=>"off"),
  197.                                         )
  198.                     )                                 
  199.                                 
  200.                 ->add(  'sens'ChoiceType::class, array(
  201.                         'constraints' => new Range(array('min' => 0)),
  202.                         'label' => 'Type Operation',  
  203.                         'attr' => array('class' => 'form-control'
  204.                                         'name' => 'typeopertion'
  205.                                         'disabled' => true,
  206.                                         'placeholder' => '''autocomplete'=>"off"),
  207.                                         'choices'  => $tab)
  208.                     )  
  209.                                 
  210.                 ->add(  'reel'IntegerType::class,                         
  211.                         array(
  212.                             'constraints' => new Range(array('min' => 0'minMessage'=>'Nombre équipements du mouvement de stock ne peut être inférieur à zéro!')),
  213.                             'label' => 'reel'
  214.                             'attr' => array(
  215.                                         'required' => FALSE,
  216.                                         'min'=>0,
  217.                                         'class' => 'form-control'
  218.                                         'name' => 'reel'
  219.                                         'placeholder' => 'Nbre en stock'
  220.                                         'autocomplete'=>"off"))
  221.                     )  
  222.                 ->add(  'nbre'IntegerType::class, array(
  223.                     'label' => 'nbre'
  224.                     'attr' => array('required' => TRUE,'min'=>0,'class' => 'form-control''name' => 'nbre''placeholder' => 'Nbre mouvements''autocomplete'=>"off")))
  225.             ;      
  226.                                 
  227.             if ($cas 0){                    
  228.                 $builder->add(  'refcmde'TextType::class, array('label' => 'cmde''attr' => array('required' => FALSE,'class' => 'form-control''name' => 'nbre''placeholder' => 'Référence commande''autocomplete'=>"off")))                                
  229.                         ->add(  'refliv'TextType::class, array('label' => 'liv''attr' => array('required' => FALSE,'class' => 'form-control''name' => 'nbre''placeholder' => 'Référence livraison''autocomplete'=>"off")))  ;
  230.             }                  
  231.             
  232.             $form $builder->getForm();
  233.                         
  234.         return $form;
  235.     }
  236.     /**
  237.      * @Route("load/equipement", name="equipement_get", methods="GET")
  238.      */
  239.     public function mgstock_loadEquipement(Request $request): String
  240.     {
  241.         // etat initial
  242.         $rep = array('liste'=>[], 'msg' => 'Erreur survenue lors du traitement');
  243.         $encoders = array(new JsonEncoder());
  244.         $normalizers = array(new ObjectNormalizer());
  245.         
  246.         $serializer = new Serializer($normalizers$encoders);
  247.         $data $serializer->serialize($rep,'json');
  248.         $em $this->getDoctrine()->getManager();
  249.         if (($request->isXmlHttpRequest()) && ($request->getMethod() == 'POST')) {
  250.             $tempIds $request->request->get('sId');
  251.             $tabEl explode('|'$tempIds);
  252.             
  253.             foreach ($tabEl as $elS) {                
  254.                 if($elS !=""){ 
  255.                     $tabIds explode('_'$elS); 
  256.                     foreach ($tabIds as $key => $value) {
  257.                         if ( lowrcase($value) === 'f'){
  258.                             $idFam $tabIds[$key+1];
  259.                         }
  260.                         if ( lowrcase($value) === 'm'){
  261.                             $idMrq $tabIds[$key+1];
  262.                         }
  263.                     }
  264.                 }
  265.             }
  266.             
  267.             $repository $this->getDoctrine()->getRepository(Article::class);
  268.             $liste $repository->findArticles(0,$idMrq,$idFam);
  269.             $rep['liste'] = $liste;
  270.             $rep['msg'] = '';
  271.             $data $serializer->serialize($rep,'json');
  272.         }
  273.         return  $data;
  274.     }
  275.     
  276. }