em = $em; } public function postPersist(PostPersistEventArgs $args): void { $company = $args->getObject(); if (!$company instanceof Company) { return; } $entityManager = $args->getObjectManager(); // Génération des accounting par défaut $this->insertAccounting($company,"512","000","Banque",true); $this->insertAccounting($company,"530","000","Caisse",true); $this->insertAccounting($company,"600","000","Charge",false); $this->insertAccounting($company,"700","000","Produit",false); // Génération du year par } private function insertAccounting(Company $company,string $num01, string $num02, string $title, bool $isactif): void { $accounting=$this->em->getRepository("App\Entity\Accounting")->findOneBy(["company"=>$company,"num01"=>$num01,"num02"=>$num02]); if(!$accounting) { $accounting = new Accounting; $accounting->setCompany($company); $accounting->setNum01($num01); $accounting->setNum02($num02); $accounting->setTitle($title); $accounting->SetActif($isactif); $this->em->persist($accounting); $this->em->flush(); } } }