Bookings - Easyadmin support.
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
<?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 Version20240508180617 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('ALTER TABLE booking ADD ref_number VARCHAR(20) NOT NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
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('ALTER TABLE booking DROP ref_number');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\Admin;
|
||||||
|
|
||||||
|
use App\Controller\Admin\BookingCustomerCrudController;
|
||||||
|
use App\Entity\Booking;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||||
|
|
||||||
|
class BookingCrudController extends AbstractCrudController
|
||||||
|
{
|
||||||
|
public static function getEntityFqcn(): string
|
||||||
|
{
|
||||||
|
return Booking::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureFields(string $pageName): iterable
|
||||||
|
{
|
||||||
|
$fieldRefNumber = TextField::new ('refNumber');
|
||||||
|
$fieldBookingTime = DateTimeField::new ('BookingTime');
|
||||||
|
if ($pageName == Crud::PAGE_EDIT) {
|
||||||
|
$fieldRefNumber->setDisabled(true);
|
||||||
|
$fieldBookingTime->setDisabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
yield FormField::addFieldset('Booking details');
|
||||||
|
yield $fieldRefNumber;
|
||||||
|
yield $fieldBookingTime;
|
||||||
|
|
||||||
|
yield DateField::new ('ArrivalDate');
|
||||||
|
yield DateField::new ('DepartureDate');
|
||||||
|
|
||||||
|
yield AssociationField::new ('bookingCustomer')->renderAsEmbeddedForm(BookingCustomerCrudController::class);
|
||||||
|
yield CollectionField::new ('bookingRooms')->useEntryCrudForm();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\Admin;
|
||||||
|
|
||||||
|
use App\Entity\BookingCustomer;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||||
|
|
||||||
|
class BookingCustomerCrudController extends AbstractCrudController
|
||||||
|
{
|
||||||
|
public static function getEntityFqcn(): string
|
||||||
|
{
|
||||||
|
return BookingCustomer::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureFields(string $pageName): iterable
|
||||||
|
{
|
||||||
|
yield TextField::new('Name');
|
||||||
|
yield TextField::new('Surname');
|
||||||
|
yield TextField::new('Email');
|
||||||
|
yield TextField::new('PhoneNumber');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\Admin;
|
||||||
|
|
||||||
|
use App\Controller\Admin\RoomCategoryCrudController;
|
||||||
|
use App\Entity\BookingRoom;
|
||||||
|
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 BookingRoomCrudController extends AbstractCrudController
|
||||||
|
{
|
||||||
|
public static function getEntityFqcn(): string
|
||||||
|
{
|
||||||
|
return BookingRoom::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureFields(string $pageName): iterable
|
||||||
|
{
|
||||||
|
yield AssociationField::new ('RoomCategory')->setCrudController(RoomCategoryCrudController::class);
|
||||||
|
yield NumberField::new ('GuestNumber');
|
||||||
|
yield MoneyField::new ('RoomPrice')->setCurrency("EUR");
|
||||||
|
yield NumberField::new ('Amount');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,20 +2,18 @@
|
|||||||
|
|
||||||
namespace App\Controller\Admin;
|
namespace App\Controller\Admin;
|
||||||
|
|
||||||
|
use App\Entity\Booking;
|
||||||
|
use App\Entity\ConfigVariable;
|
||||||
|
use App\Entity\FareTable;
|
||||||
|
use App\Entity\RoomCategory;
|
||||||
|
use App\Entity\RoomFare;
|
||||||
|
use App\Entity\User;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
|
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
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;
|
|
||||||
|
|
||||||
class SomniaDashboardController extends AbstractDashboardController
|
class SomniaDashboardController extends AbstractDashboardController
|
||||||
{
|
{
|
||||||
#[Route('/admin', name: 'admin')]
|
#[Route('/admin', name: 'admin')]
|
||||||
@@ -26,14 +24,17 @@ class SomniaDashboardController extends AbstractDashboardController
|
|||||||
|
|
||||||
public function configureDashboard(): Dashboard
|
public function configureDashboard(): Dashboard
|
||||||
{
|
{
|
||||||
return Dashboard::new()
|
return Dashboard::new ()
|
||||||
->setTitle('SomniaRooms');
|
->setTitle('SomniaRooms');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureMenuItems(): iterable
|
public function configureMenuItems(): iterable
|
||||||
{
|
{
|
||||||
yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home');
|
yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home');
|
||||||
|
|
||||||
|
yield MenuItem::Section('Booking Management');
|
||||||
|
yield MenuItem::linkToCrud('Bookings', 'fas fa-door-open', Booking::class);
|
||||||
|
|
||||||
yield MenuItem::Section('Room Management');
|
yield MenuItem::Section('Room Management');
|
||||||
yield MenuItem::linkToCrud('Category', 'fas fa-door-open', RoomCategory::class);
|
yield MenuItem::linkToCrud('Category', 'fas fa-door-open', RoomCategory::class);
|
||||||
yield MenuItem::linkToRoute('Room Availability', 'fas fa-calendar-check', 'admin_roomAvailability');
|
yield MenuItem::linkToRoute('Room Availability', 'fas fa-calendar-check', 'admin_roomAvailability');
|
||||||
|
|||||||
+29
-9
@@ -19,21 +19,24 @@ class Booking
|
|||||||
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
||||||
private ?\DateTimeInterface $ArrivalDate = null;
|
private ?\DateTimeInterface $ArrivalDate = null;
|
||||||
|
|
||||||
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
#[ORM\Column(type : Types::DATE_MUTABLE)]
|
||||||
private ?\DateTimeInterface $DepartureDate = null;
|
private ?\DateTimeInterface $DepartureDate = null;
|
||||||
|
|
||||||
#[ORM\Column(type: Types::DATETIMETZ_MUTABLE)]
|
#[ORM\Column(type : Types::DATETIMETZ_MUTABLE)]
|
||||||
private ?\DateTimeInterface $BookingTime = null;
|
private ?\DateTimeInterface $BookingTime = null;
|
||||||
|
|
||||||
#[ORM\OneToOne(mappedBy: 'Booking', cascade: ['persist', 'remove'])]
|
#[ORM\OneToOne(mappedBy : 'Booking', cascade: ['persist', 'remove'])]
|
||||||
private ?BookingCustomer $bookingCustomer = null;
|
private ?BookingCustomer $bookingCustomer = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Collection<int, BookingRoom>
|
* @var Collection<int, BookingRoom>
|
||||||
*/
|
*/
|
||||||
#[ORM\OneToMany(targetEntity: BookingRoom::class, mappedBy: 'Booking', orphanRemoval: true)]
|
#[ORM\OneToMany(targetEntity: BookingRoom::class, mappedBy: 'Booking', orphanRemoval: true, cascade: ['persist'])]
|
||||||
private Collection $bookingRooms;
|
private Collection $bookingRooms;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 20)]
|
||||||
|
private ?string $refNumber = null;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->bookingRooms = new ArrayCollection();
|
$this->bookingRooms = new ArrayCollection();
|
||||||
@@ -88,8 +91,8 @@ class Booking
|
|||||||
public function setBookingCustomer(BookingCustomer $bookingCustomer): static
|
public function setBookingCustomer(BookingCustomer $bookingCustomer): static
|
||||||
{
|
{
|
||||||
// set the owning side of the relation if necessary
|
// set the owning side of the relation if necessary
|
||||||
if ($bookingCustomer->getBookingId() !== $this) {
|
if ($bookingCustomer->getBooking() !== $this) {
|
||||||
$bookingCustomer->setBookingId($this);
|
$bookingCustomer->setBooking($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->bookingCustomer = $bookingCustomer;
|
$this->bookingCustomer = $bookingCustomer;
|
||||||
@@ -109,7 +112,7 @@ class Booking
|
|||||||
{
|
{
|
||||||
if (!$this->bookingRooms->contains($bookingRoom)) {
|
if (!$this->bookingRooms->contains($bookingRoom)) {
|
||||||
$this->bookingRooms->add($bookingRoom);
|
$this->bookingRooms->add($bookingRoom);
|
||||||
$bookingRoom->setBookingId($this);
|
$bookingRoom->setBooking($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -119,11 +122,28 @@ class Booking
|
|||||||
{
|
{
|
||||||
if ($this->bookingRooms->removeElement($bookingRoom)) {
|
if ($this->bookingRooms->removeElement($bookingRoom)) {
|
||||||
// set the owning side to null (unless already changed)
|
// set the owning side to null (unless already changed)
|
||||||
if ($bookingRoom->getBookingId() === $this) {
|
if ($bookingRoom->getBooking() === $this) {
|
||||||
$bookingRoom->setBookingId(null);
|
$bookingRoom->setBooking(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRefNumber(): ?string
|
||||||
|
{
|
||||||
|
return $this->refNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRefNumber(string $refNumber): static
|
||||||
|
{
|
||||||
|
$this->refNumber = $refNumber;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
function __toString(): string
|
||||||
|
{
|
||||||
|
return $this->getRefNumber();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,4 +93,9 @@ class BookingCustomer
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function __toString(): string
|
||||||
|
{
|
||||||
|
return $this->getName() . " " . $this->getSurname();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class BookingRoom
|
|||||||
return $this->RoomCategory;
|
return $this->RoomCategory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRoomCategoryId(?RoomCategory $RoomCategory): static
|
public function setRoomCategory(?RoomCategory $RoomCategory): static
|
||||||
{
|
{
|
||||||
$this->RoomCategory = $RoomCategory;
|
$this->RoomCategory = $RoomCategory;
|
||||||
|
|
||||||
@@ -94,4 +94,9 @@ class BookingRoom
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function __toString(): string
|
||||||
|
{
|
||||||
|
return $this->getAmount() . " " . $this->getRoomCategory()->getName() . " - " . $this->getGuestNumber() . " Guests";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user