<?php
namespace App\Entity;
use App\Repository\MonthlyReportRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: MonthlyReportRepository::class)]
class MonthlyReport
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'monthlyReports')]
private ?PropertyList $property = null;
#[ORM\OneToMany(mappedBy: 'monthlyReport', targetEntity: Utilities::class)]
private Collection $monthlyBills;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $periodStart = null;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $periodEnd = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $generatedAt = null;
#[ORM\ManyToOne(inversedBy: 'monthlyReports')]
private ?User $generatedBy = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $water = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $gas = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $electricity = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $internet = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $other = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $extra = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $extra2 = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $extra3 = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $extra4 = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $extra5 = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $totalCost = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $RentedRoomsRatio = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $totalRevenue = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $amountPaid = null;
#[ORM\OneToMany(mappedBy: 'monthlyReport', targetEntity: UtilitiesProperty::class)]
private Collection $utilitiesProperties;
public function __construct()
{
$this->monthlyBills = new ArrayCollection();
$this->utilitiesProperties = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getProperty(): ?PropertyList
{
return $this->property;
}
public function setProperty(?PropertyList $property): self
{
$this->property = $property;
return $this;
}
/**
* @return Collection<int, Utilities>
*/
public function getMonthlyBills(): Collection
{
return $this->monthlyBills;
}
public function addMonthlyBill(Utilities $monthlyBill): self
{
if (!$this->monthlyBills->contains($monthlyBill)) {
$this->monthlyBills->add($monthlyBill);
$monthlyBill->setMonthlyReport($this);
}
return $this;
}
public function removeMonthlyBill(Utilities $monthlyBill): self
{
if ($this->monthlyBills->removeElement($monthlyBill)) {
// set the owning side to null (unless already changed)
if ($monthlyBill->getMonthlyReport() === $this) {
$monthlyBill->setMonthlyReport(null);
}
}
return $this;
}
public function getPeriodStart(): ?\DateTimeInterface
{
return $this->periodStart;
}
public function setPeriodStart(?\DateTimeInterface $periodStart): self
{
$this->periodStart = $periodStart;
return $this;
}
public function getPeriodEnd(): ?\DateTimeInterface
{
return $this->periodEnd;
}
public function setPeriodEnd(?\DateTimeInterface $periodEnd): self
{
$this->periodEnd = $periodEnd;
return $this;
}
public function getGeneratedAt(): ?\DateTimeImmutable
{
return $this->generatedAt;
}
public function setGeneratedAt(?\DateTimeImmutable $generatedAt): self
{
$this->generatedAt = $generatedAt;
return $this;
}
public function getGeneratedBy(): ?User
{
return $this->generatedBy;
}
public function setGeneratedBy(?User $generatedBy): self
{
$this->generatedBy = $generatedBy;
return $this;
}
public function getWater(): ?string
{
return $this->water;
}
public function setWater(?string $water): self
{
$this->water = $water;
return $this;
}
public function getGas(): ?string
{
return $this->gas;
}
public function setGas(?string $gas): self
{
$this->gas = $gas;
return $this;
}
public function getElectricity(): ?string
{
return $this->electricity;
}
public function setElectricity(?string $electricity): self
{
$this->electricity = $electricity;
return $this;
}
public function getInternet(): ?string
{
return $this->internet;
}
public function setInternet(?string $internet): self
{
$this->internet = $internet;
return $this;
}
public function getOther(): ?string
{
return $this->other;
}
public function setOther(?string $other): self
{
$this->other = $other;
return $this;
}
public function getExtra(): ?string
{
return $this->extra;
}
public function setExtra(?string $extra): self
{
$this->extra = $extra;
return $this;
}
public function getExtra2(): ?string
{
return $this->extra2;
}
public function setExtra2(?string $extra2): self
{
$this->extra2 = $extra2;
return $this;
}
public function getExtra3(): ?string
{
return $this->extra3;
}
public function setExtra3(?string $extra3): self
{
$this->extra3 = $extra3;
return $this;
}
public function getExtra4(): ?string
{
return $this->extra4;
}
public function setExtra4(?string $extra4): self
{
$this->extra4 = $extra4;
return $this;
}
public function getExtra5(): ?string
{
return $this->extra5;
}
public function setExtra5(?string $extra5): self
{
$this->extra5 = $extra5;
return $this;
}
public function getTotalCost(): ?string
{
return $this->totalCost;
}
public function setTotalCost(?string $totalCost): self
{
$this->totalCost = $totalCost;
return $this;
}
public function getRentedRoomsRatio(): ?string
{
return $this->RentedRoomsRatio;
}
public function setRentedRoomsRatio(?string $RentedRoomsRatio): self
{
$this->RentedRoomsRatio = $RentedRoomsRatio;
return $this;
}
public function getTotalRevenue(): ?string
{
return $this->totalRevenue;
}
public function setTotalRevenue(?string $totalRevenue): self
{
$this->totalRevenue = $totalRevenue;
return $this;
}
public function getAmountPaid(): ?string
{
return $this->amountPaid;
}
public function setAmountPaid(?string $amountPaid): self
{
$this->amountPaid = $amountPaid;
return $this;
}
/*
public function calculateUtilityCosts()
{
$property = $this->getProperty();
$utilities = $this->getMonthlyBills();
$tenants=$property->getTenants();
// Calculate the total number of rented bedrooms and tenants
$numRentedBedrooms = 0;
$numTenants = 0;
foreach ($tenants as $tenant) {
if ($tenant->getProperty() === $property) {
$numRentedBedrooms += $tenant->getProperty()->getPropertyDetails()->getBedroomNumber();
$numTenants += $tenant->getProperty()->getTenants()->count();
}
}
// Calculate the utility costs based on the number of rented bedrooms and tenants
$totalUtilityCost = 0;
foreach ($utilities as $utility) {
if ($utility->getIsVariableCost()) {
// Variable cost utilities are split equally between rented bedrooms
$totalUtilityCost += $utility->getCost() * $numRentedBedrooms / $property->getPropertyDetails()->getBedroomNumber();;
} else {
// Fixed cost utilities are split equally between tenants
$totalUtilityCost += $utility->getCost() * $numTenants / $property->getPropertyDetails()->getBedroomNumber();
}
}
return $totalUtilityCost;
}
*/
/**
* @return Collection<int, UtilitiesProperty>
*/
public function getUtilitiesProperties(): Collection
{
return $this->utilitiesProperties;
}
public function addUtilitiesProperty(UtilitiesProperty $utilitiesProperty): static
{
if (!$this->utilitiesProperties->contains($utilitiesProperty)) {
$this->utilitiesProperties->add($utilitiesProperty);
$utilitiesProperty->setMonthlyReport($this);
}
return $this;
}
public function removeUtilitiesProperty(UtilitiesProperty $utilitiesProperty): static
{
if ($this->utilitiesProperties->removeElement($utilitiesProperty)) {
// set the owning side to null (unless already changed)
if ($utilitiesProperty->getMonthlyReport() === $this) {
$utilitiesProperty->setMonthlyReport(null);
}
}
return $this;
}
}