src/Entity/HousingCertificate.php line 17

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\HousingCertificateRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\HttpFoundation\File\File;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. use EasyCorp\Bundle\EasyAdminBundle\Context\BatchContext;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. #[ORM\Entity(repositoryClassHousingCertificateRepository::class)]
  13. #[Vich\Uploadable]
  14. class HousingCertificate
  15. {
  16.     private EntityManagerInterface $entityManager;
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column]
  20.     private ?int $id null;
  21.     #[ORM\ManyToOne(inversedBy'housingCertificates')]
  22.     private ?User $user null;
  23.     #[ORM\Column(length255nullabletrue)]
  24.     private ?string $city null;
  25.     #[ORM\Column(length255nullabletrue)]
  26.     private ?string $nationality null;
  27.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  28.     private ?\DateTimeInterface $refusedAt null;
  29.     #[ORM\Column(length255nullabletrue)]
  30.     private ?string $countryDelivery null;
  31.     #[ORM\Column(length255nullabletrue)]
  32.     private ?string $issuingConsulate null;
  33.     #[ORM\Column(length255nullabletrue)]
  34.     private ?string $type null;
  35.     #[Vich\UploadableField(mapping"departureCertificate_housing_file"fileNameProperty"departureCertificateName")]
  36.     private ?File $pictureCertificate null;
  37.     #[ORM\Column(length255nullabletrue)]
  38.     private ?string $departureCertificateName null;
  39.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  40.     private ?\DateTimeInterface $uploadedAt null;
  41.     #[ORM\Column(nullabletrue)]
  42.     private ?bool $isBlock null;
  43.     #[ORM\Column(length255nullabletrue)]
  44.     private ?string $civility null;
  45.         /**
  46.      * @ORM\Column(type="boolean")
  47.      */
  48.     private $approved false;
  49.     #[ORM\Column(length255nullabletrue)]
  50.     private ?string $lastName null;
  51.     #[ORM\Column(length255nullabletrue)]
  52.     private ?string $firstName null;
  53.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  54.     private ?\DateTimeInterface $birthDate null;
  55.     #[ORM\Column(length255nullabletrue)]
  56.     private ?string $passportNumber null;
  57.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  58.     private ?\DateTimeInterface $startDate null;
  59.     #[ORM\Column(nullabletrue)]
  60.     private ?bool $isPaid null;
  61.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  62.     private ?\DateTimeInterface $createdAt null;
  63.     #[ORM\ManyToMany(targetEntityResidence::class, inversedBy'housingCertificates')]
  64.     private Collection $residence;
  65.     #[ORM\ManyToMany(targetEntityBuilding::class, inversedBy'housingCertificates')]
  66.     private Collection $building;
  67.     #[ORM\Column(length255)]
  68.     private ?string $identifierString null;
  69.     #[ORM\Column(length255nullabletrue)]
  70.     private ?string $school null;
  71.     #[ORM\Column(length255nullabletrue)]
  72.     private ?string $numberId null;
  73.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  74.     private ?\DateTimeInterface $passportExpiryAt null;
  75.     #[ORM\Column(length255nullabletrue)]
  76.     private ?string $email null;
  77.     #[ORM\Column(nullabletrue)]
  78.     private ?int $idFirstBuilding null;
  79.     #[ORM\Column]
  80.     private ?bool $notCB null;
  81.     #[ORM\Column(nullabletrue)]
  82.     private ?bool $asPaymentArrival null;
  83.     #[ORM\Column(nullablefalse)]
  84.     private ?bool $isSendToConsulat =false;
  85.     #[ORM\Column(length255nullabletrue)]
  86.     private ?string $linkId null;
  87.     public function __construct()
  88.     {
  89.         $this->createdAt = new \DateTime();
  90.         $this->residence = new ArrayCollection();
  91.         $this->building = new ArrayCollection();
  92.     }
  93.     public function getExportData(): array
  94.     {
  95.         return [
  96.             [
  97.                 'ID' => $this->id,
  98.                 'User' => $this->user $this->user->getFullName() : '',
  99.                 'City' => $this->city,
  100.                 'Nationality' => $this->nationality,
  101.                 'Refused At' => $this->refusedAt $this->refusedAt->format('d/m/Y') : '',
  102.                 'Country Delivery' => $this->countryDelivery,
  103.                 'Issuing Consulate' => $this->issuingConsulate,
  104.                 'Type' => $this->type,
  105.                 'Is Block' => $this->isBlock 'Yes' 'No',
  106.                 'Civility' => $this->civility,
  107.                 'Last Name' => $this->lastName,
  108.                 'First Name' => $this->firstName,
  109.                 'Birth Date' => $this->birthDate $this->birthDate->format('d/m/Y') : '',
  110.                 'Passport Number' => $this->passportNumber,
  111.                 'Start Date' => $this->startDate $this->startDate->format('d/m/Y') : '',
  112.                 'Is Paid' => $this->isPaid 'Yes' 'No',
  113.                 'Created At' => $this->createdAt $this->createdAt->format('d/m/Y') : '',
  114.                 'Residence' => implode(', '$this->residence->map(fn ($res) => $res->getName())->toArray()),
  115.                 'Building' => implode(', '$this->building->map(fn ($build) => $build->getName())->toArray()),
  116.                 'Identifier String' => $this->identifierString,
  117.                 'School' => $this->school,
  118.                 'Number ID' => $this->numberId,
  119.                 'Passport Expiry At' => $this->passportExpiryAt $this->passportExpiryAt->format('d/m/Y') : '',
  120.                 'Email' => $this->email,
  121.                 'ID First Building' => $this->idFirstBuilding,
  122.                 'Not CB' => $this->notCB 'Yes' 'No',
  123.                 'As Payment Arrival' => $this->asPaymentArrival 'Yes' 'No',
  124.             ]
  125.         ];
  126.     }
  127.     
  128.     public function getDatePaidAt(): ?\DateTimeImmutable
  129.     {
  130.         
  131.         $qb $this->entityManager->createQueryBuilder();
  132.         $qb->select('c.datePaidAt')
  133.         ->from(CertificateTransaction::class, 'c')
  134.         ->where('c.idCertificate = :id')
  135.         ->setParameter('id'$this->getId());
  136.         
  137.         $results $qb->getQuery()->getResult();
  138.         dd($results);
  139.         return new \DateTimeImmutable();
  140.     }
  141.     // Add the exportToCSV method
  142.     public function exportToCSV($filename): void
  143.     {
  144.         $exportData $this->getExportData();
  145.     
  146.         $file fopen($filename'w');
  147.         fputcsv($filearray_keys($exportData[0])); // Write the CSV header
  148.     
  149.         foreach ($exportData as $data) {
  150.             fputcsv($file$data); // Write each row of data
  151.         }
  152.     
  153.         fclose($file);
  154.     }
  155.     public function getLinkId(): ?string
  156.     {
  157.         return $this->linkId;
  158.     }
  159.     public function setLinkId(?string $linkId): self
  160.     {
  161.         $this->linkId $linkId;
  162.         return $this;
  163.     }
  164.     public function getId(): ?int
  165.     {
  166.         return $this->id;
  167.     }
  168.     public function getUser(): ?User
  169.     {
  170.         return $this->user;
  171.     }
  172.     public function setUser(?User $user): self
  173.     {
  174.         $this->user $user;
  175.         return $this;
  176.     }
  177.     public function getCity(): ?string
  178.     {
  179.         return $this->city;
  180.     }
  181.     public function setCity(?string $city): self
  182.     {
  183.         $this->city $city;
  184.         return $this;
  185.     }
  186.     public function getNationality(): ?string
  187.     {
  188.         return $this->nationality;
  189.     }
  190.     public function setNationality(?string $nationality): self
  191.     {
  192.         $this->nationality $nationality;
  193.         return $this;
  194.     }
  195.     public function getRefusedAt(): ?\DateTimeInterface
  196.     {
  197.         return $this->refusedAt;
  198.     }
  199.     public function setRefusedAt(?\DateTimeInterface $refusedAt): self
  200.     {
  201.         $this->refusedAt $refusedAt;
  202.         return $this;
  203.     }
  204.     public function getCountryDelivery(): ?string
  205.     {
  206.         return $this->countryDelivery;
  207.     }
  208.     public function setCountryDelivery(?string $countryDelivery): self
  209.     {
  210.         $this->countryDelivery $countryDelivery;
  211.         return $this;
  212.     }
  213.     public function getIssuingConsulate(): ?string
  214.     {
  215.         return $this->issuingConsulate;
  216.     }
  217.     public function setIssuingConsulate(?string $issuingConsulate): self
  218.     {
  219.         $this->issuingConsulate $issuingConsulate;
  220.         return $this;
  221.     }
  222.     public function getType(): ?string
  223.     {
  224.         return $this->type;
  225.     }
  226.     public function setType(?string $type): self
  227.     {
  228.         $this->type $type;
  229.         return $this;
  230.     }
  231.     public function getDepartureCertificateName(): ?string
  232.     {
  233.         return $this->departureCertificateName;
  234.     }
  235.     public function setDepartureCertificateName(?string $departureCertificateName): self
  236.     {
  237.         $this->departureCertificateName $departureCertificateName;
  238.         return $this;
  239.     }
  240.     /**
  241.      * @return File|null
  242.      */
  243.     public function getPictureCertificate(): ?File
  244.     {
  245.         return $this->pictureCertificate;
  246.     }
  247.     /**
  248.      * @param File|null $pictureCertificate
  249.      */
  250.     public function setPictureCertificate(?File $pictureCertificate): void
  251.     {
  252.         $this->pictureCertificate $pictureCertificate;
  253.         if ($pictureCertificate) {
  254.             $this->uploadedAt = new \DateTime('now');
  255.         }
  256.     }
  257.     public function isApproved(): bool
  258.     {
  259.         return $this->approved;
  260.     }
  261.     public function approve(): void
  262.     {
  263.         $this->approved true;
  264.     }
  265.     public function getUploadedAt(): ?\DateTimeInterface
  266.     {
  267.         return $this->uploadedAt;
  268.     }
  269.     public function setUploadedAt(?\DateTimeInterface $uploadedAt): self
  270.     {
  271.         $this->uploadedAt $uploadedAt;
  272.         return $this;
  273.     }
  274.     public function isIsBlock(): ?bool
  275.     {
  276.         return $this->isBlock;
  277.     }
  278.     public function setIsBlock(?bool $isBlock): self
  279.     {
  280.         $this->isBlock $isBlock;
  281.         return $this;
  282.     }
  283.     public function getCivility(): ?string
  284.     {
  285.         return $this->civility;
  286.     }
  287.     public function setCivility(?string $civility): self
  288.     {
  289.         $this->civility $civility;
  290.         return $this;
  291.     }
  292.     public function getLastName(): ?string
  293.     {
  294.         return $this->lastName;
  295.     }
  296.     public function setLastName(?string $lastName): self
  297.     {
  298.         $this->lastName $lastName;
  299.         return $this;
  300.     }
  301.     public function getFirstName(): ?string
  302.     {
  303.         return $this->firstName;
  304.     }
  305.     public function setFirstName(?string $firstName): self
  306.     {
  307.         $this->firstName $firstName;
  308.         return $this;
  309.     }
  310.     public function getBirthDate(): ?\DateTimeInterface
  311.     {
  312.         return $this->birthDate;
  313.     }
  314.     public function setBirthDate(?\DateTimeInterface $birthDate): self
  315.     {
  316.         $this->birthDate $birthDate;
  317.         return $this;
  318.     }
  319.     public function getPassportNumber(): ?string
  320.     {
  321.         return $this->passportNumber;
  322.     }
  323.     public function setPassportNumber(?string $passportNumber): self
  324.     {
  325.         $this->passportNumber $passportNumber;
  326.         return $this;
  327.     }
  328.     public function getStartDate(): ?\DateTimeInterface
  329.     {
  330.         return $this->startDate;
  331.     }
  332.     public function setStartDate(?\DateTimeInterface $startDate): self
  333.     {
  334.         $this->startDate $startDate;
  335.         return $this;
  336.     }
  337.     public function isIsPaid(): ?bool
  338.     {
  339.         return $this->isPaid;
  340.     }
  341.     public function setIsPaid(?bool $isPaid): self
  342.     {
  343.         $this->isPaid $isPaid;
  344.         return $this;
  345.     }
  346.     public function getCreatedAt(): ?\DateTimeInterface
  347.     {
  348.         return $this->createdAt;
  349.     }
  350.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  351.     {
  352.         $this->createdAt $createdAt;
  353.         return $this;
  354.     }
  355.     /**
  356.      * @return Collection<int, Residence>
  357.      */
  358.     public function getResidence(): Collection
  359.     {
  360.         return $this->residence;
  361.     }
  362.     public function addResidence(Residence $residence): self
  363.     {
  364.         if (!$this->residence->contains($residence)) {
  365.             $this->residence->add($residence);
  366.         }
  367.         return $this;
  368.     }
  369.     public function removeResidence(Residence $residence): self
  370.     {
  371.         $this->residence->removeElement($residence);
  372.         return $this;
  373.     }
  374.     /**
  375.      * @return Collection<int, Building>
  376.      */
  377.     public function getBuilding(): Collection
  378.     {
  379.         return $this->building;
  380.     }
  381.     public function addBuilding(Building $building): self
  382.     {
  383.         if (!$this->building->contains($building)) {
  384.             $this->building->add($building);
  385.         }
  386.         return $this;
  387.     }
  388.     public function removeBuilding(Building $building): self
  389.     {
  390.         $this->building->removeElement($building);
  391.         return $this;
  392.     }
  393.     public function getIdentifierString(): ?string
  394.     {
  395.         return $this->identifierString;
  396.     }
  397.     public function setIdentifierString(string $identifierString): self
  398.     {
  399.         $this->identifierString $identifierString;
  400.         return $this;
  401.     }
  402.     public function getSchool(): ?string
  403.     {
  404.         return $this->school;
  405.     }
  406.     public function setSchool(?string $school): self
  407.     {
  408.         $this->school strtoupper($school);
  409.         return $this;
  410.     }
  411.     public function getNumberId(): ?string
  412.     {
  413.         return $this->numberId;
  414.     }
  415.     public function setNumberId(?string $numberId): self
  416.     {
  417.         $this->numberId $numberId;
  418.         return $this;
  419.     }
  420.     public function getPassportExpiryAt(): ?\DateTimeInterface
  421.     {
  422.         return $this->passportExpiryAt;
  423.     }
  424.     public function setPassportExpiryAt(?\DateTimeInterface $passportExpiryAt): self
  425.     {
  426.         $this->passportExpiryAt $passportExpiryAt;
  427.         return $this;
  428.     }
  429.     public function getEmail(): ?string
  430.     {
  431.         return $this->email;
  432.     }
  433.     public function setEmail(?string $email): self
  434.     {
  435.         $this->email $email;
  436.         return $this;
  437.     }
  438.     public function getIdFirstBuilding(): ?int
  439.     {
  440.         return $this->idFirstBuilding;
  441.     }
  442.     public function setIdFirstBuilding(?int $idFirstBuilding): self
  443.     {
  444.         $this->idFirstBuilding $idFirstBuilding;
  445.         return $this;
  446.     }
  447.     public function isNotCB(): ?bool
  448.     {
  449.         return $this->notCB;
  450.     }
  451.     public function setNotCB(bool $notCB): self
  452.     {
  453.         $this->notCB $notCB;
  454.         return $this;
  455.     }
  456.     public function isAsPaymentArrival(): ?bool
  457.     {
  458.         return $this->asPaymentArrival;
  459.     }
  460.     public function setAsPaymentArrival(?bool $asPaymentArrival): self
  461.     {
  462.         $this->asPaymentArrival $asPaymentArrival;
  463.         return $this;
  464.     }
  465.     public function isIsSendToConsulat(): ?bool
  466.     {
  467.         return $this->isSendToConsulat;
  468.     }
  469.     public function setIsSendToConsulat(?bool $isSendToConsulat): self
  470.     {
  471.         $this->isSendToConsulat $isSendToConsulat;
  472.         return $this;
  473.     }
  474. }