Quantcast
Channel: Grafikart | Derniers Sujets du forum
Viewing all articles
Browse latest Browse all 13822

[symfony 4] Création de livraisonController.php

$
0
0

Bonjour,

Je suis sur une application de gestion de vente. J'ai fais le CommandeController.php (voir ci-dessous). Je suis bloqué sur la partie LivraisonController.php, je ne sais pas comment faire le lien entre les deux Controller, en gros je ne sais pas comment faire la partie livraison.
Merci d'avance de votre aide

Ce que je fais

Voic mon code CommandeController.php

public function new(Request $request, Commande $commande = null, LigneCommande $lignecommande = null, ProduitRepository $produitRepository)
{

    $repo = $this->getDoctrine()->getRepository(Compteur::class);
    $compteur = $repo->find(1);
    $numcom = $compteur->getNumCom();

    if (!$commande && !$lignecommande) {
        $commande = new Commande();
        $lignecommande = new LigneCommande();
    }

    $form = $this->createForm(CommandeType::class, $commande);
    $form->handleRequest($request);

    $f = $this->createForm(LigneCommandeType::class, $lignecommande);
    $f->handleRequest($request);

    $tva = 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++) {
                $lignecommande = new LigneCommande();
                $commande->addNumCom($lignecommande);
                $prod = $produitRepository->findOneBy(['id' => $tabcom[$i]->getProduits()]);
                $lignecommande->setProduits($prod);
                $lignecommande->setCommandes($commande);
                $lignecommande->setLigne($i);
                $lignecommande->setPu($tabcom[$i]->getPu());
                $lignecommande->setQuantite($tabcom[$i]->getQuantite());
                $lignecommande->setTva($tabcom[$i]->getTva());
                $em->persist($lignecommande);
                $mht = $tabcom[$i]->getPu() * $tabcom[$i]->getQuantite();
                $tva = $mht * ($tabcom[$i]->getTva()) * 0.01;
                $tht = $tht + $mht;
                $ttva = $ttva + $tva;
                $ttc = $ttc + ($tht + $ttva);
            }

            $commande->setTht($tht);
            $commande->setTtva($ttva);
            $commande->setDateCommandeAt(new \DateTime());
            $commande->setStatut(true);
            $commande->setTttc($ttc);


            $em->persist($commande);

            $compteur->setNumCom($numcom + 1);
            $em->persist($compteur);

            $em->flush();

            return $this->redirectToRoute('liste.commande');
        } elseif ($choix == "Ajouter") {
            $mht = $lignecommande->getPu() * $lignecommande->getQuantite();
            $lig = sizeof($tabcom) + 1;
            $lignecommande->setLigne($lig);
            $tabcom[$lig] = $lignecommande;
            $session->set('commande', $tabcom);
        }
    }
    return $this->render('commande/new.html.twig', [
        'commande' => $commande,
        'lcomm' => $tabcom,
        'form' => $form->createView(),
        'f' => $f->createView(),
        'numcom' => $numcom,
        'tht' => $tht,
        'ttva' => $ttva,
        'mht' => $mht,
        'lig' => $lig,
        'ttc' => $ttc,
        'LigneCommande' => $lignecommande,
        'prod' => $produitRepository->findAll(),
    ]);
}

Viewing all articles
Browse latest Browse all 13822

Latest Images

Trending Articles