Finalisation réception marchandise, ajout de composant UI et ajout de fixtures (!7)
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [x] Pas de régression - [ ] TU/TI/TF rédigée - [x] TU/TI/TF OK - [x] CHANGELOG modifié Reviewed-on: https://gitea.malio.fr/MALIO-DEV/Ferme/pulls/7 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit is contained in:
@@ -0,0 +1,256 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\Address;
|
||||
use App\Entity\Building;
|
||||
use App\Entity\Carrier;
|
||||
use App\Entity\Driver;
|
||||
use App\Entity\MerchandiseType;
|
||||
use App\Entity\PelletType;
|
||||
use App\Entity\ReceptionType;
|
||||
use App\Entity\Supplier;
|
||||
use App\Entity\Truck;
|
||||
use App\Entity\Vehicle;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'app:seed',
|
||||
description: 'Seed reference data (idempotent).'
|
||||
)]
|
||||
class SeedCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$created = 0;
|
||||
$updated = 0;
|
||||
|
||||
$truckRepo = $this->entityManager->getRepository(Truck::class);
|
||||
$carrierRepo = $this->entityManager->getRepository(Carrier::class);
|
||||
$driverRepo = $this->entityManager->getRepository(Driver::class);
|
||||
$vehicleRepo = $this->entityManager->getRepository(Vehicle::class);
|
||||
$merchandiseTypeRepo = $this->entityManager->getRepository(MerchandiseType::class);
|
||||
$pelletTypeRepo = $this->entityManager->getRepository(PelletType::class);
|
||||
$buildingRepo = $this->entityManager->getRepository(Building::class);
|
||||
$receptionTypeRepo = $this->entityManager->getRepository(ReceptionType::class);
|
||||
$addressRepo = $this->entityManager->getRepository(Address::class);
|
||||
$supplierRepo = $this->entityManager->getRepository(Supplier::class);
|
||||
|
||||
$upsertByCode = function (string $entityClass, string $code, callable $apply) use (&$created, &$updated) {
|
||||
$repo = $this->entityManager->getRepository($entityClass);
|
||||
$entity = $repo->findOneBy(['code' => $code]);
|
||||
if (!$entity) {
|
||||
$entity = new $entityClass();
|
||||
++$created;
|
||||
} else {
|
||||
++$updated;
|
||||
}
|
||||
$apply($entity);
|
||||
$this->entityManager->persist($entity);
|
||||
|
||||
return $entity;
|
||||
};
|
||||
|
||||
$upsertByName = function (string $entityClass, string $name, callable $apply) use (&$created, &$updated) {
|
||||
$repo = $this->entityManager->getRepository($entityClass);
|
||||
$entity = $repo->findOneBy(['name' => $name]);
|
||||
if (!$entity) {
|
||||
$entity = new $entityClass();
|
||||
++$created;
|
||||
} else {
|
||||
++$updated;
|
||||
}
|
||||
$apply($entity);
|
||||
$this->entityManager->persist($entity);
|
||||
|
||||
return $entity;
|
||||
};
|
||||
|
||||
$trucks = ['Citerne', 'Porteur'];
|
||||
$citerne = null;
|
||||
$porteur = null;
|
||||
foreach ($trucks as $name) {
|
||||
$truck = $upsertByName(Truck::class, $name, static fn (Truck $truck) => $truck->setName($name));
|
||||
if ('Citerne' === $name) {
|
||||
$citerne = $truck;
|
||||
}
|
||||
if ('Porteur' === $name) {
|
||||
$porteur = $truck;
|
||||
}
|
||||
}
|
||||
|
||||
$carriers = [
|
||||
['name' => 'LIOT', 'code' => 'LIOT'],
|
||||
['name' => 'LUI-MEME', 'code' => 'LUI-MEME'],
|
||||
];
|
||||
$liot = null;
|
||||
foreach ($carriers as $carrierData) {
|
||||
$carrier = $upsertByCode(Carrier::class, $carrierData['code'], static function (Carrier $carrier) use ($carrierData) {
|
||||
$carrier
|
||||
->setName($carrierData['name'])
|
||||
->setCode($carrierData['code'])
|
||||
;
|
||||
});
|
||||
if ('LIOT' === $carrierData['code']) {
|
||||
$liot = $carrier;
|
||||
}
|
||||
}
|
||||
|
||||
if ($liot && $citerne && $porteur) {
|
||||
$drivers = ['Eddy', 'Jean-Christophe', 'Etienne', 'Hersand'];
|
||||
foreach ($drivers as $name) {
|
||||
$driver = $driverRepo->findOneBy(['name' => $name, 'carrier' => $liot]);
|
||||
if (!$driver) {
|
||||
$driver = new Driver();
|
||||
++$created;
|
||||
} else {
|
||||
++$updated;
|
||||
}
|
||||
$driver
|
||||
->setName($name)
|
||||
->setCarrier($liot)
|
||||
;
|
||||
$this->entityManager->persist($driver);
|
||||
}
|
||||
|
||||
$vehicles = [
|
||||
['plate' => 'GH-684-VZ', 'truck' => $citerne],
|
||||
['plate' => 'FW-363-EC', 'truck' => $porteur],
|
||||
['plate' => 'FW-370-EC', 'truck' => $porteur],
|
||||
['plate' => 'FW-375-EC', 'truck' => $porteur],
|
||||
['plate' => 'FY-952-HS', 'truck' => $porteur],
|
||||
];
|
||||
foreach ($vehicles as $vehicleData) {
|
||||
$vehicle = $vehicleRepo->findOneBy(['plate' => $vehicleData['plate']]);
|
||||
if (!$vehicle) {
|
||||
$vehicle = new Vehicle();
|
||||
++$created;
|
||||
} else {
|
||||
++$updated;
|
||||
}
|
||||
$vehicle
|
||||
->setPlate($vehicleData['plate'])
|
||||
->setCarrier($liot)
|
||||
->setTruck($vehicleData['truck'])
|
||||
;
|
||||
$this->entityManager->persist($vehicle);
|
||||
}
|
||||
} else {
|
||||
$io->warning('Transport data not fully available; drivers/vehicles skipped.');
|
||||
}
|
||||
|
||||
$merchandiseTypes = [
|
||||
['label' => 'Foin', 'code' => 'FOIN'],
|
||||
['label' => 'Paille', 'code' => 'PAILLE'],
|
||||
['label' => 'Granule', 'code' => 'GRANULE'],
|
||||
];
|
||||
foreach ($merchandiseTypes as $type) {
|
||||
$upsertByCode(MerchandiseType::class, $type['code'], static function (MerchandiseType $entity) use ($type) {
|
||||
$entity
|
||||
->setLabel($type['label'])
|
||||
->setCode($type['code'])
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
$pelletTypes = [
|
||||
['label' => 'JB croissance', 'code' => 'K750'],
|
||||
['label' => 'Genisse herbe', 'code' => 'K500'],
|
||||
['label' => 'Bovistart melasse ferme', 'code' => 'K130'],
|
||||
['label' => 'Bovin mise en forme', 'code' => 'K400'],
|
||||
];
|
||||
foreach ($pelletTypes as $type) {
|
||||
$upsertByCode(PelletType::class, $type['code'], static function (PelletType $entity) use ($type) {
|
||||
$entity
|
||||
->setLabel($type['label'])
|
||||
->setCode($type['code'])
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
$buildings = [
|
||||
['label' => 'Bâtiment 1', 'code' => 'B1'],
|
||||
['label' => 'Bâtiment 2', 'code' => 'B2'],
|
||||
['label' => 'Bâtiment 3', 'code' => 'B3'],
|
||||
];
|
||||
foreach ($buildings as $buildingData) {
|
||||
$upsertByCode(Building::class, $buildingData['code'], static function (Building $entity) use ($buildingData) {
|
||||
$entity
|
||||
->setLabel($buildingData['label'])
|
||||
->setCode($buildingData['code'])
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
$receptionTypes = [
|
||||
['label' => 'Marchandises', 'code' => 'MARCHANDISES'],
|
||||
['label' => 'Bovins', 'code' => 'BOVINS'],
|
||||
];
|
||||
foreach ($receptionTypes as $type) {
|
||||
$upsertByCode(ReceptionType::class, $type['code'], static function (ReceptionType $entity) use ($type) {
|
||||
$entity
|
||||
->setLabel($type['label'])
|
||||
->setCode($type['code'])
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
$address = $addressRepo->findOneBy([
|
||||
'label' => 'LIOT CHATELLERAULT',
|
||||
'postalCode' => '86100',
|
||||
]);
|
||||
if (!$address) {
|
||||
$address = new Address();
|
||||
++$created;
|
||||
} else {
|
||||
++$updated;
|
||||
}
|
||||
$address
|
||||
->setLabel('LIOT CHATELLERAULT')
|
||||
->setStreet("14 Allée d'Argenson")
|
||||
->setStreet2('ZI Nord')
|
||||
->setPostalCode('86100')
|
||||
->setCity('CHATELLERAULT')
|
||||
->setCountryCode('FR')
|
||||
;
|
||||
$this->entityManager->persist($address);
|
||||
|
||||
$supplier = $supplierRepo->findOneBy(['name' => 'LIOT']);
|
||||
if (!$supplier) {
|
||||
$supplier = new Supplier();
|
||||
++$created;
|
||||
} else {
|
||||
++$updated;
|
||||
}
|
||||
$supplier
|
||||
->setName('LIOT')
|
||||
->setEmail('lpc.contacts@lpc-liot.fr')
|
||||
->setPhone('05.49.20.09.10')
|
||||
;
|
||||
if (!$supplier->getAddresses()->contains($address)) {
|
||||
$supplier->getAddresses()->add($address);
|
||||
}
|
||||
$this->entityManager->persist($supplier);
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
$io->success(sprintf('Seed completed: %d created, %d updated.', $created, $updated));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\DataFixtures;
|
||||
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
class AppFixtures extends Fixture implements DependentFixtureInterface
|
||||
{
|
||||
public function load(ObjectManager $manager): void
|
||||
{
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
public function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
TransportFixtures::class,
|
||||
ReferenceFixtures::class,
|
||||
SupplierFixtures::class,
|
||||
UserFixtures::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\DataFixtures;
|
||||
|
||||
use App\Entity\Building;
|
||||
use App\Entity\MerchandiseType;
|
||||
use App\Entity\PelletType;
|
||||
use App\Entity\ReceptionType;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
class ReferenceFixtures extends Fixture
|
||||
{
|
||||
public function load(ObjectManager $manager): void
|
||||
{
|
||||
$merchandiseTypes = [
|
||||
['label' => 'Foin', 'code' => 'FOIN'],
|
||||
['label' => 'Paille', 'code' => 'PAILLE'],
|
||||
['label' => 'Granule', 'code' => 'GRANULE'],
|
||||
];
|
||||
foreach ($merchandiseTypes as $type) {
|
||||
$merchandiseType = new MerchandiseType()
|
||||
->setLabel($type['label'])
|
||||
->setCode($type['code'])
|
||||
;
|
||||
$manager->persist($merchandiseType);
|
||||
}
|
||||
|
||||
$pelletTypes = [
|
||||
['label' => 'JB croissance', 'code' => 'K750'],
|
||||
['label' => 'Genisse herbe', 'code' => 'K500'],
|
||||
['label' => 'Bovistart melasse ferme', 'code' => 'K130'],
|
||||
['label' => 'Bovin mise en forme', 'code' => 'K400'],
|
||||
];
|
||||
foreach ($pelletTypes as $type) {
|
||||
$pelletType = new PelletType()
|
||||
->setLabel($type['label'])
|
||||
->setCode($type['code'])
|
||||
;
|
||||
$manager->persist($pelletType);
|
||||
}
|
||||
|
||||
$buildings = [
|
||||
['label' => 'Bâtiment 1', 'code' => 'B1'],
|
||||
['label' => 'Bâtiment 2', 'code' => 'B2'],
|
||||
['label' => 'Bâtiment 3', 'code' => 'B3'],
|
||||
];
|
||||
foreach ($buildings as $buildingData) {
|
||||
$building = new Building()
|
||||
->setLabel($buildingData['label'])
|
||||
->setCode($buildingData['code'])
|
||||
;
|
||||
$manager->persist($building);
|
||||
}
|
||||
|
||||
$receptionTypes = [
|
||||
['label' => 'Marchandises', 'code' => 'MARCHANDISES'],
|
||||
['label' => 'Bovins', 'code' => 'BOVINS'],
|
||||
];
|
||||
foreach ($receptionTypes as $type) {
|
||||
$receptionType = new ReceptionType()
|
||||
->setLabel($type['label'])
|
||||
->setCode($type['code'])
|
||||
;
|
||||
$manager->persist($receptionType);
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\DataFixtures;
|
||||
|
||||
use App\Entity\Address;
|
||||
use App\Entity\Supplier;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
class SupplierFixtures extends Fixture
|
||||
{
|
||||
public function load(ObjectManager $manager): void
|
||||
{
|
||||
$address = new Address()
|
||||
->setLabel('LIOT CHATELLERAULT')
|
||||
->setStreet("14 Allée d'Argenson")
|
||||
->setStreet2('ZI Nord')
|
||||
->setPostalCode('86100')
|
||||
->setCity('CHATELLERAULT')
|
||||
->setCountryCode('FR')
|
||||
;
|
||||
|
||||
$supplier = new Supplier()
|
||||
->setName('LIOT')
|
||||
->setEmail('lpc.contacts@lpc-liot.fr')
|
||||
->setPhone('05.49.20.09.10')
|
||||
;
|
||||
|
||||
$supplier->getAddresses()->add($address);
|
||||
|
||||
$manager->persist($address);
|
||||
$manager->persist($supplier);
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\DataFixtures;
|
||||
|
||||
use App\Entity\Carrier;
|
||||
use App\Entity\Driver;
|
||||
use App\Entity\Truck;
|
||||
use App\Entity\Vehicle;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
class TransportFixtures extends Fixture
|
||||
{
|
||||
public function load(ObjectManager $manager): void
|
||||
{
|
||||
$citerne = new Truck()->setName('Citerne');
|
||||
$porteur = new Truck()->setName('Porteur');
|
||||
|
||||
$manager->persist($citerne);
|
||||
$manager->persist($porteur);
|
||||
|
||||
$liot = new Carrier()
|
||||
->setName('LIOT')
|
||||
->setCode('LIOT')
|
||||
;
|
||||
$luiMeme = new Carrier()
|
||||
->setName('LUI-MEME')
|
||||
->setCode('LUI-MEME')
|
||||
;
|
||||
|
||||
$manager->persist($liot);
|
||||
$manager->persist($luiMeme);
|
||||
|
||||
$drivers = ['Eddy', 'Jean-Christophe', 'Etienne', 'Hersand'];
|
||||
foreach ($drivers as $name) {
|
||||
$driver = new Driver()
|
||||
->setName($name)
|
||||
->setCarrier($liot)
|
||||
;
|
||||
$manager->persist($driver);
|
||||
}
|
||||
|
||||
$citerneVehicle = new Vehicle()
|
||||
->setPlate('GH-684-VZ')
|
||||
->setCarrier($liot)
|
||||
->setTruck($citerne)
|
||||
;
|
||||
$manager->persist($citerneVehicle);
|
||||
|
||||
$porteurPlates = ['FW-363-EC', 'FW-370-EC', 'FW-375-EC', 'FY-952-HS'];
|
||||
foreach ($porteurPlates as $plate) {
|
||||
$vehicle = new Vehicle()
|
||||
->setPlate($plate)
|
||||
->setCarrier($liot)
|
||||
->setTruck($porteur)
|
||||
;
|
||||
$manager->persist($vehicle);
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\DataFixtures;
|
||||
|
||||
use App\Entity\User;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
class UserFixtures extends Fixture
|
||||
{
|
||||
public function load(ObjectManager $manager): void
|
||||
{
|
||||
$admin = new User()
|
||||
->setUsername('admin')
|
||||
->setRoles(['ROLE_ADMIN'])
|
||||
;
|
||||
|
||||
$admin->setPassword(
|
||||
'$2y$13$ZuB4LRD1i5Arc34CEO54FeUyQaIf3jamLf6caFK9v8TBMA5RcmIke'
|
||||
);
|
||||
|
||||
$manager->persist($admin);
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'address')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
requirements: ['id' => '\d+'],
|
||||
normalizationContext: ['groups' => ['address:read']],
|
||||
),
|
||||
new GetCollection(
|
||||
normalizationContext: ['groups' => ['address:read']],
|
||||
),
|
||||
],
|
||||
security: "is_granted('ROLE_USER')",
|
||||
)]
|
||||
class Address
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['address:read', 'supplier:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 120)]
|
||||
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||
private string $label = '';
|
||||
|
||||
#[ORM\Column(length: 180)]
|
||||
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||
private string $street = '';
|
||||
|
||||
#[ORM\Column(name: 'street2', length: 180, nullable: true)]
|
||||
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||
private ?string $street2 = null;
|
||||
|
||||
#[ORM\Column(name: 'postal_code', length: 20)]
|
||||
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||
private string $postalCode = '';
|
||||
|
||||
#[ORM\Column(length: 120)]
|
||||
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||
private string $city = '';
|
||||
|
||||
#[ORM\Column(name: 'country_code', length: 2)]
|
||||
#[Groups(['address:read', 'supplier:read'])]
|
||||
private string $countryCode = '';
|
||||
|
||||
/**
|
||||
* @var Collection<int, Supplier>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Supplier::class, mappedBy: 'addresses')]
|
||||
private Collection $suppliers;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->suppliers = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setLabel(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStreet(): string
|
||||
{
|
||||
return $this->street;
|
||||
}
|
||||
|
||||
public function setStreet(string $street): self
|
||||
{
|
||||
$this->street = $street;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStreet2(): ?string
|
||||
{
|
||||
return $this->street2;
|
||||
}
|
||||
|
||||
public function setStreet2(?string $street2): self
|
||||
{
|
||||
$this->street2 = $street2;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPostalCode(): string
|
||||
{
|
||||
return $this->postalCode;
|
||||
}
|
||||
|
||||
public function setPostalCode(string $postalCode): self
|
||||
{
|
||||
$this->postalCode = $postalCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCity(): string
|
||||
{
|
||||
return $this->city;
|
||||
}
|
||||
|
||||
public function setCity(string $city): self
|
||||
{
|
||||
$this->city = $city;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCountryCode(): string
|
||||
{
|
||||
return $this->countryCode;
|
||||
}
|
||||
|
||||
public function setCountryCode(string $countryCode): self
|
||||
{
|
||||
$this->countryCode = $countryCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||
public function getFullAddress(): string
|
||||
{
|
||||
$parts = array_filter([
|
||||
$this->street,
|
||||
$this->street2,
|
||||
trim(sprintf('%s %s', $this->postalCode, $this->city)),
|
||||
]);
|
||||
|
||||
return implode(', ', $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Supplier>
|
||||
*/
|
||||
public function getSuppliers(): Collection
|
||||
{
|
||||
return $this->suppliers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'building')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
requirements: ['id' => '\d+'],
|
||||
normalizationContext: ['groups' => ['building:read']],
|
||||
),
|
||||
new GetCollection(
|
||||
normalizationContext: ['groups' => ['building:read']],
|
||||
),
|
||||
],
|
||||
security: "is_granted('ROLE_USER')",
|
||||
)]
|
||||
class Building
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['building:read', 'reception:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 120)]
|
||||
#[Groups(['building:read', 'reception:read'])]
|
||||
private string $label = '';
|
||||
|
||||
#[ORM\Column(length: 50)]
|
||||
#[Groups(['building:read', 'reception:read'])]
|
||||
private string $code = '';
|
||||
|
||||
/**
|
||||
* @var Collection<int, Reception>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Reception::class, mappedBy: 'buildings')]
|
||||
private Collection $receptions;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->receptions = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setLabel(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCode(): string
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function setCode(string $code): self
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Reception>
|
||||
*/
|
||||
public function getReceptions(): Collection
|
||||
{
|
||||
return $this->receptions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'carrier')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
requirements: ['id' => '\d+'],
|
||||
normalizationContext: ['groups' => ['carrier:read']],
|
||||
),
|
||||
new GetCollection(
|
||||
normalizationContext: ['groups' => ['carrier:read']],
|
||||
),
|
||||
],
|
||||
security: "is_granted('ROLE_USER')",
|
||||
)]
|
||||
class Carrier
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['carrier:read', 'driver:read', 'vehicle:read', 'reception:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 180)]
|
||||
#[Groups(['carrier:read', 'driver:read', 'vehicle:read', 'reception:read'])]
|
||||
private string $name = '';
|
||||
|
||||
#[ORM\Column(length: 30, nullable: true)]
|
||||
#[Groups(['carrier:read', 'driver:read', 'vehicle:read', 'reception:read'])]
|
||||
private ?string $code = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCode(): ?string
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function setCode(?string $code): self
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'driver')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
requirements: ['id' => '\d+'],
|
||||
normalizationContext: ['groups' => ['driver:read']],
|
||||
),
|
||||
new GetCollection(
|
||||
normalizationContext: ['groups' => ['driver:read']],
|
||||
),
|
||||
],
|
||||
security: "is_granted('ROLE_USER')",
|
||||
)]
|
||||
class Driver
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['driver:read', 'reception:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 180)]
|
||||
#[Groups(['driver:read', 'reception:read'])]
|
||||
private string $name = '';
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[Groups(['driver:read'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
private ?Carrier $carrier = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCarrier(): ?Carrier
|
||||
{
|
||||
return $this->carrier;
|
||||
}
|
||||
|
||||
public function setCarrier(?Carrier $carrier): self
|
||||
{
|
||||
$this->carrier = $carrier;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'merchandise_type')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
requirements: ['id' => '\d+'],
|
||||
normalizationContext: ['groups' => ['merchandise-type:read']],
|
||||
),
|
||||
new GetCollection(
|
||||
normalizationContext: ['groups' => ['merchandise-type:read']],
|
||||
),
|
||||
],
|
||||
security: "is_granted('ROLE_USER')",
|
||||
)]
|
||||
class MerchandiseType
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['reception:read', 'merchandise-type:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 120)]
|
||||
#[Groups(['reception:read', 'merchandise-type:read'])]
|
||||
private string $label = '';
|
||||
|
||||
#[ORM\Column(length: 50)]
|
||||
#[Groups(['reception:read', 'merchandise-type:read'])]
|
||||
private string $code = '';
|
||||
|
||||
/**
|
||||
* @var Collection<int, Reception>
|
||||
*/
|
||||
#[ORM\OneToMany(mappedBy: 'merchandiseType', targetEntity: Reception::class)]
|
||||
private Collection $receptions;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->receptions = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setLabel(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCode(): string
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function setCode(string $code): self
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Reception>
|
||||
*/
|
||||
public function getReceptions(): Collection
|
||||
{
|
||||
return $this->receptions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'pellet_type')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
requirements: ['id' => '\d+'],
|
||||
normalizationContext: ['groups' => ['pellet-type:read']],
|
||||
),
|
||||
new GetCollection(
|
||||
normalizationContext: ['groups' => ['pellet-type:read']],
|
||||
),
|
||||
],
|
||||
security: "is_granted('ROLE_USER')",
|
||||
)]
|
||||
class PelletType
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['pellet-type:read', 'reception:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 120)]
|
||||
#[Groups(['pellet-type:read', 'reception:read'])]
|
||||
private string $label = '';
|
||||
|
||||
#[ORM\Column(length: 50)]
|
||||
#[Groups(['pellet-type:read', 'reception:read'])]
|
||||
private string $code = '';
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setLabel(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCode(): string
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function setCode(string $code): self
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
+277
-2
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
@@ -16,6 +17,7 @@ use App\State\ReceptionWeighingProvider;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Event\PostPersistEventArgs;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Context;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
@@ -77,6 +79,10 @@ class Reception
|
||||
#[Groups(['reception:read', 'reception:write'])]
|
||||
private ?string $licensePlate = null;
|
||||
|
||||
#[ORM\Column(length: 20, unique: true, nullable: true)]
|
||||
#[Groups(['reception:read'])]
|
||||
private ?string $identificationNumber = null;
|
||||
|
||||
#[ORM\Column(options: ['default' => 0])]
|
||||
#[Groups(['reception:read', 'reception:write'])]
|
||||
private int $currentStep = 0;
|
||||
@@ -90,15 +96,85 @@ class Reception
|
||||
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
||||
private ?DateTimeImmutable $receptionDate = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
#[Groups(['reception:read', 'reception:write'])]
|
||||
private ?string $merchandiseDetail = null;
|
||||
|
||||
#[ORM\OneToMany(targetEntity: Weight::class, mappedBy: 'reception', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[Groups(['reception:read'])]
|
||||
private Collection $weights;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'receptions')]
|
||||
#[ORM\JoinColumn(nullable: true)]
|
||||
#[Groups(['reception:read', 'reception:write'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
private ?ReceptionType $receptionType = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'receptions')]
|
||||
#[ORM\JoinColumn(nullable: true)]
|
||||
#[Groups(['reception:read', 'reception:write'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
private ?MerchandiseType $merchandiseType = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Building>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Building::class, inversedBy: 'receptions')]
|
||||
#[ORM\JoinTable(name: 'reception_building')]
|
||||
#[Groups(['reception:read', 'reception:write'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
private Collection $buildings;
|
||||
|
||||
/**
|
||||
* @var Collection<int, ReceptionPelletBuilding>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: ReceptionPelletBuilding::class, mappedBy: 'reception', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[Groups(['reception:read'])]
|
||||
private Collection $pelletBuildings;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: true)]
|
||||
#[Groups(['reception:read', 'reception:write'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
private ?User $user = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: true)]
|
||||
#[Groups(['reception:read', 'reception:write'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
private ?Supplier $supplier = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: true)]
|
||||
#[Groups(['reception:read', 'reception:write'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
private ?Address $address = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: true)]
|
||||
#[Groups(['reception:read', 'reception:write'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
private ?Truck $truck = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: true)]
|
||||
#[Groups(['reception:read', 'reception:write'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
private ?Carrier $carrier = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: true)]
|
||||
#[Groups(['reception:read', 'reception:write'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
private ?Driver $driver = null;
|
||||
|
||||
public function __construct(
|
||||
?DateTimeImmutable $receptionDate = null,
|
||||
) {
|
||||
$this->receptionDate = $receptionDate;
|
||||
$this->weights = new ArrayCollection();
|
||||
$this->receptionDate = $receptionDate;
|
||||
$this->weights = new ArrayCollection();
|
||||
$this->buildings = new ArrayCollection();
|
||||
$this->pelletBuildings = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
@@ -112,6 +188,18 @@ class Reception
|
||||
return $this->licensePlate;
|
||||
}
|
||||
|
||||
public function getIdentificationNumber(): ?string
|
||||
{
|
||||
return $this->identificationNumber;
|
||||
}
|
||||
|
||||
public function setIdentificationNumber(?string $identificationNumber): self
|
||||
{
|
||||
$this->identificationNumber = $identificationNumber;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setLicensePlate(?string $licensePlate): self
|
||||
{
|
||||
$this->licensePlate = $licensePlate;
|
||||
@@ -158,6 +246,18 @@ class Reception
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMerchandiseDetail(): ?string
|
||||
{
|
||||
return $this->merchandiseDetail;
|
||||
}
|
||||
|
||||
public function setMerchandiseDetail(?string $merchandiseDetail): self
|
||||
{
|
||||
$this->merchandiseDetail = $merchandiseDetail;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Weight>
|
||||
*/
|
||||
@@ -166,6 +266,155 @@ class Reception
|
||||
return $this->weights;
|
||||
}
|
||||
|
||||
public function getReceptionType(): ?ReceptionType
|
||||
{
|
||||
return $this->receptionType;
|
||||
}
|
||||
|
||||
public function setReceptionType(?ReceptionType $receptionType): self
|
||||
{
|
||||
$this->receptionType = $receptionType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMerchandiseType(): ?MerchandiseType
|
||||
{
|
||||
return $this->merchandiseType;
|
||||
}
|
||||
|
||||
public function setMerchandiseType(?MerchandiseType $merchandiseType): self
|
||||
{
|
||||
$this->merchandiseType = $merchandiseType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Building>
|
||||
*/
|
||||
public function getBuildings(): Collection
|
||||
{
|
||||
return $this->buildings;
|
||||
}
|
||||
|
||||
public function addBuilding(Building $building): self
|
||||
{
|
||||
if (!$this->buildings->contains($building)) {
|
||||
$this->buildings->add($building);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeBuilding(Building $building): self
|
||||
{
|
||||
$this->buildings->removeElement($building);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, ReceptionPelletBuilding>
|
||||
*/
|
||||
public function getPelletBuildings(): Collection
|
||||
{
|
||||
return $this->pelletBuildings;
|
||||
}
|
||||
|
||||
public function addPelletBuilding(ReceptionPelletBuilding $pelletBuilding): self
|
||||
{
|
||||
if (!$this->pelletBuildings->contains($pelletBuilding)) {
|
||||
$this->pelletBuildings->add($pelletBuilding);
|
||||
$pelletBuilding->setReception($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removePelletBuilding(ReceptionPelletBuilding $pelletBuilding): self
|
||||
{
|
||||
if ($this->pelletBuildings->removeElement($pelletBuilding)) {
|
||||
if ($pelletBuilding->getReception() === $this) {
|
||||
$pelletBuilding->setReception(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function setUser(?User $user): self
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSupplier(): ?Supplier
|
||||
{
|
||||
return $this->supplier;
|
||||
}
|
||||
|
||||
public function setSupplier(?Supplier $supplier): self
|
||||
{
|
||||
$this->supplier = $supplier;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAddress(): ?Address
|
||||
{
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
public function setAddress(?Address $address): self
|
||||
{
|
||||
$this->address = $address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTruck(): ?Truck
|
||||
{
|
||||
return $this->truck;
|
||||
}
|
||||
|
||||
public function setTruck(?Truck $truck): self
|
||||
{
|
||||
$this->truck = $truck;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCarrier(): ?Carrier
|
||||
{
|
||||
return $this->carrier;
|
||||
}
|
||||
|
||||
public function setCarrier(?Carrier $carrier): self
|
||||
{
|
||||
$this->carrier = $carrier;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDriver(): ?Driver
|
||||
{
|
||||
return $this->driver;
|
||||
}
|
||||
|
||||
public function setDriver(?Driver $driver): self
|
||||
{
|
||||
$this->driver = $driver;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addWeight(Weight $weight): self
|
||||
{
|
||||
if (!$this->weights->contains($weight)) {
|
||||
@@ -194,4 +443,30 @@ class Reception
|
||||
$this->receptionDate = new DateTimeImmutable();
|
||||
}
|
||||
}
|
||||
|
||||
#[ORM\PostPersist]
|
||||
public function initializeIdentificationNumber(PostPersistEventArgs $args): void
|
||||
{
|
||||
if (null !== $this->identificationNumber) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (null === $this->id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$number = sprintf('P-BR-%04d', $this->id);
|
||||
$this->identificationNumber = $number;
|
||||
|
||||
$args->getObjectManager()
|
||||
->getConnection()
|
||||
->executeStatement(
|
||||
'UPDATE reception SET identification_number = :number WHERE id = :id',
|
||||
[
|
||||
'number' => $number,
|
||||
'id' => $this->id,
|
||||
]
|
||||
)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
|
||||
use ApiPlatform\Metadata\ApiFilter;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'reception_pellet_building')]
|
||||
#[ORM\UniqueConstraint(name: 'uniq_reception_pellet_building', columns: ['reception_id', 'pellet_type_id', 'building_id'])]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
requirements: ['id' => '\d+'],
|
||||
normalizationContext: ['groups' => ['reception-pellet-building:read']],
|
||||
),
|
||||
new GetCollection(
|
||||
normalizationContext: ['groups' => ['reception-pellet-building:read']],
|
||||
),
|
||||
new Post(
|
||||
normalizationContext: ['groups' => ['reception-pellet-building:read']],
|
||||
denormalizationContext: ['groups' => ['reception-pellet-building:write']],
|
||||
),
|
||||
new Delete(),
|
||||
],
|
||||
security: "is_granted('ROLE_USER')",
|
||||
)]
|
||||
#[ApiFilter(SearchFilter::class, properties: ['reception' => 'exact'])]
|
||||
class ReceptionPelletBuilding
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['reception-pellet-building:read', 'reception:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'pelletBuildings')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[Groups(['reception-pellet-building:read', 'reception-pellet-building:write'])]
|
||||
private ?Reception $reception = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[Groups(['reception-pellet-building:read', 'reception-pellet-building:write', 'reception:read'])]
|
||||
private ?PelletType $pelletType = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[Groups(['reception-pellet-building:read', 'reception-pellet-building:write', 'reception:read'])]
|
||||
private ?Building $building = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getReception(): ?Reception
|
||||
{
|
||||
return $this->reception;
|
||||
}
|
||||
|
||||
public function setReception(?Reception $reception): self
|
||||
{
|
||||
$this->reception = $reception;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPelletType(): ?PelletType
|
||||
{
|
||||
return $this->pelletType;
|
||||
}
|
||||
|
||||
public function setPelletType(?PelletType $pelletType): self
|
||||
{
|
||||
$this->pelletType = $pelletType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBuilding(): ?Building
|
||||
{
|
||||
return $this->building;
|
||||
}
|
||||
|
||||
public function setBuilding(?Building $building): self
|
||||
{
|
||||
$this->building = $building;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'reception_type')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
requirements: ['id' => '\d+'],
|
||||
normalizationContext: ['groups' => ['reception-type:read']],
|
||||
),
|
||||
new GetCollection(
|
||||
normalizationContext: ['groups' => ['reception-type:read']],
|
||||
),
|
||||
],
|
||||
security: "is_granted('ROLE_USER')",
|
||||
)]
|
||||
class ReceptionType
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['reception:read', 'reception-type:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(name: 'label', length: 120)]
|
||||
#[Groups(['reception:read', 'reception-type:read'])]
|
||||
private string $label = '';
|
||||
|
||||
#[ORM\Column(length: 50)]
|
||||
#[Groups(['reception:read', 'reception-type:read'])]
|
||||
private string $code = '';
|
||||
|
||||
/**
|
||||
* @var Collection<int, Reception>
|
||||
*/
|
||||
#[ORM\OneToMany(mappedBy: 'receptionType', targetEntity: Reception::class)]
|
||||
private Collection $receptions;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->receptions = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setLabel(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCode(): string
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function setCode(string $code): self
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Reception>
|
||||
*/
|
||||
public function getReceptions(): Collection
|
||||
{
|
||||
return $this->receptions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'supplier')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
requirements: ['id' => '\d+'],
|
||||
normalizationContext: ['groups' => ['supplier:read']],
|
||||
),
|
||||
new GetCollection(
|
||||
normalizationContext: ['groups' => ['supplier:read']],
|
||||
),
|
||||
],
|
||||
security: "is_granted('ROLE_USER')",
|
||||
)]
|
||||
class Supplier
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['supplier:read', 'reception:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 180)]
|
||||
#[Groups(['supplier:read', 'reception:read'])]
|
||||
private string $name = '';
|
||||
|
||||
#[ORM\Column(length: 180, nullable: true)]
|
||||
#[Groups(['supplier:read', 'reception:read'])]
|
||||
private ?string $email = null;
|
||||
|
||||
#[ORM\Column(length: 40, nullable: true)]
|
||||
#[Groups(['supplier:read', 'reception:read'])]
|
||||
private ?string $phone = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Address>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Address::class, inversedBy: 'suppliers')]
|
||||
#[ORM\JoinTable(name: 'supplier_address')]
|
||||
#[Groups(['supplier:read'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
private Collection $addresses;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->addresses = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEmail(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function setEmail(?string $email): self
|
||||
{
|
||||
$this->email = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPhone(): ?string
|
||||
{
|
||||
return $this->phone;
|
||||
}
|
||||
|
||||
public function setPhone(?string $phone): self
|
||||
{
|
||||
$this->phone = $phone;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Address>
|
||||
*/
|
||||
public function getAddresses(): Collection
|
||||
{
|
||||
return $this->addresses;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'truck')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
requirements: ['id' => '\d+'],
|
||||
normalizationContext: ['groups' => ['truck:read']],
|
||||
),
|
||||
new GetCollection(
|
||||
normalizationContext: ['groups' => ['truck:read']],
|
||||
),
|
||||
],
|
||||
security: "is_granted('ROLE_USER')",
|
||||
)]
|
||||
class Truck
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['truck:read', 'vehicle:read', 'reception:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 180)]
|
||||
#[Groups(['truck:read', 'vehicle:read', 'reception:read'])]
|
||||
private string $name = '';
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
+7
-1
@@ -23,6 +23,11 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
||||
security: "is_granted('ROLE_USER')",
|
||||
provider: MeProvider::class
|
||||
),
|
||||
new Get(
|
||||
requirements: ['id' => '\d+'],
|
||||
normalizationContext: ['groups' => ['user:read']],
|
||||
security: "is_granted('ROLE_USER')"
|
||||
),
|
||||
new GetCollection(
|
||||
normalizationContext: ['groups' => ['user:read']],
|
||||
security: "is_granted('PUBLIC_ACCESS')"
|
||||
@@ -36,10 +41,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column(type: 'integer')]
|
||||
#[Groups(['user:read', 'reception:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 180, unique: true)]
|
||||
#[Groups(['user:read'])]
|
||||
#[Groups(['user:read', 'reception:read'])]
|
||||
private string $username = '';
|
||||
|
||||
#[ORM\Column(type: 'json')]
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'vehicle')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
requirements: ['id' => '\d+'],
|
||||
normalizationContext: ['groups' => ['vehicle:read']],
|
||||
),
|
||||
new GetCollection(
|
||||
normalizationContext: ['groups' => ['vehicle:read']],
|
||||
),
|
||||
],
|
||||
security: "is_granted('ROLE_USER')",
|
||||
)]
|
||||
class Vehicle
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['vehicle:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 20)]
|
||||
#[Groups(['vehicle:read'])]
|
||||
private string $plate = '';
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[Groups(['vehicle:read'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
private ?Carrier $carrier = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[Groups(['vehicle:read'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
private ?Truck $truck = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getPlate(): string
|
||||
{
|
||||
return $this->plate;
|
||||
}
|
||||
|
||||
public function setPlate(string $plate): self
|
||||
{
|
||||
$this->plate = $plate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCarrier(): ?Carrier
|
||||
{
|
||||
return $this->carrier;
|
||||
}
|
||||
|
||||
public function setCarrier(?Carrier $carrier): self
|
||||
{
|
||||
$this->carrier = $carrier;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTruck(): ?Truck
|
||||
{
|
||||
return $this->truck;
|
||||
}
|
||||
|
||||
public function setTruck(?Truck $truck): self
|
||||
{
|
||||
$this->truck = $truck;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user