public function ValidateCmdAction()
 {
     $em = $this->getDoctrine()->getManager();
     $request = $this->get('request');
     $service = $this->get('tools.utils');
     $session = $request->getSession();
     if ($session->has('client')) {
         $caddy = $this->getCaddy($session);
         $clientid = $session->get('client');
         $client = $this->getDoctrine()->getRepository('MainFrontBundle:client')->find($clientid);
         $cmd = new command();
         if ($session->has('tpl')) {
             $tpl = $session->get('tpl');
             //echo "<pre>";print_r($tpl);exit;
             $cmd->setToprint($tpl);
         }
         $cmd->setClient($client);
         $dt = new \DateTime();
         $nbcmd = $this->getDoctrine()->getRepository("MainFrontBundle:command")->findAll();
         $ref = $dt->format("Ymd") . (count($nbcmd) + 1);
         $cmd->setRef($ref);
         $em->persist($cmd);
         foreach ($caddy as $line) {
             $ordetail = new cmdorder();
             $prod = $line['prod'];
             $ordetail->setProdid($prod);
             $ordetail->setCmd($cmd);
             $ordetail->setQte(1);
             $ordetail->setPrice($line['opt']);
             $em->persist($ordetail);
         }
         $em->flush();
         return $this->render('MainFrontBundle:Page:validateCmd.html.twig', array("panier" => $caddy, "cmd" => $cmd, "client" => $client));
     } else {
         return $this->redirect($this->generateUrl('login_Page'));
     }
 }