示例#1
0
 /**
  * @Route("/societe/{societe}/creation/{type}", name="facture_creation")
  * @ParamConverter("societe", class="AppBundle:Societe")
  */
 public function creationAction(Request $request, Societe $societe, $type)
 {
     $dm = $this->get('doctrine_mongodb')->getManager();
     $cm = $this->get('configuration.manager');
     $fm = $this->get('facture.manager');
     if ($request->get('id')) {
         $facture = $fm->getRepository()->findOneById($request->get('id'));
     }
     if ($request->get('id') && !$facture) {
         throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException(sprintf("La facture %s n'a pas été trouvé", $request->get('id')));
     }
     if (!isset($facture)) {
         $facture = $fm->createVierge($societe);
         $factureLigne = new FactureLigne();
         $factureLigne->setTauxTaxe(0.2);
         $facture->addLigne($factureLigne);
     }
     $facture->setSociete($societe);
     if (!$facture->getId()) {
         $facture->setDateEmission(new \DateTime());
     }
     $commercial = $dm->getRepository('AppBundle:Compte')->findOneByIdentifiant('003480005');
     $facture->setCommercial($commercial);
     if ($type == "devis" && !$facture->getDateDevis()) {
         $facture->setDateDevis(new \DateTime());
     } elseif ($type == "facture" && !$facture->getDateFacturation()) {
         $facture->setDateFacturation(new \DateTime());
     }
     $produitsSuggestion = array();
     foreach ($cm->getConfiguration()->getProduits() as $produit) {
         $produitsSuggestion[] = array("libelle" => $produit->getNom(), "conditionnement" => $produit->getConditionnement(), "identifiant" => $produit->getIdentifiant(), "prix" => $produit->getPrixVente());
     }
     $form = $this->createForm(new FactureType($dm, $cm, $facture->isDevis()), $facture, array('action' => "", 'method' => 'POST'));
     $form->handleRequest($request);
     if (!$form->isSubmitted() || !$form->isValid()) {
         return $this->render('facture/libre.html.twig', array('form' => $form->createView(), 'produitsSuggestion' => $produitsSuggestion, 'societe' => $societe, 'facture' => $facture));
     }
     $facture->update();
     if ($request->get('previsualiser')) {
         return $this->pdfAction($request, $facture);
     }
     if (!$facture->getId()) {
         $dm->persist($facture);
     } elseif ($facture->isFacture() && !$facture->getNumeroFacture()) {
         $fm->getRepository()->getClassMetadata()->idGenerator->generateNumeroFacture($dm, $facture);
     }
     $dm->flush();
     return $this->redirectToRoute('facture_societe', array('id' => $societe->getId()));
 }
示例#2
0
 public function create(Societe $societe, $mouvements, $dateFacturation)
 {
     $facture = new Facture();
     $facture->setSociete($societe);
     $facture->setDateFacturation($dateFacturation);
     $facture->setDateEmission(new \DateTime());
     $facture->getEmetteur()->setNom($this->parameters['emetteur']['nom']);
     $facture->getEmetteur()->setAdresse($this->parameters['emetteur']['adresse']);
     $facture->getEmetteur()->setCodePostal($this->parameters['emetteur']['code_postal']);
     $facture->getEmetteur()->setCommune($this->parameters['emetteur']['commune']);
     $facture->getEmetteur()->setTelephone($this->parameters['emetteur']['telephone']);
     $facture->getEmetteur()->setFax($this->parameters['emetteur']['fax']);
     $facture->getEmetteur()->setEmail($this->parameters['emetteur']['email']);
     foreach ($mouvements as $mouvement) {
         if (!$mouvement->isFacturable() || $mouvement->isFacture()) {
             continue;
         }
         $ligne = new FactureLigne();
         $ligne->pullFromMouvement($mouvement);
         $facture->addLigne($ligne);
     }
     $facture->update();
     $facture->facturerMouvements();
     return $facture;
 }