FareTables and RoomFares - Implementación inicial

Creación del modelo y pantallas base para administración.
This commit is contained in:
2024-04-29 23:14:28 +02:00
parent 8e7bad7771
commit 7ec989a76a
9 changed files with 427 additions and 1 deletions
+46
View File
@@ -0,0 +1,46 @@
<?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 Version20240429200025 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 SEQUENCE fare_table_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE SEQUENCE room_fare_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE TABLE fare_table (id INT NOT NULL, room_category_id INT NOT NULL, start_date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, end_date TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, comment VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_8E43BE7067333DD ON fare_table (room_category_id)');
$this->addSql('CREATE TABLE room_fare (id INT NOT NULL, fare_table_id INT NOT NULL, guest_number INT NOT NULL, fare_amount INT NOT NULL, day_type VARCHAR(2) DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_35C9B213A7233EF2 ON room_fare (fare_table_id)');
$this->addSql('ALTER TABLE fare_table ADD CONSTRAINT FK_8E43BE7067333DD FOREIGN KEY (room_category_id) REFERENCES room_category (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE room_fare ADD CONSTRAINT FK_35C9B213A7233EF2 FOREIGN KEY (fare_table_id) REFERENCES fare_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE room_availability ALTER day TYPE VARCHAR(255)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SCHEMA public');
$this->addSql('DROP SEQUENCE fare_table_id_seq CASCADE');
$this->addSql('DROP SEQUENCE room_fare_id_seq CASCADE');
$this->addSql('ALTER TABLE fare_table DROP CONSTRAINT FK_8E43BE7067333DD');
$this->addSql('ALTER TABLE room_fare DROP CONSTRAINT FK_35C9B213A7233EF2');
$this->addSql('DROP TABLE fare_table');
$this->addSql('DROP TABLE room_fare');
$this->addSql('ALTER TABLE room_availability ALTER day TYPE DATE');
}
}
@@ -0,0 +1,30 @@
<?php
namespace App\Controller\Admin;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\{AssociationField, TextField, DateField};
use App\Entity\FareTable;
use App\Entity\RoomCategory;
use App\Controller\Admin\RoomCategoryCrudController;
class FareTableCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return FareTable::class;
}
public function configureFields(string $pageName): iterable
{
//$catRepo = $this->entityManager->getRepository(SomeEntity::class);
yield AssociationField::new('roomCategory');
yield DateField::new('startDate');
yield DateField::new('endDate');
yield TextField::new('comment');
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Controller\Admin;
use App\Entity\RoomFare;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\MoneyField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
class RoomFareCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return RoomFare::class;
}
public function configureFields(string $pageName): iterable
{
$fieldFareTable = AssociationField::new ('fareTable')->setRequired(true);
if ($pageName == Crud::PAGE_EDIT) {
$fieldFareTable->setDisabled(true);
}
yield $fieldFareTable;
yield NumberField::new ('guestNumber');
yield MoneyField::new ('fareAmount')->setCurrency('EUR');
}
}
@@ -10,6 +10,8 @@ use Symfony\Component\Routing\Annotation\Route;
use App\Entity\RoomCategory;
use App\Entity\RoomAvailability;
use App\Entity\FareTable;
use App\Entity\RoomFare;
use App\Entity\User;
use App\Entity\ConfigVariable;
@@ -35,6 +37,8 @@ class SomniaDashboardController extends AbstractDashboardController
yield MenuItem::Section('Room Management');
yield MenuItem::linkToCrud('Category', 'fas fa-door-open', RoomCategory::class);
yield MenuItem::linkToRoute('Room Availability', 'fas fa-calendar-check', 'admin_roomAvailability');
yield MenuItem::linkToCrud('Fare Tables', 'fas fa-door-open', FareTable::class);
yield MenuItem::linkToCrud('Room Fares', 'fas fa-door-open', RoomFare::class);
yield MenuItem::Section('App Management');
yield MenuItem::linkToCrud('Config Vars', 'fas fa-gear', ConfigVariable::class);
+132
View File
@@ -0,0 +1,132 @@
<?php
namespace App\Entity;
use App\Repository\FareTableRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: FareTableRepository::class)]
class FareTable
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false, onDelete: "CASCADE")]
private ?RoomCategory $roomCategory = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $startDate = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $endDate = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $comment = null;
/**
* @var Collection<int, RoomFare>
*/
#[ORM\OneToMany(targetEntity: RoomFare::class, mappedBy: 'fareTable', orphanRemoval: true)]
private Collection $roomFares;
public function __construct()
{
$this->roomFares = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getRoomCategory(): ?RoomCategory
{
return $this->roomCategory;
}
public function setRoomCategory(?RoomCategory $roomCategory): static
{
$this->roomCategory = $roomCategory;
return $this;
}
public function getStartDate(): ?\DateTimeInterface
{
return $this->startDate;
}
public function setStartDate(\DateTimeInterface $startDate): static
{
$this->startDate = $startDate;
return $this;
}
public function getEndDate(): ?\DateTimeInterface
{
return $this->endDate;
}
public function setEndDate(?\DateTimeInterface $endDate): static
{
$this->endDate = $endDate;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): static
{
$this->comment = $comment;
return $this;
}
/**
* @return Collection<int, RoomFare>
*/
public function getRoomFares(): Collection
{
return $this->roomFares;
}
public function addRoomFare(RoomFare $roomFare): static
{
if (!$this->roomFares->contains($roomFare)) {
$this->roomFares->add($roomFare);
$roomFare->setFareTable($this);
}
return $this;
}
public function removeRoomFare(RoomFare $roomFare): static
{
if ($this->roomFares->removeElement($roomFare)) {
// set the owning side to null (unless already changed)
if ($roomFare->getFareTable() === $this) {
$roomFare->setFareTable(null);
}
}
return $this;
}
public function __toString() : string {
if(!\is_null($this->comment)) {
return $this->comment;
}
return $this->id;
}
}
+5 -1
View File
@@ -5,7 +5,6 @@ namespace App\Entity;
use App\Repository\RoomCategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Serializer\Annotation\Ignore;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
@@ -159,4 +158,9 @@ class RoomCategory
return $this;
}
public function __toString()
{
return $this->name;
}
}
+81
View File
@@ -0,0 +1,81 @@
<?php
namespace App\Entity;
use App\Repository\RoomFareRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: RoomFareRepository::class)]
class RoomFare
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'roomFares')]
#[ORM\JoinColumn(nullable: false)]
private ?FareTable $fareTable = null;
#[ORM\Column]
private ?int $guestNumber = null;
#[ORM\Column]
private ?int $fareAmount = null;
#[ORM\Column(length: 2, nullable: true)]
private ?string $dayType = null;
public function getId(): ?int
{
return $this->id;
}
public function getFareTable(): ?FareTable
{
return $this->fareTable;
}
public function setFareTable(?FareTable $fareTable): static
{
$this->fareTable = $fareTable;
return $this;
}
public function getGuestNumber(): ?int
{
return $this->guestNumber;
}
public function setGuestNumber(int $guestNumber): static
{
$this->guestNumber = $guestNumber;
return $this;
}
public function getFareAmount(): ?int
{
return $this->fareAmount;
}
public function setFareAmount(int $fareAmount): static
{
$this->fareAmount = $fareAmount;
return $this;
}
public function getDayType(): ?string
{
return $this->dayType;
}
public function setDayType(?string $dayType): static
{
$this->dayType = $dayType;
return $this;
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace App\Repository;
use App\Entity\FareTable;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<FareTable>
*
* @method FareTable|null find($id, $lockMode = null, $lockVersion = null)
* @method FareTable|null findOneBy(array $criteria, array $orderBy = null)
* @method FareTable[] findAll()
* @method FareTable[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class FareTableRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, FareTable::class);
}
// /**
// * @return FareTable[] Returns an array of FareTable objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('f')
// ->andWhere('f.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('f.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?FareTable
// {
// return $this->createQueryBuilder('f')
// ->andWhere('f.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace App\Repository;
use App\Entity\RoomFare;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<RoomFare>
*
* @method RoomFare|null find($id, $lockMode = null, $lockVersion = null)
* @method RoomFare|null findOneBy(array $criteria, array $orderBy = null)
* @method RoomFare[] findAll()
* @method RoomFare[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class RoomFareRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, RoomFare::class);
}
// /**
// * @return RoomFare[] Returns an array of RoomFare objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('r')
// ->andWhere('r.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('r.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?RoomFare
// {
// return $this->createQueryBuilder('r')
// ->andWhere('r.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}