1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| /**
* @Route("/new", name="commande_new", methods={"GET","POST"})
* @Route("/{NumComd}/edit", name="commande_modification", methods={"GET","POST"})
*/
public function new(Request $request, User $user=null, Commande $commande=null, Lcommande $lcommande=null, ProduitRepository $produitRepository): Response
{
$repo = $this->getDoctrine()->getRepository(Compteur::class);
$compteur = $repo->find(1);
$numcom = $compteur->getNumCom();
if (!$commande && !$lcommande) {
$commande = new Commande();
$lcommande = new Lcommande();
}
$form = $this->createForm(CommandeType::class, $commande);
$form->handleRequest($request);
$f = $this->createForm(LcommandeType::class, $lcommande);
$f->handleRequest($request);
$tva = 0;
$qte = 0;
$pxu = 0;
$mht = 0;
$lig = 0;
$ttc = 0;
$tht = 0;
$ttva = 0;
$session = $request->getSession();
if (!$session->has('commande')) {
$session->set('commande', []);
}
$choix = "";
$tabcom = $session->get('commande', []);
if ($form->isSubmitted() || $f->isSubmitted()) {
$choix = $request->get('bt');
if ($choix == "Valider") {
$em = $this->getDoctrine()->getManager();
$lig = sizeof($tabcom);
for ($i = 1; $i<=$lig; $i++) {
$lcommande = new Lcommande();
$commande->addNumCom($lcommande);
$prod = $produitRepository->findOneBy(['id'=>$tabcom[$i]->getProduits() ]);
$lcommande->setProduits($prod);
$lcommande->setNumComd($commande);
$lcommande->setLig($i);
$lcommande->setPrixUnitaire($tabcom[$i]->getPrixUnitaire());
$lcommande->setQuantite($tabcom[$i]->getQuantite());
$lcommande->setTVA($tabcom[$i]->getTVA());
$lcommande->setCreatedAt(new \DateTime());
$em->persist($lcommande);
$mht = $tabcom[$i]->getPrixUnitaire()*$tabcom[$i]->getQuantite();
$tva = $mht * ($tabcom[$i]->getTVA())*0.01;
$tht = $tht + $mht;
$ttva = $ttva + $tva;
$ttc = $ttc + ($tht + $ttva);
}
$commande->setNumCommande($numcom);
$commande->setPHTC($tht);
$commande->setTVA($ttva);
$commande->setCreatedAt(new \DateTime());
$commande->setStatut(false);
$commande->setLivratedAt(new \DateTime());
$commande->setPTTC($ttc);
$em->persist($commande);
$compteur->setNumCom($numcom+1);
$em->persist($compteur);
$em->flush();
return $this->redirectToRoute('commande_show', ['id'=>$commande->getId()]);
} elseif ($choix == "Ajouter") {
$mht = $lcommande->getPrixUnitaire()*$lcommande->getQuantite();
$lig = sizeof($tabcom)+1;
//$lcommande->setNumComd($commande);
$lcommande->setLig($lig);
$tabcom[$lig] = $lcommande;
$session->set('commande', $tabcom);
$this->get('session')->getFlashBag()->add('notice', 'Ajoute avec success ✅');
}
}
$log = $this->getUser();
return $this->render('commande/new.html.twig', [
'commande' => $commande,
'user'=>$log,
'lcomm'=>$tabcom,
'form' => $form->createView(),
'f' => $f->createView(),
'numcom'=>$numcom,
'tht'=>$tht,
'ttva'=>$ttva,
'mht'=>$mht,
'lig'=>$lig,
'ttc'=>$ttc,
'lcommande' => $lcommande,
'prod' => $produitRepository->findAll(),
//'editMode'=>$commande->getId() !== null,
//'editMode1'=>$lcommande->getNumComd() !== null,
]);
} |
Partager