diff --git a/src/Service/AdvertService.php b/src/Service/AdvertService.php new file mode 100644 index 0000000..f3224c2 --- /dev/null +++ b/src/Service/AdvertService.php @@ -0,0 +1,45 @@ +getOrderNumber() + : $this->orderNumberService->generateAndUse(); + + $advert = new Advert($orderNumber); + + if (null !== $devis) { + $advert->setDevis($devis); + } + + $this->em->persist($advert); + $this->em->flush(); + + return $advert; + } + + /** + * Cree un advert a partir d'un devis existant (meme numero). + */ + public function createFromDevis(Devis $devis): Advert + { + return $this->create($devis); + } +} diff --git a/src/Service/DevisService.php b/src/Service/DevisService.php new file mode 100644 index 0000000..820ecf4 --- /dev/null +++ b/src/Service/DevisService.php @@ -0,0 +1,29 @@ +orderNumberService->generateAndUse(); + $devis = new Devis($orderNumber); + + $this->em->persist($devis); + $this->em->flush(); + + return $devis; + } +} diff --git a/src/Service/FactureService.php b/src/Service/FactureService.php new file mode 100644 index 0000000..6dba0b9 --- /dev/null +++ b/src/Service/FactureService.php @@ -0,0 +1,60 @@ +createFromAdvert($advert); + } + + $orderNumber = $this->orderNumberService->generateAndUse(); + $facture = new Facture($orderNumber); + + $this->em->persist($facture); + $this->em->flush(); + + return $facture; + } + + /** + * Cree une facture a partir d'un advert (meme numero + splitIndex si plusieurs). + */ + public function createFromAdvert(Advert $advert): Facture + { + $existingCount = $advert->getFactures()->count(); + + $facture = new Facture($advert->getOrderNumber()); + $facture->setAdvert($advert); + + if ($existingCount > 0) { + $facture->setSplitIndex($existingCount + 1); + + // La premiere facture existante doit aussi avoir un splitIndex si elle n'en a pas + $firstFacture = $advert->getFactures()->first(); + if (false !== $firstFacture && 0 === $firstFacture->getSplitIndex()) { + $firstFacture->setSplitIndex(1); + } + } + + $this->em->persist($facture); + $this->em->flush(); + + return $facture; + } +}