feat: ajout entities Devis, Advert et Order liees a OrderNumber
Relations: - Devis → OrderNumber (OneToOne): chaque devis a un numero unique - Devis → Advert (OneToMany): un devis peut generer plusieurs factures pro forma - Advert → OrderNumber (OneToOne): chaque facture pro forma a un numero unique - Advert → Devis (ManyToOne, nullable): un advert peut exister sans devis - Advert → Order (OneToMany): un advert peut generer plusieurs factures - Order → OrderNumber (OneToOne): chaque facture a un numero unique - Order → Advert (ManyToOne, nullable): une facture peut exister sans advert Chaine: Devis → Advert → Order Si un advert genere plusieurs factures, le champ splitIndex (smallint) ajoute un suffixe -X au numero (ex: 04/2026-00001-1, 04/2026-00001-2). La methode getInvoiceNumber() retourne le numero complet avec suffixe. src/Entity/Devis.php: id, orderNumber (OneToOne), createdAt, adverts (OneToMany) src/Entity/Advert.php: id, orderNumber (OneToOne), devis (ManyToOne nullable), createdAt, orders (OneToMany) src/Entity/Order.php: id, orderNumber (OneToOne), advert (ManyToOne nullable), splitIndex (smallint default 0), createdAt, getInvoiceNumber() Table nommee `order` (mot reserve SQL, echappee avec backticks) src/Repository/DevisRepository.php, AdvertRepository.php, OrderRepository.php migrations/Version20260402202554.php: tables devis, advert, `order` avec foreign keys vers order_number et relations entre elles Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
50
migrations/Version20260402202554.php
Normal file
50
migrations/Version20260402202554.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20260402202554 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TABLE advert (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, order_number_id INT NOT NULL, devis_id INT DEFAULT NULL, PRIMARY KEY (id))');
|
||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_54F1F40B8C26A5E8 ON advert (order_number_id)');
|
||||
$this->addSql('CREATE INDEX IDX_54F1F40B41DEFADA ON advert (devis_id)');
|
||||
$this->addSql('CREATE TABLE devis (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, order_number_id INT NOT NULL, PRIMARY KEY (id))');
|
||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_8B27C52B8C26A5E8 ON devis (order_number_id)');
|
||||
$this->addSql('CREATE TABLE "order" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, split_index SMALLINT DEFAULT 0 NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, order_number_id INT NOT NULL, advert_id INT DEFAULT NULL, PRIMARY KEY (id))');
|
||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_F52993988C26A5E8 ON "order" (order_number_id)');
|
||||
$this->addSql('CREATE INDEX IDX_F5299398D07ECCB6 ON "order" (advert_id)');
|
||||
$this->addSql('ALTER TABLE advert ADD CONSTRAINT FK_54F1F40B8C26A5E8 FOREIGN KEY (order_number_id) REFERENCES order_number (id) NOT DEFERRABLE');
|
||||
$this->addSql('ALTER TABLE advert ADD CONSTRAINT FK_54F1F40B41DEFADA FOREIGN KEY (devis_id) REFERENCES devis (id) NOT DEFERRABLE');
|
||||
$this->addSql('ALTER TABLE devis ADD CONSTRAINT FK_8B27C52B8C26A5E8 FOREIGN KEY (order_number_id) REFERENCES order_number (id) NOT DEFERRABLE');
|
||||
$this->addSql('ALTER TABLE "order" ADD CONSTRAINT FK_F52993988C26A5E8 FOREIGN KEY (order_number_id) REFERENCES order_number (id) NOT DEFERRABLE');
|
||||
$this->addSql('ALTER TABLE "order" ADD CONSTRAINT FK_F5299398D07ECCB6 FOREIGN KEY (advert_id) REFERENCES advert (id) NOT DEFERRABLE');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE advert DROP CONSTRAINT FK_54F1F40B8C26A5E8');
|
||||
$this->addSql('ALTER TABLE advert DROP CONSTRAINT FK_54F1F40B41DEFADA');
|
||||
$this->addSql('ALTER TABLE devis DROP CONSTRAINT FK_8B27C52B8C26A5E8');
|
||||
$this->addSql('ALTER TABLE "order" DROP CONSTRAINT FK_F52993988C26A5E8');
|
||||
$this->addSql('ALTER TABLE "order" DROP CONSTRAINT FK_F5299398D07ECCB6');
|
||||
$this->addSql('DROP TABLE advert');
|
||||
$this->addSql('DROP TABLE devis');
|
||||
$this->addSql('DROP TABLE "order"');
|
||||
}
|
||||
}
|
||||
70
src/Entity/Advert.php
Normal file
70
src/Entity/Advert.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\AdvertRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: AdvertRepository::class)]
|
||||
class Advert
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\OneToOne(targetEntity: OrderNumber::class)]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private OrderNumber $orderNumber;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Devis::class, inversedBy: 'adverts')]
|
||||
#[ORM\JoinColumn(nullable: true)]
|
||||
private ?Devis $devis = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private \DateTimeImmutable $createdAt;
|
||||
|
||||
/** @var Collection<int, Order> */
|
||||
#[ORM\OneToMany(targetEntity: Order::class, mappedBy: 'advert')]
|
||||
private Collection $orders;
|
||||
|
||||
public function __construct(OrderNumber $orderNumber)
|
||||
{
|
||||
$this->orderNumber = $orderNumber;
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
$this->orders = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getOrderNumber(): OrderNumber
|
||||
{
|
||||
return $this->orderNumber;
|
||||
}
|
||||
|
||||
public function getDevis(): ?Devis
|
||||
{
|
||||
return $this->devis;
|
||||
}
|
||||
|
||||
public function setDevis(?Devis $devis): void
|
||||
{
|
||||
$this->devis = $devis;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): \DateTimeImmutable
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
/** @return Collection<int, Order> */
|
||||
public function getOrders(): Collection
|
||||
{
|
||||
return $this->orders;
|
||||
}
|
||||
}
|
||||
56
src/Entity/Devis.php
Normal file
56
src/Entity/Devis.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\DevisRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: DevisRepository::class)]
|
||||
class Devis
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\OneToOne(targetEntity: OrderNumber::class)]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private OrderNumber $orderNumber;
|
||||
|
||||
#[ORM\Column]
|
||||
private \DateTimeImmutable $createdAt;
|
||||
|
||||
/** @var Collection<int, Advert> */
|
||||
#[ORM\OneToMany(targetEntity: Advert::class, mappedBy: 'devis')]
|
||||
private Collection $adverts;
|
||||
|
||||
public function __construct(OrderNumber $orderNumber)
|
||||
{
|
||||
$this->orderNumber = $orderNumber;
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
$this->adverts = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getOrderNumber(): OrderNumber
|
||||
{
|
||||
return $this->orderNumber;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): \DateTimeImmutable
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
/** @return Collection<int, Advert> */
|
||||
public function getAdverts(): Collection
|
||||
{
|
||||
return $this->adverts;
|
||||
}
|
||||
}
|
||||
85
src/Entity/Order.php
Normal file
85
src/Entity/Order.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\OrderRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: OrderRepository::class)]
|
||||
#[ORM\Table(name: '`order`')]
|
||||
class Order
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\OneToOne(targetEntity: OrderNumber::class)]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private OrderNumber $orderNumber;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Advert::class, inversedBy: 'orders')]
|
||||
#[ORM\JoinColumn(nullable: true)]
|
||||
private ?Advert $advert = null;
|
||||
|
||||
/**
|
||||
* Suffixe pour les factures multiples sur un meme advert (-1, -2, etc.).
|
||||
*/
|
||||
#[ORM\Column(type: 'smallint', options: ['default' => 0])]
|
||||
private int $splitIndex = 0;
|
||||
|
||||
#[ORM\Column]
|
||||
private \DateTimeImmutable $createdAt;
|
||||
|
||||
public function __construct(OrderNumber $orderNumber)
|
||||
{
|
||||
$this->orderNumber = $orderNumber;
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getOrderNumber(): OrderNumber
|
||||
{
|
||||
return $this->orderNumber;
|
||||
}
|
||||
|
||||
public function getAdvert(): ?Advert
|
||||
{
|
||||
return $this->advert;
|
||||
}
|
||||
|
||||
public function setAdvert(?Advert $advert): void
|
||||
{
|
||||
$this->advert = $advert;
|
||||
}
|
||||
|
||||
public function getSplitIndex(): int
|
||||
{
|
||||
return $this->splitIndex;
|
||||
}
|
||||
|
||||
public function setSplitIndex(int $splitIndex): void
|
||||
{
|
||||
$this->splitIndex = $splitIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne le numero de facture complet.
|
||||
* Si splitIndex > 0, ajoute le suffixe -X (ex: 04/2026-00001-2).
|
||||
*/
|
||||
public function getInvoiceNumber(): string
|
||||
{
|
||||
$num = $this->orderNumber->getNumOrder();
|
||||
|
||||
return $this->splitIndex > 0 ? $num.'-'.$this->splitIndex : $num;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): \DateTimeImmutable
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
}
|
||||
18
src/Repository/AdvertRepository.php
Normal file
18
src/Repository/AdvertRepository.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Advert;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Advert>
|
||||
*/
|
||||
class AdvertRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Advert::class);
|
||||
}
|
||||
}
|
||||
18
src/Repository/DevisRepository.php
Normal file
18
src/Repository/DevisRepository.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Devis;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Devis>
|
||||
*/
|
||||
class DevisRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Devis::class);
|
||||
}
|
||||
}
|
||||
18
src/Repository/OrderRepository.php
Normal file
18
src/Repository/OrderRepository.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Order;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Order>
|
||||
*/
|
||||
class OrderRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Order::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user