src/Entity/HousingCertificate.php line 17
<?php
namespace App\Entity;
use App\Repository\HousingCertificateRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use EasyCorp\Bundle\EasyAdminBundle\Context\BatchContext;
use Doctrine\ORM\EntityManagerInterface;
#[ORM\Entity(repositoryClass: HousingCertificateRepository::class)]
#[Vich\Uploadable]
class HousingCertificate
{
private EntityManagerInterface $entityManager;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'housingCertificates')]
private ?User $user = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $city = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $nationality = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $refusedAt = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $countryDelivery = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $issuingConsulate = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $type = null;
#[Vich\UploadableField(mapping: "departureCertificate_housing_file", fileNameProperty: "departureCertificateName")]
private ?File $pictureCertificate = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $departureCertificateName = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $uploadedAt = null;
#[ORM\Column(nullable: true)]
private ?bool $isBlock = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $civility = null;
/**
* @ORM\Column(type="boolean")
*/
private $approved = false;
#[ORM\Column(length: 255, nullable: true)]
private ?string $lastName = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $firstName = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $birthDate = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $passportNumber = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $startDate = null;
#[ORM\Column(nullable: true)]
private ?bool $isPaid = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $createdAt = null;
#[ORM\ManyToMany(targetEntity: Residence::class, inversedBy: 'housingCertificates')]
private Collection $residence;
#[ORM\ManyToMany(targetEntity: Building::class, inversedBy: 'housingCertificates')]
private Collection $building;
#[ORM\Column(length: 255)]
private ?string $identifierString = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $school = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $numberId = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $passportExpiryAt = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $email = null;
#[ORM\Column(nullable: true)]
private ?int $idFirstBuilding = null;
#[ORM\Column]
private ?bool $notCB = null;
#[ORM\Column(nullable: true)]
private ?bool $asPaymentArrival = null;
#[ORM\Column(nullable: false)]
private ?bool $isSendToConsulat =false;
#[ORM\Column(length: 255, nullable: true)]
private ?string $linkId = null;
public function __construct()
{
$this->createdAt = new \DateTime();
$this->residence = new ArrayCollection();
$this->building = new ArrayCollection();
}
public function getExportData(): array
{
return [
[
'ID' => $this->id,
'User' => $this->user ? $this->user->getFullName() : '',
'City' => $this->city,
'Nationality' => $this->nationality,
'Refused At' => $this->refusedAt ? $this->refusedAt->format('d/m/Y') : '',
'Country Delivery' => $this->countryDelivery,
'Issuing Consulate' => $this->issuingConsulate,
'Type' => $this->type,
'Is Block' => $this->isBlock ? 'Yes' : 'No',
'Civility' => $this->civility,
'Last Name' => $this->lastName,
'First Name' => $this->firstName,
'Birth Date' => $this->birthDate ? $this->birthDate->format('d/m/Y') : '',
'Passport Number' => $this->passportNumber,
'Start Date' => $this->startDate ? $this->startDate->format('d/m/Y') : '',
'Is Paid' => $this->isPaid ? 'Yes' : 'No',
'Created At' => $this->createdAt ? $this->createdAt->format('d/m/Y') : '',
'Residence' => implode(', ', $this->residence->map(fn ($res) => $res->getName())->toArray()),
'Building' => implode(', ', $this->building->map(fn ($build) => $build->getName())->toArray()),
'Identifier String' => $this->identifierString,
'School' => $this->school,
'Number ID' => $this->numberId,
'Passport Expiry At' => $this->passportExpiryAt ? $this->passportExpiryAt->format('d/m/Y') : '',
'Email' => $this->email,
'ID First Building' => $this->idFirstBuilding,
'Not CB' => $this->notCB ? 'Yes' : 'No',
'As Payment Arrival' => $this->asPaymentArrival ? 'Yes' : 'No',
]
];
}
public function getDatePaidAt(): ?\DateTimeImmutable
{
$qb = $this->entityManager->createQueryBuilder();
$qb->select('c.datePaidAt')
->from(CertificateTransaction::class, 'c')
->where('c.idCertificate = :id')
->setParameter('id', $this->getId());
$results = $qb->getQuery()->getResult();
dd($results);
return new \DateTimeImmutable();
}
// Add the exportToCSV method
public function exportToCSV($filename): void
{
$exportData = $this->getExportData();
$file = fopen($filename, 'w');
fputcsv($file, array_keys($exportData[0])); // Write the CSV header
foreach ($exportData as $data) {
fputcsv($file, $data); // Write each row of data
}
fclose($file);
}
public function getLinkId(): ?string
{
return $this->linkId;
}
public function setLinkId(?string $linkId): self
{
$this->linkId = $linkId;
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function getNationality(): ?string
{
return $this->nationality;
}
public function setNationality(?string $nationality): self
{
$this->nationality = $nationality;
return $this;
}
public function getRefusedAt(): ?\DateTimeInterface
{
return $this->refusedAt;
}
public function setRefusedAt(?\DateTimeInterface $refusedAt): self
{
$this->refusedAt = $refusedAt;
return $this;
}
public function getCountryDelivery(): ?string
{
return $this->countryDelivery;
}
public function setCountryDelivery(?string $countryDelivery): self
{
$this->countryDelivery = $countryDelivery;
return $this;
}
public function getIssuingConsulate(): ?string
{
return $this->issuingConsulate;
}
public function setIssuingConsulate(?string $issuingConsulate): self
{
$this->issuingConsulate = $issuingConsulate;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getDepartureCertificateName(): ?string
{
return $this->departureCertificateName;
}
public function setDepartureCertificateName(?string $departureCertificateName): self
{
$this->departureCertificateName = $departureCertificateName;
return $this;
}
/**
* @return File|null
*/
public function getPictureCertificate(): ?File
{
return $this->pictureCertificate;
}
/**
* @param File|null $pictureCertificate
*/
public function setPictureCertificate(?File $pictureCertificate): void
{
$this->pictureCertificate = $pictureCertificate;
if ($pictureCertificate) {
$this->uploadedAt = new \DateTime('now');
}
}
public function isApproved(): bool
{
return $this->approved;
}
public function approve(): void
{
$this->approved = true;
}
public function getUploadedAt(): ?\DateTimeInterface
{
return $this->uploadedAt;
}
public function setUploadedAt(?\DateTimeInterface $uploadedAt): self
{
$this->uploadedAt = $uploadedAt;
return $this;
}
public function isIsBlock(): ?bool
{
return $this->isBlock;
}
public function setIsBlock(?bool $isBlock): self
{
$this->isBlock = $isBlock;
return $this;
}
public function getCivility(): ?string
{
return $this->civility;
}
public function setCivility(?string $civility): self
{
$this->civility = $civility;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(?string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getBirthDate(): ?\DateTimeInterface
{
return $this->birthDate;
}
public function setBirthDate(?\DateTimeInterface $birthDate): self
{
$this->birthDate = $birthDate;
return $this;
}
public function getPassportNumber(): ?string
{
return $this->passportNumber;
}
public function setPassportNumber(?string $passportNumber): self
{
$this->passportNumber = $passportNumber;
return $this;
}
public function getStartDate(): ?\DateTimeInterface
{
return $this->startDate;
}
public function setStartDate(?\DateTimeInterface $startDate): self
{
$this->startDate = $startDate;
return $this;
}
public function isIsPaid(): ?bool
{
return $this->isPaid;
}
public function setIsPaid(?bool $isPaid): self
{
$this->isPaid = $isPaid;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection<int, Residence>
*/
public function getResidence(): Collection
{
return $this->residence;
}
public function addResidence(Residence $residence): self
{
if (!$this->residence->contains($residence)) {
$this->residence->add($residence);
}
return $this;
}
public function removeResidence(Residence $residence): self
{
$this->residence->removeElement($residence);
return $this;
}
/**
* @return Collection<int, Building>
*/
public function getBuilding(): Collection
{
return $this->building;
}
public function addBuilding(Building $building): self
{
if (!$this->building->contains($building)) {
$this->building->add($building);
}
return $this;
}
public function removeBuilding(Building $building): self
{
$this->building->removeElement($building);
return $this;
}
public function getIdentifierString(): ?string
{
return $this->identifierString;
}
public function setIdentifierString(string $identifierString): self
{
$this->identifierString = $identifierString;
return $this;
}
public function getSchool(): ?string
{
return $this->school;
}
public function setSchool(?string $school): self
{
$this->school = strtoupper($school);
return $this;
}
public function getNumberId(): ?string
{
return $this->numberId;
}
public function setNumberId(?string $numberId): self
{
$this->numberId = $numberId;
return $this;
}
public function getPassportExpiryAt(): ?\DateTimeInterface
{
return $this->passportExpiryAt;
}
public function setPassportExpiryAt(?\DateTimeInterface $passportExpiryAt): self
{
$this->passportExpiryAt = $passportExpiryAt;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getIdFirstBuilding(): ?int
{
return $this->idFirstBuilding;
}
public function setIdFirstBuilding(?int $idFirstBuilding): self
{
$this->idFirstBuilding = $idFirstBuilding;
return $this;
}
public function isNotCB(): ?bool
{
return $this->notCB;
}
public function setNotCB(bool $notCB): self
{
$this->notCB = $notCB;
return $this;
}
public function isAsPaymentArrival(): ?bool
{
return $this->asPaymentArrival;
}
public function setAsPaymentArrival(?bool $asPaymentArrival): self
{
$this->asPaymentArrival = $asPaymentArrival;
return $this;
}
public function isIsSendToConsulat(): ?bool
{
return $this->isSendToConsulat;
}
public function setIsSendToConsulat(?bool $isSendToConsulat): self
{
$this->isSendToConsulat = $isSendToConsulat;
return $this;
}
}