svg
This commit is contained in:
54
src/EventSubscriber/CompanySubscriber.php
Normal file
54
src/EventSubscriber/CompanySubscriber.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventSubscriber;
|
||||
|
||||
use App\Entity\Accounting;
|
||||
use App\Entity\Company;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Event\PostPersistEventArgs;
|
||||
use Doctrine\ORM\Events;
|
||||
|
||||
class CompanySubscriber
|
||||
{
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user