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:
Serreau Jovann
2026-04-02 22:26:15 +02:00
parent cacd3ac66c
commit 3bda43c72f
7 changed files with 315 additions and 0 deletions

View 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"');
}
}